Merge "Fix statsd ble scan logging" into pi-dev
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index c8ae426..5e75359 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -49,7 +49,7 @@
oneof pushed {
// For StatsLog reasons, 1 is illegal and will not work. Must start at 2.
BleScanStateChanged ble_scan_state_changed = 2;
- BleUnoptimizedScanStateChanged ble_unoptimized_scan_state_changed = 3;
+ // TODO: 3 is blank, but need not be
BleScanResultReceived ble_scan_result_received = 4;
SensorStateChanged sensor_state_changed = 5;
GpsScanStateChanged gps_scan_state_changed = 6;
@@ -247,31 +247,24 @@
* Logged from:
* frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
*/
+// TODO: Consider changing to tracking per-scanner-id (log from AppScanStats).
message BleScanStateChanged {
repeated AttributionNode attribution_node = 1;
enum State {
OFF = 0;
ON = 1;
+ // RESET indicates all ble stopped. Used when it (re)starts (e.g. after it crashes).
+ RESET = 2;
}
optional State state = 2;
-}
-/**
- * Logs when an unoptimized ble scan state changes.
- *
- * Logged from:
- * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
- */
-// TODO: Consider changing to tracking per-scanner-id (log from AppScanStats).
-message BleUnoptimizedScanStateChanged {
- repeated AttributionNode attribution_node = 1;
-
- enum State {
- OFF = 0;
- ON = 1;
- }
- optional State state = 2;
+ // Does the scan have a filter.
+ optional bool is_filtered = 3;
+ // Whether the scan is a CALLBACK_TYPE_FIRST_MATCH scan. Called 'background' scan internally.
+ optional bool is_first_match = 4;
+ // Whether the scan set to piggy-back off the results of other scans (SCAN_MODE_OPPORTUNISTIC).
+ optional bool is_opportunistic = 5;
}
/**
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 8117bf7..89f6156 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -5666,29 +5666,7 @@
mBluetoothScanTimer.startRunningLocked(elapsedRealtime);
}
mBluetoothScanNesting++;
-
- if (workChain != null) {
- StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED,
- workChain.getUids(), workChain.getTags(),
- StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON);
- if (isUnoptimized) {
- StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED,
- workChain.getUids(), workChain.getTags(),
- StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__ON);
- }
- } else {
- StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED, uid, null,
- StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON);
- if (isUnoptimized) {
- StatsLog.write_non_chained(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, uid, null,
- StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__ON);
- }
- }
-
getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime, isUnoptimized);
- if (workChain != null) {
- getUidStatsLocked(uid).addBluetoothWorkChain(workChain, isUnoptimized);
- }
}
public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws, boolean isUnoptimized) {
@@ -5718,29 +5696,7 @@
addHistoryRecordLocked(elapsedRealtime, uptime);
mBluetoothScanTimer.stopRunningLocked(elapsedRealtime);
}
-
- if (workChain != null) {
- StatsLog.write(
- StatsLog.BLE_SCAN_STATE_CHANGED, workChain.getUids(), workChain.getTags(),
- StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF);
- if (isUnoptimized) {
- StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED,
- workChain.getUids(), workChain.getTags(),
- StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF);
- }
- } else {
- StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED, uid, null,
- StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF);
- if (isUnoptimized) {
- StatsLog.write_non_chained(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, uid, null,
- StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF);
- }
- }
-
getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime, isUnoptimized);
- if (workChain != null) {
- getUidStatsLocked(uid).removeBluetoothWorkChain(workChain, isUnoptimized);
- }
}
private int getAttributionUid(int uid, WorkChain workChain) {
@@ -5775,33 +5731,9 @@
+ 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);
-
- List<WorkChain> allWorkChains = uid.getAllBluetoothWorkChains();
- if (allWorkChains != null) {
- for (int j = 0; j < allWorkChains.size(); ++j) {
- StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED,
- allWorkChains.get(j).getUids(),
- allWorkChains.get(j).getTags(),
- StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF);
- }
- allWorkChains.clear();
- }
-
- List<WorkChain> unoptimizedWorkChains = uid.getUnoptimizedBluetoothWorkChains();
- if (unoptimizedWorkChains != null) {
- for (int j = 0; j < unoptimizedWorkChains.size(); ++j) {
- StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED,
- unoptimizedWorkChains.get(j).getUids(),
- unoptimizedWorkChains.get(j).getTags(),
- StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF);
- }
- unoptimizedWorkChains.clear();
- }
}
}
}
@@ -6873,15 +6805,6 @@
*/
final SparseArray<Pid> mPids = new SparseArray<>();
- /**
- * The list of WorkChains associated with active bluetooth scans.
- *
- * NOTE: This is a hack and it only needs to exist because there's a "reset" API that is
- * supposed to stop and log all WorkChains that were currently active.
- */
- ArrayList<WorkChain> mAllBluetoothChains = null;
- ArrayList<WorkChain> mUnoptimizedBluetoothChains = null;
-
public Uid(BatteryStatsImpl bsi, int uid) {
mBsi = bsi;
mUid = uid;
@@ -7410,40 +7333,6 @@
}
}
- public void addBluetoothWorkChain(WorkChain workChain, boolean isUnoptimized) {
- if (mAllBluetoothChains == null) {
- mAllBluetoothChains = new ArrayList<WorkChain>(4);
- }
-
- if (isUnoptimized && mUnoptimizedBluetoothChains == null) {
- mUnoptimizedBluetoothChains = new ArrayList<WorkChain>(4);
- }
-
- mAllBluetoothChains.add(workChain);
- if (isUnoptimized) {
- mUnoptimizedBluetoothChains.add(workChain);
- }
- }
-
- public void removeBluetoothWorkChain(WorkChain workChain, boolean isUnoptimized) {
- if (mAllBluetoothChains != null) {
- mAllBluetoothChains.remove(workChain);
- }
-
- if (isUnoptimized && mUnoptimizedBluetoothChains != null) {
- mUnoptimizedBluetoothChains.remove(workChain);
- }
- }
-
- public List<WorkChain> getAllBluetoothWorkChains() {
- return mAllBluetoothChains;
- }
-
- public List<WorkChain> getUnoptimizedBluetoothWorkChains() {
- return mUnoptimizedBluetoothChains;
- }
-
-
public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) {
if (mBluetoothScanTimer != null) {
mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs);
diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsBackgroundStatsTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsBackgroundStatsTest.java
index acf3022..992b46f 100644
--- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsBackgroundStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsBackgroundStatsTest.java
@@ -273,53 +273,6 @@
}
@SmallTest
- public void testAppBluetoothScan_workChainAccounting() throws Exception {
- final MockClocks clocks = new MockClocks();MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks);
- long curr = 0; // realtime in us
-
- // On battery
- curr = 1000 * (clocks.realtime = clocks.uptime = 100);
- bi.updateTimeBasesLocked(true, Display.STATE_ON, curr, curr); // on battery
-
- // App in foreground
- bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);
-
- WorkSource ws = new WorkSource();
- ws.createWorkChain().addNode(500, "foo");
- ws.createWorkChain().addNode(500, "bar");
-
- // Test start / stop and reset with isUnoptimized == false.
- bi.noteBluetoothScanStartedFromSourceLocked(ws, false);
- BatteryStatsImpl.Uid stats = (BatteryStatsImpl.Uid) bi.getUidStats().get(500);
- assertEquals(ws.getWorkChains(), stats.getAllBluetoothWorkChains());
- assertNull(stats.getUnoptimizedBluetoothWorkChains());
-
- bi.noteBluetoothScanStoppedFromSourceLocked(ws, false);
- assertTrue(stats.getAllBluetoothWorkChains().isEmpty());
- assertNull(stats.getUnoptimizedBluetoothWorkChains());
-
- bi.noteBluetoothScanStartedFromSourceLocked(ws, false);
- bi.noteResetBluetoothScanLocked();
- assertTrue(stats.getAllBluetoothWorkChains().isEmpty());
- assertNull(stats.getUnoptimizedBluetoothWorkChains());
-
- // Test start / stop and reset with isUnoptimized == true.
- bi.noteBluetoothScanStartedFromSourceLocked(ws, true);
- stats = (BatteryStatsImpl.Uid) bi.getUidStats().get(500);
- assertEquals(ws.getWorkChains(), stats.getAllBluetoothWorkChains());
- assertEquals(ws.getWorkChains(), stats.getUnoptimizedBluetoothWorkChains());
-
- bi.noteBluetoothScanStoppedFromSourceLocked(ws, true);
- assertTrue(stats.getAllBluetoothWorkChains().isEmpty());
- assertTrue(stats.getUnoptimizedBluetoothWorkChains().isEmpty());
-
- bi.noteBluetoothScanStartedFromSourceLocked(ws, true);
- bi.noteResetBluetoothScanLocked();
- assertTrue(stats.getAllBluetoothWorkChains().isEmpty());
- assertTrue(stats.getUnoptimizedBluetoothWorkChains().isEmpty());
- }
-
- @SmallTest
public void testJob() throws Exception {
final MockClocks clocks = new MockClocks();
MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks);