fixes for VPN service UI to work on Android6

This commit is contained in:
Nathan Freitas 2016-01-06 16:13:56 -05:00
parent fe9119d66a
commit d839b154a1
3 changed files with 54 additions and 27 deletions

View File

@ -62,7 +62,7 @@
--> -->
<activity <activity
android:name=".service.DummyActivity" android:name=".service.DummyActivity"
android:theme="@android:style/Theme.NoDisplay" android:theme="@android:style/Theme.Translucent"
android:enabled="true" android:enabled="true"
android:allowTaskReparenting="true" android:allowTaskReparenting="true"
android:noHistory="true" android:noHistory="true"
@ -76,7 +76,7 @@
<activity <activity
android:name=".vpn.VPNEnableActivity" android:label="@string/app_name" android:exported="false" android:name=".vpn.VPNEnableActivity" android:label="@string/app_name" android:exported="false"
android:theme="@android:style/Theme.NoDisplay" android:theme="@android:style/Theme.Translucent"
/> />

View File

@ -76,6 +76,11 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
private boolean isRestart = false; private boolean isRestart = false;
static{
System.loadLibrary("tun2socks");
}
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
@ -174,9 +179,6 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
System.loadLibrary("tun2socks");
// Set the locale to English (or probably any other language that^M // Set the locale to English (or probably any other language that^M
// uses Hindu-Arabic (aka Latin) numerals).^M // uses Hindu-Arabic (aka Latin) numerals).^M
// We have found that VpnService.Builder does something locale-dependent^M // We have found that VpnService.Builder does something locale-dependent^M

View File

@ -18,6 +18,8 @@ import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView; import android.widget.TextView;
/* /*
@ -27,33 +29,45 @@ public class VPNEnableActivity extends Activity {
private final static int REQUEST_VPN = 7777; private final static int REQUEST_VPN = 7777;
private Intent intent = null; private Intent intent = null;
private boolean checkVpn = true;
private Handler h = new Handler();
@Override @Override
public void onCreate( Bundle icicle ) { public void onCreate( Bundle icicle ) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate( icicle ); super.onCreate( icicle );
Log.d("VPNEnableActivity","prompting user to start Orbot VPN"); 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 () 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); AlertDialog dialog = new AlertDialog.Builder(this)
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)
.setTitle(getString(R.string.app_name) + ' ' + getString(R.string.apps_mode)) .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 () .setPositiveButton(R.string.activate, new Dialog.OnClickListener ()
{ {
@ -73,11 +87,21 @@ public class VPNEnableActivity extends Activity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
finish(); h.postDelayed(new Runnable () {
public void run ()
{
VPNEnableActivity.this.finish();
}
}, 100);
} }
}) }).create();
.show();
dialog.show();
} }
private void startVpnService () private void startVpnService ()
@ -86,7 +110,7 @@ public class VPNEnableActivity extends Activity {
{ {
Log.d("VPNEnableActivity","VPN enabled, starting Tor..."); Log.d("VPNEnableActivity","VPN enabled, starting Tor...");
sendIntentToService(TorServiceConstants.CMD_VPN); sendIntentToService(TorServiceConstants.CMD_VPN);
/**
Handler h = new Handler(); Handler h = new Handler();
h.postDelayed(new Runnable () { h.postDelayed(new Runnable () {
@ -95,8 +119,7 @@ public class VPNEnableActivity extends Activity {
sendIntentToService(TorServiceConstants.ACTION_START); sendIntentToService(TorServiceConstants.ACTION_START);
finish(); finish();
} }
}, 1000); }, 100);
*/
} }
@ -116,16 +139,18 @@ public class VPNEnableActivity extends Activity {
if (request == REQUEST_VPN && response == RESULT_OK) if (request == REQUEST_VPN && response == RESULT_OK)
{ {
sendIntentToService(TorServiceConstants.CMD_VPN); sendIntentToService(TorServiceConstants.CMD_VPN);
Handler h = new Handler();
h.postDelayed(new Runnable () { h.postDelayed(new Runnable () {
public void run () public void run ()
{ {
sendIntentToService(TorServiceConstants.ACTION_START); sendIntentToService(TorServiceConstants.ACTION_START);
finish(); finish();
} }
}, 1000); }, 1000);
} }
} }