Skip to content

Commit 9e1789d

Browse files
committed
Address comments.
1 parent 4041333 commit 9e1789d

File tree

5 files changed

+36
-52
lines changed

5 files changed

+36
-52
lines changed

firebase-sessions/firebase-sessions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ firebaseLibrary {
2626

2727
android {
2828
val targetSdkVersion: Int by rootProject
29-
compileSdk = 30
29+
compileSdk = 33
3030
defaultConfig {
3131
minSdk = 16
3232
targetSdk = targetSdkVersion

firebase-sessions/src/main/kotlin/com/google/firebase/sessions/settings/RemoteSettings.kt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import kotlin.time.Duration
2424
import kotlin.time.Duration.Companion.seconds
2525

2626
internal class RemoteSettings(val context: Context) : SettingsProvider {
27-
private val SESSION_CONFIGS_NAME = "firebase_session_settings"
2827
private val Context.dataStore by preferencesDataStore(name = SESSION_CONFIGS_NAME)
2928
private val settingsCache = SettingsCache(context.dataStore)
3029

@@ -56,22 +55,24 @@ internal class RemoteSettings(val context: Context) : SettingsProvider {
5655
}
5756

5857
companion object SettingsFetcher {
59-
private val FIREBASE_SESSIONS_BASE_URL_STRING = "https://firebase-settings.crashlytics.com"
60-
private val FIREBASE_PLATFORM = "android"
61-
private val fetchInProgress = false
58+
private const val SESSION_CONFIGS_NAME = "firebase_session_settings"
59+
private const val FIREBASE_SESSIONS_BASE_URL_STRING =
60+
"https://firebase-settings.crashlytics.com"
61+
private const val FIREBASE_PLATFORM = "android"
62+
private const val fetchInProgress = false
6263
private val settingsUrl: URL = run {
63-
var uri = Uri.Builder()
64-
uri.scheme("https")
65-
uri.authority(FIREBASE_SESSIONS_BASE_URL_STRING)
66-
uri.appendPath("spi/v2/platforms")
67-
uri.appendPath(FIREBASE_PLATFORM)
68-
uri.appendPath("gmp")
69-
// TODO(visum) Replace below with the GMP APPId
70-
uri.appendPath("GMP_APP_ID")
71-
uri.appendPath("settings")
72-
73-
uri.appendQueryParameter("build_version", "")
74-
uri.appendQueryParameter("display_version", "")
64+
var uri =
65+
Uri.Builder()
66+
.scheme("https")
67+
.authority(FIREBASE_SESSIONS_BASE_URL_STRING)
68+
.appendPath("spi/v2/platforms")
69+
.appendPath(FIREBASE_PLATFORM)
70+
.appendPath("gmp")
71+
// TODO(visum) Replace below with the GMP APPId
72+
.appendPath("GMP_APP_ID")
73+
.appendPath("settings")
74+
.appendQueryParameter("build_version", "")
75+
.appendQueryParameter("display_version", "")
7576

7677
URL(uri.build().toString())
7778
}
@@ -84,6 +85,7 @@ internal class RemoteSettings(val context: Context) : SettingsProvider {
8485

8586
// Check if cache is expired. If not, return
8687
// Initiate a fetch. On successful response cache the fetched values
88+
8789
}
8890
}
8991
}

firebase-sessions/src/main/kotlin/com/google/firebase/sessions/settings/SessionsSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import kotlin.time.Duration.Companion.minutes
2727
*/
2828
internal class SessionsSettings(val context: Context) {
2929

30-
var localOverrideSettings = LocalOverrideSettings(context)
31-
var remoteSettings = RemoteSettings(context)
30+
private var localOverrideSettings = LocalOverrideSettings(context)
31+
private var remoteSettings = RemoteSettings(context)
3232

3333
// Order of preference for all the configs below:
3434
// 1. Honor local overrides

firebase-sessions/src/main/kotlin/com/google/firebase/sessions/settings/SettingsCache.kt

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,15 @@ import androidx.datastore.preferences.core.longPreferencesKey
2626
import kotlinx.coroutines.flow.first
2727

2828
internal data class SessionConfigs(
29-
val sessionEnabled: Boolean?,
30-
val sessionSamplingRate: Double?,
31-
val cacheDuration: Int?,
32-
val sessionRestartTimeout: Int?,
33-
val cacheUpdatedTime: Long?
29+
val sessionEnabled: Boolean? = null,
30+
val sessionSamplingRate: Double? = null,
31+
val cacheDuration: Int? = null,
32+
val sessionRestartTimeout: Int? = null,
33+
val cacheUpdatedTime: Long? = null
3434
)
3535

3636
internal class SettingsCache(private val store: DataStore<Preferences>) {
37-
private var sessionConfigs =
38-
SessionConfigs(
39-
sessionEnabled = null,
40-
sessionSamplingRate = null,
41-
sessionRestartTimeout = null,
42-
cacheDuration = null,
43-
cacheUpdatedTime = null
44-
)
37+
private var sessionConfigs = SessionConfigs()
4538

4639
private object SettingsCacheKeys {
4740
val SETTINGS_CACHE_SESSIONS_ENABLED = booleanPreferencesKey("firebase_sessions_enabled")
@@ -84,17 +77,11 @@ internal class SettingsCache(private val store: DataStore<Preferences>) {
8477
return true
8578
}
8679

87-
fun sessionsEnabled(): Boolean? {
88-
return sessionConfigs.sessionEnabled
89-
}
80+
fun sessionsEnabled(): Boolean? = sessionConfigs.sessionEnabled
9081

91-
fun sessionSamplingRate(): Double? {
92-
return sessionConfigs.sessionSamplingRate
93-
}
82+
fun sessionSamplingRate(): Double? = sessionConfigs.sessionSamplingRate
9483

95-
fun sessionRestartTimeout(): Int? {
96-
return sessionConfigs.sessionRestartTimeout
97-
}
84+
fun sessionRestartTimeout(): Int? = sessionConfigs.sessionRestartTimeout
9885

9986
suspend fun updateSettingsEnabled(enabled: Boolean?) {
10087
store.edit { preferences ->
@@ -155,8 +142,4 @@ internal class SettingsCache(private val store: DataStore<Preferences>) {
155142
updateSessionConfigs()
156143
}
157144
}
158-
159-
companion object {
160-
private const val TAG = "SessionSettings"
161-
}
162145
}

firebase-sessions/src/test/kotlin/com/google/firebase/sessions/SettingsCacheTest.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,19 @@ import android.content.Context
2020
import androidx.datastore.core.DataStore
2121
import androidx.datastore.preferences.core.Preferences
2222
import androidx.datastore.preferences.preferencesDataStore
23-
import com.google.firebase.sessions.settings.SettingsCache
24-
import com.google.firebase.sessions.testing.FakeFirebaseApp
25-
import org.junit.Test
2623
import com.google.common.truth.Truth.assertThat
2724
import com.google.firebase.FirebaseApp
25+
import com.google.firebase.sessions.settings.SettingsCache
26+
import com.google.firebase.sessions.testing.FakeFirebaseApp
2827
import kotlinx.coroutines.runBlocking
2928
import org.junit.After
30-
import org.junit.Before
29+
import org.junit.Test
3130
import org.junit.runner.RunWith
3231
import org.robolectric.RobolectricTestRunner
33-
import kotlin.time.Duration.Companion.minutes
3432

3533
val SESSION_TEST_CONFIGS_NAME = "firebase_test_session_settings"
36-
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = SESSION_TEST_CONFIGS_NAME)
34+
val Context.dataStore: DataStore<Preferences> by
35+
preferencesDataStore(name = SESSION_TEST_CONFIGS_NAME)
3736

3837
@RunWith(RobolectricTestRunner::class)
3938
class SettingsCacheTest {
@@ -178,4 +177,4 @@ class SettingsCacheTest {
178177
fun cleanUp() {
179178
FirebaseApp.clearInstancesForTest()
180179
}
181-
}
180+
}

0 commit comments

Comments
 (0)