remove geoip embed and sideload

we had geoip.metadb and geosite.dat in asserts
This commit is contained in:
wwqgtxx
2024-09-11 14:41:22 +08:00
parent a1d838a98a
commit 262a6b563c
26 changed files with 3 additions and 411 deletions

View File

@@ -27,7 +27,6 @@ class ClashService : BaseService() {
val close = install(CloseModule(self))
val config = install(ConfigurationModule(self))
val network = install(NetworkObserveModule(self))
val sideload = install(SideloadDatabaseModule(self))
if (store.dynamicNotification)
install(DynamicNotificationModule(self))
@@ -49,11 +48,6 @@ class ClashService : BaseService() {
true
}
sideload.onEvent {
reason = it.message
true
}
network.onEvent {
false
}

View File

@@ -33,7 +33,6 @@ class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.De
val tun = install(TunModule(self))
val config = install(ConfigurationModule(self))
val network = install(NetworkObserveModule(self))
val sideload = install(SideloadDatabaseModule(self))
if (store.dynamicNotification)
install(DynamicNotificationModule(self))
@@ -57,11 +56,6 @@ class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.De
true
}
sideload.onEvent {
reason = it.message
true
}
network.onEvent { n ->
if (Build.VERSION.SDK_INT in 22..28) @TargetApi(22) {
setUnderlyingNetworks(n?.let { arrayOf(it) })

View File

@@ -1,87 +0,0 @@
package com.github.kr328.clash.service.clash.module
import android.app.Service
import android.content.Intent
import com.github.kr328.clash.common.constants.Intents
import com.github.kr328.clash.common.log.Log
import com.github.kr328.clash.core.Clash
import com.github.kr328.clash.service.sideload.readGeoipDatabaseFrom
import com.github.kr328.clash.service.store.ServiceStore
import com.github.kr328.clash.service.util.packageName
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.selects.select
import java.io.FileNotFoundException
import java.io.IOException
class SideloadDatabaseModule(service: Service) :
Module<SideloadDatabaseModule.LoadException>(service) {
data class LoadException(val message: String)
private val store = ServiceStore(service)
private var current: String = ""
override suspend fun run() {
val packagesChanged = receiveBroadcast(false) {
addAction(Intent.ACTION_PACKAGE_ADDED)
addAction(Intent.ACTION_PACKAGE_REPLACED)
addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED)
addDataScheme("package")
}
val profileChanged = receiveBroadcast(capacity = Channel.CONFLATED) {
addAction(Intents.ACTION_PROFILE_CHANGED)
}
val initial = Channel<Unit>(1).apply { send(Unit) }
while (true) {
val (reload, force) = select<Pair<Boolean, Boolean>> {
packagesChanged.onReceive {
when (it.action) {
Intent.ACTION_PACKAGE_ADDED ->
(it.packageName == store.sideloadGeoip) to true
Intent.ACTION_PACKAGE_REPLACED ->
(it.packageName == current) to true
Intent.ACTION_PACKAGE_FULLY_REMOVED ->
(it.packageName == current) to true
else -> false to false
}
}
profileChanged.onReceive {
true to false
}
initial.onReceive {
true to true
}
}
if (!reload) continue
val pkg = store.sideloadGeoip
try {
if (!force && pkg == current)
continue
current = pkg
if (pkg.isNotBlank()) {
val data = service.readGeoipDatabaseFrom(pkg)
Clash.installSideloadGeoip(data)
if (data != null) {
Log.d("Sideload geoip loaded, pkg = $pkg")
} else {
Log.d("Sideload geoip not found")
}
}
} catch (e: FileNotFoundException) {
return enqueueEvent(LoadException("file $pkg/assets/${e.message} not found"))
} catch (e: IOException) {
return enqueueEvent(LoadException("read data from $pkg: ${e.message}"))
} catch (e: Exception) {
return enqueueEvent(LoadException(e.toString()))
}
}
}
}

View File

@@ -1,21 +0,0 @@
package com.github.kr328.clash.service.sideload
import android.content.Context
import android.content.pm.PackageManager
import com.github.kr328.clash.common.constants.Metadata
import com.github.kr328.clash.common.log.Log
import java.io.InputStream
fun Context.readGeoipDatabaseFrom(packageName: String): ByteArray? {
return try {
val appInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
val path = appInfo.metaData.getString(Metadata.GEOIP_FILE_NAME) ?: return null
createPackageContext(packageName, 0)
.resources.assets.open(path).use(InputStream::readBytes)
} catch (e: PackageManager.NameNotFoundException) {
Log.w("Sideload geoip: $packageName not found", e)
null
}
}

View File

@@ -60,9 +60,4 @@ class ServiceStore(context: Context) {
key = "dynamic_notification",
defaultValue = true
)
var sideloadGeoip by store.string(
key = "sideload_geoip",
defaultValue = ""
)
}