small cleanup of asynctask and error handling

This commit is contained in:
Nathan Freitas 2014-07-10 11:23:49 -04:00
parent 181b92276a
commit a6da4bf530
1 changed files with 11 additions and 11 deletions

View File

@ -231,7 +231,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
R.layout.layout_notification_expanded); R.layout.layout_notification_expanded);
expandedView.setTextViewText(R.id.text, notifyMsg); expandedView.setTextViewText(R.id.text, notifyMsg);
expandedView.setTextViewText(R.id.title, "ORBOT "+exitIP); expandedView.setTextViewText(R.id.title, getString(R.string.app_name)+ ' ' + exitIP);
//expandedView.setTextViewText(R.id.exitIP, exitIP); //expandedView.setTextViewText(R.id.exitIP, exitIP);
//expandedView.setOnClickPendingIntent(R.id._tor_notificationBT, pendIntent); //expandedView.setOnClickPendingIntent(R.id._tor_notificationBT, pendIntent);
expandedView.setImageViewResource(R.id.icon, icon); expandedView.setImageViewResource(R.id.icon, icon);
@ -1370,42 +1370,42 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
private class getExternalIP extends AsyncTask<String, Void, Void>{ private class getExternalIP extends AsyncTask<String, Void, String>{
private long time; private long time;
private String nodeDetails;
@Override @Override
protected Void doInBackground(String... params) { protected String doInBackground(String... params) {
time = System.nanoTime(); time = System.nanoTime();
try { try {
nodeDetails = conn.getInfo("ns/name/"+params[0]); String nodeDetails = conn.getInfo("ns/name/"+params[0]);
if (ENABLE_DEBUG_LOG) if (ENABLE_DEBUG_LOG)
{ {
Log.d(TAG,"Node Details: "+nodeDetails); Log.d(TAG,"Node Details: "+nodeDetails);
sendCallbackLogMessage("Node Details: "+nodeDetails); sendCallbackLogMessage("Node Details: "+nodeDetails);
} }
return nodeDetails;
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block Log.e(TorService.TAG,"Error getting node details",e);
e.printStackTrace();
} }
return null; return null;
} }
@Override @Override
protected void onPostExecute(Void result) { protected void onPostExecute(String result) {
// check if we need to update the exit IP // check if we need to update the exit IP
if(time > exitIPTime) { if(time > exitIPTime) {
exitIPTime = time; exitIPTime = time;
Pattern pattern = Pattern.compile(IPADDRESS_PATTERN); Pattern pattern = Pattern.compile(IPADDRESS_PATTERN);
Matcher matcher = null; Matcher matcher = null;
if(nodeDetails!=null){ if(result!=null){
matcher = pattern.matcher(nodeDetails); matcher = pattern.matcher(result);
if (matcher.find()) { if (matcher.find()) {
Log.d(TAG, "ip: "+matcher.group());
exitIP = matcher.group(); exitIP = matcher.group();
sendCallbackLogMessage("Exit IP: "+exitIP);
} }
} }
} }