Move firebase stuff to a standalone module (mihonapp/mihon#1841)
(cherry picked from commit 046f09c4bdf8fe8bfe5886afefa0e440376184e7)
This commit is contained in:
parent
1ae2c0572c
commit
81209fb0d6
12 changed files with 105 additions and 66 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import mihon.buildlogic.Config
|
||||||
import mihon.buildlogic.getBuildTime
|
import mihon.buildlogic.getBuildTime
|
||||||
import mihon.buildlogic.getCommitCount
|
import mihon.buildlogic.getCommitCount
|
||||||
import mihon.buildlogic.getGitSha
|
import mihon.buildlogic.getGitSha
|
||||||
|
|
@ -11,16 +12,6 @@ plugins {
|
||||||
id("com.github.ben-manes.versions")
|
id("com.github.ben-manes.versions")
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConfigClass {
|
|
||||||
val includeAnalytics: Boolean = project.hasProperty("include-analytics")
|
|
||||||
val enableUpdater: Boolean = project.hasProperty("enable-updater")
|
|
||||||
val enableCodeShrink: Boolean = !project.hasProperty("disable-code-shrink")
|
|
||||||
val includeDependencyInfo: Boolean = project.hasProperty("include-dependency-info")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("PropertyName")
|
|
||||||
val Config = ConfigClass()
|
|
||||||
|
|
||||||
if (Config.includeAnalytics) {
|
if (Config.includeAnalytics) {
|
||||||
pluginManager.apply {
|
pluginManager.apply {
|
||||||
apply(libs.plugins.google.services.get().pluginId)
|
apply(libs.plugins.google.services.get().pluginId)
|
||||||
|
|
@ -102,8 +93,6 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val analyticsDir = if (Config.includeAnalytics) "analytics-firebase" else "analytics-firebase-noop"
|
|
||||||
getByName("main").kotlin.srcDirs("src/$analyticsDir/kotlin")
|
|
||||||
getByName("preview").res.srcDirs("src/beta/res")
|
getByName("preview").res.srcDirs("src/beta/res")
|
||||||
getByName("benchmark").res.srcDirs("src/debug/res")
|
getByName("benchmark").res.srcDirs("src/debug/res")
|
||||||
}
|
}
|
||||||
|
|
@ -202,6 +191,7 @@ dependencies {
|
||||||
implementation(projects.domain)
|
implementation(projects.domain)
|
||||||
implementation(projects.presentationCore)
|
implementation(projects.presentationCore)
|
||||||
implementation(projects.presentationWidget)
|
implementation(projects.presentationWidget)
|
||||||
|
implementation(projects.telemetry)
|
||||||
|
|
||||||
// Compose
|
// Compose
|
||||||
implementation(compose.activity)
|
implementation(compose.activity)
|
||||||
|
|
@ -307,13 +297,6 @@ dependencies {
|
||||||
implementation(libs.timber)
|
implementation(libs.timber)
|
||||||
implementation(libs.logcat)
|
implementation(libs.logcat)
|
||||||
|
|
||||||
// Crash reports/analytics
|
|
||||||
if (Config.includeAnalytics) {
|
|
||||||
implementation(platform(libs.firebase.bom))
|
|
||||||
implementation(libs.firebase.analytics)
|
|
||||||
implementation(libs.firebase.crashlytics)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shizuku
|
// Shizuku
|
||||||
implementation(libs.bundles.shizuku)
|
implementation(libs.bundles.shizuku)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,23 +43,6 @@
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||||
|
|
||||||
<!-- Remove unnecessary permissions from Firebase dependency -->
|
|
||||||
<uses-permission
|
|
||||||
android:name="android.permission.ACCESS_ADSERVICES_AD_ID"
|
|
||||||
tools:node="remove" />
|
|
||||||
|
|
||||||
<uses-permission
|
|
||||||
android:name="android.permission.ACCESS_ADSERVICES_ATTRIBUTION"
|
|
||||||
tools:node="remove" />
|
|
||||||
|
|
||||||
<uses-permission
|
|
||||||
android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE"
|
|
||||||
tools:node="remove" />
|
|
||||||
|
|
||||||
<uses-permission
|
|
||||||
android:name="com.google.android.gms.permission.AD_ID"
|
|
||||||
tools:node="remove" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".App"
|
android:name=".App"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
|
|
@ -289,28 +272,6 @@
|
||||||
android:name="android.webkit.WebView.MetricsOptOut"
|
android:name="android.webkit.WebView.MetricsOptOut"
|
||||||
android:value="true" />
|
android:value="true" />
|
||||||
|
|
||||||
<!-- Disable for manual opt-in -->
|
|
||||||
<meta-data
|
|
||||||
android:name="firebase_analytics_collection_enabled"
|
|
||||||
android:value="false" />
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="firebase_crashlytics_collection_enabled"
|
|
||||||
android:value="false" />
|
|
||||||
|
|
||||||
<!-- Disable unnecessary stuff from Firebase -->
|
|
||||||
<meta-data
|
|
||||||
android:name="google_analytics_adid_collection_enabled"
|
|
||||||
android:value="false" />
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="google_analytics_automatic_screen_reporting_enabled"
|
|
||||||
android:value="false" />
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="google_analytics_default_allow_ad_personalization_signals"
|
|
||||||
android:value="false" />
|
|
||||||
|
|
||||||
<!-- EH -->
|
<!-- EH -->
|
||||||
<activity
|
<activity
|
||||||
android:name="exh.ui.intercept.InterceptActivity"
|
android:name="exh.ui.intercept.InterceptActivity"
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,9 @@ import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import logcat.LogcatLogger
|
import logcat.LogcatLogger
|
||||||
import mihon.core.firebase.FirebaseConfig
|
|
||||||
import mihon.core.migration.Migrator
|
import mihon.core.migration.Migrator
|
||||||
import mihon.core.migration.migrations.migrations
|
import mihon.core.migration.migrations.migrations
|
||||||
|
import mihon.telemetry.TelemetryConfig
|
||||||
import org.conscrypt.Conscrypt
|
import org.conscrypt.Conscrypt
|
||||||
import tachiyomi.core.common.i18n.stringResource
|
import tachiyomi.core.common.i18n.stringResource
|
||||||
import tachiyomi.core.common.preference.Preference
|
import tachiyomi.core.common.preference.Preference
|
||||||
|
|
@ -109,7 +109,7 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super<Application>.onCreate()
|
super<Application>.onCreate()
|
||||||
patchInjekt()
|
patchInjekt()
|
||||||
FirebaseConfig.init(applicationContext)
|
TelemetryConfig.init(applicationContext)
|
||||||
|
|
||||||
// KMK -->
|
// KMK -->
|
||||||
if (isDebugBuildType) Timber.plant(Timber.DebugTree())
|
if (isDebugBuildType) Timber.plant(Timber.DebugTree())
|
||||||
|
|
@ -181,12 +181,12 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
|
||||||
|
|
||||||
privacyPreferences.analytics()
|
privacyPreferences.analytics()
|
||||||
.changes()
|
.changes()
|
||||||
.onEach(FirebaseConfig::setAnalyticsEnabled)
|
.onEach(TelemetryConfig::setAnalyticsEnabled)
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
privacyPreferences.crashlytics()
|
privacyPreferences.crashlytics()
|
||||||
.changes()
|
.changes()
|
||||||
.onEach(FirebaseConfig::setCrashlyticsEnabled)
|
.onEach(TelemetryConfig::setCrashlyticsEnabled)
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
basePreferences.hardwareBitmapThreshold().let { preference ->
|
basePreferences.hardwareBitmapThreshold().let { preference ->
|
||||||
|
|
|
||||||
17
buildSrc/src/main/kotlin/mihon/buildlogic/BuildConfig.kt
Normal file
17
buildSrc/src/main/kotlin/mihon/buildlogic/BuildConfig.kt
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
package mihon.buildlogic
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
interface BuildConfig {
|
||||||
|
val includeAnalytics: Boolean
|
||||||
|
val enableUpdater: Boolean
|
||||||
|
val enableCodeShrink: Boolean
|
||||||
|
val includeDependencyInfo: Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
val Project.Config: BuildConfig get() = object : BuildConfig {
|
||||||
|
override val includeAnalytics: Boolean = project.hasProperty("include-analytics")
|
||||||
|
override val enableUpdater: Boolean = project.hasProperty("enable-updater")
|
||||||
|
override val enableCodeShrink: Boolean = !project.hasProperty("disable-code-shrink")
|
||||||
|
override val includeDependencyInfo: Boolean = project.hasProperty("include-dependency-info")
|
||||||
|
}
|
||||||
|
|
@ -60,3 +60,4 @@ include(":presentation-core")
|
||||||
include(":presentation-widget")
|
include(":presentation-widget")
|
||||||
include(":source-api")
|
include(":source-api")
|
||||||
include(":source-local")
|
include(":source-local")
|
||||||
|
include(":telemetry")
|
||||||
|
|
|
||||||
29
telemetry/build.gradle.kts
Normal file
29
telemetry/build.gradle.kts
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import mihon.buildlogic.Config
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("mihon.library")
|
||||||
|
kotlin("android")
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "mihon.telemetry"
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
getByName("main") {
|
||||||
|
val dir = if (Config.includeAnalytics) "firebase" else "noop"
|
||||||
|
kotlin.srcDirs("src/$dir/kotlin")
|
||||||
|
manifest.srcFile("src/$dir/AndroidManifext.xml")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
if (Config.includeAnalytics) {
|
||||||
|
implementation(platform(libs.firebase.bom))
|
||||||
|
implementation(libs.firebase.analytics)
|
||||||
|
implementation(libs.firebase.crashlytics)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Better logging (EH)
|
||||||
|
implementation(sylibs.xlog)
|
||||||
|
}
|
||||||
45
telemetry/src/firebase/AndroidManifest.xml
Normal file
45
telemetry/src/firebase/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<!-- Remove unnecessary permissions from Firebase dependency -->
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.ACCESS_ADSERVICES_AD_ID"
|
||||||
|
tools:node="remove" />
|
||||||
|
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.ACCESS_ADSERVICES_ATTRIBUTION"
|
||||||
|
tools:node="remove" />
|
||||||
|
|
||||||
|
<uses-permission
|
||||||
|
android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE"
|
||||||
|
tools:node="remove" />
|
||||||
|
|
||||||
|
<uses-permission
|
||||||
|
android:name="com.google.android.gms.permission.AD_ID"
|
||||||
|
tools:node="remove" />
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<!-- Disable for manual opt-in -->
|
||||||
|
<meta-data
|
||||||
|
android:name="firebase_analytics_collection_enabled"
|
||||||
|
android:value="false" />
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="firebase_crashlytics_collection_enabled"
|
||||||
|
android:value="false" />
|
||||||
|
|
||||||
|
<!-- Disable unnecessary stuff from Firebase -->
|
||||||
|
<meta-data
|
||||||
|
android:name="google_analytics_adid_collection_enabled"
|
||||||
|
android:value="false" />
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="google_analytics_automatic_screen_reporting_enabled"
|
||||||
|
android:value="false" />
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="google_analytics_default_allow_ad_personalization_signals"
|
||||||
|
android:value="false" />
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package mihon.core.firebase
|
package mihon.telemetry
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.google.firebase.FirebaseApp
|
import com.google.firebase.FirebaseApp
|
||||||
|
|
@ -7,7 +7,7 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
|
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
|
||||||
|
|
||||||
object FirebaseConfig {
|
object TelemetryConfig {
|
||||||
private lateinit var analytics: FirebaseAnalytics
|
private lateinit var analytics: FirebaseAnalytics
|
||||||
private lateinit var crashlytics: FirebaseCrashlytics
|
private lateinit var crashlytics: FirebaseCrashlytics
|
||||||
|
|
||||||
2
telemetry/src/noop/AndroidManifest.xml
Normal file
2
telemetry/src/noop/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest />
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package mihon.core.firebase
|
package mihon.telemetry
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
|
||||||
object FirebaseConfig {
|
@Suppress("UNUSED_PARAMETER")
|
||||||
|
object TelemetryConfig {
|
||||||
fun init(context: Context) = Unit
|
fun init(context: Context) = Unit
|
||||||
|
|
||||||
fun setAnalyticsEnabled(enabled: Boolean) = Unit
|
fun setAnalyticsEnabled(enabled: Boolean) = Unit
|
||||||
Loading…
Reference in a new issue