Merge "Sync BatteryStats user activity types with PowerManager ones." into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9b5f8d21ed
@@ -962,7 +962,7 @@ public abstract class BatteryStats implements Parcelable {
|
||||
* also be bumped.
|
||||
*/
|
||||
static final String[] USER_ACTIVITY_TYPES = {
|
||||
"other", "button", "touch", "accessibility", "attention"
|
||||
"other", "button", "touch", "accessibility", "attention", "faceDown", "deviceState"
|
||||
};
|
||||
|
||||
public static final int NUM_USER_ACTIVITY_TYPES = USER_ACTIVITY_TYPES.length;
|
||||
|
||||
@@ -344,6 +344,39 @@ public final class PowerManager {
|
||||
*/
|
||||
public static final int USER_ACTIVITY_EVENT_DEVICE_STATE = 6;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@IntDef(prefix = { "USER_ACTIVITY_EVENT_" }, value = {
|
||||
USER_ACTIVITY_EVENT_OTHER,
|
||||
USER_ACTIVITY_EVENT_BUTTON,
|
||||
USER_ACTIVITY_EVENT_TOUCH,
|
||||
USER_ACTIVITY_EVENT_ACCESSIBILITY,
|
||||
USER_ACTIVITY_EVENT_ATTENTION,
|
||||
USER_ACTIVITY_EVENT_FACE_DOWN,
|
||||
USER_ACTIVITY_EVENT_DEVICE_STATE,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface UserActivityEvent{}
|
||||
|
||||
/**
|
||||
*
|
||||
* Convert the user activity event to a string for debugging purposes.
|
||||
* @hide
|
||||
*/
|
||||
public static String userActivityEventToString(@UserActivityEvent int userActivityEvent) {
|
||||
switch (userActivityEvent) {
|
||||
case USER_ACTIVITY_EVENT_OTHER: return "other";
|
||||
case USER_ACTIVITY_EVENT_BUTTON: return "button";
|
||||
case USER_ACTIVITY_EVENT_TOUCH: return "touch";
|
||||
case USER_ACTIVITY_EVENT_ACCESSIBILITY: return "accessibility";
|
||||
case USER_ACTIVITY_EVENT_ATTENTION: return "attention";
|
||||
case USER_ACTIVITY_EVENT_FACE_DOWN: return "faceDown";
|
||||
case USER_ACTIVITY_EVENT_DEVICE_STATE: return "deviceState";
|
||||
default: return Integer.toString(userActivityEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User activity flag: If already dimmed, extend the dim timeout
|
||||
* but do not brighten. This flag is useful for keeping the screen on
|
||||
|
||||
@@ -167,7 +167,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
|
||||
|
||||
// Current on-disk Parcel version
|
||||
static final int VERSION = 208;
|
||||
static final int VERSION = 210;
|
||||
|
||||
// The maximum number of names wakelocks we will keep track of
|
||||
// per uid; once the limit is reached, we batch the remaining wakelocks
|
||||
@@ -6145,12 +6145,13 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
|
||||
@UnsupportedAppUsage
|
||||
@GuardedBy("this")
|
||||
public void noteUserActivityLocked(int uid, int event) {
|
||||
public void noteUserActivityLocked(int uid, @PowerManager.UserActivityEvent int event) {
|
||||
noteUserActivityLocked(uid, event, mClock.elapsedRealtime(), mClock.uptimeMillis());
|
||||
}
|
||||
|
||||
@GuardedBy("this")
|
||||
public void noteUserActivityLocked(int uid, int event, long elapsedRealtimeMs, long uptimeMs) {
|
||||
public void noteUserActivityLocked(int uid, @PowerManager.UserActivityEvent int event,
|
||||
long elapsedRealtimeMs, long uptimeMs) {
|
||||
if (mOnBatteryInternal) {
|
||||
uid = mapUid(uid);
|
||||
getUidStatsLocked(uid, elapsedRealtimeMs, uptimeMs).noteUserActivityLocked(event);
|
||||
@@ -9962,14 +9963,14 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noteUserActivityLocked(int type) {
|
||||
public void noteUserActivityLocked(@PowerManager.UserActivityEvent int event) {
|
||||
if (mUserActivityCounters == null) {
|
||||
initUserActivityLocked();
|
||||
}
|
||||
if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) {
|
||||
mUserActivityCounters[type].stepAtomic();
|
||||
if (event >= 0 && event < NUM_USER_ACTIVITY_TYPES) {
|
||||
mUserActivityCounters[event].stepAtomic();
|
||||
} else {
|
||||
Slog.w(TAG, "Unknown user activity type " + type + " was specified.",
|
||||
Slog.w(TAG, "Unknown user activity type " + event + " was specified.",
|
||||
new Throwable());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,7 +571,8 @@ public class Notifier {
|
||||
/**
|
||||
* Called when there has been user activity.
|
||||
*/
|
||||
public void onUserActivity(int displayGroupId, int event, int uid) {
|
||||
public void onUserActivity(int displayGroupId, @PowerManager.UserActivityEvent int event,
|
||||
int uid) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "onUserActivity: event=" + event + ", uid=" + uid);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ public class PowerGroup {
|
||||
private long mLastPowerOnTime;
|
||||
private long mLastUserActivityTime;
|
||||
private long mLastUserActivityTimeNoChangeLights;
|
||||
@PowerManager.UserActivityEvent
|
||||
private int mLastUserActivityEvent;
|
||||
/** Timestamp (milliseconds since boot) of the last time the power group was awoken.*/
|
||||
private long mLastWakeTime;
|
||||
/** Timestamp (milliseconds since boot) of the last time the power group was put to sleep. */
|
||||
@@ -244,7 +246,7 @@ public class PowerGroup {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean dozeLocked(long eventTime, int uid, int reason) {
|
||||
boolean dozeLocked(long eventTime, int uid, @PowerManager.GoToSleepReason int reason) {
|
||||
if (eventTime < getLastWakeTimeLocked() || !isInteractive(mWakefulness)) {
|
||||
return false;
|
||||
}
|
||||
@@ -253,9 +255,14 @@ public class PowerGroup {
|
||||
try {
|
||||
reason = Math.min(PowerManager.GO_TO_SLEEP_REASON_MAX,
|
||||
Math.max(reason, PowerManager.GO_TO_SLEEP_REASON_MIN));
|
||||
long millisSinceLastUserActivity = eventTime - Math.max(
|
||||
mLastUserActivityTimeNoChangeLights, mLastUserActivityTime);
|
||||
Slog.i(TAG, "Powering off display group due to "
|
||||
+ PowerManager.sleepReasonToString(reason) + " (groupId= " + getGroupId()
|
||||
+ ", uid= " + uid + ")...");
|
||||
+ PowerManager.sleepReasonToString(reason)
|
||||
+ " (groupId= " + getGroupId() + ", uid= " + uid
|
||||
+ ", millisSinceLastUserActivity=" + millisSinceLastUserActivity
|
||||
+ ", lastUserActivityEvent=" + PowerManager.userActivityEventToString(
|
||||
mLastUserActivityEvent) + ")...");
|
||||
|
||||
setSandmanSummonedLocked(/* isSandmanSummoned= */ true);
|
||||
setWakefulnessLocked(WAKEFULNESS_DOZING, eventTime, uid, reason, /* opUid= */ 0,
|
||||
@@ -266,14 +273,16 @@ public class PowerGroup {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean sleepLocked(long eventTime, int uid, int reason) {
|
||||
boolean sleepLocked(long eventTime, int uid, @PowerManager.GoToSleepReason int reason) {
|
||||
if (eventTime < mLastWakeTime || getWakefulnessLocked() == WAKEFULNESS_ASLEEP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Trace.traceBegin(Trace.TRACE_TAG_POWER, "sleepPowerGroup");
|
||||
try {
|
||||
Slog.i(TAG, "Sleeping power group (groupId=" + getGroupId() + ", uid=" + uid + ")...");
|
||||
Slog.i(TAG,
|
||||
"Sleeping power group (groupId=" + getGroupId() + ", uid=" + uid + ", reason="
|
||||
+ PowerManager.sleepReasonToString(reason) + ")...");
|
||||
setSandmanSummonedLocked(/* isSandmanSummoned= */ true);
|
||||
setWakefulnessLocked(WAKEFULNESS_ASLEEP, eventTime, uid, reason, /* opUid= */0,
|
||||
/* opPackageName= */ null, /* details= */ null);
|
||||
@@ -287,16 +296,20 @@ public class PowerGroup {
|
||||
return mLastUserActivityTime;
|
||||
}
|
||||
|
||||
void setLastUserActivityTimeLocked(long lastUserActivityTime) {
|
||||
void setLastUserActivityTimeLocked(long lastUserActivityTime,
|
||||
@PowerManager.UserActivityEvent int event) {
|
||||
mLastUserActivityTime = lastUserActivityTime;
|
||||
mLastUserActivityEvent = event;
|
||||
}
|
||||
|
||||
public long getLastUserActivityTimeNoChangeLightsLocked() {
|
||||
return mLastUserActivityTimeNoChangeLights;
|
||||
}
|
||||
|
||||
public void setLastUserActivityTimeNoChangeLightsLocked(long time) {
|
||||
public void setLastUserActivityTimeNoChangeLightsLocked(long time,
|
||||
@PowerManager.UserActivityEvent int event) {
|
||||
mLastUserActivityTimeNoChangeLights = time;
|
||||
mLastUserActivityEvent = event;
|
||||
}
|
||||
|
||||
public int getUserActivitySummaryLocked() {
|
||||
|
||||
@@ -1169,6 +1169,7 @@ public final class PowerManagerService extends SystemService
|
||||
return;
|
||||
}
|
||||
|
||||
Slog.i(TAG, "onFlip(): Face " + (isFaceDown ? "down." : "up."));
|
||||
mIsFaceDown = isFaceDown;
|
||||
if (isFaceDown) {
|
||||
final long currentTime = mClock.uptimeMillis();
|
||||
@@ -1888,12 +1889,13 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
// Called from native code.
|
||||
@SuppressWarnings("unused")
|
||||
private void userActivityFromNative(long eventTime, int event, int displayId, int flags) {
|
||||
private void userActivityFromNative(long eventTime, @PowerManager.UserActivityEvent int event,
|
||||
int displayId, int flags) {
|
||||
userActivityInternal(displayId, eventTime, event, flags, Process.SYSTEM_UID);
|
||||
}
|
||||
|
||||
private void userActivityInternal(int displayId, long eventTime, int event, int flags,
|
||||
int uid) {
|
||||
private void userActivityInternal(int displayId, long eventTime,
|
||||
@PowerManager.UserActivityEvent int event, int flags, int uid) {
|
||||
synchronized (mLock) {
|
||||
if (displayId == Display.INVALID_DISPLAY) {
|
||||
if (userActivityNoUpdateLocked(eventTime, event, flags, uid)) {
|
||||
@@ -1944,11 +1946,12 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private boolean userActivityNoUpdateLocked(final PowerGroup powerGroup, long eventTime,
|
||||
int event, int flags, int uid) {
|
||||
@PowerManager.UserActivityEvent int event, int flags, int uid) {
|
||||
final int groupId = powerGroup.getGroupId();
|
||||
if (DEBUG_SPEW) {
|
||||
Slog.d(TAG, "userActivityNoUpdateLocked: groupId=" + groupId
|
||||
+ ", eventTime=" + eventTime + ", event=" + event
|
||||
+ ", eventTime=" + eventTime
|
||||
+ ", event=" + PowerManager.userActivityEventToString(event)
|
||||
+ ", flags=0x" + Integer.toHexString(flags) + ", uid=" + uid);
|
||||
}
|
||||
|
||||
@@ -1983,7 +1986,7 @@ public final class PowerManagerService extends SystemService
|
||||
if ((flags & PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS) != 0) {
|
||||
if (eventTime > powerGroup.getLastUserActivityTimeNoChangeLightsLocked()
|
||||
&& eventTime > powerGroup.getLastUserActivityTimeLocked()) {
|
||||
powerGroup.setLastUserActivityTimeNoChangeLightsLocked(eventTime);
|
||||
powerGroup.setLastUserActivityTimeNoChangeLightsLocked(eventTime, event);
|
||||
mDirty |= DIRTY_USER_ACTIVITY;
|
||||
if (event == PowerManager.USER_ACTIVITY_EVENT_BUTTON) {
|
||||
mDirty |= DIRTY_QUIESCENT;
|
||||
@@ -1993,7 +1996,7 @@ public final class PowerManagerService extends SystemService
|
||||
}
|
||||
} else {
|
||||
if (eventTime > powerGroup.getLastUserActivityTimeLocked()) {
|
||||
powerGroup.setLastUserActivityTimeLocked(eventTime);
|
||||
powerGroup.setLastUserActivityTimeLocked(eventTime, event);
|
||||
mDirty |= DIRTY_USER_ACTIVITY;
|
||||
if (event == PowerManager.USER_ACTIVITY_EVENT_BUTTON) {
|
||||
mDirty |= DIRTY_QUIESCENT;
|
||||
@@ -2020,7 +2023,8 @@ public final class PowerManagerService extends SystemService
|
||||
@WakeReason int reason, String details, int uid, String opPackageName, int opUid) {
|
||||
if (DEBUG_SPEW) {
|
||||
Slog.d(TAG, "wakePowerGroupLocked: eventTime=" + eventTime
|
||||
+ ", groupId=" + powerGroup.getGroupId() + ", uid=" + uid);
|
||||
+ ", groupId=" + powerGroup.getGroupId()
|
||||
+ ", reason=" + PowerManager.wakeReasonToString(reason) + ", uid=" + uid);
|
||||
}
|
||||
if (mForceSuspendActive || !mSystemReady) {
|
||||
return;
|
||||
@@ -2043,11 +2047,11 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private boolean dozePowerGroupLocked(final PowerGroup powerGroup, long eventTime,
|
||||
int reason, int uid) {
|
||||
@GoToSleepReason int reason, int uid) {
|
||||
if (DEBUG_SPEW) {
|
||||
Slog.d(TAG, "dozePowerGroup: eventTime=" + eventTime
|
||||
+ ", groupId=" + powerGroup.getGroupId() + ", reason=" + reason
|
||||
+ ", uid=" + uid);
|
||||
+ ", groupId=" + powerGroup.getGroupId()
|
||||
+ ", reason=" + PowerManager.sleepReasonToString(reason) + ", uid=" + uid);
|
||||
}
|
||||
|
||||
if (!mSystemReady || !mBootCompleted) {
|
||||
@@ -2058,10 +2062,12 @@ public final class PowerManagerService extends SystemService
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private boolean sleepPowerGroupLocked(final PowerGroup powerGroup, long eventTime, int reason,
|
||||
int uid) {
|
||||
private boolean sleepPowerGroupLocked(final PowerGroup powerGroup, long eventTime,
|
||||
@GoToSleepReason int reason, int uid) {
|
||||
if (DEBUG_SPEW) {
|
||||
Slog.d(TAG, "sleepPowerGroup: eventTime=" + eventTime + ", uid=" + uid);
|
||||
Slog.d(TAG, "sleepPowerGroup: eventTime=" + eventTime
|
||||
+ ", groupId=" + powerGroup.getGroupId()
|
||||
+ ", reason=" + PowerManager.sleepReasonToString(reason) + ", uid=" + uid);
|
||||
}
|
||||
if (!mBootCompleted || !mSystemReady) {
|
||||
return false;
|
||||
@@ -2122,8 +2128,10 @@ public final class PowerManagerService extends SystemService
|
||||
case WAKEFULNESS_DOZING:
|
||||
traceMethodName = "goToSleep";
|
||||
Slog.i(TAG, "Going to sleep due to " + PowerManager.sleepReasonToString(reason)
|
||||
+ " (uid " + uid + ")...");
|
||||
|
||||
+ " (uid " + uid + ", screenOffTimeout=" + mScreenOffTimeoutSetting
|
||||
+ ", activityTimeoutWM=" + mUserActivityTimeoutOverrideFromWindowManager
|
||||
+ ", maxDimRatio=" + mMaximumScreenDimRatioConfig
|
||||
+ ", maxDimDur=" + mMaximumScreenDimDurationConfig + ")...");
|
||||
mLastGlobalSleepTime = eventTime;
|
||||
mLastGlobalSleepReason = reason;
|
||||
mDozeStartInProgress = true;
|
||||
@@ -4207,7 +4215,7 @@ public final class PowerManagerService extends SystemService
|
||||
void onUserActivity() {
|
||||
synchronized (mLock) {
|
||||
mPowerGroups.get(Display.DEFAULT_DISPLAY_GROUP).setLastUserActivityTimeLocked(
|
||||
mClock.uptimeMillis());
|
||||
mClock.uptimeMillis(), PowerManager.USER_ACTIVITY_EVENT_OTHER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5590,7 +5598,8 @@ public final class PowerManagerService extends SystemService
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
public void userActivity(int displayId, long eventTime, int event, int flags) {
|
||||
public void userActivity(int displayId, long eventTime,
|
||||
@PowerManager.UserActivityEvent int event, int flags) {
|
||||
final long now = mClock.uptimeMillis();
|
||||
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER)
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
|
||||
Reference in New Issue
Block a user