From bc0501e2a129c947140e6f6f4a3dabe8fa85a20e Mon Sep 17 00:00:00 2001 From: Etienne Ruffieux Date: Wed, 23 Mar 2022 16:10:53 +0000 Subject: [PATCH] Added error method to interface Bluetooth stats Bug: 223344084 Test: atest BluetoothAdapterTest Tag: #feature Change-Id: Ie38afa6db3636a8264038be30e9bf025a7a9f09a --- .../server/am/BatteryExternalStatsWorker.java | 23 +++++++++++++++---- .../stats/pull/StatsPullAtomService.java | 22 ++++++++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java b/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java index d6cd054ce6c8f..c5ee259106716 100644 --- a/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java +++ b/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java @@ -560,11 +560,24 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync { new SynchronousResultReceiver("bluetooth"); adapter.requestControllerActivityEnergyInfo( Runnable::run, - info -> { - Bundle bundle = new Bundle(); - bundle.putParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, - info); - resultReceiver.send(0, bundle); + new BluetoothAdapter.OnBluetoothActivityEnergyInfoCallback() { + @Override + public void onBluetoothActivityEnergyInfoAvailable( + BluetoothActivityEnergyInfo info) { + Bundle bundle = new Bundle(); + bundle.putParcelable( + BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, info); + resultReceiver.send(0, bundle); + } + + @Override + public void onBluetoothActivityEnergyInfoError(int errorCode) { + Slog.w(TAG, "error reading Bluetooth stats: " + errorCode); + Bundle bundle = new Bundle(); + bundle.putParcelable( + BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, null); + resultReceiver.send(0, bundle); + } } ); bluetoothReceiver = resultReceiver; diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java index 86c3e23d32c0c..48d464c52df51 100644 --- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java @@ -1620,10 +1620,24 @@ public class StatsPullAtomService extends SystemService { new SynchronousResultReceiver("bluetooth"); adapter.requestControllerActivityEnergyInfo( Runnable::run, - info -> { - Bundle bundle = new Bundle(); - bundle.putParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, info); - bluetoothReceiver.send(0, bundle); + new BluetoothAdapter.OnBluetoothActivityEnergyInfoCallback() { + @Override + public void onBluetoothActivityEnergyInfoAvailable( + BluetoothActivityEnergyInfo info) { + Bundle bundle = new Bundle(); + bundle.putParcelable( + BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, info); + bluetoothReceiver.send(0, bundle); + } + + @Override + public void onBluetoothActivityEnergyInfoError(int errorCode) { + Slog.w(TAG, "error reading Bluetooth stats: " + errorCode); + Bundle bundle = new Bundle(); + bundle.putParcelable( + BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, null); + bluetoothReceiver.send(0, bundle); + } } ); return awaitControllerInfo(bluetoothReceiver);