Show more settings and add restrictions/dialogs for secondary users

Bug: 7213029 crash in About>Status
Bug: 7212495 hide System updates for second user
Bug: 7212230 nickname editor should select the text
Bug: 7160487 TTS settings
Bug: 7129411 Settings needs visibility changes for secondary users

Change-Id: Ia2d1229c08b392edfa6b671fce4a382410405b14
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a6f40d3..f0272cb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -590,6 +590,10 @@
     <string name="roaming_turn_it_on_button">Turn it on</string>
     <!-- mobile network settings screen, message in dialog box that appears when you select the "Data roaming" check box -->
     <string name="roaming_warning">When you allow data roaming, you may incur significant roaming charges!</string>
+    <!-- mobile network settings screen, message in dialog box that appears when you select the "Data roaming" check box. This is for multiuser tablets [CHAR LIMIT=none] -->
+    <string name="roaming_warning_multiuser" product="tablet">When you allow data roaming, you may incur significant roaming charges!\n\nThis setting affects all users on this tablet.</string>
+    <!-- mobile network settings screen, message in dialog box that appears when you select the "Data roaming" check box. This is for multiuser phones [CHAR LIMIT=none] -->
+    <string name="roaming_warning_multiuser" product="default">When you allow data roaming, you may incur significant roaming charges!\n\nThis setting affects all users on this phone.</string>
     <!-- mobile network settings screen, title of dialog box that appears when you select the "Data roaming" check box -->
     <string name="roaming_reenable_title">Allow data roaming?</string>
     <!-- mobile network settings screen, setting option name -->
@@ -4074,6 +4078,10 @@
     <string name="data_usage_restrict_background_title">Restrict background data?</string>
     <!-- Body of dialog shown before user restricts background data usage. [CHAR LIMIT=NONE] -->
     <string name="data_usage_restrict_background">If you restrict background mobile data, some apps and services won\'t work unless you\'re connected to a Wi-Fi network.</string>
+    <!-- Body of dialog shown before user restricts background data usage. This is for multiuser tablets. [CHAR LIMIT=NONE] -->
+    <string name="data_usage_restrict_background_multiuser" product="tablet">If you restrict background mobile data, some apps and services won\'t work unless you\'re connected to a Wi-Fi network.\n\nThis setting affects all users on this tablet.</string>
+    <!-- Body of dialog shown before user restricts background data usage. This is for multiuser phones. [CHAR LIMIT=NONE] -->
+    <string name="data_usage_restrict_background_multiuser" product="default">If you restrict background mobile data, some apps and services won\'t work unless you\'re connected to a Wi-Fi network.\n\nThis setting affects all users on this phone.</string>
 
     <!-- Label displaying current network data usage warning threshold. [CHAR LIMIT=18] -->
     <string name="data_usage_sweep_warning"><font size="21"><xliff:g id="number" example="128">^1</xliff:g></font> <font size="9"><xliff:g id="unit" example="KB">^2</xliff:g></font>\n<font size="12">warning</font></string>
@@ -4279,6 +4287,15 @@
     <!-- Spoken content description for delete icon beside a user [CHAR LIMIT=none] -->
     <string name="user_delete_user_description">Delete user</string>
 
+    <!-- Warning message when changing a global setting for a tablet.[CHAR LIMIT=none] -->
+    <string name="global_change_warning" product="tablet">This setting affects all users on this tablet.</string>
+    <!-- Warning message when changing a global setting for a phone.[CHAR LIMIT=none] -->
+    <string name="global_change_warning" product="default">This setting affects all users on this phone.</string>
+    <!-- Warning message title for global locale change [CHAR LIMIT=40] -->
+    <string name="global_locale_change_title">Change language</string>
+    <!-- Warning message title for global font change [CHAR LIMIT=40] -->
+    <string name="global_font_change_title">Change font size</string>
+
     <!-- Label for are-notifications-enabled checkbox in app details [CHAR LIMIT=20] -->
     <string name="app_notifications_switch_label">Show notifications</string>
 
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index cc526f9..d14446c 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -45,7 +45,7 @@
                 android:title="@string/screensaver_settings_title"
                 android:fragment="com.android.settings.DreamSettings" />
 
