Merge "Pin protect more screens."
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 8ed9a7e..dd04cd9 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -79,7 +79,7 @@
 /*
  * Displays preferences for application developers.
  */
-public class DevelopmentSettings extends PreferenceFragment
+public class DevelopmentSettings extends RestrictedSettingsFragment
         implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
                 OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
     private static final String TAG = "DevelopmentSettings";
@@ -210,6 +210,7 @@
             = new ArrayList<CheckBoxPreference>();
 
     private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
+    private final HashSet<Preference> mProtectedByRestrictionsPrefs = new HashSet<Preference>();
 
     // To track whether a confirmation dialog was clicked.
     private boolean mDialogClicked;
@@ -219,6 +220,10 @@
 
     private boolean mUnavailable;
 
+    public DevelopmentSettings() {
+        super(null /* Don't ask for restrictions pin on creation. */);
+    }
+
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -268,6 +273,13 @@
             disableForUser(mPassword);
         }
 
+        if (shouldBePinProtected(RESTRICTIONS_PIN_SET)) {
+            protectByRestrictions(mEnableAdb);
+            protectByRestrictions(mClearAdbKeys);
+            protectByRestrictions(mEnableTerminal);
+            protectByRestrictions(mPassword);
+        }
+
         mDebugAppPref = findPreference(DEBUG_APP_KEY);
         mAllPrefs.add(mDebugAppPref);
         mWaitForDebugger = findAndInitCheckboxPref(WAIT_FOR_DEBUGGER_KEY);
@@ -350,6 +362,12 @@
         }
     }
 
