From bd1c7158cb4741f8e055c53c0f7654488eca4e33 Mon Sep 17 00:00:00 2001 From: CASL0 Date: Wed, 17 Jul 2024 23:09:37 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20targetSDK34=E5=AF=BE=E5=BF=9C=E3=81=A7?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=82=A2=E3=82=B0=E3=83=A9=E3=82=A6=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=82=B5=E3=83=BC=E3=83=93=E3=82=B9=E3=81=AE=E3=82=B5?= =?UTF-8?q?=E3=83=BC=E3=83=93=E3=82=B9=E3=82=BF=E3=82=A4=E3=83=97=E3=81=AE?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../packet_filtering/src/main/AndroidManifest.xml | 10 +++++++++- .../feature/packet_filtering/AppBlockerService.kt | 14 +++++++++++++- gradle/libs.versions.toml | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/feature/packet_filtering/src/main/AndroidManifest.xml b/feature/packet_filtering/src/main/AndroidManifest.xml index fea9f00..cd3e779 100644 --- a/feature/packet_filtering/src/main/AndroidManifest.xml +++ b/feature/packet_filtering/src/main/AndroidManifest.xml @@ -17,11 +17,19 @@ + + + android:permission="android.permission.BIND_VPN_SERVICE" + android:foregroundServiceType="specialUse"> + diff --git a/feature/packet_filtering/src/main/java/jp/co/casl0/android/simpleappblocker/feature/packet_filtering/AppBlockerService.kt b/feature/packet_filtering/src/main/java/jp/co/casl0/android/simpleappblocker/feature/packet_filtering/AppBlockerService.kt index b4227a4..02594fd 100644 --- a/feature/packet_filtering/src/main/java/jp/co/casl0/android/simpleappblocker/feature/packet_filtering/AppBlockerService.kt +++ b/feature/packet_filtering/src/main/java/jp/co/casl0/android/simpleappblocker/feature/packet_filtering/AppBlockerService.kt @@ -19,10 +19,13 @@ package jp.co.casl0.android.simpleappblocker.feature.packet_filtering import android.app.NotificationManager import android.content.Intent import android.content.pm.PackageManager +import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE import android.net.ConnectivityManager import android.net.VpnService import android.os.Binder +import android.os.Build import android.os.IBinder +import androidx.core.app.ServiceCompat import com.orhanobut.logger.Logger import dagger.hilt.android.AndroidEntryPoint import jp.co.casl0.android.simpleappblocker.core.data.repository.BlockedPacketsRepository @@ -145,7 +148,16 @@ class AppBlockerService : VpnService(), AppBlockerConnection.OnBlockPacketListen getString(R.string.notification_channel_name) ) } - startForeground(NOTIFICATION_ID, getNotificationBuilder(message).build()) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + ServiceCompat.startForeground( + this, + NOTIFICATION_ID, + getNotificationBuilder(message).build(), + FOREGROUND_SERVICE_TYPE_SPECIAL_USE + ) + } else { + startForeground(NOTIFICATION_ID, getNotificationBuilder(message).build()) + } } // AppBlockerConnection.OnBlockPacketListener diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fed7dda..92ee820 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] versionCode = "17" versionName = "1.2.5" -targetSdk = "33" +targetSdk = "34" compileSdk = "34" buildTools = "35.0.0" agp = "8.5.1"