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

Commit f4445cda authored by Yuyang Huang's avatar Yuyang Huang
Browse files

add EXTRA_IS_ASHA_FOLLOWER as system api

This targets to resolve the conflict between ASHA device's and CSIP's advertising requirement

Test: manual
Tag: #feature
Bug: 265027285
Change-Id: Ic9604cf5f103d1417c1b02b552862ec9f980bff2
parent 0195774d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ public final class AbstractionLayer {

    static final int BT_PROPERTY_DYNAMIC_AUDIO_BUFFER = 0x10;
    static final int BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER = 0x11;
    static final int BT_PROPERTY_REMOTE_IS_ASHA_FOLLOWER = 0X12;
    static final int BT_PROPERTY_WL_MEDIA_PLAYERS_LIST = 0x14;

    public static final int BT_DEVICE_TYPE_BREDR = 0x01;
+21 −0
Original line number Diff line number Diff line
@@ -316,6 +316,7 @@ final class RemoteDevices {
        private boolean mIsBondingInitiatedLocally;
        private int mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
        private boolean mIsCoordinatedSetMember;
        private boolean mIsASHAFollower;
        @VisibleForTesting int mBondState;
        @VisibleForTesting int mDeviceType;
        @VisibleForTesting ParcelUuid[] mUuids;
@@ -634,6 +635,21 @@ final class RemoteDevices {
            }
        }

        /**
         * @return the mIsASHAFollower
        */
        boolean isASHAFollower() {
            synchronized (mObject) {
                return mIsASHAFollower;
            }
        }

        void setIsASHAFollower(boolean isASHAFollower) {
            synchronized (mObject) {
                this.mIsASHAFollower = isASHAFollower;
            }
        }

        public void setHfAudioPolicyForRemoteAg(BluetoothAudioPolicy policies) {
            mAudioPolicy = policies;
        }
@@ -880,6 +896,9 @@ final class RemoteDevices {
                        case AbstractionLayer.BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER:
                            deviceProperties.setIsCoordinatedSetMember(val[0] != 0);
                            break;
                        case AbstractionLayer.BT_PROPERTY_REMOTE_IS_ASHA_FOLLOWER:
                            deviceProperties.setIsASHAFollower(val[0] != 0);
                            break;
                    }
                }
            }
@@ -911,6 +930,8 @@ final class RemoteDevices {
        intent.putExtra(BluetoothDevice.EXTRA_NAME, deviceProp.getName());
        intent.putExtra(BluetoothDevice.EXTRA_IS_COORDINATED_SET_MEMBER,
                deviceProp.isCoordinatedSetMember());
        intent.putExtra(BluetoothDevice.EXTRA_IS_ASHA_FOLLOWER,
                deviceProp.isASHAFollower());

        final ArrayList<DiscoveringPackage> packages = mAdapterService.getDiscoveringPackages();
        synchronized (packages) {
+1 −0
Original line number Diff line number Diff line
@@ -225,6 +225,7 @@ package android.bluetooth {
    field public static final String EXTRA_ALWAYS_ALLOWED = "android.bluetooth.device.extra.ALWAYS_ALLOWED";
    field public static final String EXTRA_BATTERY_LEVEL = "android.bluetooth.device.extra.BATTERY_LEVEL";
    field public static final String EXTRA_CONNECTION_ACCESS_RESULT = "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT";
    field public static final String EXTRA_IS_ASHA_FOLLOWER = "android.bluetooth.device.extra.IS_ASHA_FOLLOWER";
    field public static final String EXTRA_LOW_LATENCY_BUFFER_SIZE = "android.bluetooth.device.extra.LOW_LATENCY_BUFFER_SIZE";
    field public static final String EXTRA_PAIRING_INITIATOR = "android.bluetooth.device.extra.PAIRING_INITIATOR";
    field public static final int EXTRA_PAIRING_INITIATOR_BACKGROUND = 2; // 0x2
+15 −0
Original line number Diff line number Diff line
@@ -322,6 +322,21 @@ public final class BluetoothDevice implements Parcelable, Attributable {
    public static final String EXTRA_IS_COORDINATED_SET_MEMBER =
            "android.bluetooth.extra.IS_COORDINATED_SET_MEMBER";

    /**
     * Used as a boolean extra field in {@link #ACTION_FOUND} intents.
     * Indicates that an ASHA device should be hidden from users because of backward compatibility.
     * ASHA requires each hearing aid to advertise as discoverable,
     * but CSIP requires follower devices of a set to advertise as non-discoverable.
     * This field helps devices supporting ASHA and CSIP to show up properly
     * in settings while pairing.
     * See Bluetooth CSIP specification for more details.
     *
     * @hide
     */
    @SuppressLint("ActionValue")
    @SystemApi
    public static final String EXTRA_IS_ASHA_FOLLOWER =
            "android.bluetooth.device.extra.IS_ASHA_FOLLOWER";
    /**
     * Used as a Parcelable {@link BluetoothClass} extra field in {@link
     * #ACTION_FOUND} and {@link #ACTION_CLASS_CHANGED} intents.
+38 −0
Original line number Diff line number Diff line
@@ -1337,6 +1337,44 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
          num_properties++;
        }

        // default to be not as a ASHA follower
        bool is_ASHA_follower = false;
        BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                                   BT_PROPERTY_REMOTE_IS_ASHA_FOLLOWER,
                                   sizeof(bool), &is_ASHA_follower);
        num_properties++;

        // based on ASHA advertising service data to decide whether it is hidden
        tBTA_DM_INQ_RES inq_res = p_search_data->inq_res;
        const uint8_t* p_service_data = p_search_data->inq_res.p_eir;
        uint8_t service_data_len = 0;
        while ((p_service_data = AdvertiseDataParser::GetFieldByType(
                    p_service_data + service_data_len,
                    inq_res.eir_len - (p_service_data - inq_res.p_eir) -
                        service_data_len,
                    BTM_BLE_AD_TYPE_SERVICE_DATA_TYPE, &service_data_len))) {
          uint16_t uuid;
          const uint8_t* p_uuid = p_service_data;
          STREAM_TO_UINT16(uuid, p_uuid);

          if (uuid == 0xfdf0 /* ASHA service*/) {
            LOG_INFO("ASHA found in %s", ADDRESS_TO_LOGGABLE_CSTR(bdaddr));

            if (service_data_len < 8) {
              LOG_WARN("ASHA device service_data_len too short");
            } else {
              is_ASHA_follower = (p_service_data[3] & 0x04) != 0;
              LOG_INFO("is_ASHA_follower_device: %d", is_ASHA_follower);
              if (is_ASHA_follower) {
                BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                                           BT_PROPERTY_REMOTE_IS_ASHA_FOLLOWER,
                                           sizeof(bool), &is_ASHA_follower);
              }
            }
            break;
          }
        }

        /* DEV_CLASS */
        uint32_t cod = devclass2uint(p_search_data->inq_res.dev_class);
        BTIF_TRACE_DEBUG("%s cod is 0x%06x", __func__, cod);
Loading