when OrbotMainActivity starts, query TorService for current status
If OrbotMainActivity gets killed while TorService is running, then when OrbotMainActivity starts again, it needs to get the current status from TorService to correctly represent things to the user.
This commit is contained in:
parent
f16394b7db
commit
e5c2e1a040
|
@ -589,7 +589,11 @@ public class OrbotMainActivity extends Activity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (action.equals(Intent.ACTION_MAIN))
|
||||||
|
{
|
||||||
|
// OrbotMainActivity was restarted after being killed
|
||||||
|
sendIntentToService(TorServiceConstants.CMD_STATUS);
|
||||||
|
}
|
||||||
updateStatus("");
|
updateStatus("");
|
||||||
|
|
||||||
setIntent(null);
|
setIntent(null);
|
||||||
|
|
|
@ -16,6 +16,7 @@ import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.ContextWrapper;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -346,6 +347,9 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
replyWithStatus(mIntent);
|
replyWithStatus(mIntent);
|
||||||
startTor();
|
startTor();
|
||||||
// stopTor() is called when the Service is destroyed
|
// stopTor() is called when the Service is destroyed
|
||||||
|
} else if (action.equals(CMD_STATUS)) {
|
||||||
|
Intent intent = getActionStatusIntent(mCurrentStatus);
|
||||||
|
sendBroadcastOnlyToOrbot(intent);
|
||||||
} else if (action.equals(CMD_SIGNAL_HUP)) {
|
} else if (action.equals(CMD_SIGNAL_HUP)) {
|
||||||
requestTorRereadConfig();
|
requestTorRereadConfig();
|
||||||
} else if (action.equals(CMD_NEWNYM)) {
|
} else if (action.equals(CMD_NEWNYM)) {
|
||||||
|
@ -1901,20 +1905,32 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
|
|
||||||
private void sendCallbackStatus(String currentStatus) {
|
private void sendCallbackStatus(String currentStatus) {
|
||||||
mCurrentStatus = currentStatus;
|
mCurrentStatus = currentStatus;
|
||||||
|
Intent intent = getActionStatusIntent(currentStatus);
|
||||||
Intent intent = new Intent(ACTION_STATUS);
|
|
||||||
intent.putExtra(EXTRA_STATUS, currentStatus);
|
|
||||||
// send for Orbot internals, using secure local broadcast
|
// send for Orbot internals, using secure local broadcast
|
||||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
sendBroadcastOnlyToOrbot(intent);
|
||||||
// send for any apps that are interested
|
// send for any apps that are interested
|
||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a secure broadcast only to Orbot itself
|
||||||
|
* @see {@link ContextWrapper#sendBroadcast(Intent)}
|
||||||
|
* @see {@link LocalBroadcastManager}
|
||||||
|
*/
|
||||||
|
private boolean sendBroadcastOnlyToOrbot(Intent intent) {
|
||||||
|
return LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Intent getActionStatusIntent(String currentStatus) {
|
||||||
|
Intent intent = new Intent(ACTION_STATUS);
|
||||||
|
intent.putExtra(EXTRA_STATUS, currentStatus);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Another way to do this would be to use the Observer pattern by defining the
|
* Another way to do this would be to use the Observer pattern by defining the
|
||||||
* BroadcastReciever in the Android manifest.
|
* BroadcastReciever in the Android manifest.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private final BroadcastReceiver mNetworkStateReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mNetworkStateReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
|
@ -119,6 +119,7 @@ public interface TorServiceConstants {
|
||||||
|
|
||||||
// actions for internal command Intents
|
// actions for internal command Intents
|
||||||
public static final String CMD_SIGNAL_HUP = "signal_hup";
|
public static final String CMD_SIGNAL_HUP = "signal_hup";
|
||||||
|
public static final String CMD_STATUS = "status";
|
||||||
public static final String CMD_FLUSH = "flush";
|
public static final String CMD_FLUSH = "flush";
|
||||||
public static final String CMD_NEWNYM = "newnym";
|
public static final String CMD_NEWNYM = "newnym";
|
||||||
public static final String CMD_VPN = "vpn";
|
public static final String CMD_VPN = "vpn";
|
||||||
|
|
Loading…
Reference in New Issue