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

Commit eb5a068c authored by Bookatz's avatar Bookatz Committed by android-build-merger
Browse files

Merge "Add BLE results counter to batterystats" into oc-dev

am: 7080fa52

Change-Id: I8e485d5a97d46f6787b5b32c17ab5b85463f2653
parents 41564af2 7080fa52
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -521,6 +521,7 @@ public abstract class BatteryStats implements Parcelable {
        public abstract Timer getForegroundActivityTimer();
        public abstract Timer getBluetoothScanTimer();
        public abstract Timer getBluetoothScanBackgroundTimer();
        public abstract Counter getBluetoothScanResultCounter();

        // Note: the following times are disjoint.  They can be added together to find the
        // total time a uid has had any processes running at all.
@@ -3370,8 +3371,10 @@ public abstract class BatteryStats implements Parcelable {
                    final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
                    final long actualTimeBg = bleTimerBg != null ?
                            bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
                    final int resultCount = u.getBluetoothScanResultCounter() != null ?
                            u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
                    dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
                            countBg, actualTime, actualTimeBg);
                            countBg, actualTime, actualTimeBg, resultCount);
                }
            }

@@ -4523,6 +4526,8 @@ public abstract class BatteryStats implements Parcelable {
                    final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
                    final long actualTimeMsBg = bleTimerBg != null ?
                            bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
                    final int resultCount = u.getBluetoothScanResultCounter() != null ?
                            u.getBluetoothScanResultCounter().getCountLocked(which) : 0;

                    sb.setLength(0);
                    sb.append(prefix);
@@ -4547,6 +4552,8 @@ public abstract class BatteryStats implements Parcelable {
                        sb.append(countBg);
                        sb.append(" times)");
                    }
                    sb.append("; Results count ");
                    sb.append(resultCount);
                    pw.println(sb.toString());
                    uidActivity = true;
                }
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ interface IBatteryStats {
    void noteBleScanStarted(in WorkSource ws);
    void noteBleScanStopped(in WorkSource ws);
    void noteResetBleScan();
    void noteBleScanResult(in WorkSource ws);

    HealthStatsParceler takeUidSnapshot(int uid);
    HealthStatsParceler[] takeUidSnapshots(in int[] uid);
+53 −1
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ public class BatteryStatsImpl extends BatteryStats {
    private static final int MAGIC = 0xBA757475; // 'BATSTATS'

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

    // Maximum number of items we will record in the history.
    private static final int MAX_HISTORY_ITEMS = 2000;
@@ -4704,6 +4704,14 @@ public class BatteryStatsImpl extends BatteryStats {
        }
    }

    public void noteBluetoothScanResultFromSourceLocked(WorkSource ws) {
        final int N = ws.size();
        for (int i = 0; i < N; i++) {
            int uid = mapUid(ws.get(i));
            getUidStatsLocked(uid).noteBluetoothScanResultLocked();
        }
    }

    private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis,
            final long uptimeMillis, int uid) {
        uid = mapUid(uid);
@@ -5421,6 +5429,7 @@ public class BatteryStatsImpl extends BatteryStats {
        StopwatchTimer mCameraTurnedOnTimer;
        StopwatchTimer mForegroundActivityTimer;
        DualTimer mBluetoothScanTimer;
        Counter mBluetoothScanResultCounter;

        int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT;
        StopwatchTimer[] mProcessStateTimer;
@@ -5864,6 +5873,17 @@ public class BatteryStatsImpl extends BatteryStats {
            }
        }

        public Counter createBluetoothScanResultCounterLocked() {
            if (mBluetoothScanResultCounter == null) {
                mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase);
            }
            return mBluetoothScanResultCounter;
        }

        public void noteBluetoothScanResultLocked() {
            createBluetoothScanResultCounterLocked().stepAtomic();
        }

        @Override
        public void noteActivityResumedLocked(long elapsedRealtimeMs) {
            // We always start, since we want multiple foreground PIDs to nest
@@ -6017,6 +6037,11 @@ public class BatteryStatsImpl extends BatteryStats {
            return mBluetoothScanTimer.getSubTimer();
        }

        @Override
        public Counter getBluetoothScanResultCounter() {
            return mBluetoothScanResultCounter;
        }

        void makeProcessState(int i, Parcel in) {
            if (i < 0 || i >= NUM_PROCESS_STATE) return;

@@ -6266,6 +6291,9 @@ public class BatteryStatsImpl extends BatteryStats {
            active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false);
            active |= !resetTimerIfNotNull(mForegroundActivityTimer, false);
            active |= !resetTimerIfNotNull(mBluetoothScanTimer, false);
            if (mBluetoothScanResultCounter != null) {
                mBluetoothScanResultCounter.reset(false);
            }

            if (mProcessStateTimer != null) {
                for (int i = 0; i < NUM_PROCESS_STATE; i++) {
@@ -6450,6 +6478,10 @@ public class BatteryStatsImpl extends BatteryStats {
                    mBluetoothScanTimer.detach();
                    mBluetoothScanTimer = null;
                }
                if (mBluetoothScanResultCounter != null) {
                    mBluetoothScanResultCounter.detach();
                    mBluetoothScanResultCounter = null;
                }
                if (mUserActivityCounters != null) {
                    for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) {
                        mUserActivityCounters[i].detach();
@@ -6620,6 +6652,12 @@ public class BatteryStatsImpl extends BatteryStats {
            } else {
                out.writeInt(0);
            }
            if (mBluetoothScanResultCounter != null) {
                out.writeInt(1);
                mBluetoothScanResultCounter.writeToParcel(out);
            } else {
                out.writeInt(0);
            }
            for (int i = 0; i < NUM_PROCESS_STATE; i++) {
                if (mProcessStateTimer[i] != null) {
                    out.writeInt(1);
@@ -6850,6 +6888,11 @@ public class BatteryStatsImpl extends BatteryStats {
            } else {
                mBluetoothScanTimer = null;
            }
            if (in.readInt() != 0) {
                mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase, in);
            } else {
                mBluetoothScanResultCounter = null;
            }
            mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT;
            for (int i = 0; i < NUM_PROCESS_STATE; i++) {
                if (in.readInt() != 0) {
@@ -10998,6 +11041,9 @@ public class BatteryStatsImpl extends BatteryStats {
            if (in.readInt() != 0) {
                u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in);
            }
            if (in.readInt() != 0) {
                u.createBluetoothScanResultCounterLocked().readSummaryFromParcelLocked(in);
            }
            u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT;
            for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) {
                if (in.readInt() != 0) {
@@ -11391,6 +11437,12 @@ public class BatteryStatsImpl extends BatteryStats {
            } else {
                out.writeInt(0);
            }
            if (u.mBluetoothScanResultCounter != null) {
                out.writeInt(1);
                u.mBluetoothScanResultCounter.writeSummaryFromParcelLocked(out);
            } else {
                out.writeInt(0);
            }
            for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) {
                if (u.mProcessStateTimer[i] != null) {
                    out.writeInt(1);
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.android.internal.os;

import static android.os.BatteryStats.STATS_SINCE_CHARGED;

import android.os.WorkSource;
import android.support.test.filters.SmallTest;

import junit.framework.TestCase;

/**
 * Test various BatteryStatsImpl noteStart methods.
 */
public class BatteryStatsNoteTest extends TestCase{
    private static final int UID = 10500;
    private static final WorkSource WS = new WorkSource(UID);

    /** Test that BatteryStatsImpl.Uid.noteBluetoothScanResultLocked. */
    @SmallTest
    public void testNoteBluetoothScanResultLocked() throws Exception {
        MockBatteryStatsImpl bi = new MockBatteryStatsImpl(new MockClocks());
        bi.updateTimeBasesLocked(true, true, 0, 0);

        bi.noteBluetoothScanResultFromSourceLocked(WS);
        bi.noteBluetoothScanResultFromSourceLocked(WS);
        assertEquals(2,
                bi.getUidStats().get(UID).getBluetoothScanResultCounter()
                        .getCountLocked(STATS_SINCE_CHARGED));
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import org.junit.runners.Suite;
        BatteryStatsUidTest.class,
        BatteryStatsSensorTest.class,
        BatteryStatsBackgroundStatsTest.class,
        BatteryStatsNoteTest.class,
    })
public class BatteryStatsTests {
}
Loading