[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] prevent a status request from starting TorService
commit c9e31020e06bf283653e5f96bbdf70fc6a50e355
Author: Hans-Christoph Steiner <hans@xxxxxxx>
Date: Wed Jun 17 11:13:35 2015 -0400
prevent a status request from starting TorService
If some internal bit of Orbot is requesting the status of TorService, it
should not cause it to start. So only request status from TorService if it
is running, otherwise keep status as OFF.
the big imports change is because of the Android auto-formatter
---
src/org/torproject/android/OrbotMainActivity.java | 43 ++++++++++++++-------
1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java
index b1ea635..d0d088b 100644
--- a/src/org/torproject/android/OrbotMainActivity.java
+++ b/src/org/torproject/android/OrbotMainActivity.java
@@ -3,22 +3,10 @@
package org.torproject.android;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import org.torproject.android.service.TorService;
-import org.torproject.android.service.TorServiceConstants;
-import org.torproject.android.service.TorServiceUtils;
-import org.torproject.android.settings.SettingsPreferences;
-import org.torproject.android.ui.ImageProgressView;
-import org.torproject.android.ui.PromoAppsActivity;
-import org.torproject.android.ui.Rotate3dAnimation;
-
import android.annotation.TargetApi;
import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningServiceInfo;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
@@ -63,6 +51,20 @@ import android.widget.ToggleButton;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
+import org.torproject.android.service.TorService;
+import org.torproject.android.service.TorServiceConstants;
+import org.torproject.android.service.TorServiceUtils;
+import org.torproject.android.settings.SettingsPreferences;
+import org.torproject.android.ui.ImageProgressView;
+import org.torproject.android.ui.PromoAppsActivity;
+import org.torproject.android.ui.Rotate3dAnimation;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.text.NumberFormat;
+import java.util.Locale;
+
public class OrbotMainActivity extends Activity
implements OrbotConstants, OnLongClickListener, OnTouchListener {
@@ -592,7 +594,8 @@ public class OrbotMainActivity extends Activity
else if (action.equals(Intent.ACTION_MAIN))
{
// OrbotMainActivity was restarted after being killed
- sendIntentToService(TorServiceConstants.CMD_STATUS);
+ if (isTorServiceRunning())
+ sendIntentToService(TorServiceConstants.CMD_STATUS);
}
updateStatus("");
@@ -1129,6 +1132,16 @@ public class OrbotMainActivity extends Activity
sendIntentToService(TorServiceConstants.ACTION_START);
}
+ private boolean isTorServiceRunning() {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (TorService.class.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public boolean onLongClick(View view) {
try {
if (torStatus == TorServiceConstants.STATUS_OFF) {
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits