2016-06-29 06:20:20 +02:00
|
|
|
package org.torproject.android;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
|
2016-09-26 18:03:30 +02:00
|
|
|
import org.torproject.android.service.util.Prefs;
|
2016-06-29 06:20:20 +02:00
|
|
|
import org.torproject.android.service.TorService;
|
|
|
|
import org.torproject.android.service.TorServiceConstants;
|
|
|
|
import org.torproject.android.vpn.VPNEnableActivity;
|
|
|
|
|
|
|
|
public class OnBootReceiver extends BroadcastReceiver {
|
2016-09-26 01:10:01 +02:00
|
|
|
|
|
|
|
private static boolean sReceivedBoot = false;
|
|
|
|
|
2016-06-29 06:20:20 +02:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
2016-10-12 22:01:09 +02:00
|
|
|
if (Prefs.startOnBoot() && (!sReceivedBoot))
|
|
|
|
{
|
2016-06-29 06:20:20 +02:00
|
|
|
if (Prefs.useVpn())
|
|
|
|
startVpnService(context); //VPN will start Tor once it is done
|
|
|
|
else
|
|
|
|
startService(TorServiceConstants.ACTION_START, context);
|
2016-09-26 01:10:01 +02:00
|
|
|
|
|
|
|
sReceivedBoot = true;
|
2016-06-29 06:20:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
Intent torService = new Intent(context, TorService.class);
|
|
|
|
torService.setAction(action);
|
|
|
|
context.startService(torService);
|
2016-10-21 20:53:58 +02:00
|
|
|
|
2016-06-29 06:20:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|