Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26492d07 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Skip DevicePolicyManagerTest that are not supported on automotive." into sc-v2-dev

parents b61f0217 bf9c164e
Loading
Loading
Loading
Loading
+64 −4
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
@@ -184,6 +185,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    public DevicePolicyManager parentDpm;
    public DevicePolicyManagerServiceTestable dpms;

    private boolean mIsAutomotive;

    /*
     * The CA cert below is the content of cacert.pem as generated by:
     *
@@ -266,6 +269,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        setUpUserManager();

        when(getServices().lockPatternUtils.hasSecureLockScreen()).thenReturn(true);

        mIsAutomotive = mContext.getPackageManager()
                .hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
    }

    private TransferOwnershipMetadataManager getMockTransferMetadataManager() {
@@ -2117,11 +2123,14 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        assertThat(dpm.getPasswordExpirationTimeout(admin1))
                .isEqualTo(originalPasswordExpirationTimeout);

        if (isDeprecatedPasswordApisSupported()) {
            int originalPasswordQuality = dpm.getPasswordQuality(admin1);
            assertExpectException(SecurityException.class, /* messageRegex= */ null,
                () -> dpm.setPasswordQuality(admin1, DevicePolicyManager.PASSWORD_QUALITY_NUMERIC));
                    () -> dpm.setPasswordQuality(admin1,
                            DevicePolicyManager.PASSWORD_QUALITY_NUMERIC));
            assertThat(dpm.getPasswordQuality(admin1)).isEqualTo(originalPasswordQuality);
        }
    }

    @Test
    public void testSetUserRestriction_asPo() {
@@ -5231,6 +5240,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testIsActivePasswordSufficient() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
        mContext.packageName = admin1.getPackageName();
        setupDeviceOwner();
@@ -5283,6 +5294,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testIsActivePasswordSufficient_noLockScreen() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        // If there is no lock screen, the password is considered empty no matter what, because
        // it provides no security.
        when(getServices().lockPatternUtils.hasSecureLockScreen()).thenReturn(false);
@@ -5363,6 +5376,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void testGetAggregatedPasswordMetrics_IgnoreProfileRequirement()
            throws Exception {
        assumeDeprecatedPasswordApisSupported();

        final int managedProfileUserId = CALLER_USER_HANDLE;
        final int managedProfileAdminUid =
                UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
@@ -5392,6 +5407,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testCanSetPasswordRequirementOnParentPreS() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        final int managedProfileUserId = CALLER_USER_HANDLE;
        final int managedProfileAdminUid =
                UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
@@ -5407,6 +5424,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testCannotSetPasswordRequirementOnParent() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        final int managedProfileUserId = CALLER_USER_HANDLE;
        final int managedProfileAdminUid =
                UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
@@ -5427,6 +5446,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void isActivePasswordSufficient_SeparateWorkChallenge_ProfileQualityRequirementMet()
            throws Exception {
        assumeDeprecatedPasswordApisSupported();

        // Create work profile with empty separate challenge
        final int managedProfileUserId = 15;
        final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
@@ -5450,6 +5471,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void isActivePasswordSufficient_SeparateWorkChallenge_ProfileComplexityRequirementMet()
            throws Exception {
        assumeDeprecatedPasswordApisSupported();

        // Create work profile with empty separate challenge
        final int managedProfileUserId = 15;
        final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
@@ -5473,6 +5496,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void isActivePasswordSufficient_SeparateWorkChallenge_ParentQualityRequirementMet()
            throws Exception {
        assumeDeprecatedPasswordApisSupported();

        // Create work profile with empty separate challenge
        final int managedProfileUserId = 15;
        final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
@@ -5519,6 +5544,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void isActivePasswordSufficient_UnifiedWorkChallenge_ProfileQualityRequirementMet()
            throws Exception {
        assumeDeprecatedPasswordApisSupported();

        // Create work profile with unified challenge
        final int managedProfileUserId = 15;
        final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
@@ -5565,6 +5592,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    @Test
    public void isActivePasswordSufficient_UnifiedWorkChallenge_ParentQualityRequirementMet()
            throws Exception {
        assumeDeprecatedPasswordApisSupported();

        // Create work profile with unified challenge
        final int managedProfileUserId = 15;
        final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
@@ -5625,6 +5654,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testPasswordQualityAppliesToParentPreS() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        final int managedProfileUserId = CALLER_USER_HANDLE;
        final int managedProfileAdminUid =
                UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
@@ -7285,6 +7316,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexity_UnauthorizedCallersOnDO() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
        setupDeviceOwner();
        // DO must be able to set it.
@@ -7300,6 +7333,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexity_UnauthorizedCallersOnPO() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        setupProfileOwner();
        // PO must be able to set it.
@@ -7314,6 +7349,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexity_validValuesOnly() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        setupProfileOwner();

@@ -7335,6 +7372,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexity_setAndGet() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        setupProfileOwner();

@@ -7348,6 +7387,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexityOnParent_setAndGet() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        final int managedProfileUserId = 15;
        final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);

@@ -7366,6 +7407,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexity_isSufficient() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
        mContext.packageName = admin1.getPackageName();
        setupDeviceOwner();
@@ -7395,6 +7438,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexity_resetBySettingQuality() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        setupProfileOwner();

@@ -7407,6 +7452,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexity_overridesQuality() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        setupProfileOwner();

@@ -7421,6 +7468,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetRequiredPasswordComplexityFailsWithQualityOnParent() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        final int managedProfileUserId = CALLER_USER_HANDLE;
        final int managedProfileAdminUid =
                UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
@@ -7435,6 +7484,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {

    @Test
    public void testSetQualityOnParentFailsWithComplexityOnProfile() throws Exception {
        assumeDeprecatedPasswordApisSupported();

        final int managedProfileUserId = CALLER_USER_HANDLE;
        final int managedProfileAdminUid =
                UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
@@ -8015,4 +8066,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        when(mContext.getResources().getStringArray(R.array.vendor_policy_exempt_apps))
                .thenReturn(new String[0]);
    }

    private boolean isDeprecatedPasswordApisSupported() {
        return !mIsAutomotive;
    }

    private void assumeDeprecatedPasswordApisSupported() {
        assumeTrue("device doesn't support deprecated password APIs",
                isDeprecatedPasswordApisSupported());
    }
}