diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index a0e2bf8a76821..3abccbcb73b12 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; @@ -2446,6 +2447,38 @@ public class ConnectivityManager { } catch (RemoteException e) {} } + /** + * 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 diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java index a8e7757c2e8f1..a7ffee924bbff 100644 --- a/core/java/android/net/NetworkPolicyManager.java +++ b/core/java/android/net/NetworkPolicyManager.java @@ -179,6 +179,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 diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index fbc70db2ef133..6bc6de63ba67b 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -3316,11 +3316,11 @@ public class TelephonyManager { * @return the preferred network type, defined in RILConstants.java. * @hide */ - public int getPreferredNetworkType() { + public int getPreferredNetworkType(int subId) { try { ITelephony telephony = getITelephony(); if (telephony != null) - return telephony.getPreferredNetworkType(); + return telephony.getPreferredNetworkType(subId); } catch (RemoteException ex) { Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); } catch (NullPointerException ex) { @@ -3329,6 +3329,27 @@ public class TelephonyManager { return -1; } + /** + * Sets the network selection mode to automatic. + *
+ * Requires Permission:
+ * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
+ * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
+ *
+ * @hide
+ */
+ public void setNetworkSelectionModeAutomatic(int subId) {
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null)
+ telephony.setNetworkSelectionModeAutomatic(subId);
+ } catch (RemoteException ex) {
+ Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex);
+ } catch (NullPointerException ex) {
+ Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex);
+ }
+ }
+
/**
* Set the preferred network type.
* Used for device configuration by some CDMA operators.
@@ -3337,15 +3358,16 @@ public class TelephonyManager {
* {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
* Or the calling app has carrier privileges. @see #hasCarrierPrivileges
*
+ * @param subId the id of the subscription to set the preferred network type for.
* @param networkType the preferred network type, defined in RILConstants.java.
* @return true on success; false on any failure.
* @hide
*/
- public boolean setPreferredNetworkType(int networkType) {
+ public boolean setPreferredNetworkType(int subId, int networkType) {
try {
ITelephony telephony = getITelephony();
if (telephony != null)
- return telephony.setPreferredNetworkType(networkType);
+ return telephony.setPreferredNetworkType(subId, networkType);
} catch (RemoteException ex) {
Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex);
} catch (NullPointerException ex) {
@@ -3364,7 +3386,8 @@ public class TelephonyManager {
* @return true on success; false on any failure.
*/
public boolean setPreferredNetworkTypeToGlobal() {
- return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
+ return setPreferredNetworkType(getDefaultSubscription(),
+ RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
}
/**
@@ -4448,4 +4471,22 @@ public class TelephonyManager {
return retval;
}
+
+ /**
+ * Resets telephony manager settings back to factory defaults.
+ *
+ * @hide
+ */
+ public void factoryReset(int subId) {
+ if (SubscriptionManager.isUsableSubIdValue(subId)) {
+ // Enable data
+ setDataEnabled(subId, true);
+ // Set network selection mode to automatic
+ setNetworkSelectionModeAutomatic(subId);
+ // Set preferred mobile network type to the best available
+ setPreferredNetworkType(subId, RILConstants.PREFERRED_NETWORK_MODE);
+ // Turn off roaming
+ SubscriptionManager.from(mContext).setDataRoaming(0, subId);
+ }
+ }
}
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index c18e3b69d3ac6..a24859b2820a5 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -653,9 +653,10 @@ interface ITelephony {
* Get the preferred network type.
* Used for device configuration by some CDMA operators.
*
+ * @param subId the id of the subscription to query.
* @return the preferred network type, defined in RILConstants.java.
*/
- int getPreferredNetworkType();
+ int getPreferredNetworkType(int subId);
/**
* Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
@@ -666,14 +667,22 @@ interface ITelephony {
*/
int getTetherApnRequired();
+ /**
+ * Set the network selection mode to automatic.
+ *
+ * @param subId the id of the subscription to update.
+ */
+ void setNetworkSelectionModeAutomatic(int subId);
+
/**
* Set the preferred network type.
* Used for device configuration by some CDMA operators.
*
+ * @param subId the id of the subscription to update.
* @param networkType the preferred network type, defined in RILConstants.java.
* @return true on success; false on any failure.
*/
- boolean setPreferredNetworkType(int networkType);
+ boolean setPreferredNetworkType(int subId, int networkType);
/**
* User enable/disable Mobile Data.
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index e1460efb58c22..6371891f7948d 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -2621,4 +2621,25 @@ public class WifiManager {
}
return false;
}
+
+ /**
+ * Resets all wifi manager settings back to factory defaults.
+ *
+ * @hide
+ */
+ public void factoryReset() {
+ // Enable wifi
+ setWifiEnabled(true);
+ // Delete all Wifi SSIDs
+ List