Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoZenz committed Dec 11, 2021
2 parents 6209fe7 + 2625669 commit d3de267
Show file tree
Hide file tree
Showing 23 changed files with 326 additions and 47 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
compileSdkVersion 30
buildToolsVersion '30.0.2'

defaultConfig {
applicationId "dnsfilter.android"
minSdkVersion 14
targetSdkVersion 29
targetSdkVersion 30
}

buildTypes {
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dnsfilter.android"
android:versionCode="1505001"
android:versionName="1.50.50.1">
android:versionCode="1505100"
android:versionName="1.50.51.0">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>

<application
android:usesCleartextTraffic="true"
Expand All @@ -20,8 +20,7 @@
android:theme="@style/Theme.phttpp.TitleBar">
<activity
android:name="dnsfilter.android.DNSProxyActivity"
android:label="personalDNSfilter"
android:screenOrientation="portrait">
android:label="personalDNSfilter">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/assets/dnsfilter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ routeUnderlyingDNS = false
# Uncomment setting below for using this option.
# As an example below the list of Google DNS servers for IPV4 and IPV6.
# This should avoid hardcoded usage of Google DNS Servers, bypassing system DNS settings.
# routeIPs = 8.8.8.8; 8.8.4.4; 2001:4860:4860::8888; 2001:4860:4860::8844
# e.g. routeIPs = 8.8.8.8; 8.8.4.4; 2001:4860:4860::8888; 2001:4860:4860::8844
routeIPs =

# AUTOSTART = true|false - used only by Android version.
# if true android app is started automatically on device boot completed.
Expand Down Expand Up @@ -195,10 +196,14 @@ logTextSize = 14
# repeatingLogSuppressTime - time in milliseconds in which repeating logs are suppressed
repeatingLogSuppressTime = 2000

# live log timestamp settings
addLiveLogTimestamp = true
liveLogTimeStampFormat = '<font color=''#8c8c8c''><strong>'HH:mm:ss'</strong></font>'

# Text and Link for the footer bar
footerLink = <strong>Want to support us? Feel free to <a href='https://www.paypal.me/iZenz'>DONATE</a></strong>!

# Initial info PopUp
showInitialInfoPopUp = true
initialInfoPopUpTitle = Consider your rating!
initialInfoPopUpText = Thanks for using our free app personalDNSfilter!\nSometimes we get bad ratings due to misunderstanding.\nTherefore, before rating, please check our <a href='https://www.zenz-home.com/personaldnsfilter/help/faq.php'>FAQ</a></strong>, or ask our <a href='https://telegram.me/pdnsf'>Telegram group</a></strong>.\nA bad rating is not motivating to provide this free app further.
initialInfoPopUpText = Thanks for using our free app personalDNSfilter! Sometimes we get bad ratings due to misunderstanding. Therefore, before rating, please check our <a href='https://www.zenz-home.com/personaldnsfilter/help/faq.php'>FAQ</a></strong>, or ask our <a href='https://telegram.me/pdnsf'>Telegram group</a></strong>. A bad rating is not motivating to provide this free app further. <br><br><strong>In case you do not want to invest time to understand a possible issue, then just uninstall the app and do not provide an uneducated rating!</strong>
8 changes: 6 additions & 2 deletions app/src/main/java/dnsfilter/DNSFilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ of the License, or (at your option) any later version.

public class DNSFilterManager extends ConfigurationAccess {

public static final String VERSION = "1505001";
public static final String VERSION = "1505100";

private static DNSFilterManager INSTANCE = new DNSFilterManager();

Expand Down Expand Up @@ -330,7 +330,7 @@ private byte[] mergeAndPersistConfig(byte[] currentConfigBytes) throws IOExcepti
if (ln.startsWith(currentKeys[i] + " =")) {
if (currentKeys[i].equals("filterActive") && filterDisabledV15045)
ln = "filterActive = false";
else
else if (!useDefaultConfig(currentKeys[i]))
ln = currentKeys[i] + " = " + currentConfig.getProperty(currentKeys[i], "").replace("\n","\\n");
}
}
Expand Down Expand Up @@ -363,6 +363,10 @@ private byte[] mergeAndPersistConfig(byte[] currentConfigBytes) throws IOExcepti
return configBytes;
}

private boolean useDefaultConfig(String currentKey) {
return ( currentKey.equals("initialInfoPopUpText") || currentKey.equals("initialInfoPopUpTitle"));
}


