Block editing of locked down wifi network from details page.

Test: make ROBOTEST_FILTER=WifiDetailPreferenceControllerTest RunSettingsRoboTests
Bug: 68990370
Change-Id: Idceb064486afd93bc8b2f52d605a788520de8e56
This commit is contained in:
Pavel Grafov
2017-11-08 20:14:03 +00:00
parent 268de492c8
commit d429225640
9 changed files with 257 additions and 93 deletions

View File

@@ -16,8 +16,18 @@
package com.android.settings.wifi;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.wifi.WifiConfiguration;
import android.provider.Settings;
import android.text.TextUtils;
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
import com.android.settingslib.wrapper.PackageManagerWrapper;
public class WifiUtils {
private static final int SSID_ASCII_MIN_LENGTH = 1;
@@ -47,4 +57,48 @@ public class WifiUtils {
final int length = password.length();
return length >= PASSWORD_MIN_LENGTH && length <= PASSWORD_MAX_LENGTH;
}
/**
* This method is a stripped and negated version of WifiConfigStore.canModifyNetwork.
* @param context Context of caller
* @param config The WiFi config.
* @return true if Settings cannot modify the config due to lockDown.
*/
public static boolean isNetworkLockedDown(Context context, WifiConfiguration config) {
if (config == null) {
return false;
}
final DevicePolicyManagerWrapper dpm = DevicePolicyManagerWrapper.from(context);
final PackageManagerWrapper pm = new PackageManagerWrapper(context.getPackageManager());
// Check if device has DPM capability. If it has and dpm is still null, then we
// treat this case with suspicion and bail out.
if (pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN) && dpm == null) {
return true;
}
boolean isConfigEligibleForLockdown = false;
if (dpm != null) {
final ComponentName deviceOwner = dpm.getDeviceOwnerComponentOnAnyUser();
if (deviceOwner != null) {
final int deviceOwnerUserId = dpm.getDeviceOwnerUserId();
try {
final int deviceOwnerUid = pm.getPackageUidAsUser(deviceOwner.getPackageName(),
deviceOwnerUserId);
isConfigEligibleForLockdown = deviceOwnerUid == config.creatorUid;
} catch (PackageManager.NameNotFoundException e) {
// don't care
}
}
}
if (!isConfigEligibleForLockdown) {
return false;
}
final ContentResolver resolver = context.getContentResolver();
final boolean isLockdownFeatureEnabled = Settings.Global.getInt(resolver,
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0) != 0;
return isLockdownFeatureEnabled;
}
}