Hook WakefulnessLifecycle for best timing of LockedDisabled

1. Sets LockedDisabled when onStartedGoingToSleep()
2. Reset LockedDisabled when onFinishedWakingUp()
3. Update keyguard showing state to controller through
   onKeyguardVisibilityChanged(showing)

The flow changes:
 1) POWER-KEY going to sleep(AOD)
 2) onStartedGoingToSleep()   <--New timing for LockedDisabled
 3) onFinishedGoingToSleep()
 4) onKeyguardVisibilityChanged(true) <--Legacy LockedDisabled
 ---------------
 1) POWER-KEY waking up to HOME
 2) onStartedWakingUp()
 3) onFinishedWakingUp()
 4) onKeyguardVisibilityChanged(false) <--Reset LockedDisabled

Screen OFF to AOD flow takes about 1800ms:
  POWER_KEY---(400ms)---> onStartedGoingToSleep()---(100ms)--->
  onFinishedGoingToSleep()---(1300ms)--->onKeyguardVisibilityChanged()

Screen ON to HOME flow takes about 700ms:
  POWER_KEY---(50ms)---> onStartedWakingUp()---(160ms)--->
  onFinishedWakingUp()---(500ms)---> onKeyguardVisibilityChanged()

Test: Manual PowerKey going to sleep > Trigger One Handed mode
Test: atest WMShellUnitTests
Bug: 191149165
Change-Id: I557ab4736d0f77b38334fb95d89dcf0875fc5be2
This commit is contained in:
Bill Lin
2021-06-17 02:46:05 +08:00
parent 60ec24eb1e
commit 4f4b74bbce
4 changed files with 46 additions and 16 deletions

View File

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

View File

@@ -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);
});
}
}
/**

View File

@@ -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;
@@ -265,22 +270,9 @@ public final class WMShell extends SystemUI
});
mOneHandedKeyguardCallback = new KeyguardUpdateMonitorCallback() {
@Override
public void onKeyguardBouncerChanged(boolean bouncer) {
if (bouncer) {
oneHanded.stopOneHanded();
}
}
@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.
oneHanded.setLockedDisabled(false /* locked */, false /* enabled */);
}
oneHanded.onKeyguardVisibilityChanged(showing);
oneHanded.stopOneHanded();
}
@@ -291,6 +283,24 @@ public final class WMShell extends SystemUI
};
mKeyguardUpdateMonitor.registerCallback(mOneHandedKeyguardCallback);
mWakefulnessObserver =
new WakefulnessLifecycle.Observer() {
@Override
public void onFinishedWakingUp() {
// Reset locked for the case keyguard not shown.
oneHanded.setLockedDisabled(false /* locked */, false /* enabled */);
}
@Override
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 */);
}
};
mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
mScreenLifecycle.addObserver(new ScreenLifecycle.Observer() {
@Override
public void onScreenTurningOff() {

View File

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