OSDN Git Service

Add padlocks to more preferences in wireless settings.
authorSudheer Shanka <sudheersai@google.com>
Tue, 26 Jan 2016 13:50:23 +0000 (13:50 +0000)
committerSudheer Shanka <sudheersai@google.com>
Wed, 27 Jan 2016 00:25:03 +0000 (00:25 +0000)
Also set the userRestriction attribute in xml instead of
checking in WirelessSettings class and set useAdminDisabledSummary
attribute.

Change-Id: I0494bd18752425f9d4f3f7d0f64f21fcba0d26da

res/xml/wireless_settings.xml
src/com/android/settings/WirelessSettings.java

index 10ec484..d0d429a 100644 (file)
         android:fragment="com.android.settings.TetherSettings"
         android:key="tether_settings"
         android:title="@string/tether_settings_title_all"
+        settings:userRestriction="no_config_tethering"
         settings:useAdminDisabledSummary="true" />
 
     <com.android.settingslib.RestrictedPreference
         android:fragment="com.android.settings.vpn2.VpnSettings"
         android:key="vpn_settings"
         android:title="@string/vpn_settings_title"
+        settings:userRestriction="no_config_vpn"
         settings:useAdminDisabledSummary="true" />
 
-    <PreferenceScreen
+    <com.android.settingslib.RestrictedPreference
         android:key="mobile_network_settings"
         android:title="@string/network_settings_title"
         settings:keywords="@string/keywords_more_mobile_networks"
+        settings:userRestriction="no_config_mobile_networks"
+        settings:useAdminDisabledSummary="true"
         android:dependency="toggle_airplane">
         <intent
             android:action="android.intent.action.MAIN"
             android:targetPackage="com.android.phone"
             android:targetClass="com.android.phone.MobileNetworkSettings" />
-    </PreferenceScreen>
+    </com.android.settingslib.RestrictedPreference>
 
-    <Preference
+    <com.android.settingslib.RestrictedPreference
         android:key="manage_mobile_plan"
         android:title="@string/manage_mobile_plan_title"
-        android:persistent="false" />
+        android:persistent="false"
+        settings:userRestriction="no_config_mobile_networks"
+        settings:useAdminDisabledSummary="true" />
 
-    <PreferenceScreen
+    <com.android.settingslib.RestrictedPreference
         android:key="wimax_settings"
-        android:title="@string/wimax_settings" >
+        android:title="@string/wimax_settings"
+        settings:userRestriction="no_config_mobile_networks"
+        settings:useAdminDisabledSummary="true">
         <intent
             android:action="android.intent.action.MAIN"
             android:targetPackage="com.android.settings.wimax"
             android:targetClass="com.android.settings.wimax.WimaxSettings" />
-    </PreferenceScreen>
+    </com.android.settingslib.RestrictedPreference>
 
     <PreferenceScreen
         android:fragment="com.android.settings.ProxySelector"
index 63455d8..36cd346 100644 (file)
@@ -51,6 +51,7 @@ import com.android.internal.telephony.TelephonyProperties;
 import com.android.settings.nfc.NfcEnabler;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
+import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedPreference;
 
 import java.util.ArrayList;
@@ -241,8 +242,7 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
         //enable/disable wimax depending on the value in config.xml
         final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(
                 com.android.internal.R.bool.config_wimaxEnabled);
-        if (!isWimaxEnabled
-                || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
+        if (!isWimaxEnabled) {
             PreferenceScreen root = getPreferenceScreen();
             Preference ps = findPreference(KEY_WIMAX_SETTINGS);
             if (ps != null) root.removePreference(ps);
@@ -284,9 +284,8 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
         }
 
         // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
-        // if it's a wifi-only device, or if the settings are restricted.
-        if (!isAdmin || Utils.isWifiOnly(getActivity())
-                || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
+        // if it's a wifi-only device.
+        if (!isAdmin || Utils.isWifiOnly(getActivity())) {
             removePreference(KEY_MOBILE_NETWORK_SETTINGS);
             removePreference(KEY_MANAGE_MOBILE_PLAN);
         }
@@ -318,9 +317,11 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
         final ConnectivityManager cm =
                 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
 
-        if (!isAdmin || !cm.isTetheringSupported()) {
+        final boolean adminDisallowedTetherConfig = mUm.hasUserRestriction(
+                UserManager.DISALLOW_CONFIG_TETHERING);
+        if (!isAdmin || (!cm.isTetheringSupported() && !adminDisallowedTetherConfig)) {
             getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
-        } else if (!mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
+        } else if (!adminDisallowedTetherConfig) {
             Preference p = findPreference(KEY_TETHER_SETTINGS);
             p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
 
@@ -349,19 +350,6 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
         } else {
             removePreference(KEY_WFC_SETTINGS);
         }
-
-        RestrictedPreference tetherSettingsPref = (RestrictedPreference) findPreference(
-                KEY_TETHER_SETTINGS);
-        if (tetherSettingsPref != null) {
-            tetherSettingsPref.checkRestrictionAndSetDisabled(
-                    UserManager.DISALLOW_CONFIG_TETHERING);
-        }
-
-        RestrictedPreference vpnSettingsPref = (RestrictedPreference) findPreference(
-                KEY_VPN_SETTINGS);
-        if (vpnSettingsPref != null) {
-            vpnSettingsPref.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN);
-        }
     }
 
     @Override
@@ -421,8 +409,7 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
                 final boolean isWimaxEnabled = !isSecondaryUser
                         && context.getResources().getBoolean(
                         com.android.internal.R.bool.config_wimaxEnabled);
-                if (!isWimaxEnabled
-                        || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
+                if (!isWimaxEnabled) {
                     result.add(KEY_WIMAX_SETTINGS);
                 }