Move factoryReset to service and protect.

bug:16161518
Change-Id: I02d1bbae1887c62ee426e6f03e8bc1f18c6666bf
This commit is contained in:
Stuart Scott
2015-04-02 18:00:02 -07:00
parent 19f1faa376
commit f1fb39763d
10 changed files with 72 additions and 62 deletions

View File

@@ -40,7 +40,6 @@ 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;
@@ -2515,30 +2514,9 @@ public class ConnectivityManager {
* @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);
}
}
mService.factoryReset();
} catch (RemoteException e) {
// Well, we tried
}
}

View File

@@ -164,4 +164,6 @@ interface IConnectivityManager
boolean addVpnAddress(String address, int prefixLength);
boolean removeVpnAddress(String address, int prefixLength);
boolean setUnderlyingNetworksForVpn(in Network[] networks);
void factoryReset();
}

View File

@@ -58,4 +58,6 @@ interface INetworkPolicyManager {
NetworkQuotaInfo getNetworkQuotaInfo(in NetworkState state);
boolean isNetworkMetered(in NetworkState state);
void factoryReset(String subscriber);
}

View File

@@ -187,24 +187,9 @@ public class NetworkPolicyManager {
* @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);
try {
mService.factoryReset(subscriber);
} catch (RemoteException e) {
}
}

View File

@@ -4444,4 +4444,30 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
return success;
}
@Override
public void factoryReset() {
enforceConnectivityInternalPermission();
// Turn airplane mode off
setAirplaneMode(false);
// Untether
for (String tether : getTetheredIfaces()) {
untether(tether);
}
// Turn VPN off
VpnConfig vpnConfig = getVpnConfig();
if (vpnConfig != null) {
if (vpnConfig.legacy) {
prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN);
} else {
// Prevent this app from initiating VPN connections in the future without
// user intervention.
setVpnPackageAuthorization(false);
prepareVpn(vpnConfig.user, VpnConfig.LEGACY_VPN);
}
}
}
}

View File

@@ -2301,4 +2301,29 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
fout.print("]");
}
@Override
public void factoryReset(String subscriber) {
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
// 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, POLICY_NONE);
}
}
}

View File

@@ -4550,15 +4550,12 @@ public class TelephonyManager {
* @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);
try {
Log.d(TAG, "factoryReset: subId=" + subId);
ITelephony telephony = getITelephony();
if (telephony != null)
telephony.factoryReset(subId);
} catch (RemoteException e) {
}
}
}

View File

@@ -942,4 +942,6 @@ interface ITelephony {
* Returns the subscription ID associated with the specified PhoneAccount.
*/
int getSubIdForPhoneAccount(in PhoneAccount phoneAccount);
void factoryReset(int subId);
}

View File

@@ -166,5 +166,7 @@ interface IWifiManager
WifiConnectionStatistics getConnectionStatistics();
void disableEphemeralNetwork(String SSID);
void factoryReset();
}

View File

@@ -2791,18 +2791,9 @@ public class WifiManager {
* @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();
try {
mService.factoryReset();
} catch (RemoteException e) {
}
// Turn mobile hotspot off
setWifiApEnabled(null, false);
}
}