Respect user restrictions about adding/removing accounts, sideloading
Hide or disable options in the settings app when the user is restricted from making changes. Remove "Add account" button from Settings menu, and "remove account" option from menu in AccountSyncSettings. Remove sideloading checkbox in SecuritySettings. Also handle replacement of UserManager.isShareLocationToggleAllowed() with hasUserRestriction, which takes a restriction key string. Change-Id: I34c74fd5aed8956ba00f92e3d3c657b608454dfe
This commit is contained in:
@@ -96,7 +96,7 @@ public class LocationSettings extends SettingsPreferenceFragment
|
||||
// Only enable these controls if this user is allowed to change location
|
||||
// sharing settings.
|
||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
boolean isToggleAllowed = um.isLocationSharingToggleAllowed();
|
||||
boolean isToggleAllowed = !um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
|
||||
if (mLocationAccess != null) mLocationAccess.setEnabled(isToggleAllowed);
|
||||
if (mNetwork != null) mNetwork.setEnabled(isToggleAllowed);
|
||||
if (mGps != null) mGps.setEnabled(isToggleAllowed);
|
||||
@@ -117,6 +117,7 @@ public class LocationSettings extends SettingsPreferenceFragment
|
||||
|
||||
if (mSettingsObserver == null) {
|
||||
mSettingsObserver = new Observer() {
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
updateLocationToggles();
|
||||
}
|
||||
@@ -131,13 +132,13 @@ public class LocationSettings extends SettingsPreferenceFragment
|
||||
final ContentResolver cr = getContentResolver();
|
||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
if (preference == mNetwork) {
|
||||
if (um.isLocationSharingToggleAllowed()) {
|
||||
if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
||||
Settings.Secure.setLocationProviderEnabled(cr,
|
||||
LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
|
||||
}
|
||||
} else if (preference == mGps) {
|
||||
boolean enabled = mGps.isChecked();
|
||||
if (um.isLocationSharingToggleAllowed()) {
|
||||
if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
||||
Settings.Secure.setLocationProviderEnabled(cr,
|
||||
LocationManager.GPS_PROVIDER, enabled);
|
||||
if (mAssistedGps != null) {
|
||||
@@ -186,7 +187,7 @@ public class LocationSettings extends SettingsPreferenceFragment
|
||||
/** Enable or disable all providers when the master toggle is changed. */
|
||||
private void onToggleLocationAccess(boolean checked) {
|
||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
if (! um.isLocationSharingToggleAllowed()) {
|
||||
if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
||||
return;
|
||||
}
|
||||
final ContentResolver cr = getContentResolver();
|
||||
|
@@ -236,10 +236,26 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
removePreference(KEY_CREDENTIALS_MANAGER);
|
||||
}
|
||||
|
||||
PreferenceGroup deviceAdminCategory= (PreferenceGroup)
|
||||
root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
|
||||
mToggleAppInstallation = (CheckBoxPreference) findPreference(
|
||||
KEY_TOGGLE_INSTALL_APPLICATIONS);
|
||||
mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
|
||||
|
||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
boolean isSideloadingAllowed =
|
||||
!um.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
|
||||
// Side loading of apps.
|
||||
if (isSideloadingAllowed) {
|
||||
mToggleAppInstallation.setEnabled(isSideloadingAllowed);
|
||||
} else {
|
||||
if (deviceAdminCategory != null) {
|
||||
deviceAdminCategory.removePreference(mToggleAppInstallation);
|
||||
} else {
|
||||
mToggleAppInstallation.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Package verification, only visible to primary user and if enabled
|
||||
mToggleVerifyApps = (CheckBoxPreference) findPreference(KEY_TOGGLE_VERIFY_APPLICATIONS);
|
||||
if (mIsPrimary && showVerifierSetting()) {
|
||||
@@ -250,8 +266,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
mToggleVerifyApps.setEnabled(false);
|
||||
}
|
||||
} else {
|
||||
PreferenceGroup deviceAdminCategory= (PreferenceGroup)
|
||||
root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
|
||||
if (deviceAdminCategory != null) {
|
||||
deviceAdminCategory.removePreference(mToggleVerifyApps);
|
||||
} else {
|
||||
@@ -268,6 +282,10 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
private void setNonMarketAppsAllowed(boolean enabled) {
|
||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
if (um.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)) {
|
||||
return;
|
||||
}
|
||||
// Change the system setting
|
||||
Settings.Global.putInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS,
|
||||
enabled ? 1 : 0);
|
||||
@@ -303,6 +321,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (dialog == mWarnInstallApps && which == DialogInterface.BUTTON_POSITIVE) {
|
||||
setNonMarketAppsAllowed(true);
|
||||
@@ -505,6 +524,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
createPreferenceHierarchy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
if (preference == mLockAfter) {
|
||||
int timeout = Integer.parseInt((String) value);
|
||||
|
@@ -178,6 +178,7 @@ public class Settings extends PreferenceActivity
|
||||
|
||||
if (mParentHeader != null) {
|
||||
setParentTitle(mParentHeader.title, null, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchToParent(mParentHeader.fragment);
|
||||
}
|
||||
@@ -405,7 +406,6 @@ public class Settings extends PreferenceActivity
|
||||
@Override
|
||||
public void onBuildHeaders(List<Header> headers) {
|
||||
loadHeadersFromResource(R.xml.settings_headers, headers);
|
||||
|
||||
updateHeaderList(headers);
|
||||
}
|
||||
|
||||
@@ -414,6 +414,8 @@ public class Settings extends PreferenceActivity
|
||||
DevelopmentSettings.PREF_SHOW,
|
||||
android.os.Build.TYPE.equals("eng"));
|
||||
int i = 0;
|
||||
|
||||
final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
mHeaderIndexMap.clear();
|
||||
while (i < target.size()) {
|
||||
Header header = target.get(i);
|
||||
@@ -464,6 +466,10 @@ public class Settings extends PreferenceActivity
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (id == R.id.account_add) {
|
||||
if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
target.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (i < target.size() && target.get(i) == header
|
||||
@@ -778,6 +784,7 @@ public class Settings extends PreferenceActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUpRecreateTask(Intent targetIntent) {
|
||||
return super.shouldUpRecreateTask(new Intent(this, Settings.class));
|
||||
}
|
||||
|
@@ -28,17 +28,16 @@ import android.app.Dialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SyncAdapterType;
|
||||
import android.content.SyncInfo;
|
||||
import android.content.SyncStatusInfo;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@@ -93,10 +92,12 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.remove_account_label,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AccountManager.get(AccountSyncSettings.this.getActivity())
|
||||
.removeAccount(mAccount,
|
||||
new AccountManagerCallback<Boolean>() {
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Boolean> future) {
|
||||
// If already out of this screen, don't proceed.
|
||||
if (!AccountSyncSettings.this.isResumed()) {
|
||||
@@ -233,12 +234,15 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
||||
MenuItem syncCancel = menu.add(0, MENU_SYNC_CANCEL_ID, 0,
|
||||
getString(R.string.sync_menu_sync_cancel))
|
||||
.setIcon(com.android.internal.R.drawable.ic_menu_close_clear_cancel);
|
||||
MenuItem removeAccount = menu.add(0, MENU_REMOVE_ACCOUNT_ID, 0,
|
||||
getString(R.string.remove_account_label))
|
||||
.setIcon(R.drawable.ic_menu_delete_holo_dark);
|
||||
|
||||
removeAccount.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
if (!um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
MenuItem removeAccount = menu.add(0, MENU_REMOVE_ACCOUNT_ID, 0,
|
||||
getString(R.string.remove_account_label))
|
||||
.setIcon(R.drawable.ic_menu_delete_holo_dark);
|
||||
removeAccount.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
}
|
||||
syncNow.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
syncCancel.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
||||
|
@@ -23,8 +23,10 @@ import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
@@ -71,7 +73,8 @@ public class AddAccountSettings extends Activity {
|
||||
|
||||
private PendingIntent mPendingIntent;
|
||||
|
||||
private AccountManagerCallback<Bundle> mCallback = new AccountManagerCallback<Bundle>() {
|
||||
private final AccountManagerCallback<Bundle> mCallback = new AccountManagerCallback<Bundle>() {
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Bundle> future) {
|
||||
boolean done = true;
|
||||
try {
|
||||
@@ -120,8 +123,10 @@ public class AddAccountSettings extends Activity {
|
||||
if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "restored");
|
||||
}
|
||||
|
||||
if (mAddAccountCalled) {
|
||||
final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
if (mAddAccountCalled || um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
|
||||
// We already called add account - maybe the callback was lost.
|
||||
// Or we aren't allowed to add an account.
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
@@ -162,6 +167,7 @@ public class AddAccountSettings extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(KEY_ADD_CALLED, mAddAccountCalled);
|
||||
|
@@ -541,7 +541,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
|
||||
protected Boolean doInBackground(Void... args) {
|
||||
final UserManager um =
|
||||
(UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
if (um.isLocationSharingToggleAllowed()) {
|
||||
if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
||||
Settings.Secure.setLocationProviderEnabled(
|
||||
resolver,
|
||||
LocationManager.GPS_PROVIDER,
|
||||
|
Reference in New Issue
Block a user