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

Commit b2b510e3 authored by Al Sutton's avatar Al Sutton
Browse files

Clear the setttings provider cache before test runs

The Settings class has a cache (Settings$NameValueCache)
which stores, in process, data read or written via the
SettingsProvider.

Currently we do not clear the cache between tests, which
means that tests isolation is lost because each test
shares a common cache with other tests. This CL forces
the cache to be cleared between tests.

Bug: 139449903
Test: atest SettingsProviderTest
Change-Id: Iebbb335fd56b1bd24cf0e2ab98a1f392e4b84609
parent d4299771
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import androidx.test.runner.AndroidJUnit4;

import libcore.io.Streams;

import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;

import java.io.FileInputStream;
@@ -60,6 +62,20 @@ abstract class BaseSettingsProviderTest {

    private int mSecondaryUserId = Integer.MIN_VALUE;

    @Before
    public void setUp() {
        Settings.Global.clearProviderForTest();
        Settings.Secure.clearProviderForTest();
        Settings.System.clearProviderForTest();
    }

    @After
    public void tearDown() {
        Settings.Global.clearProviderForTest();
        Settings.Secure.clearProviderForTest();
        Settings.System.clearProviderForTest();
    }

    protected void setStringViaFrontEndApiSetting(int type, String name, String value, int userId) {
        ContentResolver contentResolver = getContext().getContentResolver();

+4 −0
Original line number Diff line number Diff line
@@ -84,8 +84,10 @@ public class InstallNonMarketAppsDeprecationTest extends BaseSettingsProviderTes
        return line.trim();
    }

    @Override
    @Before
    public void setUp() {
        super.setUp();
        mUm = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
        mHasUserRestriction = mUm.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
        mSystemSetUserRestriction = mUm.getUserRestrictionSource(
@@ -145,8 +147,10 @@ public class InstallNonMarketAppsDeprecationTest extends BaseSettingsProviderTes
        assertTrue("Invalid value", value.equals("1") || value.equals("0"));
    }

    @Override
    @After
    public void tearDown() {
        super.tearDown();
        if (!mHasUserRestriction || mSystemSetUserRestriction) {
            // The test may have modified the user restriction state. Restore it.
            mUm.setUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,
+2 −0
Original line number Diff line number Diff line
@@ -64,8 +64,10 @@ public class SettingsBackupAgentTest extends BaseSettingsProviderTest {
    private TestFriendlySettingsBackupAgent mAgentUnderTest;
    private Context mContext;

    @Override
    @Before
    public void setUp() {
        super.setUp();
        mContext = new ContextWithMockContentResolver(getContext());

        mAgentUnderTest = new TestFriendlySettingsBackupAgent();