Unverified Commit fcec39d1 authored by Matthew Finkel's avatar Matthew Finkel
Browse files

Add Tor integration and UI

Bug 40001: Start Tor as part of the Fenix initialization

Bug 40028: Implement Tor Service controller

Bug 40028: Integrate Tor Controller into HomeFragment

Bug 40028: Implement Tor connect and logger screens

Bug 40028: Implement Tor Onboarding

Bug 40028: Implement new home screen

Bug 40028: Define bootstrapping events and Quick Start

Bug 40041: Implement Tor Network Settings

Bug 40041: Integrate Tor Network Settings

Bug 40179: Show Snowflake bridge option on Release
parent 77eb8a1c
Loading
Loading
Loading
Loading
+35 −6
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ default:
        - 32GB

    before_script:
        - set -e

        # Prepare our Debian environment.
        - apt-get update -qq
        - apt-get upgrade -qy
@@ -47,6 +49,33 @@ default:
        # Create local.properties file.
        - echo "sdk.dir=$PWD" > local.properties

        # Fetch tor library build dependencies
        - wget --quiet https://people.torproject.org/~sysrqb/mirrors/tor-onion-proxy-library/0.0.3/android-release.aar
        - wget --quiet https://people.torproject.org/~sysrqb/mirrors/tor-onion-proxy-library/0.0.3/universal-0.0.3.jar
        - wget --quiet https://people.torproject.org/~sysrqb/mirrors/tor-android-service/1.0/jsocksAndroid-release.aar
        - wget --quiet https://people.torproject.org/~sysrqb/mirrors/tor-android-service/1.0/service-release.aar
        - wget --quiet https://people.torproject.org/~sysrqb/mirrors/tor/0.4.4.4-rc/tor_x86.tar.gz
        - wget --quiet https://people.torproject.org/~sysrqb/mirrors/tor/0.4.4.4-rc/tor_x86_64.tar.gz
        - wget --quiet https://people.torproject.org/~sysrqb/mirrors/tor/0.4.4.4-rc/tor_armv7.tar.gz
        - wget --quiet https://people.torproject.org/~sysrqb/mirrors/tor/0.4.4.4-rc/tor_aarch64.tar.gz

        - echo "4e2bd087df6128a31c598d297367c106762f539c25d71cc343aae25386e4bee9  android-release.aar" | sha256sum -c
        - echo "0082d1d035a0808d03d7e1009398ed2c3e3ea4c51811198f6ff83ccda456036f  universal-0.0.3.jar" | sha256sum -c
        - echo "3dca44a48fdbd3f6c44f7ea335ae85fe542676d8e48c6438f84a2c852daf4f54  jsocksAndroid-release.aar" | sha256sum -c
        - echo "d38967569af56d809f09f08b888962971149411832c3bc2b7b0b64a43ceb0dcd  service-release.aar" | sha256sum -c
        - echo "0faa344f658d2e38c7cc881f51c1d8658aac56801f7def1b75be72a8d3f90c54  tor_x86.tar.gz" | sha256sum -c
        - echo "acf1d403ca12e3302d1150d2b5fba6585aa83d46db16f15ad33fae39645c5b5d  tor_x86_64.tar.gz" | sha256sum -c
        - echo "132cb40bbc15bd8f72abd15324705ab720f8b316a2fca84baaeb5db37f602c32  tor_armv7.tar.gz" | sha256sum -c
        - echo "6c453c5f7566c87d422ef60750cba794d9616e9197114be5dc1194f75b55b04e  tor_aarch64.tar.gz" | sha256sum -c

        - mv android-release.aar universal-0.0.3.jar jsocksAndroid-release.aar service-release.aar app/

        - tar -C app/src/main -xf tor_x86.tar.gz
        - tar -C app/src/main -xf tor_x86_64.tar.gz
        - tar -C app/src/main -xf tor_armv7.tar.gz
        - tar -C app/src/main -xf tor_aarch64.tar.gz
        - rm tor_x86.tar.gz tor_x86_64.tar.gz tor_armv7.tar.gz tor_aarch64.tar.gz

stages:
    - build
    - buildFenixProduction
@@ -57,7 +86,7 @@ stages:
buildDebug:
    stage: build
    script:
        - ./gradlew clean app:assembleDebug --stacktrace
        - ./gradlew -PdisableTor=true clean app:assembleDebug --stacktrace

    # Disable for now.
    #artifacts:
@@ -71,7 +100,7 @@ testLight:
        # from config/pre-push-recommended.sh
        # `tee` into a log file because resulting output is larger than 4 MB
        # (4 MB is max log size)
        - ./gradlew ktlint detekt assembleDebug assembleDebugAndroidTest testDebug | tee testLight_gradle.log
        - ./gradlew -PdisableTor=true ktlint detekt assembleDebug assembleDebugAndroidTest testDebug | tee testLight_gradle.log
    artifacts:
        paths:
            - testLight_gradle.log
@@ -85,25 +114,25 @@ buildFenixProduction:
    only:
        - schedules
    script:
        - ./gradlew clean app:assembleNightly --stacktrace
        - ./gradlew -PdisableTor=true clean app:assembleNightly --stacktrace

buildFennecBeta:
    stage: buildFennecBeta
    only:
        - schedules
    script:
        - ./gradlew clean app:assembleBeta --stacktrace
        - ./gradlew -PdisableTor=true clean app:assembleBeta --stacktrace

buildFennecProduction:
    stage: buildFennecProduction
    only:
        - schedules
    script:
        - ./gradlew clean app:assembleRelease --stacktrace
        - ./gradlew -PdisableTor=true clean app:assembleRelease --stacktrace

testAll:
    stage: test
    only:
        - schedules
    script:
        - ./gradlew clean test
        - ./gradlew -PdisableTor=true clean test
+20 −0
Original line number Diff line number Diff line
@@ -246,12 +246,20 @@ android.applicationVariants.all { variant ->
    def useReleaseVersioning = variant.buildType.buildConfigFields['USE_RELEASE_VERSIONING']?.value ?: false
    def versionName = variant.buildType.name == 'nightly' ? Config.nightlyVersionName() : Config.releaseVersionName(project)

    def disableTor = false
    if (project.hasProperty("disableTor")) {
        disableTor = project.getProperty("disableTor")
    }

    println("----------------------------------------------")
    println("Variant name:      " + variant.name)
    println("Application ID:    " + [variant.mergedFlavor.applicationId, variant.buildType.applicationIdSuffix].findAll().join())
    println("Build type:        " + variant.buildType.name)
    println("Flavor:            " + variant.flavorName)
    println("Telemetry enabled: " + !isDebugOrDCD)
    println("Tor is disabled:   " + disableTor)

    buildConfigField "boolean", "DISABLE_TOR", "$disableTor"

    if (useReleaseVersioning) {
        // The Google Play Store does not allow multiple APKs for the same app that all have the
@@ -580,6 +588,18 @@ dependencies {
    testImplementation "org.mozilla.telemetry:glean-forUnitTests:${project.ext.glean_version}"

    lintChecks project(":mozilla-lint-rules")

    // Tor Android Services Dependencies
    implementation 'net.freehaven.tor.control:jtorctl:0.2'
    implementation 'org.slf4j:slf4j-api:1.7.25'
    implementation 'org.slf4j:slf4j-android:1.7.25'

    // Tor Android Services.
    implementation files('service-release.aar')

    // Tor Onion Proxy Library.
    implementation files('universal-0.0.3.jar')
    implementation files('android-release.aar')
}

if (project.hasProperty("coverage")) {
+7 −0
Original line number Diff line number Diff line
@@ -292,6 +292,13 @@
            android:name="androidx.work.impl.WorkManagerInitializer"
            android:authorities="${applicationId}.workmanager-init"
            tools:node="remove" />
        <!-- Define Orbotservice's TorService -->
        <service
            android:name="org.torproject.android.service.TorService"
            android:enabled="true"
            android:exported="false"
            android:stopWithTask="true">
        </service>
    </application>

</manifest>
+24 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MozillaProductDetector
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.utils.Settings
import org.torproject.android.service.util.Prefs

/**
 *The main application class for Fenix. Records data to measure initialization performance.
@@ -87,6 +88,8 @@ open class FenixApplication : LocaleAwareApplication(), Provider {

    private val logger = Logger("FenixApplication")

    var terminating = false

    open val components by lazy { Components(this) }

    var visibilityLifecycleCallback: VisibilityLifecycleCallback? = null
@@ -125,6 +128,21 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
        PerfStartup.applicationOnCreate.stopAndAccumulate(completeMethodDurationTimerId)
    }

    fun isTerminating() = terminating

    fun terminate() {
        onTerminate()
        System.exit(0)
    }

    override fun onTerminate() {
        terminating = true

        super.onTerminate()
        components.torController.stop()
        components.torController.stopTor()
    }

    protected open fun initializeGlean() {
        val telemetryEnabled = settings().isTelemetryEnabled

@@ -184,6 +202,11 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
                    runBlockingIncrement { megazordSetup.await() }
                }
            }

            GlobalScope.launch(Dispatchers.IO) {
                // Give TAS the base Context
                Prefs.setContext(applicationContext)
            }
        }

        PerfStartup.appOnCreateToSetupInMain.measureNoInline {
@@ -207,6 +230,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
            ProcessLifecycleOwner.get().lifecycle.addObserver(TelemetryLifecycleObserver(components.core.store))

            components.appStartupTelemetry.onFenixApplicationOnCreate()
            components.torController.start()
        }
    }

+13 −0
Original line number Diff line number Diff line
@@ -145,6 +145,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {

    private var isToolbarInflated = false

    private var isBeingRecreated = false

    private val webExtensionPopupFeature by lazy {
        WebExtensionPopupFeature(components.core.store, ::openPopup)
    }
@@ -180,6 +182,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
        components.core.engine.profiler?.addMarker("Activity.onCreate", "HomeActivity")

        components.strictMode.attachListenerToDisablePenaltyDeath(supportFragmentManager)

        // There is disk read violations on some devices such as samsung and pixel for android 9/10
        components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
            // Theme setup should always be called before super.onCreate
@@ -447,6 +450,14 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
        )

        privateNotificationObserver?.stop()
        if (!isBeingRecreated && !(application as FenixApplication).isTerminating()) {
            // We assume the Activity is being destroyed because the user
            // swiped away the app on the Recent screen. When this happens,
            // we assume the user expects the entire Application is destroyed
            // and not only the top Activity/Task. Therefore we kill the
            // underlying Application, as well.
            (application as FenixApplication).terminate()
        }
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
@@ -466,6 +477,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
            message = "recreate()"
        )

        isBeingRecreated = true

        super.recreate()
    }

Loading