diff options
author | Jakub Tyszkowski <jakub.tyszkowski@codecoup.pl> | 2022-03-08 09:46:15 +0000 |
---|---|---|
committer | Jakub Tyszkowski <jakub.tyszkowski@codecoup.pl> | 2022-03-08 11:39:36 +0000 |
commit | 4453f3b2dcba5e47f09c71e3299b07de99d84470 (patch) | |
tree | e21e117369469a120b1c5f87a00e96c13d2f7be4 /framework/java/android/bluetooth/BluetoothHapClient.java | |
parent | 1e33487f3354790b2755f197e0a1e2546b3e7883 (diff) |
hap: Improve callback registration mechanism
Improves input parameters verification by throwing NPE as requested in
b/218616250. Adjusts the doc accordingly.
Bug: 150670922
Bug: 218616250
Tag: #feature
Test: atest CtsBluetoothTestCases:android.bluetooth.cts.BluetoothHapClientTest
Sponsor: jpawlowski@
Change-Id: I828d578ca53678a2642bc4e73d57b7b481feb88b
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothHapClient.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothHapClient.java | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/framework/java/android/bluetooth/BluetoothHapClient.java b/framework/java/android/bluetooth/BluetoothHapClient.java index fd769d412b..052bd6bfd6 100644 --- a/framework/java/android/bluetooth/BluetoothHapClient.java +++ b/framework/java/android/bluetooth/BluetoothHapClient.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.Executor; import java.util.concurrent.TimeoutException; @@ -457,14 +458,16 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable * Register a {@link Callback} that will be invoked during the * operation of this profile. * - * Repeated registration of the same <var>callback</var> object will have no effect after - * the first call to this method, even when the <var>executor</var> is different. API caller - * would have to call {@link #unregisterCallback(Callback)} with - * the same callback object before registering it again. + * Repeated registration of the same <var>callback</var> object after the first call to this + * method will result with IllegalArgumentException being thrown, even when the + * <var>executor</var> is different. API caller would have to call + * {@link #unregisterCallback(Callback)} with the same callback object before registering it + * again. * * @param executor an {@link Executor} to execute given callback * @param callback user implementation of the {@link Callback} - * @throws IllegalArgumentException if a null executor, sink, or callback is given + * @throws NullPointerException if a null executor, or callback is given, or + * IllegalArgumentException if the same <var>callback<var> is already registered. * @hide */ @SystemApi @@ -475,12 +478,8 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable }) public void registerCallback(@NonNull @CallbackExecutor Executor executor, @NonNull Callback callback) { - if (executor == null) { - throw new IllegalArgumentException("executor cannot be null"); - } - if (callback == null) { - throw new IllegalArgumentException("callback cannot be null"); - } + Objects.requireNonNull(executor, "executor cannot be null"); + Objects.requireNonNull(callback, "callback cannot be null"); if (!isEnabled()) { throw new IllegalStateException("service not enabled"); } @@ -521,7 +520,8 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable * <p>Callbacks are automatically unregistered when application process goes away * * @param callback user implementation of the {@link Callback} - * @throws IllegalArgumentException when callback is null or when no callback is registered + * @throws NullPointerException when callback is null or IllegalArgumentException when no + * callback is registered * @hide */ @SystemApi @@ -531,9 +531,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) public void unregisterCallback(@NonNull Callback callback) { - if (callback == null) { - throw new IllegalArgumentException("callback cannot be null"); - } + Objects.requireNonNull(callback, "callback cannot be null"); if (DBG) log("unregisterCallback"); |