Skip to content

Setup configuration layer for the library. #4853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.app.Activity
import android.app.Application.ActivityLifecycleCallbacks
import android.os.Bundle
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes

/**
* The [SessionInitiator] is responsible for calling the [initiateSessionStart] callback whenever a
Expand All @@ -34,7 +33,6 @@ internal class SessionInitiator(
private val initiateSessionStart: () -> Unit
) {
private var backgroundTime = elapsedRealtime()
private val sessionTimeout = 30.minutes // TODO(mrober): Get session timeout from settings

init {
initiateSessionStart()
Expand All @@ -46,6 +44,7 @@ internal class SessionInitiator(

fun appForegrounded() {
val interval = elapsedRealtime() - backgroundTime
val sessionTimeout = SessionsSettings().sessionRestartTimeout
if (interval > sessionTimeout) {
initiateSessionStart()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.sessions

import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes

/**
* [SessionsSettings] manages all the configs that are relevant to the sessions library.
*
* @hide
*/
internal class SessionsSettings {
// Setting to qualify if sessions service is enabled.
val sessionsEnabled: Boolean
get() {
return true
}

// Setting that provides the sessions sampling rate.
val samplingRate: Double
get() {
return 1.0
}

// Background timeout config value before which a new session is generated
val sessionRestartTimeout: Duration
get() = 30.minutes

// Update the settings for all the settings providers
fun updateSettings() {
// Placeholder to initiate settings update on different sources
// Expected sources: RemoteSettings, ManifestOverrides, SDK Defaults
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.sessions

import com.google.common.truth.Truth.assertThat
import kotlin.time.Duration.Companion.minutes
import org.junit.Test

class SessionsSettingsTest {

@Test
fun sessionSettings_fetchDefaults() {
val sessionsSettings = SessionsSettings()
assertThat(sessionsSettings.sessionsEnabled).isTrue()
assertThat(sessionsSettings.samplingRate).isEqualTo(1.0)
assertThat(sessionsSettings.sessionRestartTimeout).isEqualTo(30.minutes)
}
}