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

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

Merge "Optimize retrieval of attributed power by process state"

parents 9b9f6b5e df174313
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -673,6 +673,7 @@ public abstract class BatteryConsumer {
        public final int firstCustomConsumedPowerColumn;
        public final int firstCustomUsageDurationColumn;
        public final int columnCount;
        public final Key[][] processStateKeys;

        private BatteryConsumerDataLayout(int firstColumn, String[] customPowerComponentNames,
                boolean powerModelsIncluded, boolean includeProcessStateData) {
@@ -728,6 +729,28 @@ public abstract class BatteryConsumer {
                keys[componentId] = perComponentKeys.toArray(KEY_ARRAY);
            }

            if (includeProcessStateData) {
                processStateKeys = new Key[BatteryConsumer.PROCESS_STATE_COUNT][];
                ArrayList<Key> perProcStateKeys = new ArrayList<>();
                for (int processState = 0; processState < PROCESS_STATE_COUNT; processState++) {
                    if (processState == PROCESS_STATE_UNSPECIFIED) {
                        continue;
                    }

                    perProcStateKeys.clear();
                    for (int i = 0; i < keys.length; i++) {
                        for (int j = 0; j < keys[i].length; j++) {
                            if (keys[i][j].processState == processState) {
                                perProcStateKeys.add(keys[i][j]);
                            }
                        }
                    }
                    processStateKeys[processState] = perProcStateKeys.toArray(KEY_ARRAY);
                }
            } else {
                processStateKeys = null;
            }

            firstCustomConsumedPowerColumn = columnIndex;
            columnIndex += customPowerComponentCount;

+7 −11
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package android.os;

import static android.os.BatteryConsumer.POWER_COMPONENT_ANY;
import static android.os.BatteryConsumer.POWER_COMPONENT_COUNT;
import static android.os.BatteryConsumer.PROCESS_STATE_ANY;
import static android.os.BatteryConsumer.PROCESS_STATE_UNSPECIFIED;
import static android.os.BatteryConsumer.convertMahToDeciCoulombs;
@@ -60,19 +59,16 @@ class PowerComponents {
            return mData.getDouble(mData.getKeyOrThrow(dimensions.powerComponent,
                    dimensions.processState).mPowerColumnIndex);
        } else if (dimensions.processState != PROCESS_STATE_ANY) {
            boolean foundSome = false;
            double totalPowerMah = 0;
            for (int componentId = 0; componentId < POWER_COMPONENT_COUNT; componentId++) {
                BatteryConsumer.Key key = mData.getKey(componentId, dimensions.processState);
                if (key != null) {
                    foundSome = true;
                    totalPowerMah += mData.getDouble(key.mPowerColumnIndex);
                }
            }
            if (!foundSome) {
            if (!mData.layout.processStateDataIncluded) {
                throw new IllegalArgumentException(
                        "No data included in BatteryUsageStats for " + dimensions);
            }
            final BatteryConsumer.Key[] keys =
                    mData.layout.processStateKeys[dimensions.processState];
            double totalPowerMah = 0;
            for (int i = keys.length - 1; i >= 0; i--) {
                totalPowerMah += mData.getDouble(keys[i].mPowerColumnIndex);
            }
            return totalPowerMah;
        } else {
            return mData.getDouble(mData.layout.totalConsumedPowerColumnIndex);