[tor-commits] [orbot/master] add dynamic display of SOCKS and HTTP port proxy value
n8fr8 at torproject.org
n8fr8 at torproject.org
Fri Jul 5 12:40:01 UTC 2019
commit 6dffafcbea68ad426c0555c14a31324caa4e9337
Author: n8fr8 <nathan at guardianproject.info>
Date: Tue Jun 4 05:49:47 2019 -0400
add dynamic display of SOCKS and HTTP port proxy value
---
.../org/torproject/android/OrbotMainActivity.java | 36 +++++++++++++++++++---
app/src/main/res/layout/layout_main.xml | 18 ++++++++++-
app/src/main/res/values/strings.xml | 1 +
.../org/torproject/android/service/TorService.java | 16 +++++++++-
.../android/service/TorServiceConstants.java | 1 +
5 files changed, 65 insertions(+), 7 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index d1929f88..a87da30d 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -96,6 +96,7 @@ public class OrbotMainActivity extends AppCompatActivity
/* Useful UI bits */
private TextView lblStatus = null; //the main text display widget
+ private TextView lblPorts = null;
private ImageView imgStatus = null; //the main touchable image for activating Orbot
private TextView downloadText = null;
@@ -128,8 +129,10 @@ public class OrbotMainActivity extends AppCompatActivity
// message types for mStatusUpdateHandler
private final static int STATUS_UPDATE = 1;
private static final int MESSAGE_TRAFFIC_COUNT = 2;
+ private static final int MESSAGE_PORTS = 3;
- public final static String INTENT_ACTION_REQUEST_HIDDEN_SERVICE = "org.torproject.android.REQUEST_HS_PORT";
+
+ public final static String INTENT_ACTION_REQUEST_HIDDEN_SERVICE = "org.torproject.android.REQUEST_HS_PORT";
public final static String INTENT_ACTION_REQUEST_START_TOR = "org.torproject.android.START_TOR";
@@ -179,6 +182,10 @@ public class OrbotMainActivity extends AppCompatActivity
new IntentFilter(TorServiceConstants.LOCAL_ACTION_BANDWIDTH));
lbm.registerReceiver(mLocalBroadcastReceiver,
new IntentFilter(TorServiceConstants.LOCAL_ACTION_LOG));
+ lbm.registerReceiver(mLocalBroadcastReceiver,
+ new IntentFilter(TorServiceConstants.LOCAL_ACTION_PORTS));
+
+
boolean showFirstTime = mPrefs.getBoolean("connect_first_time", true);
@@ -253,6 +260,15 @@ public class OrbotMainActivity extends AppCompatActivity
mStatusUpdateHandler.sendMessage(msg);
}
+ else if (action.equals(TorServiceConstants.LOCAL_ACTION_PORTS)) {
+
+ Message msg = mStatusUpdateHandler.obtainMessage(MESSAGE_PORTS);
+ msg.getData().putInt("socks",intent.getIntExtra("socks",-1));
+ msg.getData().putInt("http",intent.getIntExtra("http",-1));
+
+ mStatusUpdateHandler.sendMessage(msg);
+
+ }
}
};
@@ -277,6 +293,8 @@ public class OrbotMainActivity extends AppCompatActivity
}
});
+ lblPorts = findViewById(R.id.lblPorts);
+
imgStatus = (ImageView)findViewById(R.id.imgStatus);
imgStatus.setOnLongClickListener(this);
@@ -1112,7 +1130,7 @@ public class OrbotMainActivity extends AppCompatActivity
}
- if (torStatus == null || newTorStatus.equals(torStatus)) {
+ if (torStatus == null || (newTorStatus != null && newTorStatus.equals(torStatus))) {
torStatus = newTorStatus;
return;
}
@@ -1233,14 +1251,14 @@ public class OrbotMainActivity extends AppCompatActivity
@Override
public void handleMessage(final Message msg) {
-
+ Bundle data = msg.getData();
+
switch (msg.what) {
case MESSAGE_TRAFFIC_COUNT:
- Bundle data = msg.getData();
- DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download"));
+ DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download"));
long totalRead = data.getLong("readTotal");
long totalWrite = data.getLong("writeTotal");
@@ -1249,6 +1267,14 @@ public class OrbotMainActivity extends AppCompatActivity
uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(totalWrite));
break;
+ case MESSAGE_PORTS:
+
+ int socksPort = data.getInt("socks");
+ int httpPort = data.getInt("http");
+
+ lblPorts.setText("SOCKS: " + socksPort + " | HTTP: " + httpPort);
+
+ break;
default:
String newTorStatus = msg.getData().getString("status");
String log = (String)msg.obj;
diff --git a/app/src/main/res/layout/layout_main.xml b/app/src/main/res/layout/layout_main.xml
index 8c8ca79d..42e6691f 100644
--- a/app/src/main/res/layout/layout_main.xml
+++ b/app/src/main/res/layout/layout_main.xml
@@ -84,11 +84,27 @@
android:layout_below="@+id/frameMain"
/>
+ <TextView
+ android:id="@+id/lblPorts"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="14sp"
+ android:fontFamily="sans-serif-light"
+ android:lines="1"
+ android:text="@string/default_socks_http"
+ android:maxLines="1"
+ android:layout_margin="12dp"
+ android:ellipsize="end"
+ android:layout_gravity="top|center"
+ android:gravity="center"
+ android:layout_below="@+id/lblStatus"
+ />
+
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
- android:layout_below="@+id/lblStatus"
+ android:layout_below="@+id/lblPorts"
android:id="@+id/controls"
>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9ae73c04..e8802b1f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -253,4 +253,5 @@
<string name="user_services">User services</string>
<string name="app_services">App services</string>
+ <string name="default_socks_http">SOCKS: - HTTP: -</string>
</resources>
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
index 9d88aeb9..690b2c5b 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -1092,7 +1092,9 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
confTrans = st.nextToken().split(":")[1];
confTrans = confDns.substring(0,confTrans.length()-1);
mPortTrans = Integer.parseInt(confTrans);
-
+
+ sendCallbackPorts(mPortSOCKS, mPortHTTP);
+
return Integer.parseInt(torProcId);
}
@@ -1405,6 +1407,18 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
+
+ private void sendCallbackPorts (int socksPort, int httpPort)
+ {
+
+ Intent intent = new Intent(LOCAL_ACTION_PORTS);
+ // You can also include some extra data.
+ intent.putExtra("socks",socksPort);
+ intent.putExtra("http",httpPort);
+
+ LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
+
+ }
protected void sendCallbackStatus(String currentStatus) {
mCurrentStatus = currentStatus;
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
index 22a6ea29..dcbb824a 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
@@ -107,6 +107,7 @@ public interface TorServiceConstants {
String LOCAL_ACTION_LOG = "log";
String LOCAL_ACTION_BANDWIDTH = "bandwidth";
String LOCAL_EXTRA_LOG = "log";
+ String LOCAL_ACTION_PORTS = "ports";
/**
* All tor-related services and daemons are stopped
More information about the tor-commits
mailing list