From 68a067c0864a1f004343a6c4c706626a4d2af429 Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Sat, 2 Dec 2023 19:59:02 +0100 Subject: [PATCH] Upgrade to SDK 34 - Android 14 Define a foregroundServiceType to meet the new Android policy: https://developer.android.com/about/versions/14/behavior-changes-14#fgs-types Closes #368 --- app/build.gradle | 4 ++-- app/src/main/AndroidManifest.xml | 6 ++++++ .../java/com/emanuelef/remote_capture/CaptureService.java | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0595de9a..5f43cf6f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,9 +5,9 @@ android { defaultConfig { applicationId "com.emanuelef.remote_capture" - compileSdk 33 minSdkVersion 21 - targetSdkVersion 33 + compileSdk 34 + targetSdk 34 versionCode 71 versionName "1.6.8" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5c46d3ee..bb1b48d6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,6 +11,7 @@ + @@ -114,7 +115,12 @@ + + + diff --git a/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java b/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java index 23cdafee..f785f3c4 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java +++ b/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java @@ -31,6 +31,7 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; import android.net.ConnectivityManager; import android.net.LinkProperties; import android.net.Network; @@ -220,7 +221,10 @@ public int onStartCommand(@Nullable Intent intent, int flags, int startId) { // NOTE: since Android 12, startForeground cannot be called when the app is in background // (unless invoked via an Intent). setupNotifications(); - startForeground(NOTIFY_ID_VPNSERVICE, getStatusNotification()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + startForeground(NOTIFY_ID_VPNSERVICE, getStatusNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE); + else + startForeground(NOTIFY_ID_VPNSERVICE, getStatusNotification()); // NOTE: onStartCommand may be called when the capture is already running, e.g. if the user // turns on the always-on VPN while the capture is running in root mode