From 05c0ab03242f3b602477faf3f5552df3dbd3d320 Mon Sep 17 00:00:00 2001 From: Alex Johnston Date: Tue, 28 Apr 2020 13:47:14 +0100 Subject: [PATCH] Check if FRP policy is supported in Settings * Check if FRP policy is supported before erasing a device via settings. * Call DPM TestAPI isFactoryResetProtectionPolicySupported * If FRP policy is not supported, then do not erase the device. Bug: 155057616 Test: atest com.android.settings.MasterClearConfirmTest Change-Id: I56e4a6566457f31932658188646abe21701637fc --- src/com/android/settings/MasterClearConfirm.java | 9 +++++++-- .../android/settings/MasterClearConfirmTest.java | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/MasterClearConfirm.java b/src/com/android/settings/MasterClearConfirm.java index cac18f75e8c..3ace43621b6 100644 --- a/src/com/android/settings/MasterClearConfirm.java +++ b/src/com/android/settings/MasterClearConfirm.java @@ -151,11 +151,16 @@ public class MasterClearConfirm extends InstrumentedFragment { if (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 + // protection policy is not supported on the device. + 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. - final DevicePolicyManager dpm = (DevicePolicyManager) getActivity() - .getSystemService(Context.DEVICE_POLICY_SERVICE); FactoryResetProtectionPolicy frpPolicy = dpm.getFactoryResetProtectionPolicy(null); if (dpm.isOrganizationOwnedDeviceWithManagedProfile() && frpPolicy != null && frpPolicy.isNotEmpty()) { diff --git a/tests/robotests/src/com/android/settings/MasterClearConfirmTest.java b/tests/robotests/src/com/android/settings/MasterClearConfirmTest.java index 1222bdda701..f2000e56c3f 100644 --- a/tests/robotests/src/com/android/settings/MasterClearConfirmTest.java +++ b/tests/robotests/src/com/android/settings/MasterClearConfirmTest.java @@ -114,6 +114,20 @@ public class MasterClearConfirmTest { mPersistentDataBlockManager)).isFalse(); } + @Test + public void shouldWipePersistentDataBlock_frpPolicyNotSupported_shouldReturnFalse() { + when(mMasterClearConfirm.getActivity()).thenReturn(mMockActivity); + + doReturn(false).when(mMasterClearConfirm).isDeviceStillBeingProvisioned(); + doReturn(false).when(mMasterClearConfirm).isOemUnlockedAllowed(); + when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)) + .thenReturn(mDevicePolicyManager); + when(mDevicePolicyManager.isFactoryResetProtectionPolicySupported()).thenReturn(false); + + assertThat(mMasterClearConfirm.shouldWipePersistentDataBlock( + mPersistentDataBlockManager)).isFalse(); + } + @Test public void shouldWipePersistentDataBlock_hasFactoryResetProtectionPolicy_shouldReturnFalse() { when(mMasterClearConfirm.getActivity()).thenReturn(mMockActivity); @@ -128,6 +142,7 @@ public class MasterClearConfirmTest { .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); @@ -144,6 +159,7 @@ public class MasterClearConfirmTest { 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);