[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] app-mini project builds again
commit b9d2f90d2507b065b357c800d239caf814086cff
Author: bim <dsnake@xxxxxxxxxxxxxx>
Date: Fri Jul 10 21:53:24 2020 -0400
app-mini project builds again
Applies the changes to the app-mini project that were in commit
ec47151a0c5e9bf789c38a9f36820031241b54f4
Notably the project not building confused people cloning the
repository, see issue #348
---
app-mini/src/main/AndroidManifest.xml | 4 -
.../torproject/android/mini/MiniMainActivity.java | 52 ++++-----
.../torproject/android/mini/OnBootReceiver.java | 25 +----
.../android/mini/vpn/VPNEnableActivity.java | 121 ---------------------
4 files changed, 28 insertions(+), 174 deletions(-)
diff --git a/app-mini/src/main/AndroidManifest.xml b/app-mini/src/main/AndroidManifest.xml
index 5da4d86e..6e73081a 100644
--- a/app-mini/src/main/AndroidManifest.xml
+++ b/app-mini/src/main/AndroidManifest.xml
@@ -50,10 +50,6 @@
android:noHistory="true"
android:stateNotNeeded="true"
android:theme="@android:style/Theme.Translucent" />
- <activity
- android:name=".vpn.VPNEnableActivity"
- android:exported="false"
- android:label="@string/app_name" />
<activity
android:name=".settings.SettingsPreferences"
android:label="@string/app_name" />
diff --git a/app-mini/src/main/java/org/torproject/android/mini/MiniMainActivity.java b/app-mini/src/main/java/org/torproject/android/mini/MiniMainActivity.java
index 7ef51c52..f697bcea 100644
--- a/app-mini/src/main/java/org/torproject/android/mini/MiniMainActivity.java
+++ b/app-mini/src/main/java/org/torproject/android/mini/MiniMainActivity.java
@@ -20,6 +20,7 @@ import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.net.VpnService;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -56,12 +57,10 @@ import org.torproject.android.mini.ui.AppConfigActivity;
import org.torproject.android.mini.ui.AppManagerActivity;
import org.torproject.android.mini.ui.Rotate3dAnimation;
import org.torproject.android.mini.ui.onboarding.OnboardingActivity;
-import org.torproject.android.mini.vpn.VPNEnableActivity;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.OrbotService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;
-import org.torproject.android.service.vpn.TorVpnService;
import org.torproject.android.service.vpn.TorifiedApp;
import org.torproject.android.service.vpn.VpnConstants;
import org.torproject.android.service.vpn.VpnPrefs;
@@ -275,7 +274,7 @@ public class MiniMainActivity extends AppCompatActivity
//auto start VPN if VPN is enabled
if (useVPN) {
- startActivity(new Intent(MiniMainActivity.this,VPNEnableActivity.class));
+ sendIntentToService(TorServiceConstants.ACTION_START_VPN);
}
mBtnVPN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@@ -463,16 +462,14 @@ public class MiniMainActivity extends AppCompatActivity
}
}
- private void refreshVPNApps ()
- {
- TorVpnService.stop(this);
- startActivity(new Intent(MiniMainActivity.this, VPNEnableActivity.class));
+ private void refreshVPNApps() {
+ sendIntentToService(TorServiceConstants.ACTION_STOP_VPN);
+ sendIntentToService(TorServiceConstants.ACTION_START_VPN);
}
private void enableVPN (boolean enable)
{
- if (enable && pkgIds.size() == 0)
- {
+ if (enable && pkgIds.size() == 0) {
showAppPicker();
}
else {
@@ -480,10 +477,18 @@ public class MiniMainActivity extends AppCompatActivity
Prefs.putStartOnBoot(enable);
if (enable) {
- startActivityForResult(new Intent(MiniMainActivity.this, VPNEnableActivity.class), REQUEST_VPN);
+
+ Intent intentVPN = VpnService.prepare(this);
+
+ if (intentVPN != null) {
+ startActivityForResult(intentVPN, REQUEST_VPN);
+ } else {
+ sendIntentToService(TorServiceConstants.ACTION_START);
+ sendIntentToService(TorServiceConstants.ACTION_START_VPN);
+ }
} else {
- TorVpnService.start(this);
- stopTor();
+ sendIntentToService(TorServiceConstants.ACTION_STOP_VPN);
+ stopTor(); // todo this call isn't in the main Orbot app, is it needed?
}
}
}
@@ -606,20 +611,7 @@ public class MiniMainActivity extends AppCompatActivity
}
- }
- else if (request == REQUEST_VPN)
- {
- if (response == RESULT_OK) {
- TorVpnService.start(this);
-
- }
- else if (response == VPNEnableActivity.ACTIVITY_RESULT_VPN_DENIED)
- {
- mBtnVPN.setChecked(false);
- Prefs.putUseVpn(false);
- }
- }
- else if (request == REQUEST_VPN_APPS_SELECT)
+ } else if (request == REQUEST_VPN_APPS_SELECT)
{
if (response == RESULT_OK &&
torStatus == TorServiceConstants.STATUS_ON) {
@@ -627,10 +619,14 @@ public class MiniMainActivity extends AppCompatActivity
String newPkgId = data.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
//add new entry
-
}
-
+ } else if (request == REQUEST_VPN && response == RESULT_OK) {
+ sendIntentToService(TorServiceConstants.ACTION_START_VPN);
+ } else if (request == REQUEST_VPN && response == RESULT_CANCELED) {
+ mBtnVPN.setChecked(false);
+ Prefs.putUseVpn(false);
}
+
IntentResult scanResult = IntentIntegrator.parseActivityResult(request, response, data);
if (scanResult != null) {
diff --git a/app-mini/src/main/java/org/torproject/android/mini/OnBootReceiver.java b/app-mini/src/main/java/org/torproject/android/mini/OnBootReceiver.java
index 56d2b5e9..c958df8b 100644
--- a/app-mini/src/main/java/org/torproject/android/mini/OnBootReceiver.java
+++ b/app-mini/src/main/java/org/torproject/android/mini/OnBootReceiver.java
@@ -1,11 +1,10 @@
package org.torproject.android.mini;
-
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
-import org.torproject.android.mini.vpn.VPNEnableActivity;
+
import org.torproject.android.service.OrbotService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;
@@ -16,29 +15,13 @@ public class OnBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
-
- if (Prefs.startOnBoot() && (!sReceivedBoot))
- {
- if (Prefs.useVpn())
- startVpnService(context); //VPN will start Tor once it is done
- else
- startService(TorServiceConstants.ACTION_START, context);
-
+ if (Prefs.startOnBoot() && (!sReceivedBoot)) {
+ startService(TorServiceConstants.ACTION_START_ON_BOOT, context);
sReceivedBoot = true;
}
}
- public void startVpnService (final Context context)
- {
- Intent intent = new Intent(context,VPNEnableActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(intent);
-
- }
-
- private void startService (String action, Context context)
- {
-
+ private void startService (String action, Context context) {
Intent intent = new Intent(context, OrbotService.class);
intent.setAction(action);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
diff --git a/app-mini/src/main/java/org/torproject/android/mini/vpn/VPNEnableActivity.java b/app-mini/src/main/java/org/torproject/android/mini/vpn/VPNEnableActivity.java
deleted file mode 100644
index 153f5b57..00000000
--- a/app-mini/src/main/java/org/torproject/android/mini/vpn/VPNEnableActivity.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package org.torproject.android.mini.vpn;
-
-import android.content.Intent;
-import android.net.VpnService;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Handler;
-import android.util.Log;
-import android.view.Window;
-import androidx.appcompat.app.AppCompatActivity;
-import org.torproject.android.service.OrbotService;
-import org.torproject.android.service.TorServiceConstants;
-import org.torproject.android.service.util.Prefs;
-import org.torproject.android.service.vpn.TorVpnService;
-
-/**
- * To combat background service being stopped/swiped
- */
-public class VPNEnableActivity extends AppCompatActivity {
-
- private final static int REQUEST_VPN = 7777;
- private Intent intent = null;
- private boolean checkVpn = true;
- private Handler h = new Handler();
-
- @Override
- public void onCreate(Bundle icicle ) {
- requestWindowFeature(Window.FEATURE_NO_TITLE);
-
- super.onCreate( icicle );
-
- Log.d("VPNEnableActivity","prompting user to start Orbot VPN");
- }
-
- public void onResume() {
- super.onResume();
-
- if (checkVpn)
- {
- intent = VpnService.prepare(this);
-
- if (intent != null)
- promptStartVpnService();
- else
- startVpnService ();
-
- checkVpn = false;
- }
- }
-
- public void promptStartVpnService () {
- // todo no actual prompting happens here and this should be refactored
- startVpnService();
- }
-
- private void startVpnService ()
- {
- if (intent == null)
- {
- Prefs.putUseVpn(true);
-
- Log.d("VPNEnableActivity","VPN enabled, starting Tor...");
- TorVpnService.start(this);
-
- Handler h = new Handler();
- h.postDelayed(new Runnable () {
-
- public void run ()
- {
- sendIntentToService(TorServiceConstants.ACTION_START);
- finish();
- }
- }, 100);
-
-
- }
- else
- {
- Log.w("VPNEnableActivity","prompt for VPN");
- startActivityForResult(intent,REQUEST_VPN);
-
- }
-
- }
-
- public static final int ACTIVITY_RESULT_VPN_DENIED = 63;
-
- @Override
- protected void onActivityResult(int request, int response, Intent data) {
- super.onActivityResult(request, response, data);
-
- if (request == REQUEST_VPN && response == RESULT_OK) {
- TorVpnService.start(this);
-
- h.postDelayed(new Runnable () {
- @Override
- public void run () {
- sendIntentToService(TorServiceConstants.ACTION_START);
- finish();
- }
- }, 1000);
- }
- else if (request == REQUEST_VPN && response == RESULT_CANCELED) {
- setResult(ACTIVITY_RESULT_VPN_DENIED);
- finish();
- }
- }
-
-
- private void sendIntentToService(String action) {
- Intent intent = new Intent(this, OrbotService.class);
- intent.setAction(action);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- startForegroundService(intent);
- }
- else
- {
- startService(intent);
- }
- }
-}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits