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

Commit 7faed2f1 authored by Wei Wang's avatar Wei Wang Committed by Andre Eisenbach
Browse files

Unhide Bluetooth batch APIs. Deprecate BluetoothAdpater scan APIs. (1/2)

Change-Id: Ib0c4ea6c8372a15473269660355fb5ccf4284457
parent 0649e964
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.content.Context;
import android.os.Handler;
import android.os.IBinder;
@@ -1734,7 +1736,10 @@ public final class BluetoothAdapter {
     *
     * @param callback the callback LE scan results are delivered
     * @return true, if the scan was started successfully
     * @deprecated use {@link BluetoothLeScanner#startScan(List, ScanSettings, ScanCallback)}
     *             instead.
     */
    @Deprecated
    public boolean startLeScan(LeScanCallback callback) {
        return startLeScan(null, callback);
    }
@@ -1751,7 +1756,10 @@ public final class BluetoothAdapter {
     * @param serviceUuids Array of services to look for
     * @param callback the callback LE scan results are delivered
     * @return true, if the scan was started successfully
     * @deprecated use {@link BluetoothLeScanner#startScan(List, ScanSettings, ScanCallback)}
     *             instead.
     */
    @Deprecated
    public boolean startLeScan(UUID[] serviceUuids, LeScanCallback callback) {
        if (DBG) Log.d(TAG, "startLeScan(): " + serviceUuids);

@@ -1794,7 +1802,9 @@ public final class BluetoothAdapter {
     *
     * @param callback used to identify which scan to stop
     *        must be the same handle used to start the scan
     * @deprecated Use {@link BluetoothLeScanner#stopScan(ScanCallback)} instead.
     */
    @Deprecated
    public void stopLeScan(LeScanCallback callback) {
        if (DBG) Log.d(TAG, "stopLeScan()");
        GattCallbackWrapper wrapper;
+3 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package android.bluetooth;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.AdvertisementData;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanSettings;
import android.os.ParcelUuid;
@@ -40,8 +40,8 @@ interface IBluetoothGatt {
    void stopScan(in int appIf, in boolean isServer);
    void flushPendingBatchResults(in int appIf, in boolean isServer);
    void startMultiAdvertising(in int appIf,
                               in AdvertisementData advertiseData,
                               in AdvertisementData scanResponse,
                               in AdvertiseData advertiseData,
                               in AdvertiseData scanResponse,
                               in AdvertiseSettings settings);
    void stopMultiAdvertising(in int appIf);
    void registerClient(in ParcelUuid appId, in IBluetoothGattCallback callback);
+22 −28
Original line number Diff line number Diff line
@@ -17,64 +17,58 @@
package android.bluetooth.le;

/**
 * Callback of Bluetooth LE advertising, which is used to deliver advertising operation status.
 * Bluetooth LE advertising callbacks, used to deliver advertising operation status.
 */
public abstract class AdvertiseCallback {

    /**
     * The operation is success.
     *
     * The requested operation was successful.
     * @hide
     */
    public static final int SUCCESS = 0;
    public static final int ADVERTISE_SUCCESS = 0;

    /**
     * Fails to start advertising as the advertisement data contains services that are not added to
     * the local bluetooth GATT server.
     * Failed to start advertising as the advertisement data contains services that are not
     * added to the local Bluetooth GATT server.
     */
    public static final int ADVERTISE_FAILED_SERVICE_UNKNOWN = 1;

    /**
     * Fails to start advertising as system runs out of quota for advertisers.
     * Failed to start advertising because no advertising instance is available.
     */
    public static final int ADVERTISE_FAILED_TOO_MANY_ADVERTISERS = 2;

    /**
     * Fails to start advertising as the advertising is already started.
     * Failed to start advertising as the advertising is already started.
     */
    public static final int ADVERTISE_FAILED_ALREADY_STARTED = 3;
    /**
     * Fails to stop advertising as the advertising is not started.
     */
    public static final int ADVERTISE_FAILED_NOT_STARTED = 4;

    /**
     * Operation fails due to bluetooth controller failure.
     * Operation failed due to an internal error.
     */
    public static final int ADVERTISE_FAILED_CONTROLLER_FAILURE = 5;
    public static final int ADVERTISE_FAILED_INTERNAL_ERROR = 4;

    /**
     * Operation fails due to GATT service failure.
     * @hide
     * This feature is not supported on this platform.
     */
    public static final int ADVERTISE_FAILED_GATT_SERVICE_FAILURE = 6;

    /**
     * Operation fails as this feature is not supported
     */
    public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 7;
    public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 5;


    /**
     * Callback when advertising operation succeeds.
     * Callback triggered in response to {@link BluetoothLeAdvertiser#startAdvertising} indicating
     * that the advertising has been started successfully.
     *
     * @param settingsInEffect The actual settings used for advertising, which may be different from
     *            what the app asks.
     *            what has been requested.
     */
    public abstract void onSuccess(AdvertiseSettings settingsInEffect);
    public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    }

    /**
     * Callback when advertising operation fails.
     * Callback when advertising could not be started.
     *
     * @param errorCode Error code for failures.
     * @param errorCode Error code (see ADVERTISE_FAILED_* constants) for
     */
    public abstract void onFailure(int errorCode);
    public void onStartFailure(int errorCode) {
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -16,4 +16,4 @@

package android.bluetooth.le;

parcelable AdvertisementData;
 No newline at end of file
parcelable AdvertiseData;
+35 −34
Original line number Diff line number Diff line
@@ -27,16 +27,16 @@ import java.util.Arrays;
import java.util.List;

/**
 * Advertisement data packet for Bluetooth LE advertising. This represents the data to be
 * broadcasted in Bluetooth LE advertising as well as the scan response for active scan.
 * <p>
 * Use {@link AdvertisementData.Builder} to create an instance of {@link AdvertisementData} to be
 * Advertisement data packet container for Bluetooth LE advertising. This represents the data to be
 * advertised as well as the scan response data for active scans.
 *
 * <p>Use {@link AdvertiseData.Builder} to create an instance of {@link AdvertiseData} to be
 * advertised.
 *
 * @see BluetoothLeAdvertiser
 * @see ScanRecord
 */
public final class AdvertisementData implements Parcelable {
public final class AdvertiseData implements Parcelable {

    @Nullable
    private final List<ParcelUuid> mServiceUuids;
@@ -52,7 +52,7 @@ public final class AdvertisementData implements Parcelable {

    private boolean mIncludeTxPowerLevel;

    private AdvertisementData(List<ParcelUuid> serviceUuids,
    private AdvertiseData(List<ParcelUuid> serviceUuids,
            ParcelUuid serviceDataUuid, byte[] serviceData,
            int manufacturerId,
            byte[] manufacturerSpecificData, boolean includeTxPowerLevel) {
@@ -65,8 +65,8 @@ public final class AdvertisementData implements Parcelable {
    }

    /**
     * Returns a list of service uuids within the advertisement that are used to identify the
     * bluetooth GATT services.
     * Returns a list of service UUIDs within the advertisement that are used to identify the
     * Bluetooth GATT services.
     */
    public List<ParcelUuid> getServiceUuids() {
        return mServiceUuids;
@@ -89,15 +89,14 @@ public final class AdvertisementData implements Parcelable {
    }

    /**
     * Returns a 16 bit uuid of the service that the service data is associated with.
     * Returns a 16-bit UUID of the service that the service data is associated with.
     */
    public ParcelUuid getServiceDataUuid() {
        return mServiceDataUuid;
    }

    /**
     * Returns service data. The first two bytes should be a 16 bit service uuid associated with the
     * service data.
     * Returns service data.
     */
    public byte[] getServiceData() {
        return mServiceData;
@@ -112,7 +111,7 @@ public final class AdvertisementData implements Parcelable {

    @Override
    public String toString() {
        return "AdvertisementData [mServiceUuids=" + mServiceUuids + ", mManufacturerId="
        return "AdvertiseData [mServiceUuids=" + mServiceUuids + ", mManufacturerId="
                + mManufacturerId + ", mManufacturerSpecificData="
                + Arrays.toString(mManufacturerSpecificData) + ", mServiceDataUuid="
                + mServiceDataUuid + ", mServiceData=" + Arrays.toString(mServiceData)
@@ -156,15 +155,15 @@ public final class AdvertisementData implements Parcelable {
        dest.writeByte((byte) (getIncludeTxPowerLevel() ? 1 : 0));
    }

    public static final Parcelable.Creator<AdvertisementData> CREATOR =
            new Creator<AdvertisementData>() {
    public static final Parcelable.Creator<AdvertiseData> CREATOR =
            new Creator<AdvertiseData>() {
            @Override
                public AdvertisementData[] newArray(int size) {
                    return new AdvertisementData[size];
                public AdvertiseData[] newArray(int size) {
                    return new AdvertiseData[size];
                }

            @Override
                public AdvertisementData createFromParcel(Parcel in) {
                public AdvertiseData createFromParcel(Parcel in) {
                    Builder builder = new Builder();
                    if (in.readInt() > 0) {
                        List<ParcelUuid> uuids = new ArrayList<ParcelUuid>();
@@ -194,7 +193,7 @@ public final class AdvertisementData implements Parcelable {
            };

    /**
     * Builder for {@link AdvertisementData}.
     * Builder for {@link AdvertiseData}.
     */
    public static final class Builder {
        private static final int MAX_ADVERTISING_DATA_BYTES = 31;
@@ -215,11 +214,13 @@ public final class AdvertisementData implements Parcelable {
        private byte[] mServiceData;

        /**
         * Set the service uuids. Note the corresponding bluetooth Gatt services need to be already
         * added on the device before start BLE advertising.
         * Set the service UUIDs.
         *
         * <p><b>Note:</b> The corresponding Bluetooth Gatt services need to already
         * be added on the device (using {@link android.bluetooth.BluetoothGattServer#addService}) prior
         * to advertising them.
         *
         * @param serviceUuids Service uuids to be advertised, could be 16-bit, 32-bit or 128-bit
         *            uuids.
         * @param serviceUuids Service UUIDs to be advertised.
         * @throws IllegalArgumentException If the {@code serviceUuids} are null.
         */
        public Builder setServiceUuids(List<ParcelUuid> serviceUuids) {
@@ -233,9 +234,8 @@ public final class AdvertisementData implements Parcelable {
        /**
         * Add service data to advertisement.
         *
         * @param serviceDataUuid A 16 bit uuid of the service data
         * @param serviceData Service data - the first two bytes of the service data are the service
         *            data uuid.
         * @param serviceDataUuid 16-bit UUID of the service the data is associated with
         * @param serviceData Service data
         * @throws IllegalArgumentException If the {@code serviceDataUuid} or {@code serviceData} is
         *             empty.
         */
@@ -250,13 +250,14 @@ public final class AdvertisementData implements Parcelable {
        }

        /**
         * Set manufacturer id and data. See <a
         * href="https://www.bluetooth.org/en-us/specification/assigned-numbers/company-identifiers">assigned
         * manufacturer identifies</a> for the existing company identifiers.
         * Set manufacturer specific data.
         *
         * <p>Please refer to the Bluetooth Assigned Numbers document provided by the
         * <a href="https://www.bluetooth.org">Bluetooth SIG</a> for a list of existing
         * company identifiers.
         *
         * @param manufacturerId Manufacturer id assigned by Bluetooth SIG.
         * @param manufacturerSpecificData Manufacturer specific data - the first two bytes of the
         *            manufacturer specific data are the manufacturer id.
         * @param manufacturerId Manufacturer ID assigned by Bluetooth SIG.
         * @param manufacturerSpecificData Manufacturer specific data
         * @throws IllegalArgumentException If the {@code manufacturerId} is negative or
         *             {@code manufacturerSpecificData} is null.
         */
@@ -282,16 +283,16 @@ public final class AdvertisementData implements Parcelable {
        }

        /**
         * Build the {@link AdvertisementData}.
         * Build the {@link AdvertiseData}.
         *
         * @throws IllegalArgumentException If the data size is larger than 31 bytes.
         */
        public AdvertisementData build() {
        public AdvertiseData build() {
            if (totalBytes() > MAX_ADVERTISING_DATA_BYTES) {
                throw new IllegalArgumentException(
                        "advertisement data size is larger than 31 bytes");
            }
            return new AdvertisementData(mServiceUuids,
            return new AdvertiseData(mServiceUuids,
                    mServiceDataUuid,
                    mServiceData, mManufacturerId, mManufacturerSpecificData,
                    mIncludeTxPowerLevel);
Loading