Merge "Remove BatteryStats user activity types and use PowerManager ones instead."
This commit is contained in:
committed by
Android (Google) Code Review
commit
10a0a4a61b
@@ -955,16 +955,7 @@ public abstract class BatteryStats {
|
||||
|
||||
public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
|
||||
|
||||
/**
|
||||
* Note that these must match the constants in android.os.PowerManager.
|
||||
* Also, if the user activity types change, the BatteryStatsImpl.VERSION must
|
||||
* also be bumped.
|
||||
*/
|
||||
static final String[] USER_ACTIVITY_TYPES = {
|
||||
"other", "button", "touch", "accessibility", "attention"
|
||||
};
|
||||
|
||||
public static final int NUM_USER_ACTIVITY_TYPES = USER_ACTIVITY_TYPES.length;
|
||||
public static final int NUM_USER_ACTIVITY_TYPES = PowerManager.USER_ACTIVITY_EVENT_MAX + 1;
|
||||
|
||||
public abstract void noteUserActivityLocked(int type);
|
||||
public abstract boolean hasUserActivity();
|
||||
@@ -6168,7 +6159,7 @@ public abstract class BatteryStats {
|
||||
}
|
||||
sb.append(val);
|
||||
sb.append(" ");
|
||||
sb.append(Uid.USER_ACTIVITY_TYPES[i]);
|
||||
sb.append(PowerManager.userActivityEventToString(i));
|
||||
}
|
||||
}
|
||||
if (hasData) {
|
||||
|
||||
@@ -347,6 +347,44 @@ public final class PowerManager {
|
||||
*/
|
||||
public static final int USER_ACTIVITY_EVENT_DEVICE_STATE = 6;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public static final int USER_ACTIVITY_EVENT_MAX = USER_ACTIVITY_EVENT_DEVICE_STATE;
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -1216,6 +1216,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();
|
||||
@@ -1937,12 +1938,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)) {
|
||||
@@ -1993,11 +1995,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);
|
||||
}
|
||||
|
||||
@@ -2032,7 +2035,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;
|
||||
@@ -2042,7 +2045,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;
|
||||
@@ -2069,7 +2072,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;
|
||||
@@ -2092,11 +2096,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) {
|
||||
@@ -2107,10 +2111,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;
|
||||
@@ -2172,7 +2178,11 @@ 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;
|
||||
mLastGlobalSleepTimeRealtime = mClock.elapsedRealtime();
|
||||
@@ -4257,7 +4267,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5645,7 +5655,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
|
||||
|
||||
@@ -5911,7 +5911,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -9416,14 +9417,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 event " + event + " was specified.",
|
||||
new Throwable());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user