Merge "Add screen timeout extension event to statsd"

This commit is contained in:
Alex Salo
2019-01-31 02:27:42 +00:00
committed by Android (Google) Code Review
2 changed files with 95 additions and 63 deletions

View File

@@ -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.
@@ -4983,17 +4984,17 @@ message GnssConfigurationReported {
* packages/apps/Nfc/src/com/android/nfc/cardemulation/AidRoutingManager.java
*/
message NfcErrorOccurred {
enum Type {
UNKNOWN = 0;
CMD_TIMEOUT = 1;
ERROR_NOTIFICATION = 2;
AID_OVERFLOW = 3;
}
optional Type type = 1;
// If it's nci cmd timeout, log the timeout command.
optional uint32 nci_cmd = 2;
enum Type {
UNKNOWN = 0;
CMD_TIMEOUT = 1;
ERROR_NOTIFICATION = 2;
AID_OVERFLOW = 3;
}
optional Type type = 1;
// If it's nci cmd timeout, log the timeout command.
optional uint32 nci_cmd = 2;
optional uint32 error_ntf_status_code = 3;
optional uint32 error_ntf_status_code = 3;
}
/**
@@ -5002,14 +5003,14 @@ message NfcErrorOccurred {
* packages/apps/Nfc/src/com/android/nfc/NfcService.java
*/
message NfcStateChanged {
enum State {
UNKNOWN = 0;
OFF = 1;
ON = 2;
ON_LOCKED = 3; // Secure Nfc enabled.
CRASH_RESTART = 4; // NfcService watchdog timeout restart.
}
optional State state = 1;
enum State {
UNKNOWN = 0;
OFF = 1;
ON = 2;
ON_LOCKED = 3; // Secure Nfc enabled.
CRASH_RESTART = 4; // NfcService watchdog timeout restart.
}
optional State state = 1;
}
/**
@@ -5018,12 +5019,12 @@ message NfcStateChanged {
* packages/apps/Nfc/src/com/android/nfc/P2pLinkManager.java
*/
message NfcBeamOccurred {
enum Operation {
UNKNOWN = 0;
SEND = 1;
RECEIVE = 2;
}
optional Operation operation = 1;
enum Operation {
UNKNOWN = 0;
SEND = 1;
RECEIVE = 2;
}
optional Operation operation = 1;
}
/**
@@ -5033,16 +5034,16 @@ message NfcBeamOccurred {
* packages/apps/Nfc/src/com/android/nfc/cardemulation/HostNfcFEmulationManager.java
*/
message NfcCardemulationOccurred {
enum Category {
UNKNOWN = 0;
HCE_PAYMENT = 1;
HCE_OTHER = 2;
OFFHOST = 3;
}
// Transaction belongs to HCE payment or HCE other category, or offhost.
optional Category category = 1;
// SeName from transaction: SIMx, eSEx, HCE, HCEF.
optional string se_name = 2;
enum Category {
UNKNOWN = 0;
HCE_PAYMENT = 1;
HCE_OTHER = 2;
OFFHOST = 3;
}
// Transaction belongs to HCE payment or HCE other category, or offhost.
optional Category category = 1;
// SeName from transaction: SIMx, eSEx, HCE, HCEF.
optional string se_name = 2;
}
/**
@@ -5051,16 +5052,16 @@ message NfcCardemulationOccurred {
* packages/apps/Nfc/src/com/android/nfc/NfcDispatcher.java
*/
message NfcTagOccurred {
enum Type {
UNKNOWN = 0;
URL = 1;
BT_PAIRING = 2;
PROVISION = 3;
WIFI_CONNECT = 4;
APP_LAUNCH = 5;
OTHERS = 6;
}
optional Type type = 1;
enum Type {
UNKNOWN = 0;
URL = 1;
BT_PAIRING = 2;
PROVISION = 3;
WIFI_CONNECT = 4;
APP_LAUNCH = 5;
OTHERS = 6;
}
optional Type type = 1;
}
/**
@@ -5080,18 +5081,18 @@ message NfcHceTransactionOccurred {
* packages/apps/SecureElement/src/com/android/se/Terminal.java
*/
message SeStateChanged {
enum State {
UNKNOWN = 0;
INITIALIZED = 1;
DISCONNECTED = 2;
CONNECTED = 3;
HALCRASH = 4;
}
optional State state = 1;
enum State {
UNKNOWN = 0;
INITIALIZED = 1;
DISCONNECTED = 2;
CONNECTED = 3;
HALCRASH = 4;
}
optional State state = 1;
optional string state_change_reason = 2;
// SIMx or eSEx.
optional string terminal = 3;
optional string state_change_reason = 2;
// SIMx or eSEx.
optional string terminal = 3;
}
/**
@@ -5100,15 +5101,15 @@ message SeStateChanged {
* packages/apps/SecureElement/src/com/android/se/Terminal.java
*/
message SeOmapiReported {
enum Operation {
UNKNOWN = 0;
OPEN_CHANNEL = 1;
}
optional Operation operation = 1;
// SIMx or eSEx.
optional string terminal = 2;
enum Operation {
UNKNOWN = 0;
OPEN_CHANNEL = 1;
}
optional Operation operation = 1;
// SIMx or eSEx.
optional string terminal = 2;
optional string package_name = 3;
optional string package_name = 3;
}
/**
@@ -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;
}

View File

@@ -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
@@ -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() {
@@ -95,6 +102,8 @@ public class AttentionDetector {
}
if (result == AttentionService.ATTENTION_SUCCESS_PRESENT) {
mOnUserAttention.run();
} else {
resetConsecutiveExtensionCount();
}
}
}
@@ -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:
@@ -183,6 +193,7 @@ public class AttentionDetector {
case PowerManager.USER_ACTIVITY_EVENT_ACCESSIBILITY:
cancelCurrentRequestIfAny();
mLastUserActivityTime = eventTime;
resetConsecutiveExtensionCount();
return 1;
default:
if (DEBUG) {
@@ -196,6 +207,7 @@ public class AttentionDetector {
mWakefulness = wakefulness;
if (wakefulness != PowerManagerInternal.WAKEFULNESS_AWAKE) {
cancelCurrentRequestIfAny();
resetConsecutiveExtensionCount();
}
}
@@ -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);