diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 454597e18..713bdf69e 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -48,6 +48,7 @@ import org.mozilla.fenix.GleanMetrics.Metrics import org.mozilla.fenix.GleanMetrics.PerfStartup import org.mozilla.fenix.components.Components import org.mozilla.fenix.components.metrics.MetricServiceType +import org.mozilla.fenix.components.metrics.SecurePrefsTelemetry import org.mozilla.fenix.ext.settings import org.mozilla.fenix.perf.ProfilerMarkerFactProcessor import org.mozilla.fenix.perf.StartupTimeline @@ -218,6 +219,8 @@ open class FenixApplication : LocaleAwareApplication(), Provider { components.core.bookmarksStorage.warmUp() components.core.passwordsStorage.warmUp() } + + SecurePrefsTelemetry(this@FenixApplication, components.analytics.experiments).startTests() } // Account manager initialization needs to happen on the main thread. GlobalScope.launch(Dispatchers.Main) { diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/SecurePrefsTelemetry.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/SecurePrefsTelemetry.kt new file mode 100644 index 000000000..47a34497a --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/SecurePrefsTelemetry.kt @@ -0,0 +1,35 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.components.metrics + +import android.content.Context +import android.os.Build +import mozilla.components.lib.dataprotect.SecurePrefsReliabilityExperiment +import mozilla.components.service.nimbus.NimbusApi +import org.mozilla.fenix.experiments.ExperimentBranch +import org.mozilla.fenix.experiments.Experiments +import org.mozilla.fenix.ext.withExperiment + +/** + * Allows starting a quick test of ACs SecureAbove22Preferences that will emit Facts + * for the basic operations and allow us to log them for later evaluation of APIs stability. + */ +class SecurePrefsTelemetry( + private val appContext: Context, + private val experiments: NimbusApi +) { + suspend fun startTests() { + // The Android Keystore is used to secure the shared prefs only on API 23+ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + // These tests should run only if the experiment is live + experiments.withExperiment(Experiments.ANDROID_KEYSTORE) { experimentBranch -> + // .. and this device is not in the control group. + if (experimentBranch == ExperimentBranch.TREATMENT) { + SecurePrefsReliabilityExperiment(appContext)() + } + } + } + } +} diff --git a/app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt b/app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt index baa800910..9a9a39036 100644 --- a/app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt +++ b/app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt @@ -8,6 +8,7 @@ class Experiments { companion object { const val A_A_NIMBUS_VALIDATION = "fenix-nimbus-validation-v3" const val BOOKMARK_ICON = "fenix-bookmark-list-icon" + const val ANDROID_KEYSTORE = "fenix-android-keystore" } }