Workaround VPN start problems on some devices

This commit is contained in:
M66B 2016-01-03 09:50:10 +01:00
parent 4c770f8c6d
commit f819bc3b1d
2 changed files with 19 additions and 2 deletions

View File

@ -74,6 +74,9 @@ public class Receiver extends BroadcastReceiver {
}
} else {
// Boot completed
// My package replaced
// Upgrade settings
upgrade(true, context);
@ -82,7 +85,10 @@ public class Receiver extends BroadcastReceiver {
if (prefs.getBoolean("enabled", false))
try {
if (VpnService.prepare(context) == null)
SinkholeService.start("receiver", context);
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
SinkholeService.run("receiver", context);
else
SinkholeService.start("receiver", context);
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, context);

View File

@ -105,7 +105,7 @@ public class SinkholeService extends VpnService {
private static final int MSG_STATS_STOP = 2;
private static final int MSG_STATS_UPDATE = 3;
public enum Command {start, reload, stop, stats, set, theme}
public enum Command {run, start, reload, stop, stats, set, theme}
private static volatile PowerManager.WakeLock wlInstance = null;
@ -198,6 +198,10 @@ public class SinkholeService extends VpnService {
try {
switch (cmd) {
case run:
// Do nothing
break;
case start:
if (vpn == null) {
startForeground(NOTIFY_FOREGROUND, getForegroundNotification(0, 0));
@ -981,6 +985,13 @@ public class SinkholeService extends VpnService {
NotificationManagerCompat.from(this).cancel(NOTIFY_DISABLED);
}
public static void run(String reason, Context context) {
Intent intent = new Intent(context, SinkholeService.class);
intent.putExtra(EXTRA_COMMAND, Command.run);
intent.putExtra(EXTRA_REASON, reason);
context.startService(intent);
}
public static void start(String reason, Context context) {
Intent intent = new Intent(context, SinkholeService.class);
intent.putExtra(EXTRA_COMMAND, Command.start);