Improve: remove tracking for flavor 'foss'

This commit is contained in:
kr328 2021-05-16 18:15:36 +08:00
parent 45ab647c67
commit 0b69bf735e
5 changed files with 60 additions and 42 deletions

View File

@ -45,6 +45,14 @@ android {
create("premium") {
dimension = "premium"
versionNameSuffix = ".premium"
val appCenterKey = rootProject.file("local.properties").inputStream()
.use { Properties().apply { load(it) } }
.getProperty("appcenter.key", null)
Objects.requireNonNull(appCenterKey)
buildConfigField("String", "APP_CENTER_KEY", "\"$appCenterKey\"")
}
}
@ -89,32 +97,19 @@ android {
isUniversalApk = true
}
}
buildTypes.apply {
val properties = Properties().apply {
rootProject.file("local.properties").inputStream().use {
load(it)
}
}
val key = properties.getProperty("appcenter.key", null)
forEach {
if (it.name == "debug" || key == null) {
it.buildConfigField("String", "APP_CENTER_KEY", "null")
} else {
it.buildConfigField("String", "APP_CENTER_KEY", "\"$key\"")
}
}
}
}
dependencies {
val premiumImplementation by configurations
api(project(":core"))
api(project(":service"))
api(project(":design"))
api(project(":common"))
premiumImplementation("com.microsoft.appcenter:appcenter-analytics:$appcenterVersion")
premiumImplementation("com.microsoft.appcenter:appcenter-crashes:$appcenterVersion")
implementation(kotlin("stdlib-jdk7"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
implementation("androidx.core:core-ktx:$ktxVersion")
@ -123,8 +118,6 @@ dependencies {
implementation("androidx.coordinatorlayout:coordinatorlayout:$coordinatorlayoutVersion")
implementation("androidx.recyclerview:recyclerview:$recyclerviewVersion")
implementation("androidx.fragment:fragment:$fragmentVersion")
implementation("com.microsoft.appcenter:appcenter-analytics:$appcenterVersion")
implementation("com.microsoft.appcenter:appcenter-crashes:$appcenterVersion")
implementation("com.google.android.material:material:$materialVersion")
}

View File

@ -0,0 +1,14 @@
package com.github.kr328.clash
import android.app.Application
@Suppress("UNUSED_PARAMETER")
object Tracker {
fun initialize(application: Application) {
// do nothing
}
fun uploadLogcat(logcat: String) {
// do nothing
}
}

View File

@ -1,12 +1,9 @@
package com.github.kr328.clash
import android.os.DeadObjectException
import com.github.kr328.clash.common.compat.versionCodeCompat
import com.github.kr328.clash.common.log.Log
import com.github.kr328.clash.design.AppCrashedDesign
import com.github.kr328.clash.log.SystemLogcat
import com.microsoft.appcenter.crashes.Crashes
import com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.isActive
import kotlinx.coroutines.withContext
@ -27,15 +24,7 @@ class AppCrashedActivity : BaseActivity<AppCrashedDesign>() {
SystemLogcat.dumpCrash()
}
if (BuildConfig.APP_CENTER_KEY != null && !BuildConfig.DEBUG) {
if (logs.isNotBlank()) {
Crashes.trackError(
DeadObjectException(),
mapOf("type" to "app_crashed"),
listOf(ErrorAttachmentLog.attachmentWithText(logs, "logcat.txt"))
)
}
}
Tracker.uploadLogcat(logs)
design.setAppLogs(logs)

View File

@ -7,9 +7,6 @@ import com.github.kr328.clash.common.compat.currentProcessName
import com.github.kr328.clash.common.log.Log
import com.github.kr328.clash.remote.Remote
import com.github.kr328.clash.service.util.sendServiceRecreated
import com.microsoft.appcenter.AppCenter
import com.microsoft.appcenter.analytics.Analytics
import com.microsoft.appcenter.crashes.Crashes
@Suppress("unused")
class MainApplication : Application() {
@ -23,13 +20,7 @@ class MainApplication : Application() {
super.onCreate()
// Initialize AppCenter
if (BuildConfig.APP_CENTER_KEY != null && !BuildConfig.DEBUG) {
AppCenter.start(
this,
BuildConfig.APP_CENTER_KEY,
Analytics::class.java, Crashes::class.java
)
}
Tracker.initialize(this)
val processName = currentProcessName

View File

@ -0,0 +1,31 @@
package com.github.kr328.clash
import android.app.Application
import com.microsoft.appcenter.AppCenter
import com.microsoft.appcenter.analytics.Analytics
import com.microsoft.appcenter.crashes.Crashes
import com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog
object Tracker {
fun initialize(application: Application) {
if (BuildConfig.APP_CENTER_KEY != null && !BuildConfig.DEBUG) {
AppCenter.start(
application,
BuildConfig.APP_CENTER_KEY,
Analytics::class.java, Crashes::class.java
)
}
}
fun uploadLogcat(logcat: String) {
if (BuildConfig.APP_CENTER_KEY != null && !BuildConfig.DEBUG) {
if (logcat.isNotBlank()) {
Crashes.trackError(
RuntimeException(),
mapOf("type" to "app_crashed"),
listOf(ErrorAttachmentLog.attachmentWithText(logcat, "logcat.txt"))
)
}
}
}
}