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:
parent
e5c2e1a040
commit
c9e31020e0
|
@ -3,22 +3,10 @@
|
||||||
|
|
||||||
package org.torproject.android;
|
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.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
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;
|
||||||
|
@ -63,6 +51,20 @@ import android.widget.ToggleButton;
|
||||||
import com.google.zxing.integration.android.IntentIntegrator;
|
import com.google.zxing.integration.android.IntentIntegrator;
|
||||||
import com.google.zxing.integration.android.IntentResult;
|
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
|
public class OrbotMainActivity extends Activity
|
||||||
implements OrbotConstants, OnLongClickListener, OnTouchListener {
|
implements OrbotConstants, OnLongClickListener, OnTouchListener {
|
||||||
|
@ -592,7 +594,8 @@ public class OrbotMainActivity extends Activity
|
||||||
else if (action.equals(Intent.ACTION_MAIN))
|
else if (action.equals(Intent.ACTION_MAIN))
|
||||||
{
|
{
|
||||||
// OrbotMainActivity was restarted after being killed
|
// OrbotMainActivity was restarted after being killed
|
||||||
sendIntentToService(TorServiceConstants.CMD_STATUS);
|
if (isTorServiceRunning())
|
||||||
|
sendIntentToService(TorServiceConstants.CMD_STATUS);
|
||||||
}
|
}
|
||||||
updateStatus("");
|
updateStatus("");
|
||||||
|
|
||||||
|
@ -1129,6 +1132,16 @@ public class OrbotMainActivity extends Activity
|
||||||
sendIntentToService(TorServiceConstants.ACTION_START);
|
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) {
|
public boolean onLongClick(View view) {
|
||||||
try {
|
try {
|
||||||
if (torStatus == TorServiceConstants.STATUS_OFF) {
|
if (torStatus == TorServiceConstants.STATUS_OFF) {
|
||||||
|
|
Loading…
Reference in New Issue