Merge "Check if FRP policy is supported in Settings" into rvc-dev am: d1408a66a6 am: b2c004b3b7

Change-Id: I35a73ed9051d360ab493968defcee656ca92f0c1
This commit is contained in:
Alex Johnston
2020-04-29 08:49:52 +00:00
committed by Automerger Merge Worker
2 changed files with 23 additions and 2 deletions

View File

@@ -151,11 +151,16 @@ public class MasterClearConfirm extends InstrumentedFragment {
if (isOemUnlockedAllowed()) { if (isOemUnlockedAllowed()) {
return false; 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 // Do not erase the factory reset protection data (from Settings) if the
// device is an organization-owned managed profile device and a factory // device is an organization-owned managed profile device and a factory
// reset protection policy has been set. // reset protection policy has been set.
final DevicePolicyManager dpm = (DevicePolicyManager) getActivity()
.getSystemService(Context.DEVICE_POLICY_SERVICE);
FactoryResetProtectionPolicy frpPolicy = dpm.getFactoryResetProtectionPolicy(null); FactoryResetProtectionPolicy frpPolicy = dpm.getFactoryResetProtectionPolicy(null);
if (dpm.isOrganizationOwnedDeviceWithManagedProfile() && frpPolicy != null if (dpm.isOrganizationOwnedDeviceWithManagedProfile() && frpPolicy != null
&& frpPolicy.isNotEmpty()) { && frpPolicy.isNotEmpty()) {

View File

@@ -114,6 +114,20 @@ public class MasterClearConfirmTest {
mPersistentDataBlockManager)).isFalse(); 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 @Test
public void shouldWipePersistentDataBlock_hasFactoryResetProtectionPolicy_shouldReturnFalse() { public void shouldWipePersistentDataBlock_hasFactoryResetProtectionPolicy_shouldReturnFalse() {
when(mMasterClearConfirm.getActivity()).thenReturn(mMockActivity); when(mMasterClearConfirm.getActivity()).thenReturn(mMockActivity);
@@ -128,6 +142,7 @@ public class MasterClearConfirmTest {
.build(); .build();
when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)) when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE))
.thenReturn(mDevicePolicyManager); .thenReturn(mDevicePolicyManager);
when(mDevicePolicyManager.isFactoryResetProtectionPolicySupported()).thenReturn(true);
when(mDevicePolicyManager.getFactoryResetProtectionPolicy(null)).thenReturn(frp); when(mDevicePolicyManager.getFactoryResetProtectionPolicy(null)).thenReturn(frp);
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true); when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true);
@@ -144,6 +159,7 @@ public class MasterClearConfirmTest {
when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)) when(mMockActivity.getSystemService(Context.DEVICE_POLICY_SERVICE))
.thenReturn(mDevicePolicyManager); .thenReturn(mDevicePolicyManager);
when(mDevicePolicyManager.isFactoryResetProtectionPolicySupported()).thenReturn(true);
when(mDevicePolicyManager.getFactoryResetProtectionPolicy(null)).thenReturn(null); when(mDevicePolicyManager.getFactoryResetProtectionPolicy(null)).thenReturn(null);
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false); when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false);