Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8c88e6f authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #5163456: logspam/tight loop in BatteryStatsImpl

No longer use the old history code.

Change-Id: I878ffe16e0014453c46db6a4f7228a81468d8cb9
parent 9f550e91
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -67,12 +67,13 @@ public final class BatteryStatsImpl extends BatteryStats {
    private static final String TAG = "BatteryStatsImpl";
    private static final boolean DEBUG = false;
    private static final boolean DEBUG_HISTORY = false;
    private static final boolean USE_OLD_HISTORY = false;   // for debugging.

    // In-memory Parcel magic number, used to detect attempts to unmarshall bad data
    private static final int MAGIC = 0xBA757475; // 'BATSTATS'

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

    // Maximum number of items we will record in the history.
    private static final int MAX_HISTORY_ITEMS = 2000;
@@ -1285,6 +1286,10 @@ public final class BatteryStatsImpl extends BatteryStats {
    void addHistoryRecordLocked(long curTime) {
        addHistoryBufferLocked(curTime);

        if (!USE_OLD_HISTORY) {
            return;
        }

        if (!mHaveBatteryLevel || !mRecordingHistory) {
            return;
        }
@@ -1363,12 +1368,15 @@ public final class BatteryStatsImpl extends BatteryStats {

    void clearHistoryLocked() {
        if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!");
        if (USE_OLD_HISTORY) {
            if (mHistory != null) {
                mHistoryEnd.next = mHistoryCache;
                mHistoryCache = mHistory;
                mHistory = mHistoryLastEnd = mHistoryEnd = null;
            }
            mNumHistoryItems = 0;
        }

        mHistoryBaseTime = 0;
        mLastHistoryTime = 0;

@@ -4863,7 +4871,9 @@ public final class BatteryStatsImpl extends BatteryStats {
        }

        long now = SystemClock.elapsedRealtime();
        if (USE_OLD_HISTORY) {
            addHistoryRecordLocked(now, HistoryItem.CMD_START);
        }
        addHistoryBufferLocked(now, HistoryItem.CMD_START);
    }

@@ -4923,6 +4933,9 @@ public final class BatteryStatsImpl extends BatteryStats {
    }

    void readOldHistory(Parcel in) {
        if (!USE_OLD_HISTORY) {
            return;
        }
        mHistory = mHistoryEnd = mHistoryCache = null;
        long time;
        while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) {
@@ -4952,6 +4965,9 @@ public final class BatteryStatsImpl extends BatteryStats {
    }

    void writeOldHistory(Parcel out) {
        if (!USE_OLD_HISTORY) {
            return;
        }
        HistoryItem rec = mHistory;
        while (rec != null) {
            if (rec.time >= 0) rec.writeToParcel(out, 0);
+0 −1
Original line number Diff line number Diff line
@@ -2699,7 +2699,6 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
                
                if (!haveBg) {
                    Slog.i(TAG, "Low Memory: No more background processes.");
                    EventLog.writeEvent(EventLogTags.AM_LOW_MEMORY, mLruProcesses.size());
                    long now = SystemClock.uptimeMillis();
                    for (int i=mLruProcesses.size()-1; i>=0; i--) {