diff options
author | Stuart Scott <stuartscott@google.com> | 2015-03-31 18:57:54 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-31 18:57:58 +0000 |
commit | edd33c8bdf0ac9e108a34d8af5941df5c3e2b537 (patch) | |
tree | 2998a1f15bf5bf989af5f7541e71d1f522d7fbfc /core/java/android/net | |
parent | 3580cd0b5223837597cdc714180158495a866aa4 (diff) | |
parent | 984dc850b4caeb4470e52bce773935be5305cf8e (diff) | |
download | frameworks_base-edd33c8bdf0ac9e108a34d8af5941df5c3e2b537.zip frameworks_base-edd33c8bdf0ac9e108a34d8af5941df5c3e2b537.tar.gz frameworks_base-edd33c8bdf0ac9e108a34d8af5941df5c3e2b537.tar.bz2 |
Merge "Move reset network settings into framework."
Diffstat (limited to 'core/java/android/net')
-rw-r--r-- | core/java/android/net/ConnectivityManager.java | 33 | ||||
-rw-r--r-- | core/java/android/net/NetworkPolicyManager.java | 27 |
2 files changed, 60 insertions, 0 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index a0e2bf8..3abccbc 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -40,6 +40,7 @@ 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; @@ -2447,6 +2448,38 @@ public class ConnectivityManager { } /** + * Resets all connectivity manager settings back to factory defaults. + * @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); + } + } + } catch (RemoteException e) { + // Well, we tried + } + } + + /** * Binds the current process to {@code network}. All Sockets created in the future * (and not explicitly bound via a bound SocketFactory from * {@link Network#getSocketFactory() Network.getSocketFactory()}) will be bound to diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java index a8e7757..a7ffee9 100644 --- a/core/java/android/net/NetworkPolicyManager.java +++ b/core/java/android/net/NetworkPolicyManager.java @@ -180,6 +180,33 @@ public class NetworkPolicyManager { } /** + * Resets network policy settings back to factory defaults. + * + * @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); + } + } + + /** * Compute the last cycle boundary for the given {@link NetworkPolicy}. For * example, if cycle day is 20th, and today is June 15th, it will return May * 20th. When cycle day doesn't exist in current month, it snaps to the 1st |