Disable toggling wifi tethering in secondary user.

- in previous release, the shortcut widget was for the top level
Hotspot & Tethering settings page. The top level settings has logic to
check whether the page is restricted and remove all preferences and
show a message to tell the user that tethering settings are not
available, and the user will not be able to launch the wifi hotspot
settings page.
- the updated shortcut now launches the wifi hotspot page directly.
The settings does not check for restriction. Copy the logic from the top
level settings to check for restriction and remove all preferences
accordingly.

Change-Id: I76fb7838e2db379f6ffbce7bf14003bccc1b10d3
Fixes: 116642428
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2018-10-10 17:06:15 -07:00
parent 5e568343c2
commit 9f1c617016
2 changed files with 61 additions and 0 deletions

View File

@@ -71,6 +71,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
private WifiManager mWifiManager;
private boolean mRestartWifiApAfterConfigChange;
private boolean mUnavailable;
@VisibleForTesting
TetherChangeReceiver mTetherChangeReceiver;
@@ -94,6 +95,15 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
return "WifiTetherSettings";
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setIfOnlyAvailableForAdmins(true);
if (isUiRestricted()) {
mUnavailable = true;
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
@@ -109,6 +119,9 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (mUnavailable) {
return;
}
// Assume we are in a SettingsActivity. This is only safe because we currently use
// SettingsActivity as base for all preference fragments.
final SettingsActivity activity = (SettingsActivity) getActivity();
@@ -122,6 +135,13 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
@Override
public void onStart() {
super.onStart();
if (mUnavailable) {
if (!isUiRestrictedByOnlyAdmin()) {
getEmptyTextView().setText(R.string.tethering_settings_not_available);
}
getPreferenceScreen().removeAll();
return;
}
final Context context = getContext();
if (context != null) {
context.registerReceiver(mTetherChangeReceiver, TETHER_STATE_CHANGE_FILTER);
@@ -131,6 +151,9 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
@Override
public void onStop() {
super.onStop();
if (mUnavailable) {
return;
}
final Context context = getContext();
if (context != null) {
context.unregisterReceiver(mTetherChangeReceiver);