mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-05 05:55:27 +02:00
Device scan: Fix permission check on Android 11 and below (#3659)
Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/3659 Co-authored-by: Daniel Dakhno <dakhnod@gmail.com> Co-committed-by: Daniel Dakhno <dakhnod@gmail.com>
This commit is contained in:
parent
a37f0c89bb
commit
9502a0dcfb
@ -326,10 +326,20 @@ public class BLEScanService extends Service {
|
||||
unregisterReceiver(bluetoothStateChangedReceiver);
|
||||
}
|
||||
|
||||
private boolean hasBluetoothPermission(){
|
||||
if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.R){
|
||||
// workaround. Cannot give bluetooth permission on Android O
|
||||
LOG.warn("Running on android 11, skipping bluetooth permission check");
|
||||
return ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
return ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
private void restartScan(boolean applyFilters) {
|
||||
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
|
||||
if (!hasBluetoothPermission()) {
|
||||
// this should never happen
|
||||
LOG.error("No BLUETOOTH_SCAN permission");
|
||||
updateNotification("Missing Bluetooth scan permissions");
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user