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
This commit is contained in:
Nathan Freitas 2015-02-23 13:00:46 -05:00
parent 759966aa13
commit fb9a6c9994
3 changed files with 56 additions and 18 deletions

View File

@ -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"

View File

@ -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>

View File

@ -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,6 +414,23 @@ 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);
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();
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}