Merge changes from topic "api-review-result-receiver"
* changes: Added error method to interface Bluetooth stats [API Review] Replace ResultReceiver by Executor
This commit is contained in:
@@ -556,8 +556,31 @@ 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,
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1618,7 +1618,28 @@ 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,
|
||||||
|
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);
|
return awaitControllerInfo(bluetoothReceiver);
|
||||||
} else {
|
} else {
|
||||||
Slog.e(TAG, "Failed to get bluetooth adapter!");
|
Slog.e(TAG, "Failed to get bluetooth adapter!");
|
||||||
|
|||||||
Reference in New Issue
Block a user