OSDN Git Service

Change RecoverySystem#wipeEuiccData to public
authorQingxi Li <qingxi@google.com>
Tue, 9 Jan 2018 18:57:38 +0000 (10:57 -0800)
committerQingxi Li <qingxi@google.com>
Fri, 19 Jan 2018 20:23:53 +0000 (12:23 -0800)
This function is used to wipe the eSIM profiles from eUICC card which
should not only be called from FDR and also from the network reset. This
CL changes it to hide public API.

Bug: 62961867
Test: TBC
Change-Id: I1d716763720e9a2c897b9e85f95bab562fe150e2

core/java/android/os/RecoverySystem.java

index 673a8ba..57db9d1 100644 (file)
@@ -61,6 +61,7 @@ import java.util.HashSet;
 import java.util.Locale;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipInputStream;
@@ -101,6 +102,9 @@ public class RecoverySystem {
     private static final String ACTION_EUICC_FACTORY_RESET =
             "com.android.internal.action.EUICC_FACTORY_RESET";
 
+    /** used in {@link #wipeEuiccData} as package name of callback intent */
+    private static final String PACKAGE_NAME_WIPING_EUICC_DATA_CALLBACK = "android";
+
     /**
      * The recovery image uses this file to identify the location (i.e. blocks)
      * of an OTA package on the /data partition. The block map file is
@@ -751,7 +755,7 @@ public class RecoverySystem {
         // Block until the ordered broadcast has completed.
         condition.block();
 
-        wipeEuiccData(context, wipeEuicc);
+        wipeEuiccData(context, wipeEuicc, PACKAGE_NAME_WIPING_EUICC_DATA_CALLBACK);
 
         String shutdownArg = null;
         if (shutdown) {
@@ -767,19 +771,29 @@ public class RecoverySystem {
         bootCommand(context, shutdownArg, "--wipe_data", reasonArg, localeArg);
     }
 
-    private static void wipeEuiccData(Context context, final boolean isWipeEuicc) {
+    /**
+     * Returns whether wipe Euicc data successfully or not.
+     *
+     * @param isWipeEuicc whether we want to wipe Euicc data or not
+     * @param packageName the package name of the caller app.
+     *
+     * @hide
+     */
+    public static boolean wipeEuiccData(
+            Context context, final boolean isWipeEuicc, final String packageName) {
         ContentResolver cr = context.getContentResolver();
         if (Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) == 0) {
             // If the eUICC isn't provisioned, there's no reason to either wipe or retain profiles,
             // as there's nothing to wipe nor retain.
             Log.d(TAG, "Skipping eUICC wipe/retain as it is not provisioned");
-            return;
+            return true;
         }
 
         EuiccManager euiccManager = (EuiccManager) context.getSystemService(
                 Context.EUICC_SERVICE);
         if (euiccManager != null && euiccManager.isEnabled()) {
             CountDownLatch euiccFactoryResetLatch = new CountDownLatch(1);
+            final AtomicBoolean wipingSucceeded = new AtomicBoolean(false);
 
             BroadcastReceiver euiccWipeFinishReceiver = new BroadcastReceiver() {
                 @Override
@@ -801,6 +815,7 @@ public class RecoverySystem {
                             } else {
                                 Log.d(TAG, "Successfully retained euicc data.");
                             }
+                            wipingSucceeded.set(true /* newValue */);
                         }
                         euiccFactoryResetLatch.countDown();
                     }
@@ -808,7 +823,7 @@ public class RecoverySystem {
             };
 
             Intent intent = new Intent(ACTION_EUICC_FACTORY_RESET);
-            intent.setPackage("android");
+            intent.setPackage(packageName);
             PendingIntent callbackIntent = PendingIntent.getBroadcastAsUser(
                     context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, UserHandle.SYSTEM);
             IntentFilter filterConsent = new IntentFilter();
@@ -839,8 +854,8 @@ public class RecoverySystem {
                     } else {
                         Log.e(TAG, "Timeout retaining eUICC data.");
                     }
+                    return false;
                 }
-                context.getApplicationContext().unregisterReceiver(euiccWipeFinishReceiver);
             } catch (InterruptedException e) {
                 Thread.currentThread().interrupt();
                 if (isWipeEuicc) {
@@ -848,8 +863,13 @@ public class RecoverySystem {
                 } else {
                     Log.e(TAG, "Retaining eUICC data interrupted", e);
                 }
+                return false;
+            } finally {
+                context.getApplicationContext().unregisterReceiver(euiccWipeFinishReceiver);
             }
+            return wipingSucceeded.get();
         }
+        return false;
     }
 
     /** {@hide} */