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