improve start on boot

This commit is contained in:
Nathan Freitas 2015-02-14 00:43:13 -05:00
parent 266c29701d
commit b1294f6d60
1 changed files with 18 additions and 2 deletions

View File

@ -1,10 +1,12 @@
package org.torproject.android.service; package org.torproject.android.service;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.VpnService;
public class OnBootReceiver extends BroadcastReceiver { public class OnBootReceiver extends BroadcastReceiver {
@ -14,15 +16,29 @@ public class OnBootReceiver extends BroadcastReceiver {
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(context.getApplicationContext()); SharedPreferences prefs = TorServiceUtils.getSharedPrefs(context.getApplicationContext());
boolean startOnBoot = prefs.getBoolean("pref_start_boot",true); boolean startOnBoot = prefs.getBoolean("pref_start_boot",true);
boolean useVPN = prefs.getBoolean("pref_vpn",true);
if (startOnBoot) if (startOnBoot)
{ {
startService("init",context); if (useVPN)
startService("start",context); 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) private void startService (String action, Context context)
{ {