From 73281fbcfe38f74cd5177b8c2c7af42d58eec8e9 Mon Sep 17 00:00:00 2001 From: Stuart Scott Date: Mon, 30 Mar 2015 13:16:29 -0700 Subject: [PATCH] Move reset network settings into framework. bug: 16161518 Change-Id: I7d62201758e97bf08117183429a7acfa13b74994 --- .../android/settings/ResetNetworkConfirm.java | 109 +++--------------- 1 file changed, 17 insertions(+), 92 deletions(-) diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java index 9e5017e47b9..1edc7a931a0 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)); + ConnectivityManager connectivityManager = (ConnectivityManager) + getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivityManager != null) { + connectivityManager.factoryReset(); + } + WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); + if (wifiManager != null) { + wifiManager.factoryReset(); + } + 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 + if (telephonyManager != null) { + telephonyManager.factoryReset(mSubId); } - // Turn wifi on - wifiManager.setWifiEnabled(true); - - // Delete all Wifi SSIDs - List networks = wifiManager.getConfiguredNetworks(); - if (networks != null) { - for (WifiConfiguration config : networks) { - wifiManager.removeNetwork(config.networkId); - } - wifiManager.saveConfiguration(); - } - - // 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 - } - - // 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 - } - - 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)