diff --git a/app/src/main/java/com/github/kr328/clash/remote/Remote.kt b/app/src/main/java/com/github/kr328/clash/remote/Remote.kt index d4d3948..843d616 100644 --- a/app/src/main/java/com/github/kr328/clash/remote/Remote.kt +++ b/app/src/main/java/com/github/kr328/clash/remote/Remote.kt @@ -8,26 +8,21 @@ import android.content.ServiceConnection import android.os.Build import android.os.Handler import android.os.IBinder -import android.os.RemoteException import androidx.core.content.edit import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner import com.github.kr328.clash.ApkBrokenActivity import com.github.kr328.clash.Constants -import com.github.kr328.clash.core.utils.Log -import com.github.kr328.clash.dump.LogcatDumper import com.github.kr328.clash.service.ClashManagerService import com.github.kr328.clash.service.IClashManager import com.github.kr328.clash.service.IProfileService import com.github.kr328.clash.service.ProfileService import com.github.kr328.clash.service.util.intent import com.microsoft.appcenter.crashes.Crashes -import com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import java.io.File -import java.lang.Exception import java.util.zip.ZipFile object Remote { @@ -95,7 +90,11 @@ object Remote { handler.removeMessages(0) GlobalScope.launch { - if (!verifyApk(application)) { + val valid = withContext(Dispatchers.IO) { + verifyApk(application) + } + + if (!valid) { application.startActivity( ApkBrokenActivity::class.intent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) @@ -139,45 +138,44 @@ object Remote { }) } - private suspend fun verifyApk(application: Application) = withContext(Dispatchers.IO) { - val sp = application.getSharedPreferences( - Constants.PREFERENCE_NAME_APP, - Context.MODE_PRIVATE - ) - val pkg = application.packageManager.getPackageInfo(application.packageName, 0) + private fun verifyApk(application: Application): Boolean { + return try { + val sp = application.getSharedPreferences( + Constants.PREFERENCE_NAME_APP, + Context.MODE_PRIVATE + ) + val pkg = application.packageManager.getPackageInfo(application.packageName, 0) - if (sp.getLong(Constants.PREFERENCE_KEY_LAST_INSTALL, 0) == pkg.lastUpdateTime) - return@withContext true + if (sp.getLong(Constants.PREFERENCE_KEY_LAST_INSTALL, 0) == pkg.lastUpdateTime) + return true - val info = application.applicationInfo - val sources = - info.splitSourceDirs ?: arrayOf(info.sourceDir) ?: return@withContext false + val info = application.applicationInfo + val sources = + info.splitSourceDirs ?: arrayOf(info.sourceDir) ?: return false - val regexNativeLibrary = Regex("lib/(\\S+)/libgojni.so") - val availableAbi = Build.SUPPORTED_ABIS.toSet() - val apkAbi = try { - sources - .asSequence() - .filter { File(it).exists() } - .flatMap { ZipFile(it).entries().asSequence() } - .mapNotNull { regexNativeLibrary.matchEntire(it.name) } - .mapNotNull { it.groups[1]?.value } - .toSet() - } - catch (e: Exception) { + val regexNativeLibrary = Regex("lib/(\\S+)/libgojni.so") + val availableAbi = Build.SUPPORTED_ABIS.toSet() + val apkAbi = + sources + .asSequence() + .filter { File(it).exists() } + .flatMap { ZipFile(it).entries().asSequence() } + .mapNotNull { regexNativeLibrary.matchEntire(it.name) } + .mapNotNull { it.groups[1]?.value } + .toSet() + + if (availableAbi.intersect(apkAbi).isNotEmpty()) { + sp.edit { + putLong(Constants.PREFERENCE_KEY_LAST_INSTALL, pkg.lastUpdateTime) + } + + true + } else { + false + } + } catch (e: Exception) { Crashes.trackError(e) - emptySet() - } - - if (availableAbi.intersect(apkAbi).isNotEmpty()) { - sp.edit { - putLong(Constants.PREFERENCE_KEY_LAST_INSTALL, pkg.lastUpdateTime) - } - - true - } - else { false } } diff --git a/build.gradle b/build.gradle index a229223..5036d00 100644 --- a/build.gradle +++ b/build.gradle @@ -8,8 +8,8 @@ buildscript { gMinSdkVersion = 24 gTargetSdkVersion = 29 - gVersionCode = 10109 - gVersionName = "1.1.9" + gVersionCode = 10110 + gVersionName = "1.1.10" gKotlinVersion = '1.3.61' gKotlinCoroutineVersion = '1.3.3' diff --git a/core/src/main/golang/clash b/core/src/main/golang/clash index 8becf32..6dd2393 160000 --- a/core/src/main/golang/clash +++ b/core/src/main/golang/clash @@ -1 +1 @@ -Subproject commit 8becf32bb308f84ed81079361fd5c21d50e54bff +Subproject commit 6dd23933fe84606baa1d5bdebc494ce1a93c299e