private void createDefaultConfiguration() {
try {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/dnsfilter/DNSFilterProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ of the License, or (at your option) any later version.
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.Vector;

Expand Down Expand Up @@ -156,6 +158,13 @@ public void closeLogger() {
long repeatingLogSuppressTime = Long.parseLong(DNSFilterManager.getInstance().getConfig().getProperty("repeatingLogSuppressTime", "1000"));
myLogger.setSuppressTime(repeatingLogSuppressTime);

boolean liveLogTimestampEnabled = Boolean.parseBoolean(DNSFilterManager.getInstance().getConfig().getProperty("addLiveLogTimestamp", "false"));
myLogger.setTimestampFormat(null);
if (liveLogTimestampEnabled) {
String timeStampPattern = DNSFilterManager.getInstance().getConfig().getProperty("liveLogTimeStampFormat", "hh:mm:ss");
myLogger.setTimestampFormat(timeStampPattern);
}

initDNS(filtermgr);

int port = Integer.parseInt(DNSFilterManager.getInstance().getConfig().getProperty("dnsProxyPortNonAndroid","53"));
Expand Down
31 changes: 21 additions & 10 deletions app/src/main/java/dnsfilter/DNSServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,9 @@ public String getProtocolName(){

@Override
public void resolve(DatagramPacket request, DatagramPacket response) throws IOException {
for (int i = 0; i<2; i++) { //retry once in case of EOFException (pooled connection was already closed)
Connection con = Connection.connect(address, timeout, ssl, null, proxy);

Connection con = Connection.connect(address, timeout, ssl, null, proxy);
for (int i = 0; i < 2; i++) { //retry once in case of EOFException (pooled connection was already closed)
con.setSoTimeout(timeout);
try {
DataInputStream in = new DataInputStream(con.getInputStream());
Expand All @@ -437,9 +438,13 @@ public void resolve(DatagramPacket request, DatagramPacket response) throws IOEx
con.release(true);
return;
} catch (EOFException eof) {
con.release(false);
if (i == 1)
throw new IOException ("EOF when reading from "+this.toString(),eof); // retried already once, now throw exception
if (i == 0)
// pooled connection was closed in between - refresh connection and retry!
con.refreshConnection();
else {
con.release(false);
throw new IOException("EOF when reading from " + this.toString(), eof); // retried already once, now throw exception
}
} catch (IOException eio) {
con.release(false);
throw eio;
Expand Down Expand Up @@ -492,8 +497,10 @@ public void resolve(DatagramPacket request, DatagramPacket response) throws IOEx

byte[] reqHeader = buildRequestHeader(request.getLength());

Connection con = Connection.connect(urlHostAddress, timeout, true, null, proxy);
con.setSoTimeout(timeout);

for (int i = 0; i<2; i++) { //retry once in case of EOFException (pooled connection was already closed)
Connection con = Connection.connect(urlHostAddress, timeout, true, null, proxy);

try {
OutputStream out = con.getOutputStream();
Expand Down Expand Up @@ -530,12 +537,16 @@ public void resolve(DatagramPacket request, DatagramPacket response) throws IOEx
}
readResponseFromStream(new DataInputStream(in), size, response);
response.setSocketAddress(address);
con.release(reuse);
con.release(reuse && !responseHeader.getConnectionClose());
return;
} catch (EOFException eof) {
con.release(false);
if (i == 1)
throw new IOException ("EOF when reading from "+this.toString(),eof); // retried already once, now throw exception
if (i == 0)
// pooled connection was closed in between - refresh connection and retry!
con.refreshConnection();
else {
con.release(false);
throw new IOException("EOF when reading from " + this.toString(), eof); // retried already once, now throw exception
}
} catch (IOException eio) {
con.release(false);
throw eio;
Expand Down
46 changes: 43 additions & 3 deletions app/src/main/java/dnsfilter/android/AppSelectorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.graphics.Bitmap;
import android.graphics.Canvas;
Expand All @@ -20,7 +22,7 @@
import util.Logger;


public class AppSelectorView extends LinearLayout {
public class AppSelectorView extends LinearLayout implements View.OnClickListener {

private PackageManager pm = this.getContext().getPackageManager();
private boolean loaded = false;
Expand All @@ -30,6 +32,36 @@ public class AppSelectorView extends LinearLayout {
private AsyncLoader runningUpdate = null;

private ComparableAppInfoWrapper[] wrappers = null;
private View searchView;
private View emptyResult;

@Override
public void onClick(View v) {
//search clicked
if (!loaded || runningUpdate != null)
return ;

String searchStr = ((EditText)searchView.findViewById(R.id.searchString)).getText().toString().toLowerCase();

ComparableAppInfoWrapper[] allwrappers = wrappers;
int count = 0;
emptyResult.setVisibility(View.GONE);

for (int i = 0; i < allwrappers.length; i++) {
boolean visible = allwrappers[i].checkBox.getText().toString().toLowerCase().indexOf(searchStr) != -1;
if (visible)
allwrappers[i].checkBox.setVisibility(View.VISIBLE);
else
allwrappers[i].checkBox.setVisibility(View.GONE);

if (visible)
count++;
}
if (count == 0)
emptyResult.setVisibility(View.VISIBLE);
Logger.getLogger().logLine("Found: "+count+" apps!");

}

private class ComparableAppInfoWrapper implements Comparable<ComparableAppInfoWrapper> {

Expand Down Expand Up @@ -86,7 +118,6 @@ public synchronized void run() {
return;

try {

//set 'Loading apps...' info
final TextView infoText = new TextView(getContext());
infoText.setTextColor(Color.BLACK);
Expand All @@ -111,11 +142,13 @@ public void run() {
sortedWrappers.add(new ComparableAppInfoWrapper(packages[i], entry));
}

//remove 'Loading apps...' info
//remove 'Loading apps...' info, add searchView
post(new Runnable() {
@Override
public void run() {
removeView(infoText);
addView(searchView);
addView(emptyResult);
}
});

Expand Down Expand Up @@ -166,6 +199,11 @@ public AppSelectorView(Context context, AttributeSet attrs, int defStyleAttr, in

public void loadAppList() {

searchView = LayoutInflater.from(getContext()).inflate(R.layout.appselectorsearch, null);
searchView.findViewById(R.id.searchBtn).setOnClickListener(this);
emptyResult = LayoutInflater.from(getContext()).inflate(R.layout.emptyresult, null);
emptyResult.setVisibility(View.GONE);

if (loaded || runningUpdate != null)
return;

Expand Down Expand Up @@ -195,6 +233,8 @@ public void clear() {

//clear
wrappers = null;
if (searchView!= null)
searchView.setOnClickListener(null);
this.removeAllViews();
loaded = false;
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/dnsfilter/android/DNSProxyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,12 @@ protected void startup() {

try {
long repeatingLogSuppressTime = Long.parseLong(getConfig().getProperty("repeatingLogSuppressTime", "1000"));
boolean liveLogTimestampEnabled = Boolean.parseBoolean(getConfig().getProperty("addLiveLogTimestamp", "false"));
myLogger.setTimestampFormat(null);
if (liveLogTimestampEnabled) {
String timeStampPattern = getConfig().getProperty("liveLogTimeStampFormat", "hh:mm:ss");
myLogger.setTimestampFormat(timeStampPattern);
}
myLogger.setSuppressTime(repeatingLogSuppressTime);
boolean vpnInAdditionToProxyMode = Boolean.parseBoolean(getConfig().getProperty("vpnInAdditionToProxyMode", "false"));
boolean vpnDisabled = !vpnInAdditionToProxyMode && Boolean.parseBoolean(getConfig().getProperty("dnsProxyOnAndroid", "false"));
Expand Down
31 changes: 27 additions & 4 deletions app/src/main/java/util/SuppressRepeatingsLogger.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
package util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class SuppressRepeatingsLogger implements LoggerInterface {
LoggerInterface nestedLogger;
private String lastLog = "";
private HashMap<String, Long> lastLogs = new HashMap<String, Long>();
private long timeRepeat = 0;
private long lastCleanup = 0;
DateFormat dateFormatter = null; //new SimpleDateFormat("H:mm:ss");
String lastTS="";


public SuppressRepeatingsLogger(LoggerInterface nestedLogger) {
this.nestedLogger = nestedLogger;
}

private void addTimeStamp() {
if (dateFormatter == null)
return;
String ts = dateFormatter.format(new Date());
if ((!ts.equals(lastTS))) {
nestedLogger.logLine(dateFormatter.format(new Date()));
lastTS=ts;
}
}


public void setNestedLogger(LoggerInterface nestedLogger) {
this.nestedLogger = nestedLogger;
}
Expand All @@ -27,6 +42,13 @@ public void setSuppressTime(long suppressTime) {
timeRepeat = suppressTime;
}

public void setTimestampFormat(String timeStampPattern) {
if (timeStampPattern != null)
dateFormatter = new SimpleDateFormat(timeStampPattern);
else
dateFormatter = null;
}

private boolean repeatingLog(String logStr){

long lastLogged = 0;
Expand Down Expand Up @@ -58,21 +80,22 @@ private boolean repeatingLog(String logStr){

@Override
public void logLine(String txt) {
if (!repeatingLog(txt))
if (!repeatingLog(txt)) {
addTimeStamp();
nestedLogger.logLine(txt);
lastLog = txt;
}
}

@Override
public void logException(Exception e) {
addTimeStamp();
nestedLogger.logException(e);
}

@Override
public void log(String txt) {
if (!repeatingLog(txt))
nestedLogger.log(txt);
lastLog = txt;
}

@Override
Expand Down
Loading

0 comments on commit d3de267

Please sign in to comment.