Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 2ff1d24

Browse files
committed
Bug 1944956 - Part 1: Add simple privacy pref repository r=android-reviewers,gmalekpour,twhite
Adding a simplied repository to replace the existing one. Differential Revision: https://phabricator.services.mozilla.com/D236294
1 parent 0bac0d4 commit 2ff1d24

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package org.mozilla.fenix.onboarding.store
6+
7+
import org.mozilla.fenix.utils.Settings
8+
9+
/**
10+
* The repository for managing user privacy preferences set during onboarding.
11+
*/
12+
interface SimplePrivacyPreferencesRepository {
13+
14+
/**
15+
* Retrieves the state of a specific preference.
16+
*
17+
* @param type The type of preference to retrieve.
18+
* @return Returns `true` if the preference is enabled.
19+
*/
20+
fun getPrivacyPreference(type: PreferenceType): Boolean
21+
22+
/**
23+
* Updates a specific preference.
24+
*
25+
* @param type The type of preference to modify.
26+
* @param enabled The new state of the preference.
27+
*/
28+
fun setPrivacyPreference(type: PreferenceType, enabled: Boolean)
29+
}
30+
31+
/**
32+
* Enum representing the types of privacy preferences available.
33+
*/
34+
enum class PreferenceType {
35+
CrashReporting, UsageData,
36+
}
37+
38+
/**
39+
* The default implementation of [SimplePrivacyPreferencesRepository].
40+
*
41+
* @param settings The [Settings] instance for accessing and modifying privacy-related settings.
42+
*/
43+
class DefaultSimplePrivacyPreferencesRepository(
44+
private val settings: Settings,
45+
) : SimplePrivacyPreferencesRepository {
46+
47+
override fun getPrivacyPreference(type: PreferenceType): Boolean {
48+
return when (type) {
49+
PreferenceType.CrashReporting -> settings.crashReportAlwaysSend
50+
PreferenceType.UsageData -> settings.isTelemetryEnabled
51+
}
52+
}
53+
54+
override fun setPrivacyPreference(
55+
type: PreferenceType,
56+
enabled: Boolean,
57+
) {
58+
when (type) {
59+
PreferenceType.CrashReporting -> settings.crashReportAlwaysSend = enabled
60+
PreferenceType.UsageData -> settings.isTelemetryEnabled = enabled
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)