-
-
Notifications
You must be signed in to change notification settings - Fork 325
/
OnBootReceiver.java
56 lines (41 loc) · 1.34 KB
/
OnBootReceiver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.torproject.android.mini;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import org.torproject.android.mini.vpn.VPNEnableActivity;
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;
public class OnBootReceiver extends BroadcastReceiver {
private static boolean sReceivedBoot = false;
@Override
public void onReceive(Context context, Intent intent) {
if (Prefs.startOnBoot() && (!sReceivedBoot))
{
if (Prefs.useVpn())
startVpnService(context); //VPN will start Tor once it is done
else
startService(TorServiceConstants.ACTION_START, context);
sReceivedBoot = true;
}
}
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);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(torService);
}
else
{
context.startService(torService);
}
}
}