Network Reset should have a lockdown like Factory Reset.
bug:20332322
Change-Id: I7c61a011d11e89513757f112abf320bb2a785edb
(cherry picked from commit 94b038bbb291431a7b39611d72f206b07e839891)
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index 1a79568..792d4ba 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -253,6 +253,7 @@
private final INetworkManagementService mNetworkManager;
private UsageStatsManagerInternal mUsageStats;
private final TrustedTime mTime;
+ private final UserManager mUserManager;
private IConnectivityManager mConnManager;
private INotificationManager mNotifManager;
@@ -336,6 +337,7 @@
mDeviceIdleController = IDeviceIdleController.Stub.asInterface(ServiceManager.getService(
DeviceIdleController.SERVICE_NAME));
mTime = checkNotNull(time, "missing TrustedTime");
+ mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
HandlerThread thread = new HandlerThread(TAG);
thread.start();
@@ -1986,7 +1988,6 @@
*/
void updateRulesForGlobalChangeLocked(boolean restrictedNetworksChanged) {
final PackageManager pm = mContext.getPackageManager();
- final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
// If we are in restrict power mode, we allow all important apps
// to have data access. Otherwise, we restrict data access to only
@@ -1996,7 +1997,7 @@
: ActivityManager.PROCESS_STATE_TOP;
// update rules for all installed applications
- final List<UserInfo> users = um.getUsers();
+ final List<UserInfo> users = mUserManager.getUsers();
final List<ApplicationInfo> apps = pm.getInstalledApplications(
PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
@@ -2353,6 +2354,10 @@
public void factoryReset(String subscriber) {
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+ if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
+ return;
+ }
+
// Turn mobile data limit off
NetworkPolicy[] policies = getNetworkPolicies(mContext.getOpPackageName());
NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriber);
@@ -2368,9 +2373,11 @@
// Turn restrict background data off
setRestrictBackground(false);
- // Remove app's "restrict background data" flag
- for (int uid : getUidsWithPolicy(POLICY_REJECT_METERED_BACKGROUND)) {
- setUidPolicy(uid, POLICY_NONE);
+ if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_APPS_CONTROL)) {
+ // Remove app's "restrict background data" flag
+ for (int uid : getUidsWithPolicy(POLICY_REJECT_METERED_BACKGROUND)) {
+ setUidPolicy(uid, POLICY_NONE);
+ }
}
}
}