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

Commit bb996d4a authored by Eric Biggers's avatar Eric Biggers
Browse files

Ensure PropertyInvalidatedCache test mode in all locksettings tests

WeakEscrowTokenTests (and possibly other test classes in
com.android.server.locksettings) was missing a call to
PropertyInvalidatedCache.disableForTestMode().  There are other tests in
com.android.server.locksettings that do make that call, and it applies
to the whole process.  So WeakEscrowTokenTests was relying on the
implicit test ordering, and it failed when run by itself.

To fix this, move the enabling of test mode into
BaseLockSettingsServiceTests, which is the base class that all the
relevant test classes inherit from.

Additionally, switch from a process-wide toggle to a per-test toggle.
That ensures implicit test ordering is no longer being relied on.

Test: atest FrameworksServicesTests:WeakEscrowTokenTests
Test: atest FrameworksServicesTests:com.android.server.locksettings
Bug: 418862901
Flag: TEST_ONLY
Change-Id: I30f451ff46b3a46bd5a89f6d618df69db6506f75
parent c61d5377
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.app.NotificationManager;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.admin.DeviceStateCache;
import android.app.test.PropertyInvalidatedCacheTestRule;
import android.app.trust.TrustManager;
import android.content.ComponentName;
import android.content.Context;
@@ -116,6 +117,9 @@ public abstract class BaseLockSettingsServiceTests {
    @Rule
    public FakeSettingsProviderRule mSettingsRule = FakeSettingsProvider.rule();

    @Rule
    public PropertyInvalidatedCacheTestRule mCacheRule = new PropertyInvalidatedCacheTestRule();

    @Before
    public void setUp_baseServices() throws Exception {
        mResources = createMockResources();
+0 −2
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.app.PropertyInvalidatedCache;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.SetFlagsRule;
@@ -46,7 +45,6 @@ public class LockSettingsServiceSwRateLimiterNotEnforcingTests

    @Before
    public void setUp() {
        PropertyInvalidatedCache.disableForTestMode();
        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
    }

+0 −4
Original line number Diff line number Diff line
@@ -38,15 +38,12 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.PropertyInvalidatedCache;
import android.content.Intent;
import android.os.RemoteException;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.SetFlagsRule;
@@ -78,7 +75,6 @@ public class LockSettingsServiceTests extends BaseLockSettingsServiceTests {

    @Before
    public void setUp() {
        PropertyInvalidatedCache.disableForTestMode();
        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
        mService.initializeSyntheticPassword(MANAGED_PROFILE_USER_ID);
    }
+0 −3
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.app.PropertyInvalidatedCache;
import android.app.admin.DevicePolicyManager;
import android.platform.test.annotations.Presubmit;

@@ -50,8 +49,6 @@ public class LockscreenFrpTest extends BaseLockSettingsServiceTests {

    @Before
    public void setUp() throws Exception {
        PropertyInvalidatedCache.disableForTestMode();

        // FRP credential can only be verified prior to provisioning
        setDeviceProvisioned(false);

+0 −2
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;

import android.app.PropertyInvalidatedCache;
import android.platform.test.annotations.Presubmit;
import android.provider.Settings;

@@ -46,7 +45,6 @@ public class LockscreenRepairModeTest extends BaseLockSettingsServiceTests {

    @Before
    public void setUp() throws Exception {
        PropertyInvalidatedCache.disableForTestMode();
        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
    }

Loading