Merge "Don't poke user activity when dream ends" into tm-dev am: 3f31afd1cf

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17135323

Change-Id: I8f09bf4f684b1620a9432d61b88095f66b987fd8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Robert Horvath
2022-03-31 07:36:44 +00:00
committed by Automerger Merge Worker
3 changed files with 36 additions and 3 deletions

View File

@@ -566,7 +566,8 @@ public final class PowerManager {
WAKE_REASON_HDMI,
WAKE_REASON_DISPLAY_GROUP_ADDED,
WAKE_REASON_DISPLAY_GROUP_TURNED_ON,
WAKE_REASON_UNFOLD_DEVICE
WAKE_REASON_UNFOLD_DEVICE,
WAKE_REASON_DREAM_FINISHED
})
@Retention(RetentionPolicy.SOURCE)
public @interface WakeReason{}
@@ -672,6 +673,12 @@ public final class PowerManager {
*/
public static final int WAKE_REASON_UNFOLD_DEVICE = 12;
/**
* Wake up reason code: Waking the device due to the dream finishing.
* @hide
*/
public static final int WAKE_REASON_DREAM_FINISHED = 13;
/**
* Convert the wake reason to a string for debugging purposes.
* @hide
@@ -691,6 +698,7 @@ public final class PowerManager {
case WAKE_REASON_DISPLAY_GROUP_ADDED: return "WAKE_REASON_DISPLAY_GROUP_ADDED";
case WAKE_REASON_DISPLAY_GROUP_TURNED_ON: return "WAKE_REASON_DISPLAY_GROUP_TURNED_ON";
case WAKE_REASON_UNFOLD_DEVICE: return "WAKE_REASON_UNFOLD_DEVICE";
case WAKE_REASON_DREAM_FINISHED: return "WAKE_REASON_DREAM_FINISHED";
default: return Integer.toString(wakeReason);
}
}

View File

@@ -669,8 +669,12 @@ public final class PowerManagerService extends SystemService
int reason, int uid, int opUid, String opPackageName, String details) {
if (wakefulness == WAKEFULNESS_AWAKE) {
// Kick user activity to prevent newly awake group from timing out instantly.
// The dream may end without user activity if the dream app crashes / is updated,
// don't poke the user activity timer for these wakes.
int flags = reason == PowerManager.WAKE_REASON_DREAM_FINISHED
? PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS : 0;
userActivityNoUpdateLocked(mPowerGroups.get(groupId), eventTime,
PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, uid);
PowerManager.USER_ACTIVITY_EVENT_OTHER, flags, uid);
}
mDirty |= DIRTY_DISPLAY_GROUP_WAKEFULNESS;
updateGlobalWakefulnessLocked(eventTime, reason, uid, opUid, opPackageName, details);
@@ -3275,7 +3279,7 @@ public final class PowerManagerService extends SystemService
}
} else {
wakePowerGroupLocked(powerGroup, now,
PowerManager.WAKE_REASON_UNKNOWN,
PowerManager.WAKE_REASON_DREAM_FINISHED,
"android.server.power:DREAM_FINISHED", Process.SYSTEM_UID,
mContext.getOpPackageName(), Process.SYSTEM_UID);
}

View File

@@ -930,6 +930,27 @@ public class PowerManagerServiceTest {
PowerManager.GO_TO_SLEEP_REASON_INATTENTIVE);
}
@Test
public void testInattentiveSleep_dreamEnds_goesToSleepAfterTimeout() {
setMinimumScreenOffTimeoutConfig(5);
setAttentiveTimeout(30000);
createService();
startSystem();
advanceTime(10000);
forceDream();
advanceTime(10000);
final String pkg = mContextSpy.getOpPackageName();
mService.getBinderServiceInstance().wakeUp(mClock.now(),
PowerManager.WAKE_REASON_DREAM_FINISHED, "PowerManagerServiceTest:DREAM_FINISHED",
pkg);
advanceTime(10001);
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
assertThat(mService.getBinderServiceInstance().getLastSleepReason()).isEqualTo(
PowerManager.GO_TO_SLEEP_REASON_INATTENTIVE);
}
@Test
public void testScreenOffTimeout_goesToSleepAfterTimeout() {
final DisplayInfo info = new DisplayInfo();