Skip to content

Commit df693de

Browse files
author
Jeff Brown
committed
Fix inconsistency in user activity types.
Looks like BatteryStats was not updated when we reduced the number of user activity types from 7 to 3. Change-Id: I7465f86c78baa561a6555c33f681553b870827f2
1 parent 5590027 commit df693de

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

core/java/android/os/BatteryStats.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,15 @@ public abstract long getWifiMulticastTime(long batteryRealtime,
277277
public abstract long getVideoTurnedOnTime(long batteryRealtime, int which);
278278

279279
/**
280-
* Note that these must match the constants in android.os.LocalPowerManager.
280+
* Note that these must match the constants in android.os.PowerManager.
281+
* Also, if the user activity types change, the BatteryStatsImpl.VERSION must
282+
* also be bumped.
281283
*/
282284
static final String[] USER_ACTIVITY_TYPES = {
283-
"other", "cheek", "touch", "long_touch", "touch_up", "button", "unknown"
285+
"other", "button", "touch"
284286
};
285287

286-
public static final int NUM_USER_ACTIVITY_TYPES = 7;
288+
public static final int NUM_USER_ACTIVITY_TYPES = 3;
287289

288290
public abstract void noteUserActivityLocked(int type);
289291
public abstract boolean hasUserActivity();

core/java/com/android/internal/os/BatteryStatsImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public final class BatteryStatsImpl extends BatteryStats {
8787
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
8888

8989
// Current on-disk Parcel version
90-
private static final int VERSION = 61 + (USE_OLD_HISTORY ? 1000 : 0);
90+
private static final int VERSION = 62 + (USE_OLD_HISTORY ? 1000 : 0);
9191

9292
// Maximum number of items we will record in the history.
9393
private static final int MAX_HISTORY_ITEMS = 2000;
@@ -2681,9 +2681,12 @@ public void noteUserActivityLocked(int type) {
26812681
if (mUserActivityCounters == null) {
26822682
initUserActivityLocked();
26832683
}
2684-
if (type < 0) type = 0;
2685-
else if (type >= NUM_USER_ACTIVITY_TYPES) type = NUM_USER_ACTIVITY_TYPES-1;
2686-
mUserActivityCounters[type].stepAtomic();
2684+
if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) {
2685+
mUserActivityCounters[type].stepAtomic();
2686+
} else {
2687+
Slog.w(TAG, "Unknown user activity type " + type + " was specified.",
2688+
new Throwable());
2689+
}
26872690
}
26882691

26892692
@Override

0 commit comments

Comments
 (0)