Merge "Use the main thread to update alignment indication" into qt-qpr1-dev

This commit is contained in:
Wilson Wu
2020-02-11 03:54:55 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 21 deletions

View File

@@ -166,7 +166,8 @@ public class KeyguardIndicationController implements StateListener,
mStatusBarStateController = statusBarStateController; mStatusBarStateController = statusBarStateController;
mKeyguardUpdateMonitor = keyguardUpdateMonitor; mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mDockManager = dockManager; mDockManager = dockManager;
mDockManager.addAlignmentStateListener(this::handleAlignStateChanged); mDockManager.addAlignmentStateListener(
alignState -> mHandler.post(() -> handleAlignStateChanged(alignState)));
// lock icon is not used on all form factors. // lock icon is not used on all form factors.
if (mLockIcon != null) { if (mLockIcon != null) {
mLockIcon.setOnLongClickListener(this::handleLockLongClick); mLockIcon.setOnLongClickListener(this::handleLockLongClick);

View File

@@ -223,12 +223,14 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void onAlignmentStateChanged_showsSlowChargingIndication() { public void onAlignmentStateChanged_showsSlowChargingIndication() {
createController(); mInstrumentation.runOnMainSync(() -> {
verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture()); createController();
mController.setVisible(true); verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
mController.setVisible(true);
mAlignmentListener.getValue().onAlignmentStateChanged( mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
DockManager.ALIGN_STATE_POOR); });
mInstrumentation.waitForIdleSync();
assertThat(mTextView.getText()).isEqualTo( assertThat(mTextView.getText()).isEqualTo(
mContext.getResources().getString(R.string.dock_alignment_slow_charging)); mContext.getResources().getString(R.string.dock_alignment_slow_charging));
@@ -238,11 +240,14 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void onAlignmentStateChanged_showsNotChargingIndication() { public void onAlignmentStateChanged_showsNotChargingIndication() {
createController(); mInstrumentation.runOnMainSync(() -> {
verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture()); createController();
mController.setVisible(true); verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
mController.setVisible(true);
mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE); mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
});
mInstrumentation.waitForIdleSync();
assertThat(mTextView.getText()).isEqualTo( assertThat(mTextView.getText()).isEqualTo(
mContext.getResources().getString(R.string.dock_alignment_not_charging)); mContext.getResources().getString(R.string.dock_alignment_not_charging));
@@ -252,13 +257,15 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void onAlignmentStateChanged_whileDozing_showsSlowChargingIndication() { public void onAlignmentStateChanged_whileDozing_showsSlowChargingIndication() {
createController(); mInstrumentation.runOnMainSync(() -> {
verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture()); createController();
mController.setVisible(true); verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
mController.setDozing(true); mController.setVisible(true);
mController.setDozing(true);
mAlignmentListener.getValue().onAlignmentStateChanged( mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
DockManager.ALIGN_STATE_POOR); });
mInstrumentation.waitForIdleSync();
assertThat(mTextView.getText()).isEqualTo( assertThat(mTextView.getText()).isEqualTo(
mContext.getResources().getString(R.string.dock_alignment_slow_charging)); mContext.getResources().getString(R.string.dock_alignment_slow_charging));
@@ -268,12 +275,15 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
@Test @Test
public void onAlignmentStateChanged_whileDozing_showsNotChargingIndication() { public void onAlignmentStateChanged_whileDozing_showsNotChargingIndication() {
createController(); mInstrumentation.runOnMainSync(() -> {
verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture()); createController();
mController.setVisible(true); verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
mController.setDozing(true); mController.setVisible(true);
mController.setDozing(true);
mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE); mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
});
mInstrumentation.waitForIdleSync();
assertThat(mTextView.getText()).isEqualTo( assertThat(mTextView.getText()).isEqualTo(
mContext.getResources().getString(R.string.dock_alignment_not_charging)); mContext.getResources().getString(R.string.dock_alignment_not_charging));