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

Commit 71937f9e authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

Merge changes from topic "bt-api-update" am: 0b3fcdf1 am: 5b479003

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

Change-Id: Ib2c06728fc1d3e42068d158aa23dfa7e3d654928
parents 0921283f 5b479003
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
package com.android.bluetooth.csip;

import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;

import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
@@ -26,6 +25,7 @@ import android.annotation.Nullable;
import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.IBluetoothCsipSetCoordinator;
import android.bluetooth.IBluetoothCsipSetCoordinatorCallback;
@@ -488,7 +488,8 @@ public class CsipSetCoordinatorService extends ProfileService {
            if (mLocks.containsKey(groupId)) {
                try {
                    callback.onGroupLockSet(groupId,
                            BluetoothCsipSetCoordinator.GROUP_LOCK_FAILED_LOCKED_BY_OTHER, true);
                            BluetoothStatusCodes.ERROR_CSIP_GROUP_LOCKED_BY_OTHER,
                            true);
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                }
@@ -615,6 +616,25 @@ public class CsipSetCoordinatorService extends ProfileService {
        }
    }

    int getApiStatusCode(int nativeResult) {
        switch (nativeResult) {
            case IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_SUCCESS:
                return BluetoothStatusCodes.SUCCESS;
            case IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_FAILED_INVALID_GROUP:
                return BluetoothStatusCodes.ERROR_CSIP_INVALID_GROUP_ID;
            case IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_FAILED_GROUP_NOT_CONNECTED:
                return BluetoothStatusCodes.ERROR_DEVICE_NOT_CONNECTED;
            case IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_FAILED_LOCKED_BY_OTHER:
                return BluetoothStatusCodes.ERROR_CSIP_GROUP_LOCKED_BY_OTHER;
            case IBluetoothCsipSetCoordinator.CSIS_LOCKED_GROUP_MEMBER_LOST:
                return BluetoothStatusCodes.ERROR_CSIP_LOCKED_GROUP_MEMBER_LOST;
            case IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_FAILED_OTHER_REASON:
            default:
                Log.e(TAG, " Unknown status code: " + nativeResult);
                return BluetoothStatusCodes.ERROR_UNKNOWN;
        }
    }

    void handleGroupLockChanged(int groupId, int status, boolean isLocked) {
        synchronized (mLocks) {
            if (!mLocks.containsKey(groupId)) {
@@ -623,7 +643,7 @@ public class CsipSetCoordinatorService extends ProfileService {

            IBluetoothCsipSetCoordinatorLockCallback cb = mLocks.get(groupId).second;
            try {
                cb.onGroupLockSet(groupId, status, isLocked);
                cb.onGroupLockSet(groupId, getApiStatusCode(status), isLocked);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
+7 −5
Original line number Diff line number Diff line
@@ -260,11 +260,12 @@ public class CsipSetCoordinatorServiceTest {
                .when(mCsipSetCoordinatorNativeInterface)
                .onGroupLockChanged(anyInt(), anyBoolean(), anyInt());
        mCsipSetCoordinatorNativeInterface.onGroupLockChanged(
                group, true, BluetoothCsipSetCoordinator.GROUP_LOCK_SUCCESS);
                group, true, IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_SUCCESS);

        try {
            verify(mCsipSetCoordinatorLockCallback, times(1))
                    .onGroupLockSet(group, BluetoothCsipSetCoordinator.GROUP_LOCK_SUCCESS, true);
                    .onGroupLockSet(group, BluetoothStatusCodes.SUCCESS,
                        true);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -273,11 +274,12 @@ public class CsipSetCoordinatorServiceTest {
        verify(mCsipSetCoordinatorNativeInterface, times(1)).groupLockSet(eq(group), eq(false));

        mCsipSetCoordinatorNativeInterface.onGroupLockChanged(
                group, false, BluetoothCsipSetCoordinator.GROUP_LOCK_SUCCESS);
                group, false, IBluetoothCsipSetCoordinator.CSIS_GROUP_LOCK_SUCCESS);

        try {
            verify(mCsipSetCoordinatorLockCallback, times(1))
                    .onGroupLockSet(group, BluetoothCsipSetCoordinator.GROUP_LOCK_SUCCESS, false);
                    .onGroupLockSet(group, BluetoothStatusCodes.SUCCESS,
                        false);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -305,7 +307,7 @@ public class CsipSetCoordinatorServiceTest {
        try {
            verify(mCsipSetCoordinatorLockCallback, times(1))
                    .onGroupLockSet(group,
                            BluetoothCsipSetCoordinator.GROUP_LOCK_FAILED_LOCKED_BY_OTHER, true);
                    BluetoothStatusCodes.ERROR_CSIP_GROUP_LOCKED_BY_OTHER, true);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −9
Original line number Diff line number Diff line
@@ -751,15 +751,6 @@ package android.bluetooth {
    field protected java.util.List<android.bluetooth.BluetoothGattService> mIncludedServices;
  }

  public final class BluetoothHapClient implements java.lang.AutoCloseable android.bluetooth.BluetoothProfile {
    method public void close();
    method protected void finalize();
    method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getConnectionState(@NonNull android.bluetooth.BluetoothDevice);
    method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(@NonNull int[]);
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_HAP_CONNECTION_STATE_CHANGED = "android.bluetooth.action.HAP_CONNECTION_STATE_CHANGED";
  }

  public final class BluetoothHeadset implements android.bluetooth.BluetoothProfile {
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getConnectionState(android.bluetooth.BluetoothDevice);
@@ -918,6 +909,7 @@ package android.bluetooth {
    method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(@NonNull int[]);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getGroupId(@NonNull android.bluetooth.BluetoothDevice);
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED = "android.bluetooth.action.LE_AUDIO_CONNECTION_STATE_CHANGED";
    field public static final int GROUP_ID_INVALID = -1; // 0xffffffff
  }

  public final class BluetoothLeAudioCodecConfig implements android.os.Parcelable {
+38 −0
Original line number Diff line number Diff line
@@ -148,6 +148,32 @@ package android.bluetooth {
    field public static final int METADATA_UNTETHERED_RIGHT_LOW_BATTERY_THRESHOLD = 22; // 0x16
  }

  public final class BluetoothHapClient implements java.lang.AutoCloseable android.bluetooth.BluetoothProfile {
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public android.bluetooth.BluetoothHapPresetInfo getActivePresetInfo(@NonNull android.bluetooth.BluetoothDevice);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<android.bluetooth.BluetoothHapPresetInfo> getAllPresetInfo(@NonNull android.bluetooth.BluetoothDevice);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionState(@NonNull android.bluetooth.BluetoothDevice);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(@NonNull int[]);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothHapClient.Callback);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void selectPreset(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void selectPresetForGroup(int, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setPresetName(@NonNull android.bluetooth.BluetoothDevice, int, @NonNull String);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setPresetNameForGroup(int, int, @NonNull String);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void unregisterCallback(@NonNull android.bluetooth.BluetoothHapClient.Callback);
    field @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public static final String ACTION_HAP_CONNECTION_STATE_CHANGED = "android.bluetooth.action.HAP_CONNECTION_STATE_CHANGED";
  }

  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 onSetPresetNameFailed(@NonNull android.bluetooth.BluetoothDevice, int);
    method public void onSetPresetNameForGroupFailed(int, int);
  }

  public final class BluetoothHapPresetInfo implements android.os.Parcelable {
    method public int getIndex();
    method @NonNull public String getName();
@@ -207,6 +233,12 @@ package android.bluetooth {

  public final class BluetoothLeAudio implements java.lang.AutoCloseable android.bluetooth.BluetoothProfile {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getAudioLocation(@NonNull android.bluetooth.BluetoothDevice);
    field @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public static final String ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED = "android.bluetooth.action.LE_AUDIO_ACTIVE_DEVICE_CHANGED";
    field @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public static final String ACTION_LE_AUDIO_GROUP_NODE_STATUS_CHANGED = "android.bluetooth.action.LE_AUDIO_GROUP_NODE_STATUS_CHANGED";
    field public static final String EXTRA_LE_AUDIO_GROUP_ID = "android.bluetooth.extra.LE_AUDIO_GROUP_ID";
    field public static final String EXTRA_LE_AUDIO_GROUP_NODE_STATUS = "android.bluetooth.extra.LE_AUDIO_GROUP_NODE_STATUS";
    field public static final int GROUP_NODE_ADDED = 1; // 0x1
    field public static final int GROUP_NODE_REMOVED = 2; // 0x2
  }

  public final class BluetoothLeAudioCodecConfigMetadata implements android.os.Parcelable {
@@ -461,6 +493,11 @@ package android.bluetooth {
    field public static final int ERROR_ALREADY_IN_TARGET_STATE = 26; // 0x1a
    field public static final int ERROR_ANOTHER_ACTIVE_OOB_REQUEST = 1000; // 0x3e8
    field public static final int ERROR_BAD_PARAMETERS = 21; // 0x15
    field public static final int ERROR_CSIP_GROUP_LOCKED_BY_OTHER = 1208; // 0x4b8
    field public static final int ERROR_CSIP_INVALID_GROUP_ID = 1207; // 0x4b7
    field public static final int ERROR_CSIP_LOCKED_GROUP_MEMBER_LOST = 1209; // 0x4b9
    field public static final int ERROR_HAP_INVALID_PRESET_INDEX = 1211; // 0x4bb
    field public static final int ERROR_HAP_PRESET_NAME_TOO_LONG = 1210; // 0x4ba
    field public static final int ERROR_HARDWARE_GENERIC = 20; // 0x14
    field public static final int ERROR_LE_BROADCAST_ASSISTANT_DUPLICATE_ADDITION = 1203; // 0x4b3
    field public static final int ERROR_LE_BROADCAST_ASSISTANT_INVALID_SOURCE_ID = 1202; // 0x4b2
@@ -472,6 +509,7 @@ package android.bluetooth {
    field public static final int ERROR_LOCAL_NOT_ENOUGH_RESOURCES = 22; // 0x16
    field public static final int ERROR_REMOTE_LINK_ERROR = 25; // 0x19
    field public static final int ERROR_REMOTE_NOT_ENOUGH_RESOURCES = 23; // 0x17
    field public static final int ERROR_REMOTE_OPERATION_NOT_SUPPORTED = 24; // 0x18
    field public static final int ERROR_REMOTE_OPERATION_REJECTED = 24; // 0x18
    field public static final int ERROR_TIMEOUT = 15; // 0xf
    field public static final int NOT_ALLOWED = 401; // 0x191
+24 −51
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.bluetooth.BluetoothUtils.getSyncTimeout;

import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -37,6 +38,8 @@ import android.util.Log;

import com.android.modules.utils.SynchronousResultReceiver;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -49,7 +52,7 @@ import java.util.concurrent.TimeoutException;
/**
 * This class provides the public APIs to control the Bluetooth CSIP set coordinator.
 *
 * <p>BluetoothCsipSetCoordinator is a proxy object for controlling the Bluetooth VC
 * <p>BluetoothCsipSetCoordinator is a proxy object for controlling the Bluetooth CSIP set
 * Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get
 * the BluetoothCsipSetCoordinator proxy object.
 *
@@ -66,10 +69,29 @@ public final class BluetoothCsipSetCoordinator implements BluetoothProfile, Auto
     */
    @SystemApi
    public interface ClientLockCallback {
        /** @hide */
        @IntDef(value = {
                BluetoothStatusCodes.SUCCESS,
                BluetoothStatusCodes.ERROR_DEVICE_NOT_CONNECTED,
                BluetoothStatusCodes.ERROR_CSIP_INVALID_GROUP_ID,
                BluetoothStatusCodes.ERROR_CSIP_GROUP_LOCKED_BY_OTHER,
                BluetoothStatusCodes.ERROR_CSIP_LOCKED_GROUP_MEMBER_LOST,
                BluetoothStatusCodes.ERROR_UNKNOWN,
        })
        @Retention(RetentionPolicy.SOURCE)
        @interface Status {}

        /**
         * Callback is invoken as a result on {@link #groupLock()}.
         *
         * @param groupId group identifier
         * @param opStatus status of lock operation
         * @param isLocked inidcates if group is locked
         *
         * @hide
         */
        @SystemApi void onGroupLockSet(int groupId, int opStatus, boolean isLocked);
        @SystemApi
        void onGroupLockSet(int groupId, @Status int opStatus, boolean isLocked);
    }

    private static class BluetoothCsipSetCoordinatorLockCallbackDelegate
@@ -177,55 +199,6 @@ public final class BluetoothCsipSetCoordinator implements BluetoothProfile, Auto
     */
    public static final int GROUP_ID_INVALID = IBluetoothCsipSetCoordinator.CSIS_GROUP_ID_INVALID;

    /**
     * Indicating that group was locked with success.
     *
     * @hide
     */
    public static final int GROUP_LOCK_SUCCESS = 0;

    /**
     * Indicating that group locked failed due to invalid group ID.
     *
     * @hide
     */
    public static final int GROUP_LOCK_FAILED_INVALID_GROUP = 1;

    /**
     * Indicating that group locked failed due to empty group.
     *
     * @hide
     */
    public static final int GROUP_LOCK_FAILED_GROUP_EMPTY = 2;

    /**
     * Indicating that group locked failed due to group members being disconnected.
     *
     * @hide
     */
    public static final int GROUP_LOCK_FAILED_GROUP_NOT_CONNECTED = 3;

    /**
     * Indicating that group locked failed due to group member being already locked.
     *
     * @hide
     */
    public static final int GROUP_LOCK_FAILED_LOCKED_BY_OTHER = 4;

    /**
     * Indicating that group locked failed due to other reason.
     *
     * @hide
     */
    public static final int GROUP_LOCK_FAILED_OTHER_REASON = 5;

    /**
     * Indicating that group member in locked state was lost.
     *
     * @hide
     */
    public static final int LOCKED_GROUP_MEMBER_LOST = 6;

    private final BluetoothAdapter mAdapter;
    private final AttributionSource mAttributionSource;
    private final BluetoothProfileConnector<IBluetoothCsipSetCoordinator> mProfileConnector =
Loading