From b1294f6d60eacf19c291a372ceeb509701964bb6 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Sat, 14 Feb 2015 00:43:13 -0500 Subject: [PATCH] improve start on boot --- .../android/service/OnBootReceiver.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/org/torproject/android/service/OnBootReceiver.java b/src/org/torproject/android/service/OnBootReceiver.java index ef40619e..b04a6a19 100644 --- a/src/org/torproject/android/service/OnBootReceiver.java +++ b/src/org/torproject/android/service/OnBootReceiver.java @@ -1,10 +1,12 @@ package org.torproject.android.service; +import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.net.VpnService; public class OnBootReceiver extends BroadcastReceiver { @@ -14,15 +16,29 @@ public class OnBootReceiver extends BroadcastReceiver { SharedPreferences prefs = TorServiceUtils.getSharedPrefs(context.getApplicationContext()); boolean startOnBoot = prefs.getBoolean("pref_start_boot",true); + boolean useVPN = prefs.getBoolean("pref_vpn",true); if (startOnBoot) { - startService("init",context); - startService("start",context); + if (useVPN) + startVpnService(context); + + startService(TorServiceConstants.CMD_INIT,context); + startService(TorServiceConstants.CMD_START,context); + } } + @SuppressLint("NewApi") + public void startVpnService (Context context) + { + Intent intent = VpnService.prepare(context); + if (intent != null) { + context.startActivity(intent); + } + + } private void startService (String action, Context context) {