Commit 86584f6e authored by Dan Ballard's avatar Dan Ballard Committed by brizental
Browse files

TB 41878: [android] Add standalone Tor Bootstrap

parent 901e38fc
Loading
Loading
Loading
Loading
+2 −0
Changes for mobile/android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2218,6 +2218,8 @@ class GeckoEngine(
        installedExtension.registerTabHandler(webExtensionTabHandler, defaultSettings)
        onSuccess(installedExtension)
    }

    fun getTorIntegrationController() = runtime.getTorIntegrationController()
}

internal fun ContentBlockingController.LogEntry.BlockingData.hasBlockedCookies(): Boolean {
+9 −0
Changes for mobile/android/fenix/app/build.gradle: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
import com.android.build.api.variant.BuildConfigField
import com.android.build.api.variant.FilterConfiguration

import java.time.format.DateTimeFormatter
@@ -295,11 +296,16 @@ androidComponents {
            System.setProperty("nimbusFml",  gradle.mozconfig.substs.NIMBUS_FML)
        }

        def disableTor = providers.gradleProperty("disableTor").getOrElse(false)

        project.logger.debug("----------------------------------------------")
        project.logger.debug("Variant name:      " + variant.name)
        project.logger.debug("Build type:        " + buildType)
        project.logger.debug("Flavor:            " + variant.flavorName)
        project.logger.debug("nimbusFml:         " + providers.gradleProperty("nimbusFml").getOrNull())
        project.logger.debug("Tor is disabled:   " + disableTor)

        variant.buildConfigFields.put("DISABLE_TOR", new BuildConfigField("boolean", "$disableTor", null))

        // This list must stay in sync with the build types that set USE_RELEASE_VERSIONING=true in
        // their buildConfigField. The legacy variant API exposed buildConfigFields on the build type
@@ -695,6 +701,9 @@ dependencies {
    androidTestUtil libs.androidx.test.orchestrator

    lintChecks project(':components:tooling-lint')

    // Tor Expert Bundle
    implementation files(gradle.mozconfig.substs.TOR_EXPERT_BUNDLE_AAR)
}

protobuf {
+9 −0
Changes for mobile/android/fenix/app/src/main/assets/common/torrc-defaults: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
## torrc-defaults for Tor Browser for Android
AvoidDiskWrites 1
# (stderr|stdout|syslog|file FILENAME).
Log notice stdout
CookieAuthentication 1
DormantCanceledByStartup 1
ClientTransportPlugin meek_lite,obfs2,obfs3,obfs4,scramblesuit,webtunnel exec ./libLyrebird.so
ClientTransportPlugin snowflake exec ./libLyrebird.so
ClientTransportPlugin conjure exec ./libConjure.so -registerURL https://registration.refraction.network/api
+3 −1
Changes for mobile/android/fenix/app/src/main/java/org/mozilla/fenix/FenixApplication.kt: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -415,6 +415,8 @@ open class FenixApplication : Application(), Provider, ThemeProvider {
        CoroutineScope(IO).launch {
            components.useCases.wallpaperUseCases.fetchCurrentWallpaperUseCase.invoke()
        }

        components.torController.start()
    }

    @OptIn(DelicateCoroutinesApi::class) // GlobalScope usage
@@ -1120,7 +1122,7 @@ open class FenixApplication : Application(), Provider, ThemeProvider {
            bookmarksSuggestion.set(settings.shouldShowBookmarkSuggestions)
            clipboardSuggestionsEnabled.set(settings.shouldShowClipboardSuggestions)
            voiceSearchEnabled.set(settings.shouldShowVoiceSearch)
            openLinksInAppEnabled.set(settings.openLinksInExternalApp)
            // openLinksInAppEnabled.set(settings.openLinksInExternalApp)
            signedInSync.set(settings.signedInFxaAccount)
            isolatedContentProcessesEnabled.set(settings.isIsolatedProcessEnabled)
            appZygoteIsolatedContentProcessesEnabled.set(settings.isAppZygoteEnabled)
+31 −7
Changes for mobile/android/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt: 31 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

package org.mozilla.fenix

import android.annotation.SuppressLint
import android.app.assist.AssistContent
import android.app.PendingIntent
import android.content.ComponentName
@@ -187,6 +188,7 @@ import org.mozilla.fenix.theme.StatusBarColorManager
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.translations.TranslationsAIControllableFeatureRegistrar
import org.mozilla.fenix.translations.TranslationsEnabledSettings
import org.mozilla.fenix.tor.TorEvents
import org.mozilla.fenix.utils.AccessibilityUtils.announcePrivateModeForAccessibility
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.utils.changeAppLauncherIcon
@@ -967,7 +969,26 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity, Crash
    /**
     * Handles intents received when the activity is open.
     */
    @SuppressLint("MissingSuperCall") // super.onNewIntent is called in [onNewIntentInternal(intent)]
    final override fun onNewIntent(intent: Intent) {
        if (intent.action == ACTION_MAIN || components.torController.isBootstrapped) {
            onNewIntentInternal(intent)
        } else {
            // Wait until Tor is connected to handle intents from external apps for links, search, etc.
            components.torController.registerTorListener(object : TorEvents {
                override fun onTorConnected() {
                    components.torController.unregisterTorListener(this)
                    onNewIntentInternal(intent)
                }
                override fun onTorConnecting() { /* no-op */ }
                override fun onTorStopped() { /* no-op */ }
                override fun onTorStatusUpdate(entry: String?, status: String?, progress: Double?) { /* no-op */ }
            })
            return
        }
    }

    private fun onNewIntentInternal(intent: Intent) {
        super.onNewIntent(intent)
        handleNewIntent(intent)
        startupPathProvider.onIntentReceived(intent)
@@ -1443,11 +1464,11 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity, Crash

    @VisibleForTesting
    internal fun navigateToHome(navController: NavController) {
        if (this is ExternalAppBrowserActivity) {
            return
        }
        // if (this is ExternalAppBrowserActivity) {
        //     return
        // }

        navController.navigate(NavGraphDirections.actionStartupHome())
        navController.navigate(NavGraphDirections.actionStartupTorbootstrap())
    }

    final override fun attachBaseContext(base: Context) {
@@ -1592,14 +1613,17 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity, Crash

    /**
     *  Indicates if the user should be redirected to the [BrowserFragment] or to the [HomeFragment],
     *  links from an external apps should always opened in the [BrowserFragment].
     *  links from an external apps should always opened in the [BrowserFragment],
     *  unless Tor is not yet connected.
     */
    @VisibleForTesting
    internal fun shouldStartOnHome(intent: Intent? = this.intent): Boolean {
        return components.strictMode.allowViolation(StrictMode::allowThreadDiskReads) {
            // We only want to open on home when users tap the app,
            // we want to ignore other cases when the app gets open by users clicking on links.
            getSettings().shouldStartOnHome() && intent?.action == ACTION_MAIN
            // we want to ignore other cases when the app gets open by users clicking on links,
            // unless Tor is not yet connected.
            getSettings().shouldStartOnHome() && (intent?.action == ACTION_MAIN ||
                    !components.torController.isBootstrapped)
        }
    }

Loading