Fixed persistent notification

Closes #217
This commit is contained in:
M66B 2016-01-05 22:38:23 +01:00
parent 50be022cbc
commit 12eab96394
2 changed files with 22 additions and 21 deletions

View File

@ -73,25 +73,27 @@ public class Receiver extends BroadcastReceiver {
}
} else {
// Boot completed
// My package replaced
// Upgrade settings
upgrade(true, context);
// Start service
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.getBoolean("enabled", false))
try {
if (VpnService.prepare(context) == null)
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
SinkholeService.run("receiver", context);
else
try {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false))
SinkholeService.run("receiver", context);
} else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
if (prefs.getBoolean("enabled", false)) {
if (VpnService.prepare(context) == null)
SinkholeService.start("receiver", context);
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, context);
} else if (prefs.getBoolean("show_stats", false))
SinkholeService.run("receiver", context);
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, context);
}
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm.isInteractive())

View File

@ -268,9 +268,12 @@ public class SinkholeService extends VpnService {
if (state == State.enforcing) {
Log.d(TAG, "Stop foreground state=" + state.toString());
stopForeground(true);
startForeground(NOTIFY_WAITING, getWaitingNotification());
state = State.waiting;
Log.d(TAG, "Start foreground state=" + state.toString());
if (prefs.getBoolean("show_stats", false)) {
startForeground(NOTIFY_WAITING, getWaitingNotification());
state = State.waiting;
Log.d(TAG, "Start foreground state=" + state.toString());
} else
state = State.none;
}
}
break;
@ -346,9 +349,7 @@ public class SinkholeService extends VpnService {
if (state == State.stats) {
Log.d(TAG, "Stop foreground state=" + state.toString());
stopForeground(true);
startForeground(NOTIFY_WAITING, getWaitingNotification());
state = State.waiting;
Log.d(TAG, "Start foreground state=" + state.toString());
state = State.none;
} else
NotificationManagerCompat.from(SinkholeService.this).cancel(NOTIFY_TRAFFIC);
}
@ -567,10 +568,8 @@ public class SinkholeService extends VpnService {
}
if (state == State.enforcing)
startForeground(NOTIFY_ENFORCING, getEnforcingNotification(0, 0));
else {
else if (state != State.none)
startForeground(NOTIFY_WAITING, getWaitingNotification());
state = State.waiting;
}
Log.d(TAG, "Start foreground state=" + state.toString());
}