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

Commit ab39cb7f authored by Wei Wang's avatar Wei Wang
Browse files

Add scan response as an advertising parameter(1/2).

Change-Id: I75c500dd7b5f2609d3092f50ba284a5ec4a41987
parent 3d6eed96
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6140,6 +6140,7 @@ package android.bluetooth {
    ctor public BluetoothLeAdvertiseScanData();
    field public static final int ADVERTISING_DATA = 0; // 0x0
    field public static final int PARSED_SCAN_RECORD = 2; // 0x2
    field public static final int SCAN_RESPONSE_DATA = 1; // 0x1
  }
  public static abstract class BluetoothLeAdvertiseScanData.AdvertiseBaseData {
@@ -6183,6 +6184,7 @@ package android.bluetooth {
  public class BluetoothLeAdvertiser {
    method public void startAdvertising(android.bluetooth.BluetoothLeAdvertiser.Settings, android.bluetooth.BluetoothLeAdvertiseScanData.AdvertisementData, android.bluetooth.BluetoothLeAdvertiser.AdvertiseCallback);
    method public void startAdvertising(android.bluetooth.BluetoothLeAdvertiser.Settings, android.bluetooth.BluetoothLeAdvertiseScanData.AdvertisementData, android.bluetooth.BluetoothLeAdvertiseScanData.AdvertisementData, android.bluetooth.BluetoothLeAdvertiser.AdvertiseCallback);
    method public void stopAdvertising(android.bluetooth.BluetoothLeAdvertiser.Settings, android.bluetooth.BluetoothLeAdvertiser.AdvertiseCallback);
  }
+0 −3
Original line number Diff line number Diff line
@@ -53,9 +53,6 @@ public final class BluetoothLeAdvertiseScanData {
     * Bluetooth LE scan response data, the data will be placed in ScanRspData field of advertising
     * packet.
     * <p>
     * TODO: unhide when stack supports setting scan response data.
     *
     * @hide
     */
    public static final int SCAN_RESPONSE_DATA = 1;
    /**
+19 −4
Original line number Diff line number Diff line
@@ -328,6 +328,7 @@ public class BluetoothLeAdvertiser {
        private static final int LE_CALLBACK_TIMEOUT_MILLIS = 2000;
        private final AdvertiseCallback mAdvertiseCallback;
        private final AdvertisementData mAdvertisement;
        private final AdvertisementData mScanResponse;
        private final Settings mSettings;
        private final IBluetoothGatt mBluetoothGatt;

@@ -338,10 +339,11 @@ public class BluetoothLeAdvertiser {
        private boolean isAdvertising = false;

        public AdvertiseCallbackWrapper(AdvertiseCallback advertiseCallback,
                AdvertisementData advertiseData, Settings settings,
                AdvertisementData advertiseData, AdvertisementData scanResponse, Settings settings,
                IBluetoothGatt bluetoothGatt) {
            mAdvertiseCallback = advertiseCallback;
            mAdvertisement = advertiseData;
            mScanResponse = scanResponse;
            mSettings = settings;
            mBluetoothGatt = bluetoothGatt;
            mLeHandle = 0;
@@ -384,7 +386,8 @@ public class BluetoothLeAdvertiser {
                if (status == BluetoothGatt.GATT_SUCCESS) {
                    mLeHandle = clientIf;
                    try {
                        mBluetoothGatt.startMultiAdvertising(mLeHandle, mAdvertisement, mSettings);
                        mBluetoothGatt.startMultiAdvertising(mLeHandle, mAdvertisement,
                                mScanResponse, mSettings);
                    } catch (RemoteException e) {
                        Log.e(TAG, "fail to start le advertise: " + e);
                        mLeHandle = -1;
@@ -540,6 +543,19 @@ public class BluetoothLeAdvertiser {
     */
    public void startAdvertising(Settings settings,
            AdvertisementData advertiseData, final AdvertiseCallback callback) {
        startAdvertising(settings, advertiseData, null, callback);
    }

    /**
     * Start Bluetooth LE Advertising.
     * @param settings {@link Settings} for Bluetooth LE advertising.
     * @param advertiseData {@link AdvertisementData} to be advertised in advertisement packet.
     * @param scanResponse {@link AdvertisementData} for scan response.
     * @param callback {@link AdvertiseCallback} for advertising status.
     */
    public void startAdvertising(Settings settings,
            AdvertisementData advertiseData, AdvertisementData scanResponse,
            final AdvertiseCallback callback) {
        if (callback == null) {
            throw new IllegalArgumentException("callback cannot be null");
        }
@@ -548,8 +564,7 @@ public class BluetoothLeAdvertiser {
            return;
        }
        AdvertiseCallbackWrapper wrapper = new AdvertiseCallbackWrapper(callback, advertiseData,
                settings,
                mBluetoothGatt);
                scanResponse, settings, mBluetoothGatt);
        UUID uuid = UUID.randomUUID();
        try {
            mBluetoothGatt.registerClient(new ParcelUuid(uuid), wrapper);
+3 −1
Original line number Diff line number Diff line
@@ -41,7 +41,9 @@ interface IBluetoothGatt {
                              in BluetoothLeScanner.Settings settings,
                              in List<BluetoothLeScanFilter> filters);
    void stopScan(in int appIf, in boolean isServer);
    void startMultiAdvertising(in int appIf, in BluetoothLeAdvertiseScanData.AdvertisementData data,
    void startMultiAdvertising(in int appIf,
                               in BluetoothLeAdvertiseScanData.AdvertisementData advertiseData,
                               in BluetoothLeAdvertiseScanData.AdvertisementData scanResponse,
                               in BluetoothLeAdvertiser.Settings settings);
    void stopMultiAdvertising(in int appIf);
    void registerClient(in ParcelUuid appId, in IBluetoothGattCallback callback);