/** * Returns the callback that is registered for value changes (notifications) of given * characteristic. After assigning the notifications callback, notifications must be * enabled using {@link #enableNotifications(BluetoothGattCharacteristic)}. * This applies also when they were already enabled on the remote side. * <p> * To remove the callback, disable notifications using * {@link #disableNotifications(BluetoothGattCharacteristic)}. * * @param characteristic characteristic to bind the callback with. If null, the returned * callback will not be null, but will not be used. * @return The callback. */ @MainThread @NonNull protected final ValueChangedCallback setNotificationCallback(@Nullable final BluetoothGattCharacteristic characteristic) { ValueChangedCallback callback = mNotificationCallbacks.get(characteristic); if (callback == null) { callback = new ValueChangedCallback(); if (characteristic != null) { mNotificationCallbacks.put(characteristic, callback); } } return callback.free(); }