1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-02-22 22:31:17 +00:00

Mute some logging, improvements

This commit is contained in:
M66B 2015-11-08 09:40:17 +01:00
parent a11097d992
commit a5be9d2ec3
7 changed files with 22 additions and 21 deletions

View file

@ -150,7 +150,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
if (running) { if (running) {
Log.i(TAG, "Start intent=" + prepare); Log.i(TAG, "Start intent=" + prepare);
try { try {
prefs.edit().putBoolean("enabled", true).apply();
startActivityForResult(prepare, REQUEST_VPN); startActivityForResult(prepare, REQUEST_VPN);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
@ -384,6 +383,10 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
private BroadcastReceiver connectivityChangedReceiver = new BroadcastReceiver() { private BroadcastReceiver connectivityChangedReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
int networkType = intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_DUMMY);
if (networkType == ConnectivityManager.TYPE_VPN)
return;
Log.i(TAG, "Received " + intent); Log.i(TAG, "Received " + intent);
Util.logExtras(TAG, intent); Util.logExtras(TAG, intent);

View file

@ -142,7 +142,8 @@ public class SinkholeService extends VpnService {
for (Rule rule : Rule.getRules(true, TAG, this)) { for (Rule rule : Rule.getRules(true, TAG, this)) {
boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked); boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked);
if ((!blocked || (rule.unused && interactive)) && (!metered || !(rule.roaming && roaming))) { if ((!blocked || (rule.unused && interactive)) && (!metered || !(rule.roaming && roaming))) {
Log.i(TAG, "Allowing " + rule.info.packageName); if (debug)
Log.i(TAG, "Allowing " + rule.info.packageName);
try { try {
builder.addDisallowedApplication(rule.info.packageName); builder.addDisallowedApplication(rule.info.packageName);
} catch (PackageManager.NameNotFoundException ex) { } catch (PackageManager.NameNotFoundException ex) {
@ -269,6 +270,11 @@ public class SinkholeService extends VpnService {
private BroadcastReceiver connectivityChangedReceiver = new BroadcastReceiver() { private BroadcastReceiver connectivityChangedReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
// Get network type
int networkType = intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_DUMMY);
if (!debug && networkType == ConnectivityManager.TYPE_VPN)
return;
Log.i(TAG, "Received " + intent); Log.i(TAG, "Received " + intent);
Util.logExtras(TAG, intent); Util.logExtras(TAG, intent);
@ -278,9 +284,7 @@ public class SinkholeService extends VpnService {
Log.i(TAG, "New state roaming=" + last_roaming); Log.i(TAG, "New state roaming=" + last_roaming);
reload(null, SinkholeService.this); reload(null, SinkholeService.this);
} else if (intent.hasExtra(ConnectivityManager.EXTRA_NETWORK_TYPE) && } else if (networkType == ConnectivityManager.TYPE_WIFI) {
intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_DUMMY) ==
ConnectivityManager.TYPE_WIFI) {
// Wifi connected/disconnected // Wifi connected/disconnected
reload(null, SinkholeService.this); reload(null, SinkholeService.this);
} }
@ -344,17 +348,17 @@ public class SinkholeService extends VpnService {
public void onDestroy() { public void onDestroy() {
Log.i(TAG, "Destroy"); Log.i(TAG, "Destroy");
if (vpn != null) { mServiceLooper.quit();
stopDebug();
stopVPN(vpn);
vpn = null;
}
unregisterReceiver(interactiveStateReceiver); unregisterReceiver(interactiveStateReceiver);
unregisterReceiver(connectivityChangedReceiver); unregisterReceiver(connectivityChangedReceiver);
unregisterReceiver(packageAddedReceiver); unregisterReceiver(packageAddedReceiver);
mServiceLooper.quit(); if (vpn != null) {
stopDebug();
stopVPN(vpn);
vpn = null;
}
super.onDestroy(); super.onDestroy();
} }
@ -363,17 +367,11 @@ public class SinkholeService extends VpnService {
public void onRevoke() { public void onRevoke() {
Log.i(TAG, "Revoke"); Log.i(TAG, "Revoke");
// Disable firewall // Disable firewall (will result in stop command)
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putBoolean("enabled", false).apply(); prefs.edit().putBoolean("enabled", false).apply();
if (vpn != null) { // Feedback
stopDebug();
stopVPN(vpn);
vpn = null;
}
// Display warning
showDisabledNotification(); showDisabledNotification();
Widget.updateWidgets(this); Widget.updateWidgets(this);
@ -391,7 +389,7 @@ public class SinkholeService extends VpnService {
.setContentIntent(pi) .setContentIntent(pi)
.setCategory(Notification.CATEGORY_STATUS) .setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_SECRET) .setVisibility(Notification.VISIBILITY_SECRET)
.setColor(ContextCompat.getColor(this, R.color.colorAccent)) .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setAutoCancel(true); .setAutoCancel(true);
return notification.build(); return notification.build();
@ -402,7 +400,7 @@ public class SinkholeService extends VpnService {
PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this) NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_security_white_24dp) .setSmallIcon(R.drawable.ic_error_white_24dp)
.setContentTitle(getString(R.string.app_name)) .setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_revoked)) .setContentText(getString(R.string.msg_revoked))
.setContentIntent(pi) .setContentIntent(pi)

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B