mirror of https://github.com/M66B/NetGuard.git
Revert "Fixed swiping away graph while service not running"
This reverts commit 888c2635c8
.
This commit is contained in:
parent
5c92573d49
commit
dd9f5b101e
|
@ -94,6 +94,8 @@ public class Receiver extends BroadcastReceiver {
|
|||
} else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
|
||||
if (prefs.getBoolean("enabled", false))
|
||||
ServiceSinkhole.start("receiver", context);
|
||||
else if (prefs.getBoolean("show_stats", false))
|
||||
ServiceSinkhole.run("receiver", context);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
|
|
|
@ -170,7 +170,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
private static final int MSG_PACKET = 4;
|
||||
private static final int MSG_USAGE = 5;
|
||||
|
||||
private enum State {none, waiting, enforcing}
|
||||
private enum State {none, waiting, enforcing, stats}
|
||||
|
||||
public enum Command {run, start, reload, stop, stats, set, householding}
|
||||
|
||||
|
@ -507,6 +507,12 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
if (state == State.enforcing) {
|
||||
Log.d(TAG, "Stop foreground state=" + state.toString());
|
||||
stopForeground(true);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -706,6 +712,11 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
Log.i(TAG, "Stats stop");
|
||||
stats = false;
|
||||
this.removeMessages(MSG_STATS_UPDATE);
|
||||
if (state == State.stats) {
|
||||
Log.d(TAG, "Stop foreground state=" + state.toString());
|
||||
stopForeground(true);
|
||||
state = State.none;
|
||||
} else
|
||||
NotificationManagerCompat.from(ServiceSinkhole.this).cancel(NOTIFY_TRAFFIC);
|
||||
}
|
||||
|
||||
|
@ -915,6 +926,15 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
.setVisibility(Notification.VISIBILITY_PUBLIC);
|
||||
}
|
||||
|
||||
if (state == State.none || state == State.waiting) {
|
||||
if (state != State.none) {
|
||||
Log.d(TAG, "Stop foreground state=" + state.toString());
|
||||
stopForeground(true);
|
||||
}
|
||||
startForeground(NOTIFY_TRAFFIC, builder.build());
|
||||
state = State.stats;
|
||||
Log.d(TAG, "Start foreground state=" + state.toString());
|
||||
} else
|
||||
NotificationManagerCompat.from(ServiceSinkhole.this).notify(NOTIFY_TRAFFIC, builder.build());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue