Skip to content

Commit 72b01fe

Browse files
committed
Setup configuration layer for the library.
1 parent f1c51b5 commit 72b01fe

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionInitiator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import android.app.Activity
2020
import android.app.Application.ActivityLifecycleCallbacks
2121
import android.os.Bundle
2222
import kotlin.time.Duration
23-
import kotlin.time.Duration.Companion.minutes
2423

2524
/**
2625
* The [SessionInitiator] is responsible for calling the [initiateSessionStart] callback whenever a
@@ -34,7 +33,7 @@ internal class SessionInitiator(
3433
private val initiateSessionStart: () -> Unit
3534
) {
3635
private var backgroundTime = elapsedRealtime()
37-
private val sessionTimeout = 30.minutes // TODO(mrober): Get session timeout from settings
36+
private val sessionTimeout = SessionsSettings().sessionRestartTimeout
3837

3938
init {
4039
initiateSessionStart()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2023 Google LLC
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+
* http://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+
17+
package com.google.firebase.sessions
18+
19+
import kotlin.time.Duration
20+
import kotlin.time.Duration.Companion.minutes
21+
22+
/**
23+
* [SessionsSettings] manages all the configs that are relevant to the sessions library.
24+
*
25+
* @hide
26+
*/
27+
internal class SessionsSettings {
28+
// Setting to qualify if sessions service is enabled.
29+
internal val sessionsEnabled: Boolean get() {
30+
return true
31+
}
32+
33+
// Setting that provides the sessions sampling rate.
34+
internal val samplingRate: Double get() {
35+
return 1.0
36+
}
37+
38+
// Background timeout config value before which a new session is generated
39+
val sessionRestartTimeout: Duration
40+
get() = 30.minutes
41+
42+
// Update the settings for all the settings providers
43+
internal fun updateSettings() {
44+
// Placeholder to initiate settings update on different sources
45+
// Expected sources: RemoteSettings, ManifestOverrides, SDK Defaults
46+
}
47+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2023 Google LLC
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+
* http://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+
17+
package com.google.firebase.sessions
18+
19+
import com.google.common.truth.Truth.assertThat
20+
import org.junit.Test
21+
import kotlin.time.Duration.Companion.minutes
22+
23+
class SessionsSettingsTest {
24+
25+
@Test
26+
fun sessionSettings_fetchDefaults() {
27+
assertThat(SessionsSettings().sessionsEnabled).isTrue()
28+
assertThat(SessionsSettings().samplingRate).isEqualTo(1.0)
29+
assertThat(SessionsSettings().sessionRestartTimeout).isEqualTo(30.minutes)
30+
}
31+
}

0 commit comments

Comments
 (0)