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:
@@ -21,13 +21,9 @@ import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
|
||||
import android.annotation.NonNull;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
@@ -491,7 +487,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
WifiConfiguration config = mSelectedAccessPoint.getConfig();
|
||||
// Some configs are ineditable
|
||||
if (isEditabilityLockedDown(getActivity(), config)) {
|
||||
if (WifiUtils.isNetworkLockedDown(getActivity(), config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -594,7 +590,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
private void showDialog(AccessPoint accessPoint, int dialogMode) {
|
||||
if (accessPoint != null) {
|
||||
WifiConfiguration config = accessPoint.getConfig();
|
||||
if (isEditabilityLockedDown(getActivity(), config) && accessPoint.isActive()) {
|
||||
if (WifiUtils.isNetworkLockedDown(getActivity(), config) && accessPoint.isActive()) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(),
|
||||
RestrictedLockUtils.getDeviceOwner(getActivity()));
|
||||
return;
|
||||
@@ -1120,62 +1116,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the config is not editable through Settings.
|
||||
* @param context Context of caller
|
||||
* @param config The WiFi config.
|
||||
* @return true if the config is not editable through Settings.
|
||||
*/
|
||||
public static boolean isEditabilityLockedDown(Context context, WifiConfiguration config) {
|
||||
return !canModifyNetwork(context, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is a stripped version of WifiConfigStore.canModifyNetwork.
|
||||
* TODO: refactor to have only one method.
|
||||
* @param context Context of caller
|
||||
* @param config The WiFi config.
|
||||
* @return true if Settings can modify the config.
|
||||
*/
|
||||
static boolean canModifyNetwork(Context context, WifiConfiguration config) {
|
||||
if (config == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
|
||||
Context.DEVICE_POLICY_SERVICE);
|
||||
|
||||
// Check if device has DPM capability. If it has and dpm is still null, then we
|
||||
// treat this case with suspicion and bail out.
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
if (pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN) && dpm == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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 (NameNotFoundException e) {
|
||||
// don't care
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isConfigEligibleForLockdown) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
final boolean isLockdownFeatureEnabled = Settings.Global.getInt(resolver,
|
||||
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0) != 0;
|
||||
return !isLockdownFeatureEnabled;
|
||||
}
|
||||
|
||||
private static class SummaryProvider
|
||||
implements SummaryLoader.SummaryProvider, OnSummaryChangeListener {
|
||||
|
||||
|
Reference in New Issue
Block a user