mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Avoid crash when BLE Scan Service is enabled on zip restore
This commit is contained in:
+7
@@ -231,11 +231,18 @@ public class BLEScanService extends Service {
|
|||||||
private void startForeground() {
|
private void startForeground() {
|
||||||
Notification serviceNotification = createNotification(false, 0);
|
Notification serviceNotification = createNotification(false, 0);
|
||||||
|
|
||||||
|
try {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
ServiceCompat.startForeground(this, GB.NOTIFICATION_ID_SCAN, serviceNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE);
|
ServiceCompat.startForeground(this, GB.NOTIFICATION_ID_SCAN, serviceNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE);
|
||||||
} else {
|
} else {
|
||||||
ServiceCompat.startForeground(this, GB.NOTIFICATION_ID_SCAN, serviceNotification, 0);
|
ServiceCompat.startForeground(this, GB.NOTIFICATION_ID_SCAN, serviceNotification, 0);
|
||||||
}
|
}
|
||||||
|
} catch (final SecurityException e) {
|
||||||
|
// FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE will fail if the user has not granted the necessary permissions
|
||||||
|
// this can cause a crash on startup when restoring a zip with BLE scan service enabled
|
||||||
|
LOG.error("Failed to start foreground service", e);
|
||||||
|
updateNotification(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user