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

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

Merge "Fold SDK Sandbox UID battery stats into parent UID stats" into tm-dev

parents d8c04441 70a3d9e8
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -546,9 +546,9 @@ public class BatteryStatsImpl extends BatteryStats {
                final LongArrayMultiStateCounter onBatteryScreenOffCounter =
                        u.getProcStateScreenOffTimeCounter().getCounter();
                if (uid == parentUid) {
                    mKernelSingleUidTimeReader.addDelta(uid, onBatteryCounter, timestampMs);
                    mKernelSingleUidTimeReader.addDelta(uid, onBatteryScreenOffCounter,
                if (uid == parentUid || Process.isSdkSandboxUid(uid)) {
                    mKernelSingleUidTimeReader.addDelta(parentUid, onBatteryCounter, timestampMs);
                    mKernelSingleUidTimeReader.addDelta(parentUid, onBatteryScreenOffCounter,
                            timestampMs);
                } else {
                    Uid.ChildUid childUid = u.getChildUid(uid);
@@ -4560,7 +4560,10 @@ public class BatteryStatsImpl extends BatteryStats {
        mIsolatedUidRefCounts.put(uid, refCount + 1);
    }
    public int mapUid(int uid) {
    private int mapUid(int uid) {
        if (Process.isSdkSandboxUid(uid)) {
            return Process.getAppUidForSdkSandboxUid(uid);
        }
        int isolated = mIsolatedUids.get(uid, -1);
        return isolated > 0 ? isolated : uid;
    }
@@ -4656,16 +4659,18 @@ public class BatteryStatsImpl extends BatteryStats {
            long elapsedRealtimeMs, long uptimeMs) {
        int parentUid = mapUid(uid);
        if (uid != parentUid) {
            if (Process.isIsolated(uid)) {
                // Isolated UIDs process state is already rolled up into parent, so no need to track
                // Otherwise the parent's process state will get downgraded incorrectly
                return;
            }
        }
        // TODO(b/155216561): It is possible for isolated uids to be in a higher
        // state than its parent uid. We should track the highest state within the union of host
        // and isolated uids rather than only the parent uid.
        FrameworkStatsLog.write(FrameworkStatsLog.UID_PROCESS_STATE_CHANGED, uid,
                ActivityManager.processStateAmToProto(state));
        getUidStatsLocked(uid, elapsedRealtimeMs, uptimeMs)
        getUidStatsLocked(parentUid, elapsedRealtimeMs, uptimeMs)
                .updateUidProcessStateLocked(state, elapsedRealtimeMs, uptimeMs);
    }
@@ -15970,6 +15975,9 @@ public class BatteryStatsImpl extends BatteryStats {
    public Uid getUidStatsLocked(int uid, long elapsedRealtimeMs, long uptimeMs) {
        Uid u = mUidStats.get(uid);
        if (u == null) {
            if (Process.isSdkSandboxUid(uid)) {
                Log.wtf(TAG, "Tracking an SDK Sandbox UID");
            }
            u = new Uid(this, uid, elapsedRealtimeMs, uptimeMs);
            mUidStats.put(uid, u);
        }
+1 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import junit.framework.TestCase;
public class BatteryStatsSensorTest extends TestCase {

    private static final int UID = 10500;
    private static final int UID_2 = 10501; // second uid for testing pool usage
    private static final int SENSOR_ID = -10000;

    @SmallTest
@@ -239,7 +240,6 @@ public class BatteryStatsSensorTest extends TestCase {

    @SmallTest
    public void testPooledBackgroundUsage() throws Exception {
        final int UID_2 = 20000; // second uid for testing pool usage
        final MockClock clocks = new MockClock();
        MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks);
        bi.mForceOnBattery = true;
+1 −2
Original line number Diff line number Diff line
@@ -1886,8 +1886,7 @@ public class AppProfiler {
                                    BatteryStatsImpl.Uid.Proc ps = st.batteryStats;
                                    if (ps == null || !ps.isActive()) {
                                        st.batteryStats = ps = bstats.getProcessStatsLocked(
                                                bstats.mapUid(st.uid), st.name,
                                                elapsedRealtime, uptime);
                                                st.uid, st.name, elapsedRealtime, uptime);
                                    }
                                    ps.addCpuTimeLocked(st.rel_utime, st.rel_stime);
                                }