summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothHapClient.java
diff options
context:
space:
mode:
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();