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

Commit 36de7b51 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Share UID mapping logic between BatteryStats and PowerStatCollectors

Bug: 292247660
Test: atest PowerStatsTests

Change-Id: I488715c8a52df3cff4b736ed873b303401822d39
parent 68075ac6
Loading
Loading
Loading
Loading
+12 −19
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ import com.android.server.power.stats.PowerStatsAggregator;
import com.android.server.power.stats.PowerStatsExporter;
import com.android.server.power.stats.PowerStatsScheduler;
import com.android.server.power.stats.PowerStatsStore;
import com.android.server.power.stats.PowerStatsUidResolver;
import com.android.server.power.stats.SystemServerCpuThreadReader.SystemServiceCpuThreadTimes;
import com.android.server.power.stats.wakeups.CpuWakeupStats;

@@ -184,6 +185,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    private final BatteryUsageStatsProvider mBatteryUsageStatsProvider;
    private final AtomicFile mConfigFile;
    private final BatteryStats.BatteryStatsDumpHelper mDumpHelper;
    private final PowerStatsUidResolver mPowerStatsUidResolver;

    private volatile boolean mMonitorEnabled = true;

@@ -411,9 +413,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                        .setResetOnUnplugAfterSignificantCharge(resetOnUnplugAfterSignificantCharge)
                        .setPowerStatsThrottlePeriodCpu(powerStatsThrottlePeriodCpu)
                        .build();
        mPowerStatsUidResolver = new PowerStatsUidResolver();
        mStats = new BatteryStatsImpl(mBatteryStatsConfig, Clock.SYSTEM_CLOCK, mMonotonicClock,
                systemDir, handler, this, this, mUserManagerUserInfoProvider, mPowerProfile,
                mCpuScalingPolicies);
                mCpuScalingPolicies, mPowerStatsUidResolver);
        mWorker = new BatteryExternalStatsWorker(context, mStats);
        mStats.setExternalStatsSyncLocked(mWorker);
        mStats.setRadioScanningTimeoutLocked(mContext.getResources().getInteger(
@@ -784,25 +787,15 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    }

    void addIsolatedUid(final int isolatedUid, final int appUid) {
        synchronized (mLock) {
            final long elapsedRealtime = SystemClock.elapsedRealtime();
            final long uptime = SystemClock.uptimeMillis();
            mHandler.post(() -> {
                synchronized (mStats) {
                    mStats.addIsolatedUidLocked(isolatedUid, appUid, elapsedRealtime, uptime);
                }
            });
        }
        mPowerStatsUidResolver.noteIsolatedUidAdded(isolatedUid, appUid);
        FrameworkStatsLog.write(FrameworkStatsLog.ISOLATED_UID_CHANGED, appUid, isolatedUid,
                FrameworkStatsLog.ISOLATED_UID_CHANGED__EVENT__CREATED);
    }

    void removeIsolatedUid(final int isolatedUid, final int appUid) {
        synchronized (mLock) {
            mHandler.post(() -> {
                synchronized (mStats) {
                    mStats.scheduleRemoveIsolatedUidLocked(isolatedUid, appUid);
                }
            });
        }
        mPowerStatsUidResolver.noteIsolatedUidRemoved(isolatedUid, appUid);
        FrameworkStatsLog.write(FrameworkStatsLog.ISOLATED_UID_CHANGED, -1, isolatedUid,
                FrameworkStatsLog.ISOLATED_UID_CHANGED__EVENT__REMOVED);
    }

    void noteProcessStart(final String name, final int uid) {
@@ -3020,7 +3013,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                                        mBatteryStatsConfig, Clock.SYSTEM_CLOCK, mMonotonicClock,
                                        null, mStats.mHandler, null, null,
                                        mUserManagerUserInfoProvider, mPowerProfile,
                                        mCpuScalingPolicies);
                                        mCpuScalingPolicies, null);
                                checkinStats.readSummaryFromParcel(in);
                                in.recycle();
                                checkinStats.dumpProtoLocked(mContext, fd, apps, flags,
@@ -3062,7 +3055,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                                        mBatteryStatsConfig, Clock.SYSTEM_CLOCK, mMonotonicClock,
                                        null, mStats.mHandler, null, null,
                                        mUserManagerUserInfoProvider, mPowerProfile,
                                        mCpuScalingPolicies);
                                        mCpuScalingPolicies, null);
                                checkinStats.readSummaryFromParcel(in);
                                in.recycle();
                                checkinStats.dumpCheckin(mContext, pw, apps, flags,
+1 −4
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import static android.os.Process.getFreeMemory;
import static android.os.Process.getTotalMemory;
import static android.os.Process.killProcessQuiet;
import static android.os.Process.startWebView;
import static android.system.OsConstants.*;
import static android.system.OsConstants.EAGAIN;

import static com.android.sdksandbox.flags.Flags.selinuxSdkSandboxAudit;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LRU;
@@ -133,7 +133,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.ProcessMap;
import com.android.internal.os.Zygote;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.MemInfoReader;
import com.android.server.AppStateTracker;
import com.android.server.LocalServices;
@@ -3299,8 +3298,6 @@ public final class ProcessList {
            // about the process state of the isolated UID *before* it is registered with the
            // owning application.
            mService.mBatteryStatsService.addIsolatedUid(uid, info.uid);
            FrameworkStatsLog.write(FrameworkStatsLog.ISOLATED_UID_CHANGED, info.uid, uid,
                    FrameworkStatsLog.ISOLATED_UID_CHANGED__EVENT__CREATED);
        }
        final ProcessRecord r = new ProcessRecord(mService, info, proc, uid,
                sdkSandboxClientAppPackage,
+0 −16
Original line number Diff line number Diff line
@@ -44,11 +44,8 @@ import android.util.SparseLongArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.power.EnergyConsumerStats;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.LocalServices;

import libcore.util.EmptyArray;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
@@ -127,9 +124,6 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat
    @GuardedBy("this")
    private boolean mUseLatestStates = true;

    @GuardedBy("this")
    private final IntArray mUidsToRemove = new IntArray();

    @GuardedBy("this")
    private Future<?> mWakelockChangesUpdate;

@@ -260,7 +254,6 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat

    @Override
    public synchronized Future<?> scheduleCpuSyncDueToRemovedUid(int uid) {
        mUidsToRemove.add(uid);
        return scheduleSyncLocked("remove-uid", UPDATE_CPU);
    }

@@ -459,7 +452,6 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat
            // Capture a snapshot of the state we are meant to process.
            final int updateFlags;
            final String reason;
            final int[] uidsToRemove;
            final boolean onBattery;
            final boolean onBatteryScreenOff;
            final int screenState;
@@ -468,7 +460,6 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat
            synchronized (BatteryExternalStatsWorker.this) {
                updateFlags = mUpdateFlags;
                reason = mCurrentReason;
                uidsToRemove = mUidsToRemove.size() > 0 ? mUidsToRemove.toArray() : EmptyArray.INT;
                onBattery = mOnBattery;
                onBatteryScreenOff = mOnBatteryScreenOff;
                screenState = mScreenState;
@@ -476,7 +467,6 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat
                useLatestStates = mUseLatestStates;
                mUpdateFlags = 0;
                mCurrentReason = null;
                mUidsToRemove.clear();
                mCurrentFuture = null;
                mUseLatestStates = true;
                if ((updateFlags & UPDATE_ALL) == UPDATE_ALL) {
@@ -512,12 +502,6 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat

                // Clean up any UIDs if necessary.
                synchronized (mStats) {
                    for (int uid : uidsToRemove) {
                        FrameworkStatsLog.write(FrameworkStatsLog.ISOLATED_UID_CHANGED, -1, uid,
                                FrameworkStatsLog.ISOLATED_UID_CHANGED__EVENT__REMOVED);
                        mStats.maybeRemoveIsolatedUidLocked(uid, SystemClock.elapsedRealtime(),
                                SystemClock.uptimeMillis());
                    }
                    mStats.clearPendingRemovedUidsLocked();
                }
            } catch (Exception e) {
+64 −89
Original line number Diff line number Diff line
@@ -779,13 +779,10 @@ public class BatteryStatsImpl extends BatteryStats {
    private BatteryCallback mCallback;
    /**
     * Mapping isolated uids to the actual owning app uid.
     * Mapping child uids to their parent uid.
     */
    private final SparseIntArray mIsolatedUids = new SparseIntArray();
    /**
     * Internal reference count of isolated uids.
     */
    private final SparseIntArray mIsolatedUidRefCounts = new SparseIntArray();
    @VisibleForTesting
    protected final PowerStatsUidResolver mPowerStatsUidResolver;
    /**
     * The statistics we have collected organized by uids.
@@ -1718,10 +1715,12 @@ public class BatteryStatsImpl extends BatteryStats {
    }
    @VisibleForTesting
    public BatteryStatsImpl(Clock clock, File historyDirectory) {
    public BatteryStatsImpl(Clock clock, File historyDirectory, @NonNull Handler handler,
            @NonNull PowerStatsUidResolver powerStatsUidResolver) {
        init(clock);
        mBatteryStatsConfig = new BatteryStatsConfig.Builder().build();
        mHandler = null;
        mHandler = handler;
        mPowerStatsUidResolver = powerStatsUidResolver;
        mConstants = new Constants(mHandler);
        mStartClockTimeMs = clock.currentTimeMillis();
        mDailyFile = null;
@@ -4271,92 +4270,51 @@ public class BatteryStatsImpl extends BatteryStats {
        }
    }
    @GuardedBy("this")
    public void addIsolatedUidLocked(int isolatedUid, int appUid) {
        addIsolatedUidLocked(isolatedUid, appUid,
                mClock.elapsedRealtime(), mClock.uptimeMillis());
    private void onIsolatedUidAdded(int isolatedUid, int parentUid) {
        long realtime = mClock.elapsedRealtime();
        long uptime = mClock.uptimeMillis();
        synchronized (this) {
            getUidStatsLocked(parentUid, realtime, uptime).addIsolatedUid(isolatedUid);
        }
    @GuardedBy("this")
    @SuppressWarnings("GuardedBy")   // errorprone false positive on u.addIsolatedUid
    public void addIsolatedUidLocked(int isolatedUid, int appUid,
            long elapsedRealtimeMs, long uptimeMs) {
        mIsolatedUids.put(isolatedUid, appUid);
        mIsolatedUidRefCounts.put(isolatedUid, 1);
        final Uid u = getUidStatsLocked(appUid, elapsedRealtimeMs, uptimeMs);
        u.addIsolatedUid(isolatedUid);
    }
    /**
     * Schedules a read of the latest cpu times before removing the isolated UID.
     * @see #removeIsolatedUidLocked(int, int, int)
     */
    public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) {
        int curUid = mIsolatedUids.get(isolatedUid, -1);
        if (curUid == appUid) {
    private void onBeforeIsolatedUidRemoved(int isolatedUid, int parentUid) {
        long realtime = mClock.elapsedRealtime();
        mPowerStatsUidResolver.retainIsolatedUid(isolatedUid);
        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();
        synchronized (this) {
            getUidStatsLocked(parentUid, realtime, uptime).removeIsolatedUid(isolatedUid);
        }
    }
    /**
     * Isolated uid should only be removed after all wakelocks associated with the uid are stopped
     * and the cpu time-in-state has been read one last time for the uid.
     *
     * @see #scheduleRemoveIsolatedUidLocked(int, int)
     *
     * @return true if the isolated uid is actually removed.
     */
    @GuardedBy("this")
    public boolean maybeRemoveIsolatedUidLocked(int isolatedUid, long elapsedRealtimeMs,
            long uptimeMs) {
        final int refCount = mIsolatedUidRefCounts.get(isolatedUid, 0) - 1;
        if (refCount > 0) {
            // Isolated uid is still being tracked
            mIsolatedUidRefCounts.put(isolatedUid, refCount);
            return false;
        }
        final int idx = mIsolatedUids.indexOfKey(isolatedUid);
        if (idx >= 0) {
            final int ownerUid = mIsolatedUids.valueAt(idx);
            final Uid u = getUidStatsLocked(ownerUid, elapsedRealtimeMs, uptimeMs);
            u.removeIsolatedUid(isolatedUid);
            mIsolatedUids.removeAt(idx);
            mIsolatedUidRefCounts.delete(isolatedUid);
        } else {
            Slog.w(TAG, "Attempted to remove untracked isolated uid (" + isolatedUid + ")");
        }
        mPendingRemovedUids.add(new UidToRemove(isolatedUid, elapsedRealtimeMs));
        return true;
    }
    /**
     * Increment the ref count for an isolated uid.
     * call #maybeRemoveIsolatedUidLocked to decrement.
     */
    public void incrementIsolatedUidRefCount(int uid) {
        final int refCount = mIsolatedUidRefCounts.get(uid, 0);
        if (refCount <= 0) {
            // Uid is not mapped or referenced
            Slog.w(TAG,
                    "Attempted to increment ref counted of untracked isolated uid (" + uid + ")");
            return;
        }
        mIsolatedUidRefCounts.put(uid, refCount + 1);
    public void releaseIsolatedUidLocked(int isolatedUid, long elapsedRealtimeMs, long uptimeMs) {
        mPowerStatsUidResolver.releaseIsolatedUid(isolatedUid);
    }
    private int mapUid(int uid) {
        if (Process.isSdkSandboxUid(uid)) {
            return Process.getAppUidForSdkSandboxUid(uid);
        }
        return mapIsolatedUid(uid);
        return mPowerStatsUidResolver.mapUid(uid);
    }
    private int mapIsolatedUid(int uid) {
        return mIsolatedUids.get(/*key=*/uid, /*valueIfKeyNotFound=*/uid);
        return mPowerStatsUidResolver.mapUid(uid);
    }
    @GuardedBy("this")
@@ -4738,7 +4696,7 @@ public class BatteryStatsImpl extends BatteryStats {
            if (mappedUid != uid) {
                // Prevent the isolated uid mapping from being removed while the wakelock is
                // being held.
                incrementIsolatedUidRefCount(uid);
                mPowerStatsUidResolver.retainIsolatedUid(uid);
            }
            if (mOnBatteryScreenOffTimeBase.isRunning()) {
                // We only update the cpu time when a wake lock is acquired if the screen is off.
@@ -4818,7 +4776,7 @@ public class BatteryStatsImpl extends BatteryStats {
            if (mappedUid != uid) {
                // Decrement the ref count for the isolated uid and delete the mapping if uneeded.
                maybeRemoveIsolatedUidLocked(uid, elapsedRealtimeMs, uptimeMs);
                releaseIsolatedUidLocked(uid, elapsedRealtimeMs, uptimeMs);
            }
        }
    }
@@ -4989,7 +4947,7 @@ public class BatteryStatsImpl extends BatteryStats {
        if (mappedUid != uid) {
            // Prevent the isolated uid mapping from being removed while the wakelock is
            // being held.
            incrementIsolatedUidRefCount(uid);
            mPowerStatsUidResolver.retainIsolatedUid(uid);
        }
    }
@@ -5041,7 +4999,7 @@ public class BatteryStatsImpl extends BatteryStats {
                historyName, mappedUid);
        if (mappedUid != uid) {
            // Decrement the ref count for the isolated uid and delete the mapping if uneeded.
            maybeRemoveIsolatedUidLocked(uid, elapsedRealtimeMs, uptimeMs);
            releaseIsolatedUidLocked(uid, elapsedRealtimeMs, uptimeMs);
        }
    }
@@ -8208,7 +8166,9 @@ public class BatteryStatsImpl extends BatteryStats {
            return mProportionalSystemServiceUsage;
        }
        @GuardedBy("mBsi")
        /**
         * Adds isolated UID to the list of children.
         */
        public void addIsolatedUid(int isolatedUid) {
            if (mChildUids == null) {
                mChildUids = new SparseArray<>();
@@ -8218,6 +8178,9 @@ public class BatteryStatsImpl extends BatteryStats {
            mChildUids.put(isolatedUid, new ChildUid());
        }
        /**
         * Removes isolated UID from the list of children.
         */
        public void removeIsolatedUid(int isolatedUid) {
            final int idx = mChildUids == null ? -1 : mChildUids.indexOfKey(isolatedUid);
            if (idx < 0) {
@@ -10921,7 +10884,8 @@ public class BatteryStatsImpl extends BatteryStats {
            @NonNull Handler handler, @Nullable PlatformIdleStateCallback cb,
            @Nullable EnergyStatsRetriever energyStatsCb,
            @NonNull UserInfoProvider userInfoProvider, @NonNull PowerProfile powerProfile,
            @NonNull CpuScalingPolicies cpuScalingPolicies) {
            @NonNull CpuScalingPolicies cpuScalingPolicies,
            @NonNull PowerStatsUidResolver powerStatsUidResolver) {
        init(clock);
        mBatteryStatsConfig = config;
@@ -10931,6 +10895,7 @@ public class BatteryStatsImpl extends BatteryStats {
        mPowerProfile = powerProfile;
        mCpuScalingPolicies = cpuScalingPolicies;
        mPowerStatsUidResolver = powerStatsUidResolver;
        initPowerProfile();
@@ -10949,7 +10914,7 @@ public class BatteryStatsImpl extends BatteryStats {
        }
        mCpuPowerStatsCollector = new CpuPowerStatsCollector(mCpuScalingPolicies, mPowerProfile,
                () -> mBatteryVoltageMv, mHandler,
                mPowerStatsUidResolver, () -> mBatteryVoltageMv, mHandler,
                mBatteryStatsConfig.getPowerStatsThrottlePeriodCpu());
        mCpuPowerStatsCollector.addConsumer(this::recordPowerStats);
@@ -10966,6 +10931,23 @@ public class BatteryStatsImpl extends BatteryStats {
        mEnergyConsumerRetriever = energyStatsCb;
        mUserInfoProvider = userInfoProvider;
        mPowerStatsUidResolver.addListener(new PowerStatsUidResolver.Listener() {
            @Override
            public void onIsolatedUidAdded(int isolatedUid, int parentUid) {
                BatteryStatsImpl.this.onIsolatedUidAdded(isolatedUid, parentUid);
            }
            @Override
            public void onBeforeIsolatedUidRemoved(int isolatedUid, int parentUid) {
                BatteryStatsImpl.this.onBeforeIsolatedUidRemoved(isolatedUid, parentUid);
            }
            @Override
            public void onAfterIsolatedUidRemoved(int isolatedUid, int parentUid) {
                BatteryStatsImpl.this.onAfterIsolatedUidRemoved(isolatedUid, parentUid);
            }
        });
        // Notify statsd that the system is initially not in doze.
        mDeviceIdleMode = DEVICE_IDLE_MODE_OFF;
        FrameworkStatsLog.write(FrameworkStatsLog.DEVICE_IDLE_MODE_STATE_CHANGED, mDeviceIdleMode);
@@ -15182,6 +15164,7 @@ public class BatteryStatsImpl extends BatteryStats {
            if (mKernelSingleUidTimeReader != null) {
                mKernelSingleUidTimeReader.removeUidsInRange(startUid, endUid);
            }
            mPowerStatsUidResolver.releaseUidsInRange(startUid, endUid);
            // Treat as one. We don't know how many uids there are in between.
            mNumUidsRemoved++;
        } else {
@@ -17049,15 +17032,7 @@ public class BatteryStatsImpl extends BatteryStats {
            pw.print("UIDs removed since the later of device start or stats reset: ");
            pw.println(mNumUidsRemoved);
            pw.println("Currently mapped isolated uids:");
            final int numIsolatedUids = mIsolatedUids.size();
            for (int i = 0; i < numIsolatedUids; i++) {
                final int isolatedUid = mIsolatedUids.keyAt(i);
                final int ownerUid = mIsolatedUids.valueAt(i);
                final int refCount = mIsolatedUidRefCounts.get(isolatedUid);
                pw.println(
                        "  " + isolatedUid + "->" + ownerUid + " (ref count = " + refCount + ")");
            }
            mPowerStatsUidResolver.dump(pw);
            pw.println();
            dumpConstantsLocked(pw);
+23 −6
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.hardware.power.stats.EnergyConsumerType;
import android.os.BatteryConsumer;
import android.os.Handler;
import android.os.PersistableBundle;
import android.os.Process;
import android.power.PowerStatsInternal;
import android.util.Slog;
import android.util.SparseArray;
@@ -67,6 +68,7 @@ public class CpuPowerStatsCollector extends PowerStatsCollector {
    private final CpuScalingPolicies mCpuScalingPolicies;
    private final PowerProfile mPowerProfile;
    private final KernelCpuStatsReader mKernelCpuStatsReader;
    private final PowerStatsUidResolver mUidResolver;
    private final Supplier<PowerStatsInternal> mPowerStatsSupplier;
    private final IntSupplier mVoltageSupplier;
    private final int mDefaultCpuPowerBrackets;
@@ -247,8 +249,9 @@ public class CpuPowerStatsCollector extends PowerStatsCollector {
    }

    public CpuPowerStatsCollector(CpuScalingPolicies cpuScalingPolicies, PowerProfile powerProfile,
            IntSupplier voltageSupplier, Handler handler, long throttlePeriodMs) {
        this(cpuScalingPolicies, powerProfile, handler, new KernelCpuStatsReader(),
            PowerStatsUidResolver uidResolver, IntSupplier voltageSupplier, Handler handler,
            long throttlePeriodMs) {
        this(cpuScalingPolicies, powerProfile, handler, new KernelCpuStatsReader(), uidResolver,
                () -> LocalServices.getService(PowerStatsInternal.class), voltageSupplier,
                throttlePeriodMs, Clock.SYSTEM_CLOCK, DEFAULT_CPU_POWER_BRACKETS,
                DEFAULT_CPU_POWER_BRACKETS_PER_ENERGY_CONSUMER);
@@ -256,18 +259,18 @@ public class CpuPowerStatsCollector extends PowerStatsCollector {

    public CpuPowerStatsCollector(CpuScalingPolicies cpuScalingPolicies, PowerProfile powerProfile,
            Handler handler, KernelCpuStatsReader kernelCpuStatsReader,
            Supplier<PowerStatsInternal> powerStatsSupplier,
            PowerStatsUidResolver uidResolver, Supplier<PowerStatsInternal> powerStatsSupplier,
            IntSupplier voltageSupplier, long throttlePeriodMs, Clock clock,
            int defaultCpuPowerBrackets, int defaultCpuPowerBracketsPerEnergyConsumer) {
        super(handler, throttlePeriodMs, clock);
        mCpuScalingPolicies = cpuScalingPolicies;
        mPowerProfile = powerProfile;
        mKernelCpuStatsReader = kernelCpuStatsReader;
        mUidResolver = uidResolver;
        mPowerStatsSupplier = powerStatsSupplier;
        mVoltageSupplier = voltageSupplier;
        mDefaultCpuPowerBrackets = defaultCpuPowerBrackets;
        mDefaultCpuPowerBracketsPerEnergyConsumer = defaultCpuPowerBracketsPerEnergyConsumer;

    }

    /**
@@ -638,7 +641,21 @@ public class CpuPowerStatsCollector extends PowerStatsCollector {
            uidStats.timeByPowerBracket[bracket] = timeByPowerBracket[bracket];
        }
        if (nonzero) {
            mCpuPowerStats.uidStats.put(uid, uidStats.stats);
            int ownerUid;
            if (Process.isSdkSandboxUid(uid)) {
                ownerUid = Process.getAppUidForSdkSandboxUid(uid);
            } else {
                ownerUid = mUidResolver.mapUid(uid);
            }

            long[] ownerStats = mCpuPowerStats.uidStats.get(ownerUid);
            if (ownerStats == null) {
                mCpuPowerStats.uidStats.put(ownerUid, uidStats.stats);
            } else {
                for (int i = 0; i < ownerStats.length; i++) {
                    ownerStats[i] += uidStats.stats[i];
                }
            }
        }
    }

Loading