Merge "Move factoryReset to service and protect."
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index c040410..c6ba22f 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -1419,6 +1419,12 @@
                 null);
     }
 
+    private void enforceConnectivityInternalPermission() {
+        mApp.enforceCallingOrSelfPermission(
+                android.Manifest.permission.CONNECTIVITY_INTERNAL,
+                "ConnectivityService");
+    }
+
     private String createTelUrl(String number) {
         if (TextUtils.isEmpty(number)) {
             return null;
@@ -2358,4 +2364,19 @@
 
         return true;
     }
+
+    @Override
+    public void factoryReset(int subId) {
+        enforceConnectivityInternalPermission();
+        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, Phone.PREFERRED_NT_MODE);
+            // Turn off roaming
+            SubscriptionManager.from(mApp).setDataRoaming(0, subId);
+        }
+    }
 }