fixes for layout and notification data

be sure to only get the IP of the last hop (that is the exit)
This commit is contained in:
Nathan Freitas 2014-07-10 12:34:31 -04:00
parent a6da4bf530
commit f2f076c29c
2 changed files with 79 additions and 101 deletions

View File

@ -18,9 +18,7 @@
xmlns:internal="http://schemas.android.com/apk/prv/res/android" xmlns:internal="http://schemas.android.com/apk/prv/res/android"
android:id="@+id/status_bar_latest_event_content" android:id="@+id/status_bar_latest_event_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="128dp" android:layout_height="wrap_content"
internal:layout_minHeight="128dp"
internal:layout_maxHeight="128dp"
> >
<ImageView android:id="@+id/icon" <ImageView android:id="@+id/icon"
android:layout_width="@dimen/notification_large_icon_width" android:layout_width="@dimen/notification_large_icon_width"
@ -54,7 +52,9 @@
android:ellipsize="marquee" android:ellipsize="marquee"
android:fadingEdge="horizontal" android:fadingEdge="horizontal"
android:layout_weight="1" android:layout_weight="1"
/> android:textStyle="bold"
android:textAppearance="@style/NotificationTitle"
/>
<ViewStub android:id="@+id/time" <ViewStub android:id="@+id/time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -70,31 +70,11 @@
android:layout="@layout/notification_template_part_chronometer" android:layout="@layout/notification_template_part_chronometer"
/> />
</LinearLayout> </LinearLayout>
<TextView android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-2dp"
android:layout_marginBottom="-2dp"
android:layout_marginStart="8dp"
android:singleLine="true"
android:fadingEdge="horizontal"
android:ellipsize="marquee"
android:visibility="gone"
/>
<ProgressBar
android:id="@android:id/progress"
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_marginStart="8dp"
android:visibility="gone"
style="?android:attr/progressBarStyleHorizontal"
/>
<LinearLayout <LinearLayout
android:id="@+id/line3" android:id="@+id/line3"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
> >
<TextView android:id="@+id/text" <TextView android:id="@+id/text"
@ -105,6 +85,7 @@
android:singleLine="true" android:singleLine="true"
android:ellipsize="marquee" android:ellipsize="marquee"
android:fadingEdge="horizontal" android:fadingEdge="horizontal"
android:textAppearance="@style/NotificationText"
/> />
<TextView android:id="@+id/info" <TextView android:id="@+id/info"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -114,6 +95,7 @@
android:singleLine="true" android:singleLine="true"
android:gravity="center" android:gravity="center"
android:paddingStart="8dp" android:paddingStart="8dp"
android:textAppearance="@style/NotificationText"
/> />
<ImageView android:id="@+id/right_icon" <ImageView android:id="@+id/right_icon"
android:layout_width="16dp" android:layout_width="16dp"
@ -124,13 +106,30 @@
android:scaleType="centerInside" android:scaleType="centerInside"
android:visibility="gone" android:visibility="gone"
/> />
<Button <!--
<ImageButton
android:id="@+id/_tor_notificationBT" android:id="@+id/_tor_notificationBT"
android:layout_width="wrap_content" android:layout_width="24dp"
android:layout_height="wrap_content" android:layout_height="24dp"
android:layout_alignParentRight="true" android:src="@drawable/nav_refresh" />
android:layout_below="@+id/tv" -->
android:text="test2" />
</LinearLayout> </LinearLayout>
<TextView android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-2dp"
android:layout_marginBottom="-2dp"
android:layout_marginStart="8dp"
android:fadingEdge="horizontal"
/>
<ProgressBar
android:id="@android:id/progress"
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_marginStart="8dp"
android:visibility="gone"
style="?android:attr/progressBarStyleHorizontal"
/>
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>

View File

