Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.routee.android.application.compose)
alias(libs.plugins.routee.hilt)
alias(libs.plugins.google.services)
alias(libs.plugins.firebase.crashlytics)
}

android {
Expand Down Expand Up @@ -79,6 +80,9 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.timber)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.analytics)
implementation(libs.firebase.crashlytics.ndk)
testImplementation(libs.junit)
androidTestImplementation(libs.bundles.android.test)
debugImplementation(libs.androidx.compose.ui.test.manifest)
Expand Down
11 changes: 11 additions & 0 deletions app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<!-- debug 빌드 Analytics 수집 끔 -->
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="false" />
</application>

</manifest>
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- 광고 ID 미사용 -->
<uses-permission
android:name="com.google.android.gms.permission.AD_ID"
tools:node="remove" />
<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" />

<application
android:name=".RouteeApplication"
android:allowBackup="true"
Expand All @@ -17,6 +28,19 @@
android:name="com.naver.maps.map.NCP_KEY_ID"
android:value="${naverMapClientId}" />

<!-- Analytics 광고 ID, 광고 개인 최적화 끔 -->
<meta-data
android:name="google_analytics_adid_collection_enabled"
android:value="false" />
<meta-data
android:name="google_analytics_default_allow_ad_personalization_signals"
android:value="false" />

<!-- 화면 이동은 ScreenViewTracker에서 기록 -->
<meta-data
android:name="google_analytics_automatic_screen_reporting_enabled"
android:value="false" />

<service
android:name="com.google.android.gms.metadata.ModuleDependencies"
android:enabled="false"
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/com/routee/android/CrashlyticsTree.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.routee.android

import android.util.Log
import com.google.firebase.Firebase
import com.google.firebase.crashlytics.crashlytics
import com.routee.android.core.network.exception.ApiException
import java.io.IOException
import kotlin.coroutines.cancellation.CancellationException
import timber.log.Timber

// INFO 이상 로그를 크래시 리포트 Logs에 남김, 예상 못 한 ERROR 예외는 non-fatal로 전송
internal class CrashlyticsTree : Timber.Tree() {
override fun isLoggable(tag: String?, priority: Int): Boolean = priority >= Log.INFO

override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
val error = t?.let { " (${it::class.simpleName})" }.orEmpty()
Firebase.crashlytics.log("${PRIORITY_LABELS[priority]}/${message.substringBefore('\n')}$error")
if (priority >= Log.ERROR && t != null && !t.isExpected()) {
Firebase.crashlytics.recordException(t)
}
}

// 앱이 이미 처리하는 오류. 응답 파싱 실패와 빈 data는 버그일 수 있어 보냄
private fun Throwable.isExpected(): Boolean = when (this) {
is ApiException.Unknown, is ApiException.EmptyData -> false
is ApiException, is IOException, is CancellationException -> true
else -> false
}