-        <ListPreference
+        <com.android.settings.WarnedListPreference
                 android:key="font_size"
                 android:title="@string/title_font_size"
                 android:summary="@string/summary_font_size"
diff --git a/res/xml/user_settings.xml b/res/xml/user_settings.xml
index acb7c0f..457239a 100644
--- a/res/xml/user_settings.xml
+++ b/res/xml/user_settings.xml
@@ -21,7 +21,7 @@
     <Preference
             android:key="user_me"
             android:summary="@string/user_owner" />
-    <EditTextPreference
+    <com.android.settings.SelectableEditTextPreference
             android:key="user_nickname"
             android:title="@string/user_nickname"
             android:icon="@drawable/empty_icon" />
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index 8d51e10..90c3460 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -452,7 +452,6 @@
         mMenuDataRoaming = menu.findItem(R.id.data_usage_menu_roaming);
         mMenuDataRoaming.setVisible(hasReadyMobileRadio(context) && !appDetailMode);
         mMenuDataRoaming.setChecked(getDataRoaming());
-        mMenuDataRoaming.setVisible(isOwner);
 
         mMenuRestrictBackground = menu.findItem(R.id.data_usage_menu_restrict_background);
         mMenuRestrictBackground.setVisible(hasReadyMobileRadio(context) && !appDetailMode);
@@ -485,7 +484,7 @@
 
         final MenuItem metered = menu.findItem(R.id.data_usage_menu_metered);
         if (hasReadyMobileRadio(context) || hasWifiRadio(context)) {
-            metered.setVisible(isOwner && !appDetailMode);
+            metered.setVisible(!appDetailMode);
         } else {
             metered.setVisible(false);
         }
@@ -1936,7 +1935,11 @@
 
             final AlertDialog.Builder builder = new AlertDialog.Builder(context);
             builder.setTitle(R.string.roaming_reenable_title);
-            builder.setMessage(R.string.roaming_warning);
+            if (Utils.hasMultipleUsers(context)) {
+                builder.setMessage(R.string.roaming_warning_multiuser);
+            } else {
+                builder.setMessage(R.string.roaming_warning);
+            }
 
             builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                 @Override
@@ -1972,7 +1975,11 @@
 
             final AlertDialog.Builder builder = new AlertDialog.Builder(context);
             builder.setTitle(R.string.data_usage_restrict_background_title);
-            builder.setMessage(getString(R.string.data_usage_restrict_background));
+            if (Utils.hasMultipleUsers(context)) {
+                builder.setMessage(R.string.data_usage_restrict_background_multiuser);
+            } else {
+                builder.setMessage(R.string.data_usage_restrict_background);
+            }
 
             builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                 @Override
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index eb9e918..5f35871 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -26,6 +26,7 @@
 import android.os.SELinux;
 import android.os.SystemClock;
 import android.os.SystemProperties;
+import android.os.UserHandle;
 import android.preference.Preference;
 import android.preference.PreferenceGroup;
 import android.preference.PreferenceScreen;
@@ -126,9 +127,14 @@
 
         // These are contained by the root preference screen
         parentPreference = getPreferenceScreen();
-        Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference,
-                KEY_SYSTEM_UPDATE_SETTINGS,
-                Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
+        if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
+            Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference,
+                    KEY_SYSTEM_UPDATE_SETTINGS,
+                    Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
+        } else {
+            // Remove for secondary users
+            removePreference(KEY_SYSTEM_UPDATE_SETTINGS);
+        }
         Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_CONTRIBUTORS,
                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
 
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index e7e1ea6..a698538 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -19,6 +19,7 @@
 import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
 
 import android.app.ActivityManagerNative;
+import android.app.Dialog;
 import android.app.admin.DevicePolicyManager;
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
@@ -35,9 +36,11 @@
 import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceScreen;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
+import android.util.AttributeSet;
 import android.util.Log;
 
 import com.android.internal.view.RotationPolicy;
@@ -46,7 +49,7 @@
 import java.util.ArrayList;
 
 public class DisplaySettings extends SettingsPreferenceFragment implements
