Merge "Fix issue #3074745: Crash in system process" into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
9934fa77ef
@@ -449,6 +449,10 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
public static final int STATE_WAKE_LOCK_FLAG = 1<<17;
|
public static final int STATE_WAKE_LOCK_FLAG = 1<<17;
|
||||||
public static final int STATE_SENSOR_ON_FLAG = 1<<16;
|
public static final int STATE_SENSOR_ON_FLAG = 1<<16;
|
||||||
|
|
||||||
|
public static final int MOST_INTERESTING_STATES =
|
||||||
|
STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
|
||||||
|
| STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG;
|
||||||
|
|
||||||
public int states;
|
public int states;
|
||||||
|
|
||||||
public HistoryItem() {
|
public HistoryItem() {
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
// Maximum number of items we will record in the history.
|
// Maximum number of items we will record in the history.
|
||||||
private static final int MAX_HISTORY_ITEMS = 2000;
|
private static final int MAX_HISTORY_ITEMS = 2000;
|
||||||
|
|
||||||
|
// No, really, THIS is the maximum number of items we will record in the history.
|
||||||
|
private static final int MAX_MAX_HISTORY_ITEMS = 3000;
|
||||||
|
|
||||||
// The maximum number of names wakelocks we will keep track of
|
// The maximum number of names wakelocks we will keep track of
|
||||||
// per uid; once the limit is reached, we batch the remaining wakelocks
|
// per uid; once the limit is reached, we batch the remaining wakelocks
|
||||||
// in to one common name.
|
// in to one common name.
|
||||||
@@ -1169,15 +1172,20 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
mBtHeadset = headset;
|
mBtHeadset = headset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mChangedStates = 0;
|
||||||
|
|
||||||
void addHistoryRecordLocked(long curTime) {
|
void addHistoryRecordLocked(long curTime) {
|
||||||
if (!mHaveBatteryLevel || !mRecordingHistory) {
|
if (!mHaveBatteryLevel || !mRecordingHistory) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the current time is basically the same as the last time,
|
// If the current time is basically the same as the last time,
|
||||||
// just collapse into one record.
|
// and no states have since the last recorded entry changed and
|
||||||
|
// are now resetting back to their original value, then just collapse
|
||||||
|
// into one record.
|
||||||
if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE
|
if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE
|
||||||
&& (mHistoryBaseTime+curTime) < (mHistoryEnd.time+500)) {
|
&& (mHistoryBaseTime+curTime) < (mHistoryEnd.time+2000)
|
||||||
|
&& ((mHistoryEnd.states^mHistoryCur.states)&mChangedStates) == 0) {
|
||||||
// If the current is the same as the one before, then we no
|
// If the current is the same as the one before, then we no
|
||||||
// longer need the entry.
|
// longer need the entry.
|
||||||
if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE
|
if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE
|
||||||
@@ -1188,20 +1196,29 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
mHistoryEnd = mHistoryLastEnd;
|
mHistoryEnd = mHistoryLastEnd;
|
||||||
mHistoryLastEnd = null;
|
mHistoryLastEnd = null;
|
||||||
} else {
|
} else {
|
||||||
|
mChangedStates |= mHistoryEnd.states^mHistoryCur.states;
|
||||||
mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, mHistoryCur);
|
mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, mHistoryCur);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mNumHistoryItems == MAX_HISTORY_ITEMS) {
|
mChangedStates = 0;
|
||||||
|
|
||||||
|
if (mNumHistoryItems == MAX_HISTORY_ITEMS
|
||||||
|
|| mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) {
|
||||||
addHistoryRecordLocked(curTime, HistoryItem.CMD_OVERFLOW);
|
addHistoryRecordLocked(curTime, HistoryItem.CMD_OVERFLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mNumHistoryItems >= MAX_HISTORY_ITEMS) {
|
if (mNumHistoryItems >= MAX_HISTORY_ITEMS) {
|
||||||
// Once we've reached the maximum number of items, we only
|
// Once we've reached the maximum number of items, we only
|
||||||
|
// record changes to the battery level and the most interesting states.
|
||||||
|
// Once we've reached the maximum maximum number of items, we only
|
||||||
// record changes to the battery level.
|
// record changes to the battery level.
|
||||||
if (mHistoryEnd != null && mHistoryEnd.batteryLevel
|
if (mHistoryEnd != null && mHistoryEnd.batteryLevel
|
||||||
== mHistoryCur.batteryLevel) {
|
== mHistoryCur.batteryLevel &&
|
||||||
|
(mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS
|
||||||
|
|| ((mHistoryEnd.states^mHistoryCur.states)
|
||||||
|
& HistoryItem.MOST_INTERESTING_STATES) == 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4450,10 +4467,13 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void commitPendingDataToDisk() {
|
public void commitPendingDataToDisk() {
|
||||||
Parcel next;
|
final Parcel next;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
next = mPendingWrite;
|
next = mPendingWrite;
|
||||||
mPendingWrite = null;
|
mPendingWrite = null;
|
||||||
|
if (next == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mWriteLock.lock();
|
mWriteLock.lock();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user