BLEScanService: Allow supported ScanSettings on Android API level 23

This commit is contained in:
Andreas Shimokawa 2024-03-25 10:34:44 +01:00
parent cbc9bb4e11
commit 7fe619c976
1 changed files with 24 additions and 3 deletions

View File

@ -1,3 +1,20 @@
/* Copyright (C) 2024 Daniel Dakhno, José Rebelo, Andreas Shimokawa
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.btle;
import android.Manifest;
@ -17,6 +34,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
@ -357,11 +375,14 @@ public class BLEScanService extends Service {
final ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER); // enforced anyway in background
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
scanSettingsBuilder
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setMatchMode(ScanSettings.MATCH_MODE_STICKY)
.setLegacy(false);
.setMatchMode(ScanSettings.MATCH_MODE_STICKY);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
scanSettingsBuilder.setLegacy(false);
}
scanner.startScan(scanFilters, scanSettingsBuilder.build(), scanCallback);