Don't trigger lift-to-wake on wireless charger

Test: atest DozeTriggersTest
Fixes: 198154565
Change-Id: I8c815186c34b8b84f3d2ba27e66e7423f7b580e5
This commit is contained in:
Beverly
2022-02-02 20:29:18 +00:00
committed by Beverly Tai
parent d7c5ca769d
commit a874fa40d7
3 changed files with 52 additions and 9 deletions

View File

@@ -41,6 +41,7 @@ import com.android.systemui.dock.DockManager;
import com.android.systemui.doze.DozeMachine.State;
import com.android.systemui.doze.dagger.DozeScope;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.Assert;
@@ -96,6 +97,7 @@ public class DozeTriggers implements DozeMachine.Part {
private final AuthController mAuthController;
private final DelayableExecutor mMainExecutor;
private final KeyguardStateController mKeyguardStateController;
private final BatteryController mBatteryController;
private final UiEventLogger mUiEventLogger;
private final DevicePostureController mDevicePostureController;
@@ -187,7 +189,8 @@ public class DozeTriggers implements DozeMachine.Part {
@Main DelayableExecutor mainExecutor,
UiEventLogger uiEventLogger,
KeyguardStateController keyguardStateController,
DevicePostureController devicePostureController) {
DevicePostureController devicePostureController,
BatteryController batteryController) {
mContext = context;
mDozeHost = dozeHost;
mConfig = config;
@@ -210,6 +213,7 @@ public class DozeTriggers implements DozeMachine.Part {
mMainExecutor = mainExecutor;
mUiEventLogger = uiEventLogger;
mKeyguardStateController = keyguardStateController;
mBatteryController = batteryController;
}
private final DevicePostureController.Callback mDevicePostureCallback =
posture -> {
@@ -320,7 +324,12 @@ public class DozeTriggers implements DozeMachine.Part {
gentleWakeUp(pulseReason);
} else if (isPickup) {
if (shouldDropPickupEvent()) {
mDozeLog.traceSensorEventDropped(pulseReason, "keyguard occluded");
mDozeLog.traceSensorEventDropped(
pulseReason,
"keyguardOccluded="
+ mKeyguardStateController.isOccluded()
+ " pluggedInWireless="
+ mBatteryController.isPluggedInWireless());
return;
}
gentleWakeUp(pulseReason);
@@ -351,7 +360,7 @@ public class DozeTriggers implements DozeMachine.Part {
}
private boolean shouldDropPickupEvent() {
return mKeyguardStateController.isOccluded();
return mKeyguardStateController.isOccluded() || mBatteryController.isPluggedInWireless();
}
private void gentleWakeUp(int reason) {

View File

@@ -45,6 +45,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dock.DockManager;
import com.android.systemui.doze.DozeTriggers.DozingUpdateUiEvent;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.concurrency.FakeExecutor;
@@ -90,6 +91,8 @@ public class DozeTriggersTest extends SysuiTestCase {
private KeyguardStateController mKeyguardStateController;
@Mock
private DevicePostureController mDevicePostureController;
@Mock
private BatteryController mBatteryController;
private DozeTriggers mTriggers;
private FakeSensorManager mSensors;
@@ -122,7 +125,7 @@ public class DozeTriggersTest extends SysuiTestCase {
asyncSensorManager, wakeLock, mDockManager, mProximitySensor,
mProximityCheck, mock(DozeLog.class), mBroadcastDispatcher, new FakeSettings(),
mAuthController, mExecutor, mUiEventLogger, mKeyguardStateController,
mDevicePostureController);
mDevicePostureController, mBatteryController);
mTriggers.setDozeMachine(mMachine);
waitForSensorManager();
}
@@ -230,7 +233,9 @@ public class DozeTriggersTest extends SysuiTestCase {
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
// WHEN the pick up gesture is triggered and keyguard isn't occluded
// and device isn't on a wireless charger
when(mKeyguardStateController.isOccluded()).thenReturn(false);
when(mBatteryController.isPluggedInWireless()).thenReturn(false);
mTriggers.onSensor(DozeLog.REASON_SENSOR_PICKUP, 100, 100, null);
// THEN wakeup
@@ -244,6 +249,22 @@ public class DozeTriggersTest extends SysuiTestCase {
// WHEN the pick up gesture is triggered and keyguard IS occluded
when(mKeyguardStateController.isOccluded()).thenReturn(true);
when(mBatteryController.isPluggedInWireless()).thenReturn(false);
mTriggers.onSensor(DozeLog.REASON_SENSOR_PICKUP, 100, 100, null);
// THEN never wakeup
verify(mMachine, never()).wakeUp();
}
@Test
public void testPickupGestureWirelessCharger() {
// GIVEN device is in doze (screen blank, but running doze sensors)
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
// WHEN the pick up gesture is triggered
// and device IS on a wireless charger
when(mKeyguardStateController.isOccluded()).thenReturn(false);
when(mBatteryController.isPluggedInWireless()).thenReturn(true);
mTriggers.onSensor(DozeLog.REASON_SENSOR_PICKUP, 100, 100, null);
// THEN never wakeup

View File

@@ -27,6 +27,7 @@ import static android.content.pm.PackageManager.FEATURE_LEANBACK;
import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
import static android.content.pm.PackageManager.FEATURE_WATCH;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.BatteryManager.BATTERY_PLUGGED_WIRELESS;
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.O;
import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
@@ -129,6 +130,7 @@ import android.media.AudioManagerInternal;
import android.media.AudioSystem;
import android.media.IAudioService;
import android.media.session.MediaSessionLegacyHelper;
import android.os.BatteryManagerInternal;
import android.os.Binder;
import android.os.Bundle;
import android.os.DeviceIdleManager;
@@ -392,11 +394,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
PowerManagerInternal mPowerManagerInternal;
IStatusBarService mStatusBarService;
StatusBarManagerInternal mStatusBarManagerInternal;
BatteryManagerInternal mBatteryManagerInternal;
AudioManagerInternal mAudioManagerInternal;
DisplayManager mDisplayManager;
DisplayManagerInternal mDisplayManagerInternal;
boolean mPreloadedRecentApps;
final Object mServiceAquireLock = new Object();
final Object mServiceAcquireLock = new Object();
Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
SearchManager mSearchManager;
AccessibilityManager mAccessibilityManager;
@@ -782,7 +785,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
@Override
public void onWakeUp() {
synchronized (mLock) {
if (shouldEnableWakeGestureLp()) {
if (shouldEnableWakeGestureLp()
&& mBatteryManagerInternal.getPlugType() != BATTERY_PLUGGED_WIRELESS) {
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, false,
"Wake Up");
wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
@@ -811,7 +815,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
IStatusBarService getStatusBarService() {
synchronized (mServiceAquireLock) {
synchronized (mServiceAcquireLock) {
if (mStatusBarService == null) {
mStatusBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService("statusbar"));
@@ -821,7 +825,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
StatusBarManagerInternal getStatusBarManagerInternal() {
synchronized (mServiceAquireLock) {
synchronized (mServiceAcquireLock) {
if (mStatusBarManagerInternal == null) {
mStatusBarManagerInternal =
LocalServices.getService(StatusBarManagerInternal.class);
@@ -831,7 +835,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
AudioManagerInternal getAudioManagerInternal() {
synchronized (mServiceAquireLock) {
synchronized (mServiceAcquireLock) {
if (mAudioManagerInternal == null) {
mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class);
}
@@ -839,6 +843,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
BatteryManagerInternal getBatteryManagerInternal() {
synchronized (mServiceAcquireLock) {
if (mBatteryManagerInternal == null) {
mBatteryManagerInternal =
LocalServices.getService(BatteryManagerInternal.class);
}
return mBatteryManagerInternal;
}
}
// returns true if the key was handled and should not be passed to the user
private boolean backKeyPress() {