Skip to content

Commit

Permalink
Add advertisingSid property to ScanResult
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofMamak committed Jul 22, 2024
1 parent e35ae86 commit f1d6582
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 11 deletions.
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 sid.
*/
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;
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) {
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
+ '}';
}
}

0 comments on commit f1d6582

Please sign in to comment.