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

Commit 72a69778 authored by Rahul Arya's avatar Rahul Arya Committed by Gerrit Code Review
Browse files

Merge changes from topic "ndm"

* changes:
  [Non-Discoverable Mode] Selectively hide Device Name characteristic
  [Non-Discoverable Mode] Store discoverable bit in security record
  [Non-Discoverable Mode] Add discoverable bit to advertiser config
  [Non-Discoverable Mode] Remove AdvertiserConfig
  [Non-Discoverable Mode] Hold ConnectComplete callback until local_address is known
  Fix uninitialized memory in controller
parents edcfbb25 5fc5174d
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -2134,6 +2134,8 @@ static AdvertiseParameters parseParams(JNIEnv* env, jobject i) {


  methodId = env->GetMethodID(clazz, "isConnectable", "()Z");
  methodId = env->GetMethodID(clazz, "isConnectable", "()Z");
  jboolean isConnectable = env->CallBooleanMethod(i, methodId);
  jboolean isConnectable = env->CallBooleanMethod(i, methodId);
  methodId = env->GetMethodID(clazz, "isDiscoverable", "()Z");
  jboolean isDiscoverable = env->CallBooleanMethod(i, methodId);
  methodId = env->GetMethodID(clazz, "isScannable", "()Z");
  methodId = env->GetMethodID(clazz, "isScannable", "()Z");
  jboolean isScannable = env->CallBooleanMethod(i, methodId);
  jboolean isScannable = env->CallBooleanMethod(i, methodId);
  methodId = env->GetMethodID(clazz, "isLegacy", "()Z");
  methodId = env->GetMethodID(clazz, "isLegacy", "()Z");
@@ -2156,6 +2158,7 @@ static AdvertiseParameters parseParams(JNIEnv* env, jobject i) {
  uint16_t props = 0;
  uint16_t props = 0;
  if (isConnectable) props |= 0x01;
  if (isConnectable) props |= 0x01;
  if (isScannable) props |= 0x02;
  if (isScannable) props |= 0x02;
  if (isDiscoverable) props |= 0x04;
  if (isLegacy) props |= 0x10;
  if (isLegacy) props |= 0x10;
  if (isAnonymous) props |= 0x20;
  if (isAnonymous) props |= 0x20;
  if (includeTxPower) props |= 0x40;
  if (includeTxPower) props |= 0x40;
+4 −0
Original line number Original line Diff line number Diff line
@@ -1121,6 +1121,7 @@ package android.bluetooth.le {
    method public int getTimeout();
    method public int getTimeout();
    method public int getTxPowerLevel();
    method public int getTxPowerLevel();
    method public boolean isConnectable();
    method public boolean isConnectable();
    method public boolean isDiscoverable();
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int ADVERTISE_MODE_BALANCED = 1; // 0x1
    field public static final int ADVERTISE_MODE_BALANCED = 1; // 0x1
    field public static final int ADVERTISE_MODE_LOW_LATENCY = 2; // 0x2
    field public static final int ADVERTISE_MODE_LOW_LATENCY = 2; // 0x2
@@ -1137,6 +1138,7 @@ package android.bluetooth.le {
    method public android.bluetooth.le.AdvertiseSettings build();
    method public android.bluetooth.le.AdvertiseSettings build();
    method public android.bluetooth.le.AdvertiseSettings.Builder setAdvertiseMode(int);
    method public android.bluetooth.le.AdvertiseSettings.Builder setAdvertiseMode(int);
    method public android.bluetooth.le.AdvertiseSettings.Builder setConnectable(boolean);
    method public android.bluetooth.le.AdvertiseSettings.Builder setConnectable(boolean);
    method @NonNull public android.bluetooth.le.AdvertiseSettings.Builder setDiscoverable(boolean);
    method public android.bluetooth.le.AdvertiseSettings.Builder setTimeout(int);
    method public android.bluetooth.le.AdvertiseSettings.Builder setTimeout(int);
    method public android.bluetooth.le.AdvertiseSettings.Builder setTxPowerLevel(int);
    method public android.bluetooth.le.AdvertiseSettings.Builder setTxPowerLevel(int);
  }
  }
@@ -1179,6 +1181,7 @@ package android.bluetooth.le {
    method public boolean includeTxPower();
    method public boolean includeTxPower();
    method public boolean isAnonymous();
    method public boolean isAnonymous();
    method public boolean isConnectable();
    method public boolean isConnectable();
    method public boolean isDiscoverable();
    method public boolean isLegacy();
    method public boolean isLegacy();
    method public boolean isScannable();
    method public boolean isScannable();
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
@@ -1201,6 +1204,7 @@ package android.bluetooth.le {
    method public android.bluetooth.le.AdvertisingSetParameters build();
    method public android.bluetooth.le.AdvertisingSetParameters build();
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setAnonymous(boolean);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setAnonymous(boolean);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setConnectable(boolean);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setConnectable(boolean);
    method @NonNull public android.bluetooth.le.AdvertisingSetParameters.Builder setDiscoverable(boolean);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setIncludeTxPower(boolean);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setIncludeTxPower(boolean);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setInterval(int);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setInterval(int);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setLegacyMode(boolean);
    method public android.bluetooth.le.AdvertisingSetParameters.Builder setLegacyMode(boolean);
+35 −4
Original line number Original line Diff line number Diff line
@@ -78,14 +78,20 @@ public final class AdvertiseSettings implements Parcelable {
    private final int mAdvertiseTxPowerLevel;
    private final int mAdvertiseTxPowerLevel;
    private final int mAdvertiseTimeoutMillis;
    private final int mAdvertiseTimeoutMillis;
    private final boolean mAdvertiseConnectable;
    private final boolean mAdvertiseConnectable;
    private final boolean mAdvertiseDiscoverable;
    private final int mOwnAddressType;
    private final int mOwnAddressType;


    private AdvertiseSettings(int advertiseMode, int advertiseTxPowerLevel,
    private AdvertiseSettings(
            boolean advertiseConnectable, int advertiseTimeout,
            int advertiseMode,
            int advertiseTxPowerLevel,
            boolean advertiseConnectable,
            boolean discoverable,
            int advertiseTimeout,
            @AddressTypeStatus int ownAddressType) {
            @AddressTypeStatus int ownAddressType) {
        mAdvertiseMode = advertiseMode;
        mAdvertiseMode = advertiseMode;
        mAdvertiseTxPowerLevel = advertiseTxPowerLevel;
        mAdvertiseTxPowerLevel = advertiseTxPowerLevel;
        mAdvertiseConnectable = advertiseConnectable;
        mAdvertiseConnectable = advertiseConnectable;
        mAdvertiseDiscoverable = discoverable;
        mAdvertiseTimeoutMillis = advertiseTimeout;
        mAdvertiseTimeoutMillis = advertiseTimeout;
        mOwnAddressType = ownAddressType;
        mOwnAddressType = ownAddressType;
    }
    }
@@ -96,6 +102,7 @@ public final class AdvertiseSettings implements Parcelable {
        mAdvertiseConnectable = in.readInt() != 0;
        mAdvertiseConnectable = in.readInt() != 0;
        mAdvertiseTimeoutMillis = in.readInt();
        mAdvertiseTimeoutMillis = in.readInt();
        mOwnAddressType = in.readInt();
        mOwnAddressType = in.readInt();
        mAdvertiseDiscoverable = in.readInt() != 0;
    }
    }


    /**
    /**
@@ -119,6 +126,11 @@ public final class AdvertiseSettings implements Parcelable {
        return mAdvertiseConnectable;
        return mAdvertiseConnectable;
    }
    }


    /** Returns whether the advertisement will be discoverable. */
    public boolean isDiscoverable() {
        return mAdvertiseDiscoverable;
    }

    /**
    /**
     * Returns the advertising time limit in milliseconds.
     * Returns the advertising time limit in milliseconds.
     */
     */
@@ -141,6 +153,7 @@ public final class AdvertiseSettings implements Parcelable {
        return "Settings [mAdvertiseMode=" + mAdvertiseMode
        return "Settings [mAdvertiseMode=" + mAdvertiseMode
                + ", mAdvertiseTxPowerLevel=" + mAdvertiseTxPowerLevel
                + ", mAdvertiseTxPowerLevel=" + mAdvertiseTxPowerLevel
                + ", mAdvertiseConnectable=" + mAdvertiseConnectable
                + ", mAdvertiseConnectable=" + mAdvertiseConnectable
                + ", mAdvertiseDiscoverable=" + mAdvertiseDiscoverable
                + ", mAdvertiseTimeoutMillis=" + mAdvertiseTimeoutMillis
                + ", mAdvertiseTimeoutMillis=" + mAdvertiseTimeoutMillis
                + ", mOwnAddressType=" + mOwnAddressType + "]";
                + ", mOwnAddressType=" + mOwnAddressType + "]";
    }
    }
@@ -157,6 +170,7 @@ public final class AdvertiseSettings implements Parcelable {
        dest.writeInt(mAdvertiseConnectable ? 1 : 0);
        dest.writeInt(mAdvertiseConnectable ? 1 : 0);
        dest.writeInt(mAdvertiseTimeoutMillis);
        dest.writeInt(mAdvertiseTimeoutMillis);
        dest.writeInt(mOwnAddressType);
        dest.writeInt(mOwnAddressType);
        dest.writeInt(mAdvertiseDiscoverable ? 1 : 0);
    }
    }


    public static final @android.annotation.NonNull Parcelable.Creator<AdvertiseSettings> CREATOR =
    public static final @android.annotation.NonNull Parcelable.Creator<AdvertiseSettings> CREATOR =
@@ -180,6 +194,7 @@ public final class AdvertiseSettings implements Parcelable {
        private int mTxPowerLevel = ADVERTISE_TX_POWER_MEDIUM;
        private int mTxPowerLevel = ADVERTISE_TX_POWER_MEDIUM;
        private int mTimeoutMillis = 0;
        private int mTimeoutMillis = 0;
        private boolean mConnectable = true;
        private boolean mConnectable = true;
        private boolean mDiscoverable = true;
        private int mOwnAddressType = AdvertisingSetParameters.ADDRESS_TYPE_DEFAULT;
        private int mOwnAddressType = AdvertisingSetParameters.ADDRESS_TYPE_DEFAULT;


        /**
        /**
@@ -230,6 +245,17 @@ public final class AdvertiseSettings implements Parcelable {
            return this;
            return this;
        }
        }


        /**
         * Set whether the advertisement type should be discoverable or non-discoverable.
         *
         * @param discoverable Controls whether the advertisment type will be discoverable
         * ({@code true}) or non-discoverable ({@code false}).
         */
        public @NonNull Builder setDiscoverable(boolean discoverable) {
            mDiscoverable = discoverable;
            return this;
        }

        /**
        /**
         * Limit advertising to a given amount of time.
         * Limit advertising to a given amount of time.
         *
         *
@@ -270,7 +296,12 @@ public final class AdvertiseSettings implements Parcelable {
         * Build the {@link AdvertiseSettings} object.
         * Build the {@link AdvertiseSettings} object.
         */
         */
        public AdvertiseSettings build() {
        public AdvertiseSettings build() {
            return new AdvertiseSettings(mMode, mTxPowerLevel, mConnectable, mTimeoutMillis,
            return new AdvertiseSettings(
                    mMode,
                    mTxPowerLevel,
                    mConnectable,
                    mDiscoverable,
                    mTimeoutMillis,
                    mOwnAddressType);
                    mOwnAddressType);
        }
        }
    }
    }
+49 −6
Original line number Original line Diff line number Diff line
@@ -142,16 +142,26 @@ public final class AdvertisingSetParameters implements Parcelable {
    private final int mPrimaryPhy;
    private final int mPrimaryPhy;
    private final int mSecondaryPhy;
    private final int mSecondaryPhy;
    private final boolean mConnectable;
    private final boolean mConnectable;
    private final boolean mDiscoverable;
    private final boolean mScannable;
    private final boolean mScannable;
    private final int mInterval;
    private final int mInterval;
    private final int mTxPowerLevel;
    private final int mTxPowerLevel;
    private final int mOwnAddressType;
    private final int mOwnAddressType;


    private AdvertisingSetParameters(boolean connectable, boolean scannable, boolean isLegacy,
    private AdvertisingSetParameters(
            boolean isAnonymous, boolean includeTxPower,
            boolean connectable,
            int primaryPhy, int secondaryPhy,
            boolean discoverable,
            int interval, int txPowerLevel, @AddressTypeStatus int ownAddressType) {
            boolean scannable,
            boolean isLegacy,
            boolean isAnonymous,
            boolean includeTxPower,
            int primaryPhy,
            int secondaryPhy,
            int interval,
            int txPowerLevel,
            @AddressTypeStatus int ownAddressType) {
        mConnectable = connectable;
        mConnectable = connectable;
        mDiscoverable = discoverable;
        mScannable = scannable;
        mScannable = scannable;
        mIsLegacy = isLegacy;
        mIsLegacy = isLegacy;
        mIsAnonymous = isAnonymous;
        mIsAnonymous = isAnonymous;
@@ -174,6 +184,7 @@ public final class AdvertisingSetParameters implements Parcelable {
        mInterval = in.readInt();
        mInterval = in.readInt();
        mTxPowerLevel = in.readInt();
        mTxPowerLevel = in.readInt();
        mOwnAddressType = in.readInt();
        mOwnAddressType = in.readInt();
        mDiscoverable = in.readInt() != 0;
    }
    }


    /**
    /**
@@ -183,6 +194,13 @@ public final class AdvertisingSetParameters implements Parcelable {
        return mConnectable;
        return mConnectable;
    }
    }


    /**
     * Returns whether the advertisement will be discoverable.
     */
    public boolean isDiscoverable() {
        return mDiscoverable;
    }

    /**
    /**
     * Returns whether the advertisement will be scannable.
     * Returns whether the advertisement will be scannable.
     */
     */
@@ -252,6 +270,7 @@ public final class AdvertisingSetParameters implements Parcelable {
    @Override
    @Override
    public String toString() {
    public String toString() {
        return "AdvertisingSetParameters [connectable=" + mConnectable
        return "AdvertisingSetParameters [connectable=" + mConnectable
                + ", discoverable=" + mDiscoverable
                + ", isLegacy=" + mIsLegacy
                + ", isLegacy=" + mIsLegacy
                + ", isAnonymous=" + mIsAnonymous
                + ", isAnonymous=" + mIsAnonymous
                + ", includeTxPower=" + mIncludeTxPower
                + ", includeTxPower=" + mIncludeTxPower
@@ -279,6 +298,7 @@ public final class AdvertisingSetParameters implements Parcelable {
        dest.writeInt(mInterval);
        dest.writeInt(mInterval);
        dest.writeInt(mTxPowerLevel);
        dest.writeInt(mTxPowerLevel);
        dest.writeInt(mOwnAddressType);
        dest.writeInt(mOwnAddressType);
        dest.writeInt(mDiscoverable ? 1 : 0);
    }
    }


    public static final @android.annotation.NonNull Parcelable.Creator<AdvertisingSetParameters> CREATOR =
    public static final @android.annotation.NonNull Parcelable.Creator<AdvertisingSetParameters> CREATOR =
@@ -299,6 +319,7 @@ public final class AdvertisingSetParameters implements Parcelable {
     */
     */
    public static final class Builder {
    public static final class Builder {
        private boolean mConnectable = false;
        private boolean mConnectable = false;
        private boolean mDiscoverable = true;
        private boolean mScannable = false;
        private boolean mScannable = false;
        private boolean mIsLegacy = false;
        private boolean mIsLegacy = false;
        private boolean mIsAnonymous = false;
        private boolean mIsAnonymous = false;
@@ -323,6 +344,19 @@ public final class AdvertisingSetParameters implements Parcelable {
            return this;
            return this;
        }
        }


        /**
         * Set whether the advertisement type should be discoverable or non-discoverable. By
         * default, advertisements will be discoverable. Devices connecting to non-discoverable
         * advertisements cannot initiate bonding.
         *
         * @param discoverable Controls whether the advertisement type will be discoverable
         * ({@code true}) or non-discoverable ({@code false}).
         */
        public @NonNull Builder setDiscoverable(boolean discoverable) {
            mDiscoverable = discoverable;
            return this;
        }

        /**
        /**
         * Set whether the advertisement type should be scannable.
         * Set whether the advertisement type should be scannable.
         * Legacy advertisements can be both connectable and scannable. Non-legacy
         * Legacy advertisements can be both connectable and scannable. Non-legacy
@@ -505,8 +539,17 @@ public final class AdvertisingSetParameters implements Parcelable {
                }
                }
            }
            }


            return new AdvertisingSetParameters(mConnectable, mScannable, mIsLegacy, mIsAnonymous,
            return new AdvertisingSetParameters(
                    mIncludeTxPower, mPrimaryPhy, mSecondaryPhy, mInterval, mTxPowerLevel,
                    mConnectable,
                    mDiscoverable,
                    mScannable,
                    mIsLegacy,
                    mIsAnonymous,
                    mIncludeTxPower,
                    mPrimaryPhy,
                    mSecondaryPhy,
                    mInterval,
                    mTxPowerLevel,
                    mOwnAddressType);
                    mOwnAddressType);
        }
        }
    }
    }
+8 −3
Original line number Original line Diff line number Diff line
@@ -129,7 +129,9 @@ public final class BluetoothLeAdvertiser {
                throw new IllegalArgumentException("callback cannot be null");
                throw new IllegalArgumentException("callback cannot be null");
            }
            }
            boolean isConnectable = settings.isConnectable();
            boolean isConnectable = settings.isConnectable();
            if (totalBytes(advertiseData, isConnectable) > MAX_LEGACY_ADVERTISING_DATA_BYTES
            boolean isDiscoverable = settings.isDiscoverable();
            boolean hasFlags = isConnectable && isDiscoverable;
            if (totalBytes(advertiseData, hasFlags) > MAX_LEGACY_ADVERTISING_DATA_BYTES
                    || totalBytes(scanResponse, false) > MAX_LEGACY_ADVERTISING_DATA_BYTES) {
                    || totalBytes(scanResponse, false) > MAX_LEGACY_ADVERTISING_DATA_BYTES) {
                postStartFailure(callback, AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE);
                postStartFailure(callback, AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE);
                return;
                return;
@@ -142,6 +144,7 @@ public final class BluetoothLeAdvertiser {
            AdvertisingSetParameters.Builder parameters = new AdvertisingSetParameters.Builder();
            AdvertisingSetParameters.Builder parameters = new AdvertisingSetParameters.Builder();
            parameters.setLegacyMode(true);
            parameters.setLegacyMode(true);
            parameters.setConnectable(isConnectable);
            parameters.setConnectable(isConnectable);
            parameters.setDiscoverable(isDiscoverable);
            parameters.setScannable(true); // legacy advertisements we support are always scannable
            parameters.setScannable(true); // legacy advertisements we support are always scannable
            parameters.setOwnAddressType(settings.getOwnAddressType());
            parameters.setOwnAddressType(settings.getOwnAddressType());
            if (settings.getMode() == AdvertiseSettings.ADVERTISE_MODE_LOW_POWER) {
            if (settings.getMode() == AdvertiseSettings.ADVERTISE_MODE_LOW_POWER) {
@@ -381,8 +384,10 @@ public final class BluetoothLeAdvertiser {
        }
        }


        boolean isConnectable = parameters.isConnectable();
        boolean isConnectable = parameters.isConnectable();
        boolean isDiscoverable = parameters.isDiscoverable();
        boolean hasFlags = isConnectable && isDiscoverable;
        if (parameters.isLegacy()) {
        if (parameters.isLegacy()) {
            if (totalBytes(advertiseData, isConnectable) > MAX_LEGACY_ADVERTISING_DATA_BYTES) {
            if (totalBytes(advertiseData, hasFlags) > MAX_LEGACY_ADVERTISING_DATA_BYTES) {
                throw new IllegalArgumentException("Legacy advertising data too big");
                throw new IllegalArgumentException("Legacy advertising data too big");
            }
            }


@@ -404,7 +409,7 @@ public final class BluetoothLeAdvertiser {
            }
            }


            int maxData = mBluetoothAdapter.getLeMaximumAdvertisingDataLength();
            int maxData = mBluetoothAdapter.getLeMaximumAdvertisingDataLength();
            if (totalBytes(advertiseData, isConnectable) > maxData) {
            if (totalBytes(advertiseData, hasFlags) > maxData) {
                throw new IllegalArgumentException("Advertising data too big");
                throw new IllegalArgumentException("Advertising data too big");
            }
            }


Loading