mirror of https://github.com/M66B/NetGuard.git
Bark at Samsung
This commit is contained in:
parent
18d799e9f0
commit
87f40f2ae4
|
@ -239,6 +239,9 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
screen.findPreference("pcap_record_size").setTitle(getString(R.string.setting_pcap_record_size, prefs.getString("pcap_record_size", "64")));
|
||||
screen.findPreference("pcap_file_size").setTitle(getString(R.string.setting_pcap_file_size, prefs.getString("pcap_file_size", "2")));
|
||||
|
||||
// Watchdog
|
||||
screen.findPreference("watchdog").setTitle(getString(R.string.setting_watchdog, prefs.getString("watchdog", "0")));
|
||||
|
||||
// Handle stats
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
cat_stats.removePreference(screen.findPreference("show_top"));
|
||||
|
@ -697,6 +700,10 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
if (prefs.getBoolean("pcap", false))
|
||||
ServiceSinkhole.setPcap(true, this);
|
||||
|
||||
} else if ("watchdog".equals(name)) {
|
||||
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_watchdog, prefs.getString(name, "0")));
|
||||
ServiceSinkhole.reload("changed " + name, this);
|
||||
|
||||
} else if ("show_stats".equals(name))
|
||||
ServiceSinkhole.reloadStats("changed " + name, this);
|
||||
|
||||
|
|
|
@ -164,12 +164,13 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
|
||||
private enum State {none, waiting, enforcing, stats}
|
||||
|
||||
public enum Command {run, start, reload, stop, stats, set, householding}
|
||||
public enum Command {run, start, reload, stop, stats, set, householding, watchdog}
|
||||
|
||||
private static volatile PowerManager.WakeLock wlInstance = null;
|
||||
|
||||
private static final String ACTION_HOUSE_HOLDING = "eu.faircode.netguard.HOUSE_HOLDING";
|
||||
private static final String ACTION_SCREEN_OFF_DELAYED = "eu.faircode.netguard.SCREEN_OFF_DELAYED";
|
||||
private static final String ACTION_WATCHDOG = "eu.faircode.netguard.WATCHDOG";
|
||||
|
||||
private native void jni_init();
|
||||
|
||||
|
@ -305,6 +306,22 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
Log.i(TAG, "Listening to subscription changes");
|
||||
}
|
||||
|
||||
// Watchdog
|
||||
if (cmd == Command.start || cmd == Command.reload) {
|
||||
Intent watchdogIntent = new Intent(ServiceSinkhole.this, ServiceSinkhole.class);
|
||||
watchdogIntent.setAction(ACTION_WATCHDOG);
|
||||
PendingIntent pi = PendingIntent.getService(ServiceSinkhole.this, 1, watchdogIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
am.cancel(pi);
|
||||
|
||||
int watchdog = Integer.parseInt(prefs.getString("watchdog", "0"));
|
||||
if (watchdog > 0) {
|
||||
Log.i(TAG, "Watchdog " + watchdog + " minutes");
|
||||
am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + watchdog * 60 * 1000, watchdog * 60 * 1000, pi);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
switch (cmd) {
|
||||
case run:
|
||||
|
@ -332,18 +349,24 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
householding(intent);
|
||||
break;
|
||||
|
||||
case watchdog:
|
||||
watchdog(intent);
|
||||
break;
|
||||
|
||||
default:
|
||||
Log.e(TAG, "Unknown command=" + cmd);
|
||||
}
|
||||
|
||||
// Update main view
|
||||
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
|
||||
ruleset.putExtra(ActivityMain.EXTRA_CONNECTED, cmd == Command.stop ? false : last_connected);
|
||||
ruleset.putExtra(ActivityMain.EXTRA_METERED, cmd == Command.stop ? false : last_metered);
|
||||
LocalBroadcastManager.getInstance(ServiceSinkhole.this).sendBroadcast(ruleset);
|
||||
if (cmd != Command.watchdog) {
|
||||
// Update main view
|
||||
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
|
||||
ruleset.putExtra(ActivityMain.EXTRA_CONNECTED, cmd == Command.stop ? false : last_connected);
|
||||
ruleset.putExtra(ActivityMain.EXTRA_METERED, cmd == Command.stop ? false : last_metered);
|
||||
LocalBroadcastManager.getInstance(ServiceSinkhole.this).sendBroadcast(ruleset);
|
||||
|
||||
// Update widgets
|
||||
Widget.updateWidgets(ServiceSinkhole.this);
|
||||
// Update widgets
|
||||
Widget.updateWidgets(ServiceSinkhole.this);
|
||||
}
|
||||
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
|
@ -510,6 +533,16 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
checkUpdate();
|
||||
}
|
||||
|
||||
private void watchdog(Intent intent) {
|
||||
if (vpn == null) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this);
|
||||
if (prefs.getBoolean("enabled", false)) {
|
||||
Log.e(TAG, "Service was killed");
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
StringBuilder json = new StringBuilder();
|
||||
HttpsURLConnection urlConnection = null;
|
||||
|
@ -1812,6 +1845,8 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
|
||||
if (ACTION_HOUSE_HOLDING.equals(intent.getAction()))
|
||||
intent.putExtra(EXTRA_COMMAND, Command.householding);
|
||||
if (ACTION_WATCHDOG.equals(intent.getAction()))
|
||||
intent.putExtra(EXTRA_COMMAND, Command.watchdog);
|
||||
|
||||
Command cmd = (Command) intent.getSerializableExtra(EXTRA_COMMAND);
|
||||
if (cmd == null)
|
||||
|
|
|
@ -99,6 +99,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
|
|||
<string name="setting_socks5_password">SOCKS5 password: %s</string>
|
||||
<string name="setting_pcap_record_size">PCAP record size: %s B</string>
|
||||
<string name="setting_pcap_file_size">PCAP max. file size: %s MB</string>
|
||||
<string name="setting_watchdog">Watchdog: every %s minutes</string>
|
||||
|
||||
<string name="setting_stats_category">Speed notification</string>
|
||||
<string name="setting_stats">Show speed notification</string>
|
||||
|
@ -141,6 +142,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
|
|||
<string name="summary_track_usage">Track the number of bytes sent and received for each application and address. This might result in extra battery usage.</string>
|
||||
<string name="summary_block_domains">Respond with \'name error\' (NXDOMAIN) for blocked domain names. This switch is disabled when no hosts file is available.</string>
|
||||
<string name="summary_socks5_enabled">Only TCP traffic will be sent to the proxy server</string>
|
||||
<string name="summary_watchdog">Periodically check if NetGuard is still running (enter zero to disable this option). This might result in extra battery usage.</string>
|
||||
|
||||
<string name="summary_stats">Show network speed graph in status bar notification</string>
|
||||
|
||||
|
|
|
@ -218,6 +218,11 @@
|
|||
android:defaultValue="2"
|
||||
android:inputType="number"
|
||||
android:key="pcap_file_size" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="0"
|
||||
android:inputType="number"
|
||||
android:key="watchdog"
|
||||
android:summary="@string/summary_watchdog" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
||||
|
|
|
@ -218,6 +218,11 @@
|
|||
android:defaultValue="2"
|
||||
android:inputType="number"
|
||||
android:key="pcap_file_size" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="0"
|
||||
android:inputType="number"
|
||||
android:key="watchdog"
|
||||
android:summary="@string/summary_watchdog" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
||||
|
|
Loading…
Reference in New Issue