@ -23,15 +23,14 @@ import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Timer; import java.util.concurrent.TimeoutException;
import java.util.TimerTask;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.concurrent.TimeoutException;
import net.freehaven.tor.control.ConfigEntry; import net.freehaven.tor.control.ConfigEntry;
import net.freehaven.tor.control.EventHandler; import net.freehaven.tor.control.EventHandler;
import net.freehaven.tor.control.TorControlConnection; import net.freehaven.tor.control.TorControlConnection;
import net.freehaven.tor.control.TorControlError;
import org.sufficientlysecure.rootcommands.Shell; import org.sufficientlysecure.rootcommands.Shell;
import org.sufficientlysecure.rootcommands.command.SimpleCommand; import org.sufficientlysecure.rootcommands.command.SimpleCommand;
@ -58,16 +57,13 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Environment; import android.os.Environment;
import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteCallbackList; import android.os.RemoteCallbackList;
import android.os.RemoteException; import android.os.RemoteException;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log; import android.util.Log;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.Toast;
public class TorService extends Service implements TorServiceConstants, TorConstants, EventHandler public class TorService extends Service implements TorServiceConstants, TorConstants, EventHandler
{ {
@ -219,7 +215,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
private void showToolbarNotification (String notifyMsg, int notifyId, int icon, boolean isOngoing) private void showToolbarNotification (String notifyMsg, int notifyType, int icon)
{ {
//Reusable code. //Reusable code.
@ -230,10 +226,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst
RemoteViews expandedView = new RemoteViews(this.getPackageName(), RemoteViews expandedView = new RemoteViews(this.getPackageName(),
R.layout.layout_notification_expanded); R.layout.layout_notification_expanded);
expandedView.setTextViewText(R.id.text, notifyMsg); if (notifyType == NOTIFY_ID)
expandedView.setTextViewText(R.id.title, getString(R.string.app_name)+ ' ' + exitIP); expandedView.setTextViewText(R.id.text, notifyMsg);
//expandedView.setTextViewText(R.id.exitIP, exitIP); else
//expandedView.setOnClickPendingIntent(R.id._tor_notificationBT, pendIntent); expandedView.setTextViewText(R.id.text2, notifyMsg);
expandedView.setTextViewText(R.id.title, getString(R.string.app_name));
expandedView.setTextViewText(R.id.info, "Tor IP: " + exitIP);
// expandedView.setOnClickPendingIntent(R.id._tor_notificationBT, pendIntent);
expandedView.setImageViewResource(R.id.icon, icon); expandedView.setImageViewResource(R.id.icon, icon);
if (mNotifyBuilder == null) if (mNotifyBuilder == null)
@ -245,7 +245,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
mNotifyBuilder = new NotificationCompat.Builder(this) mNotifyBuilder = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.app_name)) .setContentTitle(getString(R.string.app_name))
.setContentText( getString(R.string.status_activated))
.setSmallIcon(R.drawable.ic_stat_tor); .setSmallIcon(R.drawable.ic_stat_tor);
mNotifyBuilder.setContentIntent(pendIntent); mNotifyBuilder.setContentIntent(pendIntent);
@ -256,31 +255,24 @@ public class TorService extends Service implements TorServiceConstants, TorConst
mNotifyBuilder.setContentText(notifyMsg); mNotifyBuilder.setContentText(notifyMsg);
mNotifyBuilder.setSmallIcon(icon); mNotifyBuilder.setSmallIcon(icon);
if (notifyType != NOTIFY_ID)
if (notifyId == ERROR_NOTIFY_ID)
{ {
mNotifyBuilder.setTicker(notifyMsg); mNotifyBuilder.setTicker(notifyMsg);
mNotifyBuilder.setLights(Color.RED, 1000, 1000); mNotifyBuilder.setLights(Color.RED, 1000, 1000);
mNotifyBuilder.setSmallIcon(R.drawable.ic_stat_notifyerr); mNotifyBuilder.setSmallIcon(R.drawable.ic_stat_notifyerr);
} }
else
{ mNotifyBuilder.setOngoing(prefPersistNotifications);
mNotifyBuilder.setTicker(null); //make sure to clear ticker
}
mNotification = mNotifyBuilder.build(); mNotification = mNotifyBuilder.build();
mNotification.bigContentView = expandedView; mNotification.bigContentView = expandedView;
if (isOngoing) if (mNotification == null && prefPersistNotifications)
{ {
startForeground(notifyId, mNotification); startForeground(NOTIFY_ID, mNotification);
}
else
{
mNotificationManager.notify(notifyId, mNotification);
} }
mNotificationManager.notify(NOTIFY_ID, mNotification);
} }
@ -435,13 +427,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
logException("unable to read onion hostname file",e); logException("unable to read onion hostname file",e);
showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false); showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr);
return null; return null;
} }
} }
else else
{ {
showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false); showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr);
return null; return null;
} }
@ -451,7 +443,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
String onionHostname = result.toString(); String onionHostname = result.toString();
showToolbarNotification(getString(R.string.hidden_service_on) + ' ' + onionHostname, HS_NOTIFY_ID, R.drawable.ic_stat_tor, false); showToolbarNotification(getString(R.string.hidden_service_on) + ' ' + onionHostname, HS_NOTIFY_ID, R.drawable.ic_stat_tor);
Editor pEdit = prefs.edit(); Editor pEdit = prefs.edit();
pEdit.putString("pref_hs_hostname",onionHostname); pEdit.putString("pref_hs_hostname",onionHostname);
pEdit.commit(); pEdit.commit();
@ -719,13 +711,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if(proxyAll) if(proxyAll)
{ {
showToolbarNotification(getString(R.string.setting_up_full_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, false); showToolbarNotification(getString(R.string.setting_up_full_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
code = mTransProxy.setTransparentProxyingAll(this); code = mTransProxy.setTransparentProxyingAll(this);
} }
else else
{ {
showToolbarNotification(getString(R.string.setting_up_app_based_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, false); showToolbarNotification(getString(R.string.setting_up_app_based_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
code = mTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this, TorServiceUtils.getSharedPrefs(getApplicationContext()))); code = mTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this, TorServiceUtils.getSharedPrefs(getApplicationContext())));
} }
@ -735,11 +727,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (code == 0) if (code == 0)
{ {
showToolbarNotification(getString(R.string.transparent_proxying_enabled), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, false); showToolbarNotification(getString(R.string.transparent_proxying_enabled), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
if (enableTether) if (enableTether)
{ {
showToolbarNotification(getString(R.string.transproxy_enabled_for_tethering_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, false); showToolbarNotification(getString(R.string.transproxy_enabled_for_tethering_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
mTransProxy.enableTetheringRules(this); mTransProxy.enableTetheringRules(this);
@ -747,7 +739,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
else else
{ {
showToolbarNotification(getString(R.string.warning_error_starting_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, false); showToolbarNotification(getString(R.string.warning_error_starting_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
} }
@ -1168,7 +1160,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
stopTor(); stopTor();
logException("Unable to start Tor: " + e.toString(),e); logException("Unable to start Tor: " + e.toString(),e);
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
showToolbarNotification(getString(R.string.unable_to_start_tor) + ": " + e.getMessage(), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false); showToolbarNotification(getString(R.string.unable_to_start_tor) + ": " + e.getMessage(), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr);
} }
} }
else else
@ -1191,7 +1183,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
currentStatus = STATUS_ON; currentStatus = STATUS_ON;
showToolbarNotification(getString(R.string.status_activated), NOTIFY_ID, R.drawable.ic_stat_tor, prefPersistNotifications); showToolbarNotification(getString(R.string.status_activated), NOTIFY_ID, R.drawable.ic_stat_tor);
} }
@ -1261,7 +1253,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
iconId = R.drawable.ic_stat_tor_xfer; iconId = R.drawable.ic_stat_tor_xfer;
if (mConnectivity && prefPersistNotifications) if (mConnectivity && prefPersistNotifications)
showToolbarNotification(sb.toString(), NOTIFY_ID, iconId, prefPersistNotifications); showToolbarNotification(sb.toString(), NOTIFY_ID, iconId);
mTotalTrafficWritten += written; mTotalTrafficWritten += written;
mTotalTrafficRead += read; mTotalTrafficRead += read;
@ -1321,8 +1313,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void circuitStatus(String status, String circID, String path) { public void circuitStatus(String status, String circID, String path) {
if (status.equals("BUILT") || status.equals("CLOSED"))
{
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Circuit ("); sb.append("Circuit (");
sb.append((circID)); sb.append((circID));
@ -1332,41 +1323,25 @@ public class TorService extends Service implements TorServiceConstants, TorConst
StringTokenizer st = new StringTokenizer(path,","); StringTokenizer st = new StringTokenizer(path,",");
String node = null; String node = null;
String nodeName = null;
while (st.hasMoreTokens()) while (st.hasMoreTokens())
{ {
node = st.nextToken(); node = st.nextToken();
final String nodeName = parseNodeName(node); nodeName = parseNodeName(node);
sb.append(nodeName); sb.append(nodeName);
if(status.equals("BUILT") && currentStatus==STATUS_ON){
new getExternalIP().execute(nodeName);
}
if (st.hasMoreTokens()) if (st.hasMoreTokens())
sb.append (" > "); sb.append (" > ");
} }
logNotice(sb.toString()); logNotice(sb.toString());
}
/** //get IP from last nodename
if (currentStatus != STATUS_ON) if(status.equals("BUILT") && currentStatus==STATUS_ON){
{ new getExternalIP().execute(nodeName);
try {
String state;
state = conn.getInfo("dormant");
if (state != null && Integer.parseInt(state) == 0)
currentStatus = STATUS_ON;
else
currentStatus = STATUS_CONNECTING;
} catch (IOException e) {
logException("Error getting state from Tor control port",e);
} }
}*/
} }
@ -1386,7 +1361,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
return nodeDetails; return nodeDetails;
} catch (TorControlError e) {
Log.d(TorService.TAG,"Error getting node details for: " + params[0]);
} catch (Exception e) { } catch (Exception e) {
Log.e(TorService.TAG,"Error getting node details",e); Log.e(TorService.TAG,"Error getting node details",e);
} }
@ -1402,6 +1378,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
Pattern pattern = Pattern.compile(IPADDRESS_PATTERN); Pattern pattern = Pattern.compile(IPADDRESS_PATTERN);
Matcher matcher = null; Matcher matcher = null;
if(result!=null){ if(result!=null){
sendCallbackLogMessage("Node Info: " + result);
matcher = pattern.matcher(result); matcher = pattern.matcher(result);
if (matcher.find()) { if (matcher.find()) {
exitIP = matcher.group(); exitIP = matcher.group();
@ -1837,13 +1816,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (!mConnectivity) if (!mConnectivity)
{ {
logNotice(context.getString(R.string.no_network_connectivity_putting_tor_to_sleep_)); logNotice(context.getString(R.string.no_network_connectivity_putting_tor_to_sleep_));
showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off,prefPersistNotifications); showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off);
} }
else else
{ {
logNotice(context.getString(R.string.network_connectivity_is_good_waking_tor_up_)); logNotice(context.getString(R.string.network_connectivity_is_good_waking_tor_up_));
showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor,prefPersistNotifications); showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor);
if (mHasRoot && mEnableTransparentProxy) if (mHasRoot && mEnableTransparentProxy)
enableTransparentProxy(mTransProxyAll, mTransProxyTethering); enableTransparentProxy(mTransProxyAll, mTransProxyTethering);
@ -1940,7 +1919,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
catch (Exception e) catch (Exception e)
{ {
showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, false); showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr);
return false; return false;
} }
@ -1963,7 +1942,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
String msgBridge = getString(R.string.bridge_requires_ip) + String msgBridge = getString(R.string.bridge_requires_ip) +
getString(R.string.send_email_for_bridges); getString(R.string.send_email_for_bridges);
showToolbarNotification(msgBridge, ERROR_NOTIFY_ID, R.drawable.ic_stat_tor, false); showToolbarNotification(msgBridge, ERROR_NOTIFY_ID, R.drawable.ic_stat_tor);
logMessage(msgBridge); logMessage(msgBridge);
return false; return false;
@ -1977,7 +1956,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
bridgeDelim = ","; bridgeDelim = ",";
} }
showToolbarNotification(getString(R.string.notification_using_bridges) + ": " + bridgeList, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, false); showToolbarNotification(getString(R.string.notification_using_bridges) + ": " + bridgeList, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
StringTokenizer st = new StringTokenizer(bridgeList,bridgeDelim); StringTokenizer st = new StringTokenizer(bridgeList,bridgeDelim);
while (st.hasMoreTokens()) while (st.hasMoreTokens())
@ -2036,7 +2015,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
catch (Exception e) catch (Exception e)
{ {
showToolbarNotification (getString(R.string.your_reachableaddresses_settings_caused_an_exception_),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, false); showToolbarNotification (getString(R.string.your_reachableaddresses_settings_caused_an_exception_),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr);
return false; return false;
} }
@ -2065,7 +2044,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
catch (Exception e) catch (Exception e)
{ {
showToolbarNotification (getString(R.string.your_relay_settings_caused_an_exception_),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr, false); showToolbarNotification (getString(R.string.your_relay_settings_caused_an_exception_),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr);
return false; return false;