Browse Source

fixes grac stop

pull/1095/head
hypnosis-i2p 7 years ago
parent
commit
56f6e57118
  1. 60
      android/src/org/purplei2p/i2pd/I2PDActivity.java

60
android/src/org/purplei2p/i2pd/I2PDActivity.java

@ -20,7 +20,7 @@ import android.widget.Toast; @@ -20,7 +20,7 @@ import android.widget.Toast;
public class I2PDActivity extends Activity {
private static final String TAG = "i2pdActvt";
public static final int GRACEFUL_DELAY_MILLIS = 10 * 60 * 1000;
public static final int GRACEFUL_DELAY_MILLIS = 120 * 1000;
private TextView textView;
@ -55,10 +55,10 @@ public class I2PDActivity extends Activity { @@ -55,10 +55,10 @@ public class I2PDActivity extends Activity {
});
}
};
private volatile long graceStartedMillis;
private final Object graceStartedMillis_LOCK=new Object();
private static volatile long graceStartedMillis;
private static final Object graceStartedMillis_LOCK=new Object();
private String formatGraceTimeRemaining() {
private static String formatGraceTimeRemaining() {
long remainingSeconds;
synchronized (graceStartedMillis_LOCK){
remainingSeconds=Math.round(Math.max(0,graceStartedMillis+GRACEFUL_DELAY_MILLIS-System.currentTimeMillis())/1000.0D);
@ -79,6 +79,15 @@ public class I2PDActivity extends Activity { @@ -79,6 +79,15 @@ public class I2PDActivity extends Activity {
//set the app be foreground
doBindService();
final Timer gracefulQuitTimer = getGracefulQuitTimer();
if(gracefulQuitTimer!=null){
long gracefulStopAtMillis;
synchronized (graceStartedMillis_LOCK) {
gracefulStopAtMillis = graceStartedMillis + GRACEFUL_DELAY_MILLIS;
}
rescheduleGraceStop(gracefulQuitTimer, gracefulStopAtMillis);
}
}
@Override
@ -86,7 +95,7 @@ public class I2PDActivity extends Activity { @@ -86,7 +95,7 @@ public class I2PDActivity extends Activity {
super.onDestroy();
textView = null;
daemon.removeStateChangeListener(daemonStateUpdatedListener);
cancelGracefulStop();
//cancelGracefulStop();
try{
doUnbindService();
}catch(Throwable tr){
@ -94,7 +103,7 @@ public class I2PDActivity extends Activity { @@ -94,7 +103,7 @@ public class I2PDActivity extends Activity {
}
}
private void cancelGracefulStop() {
private static void cancelGracefulStop() {
Timer gracefulQuitTimer = getGracefulQuitTimer();
if(gracefulQuitTimer!=null) {
gracefulQuitTimer.cancel();
@ -205,7 +214,7 @@ public class I2PDActivity extends Activity { @@ -205,7 +214,7 @@ public class I2PDActivity extends Activity {
},"stop").start();
}
private volatile Timer gracefulQuitTimer;
private static volatile Timer gracefulQuitTimer;
private void i2pdGracefulStop() {
if(daemon.getState()==DaemonSingleton.State.stopped){
@ -228,11 +237,27 @@ public class I2PDActivity extends Activity { @@ -228,11 +237,27 @@ public class I2PDActivity extends Activity {
Log.d(TAG, "grac stopping");
if(daemon.isStartedOkay()) {
daemon.stopAcceptingTunnels();
final Timer gracefulQuitTimer = new Timer(true);
setGracefulQuitTimer(gracefulQuitTimer);
long gracefulStopAtMillis;
synchronized (graceStartedMillis_LOCK) {
graceStartedMillis = System.currentTimeMillis();
gracefulStopAtMillis = graceStartedMillis + GRACEFUL_DELAY_MILLIS;
}
rescheduleGraceStop(null,gracefulStopAtMillis);
}else{
i2pdStop();
}
} catch(Throwable tr) {
Log.e(TAG,"",tr);
}
}
},"gracInit").start();
}
private void rescheduleGraceStop(Timer gracefulQuitTimerOld, long gracefulStopAtMillis) {
if(gracefulQuitTimerOld!=null)gracefulQuitTimerOld.cancel();
final Timer gracefulQuitTimer = new Timer(true);
setGracefulQuitTimer(gracefulQuitTimer);
gracefulQuitTimer.schedule(new TimerTask(){
@Override
@ -240,7 +265,7 @@ public class I2PDActivity extends Activity { @@ -240,7 +265,7 @@ public class I2PDActivity extends Activity {
i2pdStop();
}
}, GRACEFUL_DELAY_MILLIS);
}, Math.max(0,gracefulStopAtMillis-System.currentTimeMillis()));
final TimerTask tickerTask = new TimerTask() {
@Override
public void run() {
@ -248,22 +273,13 @@ public class I2PDActivity extends Activity { @@ -248,22 +273,13 @@ public class I2PDActivity extends Activity {
}
};
gracefulQuitTimer.scheduleAtFixedRate(tickerTask,0/*start delay*/,1000/*millis period*/);
}else{
i2pdStop();
}
} catch(Throwable tr) {
Log.e(TAG,"",tr);
}
}
},"gracInit").start();
}
private Timer getGracefulQuitTimer() {
private static Timer getGracefulQuitTimer() {
return gracefulQuitTimer;
}
private void setGracefulQuitTimer(Timer gracefulQuitTimer) {
this.gracefulQuitTimer = gracefulQuitTimer;
private static void setGracefulQuitTimer(Timer gracefulQuitTimer) {
I2PDActivity.gracefulQuitTimer = gracefulQuitTimer;
}
}

Loading…
Cancel
Save