-        Preference.OnPreferenceChangeListener {
+        Preference.OnPreferenceChangeListener, OnPreferenceClickListener {
     private static final String TAG = "DisplaySettings";
 
     /** If there is no setting in the provider, use this. */
@@ -59,10 +62,12 @@
     private static final String KEY_SCREEN_SAVER = "screensaver";
     private static final String KEY_WIFI_DISPLAY = "wifi_display";
 
+    private static final int DLG_GLOBAL_CHANGE_WARNING = 1;
+
     private DisplayManager mDisplayManager;
 
     private CheckBoxPreference mAccelerometer;
-    private ListPreference mFontSizePref;
+    private WarnedListPreference mFontSizePref;
     private CheckBoxPreference mNotificationPulse;
 
     private final Configuration mCurConfig = new Configuration();
@@ -111,8 +116,9 @@
         disableUnusableTimeouts(mScreenTimeoutPreference);
         updateTimeoutPreferenceDescription(currentTimeout);
 
-        mFontSizePref = (ListPreference) findPreference(KEY_FONT_SIZE);
+        mFontSizePref = (WarnedListPreference) findPreference(KEY_FONT_SIZE);
         mFontSizePref.setOnPreferenceChangeListener(this);
+        mFontSizePref.setOnPreferenceClickListener(this);
         mNotificationPulse = (CheckBoxPreference) findPreference(KEY_NOTIFICATION_PULSE);
         if (mNotificationPulse != null
                 && getResources().getBoolean(
@@ -256,6 +262,20 @@
         }
     }
 
+    @Override
+    public Dialog onCreateDialog(int dialogId) {
+        if (dialogId == DLG_GLOBAL_CHANGE_WARNING) {
+            return Utils.buildGlobalChangeWarningDialog(getActivity(),
+                    R.string.global_font_change_title,
+                    new Runnable() {
+                        public void run() {
+                            mFontSizePref.click();
+                        }
+                    });
+        }
+        return null;
+    }
+
     private void updateState() {
         updateAccelerometerRotationCheckbox();
         readFontSizePreference(mFontSizePref);
@@ -345,4 +365,17 @@
             }
         }
     };
+
+    @Override
+    public boolean onPreferenceClick(Preference preference) {
+        if (preference == mFontSizePref) {
+            if (Utils.hasMultipleUsers(getActivity())) {
+                showDialog(DLG_GLOBAL_CHANGE_WARNING);
+                return true;
+            } else {
+                mFontSizePref.click();
+            }
+        }
+        return false;
+    }
 }
diff --git a/src/com/android/settings/LocalePicker.java b/src/com/android/settings/LocalePicker.java
index 8b94ccb..1272ddc 100644
--- a/src/com/android/settings/LocalePicker.java
+++ b/src/com/android/settings/LocalePicker.java
@@ -16,18 +16,87 @@
 
 package com.android.settings;
 
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.util.Log;
+
+import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment;
+
 import java.util.Locale;
 
 public class LocalePicker extends com.android.internal.app.LocalePicker
-        implements com.android.internal.app.LocalePicker.LocaleSelectionListener {
+        implements com.android.internal.app.LocalePicker.LocaleSelectionListener,
+        DialogCreatable {
+
+    private static final String TAG = "LocalePicker";
+
+    private SettingsDialogFragment mDialogFragment;
+    private static final int DLG_SHOW_GLOBAL_WARNING = 1;
+    private static final String SAVE_TARGET_LOCALE = "locale";
+
+    private Locale mTargetLocale;
+
     public LocalePicker() {
         super();
         setLocaleSelectionListener(this);
     }
 
     @Override
-    public void onLocaleSelected(Locale locale) {
-        getActivity().onBackPressed();
-        LocalePicker.updateLocale(locale);
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_TARGET_LOCALE)) {
+            mTargetLocale = new Locale(savedInstanceState.getString(SAVE_TARGET_LOCALE));
+        }
+    }
+
+    @Override
+    public void onLocaleSelected(final Locale locale) {
+        if (Utils.hasMultipleUsers(getActivity())) {
+            mTargetLocale = locale;
+            showDialog(DLG_SHOW_GLOBAL_WARNING);
+        } else {
+            LocalePicker.updateLocale(locale);
+        }
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+
+        if (mTargetLocale != null) {
+            outState.putString(SAVE_TARGET_LOCALE, mTargetLocale.toString());
+        }
+    }
+
+    protected void showDialog(int dialogId) {
+        if (mDialogFragment != null) {
+            Log.e(TAG, "Old dialog fragment not null!");
+        }
+        mDialogFragment = new SettingsDialogFragment(this, dialogId);
+        mDialogFragment.show(getActivity().getFragmentManager(), Integer.toString(dialogId));
+    }
+
+    public Dialog onCreateDialog(int dialogId) {
+        return Utils.buildGlobalChangeWarningDialog(getActivity(),
+                R.string.global_locale_change_title,
+                new Runnable() {
+                    public void run() {
+                        getActivity().onBackPressed();
+                        LocalePicker.updateLocale(mTargetLocale);
+                    }
+                }
+        );
+    }
+
+    protected void removeDialog(int dialogId) {
+        // mDialogFragment may not be visible yet in parent fragment's onResume().
+        // To be able to dismiss dialog at that time, don't check
+        // mDialogFragment.isVisible().
+        if (mDialogFragment != null && mDialogFragment.getDialogId() == dialogId) {
+            mDialogFragment.dismiss();
+        }
+        mDialogFragment = null;
     }
 }
