adds optional string to the intent

This commit is contained in:
arrase 2016-11-17 04:09:45 +01:00
parent 3f7435c90e
commit 0131cf20f0
1 changed files with 36 additions and 56 deletions

View File

@ -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="";
Editor pEdit = mPrefs.edit(); String[] mProjection = new String[]{
HSContentProvider.HiddenService._ID,
String hsPortString = mPrefs.getString("pref_hs_ports", ""); HSContentProvider.HiddenService.NAME,
String onionHostname = mPrefs.getString("pref_hs_hostname",""); HSContentProvider.HiddenService.DOMAIN,
HSContentProvider.HiddenService.PORT};
if (hsPortString.indexOf(hsPort+"")==-1)
{ if(hsName == null)
if (hsPortString.length() > 0 && hsPortString.indexOf(hsPort+"")==-1) hsName = "hs"+hsPort;
hsPortString += ',' + hsPort;
else ContentValues fields = new ContentValues();
hsPortString = hsPort + ""; fields.put("name", hsName);
fields.put("port", hsPort);
pEdit.putString("pref_hs_ports", hsPortString); ContentResolver cr = getContentResolver();
pEdit.putBoolean("pref_hs_enable", true); Cursor row = cr.query(HSContentProvider.CONTENT_URI, mProjection, "port="+hsPort, null, null);
pEdit.commit(); if(row == null) {
cr.insert(HSContentProvider.CONTENT_URI, fields);
} else {
onionHostname = row.getString(row.getColumnIndex(HSContentProvider.HiddenService.NAME));
cr.update(HSContentProvider.CONTENT_URI, fields, "port=" + hsPort, null);
row.close();
} }
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