I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 53caad9f authored by sponge's avatar sponge
Browse files

Fix state recognition on restart.

parent 742df967
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ public class MainActivity extends I2PActivityBase { ...@@ -24,7 +24,7 @@ public class MainActivity extends I2PActivityBase {
private Runnable _updater; private Runnable _updater;
private Runnable _oneShotUpdate; private Runnable _oneShotUpdate;
private String _savedStatus; private String _savedStatus;
private boolean _keep; private boolean _keep = true;
protected static final String PROP_NEW_INSTALL = "i2p.newInstall"; protected static final String PROP_NEW_INSTALL = "i2p.newInstall";
...@@ -272,13 +272,16 @@ public class MainActivity extends I2PActivityBase { ...@@ -272,13 +272,16 @@ public class MainActivity extends I2PActivityBase {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
RouterContext ctx = getRouterContext(); RouterContext ctx = getRouterContext();
// RouterService svc = _routerService;
_keep = Util.isConnected(this) && ctx != null; _keep = Util.isConnected(this) && ctx != null;
Util.e("*********************************************************");
Util.e("Back pressed, Keep? " + _keep);
Util.e("*********************************************************");
super.onBackPressed(); super.onBackPressed();
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
// RouterContext ctx = getRouterContext();
super.onDestroy(); super.onDestroy();
if (!_keep) { if (!_keep) {
Thread t = new Thread(new KillMe()); Thread t = new Thread(new KillMe());
...@@ -288,6 +291,9 @@ public class MainActivity extends I2PActivityBase { ...@@ -288,6 +291,9 @@ public class MainActivity extends I2PActivityBase {
private class KillMe implements Runnable { private class KillMe implements Runnable {
public void run() { public void run() {
Util.e("*********************************************************");
Util.e("KillMe started!");
Util.e("*********************************************************");
try { try {
Thread.sleep(500); // is 500ms long enough? Thread.sleep(500); // is 500ms long enough?
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
......
...@@ -28,8 +28,8 @@ import net.i2p.util.OrderedProperties; ...@@ -28,8 +28,8 @@ import net.i2p.util.OrderedProperties;
*/ */
public class RouterService extends Service { public class RouterService extends Service {
// These states persist even if we died... Yuck, it causes issues.
public enum State { public enum State {
INIT, WAITING, STARTING, RUNNING, INIT, WAITING, STARTING, RUNNING,
// unplanned (router stopped itself), next: killSelf() // unplanned (router stopped itself), next: killSelf()
STOPPING, STOPPED, STOPPING, STOPPED,
...@@ -80,8 +80,11 @@ public class RouterService extends Service { ...@@ -80,8 +80,11 @@ public class RouterService extends Service {
Intent intent = new Intent(this, RouterService.class); Intent intent = new Intent(this, RouterService.class);
intent.putExtra(EXTRA_RESTART, true); intent.putExtra(EXTRA_RESTART, true);
onStartCommand(intent, 12345, 67890); onStartCommand(intent, 12345, 67890);
} else if(lastState == State.MANUAL_QUITTING || lastState == State.MANUAL_QUITTED) { } else if(lastState == State.MANUAL_QUITTING) {
stopSelf(); // Die. synchronized(_stateLock) {
setState(State.MANUAL_QUITTED);
stopSelf(); // Die.
}
} }
} }
...@@ -657,14 +660,15 @@ public class RouterService extends Service { ...@@ -657,14 +660,15 @@ public class RouterService extends Service {
|| _state == State.STOPPING) { || _state == State.STOPPING) {
Util.i(this + " died of unknown causes"); Util.i(this + " died of unknown causes");
setState(State.STOPPED); setState(State.STOPPED);
stopForeground(true);
stopSelf(); stopSelf();
} else if(_state == State.MANUAL_QUITTING) { } else if(_state == State.MANUAL_QUITTING) {
setState(State.MANUAL_QUITTED); setState(State.MANUAL_QUITTED);
stopForeground(true);
stopSelf(); stopSelf();
} }
} }
} finally { } finally {
stopForeground(true);
_statusBar.remove(); _statusBar.remove();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment