From 38ba3513c098810d1f077581d78fb601f05af767 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 12 Feb 2016 09:22:12 +0100 Subject: [PATCH] Added button to filter application with same uid Also show application settings and launch button for everybody Closes #309 --- .../main/java/eu/faircode/netguard/Rule.java | 9 +++-- .../eu/faircode/netguard/RuleAdapter.java | 34 ++++++++++++------ .../drawable-hdpi/ic_launch_white_24dp.png | Bin 0 -> 253 bytes .../drawable-mdpi/ic_launch_white_24dp.png | Bin 0 -> 175 bytes .../drawable-xhdpi/ic_launch_white_24dp.png | Bin 0 -> 258 bytes .../drawable-xxhdpi/ic_launch_white_24dp.png | Bin 0 -> 343 bytes .../drawable-xxxhdpi/ic_launch_white_24dp.png | Bin 0 -> 434 bytes app/src/main/res/layout/rule.xml | 27 +++++++++----- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_launch_white_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_launch_white_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_launch_white_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_launch_white_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_launch_white_24dp.png diff --git a/app/src/main/java/eu/faircode/netguard/Rule.java b/app/src/main/java/eu/faircode/netguard/Rule.java index e568d016..7dd233f6 100644 --- a/app/src/main/java/eu/faircode/netguard/Rule.java +++ b/app/src/main/java/eu/faircode/netguard/Rule.java @@ -31,7 +31,6 @@ import android.os.Build; import android.os.Process; import android.os.SystemClock; import android.preference.PreferenceManager; -import android.text.TextUtils; import android.util.Log; import org.xmlpull.v1.XmlPullParser; @@ -68,6 +67,7 @@ public class Rule { public boolean screen_other = false; public boolean roaming = false; + public boolean relateduids = false; public String[] related = null; public float upspeed; @@ -246,13 +246,16 @@ public class Rule { rule.screen_other = screen_other.getBoolean(info.packageName, rule.screen_other_default); rule.roaming = roaming.getBoolean(info.packageName, rule.roaming_default); + // Related packages List listPkg = new ArrayList<>(); if (pre_related.containsKey(info.packageName)) listPkg.addAll(Arrays.asList(pre_related.get(info.packageName))); String[] pkgs = pm.getPackagesForUid(info.applicationInfo.uid); - if (pkgs != null) + if (pkgs != null && pkgs.length > 1) { + rule.relateduids = true; listPkg.addAll(Arrays.asList(pkgs)); - listPkg.remove(info.packageName); + listPkg.remove(info.packageName); + } rule.related = listPkg.toArray(new String[0]); long up = TrafficStats.getUidTxBytes(rule.info.applicationInfo.uid); diff --git a/app/src/main/java/eu/faircode/netguard/RuleAdapter.java b/app/src/main/java/eu/faircode/netguard/RuleAdapter.java index 56f4823f..0115dcb0 100644 --- a/app/src/main/java/eu/faircode/netguard/RuleAdapter.java +++ b/app/src/main/java/eu/faircode/netguard/RuleAdapter.java @@ -70,7 +70,6 @@ public class RuleAdapter extends RecyclerView.Adapter im private Activity context; private RecyclerView rv; private boolean filter; - private boolean debuggable; private int colorText; private int colorAccent; private int colorChanged; @@ -105,6 +104,10 @@ public class RuleAdapter extends RecyclerView.Adapter im public TextView tvDisabled; public TextView tvInternet; + public Button btnRelated; + public ImageButton ibSettings; + public ImageButton ibLaunch; + public ImageView ivWifiLegend; public CheckBox cbScreenWifi; @@ -113,8 +116,6 @@ public class RuleAdapter extends RecyclerView.Adapter im public CheckBox cbRoaming; public ImageButton btnClear; - public ImageButton btnSettings; - public Button btnLaunch; public ListView lvAccess; public TextView tvNolog; @@ -147,6 +148,10 @@ public class RuleAdapter extends RecyclerView.Adapter im tvDisabled = (TextView) itemView.findViewById(R.id.tvDisabled); tvInternet = (TextView) itemView.findViewById(R.id.tvInternet); + btnRelated = (Button) itemView.findViewById(R.id.btnRelated); + ibSettings = (ImageButton) itemView.findViewById(R.id.ibSettings); + ibLaunch = (ImageButton) itemView.findViewById(R.id.ibLaunch); + ivWifiLegend = (ImageView) itemView.findViewById(R.id.ivWifiLegend); cbScreenWifi = (CheckBox) itemView.findViewById(R.id.cbScreenWifi); @@ -155,8 +160,6 @@ public class RuleAdapter extends RecyclerView.Adapter im cbRoaming = (CheckBox) itemView.findViewById(R.id.cbRoaming); btnClear = (ImageButton) itemView.findViewById(R.id.btnClear); - btnSettings = (ImageButton) itemView.findViewById(R.id.btnSettings); - btnLaunch = (Button) itemView.findViewById(R.id.btnLaunch); lvAccess = (ListView) itemView.findViewById(R.id.lvAccess); tvNolog = (TextView) itemView.findViewById(R.id.tvNolog); @@ -197,7 +200,6 @@ public class RuleAdapter extends RecyclerView.Adapter im this.context = context; this.filter = prefs.getBoolean("filter", false); - this.debuggable = Util.isDebuggable(context); if (prefs.getBoolean("dark_theme", false)) colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY), Color.blue(Color.DKGRAY)); @@ -394,12 +396,22 @@ public class RuleAdapter extends RecyclerView.Adapter im holder.tvDisabled.setVisibility(rule.enabled ? View.GONE : View.VISIBLE); holder.tvInternet.setVisibility(rule.internet ? View.GONE : View.VISIBLE); + // Show related + holder.btnRelated.setVisibility(rule.relateduids ? View.VISIBLE : View.GONE); + holder.btnRelated.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent main = new Intent(context, ActivityMain.class); + main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(rule.info.applicationInfo.uid)); + context.startActivity(main); + } + }); + // Launch application settings final Intent settings = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); settings.setData(Uri.parse("package:" + rule.info.packageName)); - holder.btnSettings.setVisibility( - !debuggable || settings.resolveActivity(context.getPackageManager()) == null ? View.GONE : View.VISIBLE); - holder.btnSettings.setOnClickListener(new View.OnClickListener() { + holder.ibSettings.setVisibility(settings.resolveActivity(context.getPackageManager()) == null ? View.GONE : View.VISIBLE); + holder.ibSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { context.startActivity(settings); @@ -407,8 +419,8 @@ public class RuleAdapter extends RecyclerView.Adapter im }); // Launch application - holder.btnLaunch.setVisibility(!debuggable || rule.intent == null ? View.GONE : View.VISIBLE); - holder.btnLaunch.setOnClickListener(new View.OnClickListener() { + holder.ibLaunch.setVisibility(rule.intent == null ? View.GONE : View.VISIBLE); + holder.ibLaunch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { context.startActivity(rule.intent); diff --git a/app/src/main/res/drawable-hdpi/ic_launch_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_launch_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..49726bcbf047714d9180a44ec606aceb2256e281 GIT binary patch literal 253 zcmVP3#=L&}U6B+P-G4@FKB(~vDl znBYOexKQN$%(##;nnE7)22#d_A{S+5zL7E(q>KeA<3meEVa%(o7=Oy(03a!}!C9+NL(kk@X#^^i{IV-0+QJBA^%Kw?)|0-vzAsPa00000NkvXXu0mjf DTn1)U literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_launch_white_24dp.png b/app/src/main/res/drawable-mdpi/ic_launch_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..474cc8092d0737af7949cc6c349104abe9f88726 GIT binary patch literal 175 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+iGEW!BkP61L=MHi{Q8 z=SNY*f}QM>PO~i8$vBDsMW>xdyw1h XS<4nSyWCKq3m80I{an^LB{Ts5_(49t literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_launch_white_24dp.png b/app/src/main/res/drawable-xhdpi/ic_launch_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..a2caac511238c3839af6e1c4620e057054d78491 GIT binary patch literal 258 zcmV+d0sa1oP)9Kly>cAgv3GD+BhRbZ5;x;CULb{0sw@Kf!?I0|qP)1D#fpYG4bjm1j~92c&W-ur68k@Ae|tCkfw{L~I;%;4r z1-e2^T073U%u(tVc%!XAnAxln+}UMbF#JCde`oK$1r4X%nY83N zSJbF1_*BU-|34?gjX%~52cDTT9C*sipeN5z@ROn8G&@6#9m9i9j11HH8Fu{H$7uII zj29up_~7&M`<9G$2*q{hfkp-Xlx3~~Y2$3*{CW592{0RCL=D9B{rL^&_Xje=4L{Fd zGrNZ6ftU1Teg+Z8sr*bL3qJ)mD23Q@2ed3d#m?}DRltFPkp)D^T)F)1GUNMKnYUjy zxPRU9wB$g{;;Ne~UcYQu=D0U!X&KLhAnC6g#A7QOlzF87|9l)d^AFRE*{>b*Z@s>A qJ9~9%?Qc1U9SnZ;5Yt!$4w$=&<>p-Ti<1Gy1%s!npUXO@geCxg|E?AQ literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/rule.xml b/app/src/main/res/layout/rule.xml index 457f34fa..0bd179d7 100644 --- a/app/src/main/res/layout/rule.xml +++ b/app/src/main/res/layout/rule.xml @@ -200,19 +200,30 @@ android:layout_marginTop="4dp" android:orientation="horizontal"> - -