From 2dccad6f94bea5bf3edaa21406c0eeb3eae2735b Mon Sep 17 00:00:00 2001 From: bquezada Date: Tue, 2 Mar 2021 19:47:48 +0000 Subject: [PATCH] Fix dim duration on flip to screen off. Timeouts are calculated from mLastUserActivityTime, so just calling updatePowerStateLocked will go to locked with almost no dim duration. Test: Tested with local device. Bug: 164517126 Change-Id: I084c13fada7613bd745ceb1dc2f7038097d70686 --- core/java/android/os/PowerManager.java | 7 +++++++ .../java/com/android/server/power/FaceDownDetector.java | 6 ++++-- services/core/java/com/android/server/power/Notifier.java | 7 ++++--- .../java/com/android/server/power/PowerManagerService.java | 7 +++---- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 786a7d08047e4..a19728c5c4985 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -322,6 +322,13 @@ public final class PowerManager { */ public static final int USER_ACTIVITY_EVENT_ATTENTION = 4; + /** + * User activity event type: {@link com.android.server.power.FaceDownDetector} taking action + * on behalf of user. + * @hide + */ + public static final int USER_ACTIVITY_EVENT_FACE_DOWN = 5; + /** * User activity flag: If already dimmed, extend the dim timeout * but do not brighten. This flag is useful for keeping the screen on diff --git a/services/core/java/com/android/server/power/FaceDownDetector.java b/services/core/java/com/android/server/power/FaceDownDetector.java index fe9663aaabe5c..676181dcfb679 100644 --- a/services/core/java/com/android/server/power/FaceDownDetector.java +++ b/services/core/java/com/android/server/power/FaceDownDetector.java @@ -291,8 +291,10 @@ public class FaceDownDetector implements SensorEventListener { * The user interacted with the screen while face down, indicated the phone is in use. * We log this event and temporarily make this detector inactive. */ - public void userActivity() { - mHandler.post(mUserActivityRunnable); + public void userActivity(int event) { + if (event != PowerManager.USER_ACTIVITY_EVENT_FACE_DOWN) { + mHandler.post(mUserActivityRunnable); + } } private void exitFaceDown(int resultType, long millisSinceFlip) { diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java index f49e2f1631b93..7555a7f2920bd 100644 --- a/services/core/java/com/android/server/power/Notifier.java +++ b/services/core/java/com/android/server/power/Notifier.java @@ -549,6 +549,7 @@ public class Notifier { if (!mUserActivityPending) { mUserActivityPending = true; Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY); + msg.arg1 = event; msg.setAsynchronous(true); mHandler.sendMessage(msg); } @@ -647,7 +648,7 @@ public class Notifier { mSuspendBlocker.release(); } - private void sendUserActivity() { + private void sendUserActivity(int event) { synchronized (mLock) { if (!mUserActivityPending) { return; @@ -657,7 +658,7 @@ public class Notifier { TelephonyManager tm = mContext.getSystemService(TelephonyManager.class); tm.notifyUserActivity(); mPolicy.userActivity(); - mFaceDownDetector.userActivity(); + mFaceDownDetector.userActivity(event); } void postEnhancedDischargePredictionBroadcast(long delayMs) { @@ -833,7 +834,7 @@ public class Notifier { public void handleMessage(Message msg) { switch (msg.what) { case MSG_USER_ACTIVITY: - sendUserActivity(); + sendUserActivity(msg.arg1); break; case MSG_BROADCAST: sendNextBroadcast(); diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 29adde37ab3b4..d2a4cd604c017 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -180,8 +180,6 @@ public final class PowerManagerService extends SystemService private static final int DIRTY_VR_MODE_CHANGED = 1 << 13; // Dirty bit: attentive timer may have timed out private static final int DIRTY_ATTENTIVE = 1 << 14; - // Dirty bit: phone flipped to face down - private static final int DIRTY_FACE_DOWN = 1 << 15; // Dirty bit: display group power state has changed private static final int DIRTY_DISPLAY_GROUP_POWER_UPDATED = 1 << 16; @@ -1069,8 +1067,9 @@ public final class PowerManagerService extends SystemService final long screenOffTimeout = getScreenOffTimeoutLocked(sleepTimeout, -1L); millisUntilNormalTimeout = mLastUserActivityTime + screenOffTimeout - mClock.uptimeMillis(); - mDirty |= DIRTY_FACE_DOWN; - updatePowerStateLocked(); + userActivityInternal(mClock.uptimeMillis(), + PowerManager.USER_ACTIVITY_EVENT_FACE_DOWN, /* flags= */0, + Process.SYSTEM_UID); } } if (isFaceDown) {