Skip to content

Commit 9dad35e

Browse files
authored
Merge pull request #123 from android/firebase-appcheck-logs
Firebase AppCheck - Add more logging
2 parents bb3e59a + c03fb7b commit 9dad35e

File tree

27 files changed

+156
-62
lines changed

27 files changed

+156
-62
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ dependencies {
136136

137137
implementation(platform(libs.firebase.bom))
138138
implementation(libs.firebase.crashlytics)
139+
implementation(libs.timber)
139140
implementation(libs.firebase.ai)
140141
implementation(libs.firebase.app.check)
141142
implementation(libs.firebase.config)

app/proguard-rules.pro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@
4343

4444
# Ignore missing Java SE annotation processing classes, often from libraries like AutoValue
4545
-dontwarn javax.lang.model.**
46+
47+
# OkHttp
48+
-keep class okhttp3.** { *; }
49+
-keep interface okhttp3.** { *; }
50+
-dontwarn okhttp3.**
51+
52+
# Ignore SAX parser warning
53+
-dontwarn org.xml.sax.**

app/src/main/java/com/android/developers/androidify/AndroidifyApplication.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import coil3.ImageLoader
2323
import coil3.PlatformContext
2424
import coil3.SingletonImageLoader
2525
import dagger.hilt.android.HiltAndroidApp
26+
import timber.log.Timber
2627
import javax.inject.Inject
28+
2729
@HiltAndroidApp
2830
class AndroidifyApplication : Application(), SingletonImageLoader.Factory {
2931

@@ -32,6 +34,11 @@ class AndroidifyApplication : Application(), SingletonImageLoader.Factory {
3234

3335
override fun onCreate() {
3436
super.onCreate()
37+
if (isDebuggable()) {
38+
Timber.plant(Timber.DebugTree())
39+
} else {
40+
Timber.plant(CrashlyticsTree())
41+
}
3542
setStrictModePolicy()
3643
}
3744

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.android.developers.androidify
17+
18+
import android.util.Log
19+
import com.google.firebase.crashlytics.FirebaseCrashlytics
20+
import timber.log.Timber
21+
22+
/**
23+
* A Timber tree that logs to Crashlytics.
24+
*
25+
* In debug builds, this tree does nothing. In release builds, it logs non-fatal exceptions
26+
* to Crashlytics.
27+
*/
28+
class CrashlyticsTree : Timber.Tree() {
29+
30+
private val crashlytics by lazy { FirebaseCrashlytics.getInstance() }
31+
32+
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
33+
if (priority == Log.VERBOSE || priority == Log.DEBUG) {
34+
return
35+
}
36+
37+
crashlytics.log(message)
38+
39+
if (t != null) {
40+
crashlytics.recordException(t)
41+
}
42+
}
43+
}

core/network/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ dependencies {
7171
implementation(libs.coil.compose.http)
7272
implementation(libs.coil.gif)
7373
implementation(platform(libs.firebase.bom))
74+
implementation(libs.timber)
7475
implementation(libs.firebase.ai)
7576
implementation(libs.firebase.analytics) {
7677
exclude(group = "com.google.guava")

core/network/src/main/java/com/android/developers/androidify/ondevice/LocalSegmentationDataSource.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.android.developers.androidify.ondevice
1717

1818
import android.graphics.Bitmap
19-
import android.util.Log
2019
import com.google.android.gms.common.moduleinstall.InstallStatusListener
2120
import com.google.android.gms.common.moduleinstall.ModuleInstallClient
2221
import com.google.android.gms.common.moduleinstall.ModuleInstallRequest
@@ -28,6 +27,7 @@ import com.google.mlkit.vision.segmentation.subject.SubjectSegmentation
2827
import com.google.mlkit.vision.segmentation.subject.SubjectSegmenterOptions
2928
import kotlinx.coroutines.CancellableContinuation
3029
import kotlinx.coroutines.suspendCancellableCoroutine
30+
import timber.log.Timber
3131
import javax.inject.Inject
3232
import kotlin.coroutines.resume
3333
import kotlin.coroutines.resumeWithException
@@ -64,7 +64,7 @@ class LocalSegmentationDataSourceImpl @Inject constructor(
6464
) : InstallStatusListener {
6565

6666
override fun onInstallStatusUpdated(update: ModuleInstallStatusUpdate) {
67-
Log.d("LocalSegmentationDataSource", "Download progress: ${update.installState}.. ${continuation.hashCode()} ${continuation.isActive}")
67+
Timber.d("Download progress: ${update.installState}.. ${continuation.hashCode()} ${continuation.isActive}")
6868
if (!continuation.isActive) return
6969
if (update.installState == ModuleInstallStatusUpdate.InstallState.STATE_COMPLETED) {
7070
continuation.resume(true)
@@ -73,7 +73,7 @@ class LocalSegmentationDataSourceImpl @Inject constructor(
7373
ImageSegmentationException("Module download failed or was canceled. State: ${update.installState}"),
7474
)
7575
} else {
76-
Log.d("LocalSegmentationDataSource", "State update: ${update.installState}")
76+
Timber.d("State update: ${update.installState}")
7777
}
7878
}
7979
}
@@ -88,11 +88,11 @@ class LocalSegmentationDataSourceImpl @Inject constructor(
8888
moduleInstallClient
8989
.installModules(moduleInstallRequest)
9090
.addOnFailureListener {
91-
Log.e("LocalSegmentationDataSource", "Failed to download module", it)
91+
Timber.e(it, "Failed to download module")
9292
continuation.resumeWithException(it)
9393
}
9494
.addOnCompleteListener {
95-
Log.d("LocalSegmentationDataSource", "Successfully triggered download - await download progress updates")
95+
Timber.d("Successfully triggered download - await download progress updates")
9696
}
9797
}
9898
return result
@@ -102,13 +102,13 @@ class LocalSegmentationDataSourceImpl @Inject constructor(
102102
val areModulesAvailable = isSubjectSegmentationModuleInstalled()
103103

104104
if (!areModulesAvailable) {
105-
Log.d("LocalSegmentationDataSource", "Modules not available - downloading")
105+
Timber.d("Modules not available - downloading")
106106
val result = installSubjectSegmentationModule()
107107
if (!result) {
108108
throw Exception("Failed to download module")
109109
}
110110
} else {
111-
Log.d("LocalSegmentationDataSource", "Modules available")
111+
Timber.d("Modules available")
112112
}
113113
val image = InputImage.fromBitmap(bitmap, 0)
114114
return suspendCancellableCoroutine { continuation ->
@@ -121,7 +121,7 @@ class LocalSegmentationDataSourceImpl @Inject constructor(
121121
}
122122
}
123123
.addOnFailureListener { e ->
124-
Log.e("LocalSegmentationDataSource", "Exception while executing background removal", e)
124+
Timber.e(e, "Exception while executing background removal")
125125
continuation.resumeWithException(e)
126126
}
127127
}

core/network/src/main/java/com/android/developers/androidify/startup/FirebaseAppCheckInitializer.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,48 @@ package com.android.developers.androidify.startup
1717

1818
import android.annotation.SuppressLint
1919
import android.content.Context
20-
import android.util.Log
2120
import androidx.startup.Initializer
2221
import com.android.developers.androidify.network.BuildConfig
2322
import com.google.firebase.Firebase
2423
import com.google.firebase.appcheck.FirebaseAppCheck
2524
import com.google.firebase.appcheck.appCheck
2625
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
2726
import com.google.firebase.appcheck.playintegrity.PlayIntegrityAppCheckProviderFactory
27+
import timber.log.Timber
2828

2929
/**
3030
* Initialize [FirebaseAppCheck] using the App Startup Library.
3131
*/
3232
@SuppressLint("EnsureInitializerMetadata") // Registered in :app module
3333
class FirebaseAppCheckInitializer : Initializer<FirebaseAppCheck> {
3434
override fun create(context: Context): FirebaseAppCheck {
35-
return Firebase.appCheck.apply {
35+
val appCheck = Firebase.appCheck.apply {
3636
if (BuildConfig.DEBUG) {
37-
Log.i("AndroidifyAppCheck", "Firebase debug")
37+
Timber.i(
38+
"Installing Firebase debug, ensure your " +
39+
"debug token is registered on Firebase Console",
40+
)
3841
installAppCheckProviderFactory(
3942
DebugAppCheckProviderFactory.getInstance(),
4043
)
4144
} else {
42-
Log.i("AndroidifyAppCheck", "Play integrity")
45+
Timber.i("Play integrity installing...")
4346
installAppCheckProviderFactory(
4447
PlayIntegrityAppCheckProviderFactory.getInstance(),
4548
)
4649
}
50+
setTokenAutoRefreshEnabled(true)
51+
}
52+
53+
val token = appCheck.getAppCheckToken(false)
54+
token.addOnCompleteListener {
55+
if (token.isSuccessful) {
56+
Timber.i("Firebase app check token success: ${token.result.expireTimeMillis}")
57+
} else {
58+
Timber.e(token.exception, "Firebase app check token failure")
59+
}
4760
}
61+
return appCheck
4862
}
4963

5064
override fun dependencies(): List<Class<out Initializer<*>?>?> {

core/network/src/main/java/com/android/developers/androidify/startup/FirebaseRemoteConfigInitializer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ package com.android.developers.androidify.startup
1717

1818
import android.annotation.SuppressLint
1919
import android.content.Context
20-
import android.util.Log
2120
import androidx.startup.Initializer
2221
import com.android.developers.androidify.network.R
2322
import com.google.firebase.Firebase
2423
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
2524
import com.google.firebase.remoteconfig.remoteConfig
2625
import com.google.firebase.remoteconfig.remoteConfigSettings
26+
import timber.log.Timber
2727

2828
/**
2929
* Initialize [FirebaseRemoteConfig] using the App Startup Library.
@@ -39,10 +39,10 @@ class FirebaseRemoteConfigInitializer : Initializer<FirebaseRemoteConfig> {
3939
setDefaultsAsync(R.xml.remote_config_defaults)
4040
fetchAndActivate()
4141
.addOnSuccessListener {
42-
Log.d("FirebaseRemoteConfig", "Config params updated: $it")
42+
Timber.d("Config params updated: $it")
4343
}
4444
.addOnFailureListener {
45-
Log.d("FirebaseRemoteConfig", "Config params failed: $it")
45+
Timber.d("Config params failed: $it")
4646
}
4747
}
4848
}

core/testing/src/main/java/com/android/developers/testing/repository/FakeWatchFaceInstallationRepository.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.android.developers.testing.repository
217

318
import android.graphics.Bitmap
@@ -65,4 +80,4 @@ class FakeWatchFaceInstallationRepository : WatchFaceInstallationRepository {
6580
public fun setWatchAsConnected() {
6681
_connectedWatch.value = watch
6782
}
68-
}
83+
}

core/theme/src/main/res/drawable/squiggle_full.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0" encoding="utf-8"?><!--
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
23
Copyright 2025 The Android Open Source Project
34
45
Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +14,6 @@
1314
See the License for the specific language governing permissions and
1415
limitations under the License.
1516
-->
16-
<!-- The squiggle but cropped to the viewport. -->
1717
<vector xmlns:android="http://schemas.android.com/apk/res/android"
1818
android:width="1425dp"
1919
android:height="822dp"

0 commit comments

Comments
 (0)