Fixed probable memory leak in ServerTestActivity
This commit is contained in:
parent
e41c17fb84
commit
e01ad796cd
@ -40,6 +40,13 @@ public class Daedalus extends Application {
|
|||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTerminate() {
|
||||||
|
super.onTerminate();
|
||||||
|
|
||||||
|
instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Daedalus getInstance() {
|
public static Daedalus getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ public class ServerTestActivity extends AppCompatActivity {
|
|||||||
private static final int MSG_DISPLAY_STATUS = 0;
|
private static final int MSG_DISPLAY_STATUS = 0;
|
||||||
private static final int MSG_TEST_DONE = 1;
|
private static final int MSG_TEST_DONE = 1;
|
||||||
|
|
||||||
private boolean testing = false;
|
private static boolean testing = false;
|
||||||
private Thread mThread = null;
|
private static Thread mThread = null;
|
||||||
private Handler mHandler = null;
|
private ServerTestHandler mHandler = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -77,15 +77,15 @@ public class ServerTestActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String testUrl = textViewTestUrl.getText().toString();
|
String testDomain = textViewTestUrl.getText().toString();
|
||||||
if (testUrl.equals("")) {
|
if (testDomain.equals("")) {
|
||||||
testUrl = Daedalus.DEFAULT_TEST_DOMAINS[0];
|
testDomain = Daedalus.DEFAULT_TEST_DOMAINS[0];
|
||||||
}
|
}
|
||||||
String testText = "";
|
StringBuilder testText = new StringBuilder();
|
||||||
String[] dnsServers = {DnsServer.getDnsServerAddressByStringDesription(context, spinnerServerChoice.getSelectedItem().toString()), "114.114.114.114", "8.8.8.8"};
|
String[] dnsServers = {DnsServer.getDnsServerAddressByStringDescription(context, spinnerServerChoice.getSelectedItem().toString()), "114.114.114.114", "8.8.8.8"};
|
||||||
DNSClient client = new DNSClient(null);
|
DNSClient client = new DNSClient(null);
|
||||||
for (String dnsServer : dnsServers) {
|
for (String dnsServer : dnsServers) {
|
||||||
testText = testServer(client, dnsServer, testUrl, testText);
|
testText = testServer(client, dnsServer, testDomain, testText);
|
||||||
}
|
}
|
||||||
mHandler.obtainMessage(MSG_TEST_DONE).sendToTarget();
|
mHandler.obtainMessage(MSG_TEST_DONE).sendToTarget();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -93,12 +93,12 @@ public class ServerTestActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String testServer(DNSClient client, String dnsServer, String testUrl, String testText) {
|
private StringBuilder testServer(DNSClient client, String dnsServer, String testUrl, StringBuilder testText) {
|
||||||
Log.d("Dvpn", "Testing DNS " + dnsServer);
|
Log.d("Dvpn", "Testing DNS " + dnsServer);
|
||||||
testText += getResources().getString(R.string.test_domain) + " " + testUrl + "\n"
|
testText.append(getResources().getString(R.string.test_domain)).append(" ").append(testUrl).append("\n"
|
||||||
+ getResources().getString(R.string.test_dns_server) + " " + dnsServer;
|
).append(getResources().getString(R.string.test_dns_server)).append(" ").append(dnsServer);
|
||||||
|
|
||||||
mHandler.obtainMessage(MSG_DISPLAY_STATUS, testText).sendToTarget();
|
mHandler.obtainMessage(MSG_DISPLAY_STATUS, testText.toString()).sendToTarget();
|
||||||
|
|
||||||
Question question = new Question(testUrl, Record.TYPE.getType(A.class));
|
Question question = new Question(testUrl, Record.TYPE.getType(A.class));
|
||||||
DNSMessage.Builder message = DNSMessage.builder();
|
DNSMessage.Builder message = DNSMessage.builder();
|
||||||
@ -115,17 +115,17 @@ public class ServerTestActivity extends AppCompatActivity {
|
|||||||
Set<A> answers = responseMessage.getAnswersFor(question);
|
Set<A> answers = responseMessage.getAnswersFor(question);
|
||||||
for (A a : answers) {
|
for (A a : answers) {
|
||||||
InetAddress inetAddress = a.getInetAddress();
|
InetAddress inetAddress = a.getInetAddress();
|
||||||
testText += "\n" + getResources().getString(R.string.test_result_resolved) + " " + inetAddress.getHostAddress();
|
testText.append("\n").append(getResources().getString(R.string.test_result_resolved)).append(" ").append(inetAddress.getHostAddress());
|
||||||
}
|
}
|
||||||
testText += "\n" + getResources().getString(R.string.test_time_used) + " " + String.valueOf(endTime - startTime) + " ms\n\n";
|
testText.append("\n").append(getResources().getString(R.string.test_time_used)).append(" ").append(String.valueOf(endTime - startTime)).append(" ms\n\n");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
testText += "\n" + getResources().getString(R.string.test_failed) + "\n\n";
|
testText.append("\n").append(getResources().getString(R.string.test_failed)).append("\n\n");
|
||||||
|
|
||||||
Log.e("DVpn", e.toString());
|
Log.e("DVpn", e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
mHandler.obtainMessage(MSG_DISPLAY_STATUS, testText).sendToTarget();
|
mHandler.obtainMessage(MSG_DISPLAY_STATUS, testText.toString()).sendToTarget();
|
||||||
return testText;
|
return testText;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -136,22 +136,33 @@ public class ServerTestActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
mHandler = new Handler() {
|
mHandler = new ServerTestHandler();
|
||||||
public void handleMessage(Message msg) {
|
mHandler.setViews(startTestBut, textViewTestInfo);
|
||||||
super.handleMessage(msg);
|
}
|
||||||
|
|
||||||
switch (msg.what) {
|
public static class ServerTestHandler extends Handler {
|
||||||
case MSG_DISPLAY_STATUS:
|
private Button startTestBtn = null;
|
||||||
textViewTestInfo.setText((String) msg.obj);
|
private TextView textViewTestInfo = null;
|
||||||
break;
|
|
||||||
case MSG_TEST_DONE:
|
void setViews(Button startTestButton, TextView textViewTestInfo) {
|
||||||
testing = false;
|
this.startTestBtn = startTestButton;
|
||||||
startTestBut.setVisibility(View.VISIBLE);
|
this.textViewTestInfo = textViewTestInfo;
|
||||||
mThread = null;
|
}
|
||||||
break;
|
|
||||||
}
|
public void handleMessage(Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
|
||||||
|
switch (msg.what) {
|
||||||
|
case MSG_DISPLAY_STATUS:
|
||||||
|
textViewTestInfo.setText((String) msg.obj);
|
||||||
|
break;
|
||||||
|
case MSG_TEST_DONE:
|
||||||
|
testing = false;
|
||||||
|
startTestBtn.setVisibility(View.VISIBLE);
|
||||||
|
mThread = null;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,7 +51,7 @@ public class DnsServer {
|
|||||||
return Daedalus.DNS_SERVERS.get(0).getAddress();
|
return Daedalus.DNS_SERVERS.get(0).getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDnsServerAddressByStringDesription(Context context, String description) {
|
public static String getDnsServerAddressByStringDescription(Context context, String description) {
|
||||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||||
if (server.getStringDescription(context).equals(description)) {
|
if (server.getStringDescription(context).equals(description)) {
|
||||||
return server.getAddress();
|
return server.getAddress();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user