private companion object {
val PRIORITY_LABELS = mapOf(Log.INFO to "I", Log.WARN to "W", Log.ERROR to "E", Log.ASSERT to "A")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class RouteeApplication : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
Timber.plant(CrashlyticsTree())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.routee.android.navigation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.snapshotFlow
import androidx.navigation3.runtime.NavKey
import com.google.firebase.Firebase
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.analytics
import com.google.firebase.analytics.logEvent
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
import timber.log.Timber

// 화면 이동 기록 (Analytics screen_view, Crashlytics 로그)
@Composable
internal fun ScreenViewTracker(backStack: List<NavKey>) {
LaunchedEffect(backStack) {
snapshotFlow { backStack.lastOrNull()?.let { it::class.simpleName } }
.filterNotNull()
.distinctUntilChanged()
.collect { screenName ->
Timber.i("화면: $screenName")
Firebase.analytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW) {
param(FirebaseAnalytics.Param.SCREEN_NAME, screenName)
}
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/routee/android/ui/RouteeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.routee.android.feature.setting.navigation.settingEntries
import com.routee.android.feature.timeline.navigation.timelineEntries
import com.routee.android.feature.workout.api.WorkoutMainNavKey
import com.routee.android.feature.workout.navigation.workoutEntries
import com.routee.android.navigation.ScreenViewTracker
import com.routee.android.navigation.rememberRouteeTabSceneDecorator
import kotlinx.coroutines.flow.Flow

Expand All @@ -47,6 +48,7 @@ internal fun RouteeApp(
) {
val backStack = rememberNavBackStack(startKey)
val navigator = rememberRouteeNavigator(backStack, homeKey = WorkoutMainNavKey)
ScreenViewTracker(backStack)

sessionExpired.CollectSideEffect {
navigator.clearAndNavigateTo(LoginNavKey(isSessionExpired = true))
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/keepRules/rules.keep
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
#}

# 화면 이동 기록에 쓰는 화면 이름
-keepnames class * implements androidx.navigation3.runtime.NavKey

# 크래시 리포트 로그에 쓰는 예외 이름
-keepnames class * extends java.lang.Throwable
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ plugins {
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.room) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.firebase.crashlytics) apply false
}
1 change: 1 addition & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
implementation(libs.coil)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.config)
implementation(libs.timber)

testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import timber.log.Timber

@Singleton
internal class WorkoutTrackingRepositoryImpl @Inject constructor(
Expand All @@ -39,6 +40,7 @@ internal class WorkoutTrackingRepositoryImpl @Inject constructor(
recordRepository.startRecord(record).onSuccess {
_state.value = WorkoutTrackingState(record = record)
savedRoute = null
logStatus("시작", record)
}
}

Expand All @@ -62,6 +64,7 @@ internal class WorkoutTrackingRepositoryImpl @Inject constructor(
recordRepository.saveRecord(record).getOrThrow()
val trackPoints = recordRepository.getTrackPoints(record.activityId).getOrThrow()
_state.value = WorkoutTrackingState(record = record, trackPoints = trackPoints)
logStatus("복원", record)
}
}

Expand All @@ -77,6 +80,7 @@ internal class WorkoutTrackingRepositoryImpl @Inject constructor(
recordRepository.getTrackPoints(record.activityId).getOrThrow()
}
_state.value = WorkoutTrackingState(record = record, trackPoints = trackPoints)
logStatus("복구", record)
}
}

Expand All @@ -85,14 +89,20 @@ internal class WorkoutTrackingRepositoryImpl @Inject constructor(
val now = clock.instant()
val finished = record.finished(now, endedAt ?: now)
if (finished == record) return@withLock Result.success(Unit)
recordRepository.saveRecord(finished).onSuccess { _state.value = _state.value.copy(record = finished) }
recordRepository.saveRecord(finished).onSuccess {
_state.value = _state.value.copy(record = finished)
logStatus("종료", finished)
}
}

override suspend fun markSaved(): Result<Unit> = mutex.withLock {
val current = _state.value
val record = current.record ?: return@withLock Result.success(Unit)
savedRoute = SavedRoute(record.activityId, current.trackPoints)
recordRepository.deleteRecord(record.activityId).onSuccess { _state.value = WorkoutTrackingState() }
recordRepository.deleteRecord(record.activityId).onSuccess {
_state.value = WorkoutTrackingState()
logStatus("저장 완료", record)
}
}

override fun getSavedTrackPoints(activityId: Long): List<TrackPoint>? =
Expand All @@ -101,7 +111,10 @@ internal class WorkoutTrackingRepositoryImpl @Inject constructor(
override suspend fun clear(): Result<Unit> = mutex.withLock {
savedRoute = null
val record = _state.value.record ?: return@withLock Result.success(Unit)
recordRepository.deleteRecord(record.activityId).onSuccess { _state.value = WorkoutTrackingState() }
recordRepository.deleteRecord(record.activityId).onSuccess {
_state.value = WorkoutTrackingState()
logStatus("삭제", record)
}
}

private suspend fun updateStatus(transform: (WorkoutRecord) -> WorkoutRecord): Result<Unit> {
Expand All @@ -111,12 +124,17 @@ internal class WorkoutTrackingRepositoryImpl @Inject constructor(
if (updated == record) return Result.success(Unit)
recordRepository.saveRecord(updated).onFailure { return Result.failure(it) }
_state.value = _state.value.copy(record = updated)
logStatus("상태 변경", updated)
updated
}
remoteRepository.updateStatus(changed.activityId, changed.status)
return Result.success(Unit)
}

private fun logStatus(action: String, record: WorkoutRecord) {
Timber.i("운동 기록 $action: ${record.activityId} ${record.status}")
}

private companion object {
const val NO_RECORD = "진행 중인 기록이 없음"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.routee.android.core.network.di
import com.routee.android.core.network.BuildConfig
import com.routee.android.core.network.authenticator.TokenAuthenticator
import com.routee.android.core.network.extension.toPrettyJsonOrSelf
import com.routee.android.core.network.interceptor.ApiTimingInterceptor
import com.routee.android.core.network.interceptor.AuthInterceptor
import com.routee.android.core.network.interceptor.TimeZoneInterceptor
import com.routee.android.core.network.token.ReissueService
Expand Down Expand Up @@ -56,7 +57,9 @@ internal object NetworkModule {
fun provideNoAuthOkHttpClient(
timeZoneInterceptor: TimeZoneInterceptor,
loggingInterceptor: HttpLoggingInterceptor,
apiTimingInterceptor: ApiTimingInterceptor,
): OkHttpClient = OkHttpClient.Builder()
.addInterceptor(apiTimingInterceptor)
.addInterceptor(loggingInterceptor)
.addInterceptor(timeZoneInterceptor)
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.routee.android.core.network.interceptor

import java.io.IOException
import javax.inject.Inject
import okhttp3.Interceptor
import okhttp3.Response
import timber.log.Timber

/**
* API 경로, 응답 코드, 소요 시간을 남긴다
*
* 쿼리는 남기지 않는다
*/
internal class ApiTimingInterceptor @Inject constructor() : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val api = "${request.method} ${request.url.encodedPath}"
val startedAt = System.nanoTime()
val response = try {
chain.proceed(request)
} catch (e: IOException) {
Timber.i("API $api 실패 ${elapsedMillis(startedAt)}ms (${e::class.simpleName})")
throw e
}
Timber.i("API $api ${response.code} ${elapsedMillis(startedAt)}ms")
return response
}

private fun elapsedMillis(startedAt: Long): Long = (System.nanoTime() - startedAt) / 1_000_000
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ internal class WorkoutTrackingService : Service() {
when (intent?.action) {
ACTION_PAUSE -> scope.launch {
trackingRepository.restore()
trackingRepository.pause()
trackingRepository.pause().onFailure { Timber.e(it, "알림 일시정지 실패") }
}

ACTION_RESUME -> scope.launch {
trackingRepository.restore()
trackingRepository.resume()
trackingRepository.resume().onFailure { Timber.e(it, "알림 다시 시작 실패") }
}
}
if (trackingJob == null) {
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ timber = "5.0.1"
# Firebase
googleServices = "4.5.0"
firebaseBom = "35.1.0"
firebaseCrashlyticsPlugin = "3.0.8"

# Kotlin
kotlinxCollectionsImmutable = "0.5.2"
Expand Down Expand Up @@ -141,6 +142,8 @@ androidx-core-location-altitude = { group = "androidx.core", name = "core-locati
# Firebase
firebase-bom = { group = "com.google.firebase", name = "firebase-bom", version.ref = "firebaseBom" }
firebase-config = { group = "com.google.firebase", name = "firebase-config" }
firebase-analytics = { group = "com.google.firebase", name = "firebase-analytics" }
firebase-crashlytics-ndk = { group = "com.google.firebase", name = "firebase-crashlytics-ndk" }

# Logging
timber = { group = "com.jakewharton.timber", name = "timber", version.ref = "timber" }
Expand Down Expand Up @@ -196,6 +199,7 @@ hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
room = { id = "androidx.room", version.ref = "room" }
google-services = { id = "com.google.gms.google-services", version.ref = "googleServices" }
firebase-crashlytics = { id = "com.google.firebase.crashlytics", version.ref = "firebaseCrashlyticsPlugin" }

# build-logic
routee-android-application = { id = "routee.android.application", version = "unspecified" }
Expand Down
Loading