Migrate pullBluetoothActivityInfo
Bug: 145565211
Test: No Cts test. Ran adb shell cmd stats pull-source 10007
Change-Id: I6b2f5e01f966407b791ad3516d36402daab6cf8b
diff --git a/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java b/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java
index f3ba8e8..b3d41988f 100644
--- a/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java
+++ b/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java
@@ -910,33 +910,6 @@
}
}
- private void pullBluetoothActivityInfo(
- int tagId, long elapsedNanos, long wallClockNanos,
- List<StatsLogEventWrapper> pulledData) {
- BluetoothActivityEnergyInfo info = fetchBluetoothData();
- StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
- e.writeLong(info.getTimeStamp());
- e.writeInt(info.getBluetoothStackState());
- e.writeLong(info.getControllerTxTimeMillis());
- e.writeLong(info.getControllerRxTimeMillis());
- e.writeLong(info.getControllerIdleTimeMillis());
- e.writeLong(info.getControllerEnergyUsed());
- pulledData.add(e);
- }
-
- private synchronized BluetoothActivityEnergyInfo fetchBluetoothData() {
- final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
- if (adapter != null) {
- SynchronousResultReceiver bluetoothReceiver = new SynchronousResultReceiver(
- "bluetooth");
- adapter.requestControllerActivityEnergyInfo(bluetoothReceiver);
- return awaitControllerInfo(bluetoothReceiver);
- } else {
- Slog.e(TAG, "Failed to get bluetooth adapter!");
- return null;
- }
- }
-
private void pullSystemElapsedRealtime(
int tagId, long elapsedNanos, long wallClockNanos,
List<StatsLogEventWrapper> pulledData) {
@@ -2190,11 +2163,6 @@
break;
}
- case StatsLog.BLUETOOTH_ACTIVITY_INFO: {
- pullBluetoothActivityInfo(tagId, elapsedNanos, wallClockNanos, ret);
- break;
- }
-
case StatsLog.SYSTEM_UPTIME: {
pullSystemUpTime(tagId, elapsedNanos, wallClockNanos, ret);
break;
diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp
index 47e8a32..06046c1 100644
--- a/cmds/statsd/src/external/StatsPullerManager.cpp
+++ b/cmds/statsd/src/external/StatsPullerManager.cpp
@@ -111,10 +111,6 @@
{{.atomTag = android::util::MODEM_ACTIVITY_INFO},
{.puller = new StatsCompanionServicePuller(android::util::MODEM_ACTIVITY_INFO)}},
- // bluetooth_activity_info
- {{.atomTag = android::util::BLUETOOTH_ACTIVITY_INFO},
- {.puller = new StatsCompanionServicePuller(android::util::BLUETOOTH_ACTIVITY_INFO)}},
-
// system_elapsed_realtime
{{.atomTag = android::util::SYSTEM_ELAPSED_REALTIME},
{.coolDownNs = NS_PER_SEC,
diff --git a/services/core/java/com/android/server/stats/StatsPullAtomService.java b/services/core/java/com/android/server/stats/StatsPullAtomService.java
index f1cfca5..bb910b2 100644
--- a/services/core/java/com/android/server/stats/StatsPullAtomService.java
+++ b/services/core/java/com/android/server/stats/StatsPullAtomService.java
@@ -675,11 +675,31 @@
}
private void registerBluetoothActivityInfo() {
- // No op.
+ int tagId = StatsLog.BLUETOOTH_ACTIVITY_INFO;
+ mStatsManager.registerPullAtomCallback(
+ tagId,
+ /* metadata */ null,
+ (atomTag, data) -> pullBluetoothActivityInfo(atomTag, data),
+ Executors.newSingleThreadExecutor()
+ );
}
- private void pullBluetoothActivityInfo() {
- // No op.
+ private int pullBluetoothActivityInfo(int atomTag, List<StatsEvent> pulledData) {
+ BluetoothActivityEnergyInfo info = fetchBluetoothData();
+ if (info == null) {
+ return StatsManager.PULL_SKIP;
+ }
+ StatsEvent e = StatsEvent.newBuilder()
+ .setAtomId(atomTag)
+ .writeLong(info.getTimeStamp())
+ .writeInt(info.getBluetoothStackState())
+ .writeLong(info.getControllerTxTimeMillis())
+ .writeLong(info.getControllerRxTimeMillis())
+ .writeLong(info.getControllerIdleTimeMillis())
+ .writeLong(info.getControllerEnergyUsed())
+ .build();
+ pulledData.add(e);
+ return StatsManager.PULL_SUCCESS;
}
private void registerSystemElapsedRealtime() {