diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java index b1ea6353..d0d088ba 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) {