[tor-commits] [orbot/master] make expanded notif off by default; handle exceptions better

n8fr8 at torproject.org n8fr8 at torproject.org
Mon Aug 11 15:37:01 UTC 2014


commit 0d424797a2ba3c4f5646a95ffc5af9bfb217886f
Author: Nathan Freitas <nathan at freitas.net>
Date:   Mon Aug 11 10:10:18 2014 -0400

    make expanded notif off by default; handle exceptions better
    - some devices seem to not like these new expanded/remoteviews notifications, so we are turning them off by default. This will also help with load issues on onionoo servers
---
 res/layout/layout_notification_expanded.xml        |   23 +-------
 res/values/strings.xml                             |    6 ++
 res/xml/preferences.xml                            |    7 +++
 src/org/torproject/android/service/TorService.java |   62 ++++++++++----------
 4 files changed, 46 insertions(+), 52 deletions(-)

diff --git a/res/layout/layout_notification_expanded.xml b/res/layout/layout_notification_expanded.xml
index c208583..c2a9c9e 100644
--- a/res/layout/layout_notification_expanded.xml
+++ b/res/layout/layout_notification_expanded.xml
@@ -55,20 +55,7 @@
                 android:textStyle="bold"
  				android:textAppearance="@style/NotificationTitle"
                  />
-            <ViewStub android:id="@+id/time"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_weight="0"
-                android:visibility="gone"
-                android:layout="@layout/notification_template_part_time"
-                />
-            <ViewStub android:id="@+id/chronometer"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_weight="0"
-                android:visibility="gone"
-                android:layout="@layout/notification_template_part_chronometer"
-                />
+            
         </LinearLayout>
         <LinearLayout
             android:id="@+id/line3"
@@ -131,13 +118,5 @@
             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>
 </FrameLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 91264a8..155dbdd 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -227,9 +227,15 @@
   <string name="unable_to_start_tor">Unable to start Tor:</string>
   <string name="pref_use_sys_iptables_title">Use Default Iptables</string>
   <string name="pref_use_sys_iptables_summary">use the built-in iptables binary instead of the one bundled with Orbot</string>
+  
   <string name="error_installing_binares">The Tor binaries were not able to be installed or upgraded.</string>
+  
   <string name="pref_use_persistent_notifications">Always keep the icon in toolbar when Orbot is connected</string>
   <string name="pref_use_persistent_notifications_title">Always-On Notifications</string>
+  
+  <string name="pref_use_expanded_notifications">Show expanded notification with Tor exit country and IP</string>
+  <string name="pref_use_expanded_notifications_title">Expanded Notifications</string>
+  
   <string name="notification_using_bridges">Bridges enabled!</string>
   <string name="default_bridges"/>
   <string name="set_locale_title">Set Locale</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 22502b6..2b10ac4 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -23,6 +23,13 @@ android:summary="@string/pref_use_persistent_notifications"
 android:enabled="true" 
 android:title="@string/pref_use_persistent_notifications_title"/>
 
+<CheckBoxPreference
+android:defaultValue="false" 
+android:key="pref_expanded_notifications"
+android:summary="@string/pref_use_expanded_notifications"
+android:enabled="true" 
+android:title="@string/pref_use_expanded_notifications_title"/>
+
 
  <ListPreference android:title="@string/set_locale_title"
    android:key="pref_default_locale"
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index acdb134..c3b6b39 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -128,6 +128,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 	private NotificationManager mNotificationManager = null;
 	private Builder mNotifyBuilder;
 	private Notification mNotification;
+	private boolean mShowExpandedNotifications = false;
 
     private boolean mHasRoot = false;
     private boolean mEnableTransparentProxy = false;
@@ -270,7 +271,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		
 		mNotification = mNotifyBuilder.build();
 		
