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

Commit 685c25f2 authored by Fiona Campbell's avatar Fiona Campbell
Browse files

Fix DMSTests

DisplayManagerServiceTests were failing with error:
"You cannot keep your settings in the secure settings."

- testPhysicalViewports
- testCreateVirtualDisplay_sentToInputManager

This was occurring since we dont have permission to write to these
settings during the test. To improve and fix the tests we'd prefer to use a fake settings provider.

Bug: 275079012
Test: atest DisplayManagerServiceTest
Change-Id: Ia7a07081070ca88fd5e05b1c7463941f47374682
parent 3034ebdc
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ import android.os.SystemProperties;
import android.os.UserManager;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.test.mock.MockContentResolver;
import android.util.SparseArray;
import android.view.ContentRecordingSession;
import android.view.Display;
@@ -123,6 +124,8 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.R;
import com.android.internal.util.test.FakeSettingsProvider;
import com.android.internal.util.test.FakeSettingsProviderRule;
import com.android.modules.utils.testing.ExtendedMockitoRule;
import com.android.server.LocalServices;
import com.android.server.SystemService;
@@ -204,6 +207,8 @@ public class DisplayManagerServiceTest {
    @Rule
    public SetFlagsRule mSetFlagsRule =
            new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
    @Rule
    public FakeSettingsProviderRule mSettingsProviderRule = FakeSettingsProvider.rule();

    private Context mContext;

@@ -376,6 +381,8 @@ public class DisplayManagerServiceTest {
        when(display.getBrightnessInfo()).thenReturn(mock(BrightnessInfo.class));
        mContext = spy(new ContextWrapper(
                ApplicationProvider.getApplicationContext().createDisplayContext(display)));
        final MockContentResolver resolver = mSettingsProviderRule.mockContentResolver(mContext);
        when(mContext.getContentResolver()).thenReturn(resolver);
        mResources = Mockito.spy(mContext.getResources());
        mPowerHandler = new Handler(Looper.getMainLooper());
        manageDisplaysPermission(/* granted= */ false);