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

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

Move factoryReset to service and protect.

bug:16161518
Change-Id: I02d1bbae1887c62ee426e6f03e8bc1f18c6666bf
parent 19f1faa3
Loading
Loading
Loading
Loading
+1 −23
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import android.telephony.SubscriptionManager;
import android.util.ArrayMap;
import android.util.Log;

import com.android.internal.net.VpnConfig;
import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.util.Protocol;
@@ -2515,30 +2514,9 @@ public class ConnectivityManager {
     * @hide
     */
    public void factoryReset() {
        // Turn airplane mode off
        setAirplaneMode(false);

        // Untether
        for (String tether : getTetheredIfaces()) {
            untether(tether);
        }

        // Turn VPN off
        try {
            VpnConfig vpnConfig = mService.getVpnConfig();
            if (vpnConfig != null) {
                if (vpnConfig.legacy) {
                    mService.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN);
                } else {
                    // Prevent this app from initiating VPN connections in the future without
                    // user intervention.
                    mService.setVpnPackageAuthorization(false);

                    mService.prepareVpn(vpnConfig.user, VpnConfig.LEGACY_VPN);
                }
            }
            mService.factoryReset();
        } catch (RemoteException e) {
            // Well, we tried
        }
    }

+2 −0
Original line number Diff line number Diff line
@@ -164,4 +164,6 @@ interface IConnectivityManager
    boolean addVpnAddress(String address, int prefixLength);
    boolean removeVpnAddress(String address, int prefixLength);
    boolean setUnderlyingNetworksForVpn(in Network[] networks);

    void factoryReset();
}
+2 −0
Original line number Diff line number Diff line
@@ -58,4 +58,6 @@ interface INetworkPolicyManager {

    NetworkQuotaInfo getNetworkQuotaInfo(in NetworkState state);
    boolean isNetworkMetered(in NetworkState state);

    void factoryReset(String subscriber);
}
+3 −18
Original line number Diff line number Diff line
@@ -187,24 +187,9 @@ public class NetworkPolicyManager {
     * @hide
     */
    public void factoryReset(String subscriber) {
        // Turn mobile data limit off
        NetworkPolicy[] policies = getNetworkPolicies();
        NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriber);
        for (NetworkPolicy policy : policies) {
            if (policy.template.equals(template)) {
                policy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
                policy.inferred = false;
                policy.clearSnooze();
            }
        }
        setNetworkPolicies(policies);

        // Turn restrict background data off
        setRestrictBackground(false);

        // Remove app's "restrict background data" flag
        for (int uid : getUidsWithPolicy(POLICY_REJECT_METERED_BACKGROUND)) {
            setUidPolicy(uid, NetworkPolicyManager.POLICY_NONE);
        try {
            mService.factoryReset(subscriber);
        } catch (RemoteException e) {
        }
    }

+26 −0
Original line number Diff line number Diff line
@@ -4444,4 +4444,30 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
        return success;
    }

    @Override
    public void factoryReset() {
        enforceConnectivityInternalPermission();
        // Turn airplane mode off
        setAirplaneMode(false);

        // Untether
        for (String tether : getTetheredIfaces()) {
            untether(tether);
        }

        // Turn VPN off
        VpnConfig vpnConfig = getVpnConfig();
        if (vpnConfig != null) {
            if (vpnConfig.legacy) {
                prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN);
            } else {
                // Prevent this app from initiating VPN connections in the future without
                // user intervention.
                setVpnPackageAuthorization(false);

                prepareVpn(vpnConfig.user, VpnConfig.LEGACY_VPN);
            }
        }
    }
}
Loading