fenix-use-unifiedpush.patch raw
1 diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt
2 index 1cbed0f443a5..e8c9db45a476 100644
3 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt
4 +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt
5 @@ -220,7 +220,7 @@ class Components(private val context: Context) {
6 val publicSuffixList by lazyMonitored { PublicSuffixList(context) }
7 val clipboardHandler by lazyMonitored { ClipboardHandler(context) }
8 val performance by lazyMonitored { PerformanceComponent() }
9 - val push by lazyMonitored { Push(context, analytics.crashReporter) }
10 + val push by lazyMonitored { Push(context) }
11 val wifiConnectionMonitor by lazyMonitored { WifiConnectionMonitor(context as Application) }
12
13 val strictMode by lazyMonitored {
14 diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Push.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Push.kt
15 index 98a10159bff3..63c189a82256 100644
16 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Push.kt
17 +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Push.kt
18 @@ -31,7 +31,7 @@ class Push(val context: Context, val strictMode: StrictModeManager = context.com
19 private val logger = Logger("Push")
20 val feature: Pusher?
21 get() = strictMode.allowViolation(StrictMode::allowThreadDiskReads) {
22 - if (context.settings().ironfox.useUnifiedPush) {
23 + if (context.settings().useUnifiedPush) {
24 unifiedPushFeature.also { feature ->
25 if (feature.isAvailable(context)) {
26 logger.info("Using UnifiedPush")
27 @@ -50,7 +50,7 @@ class Push(val context: Context, val strictMode: StrictModeManager = context.com
28 notificationId = notificationId,
29 notification = notification
30 )
31 - context.settings().ironfox.useUnifiedPush = false
32 + context.settings().useUnifiedPush = false
33 }
34 }
35 } else {
36 diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt
37 index e6c28d967904..a3f7fbc0cd3d 100644
38 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt
39 +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt
40 @@ -220,6 +220,12 @@ class SecretSettingsFragment : PreferenceFragmentCompat() {
41 onPreferenceChangeListener = SharedPreferenceUpdater()
42 }
43
44 + requirePreference<SwitchPreference>(R.string.pref_key_enable_unifiedpush).apply {
45 + isVisible = true
46 + isChecked = context.settings().enableUnifiedPush
47 + onPreferenceChangeListener = SharedPreferenceUpdater()
48 + }
49 +
50 requirePreference<SwitchPreference>(R.string.pref_key_enable_address_sync).apply {
51 isVisible = Config.channel.isNightlyOrDebug
52 isChecked = context.settings().isAddressSyncEnabled
53 diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
54 index c47237dd222c..cb0fa7e69856 100644
55 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
56 +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
57 @@ -438,6 +438,48 @@ class SettingsFragment : PreferenceFragmentCompat() {
58 null
59 }
60
61 + // Only displayed when UnifiedPush is enabled
62 + resources.getString(R.string.pref_key_use_unifiedpush) -> {
63 + val context = requireActivity()
64 + context.settings().apply { useUnifiedPush = !useUnifiedPush }
65 + val alert = MaterialAlertDialogBuilder(context).apply {
66 + setTitle(context.getString(R.string.preferences_unifiedpush))
67 + setMessage(context.getString(R.string.quit_application))
68 + setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _ ->
69 + dialog.cancel()
70 + }
71 +
72 + setPositiveButton(android.R.string.ok) { _, _ ->
73 + Toast.makeText(
74 + context,
75 + getString(R.string.toast_change_unifiedpush_done),
76 + Toast.LENGTH_LONG,
77 + ).show()
78 +
79 + Handler(Looper.getMainLooper()).postDelayed(
80 + {
81 + exitProcess(0)
82 + },
83 + FXA_SYNC_OVERRIDE_EXIT_DELAY,
84 + )
85 + }
86 + create().withCenterAlignedButtons()
87 + }
88 + if (context.settings().useUnifiedPush) {
89 + requireComponents.push.switchToUnifiedPush(context) { success ->
90 + if (!success) {
91 + context.settings().useUnifiedPush = false
92 + } else {
93 + alert.show()
94 + }
95 + }
96 + } else {
97 + requireComponents.push.switchToAutoPush(context)
98 + alert.show()
99 + }
100 + null
101 + }
102 +
103 // Only displayed when secret settings are enabled
104 resources.getString(R.string.pref_key_override_amo_collection) -> {
105 val context = requireContext()
106 @@ -578,6 +620,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
107 findPreference<Preference>(getPreferenceKey(R.string.pref_key_start_profiler))
108
109 with(settings) {
110 + findPreference<SwitchPreference>(
111 + getPreferenceKey(R.string.pref_key_use_unifiedpush),
112 + )?.apply {
113 + isVisible = enableUnifiedPush
114 + isChecked = useUnifiedPush
115 + }
116 findPreference<Preference>(
117 getPreferenceKey(R.string.pref_key_nimbus_experiments),
118 )?.isVisible = showSecretDebugMenuThisSession
119 diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
120 index 83b0cb19b298..819eb3d2c2e4 100644
121 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
122 +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
123 @@ -2174,6 +2174,22 @@ class Settings(
124 }
125 }
126
127 + /**
128 + * Indicates if UnifiedPush can be used
129 + */
130 + var enableUnifiedPush by booleanPreference(
131 + key = appContext.getPreferenceKey(R.string.pref_key_enable_unifiedpush),
132 + default = true,
133 + )
134 +
135 + /**
136 + * Indicates if UnifiedPush is used
137 + */
138 + var useUnifiedPush by booleanPreference(
139 + key = appContext.getPreferenceKey(R.string.pref_key_use_unifiedpush),
140 + default = false,
141 + )
142 +
143 /**
144 * Get the current mode for cookie banner handling
145 */
146 diff --git a/mobile/android/fenix/app/src/main/res/values/preference_keys.xml b/mobile/android/fenix/app/src/main/res/values/preference_keys.xml
147 index 1d38ede30cc7..e1459e2af3a8 100644
148 --- a/mobile/android/fenix/app/src/main/res/values/preference_keys.xml
149 +++ b/mobile/android/fenix/app/src/main/res/values/preference_keys.xml
150 @@ -432,6 +432,8 @@
151 <string name="pref_key_pocket_sponsored_stories" translatable="false">pref_key_pocket_sponsored_stories</string>
152
153 <!-- Secret Info Setting Keys -->
154 + <string name="pref_key_enable_unifiedpush" translatable="false">pref_key_enable_unifiedpush</string>
155 + <string name="pref_key_use_unifiedpush" translatable="false">pref_key_use_unifiedpush</string>
156 <string name="pref_key_secret_debug_info" translatable="false">pref_key_secret_debug_info</string>
157 <string name="pref_key_start_profiler" translatable="false">pref_key_start_profiler</string>
158
159 diff --git a/mobile/android/fenix/app/src/main/res/values/static_strings.xml b/mobile/android/fenix/app/src/main/res/values/static_strings.xml
160 index cc62cedb1265..8a1ec895ea39 100644
161 --- a/mobile/android/fenix/app/src/main/res/values/static_strings.xml
162 +++ b/mobile/android/fenix/app/src/main/res/values/static_strings.xml
163 @@ -61,6 +61,8 @@
164 <string name="preferences_sync_debug_temporary_auth_error_button_title">Simulate temporary account auth error</string>
165 <!-- Button title for simulating an FxA permanent auth error inside the Sync Debug menu -->
166 <string name="preferences_sync_debug_permanent_auth_error_button_title">Simulate permanent account auth error</string>
167 + <!-- Label for enabling UnifiedPush -->
168 + <string name="preferences_debug_settings_unifiedpush" translatable="false">Enable UnifiedPush</string>
169 <!-- Label for enabling the Homepage Search Bar -->
170 <string name="preferences_debug_settings_homepage_searchbar" translatable="false">Enable Homepage Search Bar</string>
171 <!-- Label for enabling Homepage as a New Tab -->
172 diff --git a/mobile/android/fenix/app/src/main/res/values/strings.xml b/mobile/android/fenix/app/src/main/res/values/strings.xml
173 index d37bc1885f10..37040d026c85 100644
174 --- a/mobile/android/fenix/app/src/main/res/values/strings.xml
175 +++ b/mobile/android/fenix/app/src/main/res/values/strings.xml
176 @@ -926,6 +926,13 @@
177 <!-- Message to indicate users that we are quitting the application to apply the changes -->
178 <string name="quit_application">Quitting the application to apply changes…</string>
179
180 + <!-- Label for using UnifiedPush. UnifiedPush is a decentralized push notification system, so users can benefit from mobile push notifications without relying on Google Services. Users choose the application (and server) they wish to use to manage webpush for other applications. If enabled, the browser (e.g. Firefox for Android) will receive webpush messages via the chosen app. -->
181 + <string name="preferences_unifiedpush">Use UnifiedPush</string>
182 + <!-- The application must be restarted for the UnifiedPush setting to take effect. -->
183 + <string name="preferences_unifiedpush_summary">Requires restart</string>
184 + <!-- Toast shown after confirming the UnifiedPush configuration -->
185 + <string name="toast_change_unifiedpush_done">UnifiedPush setting modified. Quitting the application to apply changes…</string>
186 +
187 <!-- Preference for extensions -->
188 <string name="preferences_extensions">Extensions</string>
189 <!-- Preference for installing a local extension -->
190 diff --git a/mobile/android/fenix/app/src/main/res/xml/preferences.xml b/mobile/android/fenix/app/src/main/res/xml/preferences.xml
191 index bb261eb1738e..c341630ece75 100644
192 --- a/mobile/android/fenix/app/src/main/res/xml/preferences.xml
193 +++ b/mobile/android/fenix/app/src/main/res/xml/preferences.xml
194 @@ -190,6 +190,13 @@
195 app:isPreferenceVisible="false"
196 android:title="@string/firefox_labs_title" />
197
198 + <androidx.preference.SwitchPreference
199 + android:defaultValue="false"
200 + android:key="@string/pref_key_use_unifiedpush"
201 + app:iconSpaceReserved="false"
202 + android:title="@string/preferences_unifiedpush"
203 + android:summary="@string/preferences_unifiedpush_summary"/>
204 +
205 <androidx.preference.SwitchPreference
206 android:key="@string/pref_key_leakcanary"
207 android:title="@string/preference_leakcanary"
208 diff --git a/mobile/android/fenix/app/src/main/res/xml/secret_settings_preferences.xml b/mobile/android/fenix/app/src/main/res/xml/secret_settings_preferences.xml
209 index b23d258a4df0..b9e8368b19f8 100644
210 --- a/mobile/android/fenix/app/src/main/res/xml/secret_settings_preferences.xml
211 +++ b/mobile/android/fenix/app/src/main/res/xml/secret_settings_preferences.xml
212 @@ -15,6 +15,11 @@
213 android:key="@string/pref_key_nimbus_use_preview"
214 android:title="@string/preferences_nimbus_use_preview_collection"
215 app:iconSpaceReserved="false" />
216 + <SwitchPreference
217 + android:defaultValue="false"
218 + android:key="@string/pref_key_enable_unifiedpush"
219 + android:title="@string/preferences_debug_settings_unifiedpush"
220 + app:iconSpaceReserved="false" />
221 <SwitchPreference
222 android:defaultValue="false"
223 android:key="@string/pref_key_enable_address_sync"
224