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
This commit is contained in:
Hans-Christoph Steiner 2015-06-17 11:13:35 -04:00
parent e5c2e1a040
commit c9e31020e0
1 changed files with 28 additions and 15 deletions

View File

@ -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,6 +594,7 @@ public class OrbotMainActivity extends Activity
else if (action.equals(Intent.ACTION_MAIN))
{
// OrbotMainActivity was restarted after being killed
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) {