Restrict changing wi-fi networks
Bug: 31852835 Test: manual - verify unrestricted as regular user, but that a password is required in demo mode. Change-Id: I60f95ccbb10ba728b384b9c8c2ae723934fb2928
This commit is contained in:
@@ -74,7 +74,6 @@ import android.provider.ContactsContract.Data;
|
|||||||
import android.provider.ContactsContract.Profile;
|
import android.provider.ContactsContract.Profile;
|
||||||
import android.provider.ContactsContract.RawContacts;
|
import android.provider.ContactsContract.RawContacts;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.Secure;
|
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
@@ -1282,13 +1281,12 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getDemoModePackageName(Context context) {
|
public static String getDemoModePackageName(Context context) {
|
||||||
return context.getResources().getString(
|
return context.getString(com.android.internal.R.string.config_demoModePackage);
|
||||||
com.android.internal.R.string.config_demoModePackage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if a given user is a profile of another user.
|
* Returns if a given user is a profile of another user.
|
||||||
* @param user The user whose profiles will be checked.
|
* @param user The user whose profiles wibe checked.
|
||||||
* @param profile The (potential) profile.
|
* @param profile The (potential) profile.
|
||||||
* @return if the profile is actually a profile
|
* @return if the profile is actually a profile
|
||||||
*/
|
*/
|
||||||
|
@@ -200,6 +200,15 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
// loaded (ODR).
|
// loaded (ODR).
|
||||||
setAnimationAllowed(false);
|
setAnimationAllowed(false);
|
||||||
|
|
||||||
|
addPreferences();
|
||||||
|
|
||||||
|
mIsRestricted = isUiRestricted();
|
||||||
|
|
||||||
|
mBgThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
|
mBgThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPreferences() {
|
||||||
addPreferencesFromResource(R.xml.wifi_settings);
|
addPreferencesFromResource(R.xml.wifi_settings);
|
||||||
|
|
||||||
mConnectedAccessPointPreferenceCategory =
|
mConnectedAccessPointPreferenceCategory =
|
||||||
@@ -218,11 +227,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
mStatusMessagePreference = new LinkablePreference(prefContext);
|
mStatusMessagePreference = new LinkablePreference(prefContext);
|
||||||
|
|
||||||
mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());
|
mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());
|
||||||
|
|
||||||
mIsRestricted = isUiRestricted();
|
|
||||||
|
|
||||||
mBgThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
|
|
||||||
mBgThread.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -341,16 +345,20 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
mWifiTracker.startTracking();
|
mWifiTracker.startTracking();
|
||||||
|
|
||||||
if (mIsRestricted) {
|
if (mIsRestricted) {
|
||||||
if (!isUiRestrictedByOnlyAdmin()) {
|
restrictUi();
|
||||||
getEmptyTextView().setText(R.string.wifi_empty_list_user_restricted);
|
|
||||||
}
|
|
||||||
getPreferenceScreen().removeAll();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onWifiStateChanged(mWifiManager.getWifiState());
|
onWifiStateChanged(mWifiManager.getWifiState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void restrictUi() {
|
||||||
|
if (!isUiRestrictedByOnlyAdmin()) {
|
||||||
|
getEmptyTextView().setText(R.string.wifi_empty_list_user_restricted);
|
||||||
|
}
|
||||||
|
getPreferenceScreen().removeAll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only update the AP list if there are not any APs currently shown.
|
* Only update the AP list if there are not any APs currently shown.
|
||||||
*
|
*
|
||||||
@@ -390,6 +398,15 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
// Because RestrictedSettingsFragment's onResume potentially requests authorization,
|
||||||
|
// which changes the restriction state, recalculate it.
|
||||||
|
final boolean alreadyImmutablyRestricted = mIsRestricted;
|
||||||
|
mIsRestricted = isUiRestricted();
|
||||||
|
if (!alreadyImmutablyRestricted && mIsRestricted) {
|
||||||
|
restrictUi();
|
||||||
|
}
|
||||||
|
|
||||||
if (mWifiEnabler != null) {
|
if (mWifiEnabler != null) {
|
||||||
mWifiEnabler.resume(activity);
|
mWifiEnabler.resume(activity);
|
||||||
}
|
}
|
||||||
@@ -411,6 +428,19 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
final boolean formerlyRestricted = mIsRestricted;
|
||||||
|
mIsRestricted = isUiRestricted();
|
||||||
|
if (formerlyRestricted && !mIsRestricted
|
||||||
|
&& getPreferenceScreen().getPreferenceCount() == 0) {
|
||||||
|
// De-restrict the ui
|
||||||
|
addPreferences();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return MetricsEvent.WIFI;
|
return MetricsEvent.WIFI;
|
||||||
|
@@ -16,18 +16,15 @@ import android.net.LinkProperties;
|
|||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserManager;
|
|
||||||
import android.os.storage.DiskInfo;
|
import android.os.storage.DiskInfo;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
import android.os.storage.VolumeInfo;
|
import android.os.storage.VolumeInfo;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.text.style.TtsSpan;
|
import android.text.style.TtsSpan;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
Reference in New Issue
Block a user