diff options
author | Stuart Scott <stuartscott@google.com> | 2015-03-30 13:16:29 -0700 |
---|---|---|
committer | Stuart Scott <stuartscott@google.com> | 2015-03-30 18:00:41 -0700 |
commit | 73281fbcfe38f74cd5177b8c2c7af42d58eec8e9 (patch) | |
tree | 51136cc070d943107c0093d3a524b685c61f9587 /src/com/android/settings/ResetNetworkConfirm.java | |
parent | 701e55f4c0c2693f32bd95bd9b22441b5a0fb0d8 (diff) | |
download | packages_apps_Settings-73281fbcfe38f74cd5177b8c2c7af42d58eec8e9.zip packages_apps_Settings-73281fbcfe38f74cd5177b8c2c7af42d58eec8e9.tar.gz packages_apps_Settings-73281fbcfe38f74cd5177b8c2c7af42d58eec8e9.tar.bz2 |
Move reset network settings into framework.
bug: 16161518
Change-Id: I7d62201758e97bf08117183429a7acfa13b74994
Diffstat (limited to 'src/com/android/settings/ResetNetworkConfirm.java')
-rw-r--r-- | src/com/android/settings/ResetNetworkConfirm.java | 109 |
1 files changed, 17 insertions, 92 deletions
diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java index 9e5017e..1edc7a9 100644 --- a/src/com/android/settings/ResetNetworkConfirm.java +++ b/src/com/android/settings/ResetNetworkConfirm.java @@ -18,19 +18,12 @@ package com.android.settings; import android.app.Fragment; import android.content.Context; -import android.net.IConnectivityManager; -import android.net.NetworkPolicy; +import android.net.ConnectivityManager; import android.net.NetworkPolicyManager; -import android.net.NetworkTemplate; -import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Bundle; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; -import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -40,11 +33,7 @@ import android.widget.Spinner; import android.widget.Toast; import com.android.internal.logging.MetricsLogger; -import com.android.internal.net.VpnConfig; -import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; -import com.android.internal.telephony.PhoneFactory; -import com.android.settings.net.NetworkPolicyEditor; import java.util.ArrayList; import java.util.List; @@ -77,93 +66,29 @@ public class ResetNetworkConfirm extends InstrumentedFragment { } // TODO maybe show a progress dialog if this ends up taking a while - IConnectivityManager connectivityService = IConnectivityManager.Stub.asInterface( - ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); - WifiManager wifiManager = (WifiManager) - getActivity().getSystemService(Context.WIFI_SERVICE); - TelephonyManager telephonyManager = (TelephonyManager) - getActivity().getSystemService(Context.TELEPHONY_SERVICE); - NetworkPolicyManager policyManager = NetworkPolicyManager.from(getActivity()); - NetworkPolicyEditor policyEditor = new NetworkPolicyEditor(policyManager); - policyEditor.read(); - - // Turn airplane mode off - try { - connectivityService.setAirplaneMode(false); - } catch (RemoteException e) { - // Well, we tried - } - - // Turn wifi on - wifiManager.setWifiEnabled(true); - - // Delete all Wifi SSIDs - List<WifiConfiguration> networks = wifiManager.getConfiguredNetworks(); - if (networks != null) { - for (WifiConfiguration config : networks) { - wifiManager.removeNetwork(config.networkId); - } - wifiManager.saveConfiguration(); + ConnectivityManager connectivityManager = (ConnectivityManager) + getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivityManager != null) { + connectivityManager.factoryReset(); } - // Turn mobile hotspot off - wifiManager.setWifiApEnabled(null, false); - - // Un-tether - try { - for (String tether : connectivityService.getTetheredIfaces()) { - connectivityService.untether(tether); - } - } catch (RemoteException e) { - // Well, we tried + WifiManager wifiManager = (WifiManager) + getActivity().getSystemService(Context.WIFI_SERVICE); + if (wifiManager != null) { + wifiManager.factoryReset(); } - // Turn VPN off - try { - VpnConfig vpnConfig = connectivityService.getVpnConfig(); - if (vpnConfig != null) { - if (vpnConfig.legacy) { - connectivityService.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN); - } else { - // Prevent this app from initiating VPN connections in the future without - // user intervention. - connectivityService.setVpnPackageAuthorization(false); - connectivityService.prepareVpn(vpnConfig.user, VpnConfig.LEGACY_VPN); - } - } - } catch (RemoteException e) { - // Well, we tried + TelephonyManager telephonyManager = (TelephonyManager) + getActivity().getSystemService(Context.TELEPHONY_SERVICE); + if (telephonyManager != null) { + telephonyManager.factoryReset(mSubId); } - if (SubscriptionManager.isUsableSubIdValue(mSubId)) { - // Turn mobile data on - telephonyManager.setDataEnabled(mSubId, true); - - // Set mobile network selection mode to automatic - // TODO set network selection mode to automatic - // phone.setNetworkSelectionModeAutomatic(null); - - // Set preferred mobile network type to manufacturer's recommended - // int networkType = ; // TODO get manufacturer's default - // telephonyManager.setPreferredNetworkType(networkType); - - // Turn roaming to manufacturer's default - // boolean enabled = ; // TODO get manufacturer's default - // SubscriptionManager.from(getContext()).setDataRoaming(enabled, mSubId); - + NetworkPolicyManager policyManager = (NetworkPolicyManager) + getActivity().getSystemService(Context.NETWORK_POLICY_SERVICE); + if (policyManager != null) { String subscriberId = telephonyManager.getSubscriberId(mSubId); - NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId); - // Turn mobile data limit off - policyEditor.setPolicyLimitBytes(template, NetworkPolicy.LIMIT_DISABLED); - } - - // Turn restrict background data off - policyManager.setRestrictBackground(false); - - // Remove app's "restrict background data" flag - for (int uid : policyManager.getUidsWithPolicy( - NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND)) { - policyManager.setUidPolicy(uid, NetworkPolicyManager.POLICY_NONE); + policyManager.factoryReset(subscriberId); } Toast.makeText(getActivity(), R.string.reset_network_complete_toast, Toast.LENGTH_SHORT) |