Don't show developer options to secondary users

Show just a message that developer options are not available for the user.

Also fix silent exit of AddAccount operation by showing a toast that user
cannot add accounts.

Bug: 7409523
Bug: 8519646
Bug: 7304007

Change-Id: Id3f430d568d6b7151ac55f86dbc0ef91803fa10c
This commit is contained in:
Amith Yamasani
2013-04-13 18:30:59 -07:00
parent 34a62601ad
commit c39dcc1ce4
4 changed files with 39 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ import android.os.ServiceManager;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -64,6 +65,7 @@ import android.view.IWindowManager;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashSet;
@@ -202,6 +204,8 @@ public class DevelopmentSettings extends PreferenceFragment
private Dialog mAdbDialog;
private Dialog mAdbKeysDialog;
private boolean mUnavailable;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -211,6 +215,12 @@ public class DevelopmentSettings extends PreferenceFragment
ServiceManager.getService(Context.BACKUP_SERVICE));
mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
if (android.os.Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER) {
mUnavailable = true;
setPreferenceScreen(new PreferenceScreen(getActivity(), null));
return;
}
addPreferencesFromResource(R.xml.development_prefs);
mEnableAdb = findAndInitCheckboxPref(ENABLE_ADB);
@@ -333,6 +343,10 @@ public class DevelopmentSettings extends PreferenceFragment
final int padding = activity.getResources().getDimensionPixelSize(
R.dimen.action_bar_switch_padding);
mEnabledSwitch.setPaddingRelative(0, 0, padding, 0);
if (mUnavailable) {
mEnabledSwitch.setEnabled(false);
return;
}
mEnabledSwitch.setOnCheckedChangeListener(this);
}
@@ -379,6 +393,16 @@ public class DevelopmentSettings extends PreferenceFragment
public void onResume() {
super.onResume();
if (mUnavailable) {
// Show error message
TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
getListView().setEmptyView(emptyView);
if (emptyView != null) {
emptyView.setText(R.string.development_settings_not_available);
}
return;
}
if (mDpm.getMaximumTimeToLock(null) > 0) {
// A DeviceAdmin has specified a maximum time until the device
// will lock... in this case we can't allow the user to turn