Skip to content
Snippets Groups Projects
Commit cd3473f6 authored by clairehurst's avatar clairehurst
Browse files

fixup! Add Tor integration and UI

Remove quick start
parent 6c3669ee
Branches
Tags
1 merge request!48Bug 41188: Implement Android-native Connection Assist UI
......@@ -115,7 +115,6 @@ import org.mozilla.fenix.search.toolbar.SearchSelectorMenu
import org.mozilla.fenix.tabstray.TabsTrayAccessPoint
import org.mozilla.fenix.tor.TorBootstrapFragmentDirections
import org.mozilla.fenix.tor.TorBootstrapStatus
import org.mozilla.fenix.tor.bootstrap.TorQuickStart
import org.mozilla.fenix.utils.Settings.Companion.TOP_SITES_PROVIDER_MAX_THRESHOLD
import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.wallpapers.Wallpaper
......@@ -202,7 +201,6 @@ class HomeFragment : Fragment() {
private val recentBookmarksFeature = ViewBoundFeatureWrapper<RecentBookmarksFeature>()
private val historyMetadataFeature = ViewBoundFeatureWrapper<RecentVisitsFeature>()
private val searchSelectorBinding = ViewBoundFeatureWrapper<SearchSelectorBinding>()
private val torQuickStart by lazy { TorQuickStart(requireContext()) }
private val searchSelectorMenuBinding = ViewBoundFeatureWrapper<SearchSelectorMenuBinding>()
private lateinit var torBootstrapStatus: TorBootstrapStatus
......@@ -236,7 +234,6 @@ class HomeFragment : Fragment() {
val components = requireComponents
torBootstrapStatus = TorBootstrapStatus(
torQuickStart,
!BuildConfig.DISABLE_TOR,
components.torController,
::dispatchModeChanges
......
......@@ -8,14 +8,12 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.VisibleForTesting
import androidx.core.view.children
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.databinding.FragmentHomeBinding
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.tor.bootstrap.TorQuickStart
import org.mozilla.fenix.tor.interactor.DefaultTorBootstrapInteractor
import org.mozilla.fenix.tor.interactor.TorBootstrapInteractor
import androidx.navigation.fragment.findNavController
......@@ -30,7 +28,6 @@ import org.mozilla.fenix.tor.view.TorBootstrapView
@Suppress("TooManyFunctions", "LargeClass")
class TorBootstrapFragment : Fragment() {
private val torQuickStart by lazy { TorQuickStart(requireContext()) }
internal var _binding: FragmentHomeBinding? = null
private val binding get() = _binding!!
......@@ -55,7 +52,6 @@ class TorBootstrapFragment : Fragment() {
val components = requireComponents
torBootstrapStatus = TorBootstrapStatus(
torQuickStart,
!BuildConfig.DISABLE_TOR,
components.torController,
::dispatchModeChanges
......
......@@ -4,11 +4,8 @@
package org.mozilla.fenix.tor
import org.mozilla.fenix.tor.bootstrap.TorQuickStart
@SuppressWarnings("LongParameterList", "TooManyFunctions")
class TorBootstrapStatus(
private val torQuickStart: TorQuickStart,
private val shouldStartTor: Boolean,
private val torController: TorController,
private val dispatchModeChanges: (isShouldBootstrap: Boolean) -> Unit
......@@ -18,7 +15,7 @@ class TorBootstrapStatus(
torController.registerTorListener(this)
}
fun isBootstrapping() = (shouldStartTor && (!torQuickStart.quickStartTor() && !torController.isBootstrapped))
fun isBootstrapping() = (shouldStartTor && !torController.isBootstrapped)
@SuppressWarnings("EmptyFunctionBlock")
......
......@@ -52,7 +52,7 @@ class TorControllerGV(
private var torListeners = mutableListOf<TorEvents>()
private var lastKnownStatus = TorConnectState.Initial
internal var lastKnownStatus = TorConnectState.Initial
private var wasTorBootstrapped = false
private var isTorRestarting = false
......@@ -66,6 +66,17 @@ class TorControllerGV(
override val isBootstrapped get() = isTorBootstrapped
override val isConnected get() = (lastKnownStatus.isStarted() && !isTorRestarting)
override var quickstart: Boolean
get() {
return getTorSettings()?.quickstart ?: false
}
set(value) {
getTorSettings()?.let {
it.quickstart = value
getTorIntegration().setSettings(it, true, true)
}
}
private fun getTorIntegration(): TorIntegrationAndroid {
return (context.components.core.engine as GeckoEngine).getTorIntegrationController()
}
......@@ -198,7 +209,7 @@ class TorControllerGV(
}
override fun setTorStopped() {
lastKnownStatus = TorConnectState.Disabled
lastKnownStatus = TorConnectState.Configuring
onTorStopped()
}
......@@ -243,7 +254,7 @@ class TorControllerGV(
if (isTorRestarting) {
initiateTorBootstrap()
} else {
onTorStopped()
setTorStopped()
}
}
......@@ -280,6 +291,7 @@ class TorControllerGV(
// TorEventsBootstrapStateChangeListener
override fun onBootstrapError(message: String?, details: String?) {
lastKnownStatus = TorConnectState.Error
onBootstrapStateChange(TorConnectState.Error.state)
}
// TorEventsBootstrapStateChangeListener
......
/* 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.tor.bootstrap
import android.content.Context
import android.content.SharedPreferences
import android.os.StrictMode
import androidx.annotation.VisibleForTesting
import mozilla.components.support.ktx.android.content.PreferencesHolder
import mozilla.components.support.ktx.android.content.booleanPreference
import org.mozilla.fenix.ext.components
class TorQuickStart(val context: Context) : PreferencesHolder {
override val preferences: SharedPreferences =
context.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
context.getSharedPreferences(
PREF_NAME_TOR_BOOTSTRAP_KEY,
Context.MODE_PRIVATE
)
}
private var torQuickStart by booleanPreference(TOR_QUICK_START, default = false)
fun quickStartTor() =
context.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) { torQuickStart }
fun enableQuickStartTor() {
torQuickStart = true
}
fun disableQuickStartTor() {
torQuickStart = false
}
fun setQuickStartTor(enabled: Boolean) = if (enabled) {
enableQuickStartTor()
} else {
disableQuickStartTor()
}
companion object {
/**
* Name of the shared preferences file.
*/
private const val PREF_NAME_TOR_BOOTSTRAP_KEY = "tor.bootstrap"
/**
* Key for [quickStartTor].
*/
@VisibleForTesting
internal const val TOR_QUICK_START = "tor.bootstrap.quick_start_enabled"
}
}
......@@ -10,7 +10,6 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.databinding.TorBootstrapConnectBinding
import org.mozilla.fenix.tor.TorEvents
import org.mozilla.fenix.tor.bootstrap.TorQuickStart
import org.mozilla.fenix.tor.interactor.TorBootstrapInteractor
class TorBootstrapConnectViewHolder(
......@@ -23,17 +22,6 @@ class TorBootstrapConnectViewHolder(
init {
binding = TorBootstrapConnectBinding.bind(view)
val torQuickStart = TorQuickStart(view.context)
setQuickStartDescription(view, torQuickStart)
with(binding.quickStartToggle) {
setOnCheckedChangeListener { _, isChecked ->
torQuickStart.setQuickStartTor(isChecked)
setQuickStartDescription(view, torQuickStart)
}
isChecked = torQuickStart.quickStartTor()
}
with(binding.torBootstrapNetworkSettingsButton) {
setOnClickListener {
......@@ -66,20 +54,6 @@ class TorBootstrapConnectViewHolder(
components.torController.registerTorListener(this)
}
private fun setQuickStartDescription(view: View, torQuickStart: TorQuickStart) {
val resources = view.context.resources
val appName = resources.getString(R.string.app_name)
if (torQuickStart.quickStartTor()) {
binding.torBootstrapQuickStartDescription.text = resources.getString(
R.string.tor_bootstrap_quick_start_enabled, appName
)
} else {
binding.torBootstrapQuickStartDescription.text = resources.getString(
R.string.tor_bootstrap_quick_start_disabled
)
}
}
@SuppressWarnings("EmptyFunctionBlock")
override fun onTorConnecting() {
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment