mirror of https://github.com/M66B/NetGuard.git
Revert "Remove reverse DNS from access adapter"
This reverts commit fa027e50a2
.
This commit is contained in:
parent
ed53576311
commit
72815e6e79
|
@ -19,42 +19,9 @@ package eu.faircode.netguard;
|
|||
Copyright 2015-2016 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.FilterQueryProvider;
|
||||
import android.widget.ListView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class ActivityDns extends AppCompatActivity {
|
||||
private static final String TAG = "NetGuard.DNS";
|
||||
|
@ -69,7 +36,7 @@ public class ActivityDns extends AppCompatActivity {
|
|||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
ListView lvDns = (ListView) findViewById(R.id.lvDns);
|
||||
lvDns.setAdapter(new DnsAdapter(this, DatabaseHelper.getInstance(this).getDns()));
|
||||
lvDns.setAdapter(new AdapterDns(this, DatabaseHelper.getInstance(this).getDns()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,7 +40,6 @@ import android.widget.Spinner;
|
|||
import android.widget.Toast;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ActivityForwarding extends AppCompatActivity {
|
||||
|
@ -48,7 +47,7 @@ public class ActivityForwarding extends AppCompatActivity {
|
|||
|
||||
private boolean running;
|
||||
private ListView lvForwarding;
|
||||
private ForwardingAdapter adapter;
|
||||
private AdapterForwarding adapter;
|
||||
private AlertDialog dialog = null;
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +62,7 @@ public class ActivityForwarding extends AppCompatActivity {
|
|||
|
||||
|
||||
lvForwarding = (ListView) findViewById(R.id.lvForwarding);
|
||||
adapter = new ForwardingAdapter(this, DatabaseHelper.getInstance(this).getForwarding());
|
||||
adapter = new AdapterForwarding(this, DatabaseHelper.getInstance(this).getForwarding());
|
||||
lvForwarding.setAdapter(adapter);
|
||||
|
||||
lvForwarding.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
@ -87,7 +86,7 @@ public class ActivityForwarding extends AppCompatActivity {
|
|||
if (menuItem.getItemId() == R.id.menu_delete) {
|
||||
DatabaseHelper.getInstance(ActivityForwarding.this).deleteForward(protocol, dport);
|
||||
SinkholeService.reload(null, "forwarding", ActivityForwarding.this);
|
||||
adapter = new ForwardingAdapter(ActivityForwarding.this,
|
||||
adapter = new AdapterForwarding(ActivityForwarding.this,
|
||||
DatabaseHelper.getInstance(ActivityForwarding.this).getForwarding());
|
||||
lvForwarding.setAdapter(adapter);
|
||||
}
|
||||
|
@ -186,7 +185,7 @@ public class ActivityForwarding extends AppCompatActivity {
|
|||
if (running)
|
||||
if (ex == null) {
|
||||
SinkholeService.reload(null, "forwarding", ActivityForwarding.this);
|
||||
adapter = new ForwardingAdapter(ActivityForwarding.this,
|
||||
adapter = new AdapterForwarding(ActivityForwarding.this,
|
||||
DatabaseHelper.getInstance(ActivityForwarding.this).getForwarding());
|
||||
lvForwarding.setAdapter(adapter);
|
||||
} else
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
|
||||
private boolean running = false;
|
||||
private ListView lvLog;
|
||||
private LogAdapter adapter;
|
||||
private AdapterLog adapter;
|
||||
private MenuItem menuSearch = null;
|
||||
|
||||
private boolean live;
|
||||
|
@ -128,7 +128,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
boolean allowed = prefs.getBoolean("traffic_allowed", true);
|
||||
boolean blocked = prefs.getBoolean("traffic_blocked", true);
|
||||
|
||||
adapter = new LogAdapter(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve);
|
||||
adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve);
|
||||
adapter.setFilterQueryProvider(new FilterQueryProvider() {
|
||||
public Cursor runQuery(CharSequence constraint) {
|
||||
return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString());
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
|
||||
private boolean running = false;
|
||||
private SwipeRefreshLayout swipeRefresh;
|
||||
private RuleAdapter adapter = null;
|
||||
private AdapterRule adapter = null;
|
||||
private MenuItem menuSearch = null;
|
||||
private AlertDialog dialogFirst = null;
|
||||
private AlertDialog dialogVpn = null;
|
||||
|
@ -184,7 +184,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
|
||||
rvApplication.setHasFixedSize(true);
|
||||
rvApplication.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new RuleAdapter(this);
|
||||
adapter = new AdapterRule(this);
|
||||
rvApplication.setAdapter(adapter);
|
||||
|
||||
// Swipe to refresh
|
||||
|
|
|
@ -38,9 +38,10 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class AccessAdapter extends CursorAdapter {
|
||||
public class AdapterAccess extends CursorAdapter {
|
||||
private static String TAG = "NetGuard.Access";
|
||||
|
||||
private int colID;
|
||||
private int colVersion;
|
||||
private int colProtocol;
|
||||
private int colDaddr;
|
||||
|
@ -53,8 +54,9 @@ public class AccessAdapter extends CursorAdapter {
|
|||
private int colorOn;
|
||||
private int colorOff;
|
||||
|
||||
public AccessAdapter(Context context, Cursor cursor) {
|
||||
public AdapterAccess(Context context, Cursor cursor) {
|
||||
super(context, cursor, 0);
|
||||
colID = cursor.getColumnIndex("ID");
|
||||
colVersion = cursor.getColumnIndex("version");
|
||||
colProtocol = cursor.getColumnIndex("protocol");
|
||||
colDaddr = cursor.getColumnIndex("daddr");
|
||||
|
@ -85,6 +87,7 @@ public class AccessAdapter extends CursorAdapter {
|
|||
@Override
|
||||
public void bindView(final View view, final Context context, final Cursor cursor) {
|
||||
// Get values
|
||||
final long id = cursor.getLong(colID);
|
||||
final int version = cursor.getInt(colVersion);
|
||||
final int protocol = cursor.getInt(colProtocol);
|
||||
final String daddr = cursor.getString(colDaddr);
|
||||
|
@ -114,6 +117,28 @@ public class AccessAdapter extends CursorAdapter {
|
|||
Util.getProtocolName(protocol, version, true) +
|
||||
" " + daddr + (dport > 0 ? "/" + dport : ""));
|
||||
|
||||
if (Util.isNumericAddress(daddr)) {
|
||||
tvDest.setTag(id);
|
||||
new AsyncTask<String, Object, String>() {
|
||||
@Override
|
||||
protected String doInBackground(String... args) {
|
||||
try {
|
||||
return InetAddress.getByName(args[0]).getHostName();
|
||||
} catch (UnknownHostException ignored) {
|
||||
return args[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String addr) {
|
||||
if ((Long) tvDest.getTag() == id)
|
||||
tvDest.setText(
|
||||
Util.getProtocolName(protocol, version, true) +
|
||||
" " + addr + (dport > 0 ? "/" + dport : ""));
|
||||
}
|
||||
}.execute(daddr);
|
||||
}
|
||||
|
||||
if (allowed < 0)
|
||||
tvDest.setTextColor(colorText);
|
||||
else if (allowed > 0)
|
|
@ -20,22 +20,16 @@ package eu.faircode.netguard;
|
|||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class DnsAdapter extends CursorAdapter {
|
||||
public class AdapterDns extends CursorAdapter {
|
||||
private static String TAG = "NetGuard.DNS";
|
||||
|
||||
private int colTime;
|
||||
|
@ -44,7 +38,7 @@ public class DnsAdapter extends CursorAdapter {
|
|||
private int colResource;
|
||||
private int colTTL;
|
||||
|
||||
public DnsAdapter(Context context, Cursor cursor) {
|
||||
public AdapterDns(Context context, Cursor cursor) {
|
||||
super(context, cursor, 0);
|
||||
colTime = cursor.getColumnIndex("time");
|
||||
colQName = cursor.getColumnIndex("qname");
|
|
@ -28,7 +28,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.CursorAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ForwardingAdapter extends CursorAdapter {
|
||||
public class AdapterForwarding extends CursorAdapter {
|
||||
private static String TAG = "NetGuard.Forward";
|
||||
|
||||
private int colProtocol;
|
||||
|
@ -37,7 +37,7 @@ public class ForwardingAdapter extends CursorAdapter {
|
|||
private int colRPort;
|
||||
private int colRUid;
|
||||
|
||||
public ForwardingAdapter(Context context, Cursor cursor) {
|
||||
public AdapterForwarding(Context context, Cursor cursor) {
|
||||
super(context, cursor, 0);
|
||||
colProtocol = cursor.getColumnIndex("protocol");
|
||||
colDPort = cursor.getColumnIndex("dport");
|
|
@ -46,10 +46,11 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class LogAdapter extends CursorAdapter {
|
||||
public class AdapterLog extends CursorAdapter {
|
||||
private static String TAG = "NetGuard.Log";
|
||||
|
||||
private boolean resolve;
|
||||
private int colID;
|
||||
private int colTime;
|
||||
private int colVersion;
|
||||
private int colProtocol;
|
||||
|
@ -70,9 +71,10 @@ public class LogAdapter extends CursorAdapter {
|
|||
private InetAddress vpn4 = null;
|
||||
private InetAddress vpn6 = null;
|
||||
|
||||
public LogAdapter(Context context, Cursor cursor, boolean resolve) {
|
||||
public AdapterLog(Context context, Cursor cursor, boolean resolve) {
|
||||
super(context, cursor, 0);
|
||||
this.resolve = resolve;
|
||||
colID = cursor.getColumnIndex("ID");
|
||||
colTime = cursor.getColumnIndex("time");
|
||||
colVersion = cursor.getColumnIndex("version");
|
||||
colProtocol = cursor.getColumnIndex("protocol");
|
||||
|
@ -116,6 +118,7 @@ public class LogAdapter extends CursorAdapter {
|
|||
@Override
|
||||
public void bindView(final View view, final Context context, final Cursor cursor) {
|
||||
// Get values
|
||||
final long id = cursor.getLong(colID);
|
||||
long time = cursor.getLong(colTime);
|
||||
int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
|
||||
int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
|
||||
|
@ -210,12 +213,12 @@ public class LogAdapter extends CursorAdapter {
|
|||
else
|
||||
tvUid.setText(Integer.toString(uid));
|
||||
|
||||
// TODO resolve source when inbound
|
||||
tvSAddr.setText(getKnownAddress(saddr));
|
||||
|
||||
if (resolve && !isKnownAddress(daddr))
|
||||
if (dname == null) {
|
||||
tvDaddr.setText(daddr);
|
||||
tvDaddr.setTag(id);
|
||||
new AsyncTask<String, Object, String>() {
|
||||
@Override
|
||||
protected String doInBackground(String... args) {
|
||||
|
@ -228,7 +231,8 @@ public class LogAdapter extends CursorAdapter {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(String name) {
|
||||
tvDaddr.setText(name);
|
||||
if ((Long) tvDaddr.getTag() == id)
|
||||
tvDaddr.setText(name);
|
||||
}
|
||||
}.execute(daddr);
|
||||
} else
|
|
@ -64,7 +64,7 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> implements Filterable {
|
||||
public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> implements Filterable {
|
||||
private static final String TAG = "NetGuard.Adapter";
|
||||
|
||||
private Activity context;
|
||||
|
@ -195,7 +195,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
}
|
||||
}
|
||||
|
||||
public RuleAdapter(Activity context) {
|
||||
public AdapterRule(Activity context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
this.context = context;
|
||||
|
@ -553,7 +553,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
// Show access rules
|
||||
if (rule.expanded) {
|
||||
// Access the database when expanded only
|
||||
final AccessAdapter badapter = new AccessAdapter(context,
|
||||
final AdapterAccess badapter = new AdapterAccess(context,
|
||||
DatabaseHelper.getInstance(context).getAccess(rule.info.applicationInfo.uid));
|
||||
if (filter)
|
||||
holder.lvAccess.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
@ -760,7 +760,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
}
|
||||
|
||||
@Override
|
||||
public RuleAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public AdapterRule.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.rule, parent, false));
|
||||
}
|
||||
|
Loading…
Reference in New Issue