1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-02-25 07:32:46 +00:00

Added button to filter application with same uid

Also show application settings and launch button for everybody

Closes #309
This commit is contained in:
M66B 2016-02-12 09:22:12 +01:00
parent 13bc0e237d
commit 38ba3513c0
9 changed files with 49 additions and 23 deletions

View file

@ -31,7 +31,6 @@ import android.os.Build;
import android.os.Process; import android.os.Process;
import android.os.SystemClock; import android.os.SystemClock;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -68,6 +67,7 @@ public class Rule {
public boolean screen_other = false; public boolean screen_other = false;
public boolean roaming = false; public boolean roaming = false;
public boolean relateduids = false;
public String[] related = null; public String[] related = null;
public float upspeed; public float upspeed;
@ -246,13 +246,16 @@ public class Rule {
rule.screen_other = screen_other.getBoolean(info.packageName, rule.screen_other_default); rule.screen_other = screen_other.getBoolean(info.packageName, rule.screen_other_default);
rule.roaming = roaming.getBoolean(info.packageName, rule.roaming_default); rule.roaming = roaming.getBoolean(info.packageName, rule.roaming_default);
// Related packages
List<String> listPkg = new ArrayList<>(); List<String> listPkg = new ArrayList<>();
if (pre_related.containsKey(info.packageName)) if (pre_related.containsKey(info.packageName))
listPkg.addAll(Arrays.asList(pre_related.get(info.packageName))); listPkg.addAll(Arrays.asList(pre_related.get(info.packageName)));
String[] pkgs = pm.getPackagesForUid(info.applicationInfo.uid); 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.addAll(Arrays.asList(pkgs));
listPkg.remove(info.packageName); listPkg.remove(info.packageName);
}
rule.related = listPkg.toArray(new String[0]); rule.related = listPkg.toArray(new String[0]);
long up = TrafficStats.getUidTxBytes(rule.info.applicationInfo.uid); long up = TrafficStats.getUidTxBytes(rule.info.applicationInfo.uid);

View file

@ -70,7 +70,6 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
private Activity context; private Activity context;
private RecyclerView rv; private RecyclerView rv;
private boolean filter; private boolean filter;
private boolean debuggable;
private int colorText; private int colorText;
private int colorAccent; private int colorAccent;
private int colorChanged; private int colorChanged;
@ -105,6 +104,10 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
public TextView tvDisabled; public TextView tvDisabled;
public TextView tvInternet; public TextView tvInternet;
public Button btnRelated;
public ImageButton ibSettings;
public ImageButton ibLaunch;
public ImageView ivWifiLegend; public ImageView ivWifiLegend;
public CheckBox cbScreenWifi; public CheckBox cbScreenWifi;
@ -113,8 +116,6 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
public CheckBox cbRoaming; public CheckBox cbRoaming;
public ImageButton btnClear; public ImageButton btnClear;
public ImageButton btnSettings;
public Button btnLaunch;
public ListView lvAccess; public ListView lvAccess;
public TextView tvNolog; public TextView tvNolog;
@ -147,6 +148,10 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
tvDisabled = (TextView) itemView.findViewById(R.id.tvDisabled); tvDisabled = (TextView) itemView.findViewById(R.id.tvDisabled);
tvInternet = (TextView) itemView.findViewById(R.id.tvInternet); 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); ivWifiLegend = (ImageView) itemView.findViewById(R.id.ivWifiLegend);
cbScreenWifi = (CheckBox) itemView.findViewById(R.id.cbScreenWifi); cbScreenWifi = (CheckBox) itemView.findViewById(R.id.cbScreenWifi);
@ -155,8 +160,6 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
cbRoaming = (CheckBox) itemView.findViewById(R.id.cbRoaming); cbRoaming = (CheckBox) itemView.findViewById(R.id.cbRoaming);
btnClear = (ImageButton) itemView.findViewById(R.id.btnClear); 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); lvAccess = (ListView) itemView.findViewById(R.id.lvAccess);
tvNolog = (TextView) itemView.findViewById(R.id.tvNolog); tvNolog = (TextView) itemView.findViewById(R.id.tvNolog);
@ -197,7 +200,6 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
this.context = context; this.context = context;
this.filter = prefs.getBoolean("filter", false); this.filter = prefs.getBoolean("filter", false);
this.debuggable = Util.isDebuggable(context);
if (prefs.getBoolean("dark_theme", false)) if (prefs.getBoolean("dark_theme", false))
colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY), Color.blue(Color.DKGRAY)); 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<RuleAdapter.ViewHolder> im
holder.tvDisabled.setVisibility(rule.enabled ? View.GONE : View.VISIBLE); holder.tvDisabled.setVisibility(rule.enabled ? View.GONE : View.VISIBLE);
holder.tvInternet.setVisibility(rule.internet ? 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 // Launch application settings
final Intent settings = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); final Intent settings = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
settings.setData(Uri.parse("package:" + rule.info.packageName)); settings.setData(Uri.parse("package:" + rule.info.packageName));
holder.btnSettings.setVisibility( holder.ibSettings.setVisibility(settings.resolveActivity(context.getPackageManager()) == null ? View.GONE : View.VISIBLE);
!debuggable || settings.resolveActivity(context.getPackageManager()) == null ? View.GONE : View.VISIBLE); holder.ibSettings.setOnClickListener(new View.OnClickListener() {
holder.btnSettings.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
context.startActivity(settings); context.startActivity(settings);
@ -407,8 +419,8 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
}); });
// Launch application // Launch application
holder.btnLaunch.setVisibility(!debuggable || rule.intent == null ? View.GONE : View.VISIBLE); holder.ibLaunch.setVisibility(rule.intent == null ? View.GONE : View.VISIBLE);
holder.btnLaunch.setOnClickListener(new View.OnClickListener() { holder.ibLaunch.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
context.startActivity(rule.intent); context.startActivity(rule.intent);

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

View file

@ -200,19 +200,30 @@
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageButton
android:id="@+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_settings_white_24dp" />
<Button <Button
android:id="@+id/btnLaunch" android:id="@+id/btnRelated"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/title_related" />
<ImageButton
android:id="@+id/ibSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_settings_white_24dp" />
<ImageButton
android:id="@+id/ibLaunch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:text="@string/title_launch" /> android:src="@drawable/ic_launch_white_24dp" />
</LinearLayout> </LinearLayout>
<TextView <TextView

View file

@ -158,7 +158,7 @@ Your internet traffic is not being sent to a remote VPN server.</string>
<string name="title_roaming">Block when roaming</string> <string name="title_roaming">Block when roaming</string>
<string name="title_disabled">is disabled</string> <string name="title_disabled">is disabled</string>
<string name="title_internet">has no internet permission</string> <string name="title_internet">has no internet permission</string>
<string name="title_launch">Start application</string> <string name="title_related">Filter related</string>
<string name="title_access">Access attempts</string> <string name="title_access">Access attempts</string>
<string name="title_no_log"><u>Logging is not enabled</u></string> <string name="title_no_log"><u>Logging is not enabled</u></string>
<string name="title_precedence">Access rules take precedence over other rules</string> <string name="title_precedence">Access rules take precedence over other rules</string>