diff options
author | Stuart Scott <stuartscott@google.com> | 2015-03-31 18:57:09 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-31 18:57:09 +0000 |
commit | bc695c770a6acd328135b0171d3d75ca6a5b7ce6 (patch) | |
tree | f33b2224494ff230719f7850fd717a03a9ab41b4 | |
parent | 25512e82a588cd6bd6e92da10a0b25601e42f2c2 (diff) | |
parent | 73281fbcfe38f74cd5177b8c2c7af42d58eec8e9 (diff) | |
download | packages_apps_Settings-bc695c770a6acd328135b0171d3d75ca6a5b7ce6.zip packages_apps_Settings-bc695c770a6acd328135b0171d3d75ca6a5b7ce6.tar.gz packages_apps_Settings-bc695c770a6acd328135b0171d3d75ca6a5b7ce6.tar.bz2 |
Merge "Move reset network settings into framework."
-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) |