Merge "Handle SubSettings instance leaks in Index.java"
diff --git a/src/com/android/settings/BandMode.java b/src/com/android/settings/BandMode.java
index 6f83fbc..b130295 100644
--- a/src/com/android/settings/BandMode.java
+++ b/src/com/android/settings/BandMode.java
@@ -164,7 +164,12 @@
             int size = bands[0];
 
             if (size > 0) {
+                mBandListAdapter.add(
+                        new BandListItem(Phone.BM_UNSPECIFIED)); //Always include AUTOMATIC
                 for (int i=1; i<=size; i++) {
+                    if (bands[i] == Phone.BM_UNSPECIFIED) {
+                        continue;
+                    }
                     item = new BandListItem(bands[i]);
                     mBandListAdapter.add(item);
                     if (DBG) log("Add " + item.toString());
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index 7434e67..fc473fc 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -80,6 +80,7 @@
 
     private AirplaneModeEnabler mAirplaneModeEnabler;
     private SwitchPreference mAirplaneModePreference;
+    private RestrictedPreference mVpnPreference;
     private NfcEnabler mNfcEnabler;
     private NfcAdapter mNfcAdapter;
 
@@ -230,6 +231,7 @@
 
         final Activity activity = getActivity();
         mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
+        mVpnPreference = (RestrictedPreference) findPreference(KEY_VPN_SETTINGS);
         SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
         RestrictedPreference androidBeam = (RestrictedPreference) findPreference(
                 KEY_ANDROID_BEAM_SETTINGS);
@@ -260,7 +262,7 @@
 
         // 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);
+            mVpnPreference.setDependency(KEY_TOGGLE_AIRPLANE);
         }
         // Disable VPN.
         // TODO: http://b/23693383
@@ -366,6 +368,11 @@
         } else {
             removePreference(KEY_WFC_SETTINGS);
         }
+
+        // update VPN setting
+        if (mVpnPreference != null) {
+            mVpnPreference.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_VPN);
+        }
     }
 
     @Override
@@ -429,11 +436,13 @@
                 final boolean isWimaxEnabled = !isSecondaryUser
                         && context.getResources().getBoolean(
                         com.android.internal.R.bool.config_wimaxEnabled);
+                final boolean isVpnDisallowed = um.hasUserRestriction(
+                        UserManager.DISALLOW_CONFIG_VPN);
                 if (!isWimaxEnabled) {
                     result.add(KEY_WIMAX_SETTINGS);
                 }
 
-                if (isSecondaryUser) { // Disable VPN
+                if (isSecondaryUser || isVpnDisallowed) { // Disable VPN
                     result.add(KEY_VPN_SETTINGS);
                 }
 
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index a675779..0d968ab 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -164,6 +164,7 @@
     public void onResume() {
         super.onResume();
 
+        mUnavailable = mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN);
         if (mUnavailable) {
             // Show a message to explain that VPN settings have been disabled
             if (!isUiRestrictedByOnlyAdmin()) {
@@ -172,6 +173,7 @@
             getPreferenceScreen().removeAll();
             return;
         } else {
+            setEmptyView(getEmptyTextView());
             getEmptyTextView().setText(R.string.vpn_no_vpns_added);
         }