From 6a7ccfc48d3ec930390cabfd460730915215f674 Mon Sep 17 00:00:00 2001
From: Matthew Finkel <Matthew.Finkel@gmail.com>
Date: Sat, 24 Nov 2018 04:32:56 +0000
Subject: [PATCH 01/13] Bug 28051 - Build Orbot as a library

---
 app/build.gradle                 | 31 ++++++++++++++++++++-----------
 app/src/main/AndroidManifest.xml | 32 +++++++++++++++++++-------------
 build.gradle                     |  3 ++-
 jsocksAndroid/build.gradle       |  8 +++++---
 orbotservice/build.gradle        | 11 +++++++----
 5 files changed, 53 insertions(+), 32 deletions(-)

diff --git a/app/build.gradle b/app/build.gradle
index ba57f72c..3051dd5c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,12 +1,16 @@
-apply plugin: 'com.android.application'
+// Build it as a library, instead of an app
+apply plugin: 'com.android.library'
 
 android {
-    compileSdkVersion 27
-    buildToolsVersion '27.0.3'
+    // Match Fennec's version
+    compileSdkVersion 26
+    buildToolsVersion '26.0.2'
     defaultConfig {
-        applicationId "org.torproject.android"
+        // Libraries can't have an applicationId
+        //applicationId "org.torproject.android"
         minSdkVersion 16
-        targetSdkVersion 27
+        // Match Fennec's version
+        targetSdkVersion 26
     }
     lintOptions {
         checkReleaseBuilds false
@@ -17,7 +21,8 @@ android {
     buildTypes {
         release {
             minifyEnabled true
-            shrinkResources true
+            // Match Fennec
+            shrinkResources false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
         }
     }
@@ -32,8 +37,10 @@ android {
         fullperm {
             dimension "free"
             minSdkVersion 16
-            applicationId 'org.torproject.android'
-            targetSdkVersion 27
+            // Libraries can't have an applicationId
+            //applicationId 'org.torproject.android'
+            // Match Fennec's versions
+            targetSdkVersion 26
             versionCode 16050100
             versionName '16.0.5-RC-1-tor-0.3.4.9'
             archivesBaseName = "Orbot-$versionName"
@@ -70,9 +77,11 @@ dependencies {
 //    implementation 'com.github.delight-im:Android-Languages:v1.0.1'
     implementation 'com.android.support.constraint:constraint-layout:1.1.3'
     implementation project(':orbotservice')
-    implementation 'com.android.support:design:27.1.1'
+    // Match Fennec's ANDROID_SUPPORT_LIBRARY_VERSION
+    implementation 'com.android.support:design:23.4.0'
     implementation 'pl.bclogic:pulsator4droid:1.0.3'
-    implementation 'com.github.apl-devs:appintro:v4.2.2'
-    implementation 'com.github.javiersantos:AppUpdater:2.6.4'
+    // These require higher versions of ANDROID_SUPPORT_LIBRARY_VERSION
+    //implementation 'com.github.apl-devs:appintro:v4.2.2'
+    //implementation 'com.github.javiersantos:AppUpdater:2.6.4'
 
 }
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 56db8266..2cd00888 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -15,15 +15,13 @@
     <uses-feature android:name="android.hardware.touchscreen"
         android:required="false" />
 
+    <!-- Delete Orbot's name, icon, and label, so they don't conflict with the app -->
+    <!-- Fennec enables hardwareAccelerated= -->
     <application
-        android:name=".OrbotApp"
         android:allowBackup="false"
         android:allowClearUserData="true"
         android:configChanges="locale|orientation|screenSize"
         android:description="@string/app_description"
-        android:hardwareAccelerated="false"
-        android:icon="@drawable/ic_launcher"
-        android:label="@string/app_name"
         android:theme="@style/DefaultTheme"
         tools:replace="android:allowBackup"
         >
@@ -31,10 +29,10 @@
             android:name=".OrbotMainActivity"
             android:excludeFromRecents="true"
             android:launchMode="singleTop">
+            <!-- When Orbot has android.intent.category.LAUNCHER, then a
+                 launcher icon is added on the app menu. We don't want this. -->
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
-                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
             <intent-filter>
                 <action android:name="android.intent.action.VIEW" />
@@ -57,17 +55,20 @@
         </activity>
 
         <!--         This is for ensuring the background service still runs when/if the app is swiped away -->
+        <!-- We want the app and background service to die when the user swipes away the app,
+             so disable this activity -->
         <activity
             android:name=".service.util.DummyActivity"
             android:allowTaskReparenting="true"
             android:alwaysRetainTaskState="false"
             android:clearTaskOnLaunch="true"
-            android:enabled="true"
+            android:enabled="false"
             android:excludeFromRecents="true"
             android:finishOnTaskLaunch="true"
             android:noHistory="true"
             android:stateNotNeeded="true"
             android:theme="@android:style/Theme.Translucent" />
+        <!-- Don't export the VPN functionality, we don't want to use it -->
         <activity
             android:name=".vpn.VPNEnableActivity"
             android:exported="false"
@@ -85,26 +86,29 @@
             android:enabled="true"
             android:permission="android.permission.BIND_VPN_SERVICE"
             android:stopWithTask="false"></service>
+        <!-- Disable the VPN functionality, we don't want to use it -->
         <service
             android:name=".service.vpn.TorVpnService"
-            android:enabled="true"
+            android:enabled="false"
             android:permission="android.permission.BIND_VPN_SERVICE">
             <intent-filter>
                 <action android:name="android.net.VpnService" />
             </intent-filter>
         </service>
 
+        <!-- Don't let other apps start our Orbot -->
         <receiver
             android:name=".service.StartTorReceiver"
-            android:exported="true">
+            android:exported="false">
             <intent-filter>
                 <action android:name="org.torproject.android.intent.action.START" />
             </intent-filter>
         </receiver>
+        <!-- Don't automatically start our Orbot when the device boots -->
         <receiver
             android:name=".OnBootReceiver"
-            android:enabled="true"
-            android:exported="true">
+            android:enabled="false"
+            android:exported="false">
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
 
@@ -154,7 +158,9 @@
                 android:value=".OrbotMainActivity" />
         </activity>
 
-        <activity android:name=".ui.onboarding.OnboardingActivity"/>
+        <!-- Disable the Onboarding activity, because it depends on a library that
+             depends on a newer version of the Android Support Library -->
+        <!--<activity android:name=".ui.onboarding.OnboardingActivity"/>-->
         <activity android:name=".ui.onboarding.BridgeWizardActivity"/>
 
         <provider
@@ -163,4 +169,4 @@
             android:exported="false" />
     </application>
 
-</manifest>
\ No newline at end of file
+</manifest>
diff --git a/build.gradle b/build.gradle
index 553079b6..ce06f082 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,8 @@ buildscript {
         google()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.4'
+        // Match Fennec
+        classpath 'com.android.tools.build:gradle:3.0.1'
     }
 }
 
diff --git a/jsocksAndroid/build.gradle b/jsocksAndroid/build.gradle
index 7ac21e4e..8f173b5f 100644
--- a/jsocksAndroid/build.gradle
+++ b/jsocksAndroid/build.gradle
@@ -1,12 +1,14 @@
 apply plugin: 'com.android.library'
 
 android {
-    compileSdkVersion 27
-    buildToolsVersion '27.0.3'
+    // Match Fennec's version
+    compileSdkVersion 26
+    buildToolsVersion '26.0.2'
 
     defaultConfig {
         minSdkVersion 16
-        targetSdkVersion 27
+        // Match Fennec's version
+        targetSdkVersion 26
     }
 
     buildTypes {
diff --git a/orbotservice/build.gradle b/orbotservice/build.gradle
index fb9b6946..e95f76ac 100644
--- a/orbotservice/build.gradle
+++ b/orbotservice/build.gradle
@@ -1,8 +1,9 @@
 apply plugin: 'com.android.library'
 
 android {
-    compileSdkVersion 27
-    buildToolsVersion '27.0.3'
+    // Match Fennec's version
+    compileSdkVersion 26
+    buildToolsVersion '26.0.2'
 
     sourceSets {
         main {
@@ -12,7 +13,8 @@ android {
 
     defaultConfig {
         minSdkVersion 16
-        targetSdkVersion 27
+        // Match Fennec's version
+        targetSdkVersion 26
         versionCode 1
         versionName "1.0"
 
@@ -28,7 +30,8 @@ android {
 dependencies {
     implementation project(':jsocksAndroid')
     implementation 'org.torproject:tor-android-binary:0.3.4.9'
-    implementation 'com.android.support:appcompat-v7:27.1.1'
+    // Match Fennec's version
+    implementation 'com.android.support:appcompat-v7:23.4.0'
     implementation 'com.jrummyapps:android-shell:1.0.1'
     implementation fileTree(dir: 'libs', include: ['.so'])
     testImplementation 'junit:junit:4.12'
-- 
2.17.1

