diff options
-rw-r--r-- | core/java/android/net/ConnectivityManager.java | 33 | ||||
-rw-r--r-- | core/java/android/net/NetworkPolicyManager.java | 27 | ||||
-rw-r--r-- | telephony/java/android/telephony/TelephonyManager.java | 51 | ||||
-rw-r--r-- | telephony/java/com/android/internal/telephony/ITelephony.aidl | 13 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 21 |
5 files changed, 138 insertions, 7 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 diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index fbc70db..6bc6de63 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) { @@ -3330,6 +3330,27 @@ public class TelephonyManager { } /** + * Sets the network selection mode to automatic. + * <p> + * 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. * <p> @@ -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 c18e3b6..a24859b 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 @@ -667,13 +668,21 @@ 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 e1460ef..6371891 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<WifiConfiguration> networks = getConfiguredNetworks(); + if (networks != null) { + for (WifiConfiguration config : networks) { + removeNetwork(config.networkId); + } + saveConfiguration(); + } + + // Turn mobile hotspot off + setWifiApEnabled(null, false); + } } |