Loading cmds/statsd/src/atoms.proto +76 −63 Original line number Diff line number Diff line Loading @@ -234,6 +234,7 @@ message Atom { BluetoothBondStateChanged bluetooth_bond_state_changed = 165; BluetoothClassicPairingEventReported bluetooth_classic_pairing_event_reported = 166; BluetoothSmpPairingEventReported bluetooth_smp_pairing_event_reported = 167; ScreenTimeoutExtensionReported screen_timeout_extension_reported = 168; } // Pulled events will start at field 10000. Loading Loading @@ -5290,3 +5291,15 @@ message ScheduledJobConstraintChanged { } optional State state = 4; } /** * Logs PowerManagerService screen timeout resets (extensions) that happen when an attention check * returns true. * * Logged from: * frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java */ message ScreenTimeoutExtensionReported { // Describes how many times in a row did the power manager reset the screen off timeout. optional uint32 consecutive_timeout_extended_count = 1; } services/core/java/com/android/server/power/AttentionDetector.java +19 −0 Original line number Diff line number Diff line Loading @@ -24,11 +24,13 @@ import android.os.PowerManagerInternal; import android.os.SystemClock; import android.service.attention.AttentionService; import android.util.Slog; import android.util.StatsLog; import com.android.internal.annotations.VisibleForTesting; import com.android.server.LocalServices; import java.io.PrintWriter; import java.util.concurrent.atomic.AtomicLong; /** * Class responsible for checking if the user is currently paying attention to the phone and Loading Loading @@ -79,6 +81,11 @@ public class AttentionDetector { */ private int mWakefulness; /** * Describes how many times in a row was the timeout extended. */ private AtomicLong mConsecutiveTimeoutExtendedCount = new AtomicLong(0); @VisibleForTesting final AttentionCallbackInternal mCallback = new AttentionCallbackInternal() { Loading @@ -95,6 +102,8 @@ public class AttentionDetector { } if (result == AttentionService.ATTENTION_SUCCESS_PRESENT) { mOnUserAttention.run(); } else { resetConsecutiveExtensionCount(); } } } Loading Loading @@ -176,6 +185,7 @@ public class AttentionDetector { public int onUserActivity(long eventTime, int event) { switch (event) { case PowerManager.USER_ACTIVITY_EVENT_ATTENTION: mConsecutiveTimeoutExtendedCount.incrementAndGet(); return 0; case PowerManager.USER_ACTIVITY_EVENT_OTHER: case PowerManager.USER_ACTIVITY_EVENT_BUTTON: Loading @@ -183,6 +193,7 @@ public class AttentionDetector { case PowerManager.USER_ACTIVITY_EVENT_ACCESSIBILITY: cancelCurrentRequestIfAny(); mLastUserActivityTime = eventTime; resetConsecutiveExtensionCount(); return 1; default: if (DEBUG) { Loading @@ -196,6 +207,7 @@ public class AttentionDetector { mWakefulness = wakefulness; if (wakefulness != PowerManagerInternal.WAKEFULNESS_AWAKE) { cancelCurrentRequestIfAny(); resetConsecutiveExtensionCount(); } } Loading @@ -206,6 +218,13 @@ public class AttentionDetector { } } private void resetConsecutiveExtensionCount() { final long previousCount = mConsecutiveTimeoutExtendedCount.getAndSet(0); if (previousCount > 0) { StatsLog.write(StatsLog.SCREEN_TIMEOUT_EXTENSION_REPORTED, previousCount); } } @VisibleForTesting int getRequestCode() { return (int) (mLastUserActivityTime % Integer.MAX_VALUE); Loading Loading
cmds/statsd/src/atoms.proto +76 −63 Original line number Diff line number Diff line Loading @@ -234,6 +234,7 @@ message Atom { BluetoothBondStateChanged bluetooth_bond_state_changed = 165; BluetoothClassicPairingEventReported bluetooth_classic_pairing_event_reported = 166; BluetoothSmpPairingEventReported bluetooth_smp_pairing_event_reported = 167; ScreenTimeoutExtensionReported screen_timeout_extension_reported = 168; } // Pulled events will start at field 10000. Loading Loading @@ -5290,3 +5291,15 @@ message ScheduledJobConstraintChanged { } optional State state = 4; } /** * Logs PowerManagerService screen timeout resets (extensions) that happen when an attention check * returns true. * * Logged from: * frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java */ message ScreenTimeoutExtensionReported { // Describes how many times in a row did the power manager reset the screen off timeout. optional uint32 consecutive_timeout_extended_count = 1; }
services/core/java/com/android/server/power/AttentionDetector.java +19 −0 Original line number Diff line number Diff line Loading @@ -24,11 +24,13 @@ import android.os.PowerManagerInternal; import android.os.SystemClock; import android.service.attention.AttentionService; import android.util.Slog; import android.util.StatsLog; import com.android.internal.annotations.VisibleForTesting; import com.android.server.LocalServices; import java.io.PrintWriter; import java.util.concurrent.atomic.AtomicLong; /** * Class responsible for checking if the user is currently paying attention to the phone and Loading Loading @@ -79,6 +81,11 @@ public class AttentionDetector { */ private int mWakefulness; /** * Describes how many times in a row was the timeout extended. */ private AtomicLong mConsecutiveTimeoutExtendedCount = new AtomicLong(0); @VisibleForTesting final AttentionCallbackInternal mCallback = new AttentionCallbackInternal() { Loading @@ -95,6 +102,8 @@ public class AttentionDetector { } if (result == AttentionService.ATTENTION_SUCCESS_PRESENT) { mOnUserAttention.run(); } else { resetConsecutiveExtensionCount(); } } } Loading Loading @@ -176,6 +185,7 @@ public class AttentionDetector { public int onUserActivity(long eventTime, int event) { switch (event) { case PowerManager.USER_ACTIVITY_EVENT_ATTENTION: mConsecutiveTimeoutExtendedCount.incrementAndGet(); return 0; case PowerManager.USER_ACTIVITY_EVENT_OTHER: case PowerManager.USER_ACTIVITY_EVENT_BUTTON: Loading @@ -183,6 +193,7 @@ public class AttentionDetector { case PowerManager.USER_ACTIVITY_EVENT_ACCESSIBILITY: cancelCurrentRequestIfAny(); mLastUserActivityTime = eventTime; resetConsecutiveExtensionCount(); return 1; default: if (DEBUG) { Loading @@ -196,6 +207,7 @@ public class AttentionDetector { mWakefulness = wakefulness; if (wakefulness != PowerManagerInternal.WAKEFULNESS_AWAKE) { cancelCurrentRequestIfAny(); resetConsecutiveExtensionCount(); } } Loading @@ -206,6 +218,13 @@ public class AttentionDetector { } } private void resetConsecutiveExtensionCount() { final long previousCount = mConsecutiveTimeoutExtendedCount.getAndSet(0); if (previousCount > 0) { StatsLog.write(StatsLog.SCREEN_TIMEOUT_EXTENSION_REPORTED, previousCount); } } @VisibleForTesting int getRequestCode() { return (int) (mLastUserActivityTime % Integer.MAX_VALUE); Loading