Update app (#428)

This commit is contained in:
5ec1cff
2025-01-21 21:35:45 +08:00
committed by GitHub
parent 3100e1700c
commit e8e00108e6
47 changed files with 224 additions and 132 deletions

View File

@@ -19,7 +19,7 @@ dependencies {
implementation(libs.androidx.room.ktx)
implementation(libs.kaidl.runtime)
implementation(libs.rikkax.multiprocess)
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.12.0"))
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")

View File

@@ -1,6 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.github.kr328.clash.service">
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
@@ -9,19 +8,27 @@
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<application>
<service
android:name=".ClashService"
android:exported="false"
android:label="@string/clash_meta_for_android"
android:process=":background" />
android:process=":background"
android:foregroundServiceType="specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="explanation_for_special_use"/>
</service>
<service
android:name=".TunService"
android:exported="false"
android:label="@string/clash_meta_for_android"
android:permission="android.permission.BIND_VPN_SERVICE"
android:process=":background">
android:process=":background"
android:foregroundServiceType="specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="explanation_for_special_use"/>
<intent-filter>
<action android:name="android.net.VpnService" />
</intent-filter>
@@ -33,7 +40,11 @@
<service
android:name=".ProfileWorker"
android:exported="false"
android:process=":background" />
android:process=":background"
android:foregroundServiceType="specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="explanation_for_special_use"/>
</service>
<provider
android:name=".FilesProvider"

View File

@@ -9,6 +9,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.github.kr328.clash.common.compat.getColorCompat
import com.github.kr328.clash.common.compat.pendingIntentFlags
import com.github.kr328.clash.common.compat.startForegroundCompat
import com.github.kr328.clash.common.constants.Components
import com.github.kr328.clash.common.constants.Intents
import com.github.kr328.clash.common.id.UndefinedIds
@@ -123,7 +124,7 @@ class ProfileWorker : BaseService() {
.setOnlyAlertOnce(true)
.build()
startForeground(R.id.nf_profile_worker, notification)
startForegroundCompat(R.id.nf_profile_worker, notification)
}
private suspend inline fun processing(name: String, block: () -> Unit) {

View File

@@ -11,10 +11,11 @@ import java.util.concurrent.TimeUnit
class AppListCacheModule(service: Service) : Module<Unit>(service) {
private fun PackageInfo.uniqueUidName(): String =
if (sharedUserId != null && sharedUserId.isNotBlank()) sharedUserId else packageName
if (sharedUserId?.isNotBlank() == true) sharedUserId!! else packageName
private fun reload() {
val packages = service.packageManager.getInstalledPackages(0)
.filter { it.applicationInfo != null }
.groupBy { it.uniqueUidName() }
.map { (_, v) ->
val info = v[0]
@@ -23,9 +24,9 @@ class AppListCacheModule(service: Service) : Module<Unit>(service) {
// Force use package name if only one app in a single sharedUid group
// Example: firefox
info.applicationInfo.uid to info.packageName
info.applicationInfo!!.uid to info.packageName
} else {
info.applicationInfo.uid to info.uniqueUidName()
info.applicationInfo!!.uid to info.uniqueUidName()
}
}

View File

@@ -5,6 +5,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.github.kr328.clash.common.compat.registerReceiverCompat
import com.github.kr328.clash.common.constants.Permissions
import com.github.kr328.clash.common.log.Log
import kotlinx.coroutines.NonCancellable
@@ -44,9 +45,9 @@ abstract class Module<E>(val service: Service) {
}
if (requireSelf) {
service.registerReceiver(receiver, filter, Permissions.RECEIVE_SELF_BROADCASTS, null)
service.registerReceiverCompat(receiver, filter, Permissions.RECEIVE_SELF_BROADCASTS, null)
} else {
service.registerReceiver(receiver, filter)
service.registerReceiverCompat(receiver, filter)
}
receivers.add(receiver)

View File

@@ -8,6 +8,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.github.kr328.clash.common.compat.getColorCompat
import com.github.kr328.clash.common.compat.pendingIntentFlags
import com.github.kr328.clash.common.compat.startForegroundCompat
import com.github.kr328.clash.common.constants.Components
import com.github.kr328.clash.common.constants.Intents
import com.github.kr328.clash.service.R
@@ -47,7 +48,7 @@ class StaticNotificationModule(service: Service) : Module<Unit>(service) {
.setContentText(service.getText(R.string.running))
.build()
service.startForeground(R.id.nf_clash_status, notification)
service.startForegroundCompat(R.id.nf_clash_status, notification)
}
}
@@ -74,7 +75,7 @@ class StaticNotificationModule(service: Service) : Module<Unit>(service) {
.setContentTitle(service.getText(R.string.loading))
.build()
service.startForeground(R.id.nf_clash_status, notification)
service.startForegroundCompat(R.id.nf_clash_status, notification)
}
}
}