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

Commit 86ce0e2d authored by Dhavalkumar Chaudhary's avatar Dhavalkumar Chaudhary Committed by Android (Google) Code Review
Browse files

Merge "Updated elapsedTime and upTime with in sync method to avoid thread block" into main

parents 504ef37e 4e7ec43b
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -573,9 +574,8 @@ public class BatteryStatsImpl extends BatteryStats {
     * Batterystats shall remove UIDs, and a delay {@link Constants#UID_REMOVE_DELAY_MS} is
     * implemented so that STATSD can capture those UID times before they are deleted.
     */
    @GuardedBy("this")
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    protected Queue<UidToRemove> mPendingRemovedUids = new LinkedList<>();
    protected final Queue<UidToRemove> mPendingRemovedUids;
    @NonNull
    public BatteryStatsHistory getHistory() {
@@ -4602,19 +4602,23 @@ public class BatteryStatsImpl extends BatteryStats {
    }
    private void onBeforeIsolatedUidRemoved(int isolatedUid, int parentUid) {
        long realtime = mClock.elapsedRealtime();
        final long realtime = mClock.elapsedRealtime();
        mPowerStatsUidResolver.retainIsolatedUid(isolatedUid);
        if (Flags.concurrentQueueForPendingRemovedUids()) {
            mPendingRemovedUids.add(new UidToRemove(isolatedUid, realtime));
        } else {
            synchronized (this) {
                mPendingRemovedUids.add(new UidToRemove(isolatedUid, realtime));
            }
        }
        if (mExternalSync != null) {
            mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid);
        }
    }
    private void onAfterIsolatedUidRemoved(int isolatedUid, int parentUid) {
        long realtime = mClock.elapsedRealtime();
        long uptime = mClock.uptimeMillis();
        final long realtime = mClock.elapsedRealtime();
        final long uptime = mClock.uptimeMillis();
        synchronized (this) {
            getUidStatsLocked(parentUid, realtime, uptime).removeIsolatedUid(isolatedUid);
        }
@@ -10785,6 +10789,12 @@ public class BatteryStatsImpl extends BatteryStats {
        mClock = clock;
        initKernelStatsReaders();
        if (Flags.concurrentQueueForPendingRemovedUids()) {
            mPendingRemovedUids = new ConcurrentLinkedQueue<>();
        } else {
            mPendingRemovedUids = new LinkedList<>();
        }
        mBatteryStatsConfig = config;
        mMonotonicClock = monotonicClock;
        mHandler = new MyHandler(handler.getLooper());
+10 −0
Original line number Diff line number Diff line
@@ -64,3 +64,13 @@ flag {
     description: "Add a configurable value for power stats logging frequency"
     bug: "166689029"
}

flag {
     namespace: "backstage_power"
     name: "concurrent_queue_for_pending_removed_uids"
     description: "Added ConcurrentLinkedQueue to address locking issue for pending remove uids queue"
     bug: "420852486"
     metadata {
         purpose: PURPOSE_BUGFIX
     }
}
+1 −3
Original line number Diff line number Diff line
@@ -145,10 +145,8 @@ public class MockBatteryStatsImpl extends BatteryStatsImpl {
    }

    public Queue<UidToRemove> getPendingRemovedUids() {
        synchronized (this) {
        return mPendingRemovedUids;
    }
    }

    public boolean isOnBattery() {
        return mForceOnBattery ? true : super.isOnBattery();