summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/os/BatteryStats.java44
-rw-r--r--core/java/com/android/internal/app/IBatteryStats.aidl1
-rw-r--r--core/java/com/android/internal/os/BatterySipper.java10
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java348
-rw-r--r--core/java/com/android/internal/os/BluetoothPowerCalculator.java41
-rw-r--r--core/java/com/android/internal/os/WifiPowerCalculator.java8
-rw-r--r--services/core/java/com/android/server/am/BatteryStatsService.java70
7 files changed, 435 insertions, 87 deletions
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 52fa2ed162f1..b33e807235bf 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -147,6 +147,11 @@ public abstract class BatteryStats implements Parcelable {
public static final int WAKE_TYPE_DRAW = 18;
/**
+ * A constant indicating a bluetooth scan timer.
+ */
+ public static final int BLUETOOTH_SCAN_ON = 19;
+
+ /**
* Include all of the data in the stats, including previously saved data.
*/
public static final int STATS_SINCE_CHARGED = 0;
@@ -438,6 +443,7 @@ public abstract class BatteryStats implements Parcelable {
public abstract Timer getFlashlightTurnedOnTimer();
public abstract Timer getCameraTurnedOnTimer();
public abstract Timer getForegroundActivityTimer();
+ public abstract Timer getBluetoothScanTimer();
// Time this uid has any processes in the top state.
public static final int PROCESS_STATE_TOP = 0;
@@ -1179,6 +1185,7 @@ public abstract class BatteryStats implements Parcelable {
public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
public static final int STATE2_CAMERA_FLAG = 1<<21;
+ public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
public static final int MOST_INTERESTING_STATES2 =
STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
@@ -1922,6 +1929,7 @@ public abstract class BatteryStats implements Parcelable {
HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
+ new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
};
public static final String[] HISTORY_EVENT_NAMES = new String[] {
@@ -2041,6 +2049,13 @@ public abstract class BatteryStats implements Parcelable {
*/
public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
+ /**
+ * Returns the time in microseconds that bluetooth scans were running while the device was
+ * on battery.
+ *
+ * {@hide}
+ */
+ public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
public static final int NETWORK_MOBILE_RX_DATA = 0;
public static final int NETWORK_MOBILE_TX_DATA = 1;
@@ -2797,9 +2812,12 @@ public abstract class BatteryStats implements Parcelable {
final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
+ final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
+ final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
- mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
+ mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
+ btRxTotalBytes, btTxTotalBytes);
// Dump Modem controller stats
dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
@@ -3017,14 +3035,18 @@ public abstract class BatteryStats implements Parcelable {
final int mobileActiveCount = u.getMobileRadioActiveCount(which);
final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
+ final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
+ final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
|| mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
- || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
+ || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
+ || btBytesRx > 0 || btBytesTx > 0) {
dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
wifiBytesRx, wifiBytesTx,
mobilePacketsRx, mobilePacketsTx,
wifiPacketsRx, wifiPacketsTx,
- mobileActiveTime, mobileActiveCount);
+ mobileActiveTime, mobileActiveCount,
+ btBytesRx, btBytesTx);
}
// Dump modem controller data, per UID.
@@ -3046,6 +3068,9 @@ public abstract class BatteryStats implements Parcelable {
dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
u.getWifiControllerActivity(), which);
+ dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
+ u.getBluetoothControllerActivity(), which);
+
if (u.hasUserActivity()) {
args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
boolean hasData = false;
@@ -3668,6 +3693,12 @@ public abstract class BatteryStats implements Parcelable {
pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
+ final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
+ sb.setLength(0);
+ sb.append(prefix);
+ sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
+ pw.println(sb.toString());
+
printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
which);
@@ -3793,6 +3824,10 @@ public abstract class BatteryStats implements Parcelable {
pw.print(" wifi=");
printmAh(pw, bs.wifiPowerMah);
}
+ if (bs.bluetoothPowerMah != 0) {
+ pw.print(" bt=");
+ printmAh(pw, bs.bluetoothPowerMah);
+ }
if (bs.gpsPowerMah != 0) {
pw.print(" gps=");
printmAh(pw, bs.gpsPowerMah);
@@ -4035,6 +4070,9 @@ public abstract class BatteryStats implements Parcelable {
pw.println(" sent");
}
+ uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix,
+ "Bluetooth Scan");
+
if (u.hasUserActivity()) {
boolean hasData = false;
for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl
index ec53a2ec6366..74fe94f96ddb 100644
--- a/core/java/com/android/internal/app/IBatteryStats.aidl
+++ b/core/java/com/android/internal/app/IBatteryStats.aidl
@@ -124,4 +124,5 @@ interface IBatteryStats {
void noteBleScanStarted(in WorkSource ws);
void noteBleScanStopped(in WorkSource ws);
+ void noteResetBleScan();
}
diff --git a/core/java/com/android/internal/os/BatterySipper.java b/core/java/com/android/internal/os/BatterySipper.java
index 049d3eb26409..d92e59691fe9 100644
--- a/core/java/com/android/internal/os/BatterySipper.java
+++ b/core/java/com/android/internal/os/BatterySipper.java
@@ -44,6 +44,7 @@ public class BatterySipper implements Comparable<BatterySipper> {
public long wakeLockTimeMs;
public long cameraTimeMs;
public long flashlightTimeMs;
+ public long bluetoothRunningTimeMs;
public long mobileRxPackets;
public long mobileTxPackets;
@@ -56,6 +57,8 @@ public class BatterySipper implements Comparable<BatterySipper> {
public long mobileTxBytes;
public long wifiRxBytes;
public long wifiTxBytes;
+ public long btRxBytes;
+ public long btTxBytes;
public double percent;
public double noCoveragePercent;
public String[] mPackages;
@@ -71,6 +74,7 @@ public class BatterySipper implements Comparable<BatterySipper> {
public double sensorPowerMah;
public double cameraPowerMah;
public double flashlightPowerMah;
+ public double bluetoothPowerMah;
public enum DrainType {
IDLE,
@@ -142,6 +146,7 @@ public class BatterySipper implements Comparable<BatterySipper> {
wakeLockTimeMs += other.wakeLockTimeMs;
cameraTimeMs += other.cameraTimeMs;
flashlightTimeMs += other.flashlightTimeMs;
+ bluetoothRunningTimeMs += other.bluetoothRunningTimeMs;
mobileRxPackets += other.mobileRxPackets;
mobileTxPackets += other.mobileTxPackets;
mobileActive += other.mobileActive;
@@ -152,6 +157,8 @@ public class BatterySipper implements Comparable<BatterySipper> {
mobileTxBytes += other.mobileTxBytes;
wifiRxBytes += other.wifiRxBytes;
wifiTxBytes += other.wifiTxBytes;
+ btRxBytes += other.btRxBytes;
+ btTxBytes += other.btTxBytes;
wifiPowerMah += other.wifiPowerMah;
gpsPowerMah += other.gpsPowerMah;
cpuPowerMah += other.cpuPowerMah;
@@ -160,6 +167,7 @@ public class BatterySipper implements Comparable<BatterySipper> {
wakeLockPowerMah += other.wakeLockPowerMah;
cameraPowerMah += other.cameraPowerMah;
flashlightPowerMah += other.flashlightPowerMah;
+ bluetoothPowerMah += other.bluetoothPowerMah;
}
/**
@@ -169,6 +177,6 @@ public class BatterySipper implements Comparable<BatterySipper> {
public double sumPower() {
return totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah +
sensorPowerMah + mobileRadioPowerMah + wakeLockPowerMah + cameraPowerMah +
- flashlightPowerMah;
+ flashlightPowerMah + bluetoothPowerMah;
}
}
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index e2ccaae1e87f..648b1a54927d 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -107,7 +107,7 @@ public final class BatteryStatsImpl extends BatteryStats {
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
// Current on-disk Parcel version
- private static final int VERSION = 140 + (USE_OLD_HISTORY ? 1000 : 0);
+ private static final int VERSION = 141 + (USE_OLD_HISTORY ? 1000 : 0);
// Maximum number of items we will record in the history.
private static final int MAX_HISTORY_ITEMS = 2000;
@@ -186,8 +186,13 @@ public final class BatteryStatsImpl extends BatteryStats {
}
public interface ExternalStatsSync {
- void scheduleSync(String reason);
- void scheduleWifiSync(String reason);
+ public static final int UPDATE_CPU = 0x01;
+ public static final int UPDATE_WIFI = 0x02;
+ public static final int UPDATE_RADIO = 0x04;
+ public static final int UPDATE_BT = 0x08;
+ public static final int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT;
+
+ void scheduleSync(String reason, int flags);
void scheduleCpuSyncDueToRemovedUid(int uid);
}
@@ -224,6 +229,7 @@ public final class BatteryStatsImpl extends BatteryStats {
final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>();
final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>();
final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>();
+ final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>();
// Last partial timers we use for distributing CPU usage.
final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>();
@@ -435,6 +441,9 @@ public final class BatteryStatsImpl extends BatteryStats {
final StopwatchTimer[] mWifiSignalStrengthsTimer =
new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS];
+ int mBluetoothScanNesting;
+ StopwatchTimer mBluetoothScanTimer;
+
int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
long mMobileRadioActiveStartTime;
StopwatchTimer mMobileRadioActiveTimer;
@@ -3714,7 +3723,7 @@ public final class BatteryStatsImpl extends BatteryStats {
addHistoryRecordLocked(elapsedRealtime, uptime);
mWifiOn = true;
mWifiOnTimer.startRunningLocked(elapsedRealtime);
- scheduleSyncExternalWifiStatsLocked("wifi-off");
+ scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI);
}
}
@@ -3728,7 +3737,7 @@ public final class BatteryStatsImpl extends BatteryStats {
addHistoryRecordLocked(elapsedRealtime, uptime);
mWifiOn = false;
mWifiOnTimer.stopRunningLocked(elapsedRealtime);
- scheduleSyncExternalWifiStatsLocked("wifi-on");
+ scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI);
}
}
@@ -3946,6 +3955,65 @@ public final class BatteryStatsImpl extends BatteryStats {
}
}
+ private void noteBluetoothScanStartedLocked(int uid) {
+ uid = mapUid(uid);
+ final long elapsedRealtime = SystemClock.elapsedRealtime();
+ final long uptime = SystemClock.uptimeMillis();
+ if (mBluetoothScanNesting == 0) {
+ mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG;
+ if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: "
+ + Integer.toHexString(mHistoryCur.states2));
+ addHistoryRecordLocked(elapsedRealtime, uptime);
+ }
+ mBluetoothScanNesting++;
+ getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime);
+ }
+
+ public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws) {
+ final int N = ws.size();
+ for (int i = 0; i < N; i++) {
+ noteBluetoothScanStartedLocked(ws.get(i));
+ }
+ }
+
+ private void noteBluetoothScanStoppedLocked(int uid) {
+ uid = mapUid(uid);
+ final long elapsedRealtime = SystemClock.elapsedRealtime();
+ final long uptime = SystemClock.uptimeMillis();
+ mBluetoothScanNesting--;
+ if (mBluetoothScanNesting == 0) {
+ mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG;
+ if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: "
+ + Integer.toHexString(mHistoryCur.states2));
+ addHistoryRecordLocked(elapsedRealtime, uptime);
+ }
+ getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime);
+ }
+
+ public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws) {
+ final int N = ws.size();
+ for (int i = 0; i < N; i++) {
+ noteBluetoothScanStoppedLocked(ws.get(i));
+ }
+ }
+
+ public void noteResetBluetoothScanLocked() {
+ if (mBluetoothScanNesting > 0) {
+ final long elapsedRealtime = SystemClock.elapsedRealtime();
+ final long uptime = SystemClock.uptimeMillis();
+ mBluetoothScanNesting = 0;
+ mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG;
+ if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: "
+ + Integer.toHexString(mHistoryCur.states2));
+ addHistoryRecordLocked(elapsedRealtime, uptime);
+ mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime);
+ for (int i=0; i<mUidStats.size(); i++) {
+ BatteryStatsImpl.Uid uid = mUidStats.valueAt(i);
+ uid.noteResetBluetoothScanLocked(elapsedRealtime);
+ }
+ }
+ }
+
public void noteWifiRadioPowerState(int powerState, long timestampNs) {
final long elapsedRealtime = SystemClock.elapsedRealtime();
final long uptime = SystemClock.uptimeMillis();
@@ -3980,7 +4048,7 @@ public final class BatteryStatsImpl extends BatteryStats {
int uid = mapUid(ws.get(i));
getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime);
}
- scheduleSyncExternalWifiStatsLocked("wifi-running");
+ scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI);
} else {
Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running");
}
@@ -4019,7 +4087,7 @@ public final class BatteryStatsImpl extends BatteryStats {
int uid = mapUid(ws.get(i));
getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime);
}
- scheduleSyncExternalWifiStatsLocked("wifi-stopped");
+ scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI);
} else {
Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running");
}
@@ -4034,7 +4102,7 @@ public final class BatteryStatsImpl extends BatteryStats {
}
mWifiState = wifiState;
mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime);
- scheduleSyncExternalWifiStatsLocked("wifi-state");
+ scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI);
}
}
@@ -4530,6 +4598,11 @@ public final class BatteryStatsImpl extends BatteryStats {
}
@Override
+ public long getBluetoothScanTime(long elapsedRealtimeUs, int which) {
+ return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which);
+ }
+
+ @Override
public long getNetworkActivityBytes(int type, int which) {
if (type >= 0 && type < mNetworkByteActivityCounters.length) {
return mNetworkByteActivityCounters[type].getCountLocked(which);
@@ -4603,9 +4676,8 @@ public final class BatteryStatsImpl extends BatteryStats {
StopwatchTimer mVideoTurnedOnTimer;
StopwatchTimer mFlashlightTurnedOnTimer;
StopwatchTimer mCameraTurnedOnTimer;
-
-
StopwatchTimer mForegroundActivityTimer;
+ StopwatchTimer mBluetoothScanTimer;
int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT;
StopwatchTimer[] mProcessStateTimer;
@@ -4997,6 +5069,30 @@ public final class BatteryStatsImpl extends BatteryStats {
return mForegroundActivityTimer;
}
+ public StopwatchTimer createBluetoothScanTimerLocked() {
+ if (mBluetoothScanTimer == null) {
+ mBluetoothScanTimer = new StopwatchTimer(Uid.this, BLUETOOTH_SCAN_ON,
+ mBluetoothScanOnTimers, mOnBatteryTimeBase);
+ }
+ return mBluetoothScanTimer;
+ }
+
+ public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs) {
+ createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs);
+ }
+
+ public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs) {
+ if (mBluetoothScanTimer != null) {
+ mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs);
+ }
+ }
+
+ public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) {
+ if (mBluetoothScanTimer != null) {
+ mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs);
+ }
+ }
+
@Override
public void noteActivityResumedLocked(long elapsedRealtimeMs) {
// We always start, since we want multiple foreground PIDs to nest
@@ -5110,6 +5206,11 @@ public final class BatteryStatsImpl extends BatteryStats {
return mForegroundActivityTimer;
}
+ @Override
+ public Timer getBluetoothScanTimer() {
+ return mBluetoothScanTimer;
+ }
+
void makeProcessState(int i, Parcel in) {
if (i < 0 || i >= NUM_PROCESS_STATE) return;
@@ -5335,6 +5436,9 @@ public final class BatteryStatsImpl extends BatteryStats {
if (mForegroundActivityTimer != null) {
active |= !mForegroundActivityTimer.reset(false);
}
+ if (mBluetoothScanTimer != null) {
+ active |= !mBluetoothScanTimer.reset(false);
+ }
if (mProcessStateTimer != null) {
for (int i = 0; i < NUM_PROCESS_STATE; i++) {
if (mProcessStateTimer[i] != null) {
@@ -5509,6 +5613,10 @@ public final class BatteryStatsImpl extends BatteryStats {
mForegroundActivityTimer.detach();
mForegroundActivityTimer = null;
}
+ if (mBluetoothScanTimer != null) {
+ mBluetoothScanTimer.detach();
+ mBluetoothScanTimer = null;
+ }
if (mUserActivityCounters != null) {
for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) {
mUserActivityCounters[i].detach();
@@ -5669,6 +5777,12 @@ public final class BatteryStatsImpl extends BatteryStats {
} else {
out.writeInt(0);
}
+ if (mBluetoothScanTimer != null) {
+ out.writeInt(1);
+ mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs);
+ } else {
+ out.writeInt(0);
+ }
for (int i = 0; i < NUM_PROCESS_STATE; i++) {
if (mProcessStateTimer[i] != null) {
out.writeInt(1);
@@ -5874,6 +5988,12 @@ public final class BatteryStatsImpl extends BatteryStats {
} else {
mForegroundActivityTimer = null;
}
+ if (in.readInt() != 0) {
+ mBluetoothScanTimer = new StopwatchTimer(Uid.this, BLUETOOTH_SCAN_ON,
+ mBluetoothScanOnTimers, mOnBatteryTimeBase, in);
+ } else {
+ mBluetoothScanTimer = null;
+ }
mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT;
for (int i = 0; i < NUM_PROCESS_STATE; i++) {
if (in.readInt() != 0) {
@@ -7133,6 +7253,7 @@ public final class BatteryStatsImpl extends BatteryStats {
mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase);
mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase);
mCameraOnTimer = new StopwatchTimer(null, -13, null, mOnBatteryTimeBase);
+ mBluetoothScanTimer = new StopwatchTimer(null, -14, null, mOnBatteryTimeBase);
mOnBattery = mOnBatteryInternal = false;
long uptime = SystemClock.uptimeMillis() * 1000;
long realtime = SystemClock.elapsedRealtime() * 1000;
@@ -7732,6 +7853,7 @@ public final class BatteryStatsImpl extends BatteryStats {
mVideoOnTimer.reset(false);
mFlashlightOnTimer.reset(false);
mCameraOnTimer.reset(false);
+ mBluetoothScanTimer.reset(false);
for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
mPhoneSignalStrengthsTimer[i].reset(false);
}
@@ -8264,41 +8386,168 @@ public final class BatteryStatsImpl extends BatteryStats {
Slog.d(TAG, "Updating bluetooth stats: " + info);
}
- if (info != null && mOnBatteryInternal) {
- mHasBluetoothReporting = true;
- mBluetoothActivity.getRxTimeCounter().addCountLocked(
- info.getControllerRxTimeMillis());
- mBluetoothActivity.getTxTimeCounters()[0].addCountLocked(
- info.getControllerTxTimeMillis());
- mBluetoothActivity.getIdleTimeCounter().addCountLocked(
- info.getControllerIdleTimeMillis());
+ if (info == null || !mOnBatteryInternal) {
+ return;
+ }
- // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V.
- final double opVolt = mPowerProfile.getAveragePower(
- PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0;
- if (opVolt != 0) {
- // We store the power drain as mAms.
- mBluetoothActivity.getPowerCounter().addCountLocked(
- (long) (info.getControllerEnergyUsed() / opVolt));
+ mHasBluetoothReporting = true;
+
+ final long elapsedRealtimeMs = SystemClock.elapsedRealtime();
+ final long rxTimeMs = info.getControllerRxTimeMillis();
+ final long txTimeMs = info.getControllerTxTimeMillis();
+
+ if (DEBUG_ENERGY) {
+ Slog.d(TAG, "------ BEGIN BLE power blaming ------");
+ Slog.d(TAG, " Tx Time: " + txTimeMs + " ms");
+ Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms");
+ Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms");
+ }
+
+ long totalScanTimeMs = 0;
+
+ final int uidCount = mUidStats.size();
+ for (int i = 0; i < uidCount; i++) {
+ final Uid u = mUidStats.valueAt(i);
+ if (u.mBluetoothScanTimer == null) {
+ continue;
}
- final UidTraffic[] uidTraffic = info.getUidTraffic();
- final int numUids = uidTraffic != null ? uidTraffic.length : 0;
+ totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked(
+ elapsedRealtimeMs * 1000) / 1000;
+ }
+
+ final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs);
+ final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs);
+
+ if (DEBUG_ENERGY) {
+ Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime
+ + " TX=" + normalizeScanTxTime);
+ }
+
+ long leftOverRxTimeMs = rxTimeMs;
+ long leftOverTxTimeMs = txTimeMs;
+
+ for (int i = 0; i < uidCount; i++) {
+ final Uid u = mUidStats.valueAt(i);
+ if (u.mBluetoothScanTimer == null) {
+ continue;
+ }
+
+ long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked(
+ elapsedRealtimeMs * 1000) / 1000;
+ if (scanTimeSinceMarkMs > 0) {
+ // Set the new mark so that next time we get new data since this point.
+ u.mBluetoothScanTimer.setMark(elapsedRealtimeMs);
+
+ long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs;
+ long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs;
+
+ if (normalizeScanRxTime) {
+ // Scan time is longer than the total rx time in the controller,
+ // so distribute the scan time proportionately. This means regular traffic
+ // will not blamed, but scans are more expensive anyways.
+ scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs;
+ }
+
+ if (normalizeScanTxTime) {
+ // Scan time is longer than the total tx time in the controller,
+ // so distribute the scan time proportionately. This means regular traffic
+ // will not blamed, but scans are more expensive anyways.
+ scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs;
+ }
+
+ final ControllerActivityCounterImpl counter =
+ u.getOrCreateBluetoothControllerActivityLocked();
+ counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs);
+ counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs);
+
+ leftOverRxTimeMs -= scanTimeRxSinceMarkMs;
+ leftOverTxTimeMs -= scanTimeTxSinceMarkMs;
+ }
+ }
+
+ if (DEBUG_ENERGY) {
+ Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs
+ + " TX=" + leftOverTxTimeMs);
+ }
+
+ //
+ // Now distribute blame to apps that did bluetooth traffic.
+ //
+
+ long totalTxBytes = 0;
+ long totalRxBytes = 0;
+
+ final UidTraffic[] uidTraffic = info.getUidTraffic();
+ final int numUids = uidTraffic != null ? uidTraffic.length : 0;
+ for (int i = 0; i < numUids; i++) {
+ final UidTraffic traffic = uidTraffic[i];
+
+ // Add to the global counters.
+ mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked(
+ traffic.getRxBytes());
+ mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked(
+ traffic.getTxBytes());
+
+ // Add to the UID counters.
+ final Uid u = getUidStatsLocked(mapUid(traffic.getUid()));
+ u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0);
+ u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0);
+
+ // Calculate the total traffic.
+ totalTxBytes += traffic.getTxBytes();
+ totalRxBytes += traffic.getRxBytes();
+ }
+
+ if ((totalTxBytes != 0 || totalRxBytes != 0) &&
+ (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) {
for (int i = 0; i < numUids; i++) {
final UidTraffic traffic = uidTraffic[i];
- // Add to the global counters.
- mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked(
- traffic.getRxBytes());
- mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked(
- traffic.getTxBytes());
-
- // Add to the UID counters.
final Uid u = getUidStatsLocked(mapUid(traffic.getUid()));
- u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0);
- u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0);
+ final ControllerActivityCounterImpl counter =
+ u.getOrCreateBluetoothControllerActivityLocked();
+
+ if (totalRxBytes > 0 && traffic.getRxBytes() > 0) {
+ final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes;
+
+ if (DEBUG_ENERGY) {
+ Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes()
+ + " rx_time=" + timeRxMs);
+ }
+ counter.getRxTimeCounter().addCountLocked(timeRxMs);
+ leftOverRxTimeMs -= timeRxMs;
+ }
+
+ if (totalTxBytes > 0 && traffic.getTxBytes() > 0) {
+ final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes;
+
+ if (DEBUG_ENERGY) {
+ Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes()
+ + " tx_time=" + timeTxMs);
+ }
+
+ counter.getTxTimeCounters()[0].addCountLocked(timeTxMs);
+ leftOverTxTimeMs -= timeTxMs;
+ }
}
}
+
+ mBluetoothActivity.getRxTimeCounter().addCountLocked(
+ info.getControllerRxTimeMillis());
+ mBluetoothActivity.getTxTimeCounters()[0].addCountLocked(
+ info.getControllerTxTimeMillis());
+ mBluetoothActivity.getIdleTimeCounter().addCountLocked(
+ info.getControllerIdleTimeMillis());
+
+ // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V.
+ final double opVolt = mPowerProfile.getAveragePower(
+ PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0;
+ if (opVolt != 0) {
+ // We store the power drain as mAms.
+ mBluetoothActivity.getPowerCounter().addCountLocked(
+ (long) (info.getControllerEnergyUsed() / opVolt));
+ }
}
/**
@@ -8739,15 +8988,9 @@ public final class BatteryStatsImpl extends BatteryStats {
}
}
- private void scheduleSyncExternalStatsLocked(String reason) {
- if (mExternalSync != null) {
- mExternalSync.scheduleSync(reason);
- }
- }
-
- private void scheduleSyncExternalWifiStatsLocked(String reason) {
+ private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) {
if (mExternalSync != null) {
- mExternalSync.scheduleWifiSync(reason);
+ mExternalSync.scheduleSync(reason, updateFlags);
}
}
@@ -8815,7 +9058,7 @@ public final class BatteryStatsImpl extends BatteryStats {
// TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record
// which will pull external stats.
- scheduleSyncExternalStatsLocked("battery-level");
+ scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL);
}
if (mHistoryCur.batteryStatus != status) {
mHistoryCur.batteryStatus = (byte)status;
@@ -9596,6 +9839,8 @@ public final class BatteryStatsImpl extends BatteryStats {
mFlashlightOnTimer.readSummaryFromParcelLocked(in);
mCameraOnNesting = 0;
mCameraOnTimer.readSummaryFromParcelLocked(in);
+ mBluetoothScanNesting = 0;
+ mBluetoothScanTimer.readSummaryFromParcelLocked(in);
int NKW = in.readInt();
if (NKW > 10000) {
@@ -9666,6 +9911,9 @@ public final class BatteryStatsImpl extends BatteryStats {
if (in.readInt() != 0) {
u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in);
}
+ if (in.readInt() != 0) {
+ u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in);
+ }
u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT;
for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) {
if (in.readInt() != 0) {
@@ -9928,6 +10176,7 @@ public final class BatteryStatsImpl extends BatteryStats {
out.writeInt(mNumConnectivityChange);
mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
+ mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
out.writeInt(mKernelWakelockStats.size());
for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) {
@@ -10021,6 +10270,12 @@ public final class BatteryStatsImpl extends BatteryStats {
} else {
out.writeInt(0);
}
+ if (u.mBluetoothScanTimer != null) {
+ out.writeInt(1);
+ u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
+ } else {
+ out.writeInt(0);
+ }
for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) {
if (u.mProcessStateTimer[i] != null) {
out.writeInt(1);
@@ -10289,6 +10544,8 @@ public final class BatteryStatsImpl extends BatteryStats {
mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in);
mCameraOnNesting = 0;
mCameraOnTimer = new StopwatchTimer(null, -13, null, mOnBatteryTimeBase, in);
+ mBluetoothScanNesting = 0;
+ mBluetoothScanTimer = new StopwatchTimer(null, -14, null, mOnBatteryTimeBase, in);
mDischargeUnplugLevel = in.readInt();
mDischargePlugLevel = in.readInt();
mDischargeCurrentLevel = in.readInt();
@@ -10436,6 +10693,7 @@ public final class BatteryStatsImpl extends BatteryStats {
out.writeInt(mUnpluggedNumConnectivityChange);
mFlashlightOnTimer.writeToParcel(out, uSecRealtime);
mCameraOnTimer.writeToParcel(out, uSecRealtime);
+ mBluetoothScanTimer.writeToParcel(out, uSecRealtime);
out.writeInt(mDischargeUnplugLevel);
out.writeInt(mDischargePlugLevel);
out.writeInt(mDischargeCurrentLevel);
diff --git a/core/java/com/android/internal/os/BluetoothPowerCalculator.java b/core/java/com/android/internal/os/BluetoothPowerCalculator.java
index 531d1fac9991..2f383eacbac0 100644
--- a/core/java/com/android/internal/os/BluetoothPowerCalculator.java
+++ b/core/java/com/android/internal/os/BluetoothPowerCalculator.java
@@ -24,6 +24,8 @@ public class BluetoothPowerCalculator extends PowerCalculator {
private final double mIdleMa;
private final double mRxMa;
private final double mTxMa;
+ private double mAppTotalPowerMah = 0;
+ private long mAppTotalTimeMs = 0;
public BluetoothPowerCalculator(PowerProfile profile) {
mIdleMa = profile.getAveragePower(PowerProfile.POWER_BLUETOOTH_CONTROLLER_IDLE);
@@ -34,7 +36,31 @@ public class BluetoothPowerCalculator extends PowerCalculator {
@Override
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
long rawUptimeUs, int statsType) {
- // No per-app distribution yet.
+
+ final BatteryStats.ControllerActivityCounter counter = u.getBluetoothControllerActivity();
+ if (counter == null) {
+ return;
+ }
+
+ final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(statsType);
+ final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(statsType);
+ final long txTimeMs = counter.getTxTimeCounters()[0].getCountLocked(statsType);
+ final long totalTimeMs = idleTimeMs + txTimeMs + rxTimeMs;
+ double powerMah = counter.getPowerCounter().getCountLocked(statsType)
+ / (double)(1000*60*60);
+
+ if (powerMah == 0) {
+ powerMah = ((idleTimeMs * mIdleMa) + (rxTimeMs * mRxMa) + (txTimeMs * mTxMa))
+ / (1000*60*60);
+ }
+
+ app.bluetoothPowerMah = powerMah;
+ app.bluetoothRunningTimeMs = totalTimeMs;
+ app.btRxBytes = u.getNetworkActivityBytes(BatteryStats.NETWORK_BT_RX_DATA, statsType);
+ app.btTxBytes = u.getNetworkActivityBytes(BatteryStats.NETWORK_BT_TX_DATA, statsType);
+
+ mAppTotalPowerMah += powerMah;
+ mAppTotalTimeMs += totalTimeMs;
}
@Override
@@ -56,12 +82,21 @@ public class BluetoothPowerCalculator extends PowerCalculator {
/ (1000*60*60);
}
+ // Subtract what the apps used, but clamp to 0.
+ powerMah = Math.max(0, powerMah - mAppTotalPowerMah);
+
if (DEBUG && powerMah != 0) {
Log.d(TAG, "Bluetooth active: time=" + (totalTimeMs)
+ " power=" + BatteryStatsHelper.makemAh(powerMah));
}
- app.usagePowerMah = powerMah;
- app.usageTimeMs = totalTimeMs;
+ app.bluetoothPowerMah = powerMah;
+ app.bluetoothRunningTimeMs = Math.max(0, totalTimeMs - mAppTotalTimeMs);
+ }
+
+ @Override
+ public void reset() {
+ mAppTotalPowerMah = 0;
+ mAppTotalTimeMs = 0;
}
}
diff --git a/core/java/com/android/internal/os/WifiPowerCalculator.java b/core/java/com/android/internal/os/WifiPowerCalculator.java
index 2a27f70ff05d..b4470397c67b 100644
--- a/core/java/com/android/internal/os/WifiPowerCalculator.java
+++ b/core/java/com/android/internal/os/WifiPowerCalculator.java
@@ -29,6 +29,7 @@ public class WifiPowerCalculator extends PowerCalculator {
private final double mTxCurrentMa;
private final double mRxCurrentMa;
private double mTotalAppPowerDrain = 0;
+ private long mTotalAppRunningTime = 0;
public WifiPowerCalculator(PowerProfile profile) {
mIdleCurrentMa = profile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_IDLE);
@@ -48,6 +49,8 @@ public class WifiPowerCalculator extends PowerCalculator {
final long txTime = counter.getTxTimeCounters()[0].getCountLocked(statsType);
final long rxTime = counter.getRxTimeCounter().getCountLocked(statsType);
app.wifiRunningTimeMs = idleTime + rxTime + txTime;
+ mTotalAppRunningTime += app.wifiRunningTimeMs;
+
app.wifiPowerMah =
((idleTime * mIdleCurrentMa) + (txTime * mTxCurrentMa) + (rxTime * mRxCurrentMa))
/ (1000*60*60);
@@ -76,7 +79,9 @@ public class WifiPowerCalculator extends PowerCalculator {
final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(statsType);
final long txTimeMs = counter.getTxTimeCounters()[0].getCountLocked(statsType);
final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(statsType);
- app.wifiRunningTimeMs = idleTimeMs + rxTimeMs + txTimeMs;
+
+ app.wifiRunningTimeMs = Math.max(0,
+ (idleTimeMs + rxTimeMs + txTimeMs) - mTotalAppRunningTime);
double powerDrainMah = counter.getPowerCounter().getCountLocked(statsType)
/ (double)(1000*60*60);
@@ -95,5 +100,6 @@ public class WifiPowerCalculator extends PowerCalculator {
@Override
public void reset() {
mTotalAppPowerDrain = 0;
+ mTotalAppRunningTime = 0;
}
}
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index 97ef10b10ab2..28882def6b99 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -81,12 +81,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub
Context mContext;
PowerManagerInternal mPowerManagerInternal;
- final int UPDATE_CPU = 0x01;
- final int UPDATE_WIFI = 0x02;
- final int UPDATE_RADIO = 0x04;
- final int UPDATE_BT = 0x08;
- final int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT;
-
class BatteryStatsHandler extends Handler implements BatteryStatsImpl.ExternalStatsSync {
public static final int MSG_SYNC_EXTERNAL_STATS = 1;
public static final int MSG_WRITE_TO_DISK = 2;
@@ -133,16 +127,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub
}
@Override
- public void scheduleSync(String reason) {
- synchronized (this) {
- scheduleSyncLocked(reason, UPDATE_ALL);
- }
- }
-
- @Override
- public void scheduleWifiSync(String reason) {
+ public void scheduleSync(String reason, int updateFlags) {
synchronized (this) {
- scheduleSyncLocked(reason, UPDATE_WIFI);
+ scheduleSyncLocked(reason, updateFlags);
}
}
@@ -194,7 +181,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
public void shutdown() {
Slog.w("BatteryStats", "Writing battery stats before shutdown...");
- updateExternalStats("shutdown", UPDATE_ALL);
+ updateExternalStats("shutdown", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
synchronized (mStats) {
mStats.shutdownLocked();
}
@@ -294,7 +281,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
- updateExternalStats("get-stats", UPDATE_ALL);
+ updateExternalStats("get-stats", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
synchronized (mStats) {
mStats.writeToParcel(out, 0);
}
@@ -309,7 +296,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
- updateExternalStats("get-stats", UPDATE_ALL);
+ updateExternalStats("get-stats", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
synchronized (mStats) {
mStats.writeToParcel(out, 0);
}
@@ -672,7 +659,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
final String type = (powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH ||
powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM) ? "active"
: "inactive";
- mHandler.scheduleWifiSync("wifi-data: " + type);
+ mHandler.scheduleSync("wifi-data: " + type,
+ BatteryStatsImpl.ExternalStatsSync.UPDATE_WIFI);
}
mStats.noteWifiRadioPowerState(powerState, tsNanos);
}
@@ -860,13 +848,25 @@ public final class BatteryStatsService extends IBatteryStats.Stub
@Override
public void noteBleScanStarted(WorkSource ws) {
enforceCallingPermission();
- Slog.d(TAG, "BLE scan started for " + ws);
+ synchronized (mStats) {
+ mStats.noteBluetoothScanStartedFromSourceLocked(ws);
+ }
}
@Override
public void noteBleScanStopped(WorkSource ws) {
enforceCallingPermission();
- Slog.d(TAG, "BLE scan stopped for " + ws);
+ synchronized (mStats) {
+ mStats.noteBluetoothScanStoppedFromSourceLocked(ws);
+ }
+ }
+
+ @Override
+ public void noteResetBleScan() {
+ enforceCallingPermission();
+ synchronized (mStats) {
+ mStats.noteResetBluetoothScanLocked();
+ }
}
public boolean isOnBattery() {
@@ -895,7 +895,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
// Sync external stats first as the battery has changed states. If we don't sync
// immediately here, we may not collect the relevant data later.
- updateExternalStats("battery-state", UPDATE_ALL);
+ updateExternalStats("battery-state", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
synchronized (mStats) {
mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt);
}
@@ -1082,9 +1082,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub
pw.println("Battery stats reset.");
noOutput = true;
}
- updateExternalStats("dump", UPDATE_ALL);
+ updateExternalStats("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
} else if ("--write".equals(arg)) {
- updateExternalStats("dump", UPDATE_ALL);
+ updateExternalStats("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
synchronized (mStats) {
mStats.writeSyncLocked();
pw.println("Battery stats written.");
@@ -1148,7 +1148,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY;
}
// Fetch data from external sources and update the BatteryStatsImpl object with them.
- updateExternalStats("dump", UPDATE_ALL);
+ updateExternalStats("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
} finally {
Binder.restoreCallingIdentity(ident);
}
@@ -1358,8 +1358,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
*
* @param reason The reason why this collection was requested. Useful for debugging.
* @param updateFlags Which external stats to update. Can be a combination of
- * {@link #UPDATE_CPU}, {@link #UPDATE_RADIO}, {@link #UPDATE_WIFI},
- * and {@link #UPDATE_BT}.
+ * {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_CPU},
+ * {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_RADIO},
+ * {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_WIFI},
+ * and {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_BT}.
*/
void updateExternalStats(final String reason, final int updateFlags) {
synchronized (mExternalStatsLock) {
@@ -1374,17 +1376,17 @@ public final class BatteryStatsService extends IBatteryStats.Stub
}
WifiActivityEnergyInfo wifiEnergyInfo = null;
- if ((updateFlags & UPDATE_WIFI) != 0) {
+ if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_WIFI) != 0) {
wifiEnergyInfo = pullWifiEnergyInfoLocked();
}
ModemActivityInfo modemActivityInfo = null;
- if ((updateFlags & UPDATE_RADIO) != 0) {
+ if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_RADIO) != 0) {
modemActivityInfo = pullModemActivityInfoLocked();
}
BluetoothActivityEnergyInfo bluetoothEnergyInfo = null;
- if ((updateFlags & UPDATE_BT) != 0) {
+ if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_BT) != 0) {
// We only pull bluetooth stats when we have to, as we are not distributing its
// use amongst apps and the sampling frequency does not matter.
bluetoothEnergyInfo = pullBluetoothEnergyInfoLocked();
@@ -1398,20 +1400,20 @@ public final class BatteryStatsService extends IBatteryStats.Stub
BatteryStats.HistoryItem.EVENT_COLLECT_EXTERNAL_STATS, reason, 0);
}
- if ((updateFlags & UPDATE_CPU) != 0) {
+ if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_CPU) != 0) {
mStats.updateCpuTimeLocked();
mStats.updateKernelWakelocksLocked();
}
- if ((updateFlags & UPDATE_RADIO) != 0) {
+ if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_RADIO) != 0) {
mStats.updateMobileRadioStateLocked(elapsedRealtime, modemActivityInfo);
}
- if ((updateFlags & UPDATE_WIFI) != 0) {
+ if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_WIFI) != 0) {
mStats.updateWifiStateLocked(wifiEnergyInfo);
}
- if ((updateFlags & UPDATE_BT) != 0) {
+ if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_BT) != 0) {
mStats.updateBluetoothStateLocked(bluetoothEnergyInfo);
}
}