diff --git a/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java b/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java index 4fdc88d3fd649..84969aa9e9163 100644 --- a/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java +++ b/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java @@ -565,11 +565,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 526dccb72e397..5e7b5860629da 100644 --- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java @@ -1635,10 +1635,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);