Skip to content

Commit

Permalink
Android: support legacy only scan
Browse files Browse the repository at this point in the history
  • Loading branch information
jasaw authored and chipweinberger committed Jul 19, 2024
1 parent 0d439a9 commit d5854d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ public void onMethodCall(@NonNull MethodCall call,
List<Object> withMsd = (List<Object>) data.get("with_msd");
List<Object> withServiceData = (List<Object>) data.get("with_service_data");
boolean continuousUpdates = (boolean) data.get("continuous_updates");
boolean legacyOnly = (boolean) data.get("legacy_only");
int androidScanMode = (int) data.get("android_scan_mode");
boolean androidUsesFineLocation = (boolean) data.get("android_uses_fine_location");

Expand Down Expand Up @@ -515,7 +516,7 @@ public void onMethodCall(@NonNull MethodCall call,
builder.setScanMode(androidScanMode);
if (Build.VERSION.SDK_INT >= 26) { // Android 8.0 (August 2017)
builder.setPhy(ScanSettings.PHY_LE_ALL_SUPPORTED);
builder.setLegacy(false);
builder.setLegacy(legacyOnly);
}
ScanSettings settings = builder.build();

Expand Down
3 changes: 3 additions & 0 deletions lib/src/bluetooth_msgs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class BmScanSettings {
final List<BmServiceDataFilter> withServiceData;
final bool continuousUpdates;
final int continuousDivisor;
final bool legacyOnly;
final int androidScanMode;
final bool androidUsesFineLocation;

Expand All @@ -77,6 +78,7 @@ class BmScanSettings {
required this.withServiceData,
required this.continuousUpdates,
required this.continuousDivisor,
required this.legacyOnly,
required this.androidScanMode,
required this.androidUsesFineLocation,
});
Expand All @@ -91,6 +93,7 @@ class BmScanSettings {
data['with_service_data'] = withServiceData.map((d) => d.toMap()).toList();
data['continuous_updates'] = continuousUpdates;
data['continuous_divisor'] = continuousDivisor;
data['legacy_only'] = legacyOnly;
data['android_scan_mode'] = androidScanMode;
data['android_uses_fine_location'] = androidUsesFineLocation;
return data;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/flutter_blue_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class FlutterBluePlus {
/// If divisor is 1, all advertisements are returned. This argument only matters for `continuousUpdates` mode.
/// - [oneByOne] if `true`, we will stream every advertistment one by one, possibly including duplicates.
/// If `false`, we deduplicate the advertisements, and return a list of devices.
/// - [legacyOnly] Android only. If `true`, scan on 1M phy only.
/// If `false`, scan on all supported phys. How the radio cycles through all the supported phys is purely
/// dependent on the your Bluetooth stack implementation.
/// - [androidScanMode] choose the android scan mode to use when scanning
/// - [androidUsesFineLocation] request `ACCESS_FINE_LOCATION` permission at runtime
static Future<void> startScan({
Expand All @@ -224,6 +227,7 @@ class FlutterBluePlus {
bool continuousUpdates = false,
int continuousDivisor = 1,
bool oneByOne = false,
bool legacyOnly = false,
AndroidScanMode androidScanMode = AndroidScanMode.lowLatency,
bool androidUsesFineLocation = false,
}) async {
Expand Down Expand Up @@ -268,6 +272,7 @@ class FlutterBluePlus {
withServiceData: withServiceData.map((d) => d._bm).toList(),
continuousUpdates: continuousUpdates,
continuousDivisor: continuousDivisor,
legacyOnly: legacyOnly,
androidScanMode: androidScanMode.value,
androidUsesFineLocation: androidUsesFineLocation);

Expand Down

0 comments on commit d5854d1

Please sign in to comment.