Merge "CustomMeasuredPowerCalculator" into sc-dev
This commit is contained in:
@@ -5294,6 +5294,12 @@ public abstract class BatteryStats implements Parcelable {
|
||||
pw.print(" flash=");
|
||||
printmAh(pw, bs.flashlightPowerMah);
|
||||
}
|
||||
if (bs.customMeasuredPowerMah != null) {
|
||||
for (int idx = 0; idx < bs.customMeasuredPowerMah.length; idx++) {
|
||||
pw.print(" custom[" + idx + "]=");
|
||||
printmAh(pw, bs.customMeasuredPowerMah[idx]);
|
||||
}
|
||||
}
|
||||
pw.print(" )");
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
public double wakeLockPowerMah;
|
||||
public double wifiPowerMah;
|
||||
public double systemServiceCpuPowerMah;
|
||||
public double[] customMeasuredPowerMah;
|
||||
|
||||
// Do not include this sipper in results because it is included
|
||||
// in an aggregate sipper.
|
||||
@@ -251,6 +252,17 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
proportionalSmearMah += other.proportionalSmearMah;
|
||||
totalSmearedPowerMah += other.totalSmearedPowerMah;
|
||||
systemServiceCpuPowerMah += other.systemServiceCpuPowerMah;
|
||||
if (other.customMeasuredPowerMah != null) {
|
||||
if (customMeasuredPowerMah == null) {
|
||||
customMeasuredPowerMah = new double[other.customMeasuredPowerMah.length];
|
||||
}
|
||||
if (customMeasuredPowerMah.length == other.customMeasuredPowerMah.length) {
|
||||
// This should always be true.
|
||||
for (int idx = 0; idx < other.customMeasuredPowerMah.length; idx++) {
|
||||
customMeasuredPowerMah[idx] += other.customMeasuredPowerMah[idx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,6 +276,11 @@ public class BatterySipper implements Comparable<BatterySipper> {
|
||||
sensorPowerMah + mobileRadioPowerMah + wakeLockPowerMah + cameraPowerMah +
|
||||
flashlightPowerMah + bluetoothPowerMah + audioPowerMah + videoPowerMah
|
||||
+ systemServiceCpuPowerMah;
|
||||
if (customMeasuredPowerMah != null) {
|
||||
for (int idx = 0; idx < customMeasuredPowerMah.length; idx++) {
|
||||
totalPowerMah += customMeasuredPowerMah[idx];
|
||||
}
|
||||
}
|
||||
totalSmearedPowerMah = totalPowerMah + screenPowerMah + proportionalSmearMah;
|
||||
|
||||
return totalPowerMah;
|
||||
|
||||
@@ -347,6 +347,7 @@ public class BatteryStatsHelper {
|
||||
mPowerCalculators.add(new AmbientDisplayPowerCalculator(mPowerProfile));
|
||||
mPowerCalculators.add(new SystemServicePowerCalculator(mPowerProfile));
|
||||
mPowerCalculators.add(new IdlePowerCalculator(mPowerProfile));
|
||||
mPowerCalculators.add(new CustomMeasuredPowerCalculator(mPowerProfile));
|
||||
|
||||
mPowerCalculators.add(new UserPowerCalculator());
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ public class BatteryUsageStatsProvider {
|
||||
mPowerCalculators.add(new AmbientDisplayPowerCalculator(mPowerProfile));
|
||||
mPowerCalculators.add(new SystemServicePowerCalculator(mPowerProfile));
|
||||
mPowerCalculators.add(new IdlePowerCalculator(mPowerProfile));
|
||||
mPowerCalculators.add(new CustomMeasuredPowerCalculator(mPowerProfile));
|
||||
|
||||
mPowerCalculators.add(new UserPowerCalculator());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 android.os.BatteryStats;
|
||||
|
||||
/**
|
||||
* Calculates the amount of power consumed by custom energy consumers (i.e. consumers of type
|
||||
* {@link android.hardware.power.stats.EnergyConsumerType#OTHER}).
|
||||
*/
|
||||
public class CustomMeasuredPowerCalculator extends PowerCalculator {
|
||||
public CustomMeasuredPowerCalculator(PowerProfile powerProfile) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
|
||||
long rawUptimeUs, int statsType) {
|
||||
updateCustomMeasuredPowerMah(app, u.getCustomMeasuredEnergiesMicroJoules());
|
||||
}
|
||||
|
||||
private void updateCustomMeasuredPowerMah(BatterySipper sipper, long[] measuredEnergiesUJ) {
|
||||
sipper.customMeasuredPowerMah = calculateMeasuredEnergiesMah(measuredEnergiesUJ);
|
||||
}
|
||||
|
||||
private double[] calculateMeasuredEnergiesMah(long[] measuredEnergiesUJ) {
|
||||
if (measuredEnergiesUJ == null) {
|
||||
return null;
|
||||
}
|
||||
final double[] measuredEnergiesMah = new double[measuredEnergiesUJ.length];
|
||||
for (int i = 0; i < measuredEnergiesUJ.length; i++) {
|
||||
measuredEnergiesMah[i] = uJtoMah(measuredEnergiesUJ[i]);
|
||||
}
|
||||
return measuredEnergiesMah;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user