diff --git a/src/com/android/settings/SelectableEditTextPreference.java b/src/com/android/settings/SelectableEditTextPreference.java
new file mode 100644
index 0000000..503db13
--- /dev/null
+++ b/src/com/android/settings/SelectableEditTextPreference.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings;
+
+import android.content.Context;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.EditText;
+
+public class SelectableEditTextPreference extends EditTextPreference {
+
+    private int mSelectionMode;
+
+    public static final int SELECTION_CURSOR_END   = 0;
+    public static final int SELECTION_CURSOR_START = 1;
+    public static final int SELECTION_SELECT_ALL   = 2;
+
+    public SelectableEditTextPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    /**
+     * Sets the selection mode for the text when it shows up in the dialog
+     * @hide
+     * @param selectionMode can be SELECTION_CURSOR_START, SELECTION_CURSOR_END or
+     * SELECTION_SELECT_ALL. Default is SELECTION_CURSOR_END
+     */
+    public void setInitialSelectionMode(int selectionMode) {
+        mSelectionMode = selectionMode;
+    }
+
+    @Override
+    protected void onBindDialogView(View view) {
+        super.onBindDialogView(view);
+
+        EditText editText = getEditText();
+        // Set the selection based on the mSelectionMode
+        int length = editText.getText() != null ? editText.getText().length() : 0;
+        if (!TextUtils.isEmpty(editText.getText())) {
+            switch (mSelectionMode) {
+            case SELECTION_CURSOR_END:
+                editText.setSelection(length);
+                break;
+            case SELECTION_CURSOR_START:
+                editText.setSelection(0);
+                break;
+            case SELECTION_SELECT_ALL:
+                editText.setSelection(0, length);
+                break;
+            }
+        }
+    }
+}
+
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index ebd7315..b69e648 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -100,6 +100,7 @@
             R.id.wifi_settings,
             R.id.bluetooth_settings,
             R.id.data_usage_settings,
+            R.id.wireless_settings,
             R.id.device_section,
             R.id.sound_settings,
             R.id.display_settings,
@@ -107,11 +108,14 @@
             R.id.application_settings,
             R.id.battery_settings,
             R.id.personal_section,
+            R.id.location_settings,
             R.id.security_settings,
+            R.id.language_settings,
             R.id.user_settings,
             R.id.account_settings,
             R.id.account_add,
             R.id.system_section,
+            R.id.date_time_settings,
             R.id.about_settings,
             R.id.accessibility_settings
     };
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 368976a..a5f021f 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -25,6 +25,7 @@
 import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.Bundle;
+import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceFragment;
 import android.text.TextUtils;
@@ -66,6 +67,13 @@
         }
     }
 
