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

Commit f656f6d2 authored by Wilson Wu's avatar Wilson Wu
Browse files

Use the main thread to update alignment indication

The alignment status is reported from WLC-HAL level and runs
on another thread. It may cause CalledFromWrongThreadException,
if use that thread to update UI directly.

Bug: 146770234
Test: atest SystemUITests:KeyguardIndicationControllerTest
Change-Id: I89bf1c188d6ba094106e059f1590c9eaf3703bb8
(cherry picked from commit 0e72713f)
Merged-In: I89bf1c188d6ba094106e059f1590c9eaf3703bb8
parent 835a9b4e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -166,7 +166,8 @@ public class KeyguardIndicationController implements StateListener,
        mStatusBarStateController = statusBarStateController;
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mDockManager = dockManager;
        mDockManager.addAlignmentStateListener(this::handleAlignStateChanged);
        mDockManager.addAlignmentStateListener(
                alignState -> mHandler.post(() -> handleAlignStateChanged(alignState)));
        // lock icon is not used on all form factors.
        if (mLockIcon != null) {
            mLockIcon.setOnLongClickListener(this::handleLockLongClick);
+30 −20
Original line number Diff line number Diff line
@@ -223,12 +223,14 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {

    @Test
    public void onAlignmentStateChanged_showsSlowChargingIndication() {
        mInstrumentation.runOnMainSync(() -> {
            createController();
            verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
            mController.setVisible(true);

        mAlignmentListener.getValue().onAlignmentStateChanged(
                DockManager.ALIGN_STATE_POOR);
            mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
        });
        mInstrumentation.waitForIdleSync();

        assertThat(mTextView.getText()).isEqualTo(
                mContext.getResources().getString(R.string.dock_alignment_slow_charging));
@@ -238,11 +240,14 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {

    @Test
    public void onAlignmentStateChanged_showsNotChargingIndication() {
        mInstrumentation.runOnMainSync(() -> {
            createController();
            verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
            mController.setVisible(true);

            mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
        });
        mInstrumentation.waitForIdleSync();

        assertThat(mTextView.getText()).isEqualTo(
                mContext.getResources().getString(R.string.dock_alignment_not_charging));
@@ -252,13 +257,15 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {

    @Test
    public void onAlignmentStateChanged_whileDozing_showsSlowChargingIndication() {
        mInstrumentation.runOnMainSync(() -> {
            createController();
            verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
            mController.setVisible(true);
            mController.setDozing(true);

        mAlignmentListener.getValue().onAlignmentStateChanged(
                DockManager.ALIGN_STATE_POOR);
            mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
        });
        mInstrumentation.waitForIdleSync();

        assertThat(mTextView.getText()).isEqualTo(
                mContext.getResources().getString(R.string.dock_alignment_slow_charging));
@@ -268,12 +275,15 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {

    @Test
    public void onAlignmentStateChanged_whileDozing_showsNotChargingIndication() {
        mInstrumentation.runOnMainSync(() -> {
            createController();
            verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
            mController.setVisible(true);
            mController.setDozing(true);

            mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
        });
        mInstrumentation.waitForIdleSync();

        assertThat(mTextView.getText()).isEqualTo(
                mContext.getResources().getString(R.string.dock_alignment_not_charging));