41

Samsung S8、Android 7.0 ( upd。これは Android 7.0: Samsung S7、Nexus 5x でも発生します) で、(いくつかのテストの後) アプリが頻繁にスキャンしていることを示す問題に気付きました。

08-14 12:44:20.693 25329-25329/com.my.app D/BluetoothAdapter: startLeScan(): null
08-14 12:44:20.695 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON
08-14 12:44:20.696 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON
08-14 12:44:20.698 25329-25329/com.my.app D/BluetoothLeScanner: Start Scan
08-14 12:44:20.699 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON
08-14 12:44:20.700 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON
08-14 12:44:20.700 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON
08-14 12:44:20.701 25329-25329/com.my.app D/BluetoothAdapter: STATE_ON
08-14 12:44:20.703 4079-4093/? D/BtGatt.GattService: registerClient() - UUID=dbaafee1-caf1-4482-9025-b712f000eeab
08-14 12:44:20.807 4079-4204/? D/BtGatt.GattService: onClientRegistered() - UUID=dbaafee1-caf1-4482-9025-b712f000eeab, clientIf=5, status=0
08-14 12:44:20.808 25329-25342/com.my.app D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5 mClientIf=0
08-14 12:44:20.809 4079-7185/? D/BtGatt.GattService: start scan with filters
08-14 12:44:20.811 4079-7185/? D/BtGatt.GattService: getScanSettings 
08-14 12:44:20.812 4079-7185/? D/BtGatt.GattService: Is it foreground application = true
08-14 12:44:20.812 4079-7185/? D/BtGatt.GattService: not a background application
08-14 12:44:20.817 4079-7185/? E/BtGatt.GattService: App 'com.my.app' is scanning too frequently

問題は間違いなくこれらの 6 つの STATE_ON 呼び出しの結果にあります。これは、DP4 リリース ノートで最初に言及された、文書化されていない BLE 動作の変更の一部です。

DP4 以降、BLE スキャンの動作を変更しました。アプリケーションによるスキャンの開始と停止が 30 秒間に 5 回を超えないようにします。実行時間の長いスキャンについては、日和見スキャンに変換します。

取得できないのは、設定しても30秒未満で6回のスキャンです: ScanSettings.setScanMode(ScanSettings.SCAN_MODE_OPPORTUNISTIC).

コードは次のとおりです。

List<ScanFilter> filters = new ArrayList<>();
ScanSettings scanSettings = new ScanSettings.Builder()
    .setScanMode(ScanSettings.SCAN_MODE_OPPORTUNISTIC)
    .build();
bluetoothAdapter.getBluetoothLeScanner().startScan(filters, scanSettings, recoderScanCallback);
//events from the log happen before this log is printed
Log.i("test", " started!");
return recoderScanCallback.scanResultObservable().map((ScanResult record) -> {
    //never gets here
    Log.i("test", " result!");
});

RecorderScanCallbackから導出されScanCallbackます。RxAndroidBle#rxBleClient.scanBleSettingsコードがフリーズしそうで、lib の 1.1.0 バージョンを使用しているため、(ScanSettings)を使用できません。

ScanSettings.setScanModeが検索結果を変更しないのはなぜですか?

4

1 に答える 1