Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c712b670 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "hap: Fix missing preset change reason" am: 3115ab2e am: c060d82f

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2020205

Change-Id: I3bf2628562997405a7844dac68c7a7bedceb8cb6
parents 76ed8404 c060d82f
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -785,12 +785,14 @@ public class HapClientService extends ProfileService {
        }
    }

    private void notifyActivePresetChanged(BluetoothDevice device, int presetIndex) {
    private void notifyActivePresetChanged(BluetoothDevice device, int presetIndex,
            int reasonCode) {
        if (mCallbacks != null) {
            int n = mCallbacks.beginBroadcast();
            for (int i = 0; i < n; i++) {
                try {
                    mCallbacks.getBroadcastItem(i).onPresetSelected(device, presetIndex);
                    mCallbacks.getBroadcastItem(i).onPresetSelected(device, presetIndex,
                            reasonCode);
                } catch (RemoteException e) {
                    continue;
                }
@@ -799,10 +801,10 @@ public class HapClientService extends ProfileService {
        }
    }

    private void notifyActivePresetChangedForGroup(int groupId, int presetIndex) {
    private void notifyActivePresetChangedForGroup(int groupId, int presetIndex, int reasonCode) {
        List<BluetoothDevice> all_group_devices = getGroupDevices(groupId);
        for (BluetoothDevice dev : all_group_devices) {
            notifyActivePresetChanged(dev, presetIndex);
            notifyActivePresetChanged(dev, presetIndex, reasonCode);
        }
    }

@@ -1103,14 +1105,18 @@ public class HapClientService extends ProfileService {

                if (device != null) {
                    mDeviceCurrentPresetMap.put(device, currentPresetIndex);
                    notifyActivePresetChanged(device, currentPresetIndex);
                    // FIXME: Add app request queueing to support other reasons
                    int reasonCode = BluetoothStatusCodes.REASON_LOCAL_STACK_REQUEST;
                    notifyActivePresetChanged(device, currentPresetIndex, reasonCode);

                } else if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
                    List<BluetoothDevice> all_group_devices = getGroupDevices(groupId);
                    for (BluetoothDevice dev : all_group_devices) {
                        mDeviceCurrentPresetMap.put(dev, currentPresetIndex);
                    }
                    notifyActivePresetChangedForGroup(groupId, currentPresetIndex);
                    // FIXME: Add app request queueing to support other reasons
                    int reasonCode = BluetoothStatusCodes.REASON_LOCAL_STACK_REQUEST;
                    notifyActivePresetChangedForGroup(groupId, currentPresetIndex, reasonCode);
                }
            } return;

+3 −3
Original line number Diff line number Diff line
@@ -697,7 +697,7 @@ public class HapClientTest {
     * Test that native callback generates proper callback call.
     */
    @Test
    public void testOtackEventonPresetSelected() {
    public void testStackEventOnPresetSelected() {
        doReturn(new ParcelUuid[]{BluetoothUuid.HAS}).when(mAdapterService)
                .getRemoteUuids(any(BluetoothDevice.class));

@@ -705,7 +705,7 @@ public class HapClientTest {

        try {
            verify(mCallback, after(TIMEOUT_MS).times(1)).onPresetSelected(eq(mDevice),
                    eq(0x01));
                    eq(0x01), eq(BluetoothStatusCodes.REASON_LOCAL_STACK_REQUEST));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -988,7 +988,7 @@ public class HapClientTest {

        try {
            verify(mCallback, after(TIMEOUT_MS).times(1)).onPresetSelected(eq(device),
                    eq(evt.valueInt1));
                    eq(evt.valueInt1), eq(BluetoothStatusCodes.REASON_LOCAL_STACK_REQUEST));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −1
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ package android.bluetooth {

  public static interface BluetoothHapClient.Callback {
    method public void onPresetInfoChanged(@NonNull android.bluetooth.BluetoothDevice, @NonNull java.util.List<android.bluetooth.BluetoothHapPresetInfo>, int);
    method public void onPresetSelected(@NonNull android.bluetooth.BluetoothDevice, int);
    method public void onPresetSelected(@NonNull android.bluetooth.BluetoothDevice, int, int);
    method public void onPresetSelectionFailed(@NonNull android.bluetooth.BluetoothDevice, int);
    method public void onPresetSelectionForGroupFailed(int, int);
    method public void onSetPresetNameFailed(@NonNull android.bluetooth.BluetoothDevice, int);
+10 −7
Original line number Diff line number Diff line
@@ -94,11 +94,13 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
         *
         * @param device remote device,
         * @param presetIndex the currently active preset index.
         * @param statusCode reason for the selected preset change
         *
         * @hide
         */
        @SystemApi
        void onPresetSelected(@NonNull BluetoothDevice device, int presetIndex);
        void onPresetSelected(@NonNull BluetoothDevice device, int presetIndex,
                @Status int statusCode);

        /**
         * Invoked inform about the result of a failed preset change attempt.
@@ -175,13 +177,14 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    @SuppressLint("AndroidFrameworkBluetoothPermission")
    private final IBluetoothHapClientCallback mCallback = new IBluetoothHapClientCallback.Stub() {
        @Override
        public void onPresetSelected(@NonNull BluetoothDevice device, int presetIndex) {
        public void onPresetSelected(@NonNull BluetoothDevice device, int presetIndex,
                int reasonCode) {
            Attributable.setAttributionSource(device, mAttributionSource);
            for (Map.Entry<BluetoothHapClient.Callback, Executor> callbackExecutorEntry:
                    mCallbackExecutorMap.entrySet()) {
                BluetoothHapClient.Callback callback = callbackExecutorEntry.getKey();
                Executor executor = callbackExecutorEntry.getValue();
                executor.execute(() -> callback.onPresetSelected(device, presetIndex));
                executor.execute(() -> callback.onPresetSelected(device, presetIndex, reasonCode));
            }
        }

@@ -866,7 +869,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    /**
     * Selects the currently active preset for a HA device
     *
     * On success, {@link Callback#onPresetSelected(BluetoothDevice, int)} will be called with
     * On success, {@link Callback#onPresetSelected(BluetoothDevice, int, int)} will be called with
     * reason code {@link BluetoothStatusCodes#REASON_LOCAL_APP_REQUEST}
     * On failure, {@link Callback#onPresetSelectionFailed(BluetoothDevice, int)} will be called.
     *
@@ -900,11 +903,11 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
     * <p> This group call may replace multiple device calls if those are part of the
     * valid HAS group. Note that binaural HA devices may or may not support group.
     *
     * On success, {@link Callback#onPresetSelected(BluetoothDevice, int)} will be called
     * On success, {@link Callback#onPresetSelected(BluetoothDevice, int, int)} will be called
     * for each device within the group with reason code
     * {@link BluetoothStatusCodes#REASON_LOCAL_APP_REQUEST}
     * On failure, {@link Callback#onPresetSelectionFailed(BluetoothDevice, int)} will be called
     * for each device within the group.
     * On failure, {@link Callback#onPresetSelectionForGroupFailed(int, int)} will be
     * called for the group.
     *
     * @param groupId is the device group identifier for which want to set the active preset
     * @param presetIndex is an index of one of the available presets
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import java.util.List;
 * @hide
 */
oneway interface IBluetoothHapClientCallback {
    void onPresetSelected(in BluetoothDevice device, in int presetIndex);
    void onPresetSelected(in BluetoothDevice device, in int presetIndex, in int reasonCode);
    void onPresetSelectionFailed(in  BluetoothDevice device, in int statusCode);
    void onPresetSelectionForGroupFailed(in int hapGroupId, in int statusCode);
    void onPresetInfoChanged(in  BluetoothDevice device,