summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothHapClient.java
diff options
context:
space:
mode:
authorRob Seymour <rseymour@google.com>2022-04-02 03:52:13 +0000
committerRob Seymour <rseymour@google.com>2022-04-02 04:01:22 +0000
commit4c7dc59bef24cc991251f9a7924ceada90c6bd63 (patch)
treea90550aa3ce1bc5e002ab6444c96954deca81af0 /framework/java/android/bluetooth/BluetoothHapClient.java
parent6fa2bea006b362a285f744f65f15b5902e55797a (diff)
parentdd4d23c4e1de011f8cd4eb132422172d5e283a73 (diff)
Merge TP1A.220328.001
Change-Id: I5f07094ba2fb3991da03673f97d2957b1f68018b
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothHapClient.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothHapClient.java12
1 files changed, 8 insertions, 4 deletions
diff --git a/framework/java/android/bluetooth/BluetoothHapClient.java b/framework/java/android/bluetooth/BluetoothHapClient.java
index dda803ef38..c05126d9c0 100644
--- a/framework/java/android/bluetooth/BluetoothHapClient.java
+++ b/framework/java/android/bluetooth/BluetoothHapClient.java
@@ -541,15 +541,19 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
@NonNull Callback callback) {
Objects.requireNonNull(executor, "executor cannot be null");
Objects.requireNonNull(callback, "callback cannot be null");
- if (!isEnabled()) {
- throw new IllegalStateException("service not enabled");
- }
if (DBG) log("registerCallback");
synchronized (mCallbackExecutorMap) {
// If the callback map is empty, we register the service-to-app callback
if (mCallbackExecutorMap.isEmpty()) {
+ if (!isEnabled()) {
+ /* If Bluetooth is off, just store callback and it will be registered
+ * when Bluetooth is on
+ */
+ mCallbackExecutorMap.put(callback, executor);
+ return;
+ }
try {
final IBluetoothHapClient service = getService();
if (service != null) {
@@ -558,7 +562,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
service.registerCallback(mCallback, mAttributionSource, recv);
recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
}
- } catch (IllegalStateException | TimeoutException e) {
+ } catch (TimeoutException e) {
Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();