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

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

Merge "hap: Align callback names to match API calls" am: 4cd8ea79 am: d69981f0

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

Change-Id: Ia41e32f794a37d274629793c5e89cb986048680b
parents e2cc064f d69981f0
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ public class HapClientService extends ProfileService {
                int n = mCallbacks.beginBroadcast();
                for (int i = 0; i < n; i++) {
                    try {
                        mCallbacks.getBroadcastItem(i).onSelectActivePresetFailed(device,
                        mCallbacks.getBroadcastItem(i).onPresetSelectionFailed(device,
                                BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX);
                    } catch (RemoteException e) {
                        continue;
@@ -630,7 +630,7 @@ public class HapClientService extends ProfileService {
                int n = mCallbacks.beginBroadcast();
                for (int i = 0; i < n; i++) {
                    try {
                        mCallbacks.getBroadcastItem(i).onSelectActivePresetForGroupFailed(groupId,
                        mCallbacks.getBroadcastItem(i).onPresetSelectionForGroupFailed(groupId,
                                BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX);
                    } catch (RemoteException e) {
                        continue;
@@ -790,7 +790,7 @@ public class HapClientService extends ProfileService {
            int n = mCallbacks.beginBroadcast();
            for (int i = 0; i < n; i++) {
                try {
                    mCallbacks.getBroadcastItem(i).onActivePresetChanged(device, presetIndex);
                    mCallbacks.getBroadcastItem(i).onPresetSelected(device, presetIndex);
                } catch (RemoteException e) {
                    continue;
                }
@@ -832,7 +832,7 @@ public class HapClientService extends ProfileService {
            int n = mCallbacks.beginBroadcast();
            for (int i = 0; i < n; i++) {
                try {
                    mCallbacks.getBroadcastItem(i).onSelectActivePresetFailed(device,
                    mCallbacks.getBroadcastItem(i).onPresetSelectionFailed(device,
                            stackEventStatusToProfileStatus(statusCode));
                } catch (RemoteException e) {
                    continue;
@@ -847,7 +847,7 @@ public class HapClientService extends ProfileService {
            int n = mCallbacks.beginBroadcast();
            for (int i = 0; i < n; i++) {
                try {
                    mCallbacks.getBroadcastItem(i).onSelectActivePresetForGroupFailed(groupId,
                    mCallbacks.getBroadcastItem(i).onPresetSelectionForGroupFailed(groupId,
                            stackEventStatusToProfileStatus(statusCode));
                } catch (RemoteException e) {
                    continue;
+9 −9
Original line number Diff line number Diff line
@@ -458,7 +458,7 @@ public class HapClientTest {
        verify(mNativeInterface, times(0))
                .selectActivePreset(eq(mDevice), eq(0x00));
        try {
            verify(mCallback, after(TIMEOUT_MS).times(1)).onSelectActivePresetFailed(eq(mDevice),
            verify(mCallback, after(TIMEOUT_MS).times(1)).onPresetSelectionFailed(eq(mDevice),
                    eq(BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -482,7 +482,7 @@ public class HapClientTest {
        // Verify Native Interface call
        mService.selectPresetForGroup(0x03, 0x00);
        try {
            verify(mCallback, after(TIMEOUT_MS).times(1)).onSelectActivePresetForGroupFailed(
            verify(mCallback, after(TIMEOUT_MS).times(1)).onPresetSelectionForGroupFailed(
                    eq(0x03), eq(BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -564,7 +564,7 @@ public class HapClientTest {
        doReturn(new ParcelUuid[]{BluetoothUuid.HAS}).when(mAdapterService)
                .getRemoteUuids(any(BluetoothDevice.class));
        testConnectingDevice(mDevice);
        testOnActivePresetChanged(mDevice, 0x01);
        testOnPresetSelected(mDevice, 0x01);

        // Verify cached value
        Assert.assertEquals(0x01, mService.getActivePresetIndex(mDevice));
@@ -585,7 +585,7 @@ public class HapClientTest {
        Assert.assertEquals(null, mService.getActivePresetInfo(mDevice2));

        // Inject active preset change event
        testOnActivePresetChanged(mDevice2, 0x01);
        testOnPresetSelected(mDevice2, 0x01);

        // Check when active preset is known
        Assert.assertEquals(0x01, mService.getActivePresetIndex(mDevice2));
@@ -697,14 +697,14 @@ public class HapClientTest {
     * Test that native callback generates proper callback call.
     */
    @Test
    public void testStackEventOnActivePresetChanged() {
    public void testOtackEventonPresetSelected() {
        doReturn(new ParcelUuid[]{BluetoothUuid.HAS}).when(mAdapterService)
                .getRemoteUuids(any(BluetoothDevice.class));

        mNativeInterface.onActivePresetSelected(getByteAddress(mDevice), 0x01);

        try {
            verify(mCallback, after(TIMEOUT_MS).times(1)).onActivePresetChanged(eq(mDevice),
            verify(mCallback, after(TIMEOUT_MS).times(1)).onPresetSelected(eq(mDevice),
                    eq(0x01));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -726,7 +726,7 @@ public class HapClientTest {
        mNativeInterface.onActivePresetSelectError(getByteAddress(mDevice), 0x05);

        try {
            verify(mCallback, after(TIMEOUT_MS).times(1)).onSelectActivePresetFailed(eq(mDevice),
            verify(mCallback, after(TIMEOUT_MS).times(1)).onPresetSelectionFailed(eq(mDevice),
                    eq(BluetoothStatusCodes.ERROR_HAP_INVALID_PRESET_INDEX));
        } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
@@ -979,7 +979,7 @@ public class HapClientTest {
                HapClientStackEvent.PRESET_INFO_REASON_ALL_PRESET_INFO, presets);
    }

    private void testOnActivePresetChanged(BluetoothDevice device, int index) {
    private void testOnPresetSelected(BluetoothDevice device, int index) {
        HapClientStackEvent evt =
                new HapClientStackEvent(HapClientStackEvent.EVENT_TYPE_ON_ACTIVE_PRESET_SELECTED);
        evt.device = device;
@@ -987,7 +987,7 @@ public class HapClientTest {
        mService.messageFromNative(evt);

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

  public static interface BluetoothHapClient.Callback {
    method public void onActivePresetChanged(@NonNull android.bluetooth.BluetoothDevice, int);
    method public void onPresetInfoChanged(@NonNull android.bluetooth.BluetoothDevice, @NonNull java.util.List<android.bluetooth.BluetoothHapPresetInfo>, int);
    method public void onSelectActivePresetFailed(@NonNull android.bluetooth.BluetoothDevice, int);
    method public void onSelectActivePresetForGroupFailed(int, int);
    method public void onPresetSelected(@NonNull android.bluetooth.BluetoothDevice, 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);
    method public void onSetPresetNameForGroupFailed(int, int);
  }
+13 −13
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
         * @hide
         */
        @SystemApi
        void onActivePresetChanged(@NonNull BluetoothDevice device, int presetIndex);
        void onPresetSelected(@NonNull BluetoothDevice device, int presetIndex);

        /**
         * Invoked inform about the result of a failed preset change attempt.
@@ -109,7 +109,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
         * @hide
         */
        @SystemApi
        void onSelectActivePresetFailed(@NonNull BluetoothDevice device, @Status int statusCode);
        void onPresetSelectionFailed(@NonNull BluetoothDevice device, @Status int statusCode);

        /**
         * Invoked to inform about the result of a failed preset change attempt.
@@ -122,7 +122,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
         * @hide
         */
        @SystemApi
        void onSelectActivePresetForGroupFailed(int hapGroupId, @Status int statusCode);
        void onPresetSelectionForGroupFailed(int hapGroupId, @Status int statusCode);

        /**
         * Invoked to inform about the preset list changes.
@@ -175,35 +175,35 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    @SuppressLint("AndroidFrameworkBluetoothPermission")
    private final IBluetoothHapClientCallback mCallback = new IBluetoothHapClientCallback.Stub() {
        @Override
        public void onActivePresetChanged(@NonNull BluetoothDevice device, int presetIndex) {
        public void onPresetSelected(@NonNull BluetoothDevice device, int presetIndex) {
            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.onActivePresetChanged(device, presetIndex));
                executor.execute(() -> callback.onPresetSelected(device, presetIndex));
            }
        }

        @Override
        public void onSelectActivePresetFailed(@NonNull BluetoothDevice device, int status) {
        public void onPresetSelectionFailed(@NonNull BluetoothDevice device, int status) {
            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.onSelectActivePresetFailed(device, status));
                executor.execute(() -> callback.onPresetSelectionFailed(device, status));
            }
        }

        @Override
        public void onSelectActivePresetForGroupFailed(int hapGroupId, int statusCode) {
        public void onPresetSelectionForGroupFailed(int hapGroupId, int statusCode) {
            for (Map.Entry<BluetoothHapClient.Callback, Executor> callbackExecutorEntry:
                    mCallbackExecutorMap.entrySet()) {
                BluetoothHapClient.Callback callback = callbackExecutorEntry.getKey();
                Executor executor = callbackExecutorEntry.getValue();
                executor.execute(
                        () -> callback.onSelectActivePresetForGroupFailed(hapGroupId, statusCode));
                        () -> callback.onPresetSelectionForGroupFailed(hapGroupId, statusCode));
            }
        }

@@ -866,9 +866,9 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    /**
     * Selects the currently active preset for a HA device
     *
     * On success, {@link Callback#onActivePresetChanged(BluetoothDevice, int)} will be called with
     * On success, {@link Callback#onPresetSelected(BluetoothDevice, int)} will be called with
     * reason code {@link BluetoothStatusCodes#REASON_LOCAL_APP_REQUEST}
     * On failure, {@link Callback#onSelectActivePresetFailed(BluetoothDevice, int)} will be called.
     * On failure, {@link Callback#onPresetSelectionFailed(BluetoothDevice, int)} will be called.
     *
     * @param device is the device for which we want to set the active preset
     * @param presetIndex is an index of one of the available presets
@@ -900,10 +900,10 @@ 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#onActivePresetChanged(BluetoothDevice, int)} will be called
     * On success, {@link Callback#onPresetSelected(BluetoothDevice, int)} will be called
     * for each device within the group with reason code
     * {@link BluetoothStatusCodes#REASON_LOCAL_APP_REQUEST}
     * On failure, {@link Callback#onSelectActivePresetFailed(BluetoothDevice, int)} will be called
     * On failure, {@link Callback#onPresetSelectionFailed(BluetoothDevice, int)} will be called
     * for each device within the group.
     *
     * @param groupId is the device group identifier for which want to set the active preset
+3 −3
Original line number Diff line number Diff line
@@ -27,9 +27,9 @@ import java.util.List;
 * @hide
 */
oneway interface IBluetoothHapClientCallback {
    void onActivePresetChanged(in BluetoothDevice device, in int presetIndex);
    void onSelectActivePresetFailed(in  BluetoothDevice device, in int statusCode);
    void onSelectActivePresetForGroupFailed(in int hapGroupId, in int statusCode);
    void onPresetSelected(in BluetoothDevice device, in int presetIndex);
    void onPresetSelectionFailed(in  BluetoothDevice device, in int statusCode);
    void onPresetSelectionForGroupFailed(in int hapGroupId, in int statusCode);
    void onPresetInfoChanged(in  BluetoothDevice device,
                in List<BluetoothHapPresetInfo> presetInfoList,
                in int statusCode);