From d839b154a103b6d7a74fb6f36e47d7df09fe70f8 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Wed, 6 Jan 2016 16:13:56 -0500 Subject: [PATCH] fixes for VPN service UI to work on Android6 --- AndroidManifest.xml | 4 +- .../android/vpn/OrbotVpnService.java | 8 ++- .../android/vpn/VPNEnableActivity.java | 69 +++++++++++++------ 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ad2af720..caa8e74d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -62,7 +62,7 @@ --> diff --git a/src/org/torproject/android/vpn/OrbotVpnService.java b/src/org/torproject/android/vpn/OrbotVpnService.java index a8d3b70b..f4dff745 100644 --- a/src/org/torproject/android/vpn/OrbotVpnService.java +++ b/src/org/torproject/android/vpn/OrbotVpnService.java @@ -76,6 +76,11 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { private boolean isRestart = false; + + static{ + System.loadLibrary("tun2socks"); + } + @Override public int onStartCommand(Intent intent, int flags, int startId) { @@ -174,9 +179,6 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { public void onCreate() { super.onCreate(); - System.loadLibrary("tun2socks"); - - // Set the locale to English (or probably any other language that^M // uses Hindu-Arabic (aka Latin) numerals).^M // We have found that VpnService.Builder does something locale-dependent^M diff --git a/src/org/torproject/android/vpn/VPNEnableActivity.java b/src/org/torproject/android/vpn/VPNEnableActivity.java index 9083b45f..8d254f1f 100644 --- a/src/org/torproject/android/vpn/VPNEnableActivity.java +++ b/src/org/torproject/android/vpn/VPNEnableActivity.java @@ -18,6 +18,8 @@ import android.os.Handler; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.Window; +import android.view.WindowManager; import android.widget.TextView; /* @@ -27,33 +29,45 @@ public class VPNEnableActivity extends Activity { 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); + //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); + super.onCreate( icicle ); Log.d("VPNEnableActivity","prompting user to start Orbot VPN"); - intent = VpnService.prepare(this); - if (intent != null) - promptStartVpnService(); - else - startVpnService (); + } + + public void onResume () + { + super.onResume(); + if (checkVpn) + { + intent = VpnService.prepare(this); + + if (intent != null) + promptStartVpnService(); + else + startVpnService (); + + checkVpn = false; + } } public void promptStartVpnService () { - LayoutInflater li = LayoutInflater.from(this); - View view = li.inflate(R.layout.layout_diag, null); - - TextView versionName = (TextView)view.findViewById(R.id.diaglog); - versionName.setText(R.string.you_can_enable_all_apps_on_your_device_to_run_through_the_tor_network_using_the_vpn_feature_of_android_); - - new AlertDialog.Builder(this) + + AlertDialog dialog = new AlertDialog.Builder(this) .setTitle(getString(R.string.app_name) + ' ' + getString(R.string.apps_mode)) - .setView(view) + .setMessage(getString(R.string.you_can_enable_all_apps_on_your_device_to_run_through_the_tor_network_using_the_vpn_feature_of_android_)) .setPositiveButton(R.string.activate, new Dialog.OnClickListener () { @@ -73,11 +87,21 @@ public class VPNEnableActivity extends Activity { @Override public void onClick(DialogInterface dialog, int which) { - finish(); + h.postDelayed(new Runnable () { + + public void run () + { + VPNEnableActivity.this.finish(); + + } + }, 100); } - }) - .show(); + }).create(); + + dialog.show(); + + } private void startVpnService () @@ -86,7 +110,7 @@ public class VPNEnableActivity extends Activity { { Log.d("VPNEnableActivity","VPN enabled, starting Tor..."); sendIntentToService(TorServiceConstants.CMD_VPN); - /** + Handler h = new Handler(); h.postDelayed(new Runnable () { @@ -95,8 +119,7 @@ public class VPNEnableActivity extends Activity { sendIntentToService(TorServiceConstants.ACTION_START); finish(); } - }, 1000); - */ + }, 100); } @@ -116,16 +139,18 @@ public class VPNEnableActivity extends Activity { if (request == REQUEST_VPN && response == RESULT_OK) { sendIntentToService(TorServiceConstants.CMD_VPN); - Handler h = new Handler(); + h.postDelayed(new Runnable () { public void run () { sendIntentToService(TorServiceConstants.ACTION_START); - finish(); + finish(); } }, 1000); + + } }