Merge "Add setScannable to AdvertisingSetParameters (1/2)" am: 7f14b8f095

am: 8d06b41826

Change-Id: I8cc220bd494841841f89eeba840ce71b1c2a0692
This commit is contained in:
Jakub Pawlowski
2017-03-21 18:52:03 +00:00
committed by android-build-merger
5 changed files with 31 additions and 2 deletions

View File

@@ -7544,6 +7544,7 @@ package android.bluetooth.le {
method public boolean isAnonymous();
method public boolean isConnectable();
method public boolean isLegacy();
method public boolean isScannable();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.bluetooth.le.AdvertisingSetParameters> CREATOR;
field public static final int INTERVAL_HIGH = 160; // 0xa0
@@ -7571,6 +7572,7 @@ package android.bluetooth.le {
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 setPrimaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setScannable(boolean);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
}

View File

@@ -7848,6 +7848,7 @@ package android.bluetooth.le {
method public boolean isAnonymous();
method public boolean isConnectable();
method public boolean isLegacy();
method public boolean isScannable();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.bluetooth.le.AdvertisingSetParameters> CREATOR;
field public static final int INTERVAL_HIGH = 160; // 0xa0
@@ -7875,6 +7876,7 @@ package android.bluetooth.le {
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 setPrimaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setScannable(boolean);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
}

View File

@@ -7553,6 +7553,7 @@ package android.bluetooth.le {
method public boolean isAnonymous();
method public boolean isConnectable();
method public boolean isLegacy();
method public boolean isScannable();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.bluetooth.le.AdvertisingSetParameters> CREATOR;
field public static final int INTERVAL_HIGH = 160; // 0xa0
@@ -7580,6 +7581,7 @@ package android.bluetooth.le {
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 setPrimaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setScannable(boolean);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
}

View File

@@ -116,14 +116,16 @@ public final class AdvertisingSetParameters implements Parcelable {
private final int primaryPhy;
private final int secondaryPhy;
private final boolean connectable;
private final boolean scannable;
private final int interval;
private final int txPowerLevel;
private AdvertisingSetParameters(boolean connectable, boolean isLegacy,
private AdvertisingSetParameters(boolean connectable, boolean scannable, boolean isLegacy,
boolean isAnonymous, boolean includeTxPower,
int primaryPhy, int secondaryPhy,
int interval, int txPowerLevel) {
this.connectable = connectable;
this.scannable = scannable;
this.isLegacy = isLegacy;
this.isAnonymous = isAnonymous;
this.includeTxPower = includeTxPower;
@@ -135,6 +137,7 @@ public final class AdvertisingSetParameters implements Parcelable {
private AdvertisingSetParameters(Parcel in) {
connectable = in.readInt() != 0 ? true : false;
scannable = in.readInt() != 0 ? true : false;
isLegacy = in.readInt() != 0 ? true : false;
isAnonymous = in.readInt() != 0 ? true : false;
includeTxPower = in.readInt() != 0 ? true : false;
@@ -149,6 +152,11 @@ public final class AdvertisingSetParameters implements Parcelable {
*/
public boolean isConnectable() { return connectable; }
/**
* Returns whether the advertisement will be scannable.
*/
public boolean isScannable() { return scannable; }
/**
* Returns whether the legacy advertisement will be used.
*/
@@ -204,6 +212,7 @@ public final class AdvertisingSetParameters implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(connectable ? 1 : 0);
dest.writeInt(scannable ? 1 : 0);
dest.writeInt(isLegacy ? 1 : 0);
dest.writeInt(isAnonymous ? 1 : 0);
dest.writeInt(includeTxPower ? 1 : 0);
@@ -232,6 +241,7 @@ public final class AdvertisingSetParameters implements Parcelable {
public static final class Builder {
private boolean connectable = true;
private boolean scannable = true;
private boolean isLegacy = false;
private boolean isAnonymous = false;
private boolean includeTxPower = false;
@@ -253,6 +263,18 @@ public final class AdvertisingSetParameters implements Parcelable {
return this;
}
/**
* Set whether the advertisement type should be scannable
* Legacy advertisements can be both connectable and scannable. Other
* advertisements can be scannable only if not connectable.
* @param scannable Controls whether the advertisment type will be
* scannable (true) or non-scannable (false).
*/
public Builder setScannable(boolean scannable) {
this.scannable = scannable;
return this;
}
/**
* When set to true, advertising set will advertise 4.x Spec compliant
* advertisements.
@@ -371,7 +393,7 @@ public final class AdvertisingSetParameters implements Parcelable {
* Build the {@link AdvertisingSetParameters} object.
*/
public AdvertisingSetParameters build() {
return new AdvertisingSetParameters(connectable, isLegacy, isAnonymous,
return new AdvertisingSetParameters(connectable, scannable, isLegacy, isAnonymous,
includeTxPower, primaryPhy,
secondaryPhy, interval, txPowerLevel);
}

View File

@@ -130,6 +130,7 @@ public final class BluetoothLeAdvertiser {
AdvertisingSetParameters.Builder parameters = new AdvertisingSetParameters.Builder();
parameters.setLegacyMode(true);
parameters.setConnectable(isConnectable);
parameters.setScannable(true); // legacy advertisements we support are always scannable
if (settings.getMode() == AdvertiseSettings.ADVERTISE_MODE_LOW_POWER) {
parameters.setInterval(1600); // 1s
} else if (settings.getMode() == AdvertiseSettings.ADVERTISE_MODE_BALANCED) {