mirror of https://github.com/M66B/NetGuard.git
Simplifications, debug info for national roaming
This commit is contained in:
parent
9434139c6e
commit
470c1288cd
|
@ -33,6 +33,7 @@ import android.preference.Preference;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
import android.widget.Toast;
|
||||
|
@ -179,6 +180,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
|
||||
private void updateTechnicalInfo() {
|
||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(String.format("Interactive %B\r\n", Util.isInteractive(this)));
|
||||
for (Network network : cm.getAllNetworks()) {
|
||||
|
@ -194,6 +196,10 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
}
|
||||
sb.append(String.format("WiFi %B\r\n", Util.isWifiActive(this)));
|
||||
sb.append(String.format("Metered %B\r\n", Util.isMeteredNetwork(this)));
|
||||
sb.append(String.format("Network %s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName()));
|
||||
if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
|
||||
sb.append(String.format("SIM %s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName()));
|
||||
|
||||
pref_technical.setSummary(sb.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ public class SinkholeService extends VpnService {
|
|||
|
||||
private boolean last_connected;
|
||||
private boolean last_metered;
|
||||
private boolean last_roaming;
|
||||
private ParcelFileDescriptor vpn = null;
|
||||
private boolean debug = false;
|
||||
private Thread debugThread = null;
|
||||
|
@ -186,6 +185,8 @@ public class SinkholeService extends VpnService {
|
|||
boolean wifi = Util.isWifiActive(this);
|
||||
boolean metered = Util.isMeteredNetwork(this);
|
||||
boolean useMetered = prefs.getBoolean("use_metered", false);
|
||||
boolean roaming = Util.isRoaming(SinkholeService.this);
|
||||
boolean national = prefs.getBoolean("national_roaming", false);
|
||||
boolean interactive = Util.isInteractive(this);
|
||||
boolean telephony = Util.hasTelephony(this);
|
||||
|
||||
|
@ -200,16 +201,14 @@ public class SinkholeService extends VpnService {
|
|||
last_metered = metered;
|
||||
|
||||
// Update roaming state
|
||||
if (last_roaming != Util.isRoaming(SinkholeService.this)) {
|
||||
last_roaming = !last_roaming;
|
||||
Log.i(TAG, "New state roaming=" + last_roaming);
|
||||
}
|
||||
if (roaming && national)
|
||||
roaming = Util.isInternational(this);
|
||||
|
||||
Log.i(TAG, "Starting connected=" + last_connected +
|
||||
" wifi=" + wifi +
|
||||
" metered=" + metered +
|
||||
" telephony=" + telephony +
|
||||
" roaming=" + last_roaming +
|
||||
" roaming=" + roaming +
|
||||
" interactive=" + interactive);
|
||||
|
||||
// Build VPN service
|
||||
|
@ -227,7 +226,7 @@ public class SinkholeService extends VpnService {
|
|||
for (Rule rule : Rule.getRules(true, TAG, this)) {
|
||||
boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked);
|
||||
boolean screen = (metered ? rule.screen_other : rule.screen_wifi);
|
||||
if ((!blocked || (screen && interactive)) && (!metered || !(rule.roaming && last_roaming))) {
|
||||
if ((!blocked || (screen && interactive)) && (!metered || !(rule.roaming && roaming))) {
|
||||
nAllowed++;
|
||||
if (debug)
|
||||
Log.i(TAG, "Allowing " + rule.info.packageName);
|
||||
|
@ -407,10 +406,6 @@ public class SinkholeService extends VpnService {
|
|||
mServiceLooper = thread.getLooper();
|
||||
mServiceHandler = new ServiceHandler(mServiceLooper);
|
||||
|
||||
last_connected = Util.isConnected(this);
|
||||
last_metered = Util.isMeteredNetwork(this);
|
||||
last_roaming = Util.isRoaming(this);
|
||||
|
||||
// Listen for interactive state changes
|
||||
IntentFilter ifInteractive = new IntentFilter();
|
||||
ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
|
||||
|
|
|
@ -94,17 +94,12 @@ public class Util {
|
|||
|
||||
public static boolean isRoaming(Context context) {
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (tm.isNetworkRoaming()) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (prefs.getBoolean("national_roaming", false)) {
|
||||
// Ignore national roaming
|
||||
Log.i(TAG, "SIM country=" + tm.getSimCountryIso());
|
||||
Log.i(TAG, "Network country=" + tm.getNetworkCountryIso());
|
||||
return (tm.getNetworkCountryIso() == null ? true : !tm.getNetworkCountryIso().equals(tm.getSimCountryIso()));
|
||||
} else
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
return tm.isNetworkRoaming();
|
||||
}
|
||||
|
||||
public static boolean isInternational(Context context) {
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return (tm.getNetworkCountryIso() == null ? true : !tm.getNetworkCountryIso().equals(tm.getSimCountryIso()));
|
||||
}
|
||||
|
||||
public static boolean isInteractive(Context context) {
|
||||
|
@ -232,6 +227,11 @@ public class Util {
|
|||
sb.append(String.format("Metered: %b\r\n", isMeteredNetwork(context)));
|
||||
sb.append(String.format("Telephony: %b\r\n", hasTelephony(context)));
|
||||
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
sb.append(String.format("Network %s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName()));
|
||||
if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
|
||||
sb.append(String.format("SIM %s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName()));
|
||||
|
||||
// Get connectivity info
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
for (Network network : cm.getAllNetworks()) {
|
||||
|
|
Loading…
Reference in New Issue