-	    if (Build.VERSION.SDK_INT >= 16) {
+	    if (Build.VERSION.SDK_INT >= 16 && mShowExpandedNotifications) {
 	    	
 	    	
 	    	// Create remote view that needs to be set as bigContentView for the notification.
@@ -317,8 +318,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		 	
 	 		expandedView.setTextViewText(R.id.title, getString(R.string.app_name)); 
 	 		
-	 	//	expandedView.setTextViewText(R.id.info, infoMessage.toString());
-	 	//	expandedView.setOnClickPendingIntent(R.id._tor_notificationBT, pendIntent);
 	 		expandedView.setImageViewResource(R.id.icon, icon);
 	    	mNotification.bigContentView = expandedView;
 	    }
@@ -723,6 +722,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
  		mEnableTransparentProxy = prefs.getBoolean("pref_transparent", false);
  		mTransProxyAll = prefs.getBoolean("pref_transparent_all", false);
 	 	mTransProxyTethering = prefs.getBoolean("pref_transparent_tethering", false);
+	 	mShowExpandedNotifications  = prefs.getBoolean("pref_expanded_notifications", false);
 	 	
     	ENABLE_DEBUG_LOG = prefs.getBoolean("pref_enable_logging",false);
     	Log.i(TAG,"debug logging:" + ENABLE_DEBUG_LOG);
@@ -766,7 +766,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
      * 
      * the idea is that if Tor is off then transproxy is off
      */
-    protected boolean enableTransparentProxy (boolean proxyAll, boolean enableTether) throws Exception
+    private boolean enableTransparentProxy (boolean proxyAll, boolean enableTether) throws Exception
  	{
     	
  		if (mTransProxy == null)
@@ -1124,7 +1124,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		{	
 			logNotice("unable to get control port; file not found");
 		}
-		catch (IOException e)
+		catch (Exception e)
 		{	
 			logNotice("unable to read control port config file");
 		}
@@ -1170,7 +1170,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 	}*/
 	
 	
-	public void addEventHandler () throws IOException
+	public void addEventHandler () throws Exception
 	{
 	       // We extend NullEventHandler so that we don't need to provide empty
 	       // implementations for all the events we don't care about.
@@ -1386,31 +1386,33 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 			
 			logNotice(sb.toString());
 		
-			//get IP from last nodename
-			if(status.equals("BUILT")){
-				
-				if (node.ipAddress == null)
-					mExecutor.execute(new ExternalIPFetcher(node));
-				
-				hmBuiltNodes.put(node.id, node);
-			}
-			
-			if (status.equals("CLOSED"))
+			if (mShowExpandedNotifications)
 			{
-				hmBuiltNodes.remove(node.id);
-				
-				//how check the IP's of any other nodes we have
-				for (String nodeId : hmBuiltNodes.keySet())
-				{
-					node = hmBuiltNodes.get(nodeId);
+				//get IP from last nodename
+				if(status.equals("BUILT")){
 					
 					if (node.ipAddress == null)
 						mExecutor.execute(new ExternalIPFetcher(node));
-
+					
+					hmBuiltNodes.put(node.id, node);
 				}
-
-			}
 				
+				if (status.equals("CLOSED"))
+				{
+					hmBuiltNodes.remove(node.id);
+					
+					//how check the IP's of any other nodes we have
+					for (String nodeId : hmBuiltNodes.keySet())
+					{
+						node = hmBuiltNodes.get(nodeId);
+						
+						if (node.ipAddress == null)
+							mExecutor.execute(new ExternalIPFetcher(node));
+	
+					}
+	
+				}
+			}
 	
 	}
 	
@@ -1585,9 +1587,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 					
     			}
     		}
-    		catch(IOException ioe)
+    		catch(Exception ioe)
     		{
-    			Log.e(TAG,"Unable to get Tor information",ioe);
+    		//	Log.e(TAG,"Unable to get Tor information",ioe);
     			logNotice("Unable to get Tor information"+ioe.getMessage());
     		}
 			return null;
@@ -1621,7 +1623,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 	   	       		return result.toString();
 	        	}
         	}
-        	catch (IOException ioe)
+        	catch (Exception ioe)
         	{
         		
         		logException("Unable to get Tor configuration: " + ioe.getMessage(),ioe);
@@ -1678,7 +1680,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 	        			//checkAddressAndCountry();
 	        			
 	        			}
-	        			catch (IOException ioe){
+	        			catch (Exception ioe){
 	        				debug("error requesting newnym: " + ioe.getLocalizedMessage());
 	        			}
 	        		}
@@ -1855,7 +1857,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
     	}
     };
 
-    private boolean processSettingsImpl () throws RemoteException, IOException
+    private boolean processSettingsImpl () throws Exception
     {
     	logNotice(getString(R.string.updating_settings_in_tor_service));
     	





More information about the tor-commits mailing list