Move reset network settings into framework.
bug: 16161518 Change-Id: I7d62201758e97bf08117183429a7acfa13b74994
This commit is contained in:
@@ -18,19 +18,12 @@ package com.android.settings;
|
|||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.IConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkPolicy;
|
|
||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.NetworkTemplate;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.telephony.SubscriptionInfo;
|
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -40,11 +33,7 @@ import android.widget.Spinner;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsLogger;
|
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.PhoneConstants;
|
||||||
import com.android.internal.telephony.PhoneFactory;
|
|
||||||
import com.android.settings.net.NetworkPolicyEditor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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
|
// TODO maybe show a progress dialog if this ends up taking a while
|
||||||
|
|
||||||
IConnectivityManager connectivityService = IConnectivityManager.Stub.asInterface(
|
ConnectivityManager connectivityManager = (ConnectivityManager)
|
||||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (connectivityManager != null) {
|
||||||
|
connectivityManager.factoryReset();
|
||||||
|
}
|
||||||
|
|
||||||
WifiManager wifiManager = (WifiManager)
|
WifiManager wifiManager = (WifiManager)
|
||||||
getActivity().getSystemService(Context.WIFI_SERVICE);
|
getActivity().getSystemService(Context.WIFI_SERVICE);
|
||||||
|
if (wifiManager != null) {
|
||||||
|
wifiManager.factoryReset();
|
||||||
|
}
|
||||||
|
|
||||||
TelephonyManager telephonyManager = (TelephonyManager)
|
TelephonyManager telephonyManager = (TelephonyManager)
|
||||||
getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
NetworkPolicyManager policyManager = NetworkPolicyManager.from(getActivity());
|
if (telephonyManager != null) {
|
||||||
NetworkPolicyEditor policyEditor = new NetworkPolicyEditor(policyManager);
|
telephonyManager.factoryReset(mSubId);
|
||||||
policyEditor.read();
|
|
||||||
|
|
||||||
// Turn airplane mode off
|
|
||||||
try {
|
|
||||||
connectivityService.setAirplaneMode(false);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
// Well, we tried
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn wifi on
|
NetworkPolicyManager policyManager = (NetworkPolicyManager)
|
||||||
wifiManager.setWifiEnabled(true);
|
getActivity().getSystemService(Context.NETWORK_POLICY_SERVICE);
|
||||||
|
if (policyManager != null) {
|
||||||
// Delete all Wifi SSIDs
|
|
||||||
List<WifiConfiguration> 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);
|
|
||||||
|
|
||||||
String subscriberId = telephonyManager.getSubscriberId(mSubId);
|
String subscriberId = telephonyManager.getSubscriberId(mSubId);
|
||||||
NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);
|
policyManager.factoryReset(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(getActivity(), R.string.reset_network_complete_toast, Toast.LENGTH_SHORT)
|
Toast.makeText(getActivity(), R.string.reset_network_complete_toast, Toast.LENGTH_SHORT)
|
||||||
|
Reference in New Issue
Block a user