adds optional string to the intent
This commit is contained in:
parent
3f7435c90e
commit
0131cf20f0
|
@ -27,6 +27,7 @@ import org.torproject.android.ui.hs.HiddenServicesActivity;
|
||||||
import org.torproject.android.ui.ImageProgressView;
|
import org.torproject.android.ui.ImageProgressView;
|
||||||
import org.torproject.android.ui.PromoAppsActivity;
|
import org.torproject.android.ui.PromoAppsActivity;
|
||||||
import org.torproject.android.ui.Rotate3dAnimation;
|
import org.torproject.android.ui.Rotate3dAnimation;
|
||||||
|
import org.torproject.android.ui.hs.providers.HSContentProvider;
|
||||||
import org.torproject.android.vpn.VPNEnableActivity;
|
import org.torproject.android.vpn.VPNEnableActivity;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
@ -35,6 +36,8 @@ import android.app.ActivityManager.RunningServiceInfo;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -44,6 +47,7 @@ import android.content.SharedPreferences.Editor;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -561,65 +565,40 @@ public class OrbotMainActivity extends AppCompatActivity
|
||||||
stopVpnService();
|
stopVpnService();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableHiddenServicePort (int hsPort) throws RemoteException, InterruptedException
|
private void enableHiddenServicePort (String hsName, int hsPort) throws RemoteException, InterruptedException
|
||||||
{
|
{
|
||||||
|
String onionHostname="";
|
||||||
|
String[] mProjection = new String[]{
|
||||||
|
HSContentProvider.HiddenService._ID,
|
||||||
|
HSContentProvider.HiddenService.NAME,
|
||||||
|
HSContentProvider.HiddenService.DOMAIN,
|
||||||
|
HSContentProvider.HiddenService.PORT};
|
||||||
|
|
||||||
Editor pEdit = mPrefs.edit();
|
if(hsName == null)
|
||||||
|
hsName = "hs"+hsPort;
|
||||||
|
|
||||||
String hsPortString = mPrefs.getString("pref_hs_ports", "");
|
ContentValues fields = new ContentValues();
|
||||||
String onionHostname = mPrefs.getString("pref_hs_hostname","");
|
fields.put("name", hsName);
|
||||||
|
fields.put("port", hsPort);
|
||||||
|
ContentResolver cr = getContentResolver();
|
||||||
|
Cursor row = cr.query(HSContentProvider.CONTENT_URI, mProjection, "port="+hsPort, null, null);
|
||||||
|
|
||||||
if (hsPortString.indexOf(hsPort+"")==-1)
|
if(row == null) {
|
||||||
{
|
cr.insert(HSContentProvider.CONTENT_URI, fields);
|
||||||
if (hsPortString.length() > 0 && hsPortString.indexOf(hsPort+"")==-1)
|
} else {
|
||||||
hsPortString += ',' + hsPort;
|
onionHostname = row.getString(row.getColumnIndex(HSContentProvider.HiddenService.NAME));
|
||||||
else
|
cr.update(HSContentProvider.CONTENT_URI, fields, "port=" + hsPort, null);
|
||||||
hsPortString = hsPort + "";
|
row.close();
|
||||||
|
|
||||||
pEdit.putString("pref_hs_ports", hsPortString);
|
|
||||||
pEdit.putBoolean("pref_hs_enable", true);
|
|
||||||
|
|
||||||
pEdit.commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onionHostname == null || onionHostname.length() == 0)
|
requestTorRereadConfig();
|
||||||
{
|
|
||||||
requestTorRereadConfig();
|
|
||||||
|
|
||||||
new Thread () {
|
// TODO: Wait for hostname
|
||||||
|
|
||||||
public void run ()
|
Intent nResult = new Intent();
|
||||||
{
|
nResult.putExtra("hs_host", onionHostname);
|
||||||
String onionHostname = mPrefs.getString("pref_hs_hostname","");
|
setResult(RESULT_OK, nResult);
|
||||||
|
finish();
|
||||||
while (onionHostname.length() == 0)
|
|
||||||
{
|
|
||||||
//we need to stop and start Tor
|
|
||||||
try {
|
|
||||||
Thread.sleep(3000); //wait three seconds
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
onionHostname = mPrefs.getString("pref_hs_hostname","");
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent nResult = new Intent();
|
|
||||||
nResult.putExtra("hs_host", onionHostname);
|
|
||||||
setResult(RESULT_OK, nResult);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Intent nResult = new Intent();
|
|
||||||
nResult.putExtra("hs_host", onionHostname);
|
|
||||||
setResult(RESULT_OK, nResult);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,7 +619,8 @@ public class OrbotMainActivity extends AppCompatActivity
|
||||||
|
|
||||||
if (action.equals(INTENT_ACTION_REQUEST_HIDDEN_SERVICE))
|
if (action.equals(INTENT_ACTION_REQUEST_HIDDEN_SERVICE))
|
||||||
{
|
{
|
||||||
final int hiddenServicePortRequest = getIntent().getIntExtra("hs_port", -1);
|
final int hiddenServicePort = getIntent().getIntExtra("hs_port", -1);
|
||||||
|
final String hiddenServiceName = getIntent().getStringExtra("hs_name");
|
||||||
|
|
||||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
|
@ -649,7 +629,7 @@ public class OrbotMainActivity extends AppCompatActivity
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
|
||||||
try {
|
try {
|
||||||
enableHiddenServicePort (hiddenServicePortRequest);
|
enableHiddenServicePort (hiddenServiceName, hiddenServicePort);
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
|
|
Loading…
Reference in New Issue