|
|
@ -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,35 +39,45 @@ public class DaemonSingleton { |
|
|
|
public State getState() { return state; } |
|
|
|
public State getState() { return state; } |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
fireStateChange(); |
|
|
|
synchronized(this){ |
|
|
|
new Thread(new Runnable(){ |
|
|
|
fireStateChange(); |
|
|
|
|
|
|
|
new Thread(new Runnable(){ |
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
@Override |
|
|
|
try { |
|
|
|
public void run() { |
|
|
|
I2PD_JNI.loadLibraries(); |
|
|
|
try { |
|
|
|
state = State.jniLibraryLoaded; |
|
|
|
I2PD_JNI.loadLibraries(); |
|
|
|
fireStateChange(); |
|
|
|
synchronized (DaemonSingleton.this) { |
|
|
|
} catch (Throwable tr) { |
|
|
|
state = State.jniLibraryLoaded; |
|
|
|
lastThrowable=tr; |
|
|
|
fireStateChange(); |
|
|
|
state = State.startFailed; |
|
|
|
} |
|
|
|
fireStateChange(); |
|
|
|
} catch (Throwable tr) { |
|
|
|
return; |
|
|
|
lastThrowable=tr; |
|
|
|
|
|
|
|
synchronized (DaemonSingleton.this) { |
|
|
|
|
|
|
|
state = State.startFailed; |
|
|
|
|
|
|
|
fireStateChange(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
synchronized (DaemonSingleton.this) { |
|
|
|
|
|
|
|
daemonStartResult = I2PD_JNI.startDaemon(); |
|
|
|
|
|
|
|
if("ok".equals(daemonStartResult)){state=State.startedOkay;setStartedOkay(true);} |
|
|
|
|
|
|
|
else state=State.startFailed; |
|
|
|
|
|
|
|
fireStateChange(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Throwable tr) { |
|
|
|
|
|
|
|
lastThrowable=tr; |
|
|
|
|
|
|
|
synchronized (DaemonSingleton.this) { |
|
|
|
|
|
|
|
state = State.startFailed; |
|
|
|
|
|
|
|
fireStateChange(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
|
|
|
|
daemonStartResult = I2PD_JNI.startDaemon(); |
|
|
|
}, "i2pdDaemonStart").start(); |
|
|
|
if("ok".equals(daemonStartResult)){state=State.startedOkay;setStartedOkay(true);} |
|
|
|
} |
|
|
|
else state=State.startFailed; |
|
|
|
|
|
|
|
fireStateChange(); |
|
|
|
|
|
|
|
} catch (Throwable tr) { |
|
|
|
|
|
|
|
lastThrowable=tr; |
|
|
|
|
|
|
|
state = State.startFailed; |
|
|
|
|
|
|
|
fireStateChange(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, "i2pdDaemonStart").start(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
private Throwable lastThrowable; |
|
|
|
private Throwable lastThrowable; |
|
|
|
private String daemonStartResult="N/A"; |
|
|
|
private String daemonStartResult="N/A"; |
|
|
@ -90,16 +100,22 @@ public class DaemonSingleton { |
|
|
|
public String getDaemonStartResult() { |
|
|
|
public String getDaemonStartResult() { |
|
|
|
return daemonStartResult; |
|
|
|
return daemonStartResult; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Object startedOkayLock = new Object(); |
|
|
|
|
|
|
|
|
|
|
|
public synchronized boolean isStartedOkay() { |
|
|
|
public boolean isStartedOkay() { |
|
|
|
return startedOkay; |
|
|
|
synchronized (startedOkayLock) { |
|
|
|
|
|
|
|
return startedOkay; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private synchronized void setStartedOkay(boolean startedOkay) { |
|
|
|
private void setStartedOkay(boolean startedOkay) { |
|
|
|
this.startedOkay = startedOkay; |
|
|
|
synchronized (startedOkayLock) { |
|
|
|
|
|
|
|
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); |
|
|
|