Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add advertisingSid property to ScanResult #856

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ private static RxBleScanResultMock convertToPublicScanResult(RxBleDevice bleDevi
System.currentTimeMillis() * 1000000,
ScanCallbackType.CALLBACK_TYPE_FIRST_MATCH,
scanRecord,
IsConnectable.LEGACY_UNKNOWN
IsConnectable.LEGACY_UNKNOWN,
255
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
public class RxBleScanResultMock extends ScanResult implements ScanResultInterface {
public RxBleScanResultMock(RxBleDevice bleDevice, int rssi, long timestampNanos,
ScanCallbackType callbackType, ScanRecord scanRecord,
IsConnectable isConnectable) {
super(bleDevice, rssi, timestampNanos, callbackType, scanRecord, isConnectable);
IsConnectable isConnectable, Integer advertisingSid) {
super(bleDevice, rssi, timestampNanos, callbackType, scanRecord, isConnectable, advertisingSid);
}

public String getAddress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ public interface ScanResultInterface {
* Get the type of scan callback
*/
ScanCallbackType getScanCallbackType();

/**
* Get the advertising set id
*/
Integer getAdvertisingSid();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.os.Build;

import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
Expand Down Expand Up @@ -36,21 +37,23 @@ public InternalScanResultCreator(ScanRecordParser scanRecordParser, IsConnectabl
public RxBleInternalScanResult create(BluetoothDevice bluetoothDevice, int rssi, byte[] scanRecord) {
final ScanRecord scanRecordObj = scanRecordParser.parseFromBytes(scanRecord);
return new RxBleInternalScanResult(bluetoothDevice, rssi, System.nanoTime(), scanRecordObj,
ScanCallbackType.CALLBACK_TYPE_UNSPECIFIED, IsConnectable.LEGACY_UNKNOWN);
ScanCallbackType.CALLBACK_TYPE_UNSPECIFIED, IsConnectable.LEGACY_UNKNOWN, null);
}

@RequiresApi(21 /* Build.VERSION_CODES.LOLLIPOP */)
public RxBleInternalScanResult create(ScanResult result) {
final ScanRecordImplNativeWrapper scanRecord = new ScanRecordImplNativeWrapper(result.getScanRecord(), scanRecordParser);
final Integer advertisingSid = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? result.getAdvertisingSid() : null;
return new RxBleInternalScanResult(result.getDevice(), result.getRssi(), result.getTimestampNanos(), scanRecord,
ScanCallbackType.CALLBACK_TYPE_BATCH, isConnectableChecker.check(result));
ScanCallbackType.CALLBACK_TYPE_BATCH, isConnectableChecker.check(result), advertisingSid);
}

@RequiresApi(21 /* Build.VERSION_CODES.LOLLIPOP */)
public RxBleInternalScanResult create(int callbackType, ScanResult result) {
final ScanRecordImplNativeWrapper scanRecord = new ScanRecordImplNativeWrapper(result.getScanRecord(), scanRecordParser);
final Integer advertisingSid = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? result.getAdvertisingSid() : null;
KrzysztofMamak marked this conversation as resolved.
Show resolved Hide resolved
return new RxBleInternalScanResult(result.getDevice(), result.getRssi(), result.getTimestampNanos(), scanRecord,
toScanCallbackType(callbackType), isConnectableChecker.check(result));
toScanCallbackType(callbackType), isConnectableChecker.check(result), advertisingSid);
}

@RequiresApi(21 /* Build.VERSION_CODES.LOLLIPOP */)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public ScanResult apply(RxBleInternalScanResult rxBleInternalScanResult) {
rxBleInternalScanResult.getTimestampNanos(),
rxBleInternalScanResult.getScanCallbackType(),
rxBleInternalScanResult.getScanRecord(),
rxBleInternalScanResult.isConnectable()
rxBleInternalScanResult.isConnectable(),
rxBleInternalScanResult.getAdvertisingSid()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ public class RxBleInternalScanResult implements ScanResultInterface {
private final ScanRecord scanRecord;
private final ScanCallbackType scanCallbackType;
private final IsConnectable isConnectable;
private final Integer advertisingSid;

public RxBleInternalScanResult(BluetoothDevice bluetoothDevice, int rssi, long timestampNanos, ScanRecord scanRecord,
ScanCallbackType scanCallbackType, IsConnectable isConnectable) {
ScanCallbackType scanCallbackType, IsConnectable isConnectable, Integer advertisingSid) {
this.bluetoothDevice = bluetoothDevice;
this.rssi = rssi;
this.timestampNanos = timestampNanos;
this.scanRecord = scanRecord;
this.scanCallbackType = scanCallbackType;
this.isConnectable = isConnectable;
this.advertisingSid = advertisingSid;
}

public BluetoothDevice getBluetoothDevice() {
Expand Down Expand Up @@ -64,4 +66,9 @@ public String getDeviceName() {
public IsConnectable isConnectable() {
return isConnectable;
}

@Override
public Integer getAdvertisingSid() {
return advertisingSid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public RxBleInternalScanResult apply(RxBleInternalScanResult rxBleInternalScanRe
rxBleInternalScanResult.getTimestampNanos(),
rxBleInternalScanResult.getScanRecord(),
ScanCallbackType.CALLBACK_TYPE_FIRST_MATCH,
rxBleInternalScanResult.isConnectable()
rxBleInternalScanResult.isConnectable(),
rxBleInternalScanResult.getAdvertisingSid()
);
}
};
Expand All @@ -195,7 +196,8 @@ public RxBleInternalScanResult apply(RxBleInternalScanResult rxBleInternalScanRe
rxBleInternalScanResult.getTimestampNanos(),
rxBleInternalScanResult.getScanRecord(),
ScanCallbackType.CALLBACK_TYPE_MATCH_LOST,
rxBleInternalScanResult.isConnectable()
rxBleInternalScanResult.isConnectable(),
rxBleInternalScanResult.getAdvertisingSid()
);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ public class ScanResult {
private final ScanCallbackType callbackType;
private final ScanRecord scanRecord;
private final IsConnectable isConnectable;
private final Integer advertisingSid;

public ScanResult(RxBleDevice bleDevice, int rssi, long timestampNanos, ScanCallbackType callbackType,
ScanRecord scanRecord, IsConnectable isConnectable) {
ScanRecord scanRecord, IsConnectable isConnectable, Integer advertisingSid) {
KrzysztofMamak marked this conversation as resolved.
Show resolved Hide resolved
this.bleDevice = bleDevice;
this.rssi = rssi;
this.timestampNanos = timestampNanos;
this.callbackType = callbackType;
this.scanRecord = scanRecord;
this.isConnectable = isConnectable;
this.advertisingSid = advertisingSid;
}

public RxBleDevice getBleDevice() {
Expand All @@ -48,6 +50,10 @@ public IsConnectable isConnectable() {
return isConnectable;
}

public Integer getAdvertisingSid() {
return advertisingSid;
}

@Override
@NonNull
public String toString() {
Expand All @@ -58,6 +64,7 @@ public String toString() {
+ ", callbackType=" + callbackType
+ ", scanRecord=" + LoggerUtil.bytesToHex(scanRecord.getBytes())
+ ", isConnectable=" + isConnectable
+ ", advertisingSid=" + advertisingSid
+ '}';
}
}