summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Felipe Leme <felipeal@google.com> 2020-12-01 11:12:47 -0800
committer Felipe Leme <felipeal@google.com> 2020-12-14 19:26:50 -0800
commitf8dcca3c3ede6155d9e2c5293075b71ff6a316b1 (patch)
tree3aca024498cf39a2943a7b64aba68cac79d0dd2e
parenta3c423c3fd6520dafb721d94a240a9eb866c60ca (diff)
Introducing FactoryResetter, a single entry point for factory reset calls.
The new class has options to wipe external storage and factory reset proctection, so it can be a single entry point from both DPM.wipeData() and the ManagedProvisioning app, which in turn will make it easier to postpone these operations on automotive when the vehicle is moving. Test: atest FrameworksServicesTests:DevicePolicyManagerTest \ FrameworksMockingServicesTests:FactoryResetterTest Test: adb shell dumpsys activity service --user 0 com.afwsamples.testdpc wipe-data 7 Bug: 171603586 Bug: 175392542 Fixes: 172697975 Change-Id: I37d5f8c59645459e48620047261ffd06d90ac2be
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java17
-rw-r--r--core/java/android/app/admin/IDevicePolicyManager.aidl2
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java56
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/FactoryResetter.java82
-rw-r--r--services/tests/mockingservicestests/Android.bp1
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/devicepolicy/FactoryResetterTest.java228
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java6
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java28
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java3
9 files changed, 380 insertions, 43 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 94084b851ae0..a1c644a4e474 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -12675,4 +12675,21 @@ public class DevicePolicyManager {
}
}
}
+
+ // TODO(b/175392542): remove if not needed by ManagedProvisioning app anymore
+ /**
+ * Used by ManagedProvisioning app to factory reset the device when DO cannto be provisioned.
+ *
+ * @hide
+ */
+ @RequiresPermission(android.Manifest.permission.MASTER_CLEAR)
+ public void factoryReset(String reason) {
+ if (mService != null) {
+ try {
+ mService.factoryReset(reason);
+ } catch (RemoteException re) {
+ throw re.rethrowFromSystemServer();
+ }
+ }
+ }
}
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index bcc90f79d629..a81b506a9a42 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -488,4 +488,6 @@ interface IDevicePolicyManager {
boolean canProfileOwnerResetPasswordWhenLocked(int userId);
void setNextOperationSafety(int operation, boolean safe);
+ // TODO(b/175392542): remove if not needed by ManagedProvisioning app anymore
+ void factoryReset(String reason);
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 8c66137b9b10..a27e6b20c221 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -215,7 +215,6 @@ import android.os.PersistableBundle;
import android.os.PowerManager;
import android.os.PowerManagerInternal;
import android.os.Process;
-import android.os.RecoverySystem;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.ResultReceiver;
@@ -245,7 +244,6 @@ import android.security.keymaster.KeymasterCertificateChain;
import android.security.keystore.AttestationUtils;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.ParcelableKeyGenParameterSpec;
-import android.service.persistentdata.PersistentDataBlockManager;
import android.stats.devicepolicy.DevicePolicyEnums;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
@@ -1026,6 +1024,25 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
mSafetyChecker = new OneTimeSafetyChecker(this, operation, safe);
}
+ // TODO(b/175392542): remove if not needed by ManagedProvisioning app anymore
+ @Override
+ public void factoryReset(String reason) {
+ Preconditions.checkCallAuthorization(
+ hasCallingOrSelfPermission(permission.MASTER_CLEAR));
+ Slog.w(LOG_TAG, "factoryReset(): " + reason);
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ FactoryResetter.factoryReset(mContext, /* shutdown= */ false, reason,
+ /* force= */ false, /* wipeEuicc= */ false, /* wipeAdoptableStorage= */ false,
+ /* wipeFactoryResetProtection= */ false);
+ } catch (IOException e) {
+ // Shouldn't happen.
+ Slog.wtf(LOG_TAG, "Could not factory reset", e);
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ }
+
/**
* Unit test will subclass it to inject mocks.
*/
@@ -1276,8 +1293,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
void recoverySystemRebootWipeUserData(boolean shutdown, String reason, boolean force,
- boolean wipeEuicc) throws IOException {
- RecoverySystem.rebootWipeUserData(mContext, shutdown, reason, force, wipeEuicc);
+ boolean wipeEuicc, boolean wipeExtRequested, boolean wipeResetProtectionData)
+ throws IOException {
+ FactoryResetter.factoryReset(mContext, shutdown, reason, force, wipeEuicc,
+ wipeExtRequested, wipeResetProtectionData);
}
boolean systemPropertiesGetBoolean(String key, boolean def) {
@@ -6073,17 +6092,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
caller.getUserId()));
}
- private void forceWipeDeviceNoLock(boolean wipeExtRequested, String reason, boolean wipeEuicc) {
+ private void forceWipeDeviceNoLock(boolean wipeExtRequested, String reason, boolean wipeEuicc,
+ boolean wipeResetProtectionData) {
wtfIfInLock();
boolean success = false;
try {
- if (wipeExtRequested) {
- StorageManager sm = (StorageManager) mContext.getSystemService(
- Context.STORAGE_SERVICE);
- sm.wipeAdoptableDisks();
- }
mInjector.recoverySystemRebootWipeUserData(
- /*shutdown=*/ false, reason, /*force=*/ true, /*wipeEuicc=*/ wipeEuicc);
+ /* shutdown= */ false, reason, /* force= */ true, /* wipeEuicc= */ wipeEuicc,
+ wipeExtRequested, wipeResetProtectionData);
success = true;
} catch (IOException | SecurityException e) {
Slog.w(LOG_TAG, "Failed requesting data wipe", e);
@@ -6230,22 +6246,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
+ " restriction is set for user " + userId);
}
- if ((flags & WIPE_RESET_PROTECTION_DATA) != 0) {
- PersistentDataBlockManager manager = (PersistentDataBlockManager)
- mContext.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
- if (manager != null) {
- manager.wipe();
- }
- }
-
- // TODO If split user is enabled and the device owner is set in the primary user
- // (rather than system), we should probably trigger factory reset. Current code just
- // removes that user (but still clears FRP...)
if (userId == UserHandle.USER_SYSTEM) {
- forceWipeDeviceNoLock(/*wipeExtRequested=*/ (
- flags & WIPE_EXTERNAL_STORAGE) != 0,
+ forceWipeDeviceNoLock(
+ (flags & WIPE_EXTERNAL_STORAGE) != 0,
internalReason,
- /*wipeEuicc=*/ (flags & WIPE_EUICC) != 0);
+ (flags & WIPE_EUICC) != 0,
+ (flags & WIPE_RESET_PROTECTION_DATA) != 0);
} else {
forceWipeUser(userId, wipeReasonForUser, (flags & WIPE_SILENTLY) != 0);
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/FactoryResetter.java b/services/devicepolicy/java/com/android/server/devicepolicy/FactoryResetter.java
new file mode 100644
index 000000000000..1ee6f8f83428
--- /dev/null
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/FactoryResetter.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.devicepolicy;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.RecoverySystem;
+import android.os.UserManager;
+import android.os.storage.StorageManager;
+import android.service.persistentdata.PersistentDataBlockManager;
+import android.util.Log;
+
+import com.android.internal.util.Preconditions;
+
+import java.io.IOException;
+
+/**
+ * Entry point for "factory reset" requests.
+ */
+final class FactoryResetter {
+
+ private static final String TAG = FactoryResetter.class.getSimpleName();
+
+ // TODO(b/171603586): use an object that's constructed with a Builder instead (then update
+ // javadoc)
+ /**
+ * Factory reset the device.
+ */
+ public static void factoryReset(Context context, boolean shutdown, String reason,
+ boolean force, boolean wipeEuicc, boolean wipeAdoptableStorage,
+ boolean wipeFactoryResetProtection) throws IOException {
+ Log.i(TAG, "factoryReset(): shutdown=" + shutdown + ", force=" + force
+ + ", wipeEuicc=" + wipeEuicc + ", wipeAdoptableStorage=" + wipeAdoptableStorage
+ + ", wipeFRP=" + wipeFactoryResetProtection);
+
+ Preconditions.checkCallAuthorization(context.checkCallingOrSelfPermission(
+ android.Manifest.permission.MASTER_CLEAR) == PackageManager.PERMISSION_GRANTED);
+
+ UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ if (!force && um.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)) {
+ throw new SecurityException("Factory reset is not allowed for this user.");
+ }
+
+ if (wipeFactoryResetProtection) {
+ PersistentDataBlockManager manager = (PersistentDataBlockManager)
+ context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
+ if (manager != null) {
+ Log.w(TAG, "Wiping factory reset protection");
+ manager.wipe();
+ } else {
+ Log.w(TAG, "No need to wipe factory reset protection");
+ }
+ }
+
+ if (wipeAdoptableStorage) {
+ Log.w(TAG, "Wiping adoptable storage");
+ StorageManager sm = (StorageManager) context.getSystemService(
+ Context.STORAGE_SERVICE);
+ sm.wipeAdoptableDisks();
+ }
+
+ RecoverySystem.rebootWipeUserData(context, shutdown, reason, force, wipeEuicc);
+ }
+
+ private FactoryResetter() {
+ throw new UnsupportedOperationException("Contains only static methods");
+ }
+}
diff --git a/services/tests/mockingservicestests/Android.bp b/services/tests/mockingservicestests/Android.bp
index 03083c1f00b2..7c935d532f22 100644
--- a/services/tests/mockingservicestests/Android.bp
+++ b/services/tests/mockingservicestests/Android.bp
@@ -19,6 +19,7 @@ android_test {
static_libs: [
"services.core",
+ "services.devicepolicy",
"services.net",
"services.usage",
"service-jobscheduler",
diff --git a/services/tests/mockingservicestests/src/com/android/server/devicepolicy/FactoryResetterTest.java b/services/tests/mockingservicestests/src/com/android/server/devicepolicy/FactoryResetterTest.java
new file mode 100644
index 000000000000..45160dc4c1d7
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/devicepolicy/FactoryResetterTest.java
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.devicepolicy;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertThrows;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.RecoverySystem;
+import android.os.UserManager;
+import android.os.storage.StorageManager;
+import android.platform.test.annotations.Presubmit;
+import android.service.persistentdata.PersistentDataBlockManager;
+import android.util.Log;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoSession;
+import org.mockito.quality.Strictness;
+
+/**
+ * Run it as {@code atest FrameworksMockingCoreTests:FactoryResetterTest}
+ */
+@Presubmit
+public final class FactoryResetterTest {
+
+ private static final String TAG = FactoryResetterTest.class.getSimpleName();
+
+ // Fixed parameters
+ private static final String REASON = "self-destruct";
+ private static final boolean SHUTDOWN = true;
+ private static final boolean WIPE_EUICC = true;
+
+ // Parameters under test
+ private static final boolean FORCE = true;
+ private static final boolean NO_FORCE = false;
+ private static final boolean WIPE_ADOPTABLE_STORAGE = true;
+ private static final boolean NO_WIPE_ADOPTABLE_STORAGE = false;
+ private static final boolean WIPE_FACTORY_RESET_PROTECTION = true;
+ private static final boolean NO_WIPE_FACTORY_RESET_PROTECTION = false;
+
+ private MockitoSession mSession;
+
+ private @Mock Context mContext;
+ private @Mock StorageManager mSm;
+ private @Mock PersistentDataBlockManager mPdbm;
+ private @Mock UserManager mUm;
+
+ @Before
+ public void startSession() {
+ mSession = mockitoSession()
+ .initMocks(this)
+ .spyStatic(RecoverySystem.class)
+ .strictness(Strictness.LENIENT)
+ .startMocking();
+
+ when(mContext.getSystemService(any(String.class))).thenAnswer((inv) -> {
+ Log.d(TAG, "Mocking " + inv);
+ String service = (String) inv.getArguments()[0];
+ switch (service) {
+ case Context.PERSISTENT_DATA_BLOCK_SERVICE:
+ return mPdbm;
+ case Context.STORAGE_SERVICE:
+ return mSm;
+ case Context.USER_SERVICE:
+ return mUm;
+ default:
+ throw new IllegalArgumentException("Not expecting call for " + service);
+ }
+ });
+
+ doAnswer((inv) -> {
+ Log.d(TAG, "Mocking " + inv);
+ return null;
+ }).when(() -> RecoverySystem.rebootWipeUserData(any(), anyBoolean(), any(),
+ anyBoolean(), anyBoolean()));
+ }
+
+ @After
+ public void finishSession() {
+ if (mSession == null) {
+ Log.w(TAG, "finishSession(): no session");
+ return;
+ }
+ mSession.finishMocking();
+ }
+
+ @Test
+ public void testFactoryReset_noMasterClearPermission() throws Exception {
+ revokeMasterClearPermission();
+ setFactoryResetRestriction(/* allowed= */ true);
+
+ assertThrows(SecurityException.class,
+ () -> FactoryResetter.factoryReset(mContext, SHUTDOWN, REASON, NO_FORCE,
+ WIPE_EUICC, WIPE_ADOPTABLE_STORAGE, WIPE_FACTORY_RESET_PROTECTION));
+
+ verifyWipeAdoptableStorageNotCalled();
+ verifyWipeFactoryResetProtectionNotCalled();
+ verifyRebootWipeUserDataNotCalled();
+ }
+
+ @Test
+ public void testFactoryReset_noForceDisallowed()
+ throws Exception {
+ setFactoryResetRestriction(/* allowed= */ false);
+
+ assertThrows(SecurityException.class,
+ () -> FactoryResetter.factoryReset(mContext, SHUTDOWN, REASON, NO_FORCE,
+ WIPE_EUICC, WIPE_ADOPTABLE_STORAGE, WIPE_FACTORY_RESET_PROTECTION));
+
+ verifyWipeAdoptableStorageNotCalled();
+ verifyWipeFactoryResetProtectionNotCalled();
+ verifyRebootWipeUserDataNotCalled();
+ }
+
+ @Test
+ public void testFactoryReset_noForceAllowed() throws Exception {
+ setFactoryResetRestriction(/* allowed= */ true);
+
+ FactoryResetter.factoryReset(mContext, SHUTDOWN, REASON, NO_FORCE,
+ WIPE_EUICC, WIPE_ADOPTABLE_STORAGE, WIPE_FACTORY_RESET_PROTECTION);
+
+ verifyWipeAdoptableStorageCalled();
+ verifyWipeFactoryResetProtectionCalled();
+ verifyRebootWipeUserDataCalled(NO_FORCE);
+ }
+
+ @Test
+ public void testFactoryReset_forceDisallowed() throws Exception {
+ setFactoryResetRestriction(/* allowed= */ false);
+
+ FactoryResetter.factoryReset(mContext, SHUTDOWN, REASON, FORCE,
+ WIPE_EUICC, WIPE_ADOPTABLE_STORAGE, WIPE_FACTORY_RESET_PROTECTION);
+
+ verifyWipeAdoptableStorageCalled();
+ verifyWipeFactoryResetProtectionCalled();
+ verifyRebootWipeUserDataCalled(FORCE);
+ }
+
+ @Test
+ public void testFactoryReset_bothFalse() throws Exception {
+ FactoryResetter.factoryReset(mContext, SHUTDOWN, REASON, FORCE,
+ WIPE_EUICC, NO_WIPE_ADOPTABLE_STORAGE, NO_WIPE_FACTORY_RESET_PROTECTION);
+
+ verifyWipeAdoptableStorageNotCalled();
+ verifyWipeFactoryResetProtectionNotCalled();
+ verifyRebootWipeUserDataCalled(FORCE);
+ }
+
+ @Test
+ public void testFactoryReset_storageOnly() throws Exception {
+ FactoryResetter.factoryReset(mContext, SHUTDOWN, REASON, FORCE,
+ WIPE_EUICC, WIPE_ADOPTABLE_STORAGE, NO_WIPE_FACTORY_RESET_PROTECTION);
+
+ verifyWipeAdoptableStorageCalled();
+ verifyWipeFactoryResetProtectionNotCalled();
+ verifyRebootWipeUserDataCalled(FORCE);
+ }
+
+ @Test
+ public void testFactoryReset_frpOnly() throws Exception {
+ FactoryResetter.factoryReset(mContext, SHUTDOWN, REASON, FORCE,
+ WIPE_EUICC, NO_WIPE_ADOPTABLE_STORAGE, WIPE_FACTORY_RESET_PROTECTION);
+
+ verifyWipeAdoptableStorageNotCalled();
+ verifyWipeFactoryResetProtectionCalled();
+ verifyRebootWipeUserDataCalled(FORCE);
+ }
+
+ private void revokeMasterClearPermission() {
+ when(mContext.checkCallingOrSelfPermission(android.Manifest.permission.MASTER_CLEAR))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
+ }
+
+ private void setFactoryResetRestriction(boolean allowed) {
+ when(mUm.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)).thenReturn(!allowed);
+ }
+
+ private void verifyRebootWipeUserDataNotCalled() {
+ verify(() -> RecoverySystem.rebootWipeUserData(any(), anyBoolean(), any(), anyBoolean(),
+ anyBoolean()), never());
+ }
+
+ private void verifyRebootWipeUserDataCalled(boolean force) {
+ verify(() -> RecoverySystem.rebootWipeUserData(mContext, SHUTDOWN, REASON, force,
+ WIPE_EUICC));
+ }
+
+ private void verifyWipeAdoptableStorageNotCalled() {
+ verify(mSm, never()).wipeAdoptableDisks();
+ }
+
+ private void verifyWipeAdoptableStorageCalled() {
+ verify(mSm).wipeAdoptableDisks();
+ }
+
+ private void verifyWipeFactoryResetProtectionNotCalled() {
+ verify(mPdbm, never()).wipe();
+ }
+
+ private void verifyWipeFactoryResetProtectionCalled() {
+ verify(mPdbm).wipe();
+ }
+}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java
index e2b48d439a47..17324bab70d2 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java
@@ -320,8 +320,10 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi
@Override
void recoverySystemRebootWipeUserData(boolean shutdown, String reason, boolean force,
- boolean wipeEuicc) throws IOException {
- services.recoverySystem.rebootWipeUserData(shutdown, reason, force, wipeEuicc);
+ boolean wipeEuicc, boolean wipeExtRequested, boolean wipeResetProtectionData)
+ throws IOException {
+ services.recoverySystem.rebootWipeUserData(shutdown, reason, force, wipeEuicc,
+ wipeExtRequested, wipeResetProtectionData);
}
@Override
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index d9daf17058c9..1c7da3b98930 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -4681,9 +4681,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
thenReturn("Just a test string.");
dpm.wipeData(0);
- verify(getServices().recoverySystem).rebootWipeUserData(
- /*shutdown=*/ eq(false), anyString(), /*force=*/ eq(true),
- /*wipeEuicc=*/ eq(false));
+
+ verifyRebootWipeUserData(/* wipeEuicc= */ false);
}
@Test
@@ -4697,9 +4696,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
thenReturn("Just a test string.");
dpm.wipeData(WIPE_EUICC);
- verify(getServices().recoverySystem).rebootWipeUserData(
- /*shutdown=*/ eq(false), anyString(), /*force=*/ eq(true),
- /*wipeEuicc=*/ eq(true));
+
+ verifyRebootWipeUserData(/* wipeEuicc= */ true);
}
@Test
@@ -4802,9 +4800,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// The device should be wiped even if DISALLOW_FACTORY_RESET is enabled, because both the
// user restriction and the policy were set by the DO.
- verify(getServices().recoverySystem).rebootWipeUserData(
- /*shutdown=*/ eq(false), anyString(), /*force=*/ eq(true),
- /*wipeEuicc=*/ eq(false));
+ verifyRebootWipeUserData(/* wipeEuicc= */ false);
}
@Test
@@ -4863,9 +4859,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
dpm.reportFailedPasswordAttempt(UserHandle.USER_SYSTEM);
// For managed profile on an organization owned device, the whole device should be wiped.
- verify(getServices().recoverySystem).rebootWipeUserData(
- /*shutdown=*/ eq(false), anyString(), /*force=*/ eq(true),
- /*wipeEuicc=*/ eq(false));
+ verifyRebootWipeUserData(/* wipeEuicc= */ false);
}
@Test
@@ -4907,9 +4901,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
dpm.reportFailedPasswordAttempt(MANAGED_PROFILE_USER_ID);
// For managed profile on an organization owned device, the whole device should be wiped.
- verify(getServices().recoverySystem).rebootWipeUserData(
- /*shutdown=*/ eq(false), anyString(), /*force=*/ eq(true),
- /*wipeEuicc=*/ eq(false));
+ verifyRebootWipeUserData(/* wipeEuicc= */ false);
}
@Test
@@ -5788,6 +5780,12 @@ public class DevicePolicyManagerTest extends DpmTestBase {
});
}
+ private void verifyRebootWipeUserData(boolean wipeEuicc) throws Exception {
+ verify(getServices().recoverySystem).rebootWipeUserData(/*shutdown=*/ eq(false),
+ /* reason= */ anyString(), /*force=*/ eq(true), eq(wipeEuicc),
+ /* wipeAdoptableStorage= */ eq(false), /* wipeFactoryResetProtection= */ eq(false));
+ }
+
private void assertAttestationFlags(int attestationFlags, int[] expectedFlags) {
int[] gotFlags = DevicePolicyManagerService.translateIdAttestationFlags(attestationFlags);
Arrays.sort(gotFlags);
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java b/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java
index 34313b888e48..7d1de866cb44 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java
@@ -393,7 +393,8 @@ public class MockSystemServices {
public static class RecoverySystemForMock {
public void rebootWipeUserData(boolean shutdown, String reason, boolean force,
- boolean wipeEuicc) throws IOException {
+ boolean wipeEuicc, boolean wipeExtRequested, boolean wipeResetProtectionData)
+ throws IOException {
}
}