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

This commit is contained in:
Chandru S
2023-02-02 22:32:39 +00:00
committed by Android (Google) Code Review
2 changed files with 64 additions and 12 deletions

View File

@@ -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,9 +331,22 @@ 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() {
if (DEBUG_DISABLE_SCREEN_DECORATIONS) {
@@ -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() {

View File

@@ -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);