From a5be9d2ec3d2e02c51c33267c60f457de62c26a8 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 8 Nov 2015 09:40:17 +0100 Subject: [PATCH] Mute some logging, improvements --- .../eu/faircode/netguard/ActivityMain.java | 5 ++- .../eu/faircode/netguard/SinkholeService.java | 38 +++++++++--------- .../res/drawable-hdpi/ic_error_white_24dp.png | Bin 0 -> 324 bytes .../res/drawable-mdpi/ic_error_white_24dp.png | Bin 0 -> 232 bytes .../drawable-xhdpi/ic_error_white_24dp.png | Bin 0 -> 431 bytes .../drawable-xxhdpi/ic_error_white_24dp.png | Bin 0 -> 614 bytes .../drawable-xxxhdpi/ic_error_white_24dp.png | Bin 0 -> 814 bytes 7 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_error_white_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_error_white_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_error_white_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_error_white_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_error_white_24dp.png diff --git a/app/src/main/java/eu/faircode/netguard/ActivityMain.java b/app/src/main/java/eu/faircode/netguard/ActivityMain.java index 408509a8..28776633 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityMain.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityMain.java @@ -150,7 +150,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences if (running) { Log.i(TAG, "Start intent=" + prepare); try { - prefs.edit().putBoolean("enabled", true).apply(); startActivityForResult(prepare, REQUEST_VPN); } catch (Throwable 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() { @Override 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); Util.logExtras(TAG, intent); diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index 84fe808b..e0a6a64f 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -142,7 +142,8 @@ public class SinkholeService extends VpnService { for (Rule rule : Rule.getRules(true, TAG, this)) { boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked); 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 { builder.addDisallowedApplication(rule.info.packageName); } catch (PackageManager.NameNotFoundException ex) { @@ -269,6 +270,11 @@ public class SinkholeService extends VpnService { private BroadcastReceiver connectivityChangedReceiver = new BroadcastReceiver() { @Override 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); Util.logExtras(TAG, intent); @@ -278,9 +284,7 @@ public class SinkholeService extends VpnService { Log.i(TAG, "New state roaming=" + last_roaming); reload(null, SinkholeService.this); - } else if (intent.hasExtra(ConnectivityManager.EXTRA_NETWORK_TYPE) && - intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_DUMMY) == - ConnectivityManager.TYPE_WIFI) { + } else if (networkType == ConnectivityManager.TYPE_WIFI) { // Wifi connected/disconnected reload(null, SinkholeService.this); } @@ -344,17 +348,17 @@ public class SinkholeService extends VpnService { public void onDestroy() { Log.i(TAG, "Destroy"); - if (vpn != null) { - stopDebug(); - stopVPN(vpn); - vpn = null; - } + mServiceLooper.quit(); unregisterReceiver(interactiveStateReceiver); unregisterReceiver(connectivityChangedReceiver); unregisterReceiver(packageAddedReceiver); - mServiceLooper.quit(); + if (vpn != null) { + stopDebug(); + stopVPN(vpn); + vpn = null; + } super.onDestroy(); } @@ -363,17 +367,11 @@ public class SinkholeService extends VpnService { public void onRevoke() { Log.i(TAG, "Revoke"); - // Disable firewall + // Disable firewall (will result in stop command) SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.edit().putBoolean("enabled", false).apply(); - if (vpn != null) { - stopDebug(); - stopVPN(vpn); - vpn = null; - } - - // Display warning + // Feedback showDisabledNotification(); Widget.updateWidgets(this); @@ -391,7 +389,7 @@ public class SinkholeService extends VpnService { .setContentIntent(pi) .setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_SECRET) - .setColor(ContextCompat.getColor(this, R.color.colorAccent)) + .setColor(ContextCompat.getColor(this, R.color.colorPrimary)) .setAutoCancel(true); return notification.build(); @@ -402,7 +400,7 @@ public class SinkholeService extends VpnService { PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_CANCEL_CURRENT); 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)) .setContentText(getString(R.string.msg_revoked)) .setContentIntent(pi) diff --git a/app/src/main/res/drawable-hdpi/ic_error_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_error_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..69cbb1e0bd3807d27f4197a9328467df8397e169 GIT binary patch literal 324 zcmV-K0lWT*P)gGbr{!4DC&5DTe055otv=(oBcbwiQ9yc={9S=wqGvvb{)YG_-cTkwp}f z`yT&OF!RTU{~tMq?Z(U8YgIoe@jCRcP1rd4N|RY{%7e{VkWP)9pDS`rt8>j14g%vJK^s@CixA{JOk4QTA=JOC;K#wgGmprXKRz!nAc zA3zb4$$%jWbOzK>BbED)TQ7myeVhoz2|$d zb8`?1e$Og=AO=p3^FQ2v1vo`5um^p+ctP+U`du{Cg2BIYu^K^T*z8PSr06@ zpYw0-H`M_jNko7vwcEfLL;x7x0$h$_z@D56d;>86zNo-J6zHkIN)+%_AQS}x6*!9m zkqRWDK>P&Y>5nKxvcT|~X3kfEK9Y4+powG+6>vF-{mDCWD&Q~@1Kw`$gF3O$!g;S- znKKb!qTk6CPGs#5B|YHKA!{wuhu4fO{lqZ=9vf_1lQ#nnMN49>{rFYJqtG0D3I)9=d59Kjp*^Xg722Dkhl0YY!4OL5BZS<; z61=$^@!wOAvpYLG^KB0M-}Ax`HcMva+o_^St*D4Hn>1TvB%jTH^te+N{_IE%A#iov~;Ww9O+~8_}=>n&BI^ zI--;nG>?zXu6dmW zsy^r^5`EVNtszxi5A;CV{@^j=ui!6F8|2Y@HE50q*%Fo?Q`{q+AHQPUL%N-$MgCaywU1ax z+6G;Ug3gooWpz=|Tb-?RTMXpu?d?~P>4jz8YL)m<^&~w09$TEDXaAWylm9vhgN*rOUk4)Pc;58VL zwSX;~BhD&6FzauW`W`-6GCecK;!P$1b;o#Px*Fj`{^R2dS@F z);Z*a4t<7%gbeA^;g|#7@k-=V3xlfw6`%t24_R#olFFzoX8-^I07*qoM6N<$f=(S9 A<^TWy literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_error_white_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_error_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..830fb7e1e6860117fa31155fa24e5002984d1444 GIT binary patch literal 814 zcmV+}1JV46P)OpZvS)hbY2bjDdCIt{;m^E&&TAfu=g!~1xk)e#84w<3VA3%)v zT;W8QWNGmlFhK<;J7(NFz$5aw(K=mT04Ay7R#jfR3y83c+nI#j0wmeRi*`u30qCQQ zR~6}T8t{Y@ysSdMlYl->@VW}UP63jX@uMOMCjb$4@v9xe_5sWInQ0d=iQi4w0rXJA z@2Ye)4#*>+^+o{`NNKDQK#U4@`v3FnbVSrT;2nqoz?@Y;8&{$L7sRarG9U^7(^dc> z%HjYeLi&JV5C?!keZZPXz=|#)&W%Vwji?@A6hs1GL=Rw!1?2PqMX`W=9Y80D1wcX# zNQ(xf)PSsLz?>SeBpP6<0o$Shc{QLQ8nCAZoQnpWssXp60d+OtUNqqDF967Yh5q!9 z__zNV-9mDkYQQ3rn^yy}NN!dQNF%u+H6V%P+SLGq1Ef~K&;iUNwGVoL=Sc0T9w0_t z