diff --git a/app/src/main/java/com/github/kr328/clash/MainApplication.kt b/app/src/main/java/com/github/kr328/clash/MainApplication.kt index 7a21d7b..9561e2f 100644 --- a/app/src/main/java/com/github/kr328/clash/MainApplication.kt +++ b/app/src/main/java/com/github/kr328/clash/MainApplication.kt @@ -8,12 +8,17 @@ import com.github.kr328.clash.core.utils.Log import com.google.firebase.FirebaseApp import io.fabric.sdk.android.Fabric + class MainApplication : Application() { companion object { const val KEY_PROXY_MODE = "key_proxy_mode" const val PROXY_MODE_VPN = "vpn" const val PROXY_MODE_PROXY_ONLY = "proxy_only" + val GOOGLE_PLAY_INSTALLER = listOf("com.android.vending", "com.google.android.feedback") + const val CRASHLYTICS_GOOGLE_PLAY_KEY = "install_from_google" + const val CRASHLYTICS_SPLIT_APK_KEY = "split_apk" + lateinit var instance: MainApplication } @@ -33,6 +38,9 @@ class MainApplication : Application() { Fabric.with(this, Crashlytics()) } + Crashlytics.setBool(CRASHLYTICS_GOOGLE_PLAY_KEY, detectFromPlay()) + Crashlytics.setBool(CRASHLYTICS_SPLIT_APK_KEY, detectSplitArchive()) + Log.handler = object: Log.LogHandler { override fun info(message: String, throwable: Throwable?) { android.util.Log.i(Constants.TAG, message, throwable) @@ -67,4 +75,14 @@ class MainApplication : Application() { } } } + + private fun detectFromPlay(): Boolean { + val installer = packageManager.getInstallerPackageName(packageName) + return installer != null && GOOGLE_PLAY_INSTALLER.contains(installer) + } + + private fun detectSplitArchive(): Boolean { + val split = applicationInfo.splitSourceDirs + return split != null && split.isNotEmpty() + } } \ No newline at end of file