mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2026-05-09 18:11:26 +08:00
improve package name modify
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import java.util.*
|
||||
import java.security.*
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
@@ -121,6 +122,18 @@ task("injectAppCenterKey") {
|
||||
}
|
||||
}
|
||||
|
||||
task("injectPackageNameBase64") {
|
||||
doFirst {
|
||||
val packageName = android.defaultConfig.applicationId ?: return@doFirst
|
||||
|
||||
val base64 = Base64.getEncoder().encodeToString(packageName.toByteArray(Charsets.UTF_8))
|
||||
|
||||
android.buildTypes.forEach {
|
||||
it.buildConfigField("String", "PACKAGE_NAME_BASE64", "\"$base64\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
tasks["preBuild"].dependsOn(tasks["injectAppCenterKey"])
|
||||
tasks["preBuild"].dependsOn(tasks["injectAppCenterKey"], tasks["injectPackageNameBase64"])
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import android.content.ServiceConnection
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.util.Base64
|
||||
import androidx.core.content.edit
|
||||
import com.github.kr328.clash.ApkBrokenActivity
|
||||
import com.github.kr328.clash.BuildConfig
|
||||
@@ -89,7 +90,7 @@ object Remote {
|
||||
|
||||
val application = Global.application
|
||||
|
||||
if ( it ) {
|
||||
if (it) {
|
||||
handler.removeMessages(0)
|
||||
|
||||
GlobalScope.launch {
|
||||
@@ -153,7 +154,36 @@ object Remote {
|
||||
if (sp.getLong(Constants.PREFERENCE_KEY_LAST_INSTALL, 0) == pkg.lastUpdateTime)
|
||||
return true
|
||||
|
||||
if ( application.packageName != BuildConfig.APPLICATION_ID )
|
||||
val pkgName: String = try {
|
||||
application::class.java.getMethod(
|
||||
String(
|
||||
charArrayOf(
|
||||
'g',
|
||||
'e',
|
||||
't',
|
||||
'P',
|
||||
'a',
|
||||
'c',
|
||||
'k',
|
||||
'a',
|
||||
'g',
|
||||
'e',
|
||||
'N',
|
||||
'a',
|
||||
'm',
|
||||
'e'
|
||||
)
|
||||
)
|
||||
).invoke(application)?.toString()
|
||||
} catch (e: Exception) {
|
||||
Log.w("getPackageName failure", e)
|
||||
null
|
||||
} ?: application.packageName
|
||||
|
||||
val packageNameBase64 = Base64
|
||||
.encodeToString(pkgName.toByteArray(Charsets.UTF_8), Base64.NO_WRAP)
|
||||
|
||||
if (packageNameBase64 != BuildConfig.PACKAGE_NAME_BASE64)
|
||||
return false
|
||||
|
||||
val info = application.applicationInfo
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.github.kr328.clash.ApkBrokenActivity
|
||||
import com.github.kr328.clash.common.utils.intent
|
||||
import com.github.kr328.clash.service.Constants
|
||||
import com.github.kr328.clash.service.ServiceStatusProvider
|
||||
import java.lang.Exception
|
||||
|
||||
object RemoteUtils {
|
||||
fun detectClashRunning(context: Context): Boolean {
|
||||
@@ -24,7 +25,7 @@ object RemoteUtils {
|
||||
)
|
||||
|
||||
return pong != null
|
||||
} catch (e: IllegalArgumentException) {
|
||||
} catch (e: Exception) {
|
||||
context.startActivity(ApkBrokenActivity::class.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
|
||||
return false
|
||||
@@ -46,7 +47,7 @@ object RemoteUtils {
|
||||
)
|
||||
|
||||
return pong?.getString("name")
|
||||
} catch (e: IllegalArgumentException) {
|
||||
} catch (e: Exception) {
|
||||
context.startActivity(ApkBrokenActivity::class.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user