diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 41b19503..1284be0f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -15,6 +15,7 @@
+
+
= Build.VERSION_CODES.N) {
diff --git a/app/src/main/java/info/zamojski/soft/towercollector/uploader/UploaderWorker.java b/app/src/main/java/info/zamojski/soft/towercollector/uploader/UploaderWorker.java
index 7339fdfa..4ebc89ae 100644
--- a/app/src/main/java/info/zamojski/soft/towercollector/uploader/UploaderWorker.java
+++ b/app/src/main/java/info/zamojski/soft/towercollector/uploader/UploaderWorker.java
@@ -7,6 +7,7 @@
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
+import android.content.pm.ServiceInfo;
import android.os.Build;
import androidx.annotation.NonNull;
@@ -23,7 +24,6 @@
import java.util.List;
import java.util.Map;
-import info.zamojski.soft.towercollector.BuildConfig;
import info.zamojski.soft.towercollector.MyApplication;
import info.zamojski.soft.towercollector.R;
import info.zamojski.soft.towercollector.UploaderQuickSettingsTileService;
@@ -47,6 +47,7 @@
import info.zamojski.soft.towercollector.utils.ApkUtils;
import info.zamojski.soft.towercollector.utils.NetworkUtils;
import info.zamojski.soft.towercollector.utils.OpenCellIdUtils;
+import info.zamojski.soft.towercollector.utils.PermissionUtils;
import timber.log.Timber;
public class UploaderWorker extends Worker implements IProgressListener {
@@ -105,7 +106,12 @@ public UploaderWorker(@NonNull Context context, @NonNull WorkerParameters worker
public Result doWork() {
try {
Notification notification = notificationHelper.createNotification(notificationManager);
- ForegroundInfo foregroundInfo = new ForegroundInfo(NOTIFICATION_ID, notification);
+ ForegroundInfo foregroundInfo;
+ if (PermissionUtils.isForegroundServicePermissionAware()) {
+ foregroundInfo = new ForegroundInfo(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
+ } else {
+ foregroundInfo = new ForegroundInfo(NOTIFICATION_ID, notification);
+ }
setForegroundAsync(foregroundInfo);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
diff --git a/app/src/main/java/info/zamojski/soft/towercollector/utils/PermissionUtils.java b/app/src/main/java/info/zamojski/soft/towercollector/utils/PermissionUtils.java
index b2eb9ccf..e49c8412 100644
--- a/app/src/main/java/info/zamojski/soft/towercollector/utils/PermissionUtils.java
+++ b/app/src/main/java/info/zamojski/soft/towercollector/utils/PermissionUtils.java
@@ -45,6 +45,10 @@ public static boolean isNotificationPermissionRequired() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
}
+ public static boolean isForegroundServicePermissionAware() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; // TODO: should be Build.VERSION_CODES.UPSIDE_DOWN_CAKE but I recall there were issues on Android 12 as well
+ }
+
public static String getAppPermissions() {
Map permissions = getAppPermissionsInternal();
StringBuilder sb = new StringBuilder();