Merge "Ignore wake up calls when lid closed" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a15c48860b
@@ -6009,6 +6009,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
mKeyguardDelegate.setSwitchingUser(switching);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WindowManagerFuncs.LidState
|
||||
public int getLidState() {
|
||||
return mDefaultDisplayPolicy.getLidState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dumpDebug(ProtoOutputStream proto, long fieldId) {
|
||||
final long token = proto.start(fieldId);
|
||||
|
||||
@@ -218,6 +218,14 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
|
||||
* between it and the policy.
|
||||
*/
|
||||
public interface WindowManagerFuncs {
|
||||
@IntDef(prefix = { "LID_" }, value = {
|
||||
LID_ABSENT,
|
||||
LID_CLOSED,
|
||||
LID_OPEN,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface LidState{}
|
||||
|
||||
public static final int LID_ABSENT = -1;
|
||||
public static final int LID_CLOSED = 0;
|
||||
public static final int LID_OPEN = 1;
|
||||
@@ -231,8 +239,9 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
|
||||
public static final int CAMERA_LENS_COVERED = 1;
|
||||
|
||||
/**
|
||||
* Returns a code that describes the current state of the lid switch.
|
||||
* Returns a {@link LidState} that describes the current state of the lid switch.
|
||||
*/
|
||||
@LidState
|
||||
public int getLidState();
|
||||
|
||||
/**
|
||||
@@ -282,7 +291,7 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
|
||||
/**
|
||||
* Convert the lid state to a human readable format.
|
||||
*/
|
||||
static String lidStateToString(int lid) {
|
||||
static String lidStateToString(@LidState int lid) {
|
||||
switch (lid) {
|
||||
case LID_ABSENT:
|
||||
return "LID_ABSENT";
|
||||
@@ -1241,4 +1250,11 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
|
||||
* @return {@code true} if the key will be handled globally.
|
||||
*/
|
||||
boolean isGlobalKey(int keyCode);
|
||||
|
||||
/**
|
||||
* Returns a {@link WindowManagerFuncs.LidState} that describes the current state of
|
||||
* the lid switch.
|
||||
*/
|
||||
@WindowManagerFuncs.LidState
|
||||
int getLidState();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import static android.os.PowerManagerInternal.isInteractive;
|
||||
import static android.os.PowerManagerInternal.wakefulnessToString;
|
||||
|
||||
import static com.android.internal.util.LatencyTracker.ACTION_TURN_ON_SCREEN;
|
||||
import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
@@ -5733,6 +5734,11 @@ public final class PowerManagerService extends SystemService
|
||||
@Override // Binder call
|
||||
public void wakeUp(long eventTime, @WakeReason int reason, String details,
|
||||
String opPackageName) {
|
||||
if (mPolicy.getLidState() == LID_CLOSED) {
|
||||
Slog.d(TAG, "Ignoring wake up call due to the lid being closed");
|
||||
return;
|
||||
}
|
||||
|
||||
final long now = mClock.uptimeMillis();
|
||||
if (eventTime > now) {
|
||||
Slog.e(TAG, "Event time " + eventTime + " cannot be newer than " + now);
|
||||
|
||||
@@ -225,6 +225,7 @@ public class DisplayPolicy {
|
||||
/** Currently it can only be non-null when physical display switch happens. */
|
||||
private DecorInsets.Cache mCachedDecorInsets;
|
||||
|
||||
@WindowManagerFuncs.LidState
|
||||
private volatile int mLidState = LID_ABSENT;
|
||||
private volatile int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
|
||||
private volatile boolean mHdmiPlugged;
|
||||
@@ -752,10 +753,11 @@ public class DisplayPolicy {
|
||||
return mNavigationBarCanMove;
|
||||
}
|
||||
|
||||
public void setLidState(int lidState) {
|
||||
public void setLidState(@WindowManagerFuncs.LidState int lidState) {
|
||||
mLidState = lidState;
|
||||
}
|
||||
|
||||
@WindowManagerFuncs.LidState
|
||||
public int getLidState() {
|
||||
return mLidState;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE;
|
||||
import static android.os.PowerManagerInternal.WAKEFULNESS_DOZING;
|
||||
import static android.os.PowerManagerInternal.WAKEFULNESS_DREAMING;
|
||||
|
||||
import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
|
||||
import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -145,6 +148,7 @@ public class PowerManagerServiceTest {
|
||||
@Mock private ActivityManagerInternal mActivityManagerInternalMock;
|
||||
@Mock private AttentionManagerInternal mAttentionManagerInternalMock;
|
||||
@Mock private DreamManagerInternal mDreamManagerInternalMock;
|
||||
@Mock private WindowManagerPolicy mPolicyMock;
|
||||
@Mock private PowerManagerService.NativeWrapper mNativeWrapperMock;
|
||||
@Mock private Notifier mNotifierMock;
|
||||
@Mock private WirelessChargerDetector mWirelessChargerDetectorMock;
|
||||
@@ -205,6 +209,7 @@ public class PowerManagerServiceTest {
|
||||
.thenReturn(true);
|
||||
when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), anyString())).thenReturn("");
|
||||
when(mAmbientDisplayConfigurationMock.ambientDisplayAvailable()).thenReturn(true);
|
||||
when(mPolicyMock.getLidState()).thenReturn(LID_ABSENT);
|
||||
|
||||
addLocalServiceMock(LightsManager.class, mLightsManagerMock);
|
||||
addLocalServiceMock(DisplayManagerInternal.class, mDisplayManagerInternalMock);
|
||||
@@ -212,6 +217,7 @@ public class PowerManagerServiceTest {
|
||||
addLocalServiceMock(ActivityManagerInternal.class, mActivityManagerInternalMock);
|
||||
addLocalServiceMock(AttentionManagerInternal.class, mAttentionManagerInternalMock);
|
||||
addLocalServiceMock(DreamManagerInternal.class, mDreamManagerInternalMock);
|
||||
addLocalServiceMock(WindowManagerPolicy.class, mPolicyMock);
|
||||
|
||||
mContextSpy = spy(new ContextWrapper(ApplicationProvider.getApplicationContext()));
|
||||
mResourcesSpy = spy(mContextSpy.getResources());
|
||||
@@ -678,6 +684,20 @@ public class PowerManagerServiceTest {
|
||||
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWakefulnessAwake_ShouldNotWakeUpWhenLidClosed() {
|
||||
when(mPolicyMock.getLidState()).thenReturn(LID_CLOSED);
|
||||
createService();
|
||||
startSystem();
|
||||
forceSleep();
|
||||
|
||||
mService.getBinderServiceInstance().wakeUp(mClock.now(),
|
||||
PowerManager.WAKE_REASON_POWER_BUTTON,
|
||||
"testing IPowerManager.wakeUp()", "pkg.name");
|
||||
|
||||
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a series of variants that control whether a device wakes-up when it is plugged in
|
||||
* or docked.
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.android.server.wm;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE;
|
||||
|
||||
import static com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
@@ -354,4 +356,9 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
|
||||
public boolean isGlobalKey(int keyCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLidState() {
|
||||
return LID_ABSENT;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user