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

Commit ab7d545b authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by android-build-merger
Browse files

Merge "Bluetooth 5 move timeout parameter (1/2)"

am: d791d1d7

Change-Id: Iee7d485461f5e02ab65ec9f7311e962deb603543
parents d1f4d58d d791d1d7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -52,10 +52,10 @@ interface IBluetoothGatt {

    void startAdvertisingSet(in AdvertisingSetParameters parameters, in AdvertiseData advertiseData,
                                in AdvertiseData scanResponse, in PeriodicAdvertisingParameters periodicParameters,
                                in AdvertiseData periodicData, in IAdvertisingSetCallback callback);
                                in AdvertiseData periodicData, in int timeout, in IAdvertisingSetCallback callback);
    void stopAdvertisingSet(in IAdvertisingSetCallback callback);

    void enableAdverisingSet(in int advertiserId, in boolean enable);
    void enableAdverisingSet(in int advertiserId, in boolean enable, in int timeout);
    void setAdvertisingData(in int advertiserId, in AdvertiseData data);
    void setScanResponseData(in int advertiserId, in AdvertiseData data);
    void setAdvertisingParameters(in int advertiserId, in AdvertisingSetParameters parameters);
+2 −2
Original line number Diff line number Diff line
@@ -63,9 +63,9 @@ public final class AdvertisingSet {
     * Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
     *
     */
    public void enableAdvertising(boolean enable) {
    public void enableAdvertising(boolean enable, int timeout) {
        try {
            gatt.enableAdverisingSet(this.advertiserId, enable);
            gatt.enableAdverisingSet(this.advertiserId, enable, timeout);
        } catch (RemoteException e) {
            Log.e(TAG, "remote exception - ", e);
        }
+3 −33
Original line number Diff line number Diff line
@@ -118,13 +118,11 @@ public final class AdvertisingSetParameters implements Parcelable {
    private final boolean connectable;
    private final int interval;
    private final int txPowerLevel;
    private final int timeoutMillis;

    private AdvertisingSetParameters(boolean connectable, boolean isLegacy,
                                     boolean isAnonymous, boolean includeTxPower,
                                     int primaryPhy, int secondaryPhy,
                                     int interval, int txPowerLevel,
                                     int timeoutMillis) {
                                     int interval, int txPowerLevel) {
        this.connectable = connectable;
        this.isLegacy = isLegacy;
        this.isAnonymous = isAnonymous;
@@ -133,7 +131,6 @@ public final class AdvertisingSetParameters implements Parcelable {
        this.secondaryPhy = secondaryPhy;
        this.interval = interval;
        this.txPowerLevel = txPowerLevel;
        this.timeoutMillis = timeoutMillis;
    }

    private AdvertisingSetParameters(Parcel in) {
@@ -145,7 +142,6 @@ public final class AdvertisingSetParameters implements Parcelable {
        secondaryPhy = in.readInt();
        interval = in.readInt();
        txPowerLevel = in.readInt();
        timeoutMillis = in.readInt();
    }

    /**
@@ -188,11 +184,6 @@ public final class AdvertisingSetParameters implements Parcelable {
     */
    public int getTxPowerLevel() { return txPowerLevel; }

    /**
     * Returns the advertising time limit in milliseconds.
     */
    public int getTimeout() { return timeoutMillis; }

    @Override
    public String toString() {
        return "AdvertisingSetParameters [connectable=" + connectable
@@ -202,8 +193,7 @@ public final class AdvertisingSetParameters implements Parcelable {
             + ", primaryPhy=" + primaryPhy
             + ", secondaryPhy=" + secondaryPhy
             + ", interval=" + interval
             + ", txPowerLevel=" + txPowerLevel
             + ", timeoutMillis=" + timeoutMillis + "]";
             + ", txPowerLevel=" + txPowerLevel + "]";
    }

    @Override
@@ -221,7 +211,6 @@ public final class AdvertisingSetParameters implements Parcelable {
        dest.writeInt(secondaryPhy);
        dest.writeInt(interval);
        dest.writeInt(txPowerLevel);
        dest.writeInt(timeoutMillis);
    }

    public static final Parcelable.Creator<AdvertisingSetParameters> CREATOR =
@@ -250,7 +239,6 @@ public final class AdvertisingSetParameters implements Parcelable {
        private int secondaryPhy = PHY_LE_1M;
        private int interval = INTERVAL_LOW;
        private int txPowerLevel = TX_POWER_MEDIUM;
        private int timeoutMillis = 0;

        /**
         * Set whether the advertisement type should be connectable or
@@ -379,31 +367,13 @@ public final class AdvertisingSetParameters implements Parcelable {
            return this;
        }

        /**
         * Limit advertising to a given amount of time.
         * @param timeoutMillis Advertising time limit. May not exceed 180000
         * milliseconds. A value of 0 will disable the time limit.
         * @throws IllegalArgumentException If the provided timeout is over 180000
         * ms.
         */
        public Builder setTimeout(int timeoutMillis) {
            if (timeoutMillis < 0 || timeoutMillis > LIMITED_ADVERTISING_MAX_MILLIS) {
                throw new IllegalArgumentException("timeoutMillis invalid (must be 0-" +
                                                   LIMITED_ADVERTISING_MAX_MILLIS +
                                                   " milliseconds)");
            }
            this.timeoutMillis = timeoutMillis;
            return this;
        }

        /**
         * Build the {@link AdvertisingSetParameters} object.
         */
        public AdvertisingSetParameters build() {
            return new AdvertisingSetParameters(connectable, isLegacy, isAnonymous,
                                                includeTxPower, primaryPhy,
                                                secondaryPhy, interval, txPowerLevel,
                                                timeoutMillis);
                                                secondaryPhy, interval, txPowerLevel);
        }
    }
}
 No newline at end of file
+47 −5
Original line number Diff line number Diff line
@@ -130,7 +130,6 @@ public final class BluetoothLeAdvertiser {
            AdvertisingSetParameters.Builder parameters = new AdvertisingSetParameters.Builder();
            parameters.setLegacyMode(true);
            parameters.setConnectable(isConnectable);
            parameters.setTimeout(settings.getTimeout());
            if (settings.getMode() == AdvertiseSettings.ADVERTISE_MODE_LOW_POWER) {
                parameters.setInterval(1600); // 1s
            } else if (settings.getMode() == AdvertiseSettings.ADVERTISE_MODE_BALANCED) {
@@ -152,7 +151,7 @@ public final class BluetoothLeAdvertiser {
            AdvertisingSetCallback wrapped = wrapOldCallback(callback, settings);
            mLegacyAdvertisers.put(callback, wrapped);
            startAdvertisingSet(parameters.build(), advertiseData, scanResponse, null, null,
                                wrapped);
                                settings.getTimeout(), wrapped);
        }
    }

@@ -217,7 +216,7 @@ public final class BluetoothLeAdvertiser {
                                    PeriodicAdvertisingParameters periodicParameters,
                                    AdvertiseData periodicData, AdvertisingSetCallback callback) {
            startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
                            periodicData, callback, new Handler(Looper.getMainLooper()));
                            periodicData, 0, callback, new Handler(Looper.getMainLooper()));
    }

    /**
@@ -237,6 +236,49 @@ public final class BluetoothLeAdvertiser {
                                    PeriodicAdvertisingParameters periodicParameters,
                                    AdvertiseData periodicData, AdvertisingSetCallback callback,
                                    Handler handler) {
        startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
                            periodicData, 0, callback, handler);
    }

    /**
    * Creates a new advertising set. If operation succeed, device will start advertising. This
    * method returns immediately, the operation status is delivered through
    * {@code callback.onAdvertisingSetStarted()}.
    * <p>
    * @param parameters advertising set parameters.
    * @param advertiseData Advertisement data to be broadcasted.
    * @param scanResponse Scan response associated with the advertisement data.
    * @param periodicData Periodic advertising data.
    * @param timeoutMillis Advertising time limit. May not exceed 180000
    * @param callback Callback for advertising set.
    */
    public void startAdvertisingSet(AdvertisingSetParameters parameters,
                                    AdvertiseData advertiseData, AdvertiseData scanResponse,
                                    PeriodicAdvertisingParameters periodicParameters,
                                    AdvertiseData periodicData, int timeoutMillis,
                                    AdvertisingSetCallback callback) {
        startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
                            periodicData, timeoutMillis, callback, new Handler(Looper.getMainLooper()));
    }

    /**
    * Creates a new advertising set. If operation succeed, device will start advertising. This
    * method returns immediately, the operation status is delivered through
    * {@code callback.onAdvertisingSetStarted()}.
    * <p>
    * @param parameters advertising set parameters.
    * @param advertiseData Advertisement data to be broadcasted.
    * @param scanResponse Scan response associated with the advertisement data.
    * @param periodicData Periodic advertising data.
    * @param timeoutMillis Advertising time limit. May not exceed 180000
    * @param callback Callback for advertising set.
    * @param handler thread upon which the callbacks will be invoked.
    */
    public void startAdvertisingSet(AdvertisingSetParameters parameters,
                                    AdvertiseData advertiseData, AdvertiseData scanResponse,
                                    PeriodicAdvertisingParameters periodicParameters,
                                    AdvertiseData periodicData, int timeoutMillis,
                                    AdvertisingSetCallback callback, Handler handler) {
        BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);

        if (callback == null) {
@@ -259,7 +301,7 @@ public final class BluetoothLeAdvertiser {

        try {
            gatt.startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
                                     periodicData, wrapped);
                                     periodicData, timeoutMillis, wrapped);
        } catch (RemoteException e) {
          Log.e(TAG, "Failed to start advertising set - ", e);
          throw new IllegalStateException("Failed to start advertising set");