diff --git a/src/com/android/settings/MainClearConfirm.java b/src/com/android/settings/MainClearConfirm.java index b5ddd1aeb96..042c5c26c1a 100644 --- a/src/com/android/settings/MainClearConfirm.java +++ b/src/com/android/settings/MainClearConfirm.java @@ -151,15 +151,20 @@ public class MainClearConfirm extends InstrumentedFragment { if (pdbManager == null) { return false; } + // The persistent data block will persist if the device is still being provisioned. if (isDeviceStillBeingProvisioned()) { return false; } - // If OEM unlock is allowed, the persistent data block will be wiped during FR - // process. If disabled, it will be wiped here instead. - if (isOemUnlockedAllowed()) { + + // If OEM unlock is allowed, the persistent data block will be wiped during the FR + // process on devices without FRP Hardening. If disabled, it will be wiped here instead. + // On devices with FRP Hardening, the persistent data block should always be wiped, + // regardless of the OEM Unlocking state. + if (!android.security.Flags.frpEnforcement() && isOemUnlockedAllowed()) { return false; } + final DevicePolicyManager dpm = (DevicePolicyManager) getActivity() .getSystemService(Context.DEVICE_POLICY_SERVICE); // Do not erase the factory reset protection data (from Settings) if factory reset @@ -167,6 +172,7 @@ public class MainClearConfirm extends InstrumentedFragment { if (!dpm.isFactoryResetProtectionPolicySupported()) { return false; } + // Do not erase the factory reset protection data (from Settings) if the // device is an organization-owned managed profile device and a factory // reset protection policy has been set. @@ -175,6 +181,7 @@ public class MainClearConfirm extends InstrumentedFragment { && frpPolicy.isNotEmpty()) { return false; } + return true; } diff --git a/tests/robotests/src/com/android/settings/MainClearConfirmTest.java b/tests/robotests/src/com/android/settings/MainClearConfirmTest.java index b866c964f03..6d85368d0b8 100644 --- a/tests/robotests/src/com/android/settings/MainClearConfirmTest.java +++ b/tests/robotests/src/com/android/settings/MainClearConfirmTest.java @@ -25,6 +25,10 @@ import static org.mockito.Mockito.when; import android.app.admin.DevicePolicyManager; import android.app.admin.FactoryResetProtectionPolicy; import android.content.Context; +import android.platform.test.annotations.DisableFlags; +import android.platform.test.annotations.EnableFlags; +import android.platform.test.flag.junit.SetFlagsRule; +import android.security.Flags; import android.service.persistentdata.PersistentDataBlockManager; import android.view.LayoutInflater; import android.widget.TextView; @@ -32,6 +36,7 @@ import android.widget.TextView; import androidx.fragment.app.FragmentActivity; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -48,6 +53,9 @@ import java.util.ArrayList; }) public class MainClearConfirmTest { + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); + private FragmentActivity mActivity; @Mock @@ -66,6 +74,9 @@ public class MainClearConfirmTest { MockitoAnnotations.initMocks(this); mActivity = Robolectric.setupActivity(FragmentActivity.class); mMainClearConfirm = spy(new MainClearConfirm()); + + when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)) + .thenReturn(mDevicePolicyManager); } @Test @@ -110,12 +121,29 @@ public class MainClearConfirmTest { } @Test - public void shouldWipePersistentDataBlock_oemUnlockAllowed_shouldReturnFalse() { + @DisableFlags(Flags.FLAG_FRP_ENFORCEMENT) + public void shouldWipePersistentDataBlock_oemUnlockAllowedAndFlagDiscabled_shouldReturnFalse() { + when(mMainClearConfirm.getActivity()).thenReturn(mMockActivity); + + when(mDevicePolicyManager.isFactoryResetProtectionPolicySupported()).thenReturn(true); doReturn(false).when(mMainClearConfirm).isDeviceStillBeingProvisioned(); doReturn(true).when(mMainClearConfirm).isOemUnlockedAllowed(); - assertThat(mMainClearConfirm.shouldWipePersistentDataBlock( - mPersistentDataBlockManager)).isFalse(); + assertThat(mMainClearConfirm.shouldWipePersistentDataBlock(mPersistentDataBlockManager)) + .isFalse(); + } + + @Test + @EnableFlags(Flags.FLAG_FRP_ENFORCEMENT) + public void shouldWipePersistentDataBlock_oemUnlockAllowedAndFlagEnabled_shouldReturnTrue() { + when(mMainClearConfirm.getActivity()).thenReturn(mMockActivity); + + when(mDevicePolicyManager.isFactoryResetProtectionPolicySupported()).thenReturn(true); + doReturn(false).when(mMainClearConfirm).isDeviceStillBeingProvisioned(); + doReturn(true).when(mMainClearConfirm).isOemUnlockedAllowed(); + + assertThat(mMainClearConfirm.shouldWipePersistentDataBlock(mPersistentDataBlockManager)) + .isTrue(); } @Test @@ -124,8 +152,7 @@ public class MainClearConfirmTest { doReturn(false).when(mMainClearConfirm).isDeviceStillBeingProvisioned(); doReturn(false).when(mMainClearConfirm).isOemUnlockedAllowed(); - when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)) - .thenReturn(mDevicePolicyManager); + when(mDevicePolicyManager.isFactoryResetProtectionPolicySupported()).thenReturn(false); assertThat(mMainClearConfirm.shouldWipePersistentDataBlock( @@ -144,8 +171,6 @@ public class MainClearConfirmTest { .setFactoryResetProtectionAccounts(accounts) .setFactoryResetProtectionEnabled(true) .build(); - when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)) - .thenReturn(mDevicePolicyManager); when(mDevicePolicyManager.isFactoryResetProtectionPolicySupported()).thenReturn(true); when(mDevicePolicyManager.getFactoryResetProtectionPolicy(null)).thenReturn(frp); when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true); @@ -161,8 +186,6 @@ public class MainClearConfirmTest { doReturn(false).when(mMainClearConfirm).isDeviceStillBeingProvisioned(); doReturn(false).when(mMainClearConfirm).isOemUnlockedAllowed(); - when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)) - .thenReturn(mDevicePolicyManager); when(mDevicePolicyManager.isFactoryResetProtectionPolicySupported()).thenReturn(true); when(mDevicePolicyManager.getFactoryResetProtectionPolicy(null)).thenReturn(null); when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false);