diff --git a/README.md b/README.md index bed0cdf8..40a200c7 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,12 @@ but once you close it, it will not use any bandwidth. The VPN service will be restarted when you turn the screen on or off and when connectivity changes (WiFi, mobile) to apply the rules with the conditions '*Allow when device is in use*' and '*Block when roaming*'. + +**(10) Will you provide a Tasker plug-in?** + +If disabling NetGuard is allowed to Tasker, any application can disabled NetGuard too. +Allowing to disable a security application from other applications is not a good idea. + Support ------- diff --git a/app/build.gradle b/app/build.gradle index 35bdc958..4e823d2e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "eu.faircode.netguard" minSdkVersion 21 targetSdkVersion 23 - versionCode 19 - versionName "0.19" + versionCode 21 + versionName "0.21" } buildTypes { release { diff --git a/app/src/main/java/eu/faircode/netguard/ActivityMain.java b/app/src/main/java/eu/faircode/netguard/ActivityMain.java index 72397554..b2c2772d 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityMain.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityMain.java @@ -352,7 +352,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences } else if ("whitelist_wifi".equals(name) || "whitelist_other".equals(name) || "whitelist_roaming".equals(name) || - "manage_system".equals(name)) + "manage_system".equals(name) || + "imported".equals(name)) updateApplicationList(); else if ("dark_theme".equals(name)) diff --git a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java index 94e4c290..151ca045 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java +++ b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java @@ -213,11 +213,9 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere @Override protected void onPostExecute(Throwable ex) { - if (ex == null) { - SinkholeService.reload(null, ActivitySettings.this); - recreate(); + if (ex == null) Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); - } else + else Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } }.execute(); @@ -255,35 +253,51 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere Map settings = prefs.getAll(); for (String key : settings.keySet()) { Object value = settings.get(key); + + if ("imported".equals(key)) + continue; + if (value instanceof Boolean) { serializer.startTag(null, "setting"); serializer.attribute(null, "key", key); serializer.attribute(null, "type", "boolean"); serializer.attribute(null, "value", value.toString()); serializer.endTag(null, "setting"); + } else Log.e(TAG, "Unknown key=" + key); } } private void xmlImport(InputStream in) throws IOException, SAXException, ParserConfigurationException { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + prefs.edit().putBoolean("enabled", false).apply(); + SinkholeService.stop(this); + XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); XmlImportHandler handler = new XmlImportHandler(); reader.setContentHandler(handler); reader.parse(new InputSource(in)); - xmlImport(handler.application, PreferenceManager.getDefaultSharedPreferences(this)); + xmlImport(handler.application, prefs); xmlImport(handler.wifi, getSharedPreferences("wifi", Context.MODE_PRIVATE)); xmlImport(handler.mobile, getSharedPreferences("other", Context.MODE_PRIVATE)); xmlImport(handler.unused, getSharedPreferences("unused", Context.MODE_PRIVATE)); + xmlImport(handler.roaming, getSharedPreferences("roaming", Context.MODE_PRIVATE)); + + // Refresh UI + prefs.edit().putBoolean("imported", true).apply(); } private void xmlImport(Map settings, SharedPreferences prefs) { SharedPreferences.Editor editor = prefs.edit(); + // Clear existing setting for (String key : prefs.getAll().keySet()) - editor.remove(key); + if (!"enabled".equals(key)) + editor.remove(key); + // Apply new settings for (String key : settings.keySet()) { Object value = settings.get(key); if (value instanceof Boolean) @@ -296,10 +310,12 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere } private class XmlImportHandler extends DefaultHandler { + public boolean enabled = false; public Map application = new HashMap<>(); public Map wifi = new HashMap<>(); public Map mobile = new HashMap<>(); public Map unused = new HashMap<>(); + public Map roaming = new HashMap<>(); private Map current = null; @Override @@ -319,6 +335,9 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere else if (qName.equals("unused")) current = unused; + else if (qName.equals("roaming")) + roaming = unused; + else if (qName.equals("setting")) { String key = attributes.getValue("key"); String type = attributes.getValue("type"); @@ -327,10 +346,14 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere if (current == null) Log.e(TAG, "No current key=" + key); else { - if ("boolean".equals(type)) - current.put(key, Boolean.parseBoolean(value)); - else - Log.e(TAG, "Unknown type key=" + key); + if ("enabled".equals(key)) + enabled = Boolean.parseBoolean(value); + else { + if ("boolean".equals(type)) + current.put(key, Boolean.parseBoolean(value)); + else + Log.e(TAG, "Unknown type key=" + key); + } } } else diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index e0a6a64f..baf473f5 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -77,7 +77,7 @@ public class SinkholeService extends VpnService { Command cmd = (intent == null ? Command.start : (Command) intent.getSerializableExtra(EXTRA_COMMAND)); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SinkholeService.this); - Log.i(TAG, "Executing command=" + cmd + " vpn=" + (vpn != null)); + Log.i(TAG, "Executing intent=" + intent + " command=" + cmd + " vpn=" + (vpn != null)); switch (cmd) { case start: if (prefs.getBoolean("foreground", false)) { @@ -114,7 +114,7 @@ public class SinkholeService extends VpnService { stopForeground(true); } Widget.updateWidgets(SinkholeService.this); - stopSelf(); + // stopSelf(); break; } } diff --git a/app/src/main/res/layout/action.xml b/app/src/main/res/layout/action.xml index 908e4f73..312f212e 100644 --- a/app/src/main/res/layout/action.xml +++ b/app/src/main/res/layout/action.xml @@ -9,7 +9,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_marginStart="12dp" /> + android:layout_marginStart="12dp" + android:saveEnabled="false" /> +