Settings user restriction changes: wireless & networks changes.
Bug: 14081992 Change-Id: I32b0f06da7e7ff9bd8303ce26be2584e6cddbedc
This commit is contained in:
39
res/layout/apn_disallowed_preference_screen.xml
Normal file
39
res/layout/apn_disallowed_preference_screen.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright (C) 2014 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.
|
||||
*/
|
||||
-->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/listContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:drawSelectorOnTop="false"
|
||||
android:scrollbarStyle="insideOverlay"
|
||||
android:background="@android:color/white"
|
||||
android:cacheColorHint="@android:color/white"
|
||||
android:fadingEdgeLength="16dip" />
|
||||
|
||||
<TextView android:id="@+android:id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="@string/apn_settings_not_available"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
</FrameLayout>
|
@@ -3126,6 +3126,12 @@
|
||||
<!-- Setting checkbox title for Whether to enable USB debugging support on the phone. -->
|
||||
<!-- Error message for users that aren't allowed to modify developer options [CHAR LIMIT=none] -->
|
||||
<string name="development_settings_not_available">Developer options are not available for this user</string>
|
||||
<!-- Error message for users that aren't allowed to modify VPN settings [CHAR LIMIT=none] -->
|
||||
<string name="vpn_settings_not_available">VPN settings are not available for this user</string>
|
||||
<!-- Error message for users that aren't allowed to modify Tethering settings [CHAR LIMIT=none] -->
|
||||
<string name="tethering_settings_not_available">Tethering settings are not available for this user</string>
|
||||
<!-- Error message for users that aren't allowed to modify Access Point Names settings [CHAR LIMIT=none] -->
|
||||
<string name="apn_settings_not_available">Access Point Name settings are not available for this user</string>
|
||||
<string name="enable_adb">USB debugging</string>
|
||||
<!-- Setting checkbox summary for Whether to enable USB debugging support on the phone -->
|
||||
<string name="enable_adb_summary">Debug mode when USB is connected</string>
|
||||
|
@@ -32,6 +32,7 @@ import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceGroup;
|
||||
@@ -83,10 +84,14 @@ public class ApnSettings extends PreferenceActivity implements
|
||||
private RestoreApnProcessHandler mRestoreApnProcessHandler;
|
||||
private HandlerThread mRestoreDefaultApnThread;
|
||||
|
||||
private UserManager mUm;
|
||||
|
||||
private String mSelectedKey;
|
||||
|
||||
private IntentFilter mMobileStateFilter;
|
||||
|
||||
private boolean mUnavailable;
|
||||
|
||||
private final BroadcastReceiver mMobileStateReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@@ -119,6 +124,14 @@ public class ApnSettings extends PreferenceActivity implements
|
||||
protected void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
|
||||
if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
|
||||
mUnavailable = true;
|
||||
setContentView(R.layout.apn_disallowed_preference_screen);
|
||||
return;
|
||||
}
|
||||
|
||||
addPreferencesFromResource(R.xml.apn_settings);
|
||||
getListView().setItemsCanFocus(true);
|
||||
|
||||
@@ -130,6 +143,10 @@ public class ApnSettings extends PreferenceActivity implements
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mUnavailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
registerReceiver(mMobileStateReceiver, mMobileStateFilter);
|
||||
|
||||
if (!mRestoreDefaultApnMode) {
|
||||
@@ -143,6 +160,10 @@ public class ApnSettings extends PreferenceActivity implements
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (mUnavailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
unregisterReceiver(mMobileStateReceiver);
|
||||
}
|
||||
|
||||
|
@@ -465,6 +465,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (mUnavailable) {
|
||||
return;
|
||||
}
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
@@ -47,6 +47,7 @@ import android.text.TextUtils;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
@@ -92,6 +93,7 @@ public class TetherSettings extends SettingsPreferenceFragment
|
||||
private WifiApDialog mDialog;
|
||||
private WifiManager mWifiManager;
|
||||
private WifiConfiguration mWifiConfig = null;
|
||||
private UserManager mUm;
|
||||
|
||||
private boolean mUsbConnected;
|
||||
private boolean mMassStorageActive;
|
||||
@@ -110,11 +112,21 @@ public class TetherSettings extends SettingsPreferenceFragment
|
||||
private String[] mProvisionApp;
|
||||
private static final int PROVISION_REQUEST = 0;
|
||||
|
||||
private boolean mUnavailable;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.tether_prefs);
|
||||
|
||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
|
||||
if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
|
||||
mUnavailable = true;
|
||||
setPreferenceScreen(new PreferenceScreen(getActivity(), null));
|
||||
return;
|
||||
}
|
||||
|
||||
final Activity activity = getActivity();
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (adapter != null) {
|
||||
@@ -264,6 +276,15 @@ public class TetherSettings extends SettingsPreferenceFragment
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if (mUnavailable) {
|
||||
TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
|
||||
getListView().setEmptyView(emptyView);
|
||||
if (emptyView != null) {
|
||||
emptyView.setText(R.string.tethering_settings_not_available);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final Activity activity = getActivity();
|
||||
|
||||
mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
||||
@@ -297,6 +318,10 @@ public class TetherSettings extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
if (mUnavailable) {
|
||||
return;
|
||||
}
|
||||
getActivity().unregisterReceiver(mTetherChangeReceiver);
|
||||
mTetherChangeReceiver = null;
|
||||
if (mWifiApEnabler != null) {
|
||||
|
@@ -33,6 +33,7 @@ import android.nfc.NfcAdapter;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
@@ -79,6 +80,7 @@ public class WirelessSettings extends RestrictedSettingsFragment
|
||||
private ConnectivityManager mCm;
|
||||
private TelephonyManager mTm;
|
||||
private PackageManager mPm;
|
||||
private UserManager mUm;
|
||||
|
||||
private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
|
||||
private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
|
||||
@@ -244,6 +246,7 @@ public class WirelessSettings extends RestrictedSettingsFragment
|
||||
mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
mPm = getPackageManager();
|
||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
|
||||
addPreferencesFromResource(R.xml.wireless_settings);
|
||||
|
||||
@@ -289,10 +292,11 @@ public class WirelessSettings extends RestrictedSettingsFragment
|
||||
if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
|
||||
findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
|
||||
}
|
||||
if (isSecondaryUser) { // Disable VPN
|
||||
// Disable VPN.
|
||||
if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_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.
|
||||
@@ -312,8 +316,10 @@ public class WirelessSettings extends RestrictedSettingsFragment
|
||||
mNfcEnabler = null;
|
||||
}
|
||||
|
||||
// Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
|
||||
if (isSecondaryUser || Utils.isWifiOnly(getActivity())) {
|
||||
// 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 (isSecondaryUser || Utils.isWifiOnly(getActivity())
|
||||
|| mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
|
||||
removePreference(KEY_MOBILE_NETWORK_SETTINGS);
|
||||
removePreference(KEY_MANAGE_MOBILE_PLAN);
|
||||
}
|
||||
@@ -327,8 +333,6 @@ public class WirelessSettings extends RestrictedSettingsFragment
|
||||
removePreference(KEY_MANAGE_MOBILE_PLAN);
|
||||
}
|
||||
}
|
||||
protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS);
|
||||
protectByRestrictions(KEY_MANAGE_MOBILE_PLAN);
|
||||
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
if (!isSmsSupported()) {
|
||||
@@ -351,13 +355,13 @@ public class WirelessSettings extends RestrictedSettingsFragment
|
||||
// Disable Tethering if it's not allowed or if it's a wifi-only device
|
||||
ConnectivityManager cm =
|
||||
(ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (isSecondaryUser || !cm.isTetheringSupported()) {
|
||||
if (isSecondaryUser || !cm.isTetheringSupported()
|
||||
|| mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
|
||||
getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
|
||||
} else {
|
||||
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(
|
||||
@@ -372,12 +376,12 @@ public class WirelessSettings extends RestrictedSettingsFragment
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
|
||||
}
|
||||
if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
|
||||
if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
|
||||
|| mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
|
||||
PreferenceScreen root = getPreferenceScreen();
|
||||
Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
|
||||
if (ps != null) root.removePreference(ps);
|
||||
}
|
||||
protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -29,8 +29,10 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyStore;
|
||||
import android.text.TextUtils;
|
||||
@@ -45,6 +47,7 @@ import android.view.View;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.net.LegacyVpnInfo;
|
||||
@@ -80,14 +83,25 @@ public class VpnSettings extends SettingsPreferenceFragment implements
|
||||
|
||||
private Handler mUpdater;
|
||||
private LegacyVpnInfo mInfo;
|
||||
private UserManager mUm;
|
||||
|
||||
// The key of the profile for the current ContextMenu.
|
||||
private String mSelectedKey;
|
||||
|
||||
private boolean mUnavailable;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedState) {
|
||||
super.onCreate(savedState);
|
||||
|
||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
|
||||
if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
|
||||
mUnavailable = true;
|
||||
setPreferenceScreen(new PreferenceScreen(getActivity(), null));
|
||||
return;
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
addPreferencesFromResource(R.xml.vpn_settings2);
|
||||
|
||||
@@ -156,6 +170,15 @@ public class VpnSettings extends SettingsPreferenceFragment implements
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mUnavailable) {
|
||||
TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
|
||||
getListView().setEmptyView(emptyView);
|
||||
if (emptyView != null) {
|
||||
emptyView.setText(R.string.vpn_settings_not_available);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean pickLockdown = getActivity()
|
||||
.getIntent().getBooleanExtra(EXTRA_PICK_LOCKDOWN, false);
|
||||
if (pickLockdown) {
|
||||
@@ -214,6 +237,10 @@ public class VpnSettings extends SettingsPreferenceFragment implements
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (mUnavailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide the dialog if there is one.
|
||||
if (mDialog != null) {
|
||||
mDialog.setOnDismissListener(null);
|
||||
|
Reference in New Issue
Block a user