Don't prompt users to enable Google Play services if disabled or unavailable (#3152)
* fix(telemetry): prevent Google Play Services spam notifications Check for Google Play Services availability before initializing Firebase to prevent system notifications when GPS is disabled or uninstalled. - Add GPS availability check using GoogleApiAvailability - Wrap Firebase initialization in try-catch for additional safety - Skip Firebase initialization gracefully when GPS unavailable - Add proper logging for debugging purposes - Add core.common dependency to telemetry module for logcat support Fixes #3135 * docs: add changelog entry for Google Play Services notification fix --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
|||||||
- `Other` - for technical stuff.
|
- `Other` - for technical stuff.
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Changed
|
||||||
|
- Don't prompt users to enable Google Play services if disabled or unavailable ([@leodyversemilla07](https://github.com/leodyversemilla07)) ([#3152](https://github.com/mihonapp/mihon/pull/3152))
|
||||||
|
|
||||||
### Improved
|
### Improved
|
||||||
- Show informative error when trying to add unapproved titles to list on MAL ([@MajorTanya](https://github.com/MajorTanya)) ([#3155](https://github.com/mihonapp/mihon/pull/3155))
|
- Show informative error when trying to add unapproved titles to list on MAL ([@MajorTanya](https://github.com/MajorTanya)) ([#3155](https://github.com/mihonapp/mihon/pull/3155))
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation(projects.core.common)
|
||||||
|
|
||||||
if (Config.includeTelemetry) {
|
if (Config.includeTelemetry) {
|
||||||
implementation(platform(libs.firebase.bom))
|
implementation(platform(libs.firebase.bom))
|
||||||
implementation(libs.firebase.analytics)
|
implementation(libs.firebase.analytics)
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package mihon.telemetry
|
package mihon.telemetry
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import com.google.android.gms.common.ConnectionResult
|
||||||
|
import com.google.android.gms.common.GoogleApiAvailability
|
||||||
import com.google.firebase.FirebaseApp
|
import com.google.firebase.FirebaseApp
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics
|
import com.google.firebase.analytics.FirebaseAnalytics
|
||||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
|
import logcat.LogPriority
|
||||||
|
import tachiyomi.core.common.util.system.logcat
|
||||||
|
|
||||||
object TelemetryConfig {
|
object TelemetryConfig {
|
||||||
private var analytics: FirebaseAnalytics? = null
|
private var analytics: FirebaseAnalytics? = null
|
||||||
@@ -13,9 +17,30 @@ object TelemetryConfig {
|
|||||||
// To stop forks/test builds from polluting our data
|
// To stop forks/test builds from polluting our data
|
||||||
if (!context.isMihonProductionApp()) return
|
if (!context.isMihonProductionApp()) return
|
||||||
|
|
||||||
|
// Check if Google Play Services is available before initializing Firebase
|
||||||
|
if (!isGooglePlayServicesAvailable(context)) {
|
||||||
|
logcat(LogPriority.WARN) { "Google Play Services not available, skipping Firebase initialization" }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
analytics = FirebaseAnalytics.getInstance(context)
|
analytics = FirebaseAnalytics.getInstance(context)
|
||||||
FirebaseApp.initializeApp(context)
|
FirebaseApp.initializeApp(context)
|
||||||
crashlytics = FirebaseCrashlytics.getInstance()
|
crashlytics = FirebaseCrashlytics.getInstance()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logcat(LogPriority.ERROR, e) { "Failed to initialize Firebase" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isGooglePlayServicesAvailable(context: Context): Boolean {
|
||||||
|
return try {
|
||||||
|
val availability = GoogleApiAvailability.getInstance()
|
||||||
|
val resultCode = availability.isGooglePlayServicesAvailable(context)
|
||||||
|
resultCode == ConnectionResult.SUCCESS
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logcat(LogPriority.WARN, e) { "Unable to check Google Play Services availability" }
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAnalyticsEnabled(enabled: Boolean) {
|
fun setAnalyticsEnabled(enabled: Boolean) {
|
||||||
|
|||||||
Reference in New Issue
Block a user