diff --git a/app/app.iml b/app/app.iml
index 70e090c0..195a5432 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -75,7 +75,6 @@
-
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4120adbb..622e17c6 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,9 +4,11 @@
+
+
listSSID = new ArrayList<>();
+ listSSID.add("");
+ for (WifiConfiguration config : wm.getConfiguredNetworks())
+ listSSID.add(config.SSID);
+ wifi_home_pref.setEntries(listSSID.toArray(new CharSequence[0]));
+ wifi_home_pref.setEntryValues(listSSID.toArray(new CharSequence[0]));
// Handle auto enable
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Preference pref_auto_enable = screen.findPreference("auto_enable");
pref_auto_enable.setTitle(getString(R.string.setting_auto, prefs.getString("auto_enable", "0")));
@@ -247,8 +265,12 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
} else if ("auto_enable".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_auto, prefs.getString(name, "0")));
+ else if ("wifi_home".equals(name)) {
+ ListPreference pref_wifi_home = (ListPreference) getPreferenceScreen().findPreference(name);
+ pref_wifi_home.setTitle(getString(R.string.setting_wifi_home, prefs.getString(name, "")));
+ SinkholeService.reload(null, "setting changed", this);
- else if ("unmetered_2g".equals(name) ||
+ } else if ("unmetered_2g".equals(name) ||
"unmetered_3g".equals(name) ||
"unmetered_4g".equals(name)) {
if (prefs.getBoolean(name, false)) {
diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java
index 4713a526..0da9a7a6 100644
--- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java
+++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java
@@ -218,6 +218,8 @@ public class SinkholeService extends VpnService {
boolean wifi = Util.isWifiActive(this);
boolean metered = Util.isMeteredNetwork(this);
boolean useMetered = prefs.getBoolean("use_metered", false);
+ String ssidHome = prefs.getString("wifi_home", "");
+ String ssidNetwork = Util.getWifiSSID(this);
String generation = Util.getNetworkGeneration(this);
boolean unmetered_2g = prefs.getBoolean("unmetered_2g", false);
boolean unmetered_3g = prefs.getBoolean("unmetered_3g", false);
@@ -233,6 +235,8 @@ public class SinkholeService extends VpnService {
// Update metered state
if (wifi && (!useMetered || !telephony))
metered = false;
+ if (wifi && !ssidHome.equals("") && !ssidHome.equals(ssidNetwork))
+ metered = true;
if (unmetered_2g && "2G".equals(generation))
metered = false;
if (unmetered_3g && "3G".equals(generation))
diff --git a/app/src/main/java/eu/faircode/netguard/Util.java b/app/src/main/java/eu/faircode/netguard/Util.java
index 9a834139..a10e5088 100644
--- a/app/src/main/java/eu/faircode/netguard/Util.java
+++ b/app/src/main/java/eu/faircode/netguard/Util.java
@@ -33,6 +33,7 @@ import android.net.Network;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.VpnService;
+import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@@ -103,6 +104,11 @@ public class Util {
return cm.isActiveNetworkMetered();
}
+ public static String getWifiSSID(Context context) {
+ WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ return wm.getConnectionInfo().getSSID();
+ }
+
public static int getNetworkType(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 4fc78f41..a781316c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -26,6 +26,7 @@ These issues are caused by bugs in Android, or in the software provided by the m
Manage system applications
Auto enable after %1$s minutes
Use dark theme
+ Wi-Fi home network: %1$s
Handle metered Wi-Fi networks
Consider 2G unmetered
Consider 3G unmetered
@@ -40,6 +41,7 @@ These issues are caused by bugs in Android, or in the software provided by the m
Define rules for system applications (for experts)
After disabling using the widget, automatically enable NetGuard again after the selected number of minutes\nEnter zero to disable this option
+ Apply Wi-Fi network rules for selected network only (apply mobile network rules for other Wi-Fi networks)
Apply mobile network rules to metered (paid, tethered) Wi-Fi networks
Apply Wi-Fi network rules for 2G data connections
Apply Wi-Fi network rules for 3G data connections
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index 0b337965..df66e3e3 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -41,6 +41,9 @@
android:defaultValue="false"
android:key="dark_theme"
android:title="@string/setting_dark" />
+