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

Commit 17fb2d86 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov Committed by Android (Google) Code Review
Browse files

Merge "Improve logic around battery history time base" into udc-dev

parents 72d3082e 5f550dc6
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -1468,6 +1468,11 @@ public class BatteryStatsHistory {
        mHistoryLastLastWritten.setTo(mHistoryLastWritten);
        final boolean hasTags = mHistoryLastWritten.tagsFirstOccurrence || cur.tagsFirstOccurrence;
        mHistoryLastWritten.setTo(mHistoryBaseTimeMs + elapsedRealtimeMs, cmd, cur);
        if (mHistoryLastWritten.time < mHistoryLastLastWritten.time - 60000) {
            Slog.wtf(TAG, "Significantly earlier event written to battery history:"
                    + " time=" + mHistoryLastWritten.time
                    + " previous=" + mHistoryLastLastWritten.time);
        }
        mHistoryLastWritten.tagsFirstOccurrence = hasTags;
        writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten);
        mLastHistoryElapsedRealtimeMs = elapsedRealtimeMs;
@@ -1908,12 +1913,6 @@ public class BatteryStatsHistory {
            in.setDataPosition(curPos + bufSize);
        }

        if (DEBUG) {
            StringBuilder sb = new StringBuilder(128);
            sb.append("****************** OLD mHistoryBaseTimeMs: ");
            TimeUtils.formatDuration(mHistoryBaseTimeMs, sb);
            Slog.i(TAG, sb.toString());
        }
        mHistoryBaseTimeMs = historyBaseTime;
        if (DEBUG) {
            StringBuilder sb = new StringBuilder(128);
@@ -1922,11 +1921,10 @@ public class BatteryStatsHistory {
            Slog.i(TAG, sb.toString());
        }

        // We are just arbitrarily going to insert 1 minute from the sample of
        // the last run until samples in this run.
        if (mHistoryBaseTimeMs > 0) {
            long oldnow = mClock.elapsedRealtime();
            mHistoryBaseTimeMs = mHistoryBaseTimeMs - oldnow + 1;
            long elapsedRealtimeMs = mClock.elapsedRealtime();
            mLastHistoryElapsedRealtimeMs = elapsedRealtimeMs;
            mHistoryBaseTimeMs = mHistoryBaseTimeMs - elapsedRealtimeMs + 1;
            if (DEBUG) {
                StringBuilder sb = new StringBuilder(128);
                sb.append("****************** ADJUSTED mHistoryBaseTimeMs: ");
+2 −5
Original line number Diff line number Diff line
@@ -2497,13 +2497,10 @@ public class ActivityManagerService extends IActivityManager.Stub
        final File systemDir = SystemServiceManager.ensureSystemDir();
        // TODO: Move creation of battery stats service outside of activity manager service.
        mBatteryStatsService = new BatteryStatsService(systemContext, systemDir,
                BackgroundThread.get().getHandler());
        mBatteryStatsService.getActiveStatistics().readLocked();
        mBatteryStatsService.scheduleWriteToDisk();
        mBatteryStatsService = BatteryStatsService.create(systemContext, systemDir,
                BackgroundThread.getHandler(), this);
        mOnBattery = DEBUG_POWER ? true
                : mBatteryStatsService.getActiveStatistics().getIsOnBattery();
        mBatteryStatsService.getActiveStatistics().setCallback(this);
        mOomAdjProfiler.batteryPowerChanged(mOnBattery);
        mProcessStats = new ProcessStatsService(this, new File(systemDir, "procstats"));
+14 −0
Original line number Diff line number Diff line
@@ -399,6 +399,20 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        mCpuWakeupStats = new CpuWakeupStats(context, R.xml.irq_device_map, mHandler);
    }

    /**
     * Creates an instance of BatteryStatsService and restores data from stored state.
     */
    public static BatteryStatsService create(Context context, File systemDir, Handler handler,
            BatteryStatsImpl.BatteryCallback callback) {
        BatteryStatsService service = new BatteryStatsService(context, systemDir, handler);
        service.mStats.setCallback(callback);
        synchronized (service.mStats) {
            service.mStats.readLocked();
        }
        service.scheduleWriteToDisk();
        return service;
    }

    public void publish() {
        LocalServices.addService(BatteryStatsInternal.class, new LocalService());
        ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder());