Skip to content

Commit

Permalink
Upgrade to SDK 34 - Android 14
Browse files Browse the repository at this point in the history
Define a foregroundServiceType to meet the new Android policy:
https://developer.android.com/about/versions/14/behavior-changes-14#fgs-types

Closes #368
  • Loading branch information
emanuele-f committed Dec 2, 2023
1 parent 6707f24 commit 68a067c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>

<!-- Required with root to properly resolve UIDs cross-users/profiles. Granted via root -->
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" android:protectionLevel="signature" tools:ignore="ProtectedPermissions" />
Expand Down Expand Up @@ -114,7 +115,12 @@
<service
android:name=".CaptureService"
android:permission="android.permission.BIND_VPN_SERVICE"
android:foregroundServiceType="specialUse"
android:exported="false">

<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="run the VpnService to monitor network traffic"/>

<intent-filter>
<action android:name="android.net.VpnService" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 68a067c

Please sign in to comment.