Loading services/core/java/com/android/server/power/Notifier.java +26 −1 Original line number Diff line number Diff line Loading @@ -503,6 +503,31 @@ public class Notifier { } } @VisibleForTesting int getWakelockMonitorTypeForLogging(int flags) { switch (flags & PowerManager.WAKE_LOCK_LEVEL_MASK) { case PowerManager.FULL_WAKE_LOCK, PowerManager.SCREEN_DIM_WAKE_LOCK, PowerManager.SCREEN_BRIGHT_WAKE_LOCK: return PowerManager.FULL_WAKE_LOCK; case PowerManager.DRAW_WAKE_LOCK: return PowerManager.DRAW_WAKE_LOCK; case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK: if (mSuspendWhenScreenOffDueToProximityConfig) { return -1; } return PowerManager.PARTIAL_WAKE_LOCK; case PowerManager.PARTIAL_WAKE_LOCK: return PowerManager.PARTIAL_WAKE_LOCK; case PowerManager.DOZE_WAKE_LOCK: // Doze wake locks are an internal implementation detail of the // communication between dream manager service and power manager // service. They have no additive battery impact. return -1; default: return -1; } } /** * Notifies that the device is changing wakefulness. * This function may be called even if the previous change hasn't finished in Loading Loading @@ -1288,7 +1313,7 @@ public class Notifier { if (mBatteryStatsInternal == null) { return; } final int type = flags & PowerManager.WAKE_LOCK_LEVEL_MASK; final int type = getWakelockMonitorTypeForLogging(flags); if (workSource == null || workSource.isEmpty()) { final int mappedUid = mBatteryStatsInternal.getOwnerUid(ownerUid); mFrameworkStatsLogger.wakelockStateChanged(mappedUid, tag, type, eventType); Loading services/tests/powerservicetests/src/com/android/server/power/NotifierTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -889,6 +890,32 @@ public class NotifierTest { "my.package.name", false, null, null); } @Test public void getWakelockMonitorTypeForLogging_evaluatesWakelockLevel() { createNotifier(); assertEquals(mNotifier.getWakelockMonitorTypeForLogging(PowerManager.SCREEN_DIM_WAKE_LOCK), PowerManager.FULL_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging( PowerManager.SCREEN_BRIGHT_WAKE_LOCK), PowerManager.FULL_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging(PowerManager.DRAW_WAKE_LOCK), PowerManager.DRAW_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging(PowerManager.PARTIAL_WAKE_LOCK), PowerManager.PARTIAL_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging( PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK), PowerManager.PARTIAL_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging( PowerManager.DOZE_WAKE_LOCK), -1); when(mResourcesSpy.getBoolean( com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity)) .thenReturn(true); createNotifier(); assertEquals(mNotifier.getWakelockMonitorTypeForLogging( PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK), -1); } private final PowerManagerService.Injector mInjector = new PowerManagerService.Injector() { @Override Notifier createNotifier(Looper looper, Context context, IBatteryStats batteryStats, Loading Loading
services/core/java/com/android/server/power/Notifier.java +26 −1 Original line number Diff line number Diff line Loading @@ -503,6 +503,31 @@ public class Notifier { } } @VisibleForTesting int getWakelockMonitorTypeForLogging(int flags) { switch (flags & PowerManager.WAKE_LOCK_LEVEL_MASK) { case PowerManager.FULL_WAKE_LOCK, PowerManager.SCREEN_DIM_WAKE_LOCK, PowerManager.SCREEN_BRIGHT_WAKE_LOCK: return PowerManager.FULL_WAKE_LOCK; case PowerManager.DRAW_WAKE_LOCK: return PowerManager.DRAW_WAKE_LOCK; case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK: if (mSuspendWhenScreenOffDueToProximityConfig) { return -1; } return PowerManager.PARTIAL_WAKE_LOCK; case PowerManager.PARTIAL_WAKE_LOCK: return PowerManager.PARTIAL_WAKE_LOCK; case PowerManager.DOZE_WAKE_LOCK: // Doze wake locks are an internal implementation detail of the // communication between dream manager service and power manager // service. They have no additive battery impact. return -1; default: return -1; } } /** * Notifies that the device is changing wakefulness. * This function may be called even if the previous change hasn't finished in Loading Loading @@ -1288,7 +1313,7 @@ public class Notifier { if (mBatteryStatsInternal == null) { return; } final int type = flags & PowerManager.WAKE_LOCK_LEVEL_MASK; final int type = getWakelockMonitorTypeForLogging(flags); if (workSource == null || workSource.isEmpty()) { final int mappedUid = mBatteryStatsInternal.getOwnerUid(ownerUid); mFrameworkStatsLogger.wakelockStateChanged(mappedUid, tag, type, eventType); Loading
services/tests/powerservicetests/src/com/android/server/power/NotifierTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -889,6 +890,32 @@ public class NotifierTest { "my.package.name", false, null, null); } @Test public void getWakelockMonitorTypeForLogging_evaluatesWakelockLevel() { createNotifier(); assertEquals(mNotifier.getWakelockMonitorTypeForLogging(PowerManager.SCREEN_DIM_WAKE_LOCK), PowerManager.FULL_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging( PowerManager.SCREEN_BRIGHT_WAKE_LOCK), PowerManager.FULL_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging(PowerManager.DRAW_WAKE_LOCK), PowerManager.DRAW_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging(PowerManager.PARTIAL_WAKE_LOCK), PowerManager.PARTIAL_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging( PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK), PowerManager.PARTIAL_WAKE_LOCK); assertEquals(mNotifier.getWakelockMonitorTypeForLogging( PowerManager.DOZE_WAKE_LOCK), -1); when(mResourcesSpy.getBoolean( com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity)) .thenReturn(true); createNotifier(); assertEquals(mNotifier.getWakelockMonitorTypeForLogging( PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK), -1); } private final PowerManagerService.Injector mInjector = new PowerManagerService.Injector() { @Override Notifier createNotifier(Looper looper, Context context, IBatteryStats batteryStats, Loading