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

Commit d1f5758e authored by Chandru S's avatar Chandru S Committed by Android (Google) Code Review
Browse files

Merge "Add unit test for ScreenDecorations" into tm-qpr-dev

parents 71592cf7 a31515a9
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -124,16 +124,7 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
    };
    private final ScreenDecorationsLogger mLogger;

    private final AuthController.Callback mAuthControllerCallback = new AuthController.Callback() {
        @Override
        public void onFaceSensorLocationChanged() {
            mLogger.onSensorLocationChanged();
            if (mExecutor != null) {
                mExecutor.execute(
                        () -> updateOverlayProviderViews(new Integer[]{mFaceScanningViewId}));
            }
        }
    };
    private final AuthController mAuthController;

    private DisplayTracker mDisplayTracker;
    @VisibleForTesting
@@ -340,8 +331,21 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
        mFaceScanningFactory = faceScanningFactory;
        mFaceScanningViewId = com.android.systemui.R.id.face_scanning_anim;
        mLogger = logger;
        authController.addCallback(mAuthControllerCallback);
        mAuthController = authController;
    }


    private final AuthController.Callback mAuthControllerCallback = new AuthController.Callback() {
        @Override
        public void onFaceSensorLocationChanged() {
            mLogger.onSensorLocationChanged();
            if (mExecutor != null) {
                mExecutor.execute(
                        () -> updateOverlayProviderViews(
                                new Integer[]{mFaceScanningViewId}));
            }
        }
    };

    @Override
    public void start() {
@@ -353,6 +357,7 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
        mExecutor = mThreadFactory.buildDelayableExecutorOnHandler(mHandler);
        mExecutor.execute(this::startOnScreenDecorationsThread);
        mDotViewController.setUiExecutor(mExecutor);
        mAuthController.addCallback(mAuthControllerCallback);
    }

    private boolean isPrivacyDotEnabled() {
+48 −1
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -104,8 +106,12 @@ import com.android.systemui.util.time.FakeSystemClock;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.util.ArrayList;
import java.util.List;
@@ -119,7 +125,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
    private WindowManager mWindowManager;
    private DisplayManager mDisplayManager;
    private SecureSettings mSecureSettings;
    private final FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
    private FakeExecutor mExecutor;
    private final FakeDisplayTracker mDisplayTracker = new FakeDisplayTracker(mContext);
    private FakeThreadFactory mThreadFactory;
    private ArrayList<DecorProvider> mPrivacyDecorProviders;
@@ -161,6 +167,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
    private PrivacyDotViewController.ShowingListener mPrivacyDotShowingListener;
    @Mock
    private CutoutDecorProviderFactory mCutoutFactory;
    @Captor
    private ArgumentCaptor<AuthController.Callback> mAuthControllerCallback;
    private List<DecorProvider> mMockCutoutList;

    @Before
@@ -169,6 +177,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {

        Handler mainHandler = new Handler(TestableLooper.get(this).getLooper());
        mSecureSettings = new FakeSettings();
        mExecutor = new FakeExecutor(new FakeSystemClock());
        mThreadFactory = new FakeThreadFactory(mExecutor);
        mThreadFactory.setHandler(mainHandler);

@@ -1165,6 +1174,44 @@ public class ScreenDecorationsTest extends SysuiTestCase {
        verifyOverlaysExistAndAdded(false, true, false, true, View.VISIBLE);
    }

    @Test
    public void faceSensorLocationChangesReloadsFaceScanningOverlay() {
        mFaceScanningProviders = new ArrayList<>();
        mFaceScanningProviders.add(mFaceScanningDecorProvider);
        when(mFaceScanningProviderFactory.getProviders()).thenReturn(mFaceScanningProviders);
        when(mFaceScanningProviderFactory.getHasProviders()).thenReturn(true);
        ScreenDecorations screenDecorations = new ScreenDecorations(mContext, mExecutor,
                mSecureSettings, mTunerService, mUserTracker, mDisplayTracker, mDotViewController,
                mThreadFactory, mPrivacyDotDecorProviderFactory, mFaceScanningProviderFactory,
                new ScreenDecorationsLogger(logcatLogBuffer("TestLogBuffer")), mAuthController);
        screenDecorations.start();
        verify(mAuthController).addCallback(mAuthControllerCallback.capture());
        when(mContext.getDisplay()).thenReturn(mDisplay);
        when(mDisplay.getDisplayInfo(any())).thenAnswer(new Answer<Boolean>() {
            @Override
            public Boolean answer(InvocationOnMock invocation) throws Throwable {
                DisplayInfo displayInfo = invocation.getArgument(0);
                int modeId = 1;
                displayInfo.modeId = modeId;
                displayInfo.supportedModes = new Display.Mode[]{new Display.Mode(modeId, 1024, 1024,
                        90)};
                return false;
            }
        });
        mExecutor.runAllReady();
        clearInvocations(mFaceScanningDecorProvider);

        AuthController.Callback callback = mAuthControllerCallback.getValue();
        callback.onFaceSensorLocationChanged();
        mExecutor.runAllReady();

        verify(mFaceScanningDecorProvider).onReloadResAndMeasure(any(),
                anyInt(),
                anyInt(),
                anyInt(),
                any());
    }

    @Test
    public void testPrivacyDotShowingListenerWorkWellWithNullParameter() {
        mPrivacyDotShowingListener.onPrivacyDotShown(null);