Loading core/java/android/os/BatteryStats.java +14 −0 Original line number Diff line number Diff line Loading @@ -1946,6 +1946,13 @@ public abstract class BatteryStats implements Parcelable { public static final int CONTROLLER_POWER_DRAIN = 3; public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_POWER_DRAIN + 1; /** * Returns true if the BatteryStats object has detailed bluetooth power reports. * When true, calling {@link #getBluetoothControllerActivity(int, int)} will yield the * actual power data. */ public abstract boolean hasBluetoothActivityReporting(); /** * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the Loading @@ -1955,6 +1962,13 @@ public abstract class BatteryStats implements Parcelable { */ public abstract long getBluetoothControllerActivity(int type, int which); /** * Returns true if the BatteryStats object has detailed WiFi power reports. * When true, calling {@link #getWifiControllerActivity(int, int)} will yield the * actual power data. */ public abstract boolean hasWifiActivityReporting(); /** * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the Loading core/java/com/android/internal/os/BatteryStatsHelper.java +6 −12 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.hardware.SensorManager; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; import android.os.BatteryStats; import android.os.BatteryStats.Uid; import android.os.Bundle; Loading Loading @@ -130,16 +129,11 @@ public final class BatteryStatsHelper { return !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); } public static boolean checkHasWifiPowerReporting(Context context, PowerProfile profile) { WifiManager manager = context.getSystemService(WifiManager.class); if (manager.isEnhancedPowerReportingSupported()) { if (profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_IDLE) != 0 && public static boolean checkHasWifiPowerReporting(BatteryStats stats, PowerProfile profile) { return stats.hasWifiActivityReporting() && profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_IDLE) != 0 && profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_RX) != 0 && profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_TX) != 0) { return true; } } return false; profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_TX) != 0; } public BatteryStatsHelper(Context context) { Loading Loading @@ -339,7 +333,7 @@ public final class BatteryStatsHelper { mMobileRadioPowerCalculator.reset(mStats); if (mWifiPowerCalculator == null) { if (checkHasWifiPowerReporting(mContext, mPowerProfile)) { if (checkHasWifiPowerReporting(mStats, mPowerProfile)) { mWifiPowerCalculator = new WifiPowerCalculator(mPowerProfile); } else { mWifiPowerCalculator = new WifiPowerEstimator(mPowerProfile); Loading core/java/com/android/internal/os/BatteryStatsImpl.java +17 −0 Original line number Diff line number Diff line Loading @@ -472,6 +472,8 @@ public final class BatteryStatsImpl extends BatteryStats { private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); private PowerProfile mPowerProfile; private boolean mHasWifiEnergyReporting = false; private boolean mHasBluetoothEnergyReporting = false; /* * Holds a SamplingTimer associated with each kernel wakelock name being tracked. Loading Loading @@ -4298,6 +4300,10 @@ public final class BatteryStatsImpl extends BatteryStats { return mBluetoothStateTimer[bluetoothState].getCountLocked(which); } @Override public boolean hasBluetoothActivityReporting() { return mHasBluetoothEnergyReporting; } @Override public long getBluetoothControllerActivity(int type, int which) { if (type >= 0 && type < mBluetoothActivityCounters.length) { return mBluetoothActivityCounters[type].getCountLocked(which); Loading @@ -4305,6 +4311,10 @@ public final class BatteryStatsImpl extends BatteryStats { return 0; } @Override public boolean hasWifiActivityReporting() { return mHasWifiEnergyReporting; } @Override public long getWifiControllerActivity(int type, int which) { if (type >= 0 && type < mWifiActivityCounters.length) { return mWifiActivityCounters[type].getCountLocked(which); Loading Loading @@ -7567,6 +7577,8 @@ public final class BatteryStatsImpl extends BatteryStats { } if (info != null) { mHasWifiEnergyReporting = true; // Measured in mAms final long txTimeMs = info.getControllerTxTimeMillis(); final long rxTimeMs = info.getControllerRxTimeMillis(); Loading Loading @@ -7778,6 +7790,7 @@ public final class BatteryStatsImpl extends BatteryStats { */ public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { if (info != null && mOnBatteryInternal && false) { mHasBluetoothEnergyReporting = true; mBluetoothActivityCounters[CONTROLLER_RX_TIME].addCountLocked( info.getControllerRxTimeMillis()); mBluetoothActivityCounters[CONTROLLER_TX_TIME].addCountLocked( Loading Loading @@ -9533,6 +9546,8 @@ public final class BatteryStatsImpl extends BatteryStats { mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); } mHasWifiEnergyReporting = in.readInt() != 0; mHasBluetoothEnergyReporting = in.readInt() != 0; mNumConnectivityChange = in.readInt(); mLoadedNumConnectivityChange = in.readInt(); mUnpluggedNumConnectivityChange = in.readInt(); Loading Loading @@ -9686,6 +9701,8 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { mWifiActivityCounters[i].writeToParcel(out); } out.writeInt(mHasWifiEnergyReporting ? 1 : 0); out.writeInt(mHasBluetoothEnergyReporting ? 1 : 0); out.writeInt(mNumConnectivityChange); out.writeInt(mLoadedNumConnectivityChange); out.writeInt(mUnpluggedNumConnectivityChange); Loading core/java/com/android/internal/os/WifiPowerCalculator.java +7 −0 Original line number Diff line number Diff line Loading @@ -16,12 +16,15 @@ package com.android.internal.os; import android.os.BatteryStats; import android.util.Log; /** * WiFi power calculator for when BatteryStats supports energy reporting * from the WiFi controller. */ public class WifiPowerCalculator extends PowerCalculator { private static final boolean DEBUG = BatteryStatsHelper.DEBUG; private static final String TAG = "WifiPowerCalculator"; private final double mIdleCurrentMa; private final double mTxCurrentMa; private final double mRxCurrentMa; Loading Loading @@ -75,6 +78,10 @@ public class WifiPowerCalculator extends PowerCalculator { + (rxTimeMs * mRxCurrentMa)) / (1000*60*60); } app.wifiPowerMah = Math.max(0, powerDrain - mTotalAppPowerDrain); if (DEBUG) { Log.d(TAG, "left over WiFi power: " + BatteryStatsHelper.makemAh(app.wifiPowerMah)); } } @Override Loading Loading
core/java/android/os/BatteryStats.java +14 −0 Original line number Diff line number Diff line Loading @@ -1946,6 +1946,13 @@ public abstract class BatteryStats implements Parcelable { public static final int CONTROLLER_POWER_DRAIN = 3; public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_POWER_DRAIN + 1; /** * Returns true if the BatteryStats object has detailed bluetooth power reports. * When true, calling {@link #getBluetoothControllerActivity(int, int)} will yield the * actual power data. */ public abstract boolean hasBluetoothActivityReporting(); /** * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the Loading @@ -1955,6 +1962,13 @@ public abstract class BatteryStats implements Parcelable { */ public abstract long getBluetoothControllerActivity(int type, int which); /** * Returns true if the BatteryStats object has detailed WiFi power reports. * When true, calling {@link #getWifiControllerActivity(int, int)} will yield the * actual power data. */ public abstract boolean hasWifiActivityReporting(); /** * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the Loading
core/java/com/android/internal/os/BatteryStatsHelper.java +6 −12 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.hardware.SensorManager; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; import android.os.BatteryStats; import android.os.BatteryStats.Uid; import android.os.Bundle; Loading Loading @@ -130,16 +129,11 @@ public final class BatteryStatsHelper { return !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); } public static boolean checkHasWifiPowerReporting(Context context, PowerProfile profile) { WifiManager manager = context.getSystemService(WifiManager.class); if (manager.isEnhancedPowerReportingSupported()) { if (profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_IDLE) != 0 && public static boolean checkHasWifiPowerReporting(BatteryStats stats, PowerProfile profile) { return stats.hasWifiActivityReporting() && profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_IDLE) != 0 && profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_RX) != 0 && profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_TX) != 0) { return true; } } return false; profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_TX) != 0; } public BatteryStatsHelper(Context context) { Loading Loading @@ -339,7 +333,7 @@ public final class BatteryStatsHelper { mMobileRadioPowerCalculator.reset(mStats); if (mWifiPowerCalculator == null) { if (checkHasWifiPowerReporting(mContext, mPowerProfile)) { if (checkHasWifiPowerReporting(mStats, mPowerProfile)) { mWifiPowerCalculator = new WifiPowerCalculator(mPowerProfile); } else { mWifiPowerCalculator = new WifiPowerEstimator(mPowerProfile); Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +17 −0 Original line number Diff line number Diff line Loading @@ -472,6 +472,8 @@ public final class BatteryStatsImpl extends BatteryStats { private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); private PowerProfile mPowerProfile; private boolean mHasWifiEnergyReporting = false; private boolean mHasBluetoothEnergyReporting = false; /* * Holds a SamplingTimer associated with each kernel wakelock name being tracked. Loading Loading @@ -4298,6 +4300,10 @@ public final class BatteryStatsImpl extends BatteryStats { return mBluetoothStateTimer[bluetoothState].getCountLocked(which); } @Override public boolean hasBluetoothActivityReporting() { return mHasBluetoothEnergyReporting; } @Override public long getBluetoothControllerActivity(int type, int which) { if (type >= 0 && type < mBluetoothActivityCounters.length) { return mBluetoothActivityCounters[type].getCountLocked(which); Loading @@ -4305,6 +4311,10 @@ public final class BatteryStatsImpl extends BatteryStats { return 0; } @Override public boolean hasWifiActivityReporting() { return mHasWifiEnergyReporting; } @Override public long getWifiControllerActivity(int type, int which) { if (type >= 0 && type < mWifiActivityCounters.length) { return mWifiActivityCounters[type].getCountLocked(which); Loading Loading @@ -7567,6 +7577,8 @@ public final class BatteryStatsImpl extends BatteryStats { } if (info != null) { mHasWifiEnergyReporting = true; // Measured in mAms final long txTimeMs = info.getControllerTxTimeMillis(); final long rxTimeMs = info.getControllerRxTimeMillis(); Loading Loading @@ -7778,6 +7790,7 @@ public final class BatteryStatsImpl extends BatteryStats { */ public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { if (info != null && mOnBatteryInternal && false) { mHasBluetoothEnergyReporting = true; mBluetoothActivityCounters[CONTROLLER_RX_TIME].addCountLocked( info.getControllerRxTimeMillis()); mBluetoothActivityCounters[CONTROLLER_TX_TIME].addCountLocked( Loading Loading @@ -9533,6 +9546,8 @@ public final class BatteryStatsImpl extends BatteryStats { mWifiActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); } mHasWifiEnergyReporting = in.readInt() != 0; mHasBluetoothEnergyReporting = in.readInt() != 0; mNumConnectivityChange = in.readInt(); mLoadedNumConnectivityChange = in.readInt(); mUnpluggedNumConnectivityChange = in.readInt(); Loading Loading @@ -9686,6 +9701,8 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i< NUM_CONTROLLER_ACTIVITY_TYPES; i++) { mWifiActivityCounters[i].writeToParcel(out); } out.writeInt(mHasWifiEnergyReporting ? 1 : 0); out.writeInt(mHasBluetoothEnergyReporting ? 1 : 0); out.writeInt(mNumConnectivityChange); out.writeInt(mLoadedNumConnectivityChange); out.writeInt(mUnpluggedNumConnectivityChange); Loading
core/java/com/android/internal/os/WifiPowerCalculator.java +7 −0 Original line number Diff line number Diff line Loading @@ -16,12 +16,15 @@ package com.android.internal.os; import android.os.BatteryStats; import android.util.Log; /** * WiFi power calculator for when BatteryStats supports energy reporting * from the WiFi controller. */ public class WifiPowerCalculator extends PowerCalculator { private static final boolean DEBUG = BatteryStatsHelper.DEBUG; private static final String TAG = "WifiPowerCalculator"; private final double mIdleCurrentMa; private final double mTxCurrentMa; private final double mRxCurrentMa; Loading Loading @@ -75,6 +78,10 @@ public class WifiPowerCalculator extends PowerCalculator { + (rxTimeMs * mRxCurrentMa)) / (1000*60*60); } app.wifiPowerMah = Math.max(0, powerDrain - mTotalAppPowerDrain); if (DEBUG) { Log.d(TAG, "left over WiFi power: " + BatteryStatsHelper.makemAh(app.wifiPowerMah)); } } @Override Loading