Skip to content

Commit

Permalink
fix: targetSDK34対応でフォアグラウンドサービスのサービスタイプの対応
Browse files Browse the repository at this point in the history
  • Loading branch information
CASL0 committed Jul 17, 2024
1 parent 27ebf9a commit bd1c715
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion feature/packet_filtering/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"
android:minSdkVersion="34" />

<application>
<service
android:name=".AppBlockerService"
android:exported="false"
android:permission="android.permission.BIND_VPN_SERVICE">
android:permission="android.permission.BIND_VPN_SERVICE"
android:foregroundServiceType="specialUse">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="vpn" />
<intent-filter>
<action android:name="android.net.VpnService" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit bd1c715

Please sign in to comment.