Loading core/java/android/net/ConnectivityManager.java +33 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading core/java/android/net/NetworkPolicyManager.java +27 −0 Original line number Diff line number Diff line Loading @@ -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 Loading telephony/java/android/telephony/TelephonyManager.java +46 −5 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -3329,6 +3329,27 @@ public class TelephonyManager { return -1; } /** * 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. Loading @@ -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) { Loading @@ -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); } /** Loading Loading @@ -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); } } } telephony/java/com/android/internal/telephony/ITelephony.aidl +11 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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. Loading wifi/java/android/net/wifi/WifiManager.java +21 −0 Original line number Diff line number Diff line Loading @@ -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); } } Loading
core/java/android/net/ConnectivityManager.java +33 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading
core/java/android/net/NetworkPolicyManager.java +27 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
telephony/java/android/telephony/TelephonyManager.java +46 −5 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -3329,6 +3329,27 @@ public class TelephonyManager { return -1; } /** * 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. Loading @@ -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) { Loading @@ -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); } /** Loading Loading @@ -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); } } }
telephony/java/com/android/internal/telephony/ITelephony.aidl +11 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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. Loading
wifi/java/android/net/wifi/WifiManager.java +21 −0 Original line number Diff line number Diff line Loading @@ -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); } }