+    private void protectByRestrictions(Preference pref) {
+        if (pref != null) {
+            mProtectedByRestrictionsPrefs.add(pref);
+        }
+    }
+
     private CheckBoxPreference findAndInitCheckboxPref(String key) {
         CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
         if (pref == null) {
@@ -793,7 +811,7 @@
             if (flinger != null) {
                 Parcel data = Parcel.obtain();
                 data.writeInterfaceToken("android.ui.ISurfaceComposer");
-                final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0; 
+                final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0;
                 data.writeInt(showUpdates);
                 flinger.transact(1002, data, null, 0);
                 data.recycle();
@@ -810,7 +828,7 @@
             if (flinger != null) {
                 Parcel data = Parcel.obtain();
                 data.writeInterfaceToken("android.ui.ISurfaceComposer");
-                final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0; 
+                final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0;
                 data.writeInt(disableOverlays);
                 flinger.transact(1008, data, null, 0);
                 data.recycle();
@@ -824,7 +842,7 @@
     private void updateHardwareUiOptions() {
         updateCheckBox(mForceHardwareUi, SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false));
     }
-    
+
     private void writeHardwareUiOptions() {
         SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
         pokeSystemProperties();
@@ -952,7 +970,7 @@
         updateCheckBox(mShowCpuUsage, Settings.Global.getInt(getActivity().getContentResolver(),
                 Settings.Global.SHOW_PROCESSES, 0) != 0);
     }
-    
+
     private void writeCpuUsageOptions() {
         boolean value = mShowCpuUsage.isChecked();
         Settings.Global.putInt(getActivity().getContentResolver(),
@@ -1160,6 +1178,10 @@
 
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+        if (mProtectedByRestrictionsPrefs.contains(preference)
+                && !restrictionsPinCheck(RESTRICTIONS_PIN_SET)) {
+            return false;
+        }
 
         if (Utils.isMonkeyRunning()) {
             return false;
@@ -1198,12 +1220,12 @@
                             : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
         } else if (preference == mBugreportInPower) {
             Settings.Secure.putInt(getActivity().getContentResolver(),
-                    Settings.Secure.BUGREPORT_IN_POWER_MENU, 
+                    Settings.Secure.BUGREPORT_IN_POWER_MENU,
                     mBugreportInPower.isChecked() ? 1 : 0);
         } else if (preference == mKeepScreenOn) {
             Settings.Global.putInt(getActivity().getContentResolver(),
                     Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
-                    mKeepScreenOn.isChecked() ? 
+                    mKeepScreenOn.isChecked() ?
                     (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
         } else if (preference == mBtHciSnoopLog) {
             writeBtHciSnoopLogOptions();
diff --git a/src/com/android/settings/RestrictedSettingsFragment.java b/src/com/android/settings/RestrictedSettingsFragment.java
index 55c264c..ebf2bcf 100644
--- a/src/com/android/settings/RestrictedSettingsFragment.java
+++ b/src/com/android/settings/RestrictedSettingsFragment.java
@@ -25,11 +25,16 @@
 /**
  * Base class for settings activities that should be pin protected when in restricted mode.
  * The constructor for this class will take the restriction key that this screen should be
- * locked by.  If {@link UserManager.hasRestrictionsPin()} and {@link UserManager.hasUserRestriction(String)} returns true for the
- * restriction key, then the user will hav
+ * locked by.  If {@link UserManager.hasRestrictionsPin()} and
+ * {@link UserManager.hasUserRestriction(String)} returns true for the restriction key, then
+ * the user will have to enter the restrictions pin before seeing the Settings screen.
  *
+ * If this settings screen should be pin protected whenever
+ * {@link UserManager.hasUserRestriction(String)} returns true, pass in
+ * {@link RESTRICTIONS_PIN_SET} to the constructor instead of a restrictions key.
  */
 public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
+    protected static final String RESTRICTIONS_PIN_SET = "restrictions_pin_set";
 
     // Should be unique across all settings screens that use this.
     private static final int REQUEST_PIN_CHALLENGE = 12309;
@@ -45,21 +50,22 @@
 
     private final String mRestrictionKey;
 
-    public RestrictedSettingsFragment(String restrictedFlag) {
-        mRestrictionKey = restrictedFlag;
-    }
-
-    @Override
-    public void onActivityCreated(Bundle savedInstanceState) {
-        super.onActivityCreated(savedInstanceState);
-
-        mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
+    /**
+     * @param restrictionKey The restriction key to check before pin protecting
+     *            this settings page. Pass in {@link RESTRICTIONS_PIN_SET} if it should
+     *            be PIN protected whenever a restrictions pin is set. Pass in
+     *            null if it should never be PIN protected.
+     */
+    public RestrictedSettingsFragment(String restrictionKey) {
+        mRestrictionKey = restrictionKey;
     }
 
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
+        mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
+
         if (icicle != null) {
             mChallengeSucceeded = icicle.getBoolean(KEY_CHALLENGE_SUCCEEDED, false);
             mChallengeRequested = icicle.getBoolean(KEY_CHALLENGE_REQUESTED, false);
@@ -79,8 +85,7 @@
     @Override
     public void onResume() {
         super.onResume();
-        if (mUserManager.hasUserRestriction(mRestrictionKey)
-                && mUserManager.hasRestrictionsPin()) {
+        if (shouldBePinProtected(mRestrictionKey)) {
             ensurePin();
         }
     }
@@ -121,7 +126,40 @@
      * Used to determine if the settings UI should disable UI.
      */
     protected boolean isRestrictedAndNotPinProtected() {
+        if (mRestrictionKey == null || RESTRICTIONS_PIN_SET.equals(mRestrictionKey)) {
+            return false;
+        }
         return mUserManager.hasUserRestriction(mRestrictionKey)
                 && !mUserManager.hasRestrictionsPin();
     }
+
+    /**
+     * Called to trigger the pin entry if the given restriction key is locked down.
+     * @param restrictionsKey The restriction key or {@link RESTRICTIONS_PIN_SET} if
+     *          pin entry should get triggered if there is a pin set.
+     */
+   protected boolean restrictionsPinCheck(String restrictionsKey) {
+       if (shouldBePinProtected(restrictionsKey) && !mChallengeSucceeded) {
+           ensurePin();
+           return false;
+       } else {
+           return true;
+       }
+   }
+
+   protected boolean hasChallengeSucceeded() {
+       return mChallengeSucceeded;
+   }
+
+   /**
+    * Returns true if this restrictions key is locked down.
+    */
+   protected boolean shouldBePinProtected(String restrictionKey) {
+       if (restrictionKey == null) {
+           return false;
+       }
+       boolean restricted = RESTRICTIONS_PIN_SET.equals(restrictionKey)
+               || mUserManager.hasUserRestriction(restrictionKey);
+       return restricted && mUserManager.hasRestrictionsPin();
+   }
 }
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 948aded..7a442a9 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -45,14 +45,14 @@
 import com.android.internal.widget.LockPatternUtils;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 
 /**
  * Gesture lock pattern settings.
  */
-public class SecuritySettings extends SettingsPreferenceFragment
+public class SecuritySettings extends RestrictedSettingsFragment
         implements OnPreferenceChangeListener, DialogInterface.OnClickListener {
-
     static final String TAG = "SecuritySettings";
 
     // Lock Settings
@@ -82,6 +82,8 @@
     private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
     private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
 
+    private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
+
     private PackageManager mPM;
     DevicePolicyManager mDPM;
 
@@ -106,6 +108,10 @@
 
     private boolean mIsPrimary;
 
+    public SecuritySettings() {
+        super(null /* Don't ask for restrictions pin on creation. */);
+    }
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -303,9 +309,19 @@
             }
         }
 
+        if (shouldBePinProtected(RESTRICTIONS_PIN_SET)) {
+            protectByRestrictions(mToggleAppInstallation);
+            protectByRestrictions(mToggleVerifyApps);
+        }
         return root;
     }
 
+    private void protectByRestrictions(Preference pref) {
+        if (pref != null) {
+            mProtectedByRestictionsPrefs.add(pref);
+        }
+    }
+
     private int getNumEnabledNotificationListeners() {
         final String flat = Settings.Secure.getString(getContentResolver(),
                 Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
@@ -471,6 +487,11 @@
 
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+        if (mProtectedByRestictionsPrefs.contains(preference)
+                && !restrictionsPinCheck(RESTRICTIONS_PIN_SET)) {
+            return false;
+        }
+
         final String key = preference.getKey();
 
         final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index 1f29927..ecb984d 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -16,6 +16,8 @@
 
 package com.android.settings;
 
+import java.util.HashSet;
+
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Dialog;
@@ -44,7 +46,7 @@
 import com.android.settings.nfc.NfcEnabler;
 import com.android.settings.NsdEnabler;
 
-public class WirelessSettings extends SettingsPreferenceFragment {
+public class WirelessSettings extends RestrictedSettingsFragment {
     private static final String TAG = "WirelessSettings";
 
     private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
@@ -73,7 +75,11 @@
 
     private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
     private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
+    private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
 
+    public WirelessSettings() {
+        super(null);
+    }
     /**
      * Invoked on each preference click in this hierarchy, overrides
      * PreferenceActivity's implementation.  Used to make sure we track the
@@ -81,6 +87,10 @@
      */
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+        if (mProtectedByRestictionsPrefs.contains(preference) && !hasChallengeSucceeded()) {
+            restrictionsPinCheck(RESTRICTIONS_PIN_SET);
+            return false;
+        }
         log("onPreferenceTreeClick: preference=" + preference);
         if (preference == mAirplaneModePreference && Boolean.parseBoolean(
                 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
@@ -145,6 +155,13 @@
         }
     }
 
+    private void protectByRestrictions(String key) {
+        Preference pref = findPreference(key);
+        if (pref != null) {
+            mProtectedByRestictionsPrefs.add(pref);
+        }
+    }
+
     @Override
     public Dialog onCreateDialog(int dialogId) {
         log("onCreateDialog: dialogId=" + dialogId);
@@ -225,6 +242,8 @@
                 ps.setDependency(KEY_TOGGLE_AIRPLANE);
             }
         }
+        protectByRestrictions(KEY_WIMAX_SETTINGS);
+
         // Manually set dependencies for Wifi when not toggleable.
         if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
             findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
@@ -232,7 +251,7 @@
         if (isSecondaryUser) { // Disable VPN
             removePreference(KEY_VPN_SETTINGS);
         }
-
+        protectByRestrictions(KEY_VPN_SETTINGS);
         // Manually set dependencies for Bluetooth when not toggleable.
         if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
             // No bluetooth-dependent items in the list. Code kept in case one is added later.
@@ -257,6 +276,8 @@
             removePreference(KEY_MOBILE_NETWORK_SETTINGS);
             removePreference(KEY_MANAGE_MOBILE_PLAN);
         }
+        protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS);
+        protectByRestrictions(KEY_MANAGE_MOBILE_PLAN);
 
         // Remove Airplane Mode settings if it's a stationary device such as a TV.
         if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
@@ -280,6 +301,7 @@
             Preference p = findPreference(KEY_TETHER_SETTINGS);
             p.setTitle(Utils.getTetheringLabel(cm));
         }
+        protectByRestrictions(KEY_TETHER_SETTINGS);
 
         // Enable link to CMAS app settings depending on the value in config.xml.
         boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
@@ -300,6 +322,7 @@
             Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
             if (ps != null) root.removePreference(ps);
         }
+        protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS);
     }
 
     @Override
@@ -345,6 +368,7 @@
             mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
                     mAirplaneModePreference.isChecked());
         }
+        super.onActivityResult(requestCode, resultCode, data);
     }
 
     @Override
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index ab657e0..529ee79 100755
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -27,7 +27,6 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.os.Bundle;
-import android.os.UserManager;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceCategory;
@@ -74,7 +73,6 @@
 
     private final IntentFilter mIntentFilter;
 
-    private UserManager mUserManager;
 
     // accessed from inner class (not private to avoid thunks)
     Preference mMyDevicePreference;
@@ -96,13 +94,13 @@
     };
 
     public BluetoothSettings() {
+        super(DISALLOW_CONFIG_BLUETOOTH);
         mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
     }
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-        mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
         mActivityStarted = (savedInstanceState == null);    // don't auto start scan after rotation
 
         mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
@@ -171,7 +169,7 @@
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
         if (mLocalAdapter == null) return;
         // If the user is not allowed to configure bluetooth, do not show the menu.
-        if (mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) return;
+        if (isRestrictedAndNotPinProtected()) return;
 
         boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
         boolean isDiscovering = mLocalAdapter.isDiscovering();
@@ -219,7 +217,7 @@
     }
 
     private void startScanning() {
-        if (mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) return;
+        if (isRestrictedAndNotPinProtected()) return;
         if (!mAvailableDevicesCategoryIsPresent) {
             getPreferenceScreen().addPreference(mAvailableDevicesCategory);
         }
@@ -266,7 +264,7 @@
                 mMyDevicePreference.setEnabled(true);
                 preferenceScreen.addPreference(mMyDevicePreference);
 
-                if (! mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
+                if (!isRestrictedAndNotPinProtected()) {
                     if (mDiscoverableEnabler == null) {
                         mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(),
                                 mLocalAdapter, mMyDevicePreference);
@@ -297,7 +295,7 @@
                 } else {
                     mAvailableDevicesCategory.removeAll();
                 }
-                if (! mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
+                if (!isRestrictedAndNotPinProtected()) {
                     addDeviceCategory(mAvailableDevicesCategory,
                             R.string.bluetooth_preference_found_devices,
                             BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
@@ -366,7 +364,7 @@
         public void onClick(View v) {
             // User clicked on advanced options icon for a device in the list
             if (v.getTag() instanceof CachedBluetoothDevice) {
-                if (mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) return;
+                if (isRestrictedAndNotPinProtected()) return;
 
                 CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
 
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index 7fc1b65..e2faf7f 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -26,6 +26,7 @@
 import android.util.Log;
 
 import com.android.settings.ProgressCategory;
+import com.android.settings.RestrictedSettingsFragment;
 import com.android.settings.SettingsPreferenceFragment;
 
 import java.util.Collection;
@@ -39,7 +40,7 @@
  * @see DevicePickerFragment
  */
 public abstract class DeviceListPreferenceFragment extends
-        SettingsPreferenceFragment implements BluetoothCallback {
+        RestrictedSettingsFragment implements BluetoothCallback {
 
     private static final String TAG = "DeviceListPreferenceFragment";
 
@@ -58,7 +59,8 @@
     final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap =
             new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>();
 
-    DeviceListPreferenceFragment() {
+    DeviceListPreferenceFragment(String restrictedKey) {
+        super(restrictedKey);
         mFilter = BluetoothDeviceFilter.ALL_FILTER;
     }
 
diff --git a/src/com/android/settings/bluetooth/DevicePickerFragment.java b/src/com/android/settings/bluetooth/DevicePickerFragment.java
index 027ceed..de8202b 100644
--- a/src/com/android/settings/bluetooth/DevicePickerFragment.java
+++ b/src/com/android/settings/bluetooth/DevicePickerFragment.java
@@ -34,6 +34,10 @@
  */
 public final class DevicePickerFragment extends DeviceListPreferenceFragment {
 
+    DevicePickerFragment() {
+        super(null /* Not tied to any user restrictions. */);
+    }
+
     private boolean mNeedAuth;
     private String mLaunchPackage;
     private String mLaunchClass;
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index c236b6d..1c2c5f7 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -16,6 +16,10 @@
 
 package com.android.settings.users;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.app.Activity;
@@ -42,8 +46,8 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.preference.Preference;
-import android.preference.PreferenceActivity;
 import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceActivity;
 import android.preference.PreferenceGroup;
 import android.provider.ContactsContract;
 import android.provider.ContactsContract.Contacts;
@@ -59,19 +63,13 @@
 
 import com.android.internal.widget.LockPatternUtils;
 import com.android.settings.ChooseLockGeneric;
-import com.android.settings.ChooseLockGeneric.ChooseLockGenericFragment;
 import com.android.settings.OwnerInfoSettings;
 import com.android.settings.R;
+import com.android.settings.RestrictedSettingsFragment;
 import com.android.settings.SelectableEditTextPreference;
-import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.Utils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class UserSettings extends SettingsPreferenceFragment
+public class UserSettings extends RestrictedSettingsFragment
         implements OnPreferenceClickListener, OnClickListener, DialogInterface.OnDismissListener,
         Preference.OnPreferenceChangeListener {
 
@@ -136,6 +134,9 @@
     private SparseArray<Bitmap> mUserIcons = new SparseArray<Bitmap>();
     private boolean mIsOwner = UserHandle.myUserId() == UserHandle.USER_OWNER;
 
+    public UserSettings() {
+        super(null);
+    }
 
     private Handler mHandler = new Handler() {
         @Override
@@ -717,6 +718,9 @@
 
     @Override
     public boolean onPreferenceClick(Preference pref) {
+        if (pref == mAddUser && !restrictionsPinCheck(RESTRICTIONS_PIN_SET)) {
+            return false;
+        }
         if (pref == mMePreference) {
             Intent editProfile;
             if (!mProfileExists) {
@@ -776,7 +780,9 @@
             int userId = ((UserPreference) v.getTag()).getUserId();
             switch (v.getId()) {
             case UserPreference.DELETE_ID:
-                onRemoveUserClicked(userId);
+                if (restrictionsPinCheck(RESTRICTIONS_PIN_SET)) {
+                    onRemoveUserClicked(userId);
+                }
                 break;
             case UserPreference.SETTINGS_ID:
                 onManageUserClicked(userId, false);