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

Commit d228bcd8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixed the failing tests in com.android.server.dreams" into main

parents b61a03eb 45a0ff7a
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import android.view.Display;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLoggerImpl;
import com.android.internal.util.DumpUtils;
@@ -112,7 +113,7 @@ public final class DreamManagerService extends SystemService {
    private final Object mLock = new Object();

    private final Context mContext;
    private final DreamHandler mHandler;
    private final Handler mHandler;
    private final DreamController mController;
    private final PowerManager mPowerManager;
    private final PowerManagerInternal mPowerManagerInternal;
@@ -211,9 +212,14 @@ public final class DreamManagerService extends SystemService {
    }

    public DreamManagerService(Context context) {
        this(context, new DreamHandler(FgThread.get().getLooper()));
    }

    @VisibleForTesting
    DreamManagerService(Context context, Handler handler) {
        super(context);
        mContext = context;
        mHandler = new DreamHandler(FgThread.get().getLooper());
        mHandler = handler;
        mController = new DreamController(context, mHandler, mControllerListener);

        mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
@@ -244,7 +250,6 @@ public final class DreamManagerService extends SystemService {
                com.android.internal.R.bool.config_keepDreamingWhenUnplugging);
        mDreamsDisabledByAmbientModeSuppressionConfig = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_dreamsDisabledByAmbientModeSuppressionConfig);

    }

    @Override
+5 −0
Original line number Diff line number Diff line
@@ -18,6 +18,11 @@ android_test {
        "mockito-target-minus-junit4",
        "services.core",
        "mockingservicestests-utils-mockito",
        "servicestests-utils",
    ],

    defaults: [
        "modules-utils-testable-device-config-defaults",
    ],

    platform_apis: true,
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
    Insert permissions here. eg:
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    -->
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />

    <application android:debuggable="true"
                 android:testOnly="true">
+13 −17
Original line number Diff line number Diff line
@@ -36,13 +36,14 @@ import android.os.UserManager;
import android.provider.Settings;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.FlakyTest;

import com.android.server.LocalServices;
import com.android.internal.util.test.LocalServiceKeeperRule;
import com.android.server.SystemService;
import com.android.server.testutils.TestHandler;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -65,23 +66,24 @@ public class DreamManagerServiceMockingTest {
    @Mock
    private UserManager mUserManagerMock;

    private MockitoSession mMockitoSession;
    @Rule
    public LocalServiceKeeperRule mLocalServiceKeeperRule = new LocalServiceKeeperRule();

    private static <T> void addLocalServiceMock(Class<T> clazz, T mock) {
        LocalServices.removeServiceForTest(clazz);
        LocalServices.addService(clazz, mock);
    }
    private TestHandler mTestHandler;
    private MockitoSession mMockitoSession;

    @Before
    public void setUp() throws Exception {
        mTestHandler = new TestHandler(/* callback= */ null);
        MockitoAnnotations.initMocks(this);

        mContextSpy = spy(new ContextWrapper(InstrumentationRegistry.getContext()));
        mResourcesSpy = spy(mContextSpy.getResources());
        when(mContextSpy.getResources()).thenReturn(mResourcesSpy);

        addLocalServiceMock(ActivityManagerInternal.class, mActivityManagerInternalMock);
        addLocalServiceMock(PowerManagerInternal.class, mPowerManagerInternalMock);
        mLocalServiceKeeperRule.overrideLocalService(
                ActivityManagerInternal.class, mActivityManagerInternalMock);
        mLocalServiceKeeperRule.overrideLocalService(
                PowerManagerInternal.class, mPowerManagerInternalMock);

        when(mContextSpy.getSystemService(UserManager.class)).thenReturn(mUserManagerMock);
        mMockitoSession = mockitoSession()
@@ -94,26 +96,20 @@ public class DreamManagerServiceMockingTest {
    @After
    public void tearDown() throws Exception {
        mMockitoSession.finishMocking();
        LocalServices.removeServiceForTest(ActivityManagerInternal.class);
        LocalServices.removeServiceForTest(PowerManagerInternal.class);
    }

    private DreamManagerService createService() {
        return new DreamManagerService(mContextSpy);
        return new DreamManagerService(mContextSpy, mTestHandler);
    }

    @Test
    @FlakyTest(bugId = 293443309)
    public void testSettingsQueryUserChange() {
        final DreamManagerService service = createService();

        final SystemService.TargetUser from =
                new SystemService.TargetUser(mock(UserInfo.class));
        final SystemService.TargetUser to =
                new SystemService.TargetUser(mock(UserInfo.class));

        service.onUserSwitching(from, to);

        verify(() -> Settings.Secure.getIntForUser(any(),
                eq(Settings.Secure.SCREENSAVER_ENABLED),
                anyInt(),