+    protected void removePreference(String key) {
+        Preference pref = findPreference(key);
+        if (pref != null) {
+            getPreferenceScreen().removePreference(pref);
+        }
+    }
+
     /**
      * Override this if you want to show a help item in the menu, by returning the resource id.
      * @return the resource id for the help url
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 1a5c82c..07f6716 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -16,8 +16,12 @@
 
 package com.android.settings;
 
+import android.app.Activity;
 import android.app.ActivityManager;
+import android.app.AlertDialog;
+import android.app.Dialog;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
@@ -500,4 +504,26 @@
         }
         return null;
     }
+
+    /** Not global warming, it's global change warning. */
+    public static Dialog buildGlobalChangeWarningDialog(final Context context, int titleResId,
+            final Runnable positiveAction) {
+        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+        builder.setTitle(titleResId);
+        builder.setMessage(R.string.global_change_warning);
+        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                positiveAction.run();
+            }
+        });
+        builder.setNegativeButton(android.R.string.cancel, null);
+
+        return builder.create();
+    }
+
+    public static boolean hasMultipleUsers(Context context) {
+        return ((UserManager) context.getSystemService(Context.USER_SERVICE))
+                .getUsers().size() > 1;
+    }
 }
diff --git a/src/com/android/settings/VoiceInputOutputSettings.java b/src/com/android/settings/VoiceInputOutputSettings.java
index 81e624f..b499deda 100644
--- a/src/com/android/settings/VoiceInputOutputSettings.java
+++ b/src/com/android/settings/VoiceInputOutputSettings.java
@@ -183,6 +183,8 @@
     
     private void updateSettingsLink(String currentSetting) {
         ResolveInfo currentRecognizer = mAvailableRecognizersMap.get(currentSetting);
+        if (currentRecognizer == null) return;
+
         ServiceInfo si = currentRecognizer.serviceInfo;
         XmlResourceParser parser = null;
         String settingsActivity = null;
diff --git a/src/com/android/settings/WarnedListPreference.java b/src/com/android/settings/WarnedListPreference.java
new file mode 100644
index 0000000..634986d
--- /dev/null
+++ b/src/com/android/settings/WarnedListPreference.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings;
+
+import android.content.Context;
+import android.preference.ListPreference;
+import android.util.AttributeSet;
+
+public class WarnedListPreference extends ListPreference {
+    public WarnedListPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    @Override
+    protected void onClick() {
+        // Ignore this until an explicit call to click()
+    }
+
+    public void click() {
+        super.onClick();
+    }
+}
+
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index c2a3f19..10d9214 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -26,6 +26,7 @@
 import android.nfc.NfcAdapter;
 import android.os.Bundle;
 import android.os.SystemProperties;
+import android.os.UserHandle;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
@@ -96,6 +97,8 @@
 
         addPreferencesFromResource(R.xml.wireless_settings);
 
+        final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
+
         final Activity activity = getActivity();
         mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
         CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
@@ -113,7 +116,7 @@
                 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
 
         //enable/disable wimax depending on the value in config.xml
-        boolean isWimaxEnabled = this.getResources().getBoolean(
+        boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
                 com.android.internal.R.bool.config_wimaxEnabled);
         if (!isWimaxEnabled) {
             PreferenceScreen root = getPreferenceScreen();
@@ -130,6 +133,9 @@
         if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
             findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
         }
+        if (isSecondaryUser) { // Disable VPN
+            removePreference(KEY_VPN_SETTINGS);
+        }
 
         // Manually set dependencies for Bluetooth when not toggleable.
         if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
@@ -151,8 +157,8 @@
         }
 
         // Remove Mobile Network Settings if it's a wifi-only device.
