Browse Source

updated

pull/572/head
hypnosis-i2p 8 years ago
parent
commit
a3286ebac3
  1. 24
      android/src/org/purplei2p/i2pd/DaemonSingleton.java
  2. 7
      android/src/org/purplei2p/i2pd/I2PD.java

24
android/src/org/purplei2p/i2pd/DaemonSingleton.java

@ -18,7 +18,7 @@ public class DaemonSingleton {
public synchronized void addStateChangeListener(StateChangeListener listener) { stateChangeListeners.add(listener); } public synchronized void addStateChangeListener(StateChangeListener listener) { stateChangeListeners.add(listener); }
public synchronized void removeStateChangeListener(StateChangeListener listener) { stateChangeListeners.remove(listener); } public synchronized void removeStateChangeListener(StateChangeListener listener) { stateChangeListeners.remove(listener); }
public void stopAcceptingTunnels() { public synchronized void stopAcceptingTunnels() {
if(isStartedOkay()){ if(isStartedOkay()){
state=State.gracefulShutdownInProgress; state=State.gracefulShutdownInProgress;
fireStateChange(); fireStateChange();
@ -39,6 +39,7 @@ public class DaemonSingleton {
public State getState() { return state; } public State getState() { return state; }
{ {
synchronized(this){
fireStateChange(); fireStateChange();
new Thread(new Runnable(){ new Thread(new Runnable(){
@ -46,29 +47,38 @@ public class DaemonSingleton {
public void run() { public void run() {
try { try {
I2PD_JNI.loadLibraries(); I2PD_JNI.loadLibraries();
synchronized (DaemonSingleton.this) {
state = State.jniLibraryLoaded; state = State.jniLibraryLoaded;
fireStateChange(); fireStateChange();
}
} catch (Throwable tr) { } catch (Throwable tr) {
lastThrowable=tr; lastThrowable=tr;
synchronized (DaemonSingleton.this) {
state = State.startFailed; state = State.startFailed;
fireStateChange(); fireStateChange();
}
return; return;
} }
try { try {
synchronized (DaemonSingleton.this) {
daemonStartResult = I2PD_JNI.startDaemon(); daemonStartResult = I2PD_JNI.startDaemon();
if("ok".equals(daemonStartResult)){state=State.startedOkay;setStartedOkay(true);} if("ok".equals(daemonStartResult)){state=State.startedOkay;setStartedOkay(true);}
else state=State.startFailed; else state=State.startFailed;
fireStateChange(); fireStateChange();
}
} catch (Throwable tr) { } catch (Throwable tr) {
lastThrowable=tr; lastThrowable=tr;
synchronized (DaemonSingleton.this) {
state = State.startFailed; state = State.startFailed;
fireStateChange(); fireStateChange();
}
return; return;
} }
} }
}, "i2pdDaemonStart").start(); }, "i2pdDaemonStart").start();
} }
}
private Throwable lastThrowable; private Throwable lastThrowable;
private String daemonStartResult="N/A"; private String daemonStartResult="N/A";
@ -91,15 +101,21 @@ public class DaemonSingleton {
return daemonStartResult; return daemonStartResult;
} }
public synchronized boolean isStartedOkay() { private final Object startedOkayLock = new Object();
public boolean isStartedOkay() {
synchronized (startedOkayLock) {
return startedOkay; return startedOkay;
} }
}
private synchronized void setStartedOkay(boolean startedOkay) { private void setStartedOkay(boolean startedOkay) {
synchronized (startedOkayLock) {
this.startedOkay = startedOkay; this.startedOkay = startedOkay;
} }
}
public void stopDaemon() { public synchronized void stopDaemon() {
if(isStartedOkay()){ if(isStartedOkay()){
try {I2PD_JNI.stopDaemon();}catch(Throwable tr){Log.e(TAG, "", tr);} try {I2PD_JNI.stopDaemon();}catch(Throwable tr){Log.e(TAG, "", tr);}
setStartedOkay(false); setStartedOkay(false);

7
android/src/org/purplei2p/i2pd/I2PD.java

@ -5,8 +5,6 @@ import java.io.StringWriter;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import org.purplei2p.i2pd.DaemonSingleton.State;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
@ -76,8 +74,9 @@ public class I2PD extends Activity {
private void localDestroy() { private void localDestroy() {
textView = null; textView = null;
daemon.removeStateChangeListener(daemonStateChangeListener); daemon.removeStateChangeListener(daemonStateChangeListener);
if(getGracefulQuitTimer()!=null) { Timer gracefulQuitTimer = getGracefulQuitTimer();
getGracefulQuitTimer().cancel(); if(gracefulQuitTimer!=null) {
gracefulQuitTimer.cancel();
setGracefulQuitTimer(null); setGracefulQuitTimer(null);
} }
try{ try{

Loading…
Cancel
Save