Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3e314df authored by Stuart Scott's avatar Stuart Scott
Browse files

Network Reset should have a lockdown like Factory Reset.

bug:20332322
Change-Id: I7c61a011d11e89513757f112abf320bb2a785edb
(cherry picked from commit 94b038bb)
parent 540d0e0d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23629,6 +23629,7 @@ package android.os {
    field public static final java.lang.String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
    field public static final java.lang.String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
    field public static final java.lang.String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
    field public static final java.lang.String DISALLOW_NETWORK_RESET = "no_network_reset";
    field public static final java.lang.String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
    field public static final java.lang.String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
    field public static final java.lang.String DISALLOW_REMOVE_USER = "no_remove_user";
+1 −0
Original line number Diff line number Diff line
@@ -25552,6 +25552,7 @@ package android.os {
    field public static final java.lang.String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
    field public static final java.lang.String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
    field public static final java.lang.String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media";
    field public static final java.lang.String DISALLOW_NETWORK_RESET = "no_network_reset";
    field public static final java.lang.String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam";
    field public static final java.lang.String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls";
    field public static final java.lang.String DISALLOW_REMOVE_USER = "no_remove_user";
+14 −0
Original line number Diff line number Diff line
@@ -199,6 +199,20 @@ public class UserManager {
     */
    public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering";

    /**
     * Specifies if a user is disallowed from resetting network settings
     * from Settings. This can only be set by device owners and profile owners on the primary user.
     * The default value is <code>false</code>.
     * <p/>This restriction has no effect on secondary users and managed profiles since only the
     * primary user can reset the network settings of the device.
     *
     * <p/>Key for user restrictions.
     * <p/>Type: Boolean
     * @see #setUserRestrictions(Bundle)
     * @see #getUserRestrictions()
     */
    public static final String DISALLOW_NETWORK_RESET = "no_network_reset";

    /**
     * Specifies if a user is disallowed from factory resetting
     * from Settings. This can only be set by device owners and profile owners on the primary user.
+22 −13
Original line number Diff line number Diff line
@@ -4603,16 +4603,24 @@ public class ConnectivityService extends IConnectivityManager.Stub
    @Override
    public void factoryReset() {
        enforceConnectivityInternalPermission();

        if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
            return;
        }

        final int userId = UserHandle.getCallingUserId();

        // Turn airplane mode off
        setAirplaneMode(false);

        if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
            // Untether
            for (String tether : getTetheredIfaces()) {
                untether(tether);
            }
        }

        if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
            // Turn VPN off
            VpnConfig vpnConfig = getVpnConfig(userId);
            if (vpnConfig != null) {
@@ -4628,3 +4636,4 @@ public class ConnectivityService extends IConnectivityManager.Stub
            }
        }
    }
}
+12 −5
Original line number Diff line number Diff line
@@ -253,6 +253,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub
    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 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub
        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 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub
     */
    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 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub
                : 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 class NetworkPolicyManagerService extends INetworkPolicyManager.Stub
    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 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub
        // Turn restrict background data off
        setRestrictBackground(false);

        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);
            }
        }
    }
}
Loading