[tor-commits] [orbot/master] support for sharing/display bridge config as QR code

n8fr8 at torproject.org n8fr8 at torproject.org
Fri Apr 3 17:04:06 UTC 2015


commit fb9a6c9994debf59e0f71674c5698ff51d940550
Author: Nathan Freitas <nathan at freitas.net>
Date:   Mon Feb 23 13:00:46 2015 -0500

    support for sharing/display bridge config as QR code
    this is needed for sharing of bridge data between people in the
    same physical space, or by easily sharing it through chat or other
    private messaging system
---
 res/menu/orbot_main.xml                           |    8 ++-
 res/values/strings.xml                            |    7 ++-
 src/org/torproject/android/OrbotMainActivity.java |   59 +++++++++++++++------
 3 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/res/menu/orbot_main.xml b/res/menu/orbot_main.xml
index 4ac393e..55e5b17 100644
--- a/res/menu/orbot_main.xml
+++ b/res/menu/orbot_main.xml
@@ -28,9 +28,15 @@
 
   <item android:id="@+id/menu_scan"
         android:title="@string/menu_scan"
-         yourapp:showAsAction="always"
+         yourapp:showAsAction="never"
+         />
+  
+  <item android:id="@+id/menu_share_bridge"
+        android:title="@string/menu_share_bridge"
+         yourapp:showAsAction="never"
          />
  
+ 
 <!-- 
         <item android:id="@+id/menu_verify"
         android:title="@string/menu_verify_browser"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1028c9e..7ddbfb8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -34,7 +34,8 @@
   <string name="button_clear_log">Clear Log</string>
   <string name="menu_verify">Check</string>
   <string name="menu_exit">Exit</string>
-  <string name="menu_scan">Scan Bridge QR</string>
+  <string name="menu_scan">Scan BridgeQR</string>
+  <string name="menu_share_bridge">Share BridgeQR</string>
   <string name="press_to_start">- long press to start -</string>
   <string name="pref_trans_proxy_group">Transparent Proxying (Requires Root)</string>
   <string name="pref_trans_proxy_title">Transparent Proxying</string>
@@ -311,4 +312,8 @@
   <string name="kb">KB</string>
   
   <string name="mb">MB</string>
+  
+  <string name="bridges_updated">Bridges Updated</string>
+  
+  <string name="restart_orbot_to_use_this_bridge_">"Restart Orbot to use these bridges: "</string>
 </resources>
diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java
index a05c3d2..8c83cf8 100644
--- a/src/org/torproject/android/OrbotMainActivity.java
+++ b/src/org/torproject/android/OrbotMainActivity.java
@@ -7,6 +7,7 @@ import info.guardianproject.browser.Browser;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.text.NumberFormat;
 import java.util.Locale;
 
@@ -413,7 +414,24 @@ public class OrbotMainActivity extends Activity implements TorConstants, OnLongC
                 	IntentIntegrator integrator = new IntentIntegrator(OrbotMainActivity.this);
                 	integrator.initiateScan();
                 }
+                else if (item.getItemId() == R.id.menu_share_bridge)
+                {
+                	
+            		String bridges = mPrefs.getString(TorConstants.PREF_BRIDGES_LIST, null);
+                	
+            		try {
+						bridges = "bridge://" + URLEncoder.encode(bridges,"UTF-8");
+	            		
+	                	IntentIntegrator integrator = new IntentIntegrator(OrbotMainActivity.this);
+	                	integrator.shareText(bridges);
+	                	
+					} catch (UnsupportedEncodingException e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
 
+                }
+                
                 return true;
             
             }
@@ -599,7 +617,7 @@ public class OrbotMainActivity extends Activity implements TorConstants, OnLongC
 					String newBridgeValue = urlString.substring(9); //remove the bridge protocol piece
 					newBridgeValue = URLDecoder.decode(newBridgeValue); //decode the value here
 					
-					addNewBridges(newBridgeValue);
+					setNewBridges(newBridgeValue);
 				}
 			}
 		}
@@ -627,15 +645,17 @@ public class OrbotMainActivity extends Activity implements TorConstants, OnLongC
 		
 	}
 		
-	private void addNewBridges (String newBridgeValue)
+	private void setNewBridges (String newBridgeValue)
 	{
 
-		showAlert("Bridges Updated","Restart Orbot to use this bridge: " + newBridgeValue,false);	
-		
-		String bridges = mPrefs.getString(TorConstants.PREF_BRIDGES_LIST, null);
+		showAlert(getString(R.string.bridges_updated),getString(R.string.restart_orbot_to_use_this_bridge_) + newBridgeValue,false);	
 		
 		Editor pEdit = mPrefs.edit();
 		
+		/*
+		String bridges = "";//let's override, not add // mPrefs.getString(TorConstants.PREF_BRIDGES_LIST, null);
+		
+		
 		if (bridges != null && bridges.trim().length() > 0)
 		{
 			if (bridges.indexOf('\n')!=-1)
@@ -645,13 +665,16 @@ public class OrbotMainActivity extends Activity implements TorConstants, OnLongC
 		}
 		else
 			bridges = newBridgeValue;
+			*/
 		
-		pEdit.putString(TorConstants.PREF_BRIDGES_LIST,bridges); //set the string to a preference
+		pEdit.putString(TorConstants.PREF_BRIDGES_LIST,newBridgeValue); //set the string to a preference
 		pEdit.putBoolean(TorConstants.PREF_BRIDGES_ENABLED,true);
 	
 		pEdit.commit();
 		
 		setResult(RESULT_OK);
+		
+		mBtnBridges.setChecked(true);
 	}
 
 	private boolean showWizard = true;
@@ -779,16 +802,20 @@ public class OrbotMainActivity extends Activity implements TorConstants, OnLongC
              // handle scan result
         	
         	String results = scanResult.getContents();
-        	try {
-				results = URLDecoder.decode(results, "UTF-8");
-				
-				addNewBridges(results);
-				
-				
-			} catch (UnsupportedEncodingException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+        	
+        	if (results != null && results.length() > 0)
+        	{
+	        	try {
+					results = URLDecoder.decode(results, "UTF-8");
+					
+					setNewBridges(results);
+					
+					
+				} catch (UnsupportedEncodingException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+        	}
         	
           }
         





More information about the tor-commits mailing list