mirror of
https://github.com/M66B/NetGuard.git
synced 2025-01-01 12:54:07 +00:00
Added home Wi-Fi network setting
This commit is contained in:
parent
d5e3b0dc56
commit
8e5edaee96
7 changed files with 41 additions and 3 deletions
|
@ -75,7 +75,6 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
<!-- http://developer.android.com/guide/topics/security/permissions.html#normal-dangerous -->
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.wifi"
|
||||
|
|
|
@ -28,9 +28,12 @@ import android.content.IntentFilter;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
@ -55,7 +58,10 @@ import org.xmlpull.v1.XmlSerializer;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
@ -91,9 +97,21 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
ListPreference wifi_home_pref = (ListPreference) screen.findPreference("wifi_home");
|
||||
String ssid = prefs.getString("wifi_home", "");
|
||||
wifi_home_pref.setTitle(getString(R.string.setting_wifi_home, ssid));
|
||||
|
||||
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
List<CharSequence> 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)) {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -26,6 +26,7 @@ These issues are caused by bugs in Android, or in the software provided by the m
|
|||
<string name="setting_system">Manage system applications</string>
|
||||
<string name="setting_auto">Auto enable after %1$s minutes</string>
|
||||
<string name="setting_dark">Use dark theme</string>
|
||||
<string name="setting_wifi_home">Wi-Fi home network: %1$s</string>
|
||||
<string name="setting_metered">Handle metered Wi-Fi networks</string>
|
||||
<string name="setting_metered_2g">Consider 2G unmetered</string>
|
||||
<string name="setting_metered_3g">Consider 3G unmetered</string>
|
||||
|
@ -40,6 +41,7 @@ These issues are caused by bugs in Android, or in the software provided by the m
|
|||
|
||||
<string name="summary_system">Define rules for system applications (for experts)</string>
|
||||
<string name="summary_auto">After disabling using the widget, automatically enable NetGuard again after the selected number of minutes\nEnter zero to disable this option</string>
|
||||
<string name="summary_wifi_home">Apply Wi-Fi network rules for selected network only (apply mobile network rules for other Wi-Fi networks)</string>
|
||||
<string name="summary_metered">Apply mobile network rules to metered (paid, tethered) Wi-Fi networks</string>
|
||||
<string name="summary_metered_2g">Apply Wi-Fi network rules for 2G data connections</string>
|
||||
<string name="summary_metered_3g">Apply Wi-Fi network rules for 3G data connections</string>
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
android:defaultValue="false"
|
||||
android:key="dark_theme"
|
||||
android:title="@string/setting_dark" />
|
||||
<ListPreference
|
||||
android:key="wifi_home"
|
||||
android:summary="@string/summary_wifi_home" />
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="use_metered"
|
||||
|
|
Loading…
Reference in a new issue