add google play & split apk detect

This commit is contained in:
Kr328 committed 2019-12-21 10:59:06 +08:00
1 parent bc3f7d0549
commit 90456263ae
1 file changed
+18
@@ -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()
}
}