Merge "Add unit test for ScreenDecorations" into tm-qpr-dev
This commit is contained in:
@@ -124,16 +124,7 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
|
|||||||
};
|
};
|
||||||
private final ScreenDecorationsLogger mLogger;
|
private final ScreenDecorationsLogger mLogger;
|
||||||
|
|
||||||
private final AuthController.Callback mAuthControllerCallback = new AuthController.Callback() {
|
private final AuthController mAuthController;
|
||||||
@Override
|
|
||||||
public void onFaceSensorLocationChanged() {
|
|
||||||
mLogger.onSensorLocationChanged();
|
|
||||||
if (mExecutor != null) {
|
|
||||||
mExecutor.execute(
|
|
||||||
() -> updateOverlayProviderViews(new Integer[]{mFaceScanningViewId}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private DisplayTracker mDisplayTracker;
|
private DisplayTracker mDisplayTracker;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -340,9 +331,22 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
|
|||||||
mFaceScanningFactory = faceScanningFactory;
|
mFaceScanningFactory = faceScanningFactory;
|
||||||
mFaceScanningViewId = com.android.systemui.R.id.face_scanning_anim;
|
mFaceScanningViewId = com.android.systemui.R.id.face_scanning_anim;
|
||||||
mLogger = logger;
|
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
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
if (DEBUG_DISABLE_SCREEN_DECORATIONS) {
|
if (DEBUG_DISABLE_SCREEN_DECORATIONS) {
|
||||||
@@ -353,6 +357,7 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
|
|||||||
mExecutor = mThreadFactory.buildDelayableExecutorOnHandler(mHandler);
|
mExecutor = mThreadFactory.buildDelayableExecutorOnHandler(mHandler);
|
||||||
mExecutor.execute(this::startOnScreenDecorationsThread);
|
mExecutor.execute(this::startOnScreenDecorationsThread);
|
||||||
mDotViewController.setUiExecutor(mExecutor);
|
mDotViewController.setUiExecutor(mExecutor);
|
||||||
|
mAuthController.addCallback(mAuthControllerCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPrivacyDotEnabled() {
|
private boolean isPrivacyDotEnabled() {
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ import static org.junit.Assert.assertThat;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.ArgumentMatchers.isA;
|
import static org.mockito.ArgumentMatchers.isA;
|
||||||
|
import static org.mockito.Mockito.clearInvocations;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@@ -104,8 +106,12 @@ import com.android.systemui.util.time.FakeSystemClock;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -119,7 +125,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
private WindowManager mWindowManager;
|
private WindowManager mWindowManager;
|
||||||
private DisplayManager mDisplayManager;
|
private DisplayManager mDisplayManager;
|
||||||
private SecureSettings mSecureSettings;
|
private SecureSettings mSecureSettings;
|
||||||
private final FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
|
private FakeExecutor mExecutor;
|
||||||
private final FakeDisplayTracker mDisplayTracker = new FakeDisplayTracker(mContext);
|
private final FakeDisplayTracker mDisplayTracker = new FakeDisplayTracker(mContext);
|
||||||
private FakeThreadFactory mThreadFactory;
|
private FakeThreadFactory mThreadFactory;
|
||||||
private ArrayList<DecorProvider> mPrivacyDecorProviders;
|
private ArrayList<DecorProvider> mPrivacyDecorProviders;
|
||||||
@@ -161,6 +167,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
private PrivacyDotViewController.ShowingListener mPrivacyDotShowingListener;
|
private PrivacyDotViewController.ShowingListener mPrivacyDotShowingListener;
|
||||||
@Mock
|
@Mock
|
||||||
private CutoutDecorProviderFactory mCutoutFactory;
|
private CutoutDecorProviderFactory mCutoutFactory;
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<AuthController.Callback> mAuthControllerCallback;
|
||||||
private List<DecorProvider> mMockCutoutList;
|
private List<DecorProvider> mMockCutoutList;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -169,6 +177,7 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
|
|
||||||
Handler mainHandler = new Handler(TestableLooper.get(this).getLooper());
|
Handler mainHandler = new Handler(TestableLooper.get(this).getLooper());
|
||||||
mSecureSettings = new FakeSettings();
|
mSecureSettings = new FakeSettings();
|
||||||
|
mExecutor = new FakeExecutor(new FakeSystemClock());
|
||||||
mThreadFactory = new FakeThreadFactory(mExecutor);
|
mThreadFactory = new FakeThreadFactory(mExecutor);
|
||||||
mThreadFactory.setHandler(mainHandler);
|
mThreadFactory.setHandler(mainHandler);
|
||||||
|
|
||||||
@@ -1165,6 +1174,44 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
verifyOverlaysExistAndAdded(false, true, false, true, View.VISIBLE);
|
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
|
@Test
|
||||||
public void testPrivacyDotShowingListenerWorkWellWithNullParameter() {
|
public void testPrivacyDotShowingListenerWorkWellWithNullParameter() {
|
||||||
mPrivacyDotShowingListener.onPrivacyDotShown(null);
|
mPrivacyDotShowingListener.onPrivacyDotShown(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user