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

Commit aadedc76 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Hook WakefulnessLifecycle for best timing of LockedDisabled" into sc-dev

parents d39b5f03 4f4b74bb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -87,4 +87,9 @@ public interface OneHanded {
     * Notifies when user switch complete
     */
    void onUserSwitch(int userId);

    /**
     * Notifies when keyguard visibility changed
     */
    void onKeyguardVisibilityChanged(boolean showing);
}
+13 −1
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
    private volatile boolean mIsSwipeToNotificationEnabled;
    private boolean mTaskChangeToExit;
    private boolean mLockedDisabled;
    private boolean mKeyguardShowing;
    private int mUserId;
    private float mOffSetFraction;

@@ -357,7 +358,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>

    @VisibleForTesting
    void startOneHanded() {
        if (isLockedDisabled()) {
        if (isLockedDisabled() || mKeyguardShowing) {
            Slog.d(TAG, "Temporary lock disabled");
            return;
        }
@@ -692,6 +693,10 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
        mTutorialHandler.onConfigurationChanged();
    }

    private void onKeyguardVisibilityChanged(boolean showing) {
        mKeyguardShowing = showing;
    }

    private void onUserSwitch(int newUserId) {
        unregisterSettingObservers();
        mUserId = newUserId;
@@ -838,6 +843,13 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
                OneHandedController.this.onUserSwitch(userId);
            });
        }

        @Override
        public void onKeyguardVisibilityChanged(boolean showing) {
            mMainExecutor.execute(() -> {
                OneHandedController.this.onKeyguardVisibilityChanged(showing);
            });
        }
    }

    /**
+24 −14
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.WMComponent;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.keyguard.ScreenLifecycle;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.shared.tracing.ProtoTraceable;
@@ -114,6 +115,7 @@ public final class WMShell extends SystemUI
    private final NavigationModeController mNavigationModeController;
    private final ScreenLifecycle mScreenLifecycle;
    private final SysUiState mSysUiState;
    private final WakefulnessLifecycle mWakefulnessLifecycle;
    private final ProtoTracer mProtoTracer;
    private final Executor mSysUiMainExecutor;

@@ -121,6 +123,7 @@ public final class WMShell extends SystemUI
    private KeyguardUpdateMonitorCallback mSplitScreenKeyguardCallback;
    private KeyguardUpdateMonitorCallback mPipKeyguardCallback;
    private KeyguardUpdateMonitorCallback mOneHandedKeyguardCallback;
    private WakefulnessLifecycle.Observer mWakefulnessObserver;

    @Inject
    public WMShell(Context context,
@@ -136,6 +139,7 @@ public final class WMShell extends SystemUI
            ScreenLifecycle screenLifecycle,
            SysUiState sysUiState,
            ProtoTracer protoTracer,
            WakefulnessLifecycle wakefulnessLifecycle,
            @Main Executor sysUiMainExecutor) {
        super(context);
        mCommandQueue = commandQueue;
@@ -148,6 +152,7 @@ public final class WMShell extends SystemUI
        mSplitScreenOptional = splitScreenOptional;
        mOneHandedOptional = oneHandedOptional;
        mHideDisplayCutoutOptional = hideDisplayCutoutOptional;
        mWakefulnessLifecycle = wakefulnessLifecycle;
        mProtoTracer = protoTracer;
        mShellCommandHandler = shellCommandHandler;
        mSysUiMainExecutor = sysUiMainExecutor;
@@ -266,30 +271,35 @@ public final class WMShell extends SystemUI

        mOneHandedKeyguardCallback = new KeyguardUpdateMonitorCallback() {
            @Override
            public void onKeyguardBouncerChanged(boolean bouncer) {
                if (bouncer) {
            public void onKeyguardVisibilityChanged(boolean showing) {
                oneHanded.onKeyguardVisibilityChanged(showing);
                oneHanded.stopOneHanded();
            }

            @Override
            public void onUserSwitchComplete(int userId) {
                oneHanded.onUserSwitch(userId);
            }
        };
        mKeyguardUpdateMonitor.registerCallback(mOneHandedKeyguardCallback);

        mWakefulnessObserver =
                new WakefulnessLifecycle.Observer() {
                    @Override
            public void onKeyguardVisibilityChanged(boolean showing) {
                if (showing) {
                    // When keyguard shown, temperory lock OHM disabled to avoid mis-trigger.
                    oneHanded.setLockedDisabled(true /* locked */, false /* enabled */);
                } else {
                    // Reset locked.
                    public void onFinishedWakingUp() {
                        // Reset locked for the case keyguard not shown.
                        oneHanded.setLockedDisabled(false /* locked */, false /* enabled */);
                    }
                oneHanded.stopOneHanded();
            }

                    @Override
            public void onUserSwitchComplete(int userId) {
                oneHanded.onUserSwitch(userId);
                    public void onStartedGoingToSleep() {
                        oneHanded.stopOneHanded();
                        // When user press power button going to sleep, temperory lock OHM disabled
                        // to avoid mis-trigger.
                        oneHanded.setLockedDisabled(true /* locked */, false /* enabled */);
                    }
                };
        mKeyguardUpdateMonitor.registerCallback(mOneHandedKeyguardCallback);
        mWakefulnessLifecycle.addObserver(mWakefulnessObserver);

        mScreenLifecycle.addObserver(new ScreenLifecycle.Observer() {
            @Override
+4 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.keyguard.ScreenLifecycle;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.statusbar.CommandQueue;
@@ -70,6 +71,7 @@ public class WMShellTest extends SysuiTestCase {
    @Mock LegacySplitScreen mLegacySplitScreen;
    @Mock OneHanded mOneHanded;
    @Mock HideDisplayCutout mHideDisplayCutout;
    @Mock WakefulnessLifecycle mWakefulnessLifecycle;
    @Mock ProtoTracer mProtoTracer;
    @Mock ShellCommandHandler mShellCommandHandler;
    @Mock ShellExecutor mSysUiMainExecutor;
@@ -82,7 +84,8 @@ public class WMShellTest extends SysuiTestCase {
                Optional.of(mOneHanded), Optional.of(mHideDisplayCutout),
                Optional.of(mShellCommandHandler), mCommandQueue, mConfigurationController,
                mKeyguardUpdateMonitor, mNavigationModeController,
                mScreenLifecycle, mSysUiState, mProtoTracer, mSysUiMainExecutor);
                mScreenLifecycle, mSysUiState, mProtoTracer, mWakefulnessLifecycle,
                mSysUiMainExecutor);
    }

    @Test