[tbb-commits] [Git][tpo/applications/fenix][tor-browser-82.1.1-10.0-1] Bug 40087: Implement a switch for english locale spoofing
Matthew Finkel
gitlab at torproject.org
Fri Oct 23 17:59:16 UTC 2020
Matthew Finkel pushed to branch tor-browser-82.1.1-10.0-1 at The Tor Project / Applications / fenix
Commits:
54f42ec4 by Alex Catarineu at 2020-10-23T17:58:56+00:00
Bug 40087: Implement a switch for english locale spoofing
- - - - -
7 changed files:
- app/src/main/java/org/mozilla/fenix/components/Core.kt
- app/src/main/java/org/mozilla/fenix/settings/advanced/DefaultLocaleSettingsController.kt
- app/src/main/java/org/mozilla/fenix/settings/advanced/LocaleSettingsFragment.kt
- app/src/main/java/org/mozilla/fenix/utils/Settings.kt
- app/src/main/res/layout/fragment_locale_settings.xml
- app/src/main/res/values/preference_keys.xml
- app/src/main/res/values/torbrowser_strings.xml
Changes:
=====================================
app/src/main/java/org/mozilla/fenix/components/Core.kt
=====================================
@@ -93,7 +93,8 @@ class Core(private val context: Context, private val crashReporter: CrashReporti
suspendMediaWhenInactive = false,
forceUserScalableContent = context.settings().forceEnableZoom,
loginAutofillEnabled = context.settings().shouldAutofillLogins,
- torSecurityLevel = context.settings().torSecurityLevel().intRepresentation
+ torSecurityLevel = context.settings().torSecurityLevel().intRepresentation,
+ spoofEnglish = context.settings().spoofEnglish
)
GeckoEngine(
=====================================
app/src/main/java/org/mozilla/fenix/settings/advanced/DefaultLocaleSettingsController.kt
=====================================
@@ -7,6 +7,7 @@ package org.mozilla.fenix.settings.advanced
import android.app.Activity
import android.content.Context
import mozilla.components.support.locale.LocaleManager
+import org.mozilla.fenix.ext.components
import java.util.Locale
interface LocaleSettingsController {
@@ -55,5 +56,9 @@ class DefaultLocaleSettingsController(
config.setLocale(locale)
config.setLayoutDirection(locale)
resources.updateConfiguration(config, resources.displayMetrics)
+ // A slightly hacky way of triggering a `runtime.settings.locales` update,
+ // so that the locales are updated in GeckoView.
+ val spoofEnglish = context.components.core.engine.settings.spoofEnglish
+ context.components.core.engine.settings.spoofEnglish = spoofEnglish
}
}
=====================================
app/src/main/java/org/mozilla/fenix/settings/advanced/LocaleSettingsFragment.kt
=====================================
@@ -20,6 +20,8 @@ import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.locale.LocaleManager
import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
+import org.mozilla.fenix.ext.requireComponents
+import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
class LocaleSettingsFragment : Fragment() {
@@ -38,7 +40,9 @@ class LocaleSettingsFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
- val view = inflater.inflate(R.layout.fragment_locale_settings, container, false)
+ val view = inflater.inflate(R.layout.fragment_locale_settings, container, false).also {
+ bindEnableSwitch(it)
+ }
store = getStore()
interactor = LocaleSettingsInteractor(
@@ -51,6 +55,16 @@ class LocaleSettingsFragment : Fragment() {
return view
}
+ @SuppressWarnings("LongMethod")
+ private fun bindEnableSwitch(view: View) {
+ val switch = view.enable_switch
+ switch.isChecked = requireComponents.core.engine.settings.spoofEnglish
+ switch.setOnCheckedChangeListener { _, isChecked ->
+ context?.settings()?.spoofEnglish = isChecked
+ requireComponents.core.engine.settings.spoofEnglish = isChecked
+ }
+ }
+
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.languages_list, menu)
val searchItem = menu.findItem(R.id.search)
=====================================
app/src/main/java/org/mozilla/fenix/utils/Settings.kt
=====================================
@@ -204,6 +204,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
else -> SecurityLevel.STANDARD
}
+ var spoofEnglish by booleanPreference(
+ appContext.getPreferenceKey(R.string.pref_key_spoof_english),
+ default = false
+ )
+
// If any of the prefs have been modified, quit displaying the fenix moved tip
fun shouldDisplayFenixMovingTip(): Boolean =
preferences.getBoolean(
=====================================
app/src/main/res/layout/fragment_locale_settings.xml
=====================================
@@ -7,13 +7,30 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
+ <com.google.android.material.switchmaterial.SwitchMaterial
+ android:id="@+id/enable_switch"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical|end"
+ android:background="?android:attr/selectableItemBackground"
+ android:checked="true"
+ android:clickable="true"
+ android:focusable="true"
+ android:layout_marginStart="54dp"
+ android:padding="16dp"
+ android:text="@string/tor_spoof_english"
+ android:textColor="?primaryText"
+ android:textSize="16sp"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/locale_container"
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintTop_toBottomOf="@id/enable_switch" />
-</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
+</androidx.constraintlayout.widget.ConstraintLayout>
=====================================
app/src/main/res/values/preference_keys.xml
=====================================
@@ -253,4 +253,6 @@
<string name="pref_key_tor_network_settings_tor_ready">pref_key_tor_network_settings_tor_ready</string>
<string name="pref_key_tor_network_settings_state">pref_key_tor_network_settings_state</string>
<string name="pref_key_tor_network_settings_bridges_enabled">pref_key_tor_network_settings_bridges_enabled</string>
+
+ <string name="pref_key_spoof_english" translatable="false">pref_key_spoof_english</string>
</resources>
=====================================
app/src/main/res/values/torbrowser_strings.xml
=====================================
@@ -70,4 +70,6 @@
<string name="tor_security_level_safest_option">Safest</string>
<string name="tor_security_level_safest_description">Only allow website features required for static sites and basic services. These changes affect images, media, and scripts.</string>
+ <!-- Spoof locale to English -->
+ <string name="tor_spoof_english">Request English versions of web pages for enhanced privacy</string>
</resources>
View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/commit/54f42ec477b781acab908c7043ca1230e13e8442
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/fenix/-/commit/54f42ec477b781acab908c7043ca1230e13e8442
You're receiving this email because of your account on gitlab.torproject.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20201023/f5a7a305/attachment-0001.htm>
More information about the tbb-commits
mailing list