[API Review] Replace ResultReceiver by Executor

Bug: 223344084
Test: build
Tag: #feature
Merged-In: I5c6fc4780b41406dc41c26050a10768b7a2114df
Change-Id: I5c6fc4780b41406dc41c26050a10768b7a2114df
This commit is contained in:
Etienne Ruffieux
2022-03-10 15:59:01 +00:00
parent b344dfaee9
commit 8d4a9f8d72
2 changed files with 20 additions and 3 deletions

View File

@@ -556,8 +556,18 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync {
// We were asked to fetch Bluetooth data. // We were asked to fetch Bluetooth data.
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) { if (adapter != null) {
bluetoothReceiver = new SynchronousResultReceiver("bluetooth"); SynchronousResultReceiver resultReceiver =
adapter.requestControllerActivityEnergyInfo(bluetoothReceiver); new SynchronousResultReceiver("bluetooth");
adapter.requestControllerActivityEnergyInfo(
Runnable::run,
info -> {
Bundle bundle = new Bundle();
bundle.putParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY,
info);
resultReceiver.send(0, bundle);
}
);
bluetoothReceiver = resultReceiver;
} }
} }

View File

@@ -1618,7 +1618,14 @@ public class StatsPullAtomService extends SystemService {
if (adapter != null) { if (adapter != null) {
SynchronousResultReceiver bluetoothReceiver = SynchronousResultReceiver bluetoothReceiver =
new SynchronousResultReceiver("bluetooth"); new SynchronousResultReceiver("bluetooth");
adapter.requestControllerActivityEnergyInfo(bluetoothReceiver); adapter.requestControllerActivityEnergyInfo(
Runnable::run,
info -> {
Bundle bundle = new Bundle();
bundle.putParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, info);
bluetoothReceiver.send(0, bundle);
}
);
return awaitControllerInfo(bluetoothReceiver); return awaitControllerInfo(bluetoothReceiver);
} else { } else {
Slog.e(TAG, "Failed to get bluetooth adapter!"); Slog.e(TAG, "Failed to get bluetooth adapter!");