-        if (Utils.isWifiOnly(getActivity())) {
-            getPreferenceScreen().removePreference(findPreference(KEY_MOBILE_NETWORK_SETTINGS));
+        if (isSecondaryUser || Utils.isWifiOnly(getActivity())) {
+            removePreference(KEY_MOBILE_NETWORK_SETTINGS);
         }
 
         // Enable Proxy selector settings if allowed.
@@ -166,7 +172,7 @@
         // Disable Tethering if it's not allowed or if it's a wifi-only device
         ConnectivityManager cm =
                 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
-        if (!cm.isTetheringSupported()) {
+        if (isSecondaryUser || !cm.isTetheringSupported()) {
             getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
         } else {
             Preference p = findPreference(KEY_TETHER_SETTINGS);
@@ -187,7 +193,7 @@
         } catch (IllegalArgumentException ignored) {
             isCellBroadcastAppLinkEnabled = false;  // CMAS app not installed
         }
-        if (!isCellBroadcastAppLinkEnabled) {
+        if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
             PreferenceScreen root = getPreferenceScreen();
             Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
             if (ps != null) root.removePreference(ps);
diff --git a/src/com/android/settings/deviceinfo/Status.java b/src/com/android/settings/deviceinfo/Status.java
index 9e884c5..8017af3 100644
--- a/src/com/android/settings/deviceinfo/Status.java
+++ b/src/com/android/settings/deviceinfo/Status.java
@@ -33,6 +33,7 @@
 import android.os.Message;
 import android.os.SystemClock;
 import android.os.SystemProperties;
+import android.os.UserHandle;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
@@ -190,13 +191,14 @@
 
         mRes = getResources();
         sUnknown = mRes.getString(R.string.device_info_default);
-
-        mPhone = PhoneFactory.getDefaultPhone();
+        if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
+            mPhone = PhoneFactory.getDefaultPhone();
+        }
         // Note - missing in zaku build, be careful later...
         mSignalStrength = findPreference(KEY_SIGNAL_STRENGTH);
         mUptime = findPreference("up_time");
 
-        if (Utils.isWifiOnly(getApplicationContext())) {
+        if (mPhone == null || Utils.isWifiOnly(getApplicationContext())) {
             for (String key : PHONE_RELATED_ENTRIES) {
                 removePreferenceFromScreen(key);
             }
@@ -267,7 +269,7 @@
     protected void onResume() {
         super.onResume();
 
-        if (!Utils.isWifiOnly(getApplicationContext())) {
+        if (mPhone != null && !Utils.isWifiOnly(getApplicationContext())) {
             mPhoneStateReceiver.registerIntent();
 
             updateSignalStrength();
@@ -285,7 +287,7 @@
     public void onPause() {
         super.onPause();
 
-        if (!Utils.isWifiOnly(getApplicationContext())) {
+        if (mPhone != null && !Utils.isWifiOnly(getApplicationContext())) {
             mPhoneStateReceiver.unregisterIntent();
             mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
         }
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 6996a3a..56c557e 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -25,29 +25,22 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.UserInfo;
-import android.database.ContentObserver;
-import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.graphics.Bitmap.CompressFormat;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
-import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
-import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.preference.EditTextPreference;
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceGroup;
 import android.provider.ContactsContract;
 import android.provider.ContactsContract.Contacts;
-import android.provider.ContactsContract.Profile;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.text.InputType;
 import android.util.Log;
@@ -57,16 +50,13 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
-import android.widget.Toast;
+import android.widget.EditText;
 
-import com.android.internal.telephony.MccTable;
 import com.android.settings.R;
+import com.android.settings.SelectableEditTextPreference;
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.Utils;
 
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -99,14 +89,9 @@
         R.drawable.ic_user_yellow
     };
 
-    private static final String[] CONTACT_PROJECTION = new String[] {
-        Phone._ID,                      // 0
-        Phone.DISPLAY_NAME,             // 1
-    };
-
     private PreferenceGroup mUserListCategory;
     private Preference mMePreference;
-    private EditTextPreference mNicknamePreference;
+    private SelectableEditTextPreference mNicknamePreference;
     private int mRemovingUserId = -1;
     private int mAddedUserId = 0;
     private boolean mAddingUser;
@@ -156,10 +141,12 @@
         if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
             mMePreference.setSummary(null);
         }
-        mNicknamePreference = (EditTextPreference) findPreference(KEY_USER_NICKNAME);
+        mNicknamePreference = (SelectableEditTextPreference) findPreference(KEY_USER_NICKNAME);
         mNicknamePreference.setOnPreferenceChangeListener(this);
         mNicknamePreference.getEditText().setInputType(
                 InputType.TYPE_TEXT_VARIATION_NORMAL | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
+        mNicknamePreference.setInitialSelectionMode(
+                SelectableEditTextPreference.SELECTION_SELECT_ALL);
         loadProfile();
         setHasOptionsMenu(true);
         IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
@@ -385,7 +372,7 @@
                 continue;
             } else if (user.id == UserHandle.myUserId()) {
                 pref = mMePreference;
-                mNicknamePreference.setText(user.name);
+                mNicknamePreference.getEditText().setText(user.name);
                 mNicknamePreference.setSummary(user.name);
             } else {
                 pref = new UserPreference(getActivity(), null, user.id,