Browse Source

Cancel Graceful Stop

pull/1274/head
orignal 6 years ago
parent
commit
7c1961d4ef
  1. 5
      android/jni/i2pd_android.cpp
  2. 3
      android/jni/org_purplei2p_i2pd_I2PD_JNI.h
  3. 1
      android/res/values/strings.xml
  4. 7
      android/src/org/purplei2p/i2pd/DaemonSingleton.java
  5. 39
      android/src/org/purplei2p/i2pd/I2PDActivity.java
  6. 2
      android/src/org/purplei2p/i2pd/I2PD_JNI.java

5
android/jni/i2pd_android.cpp

@ -58,6 +58,11 @@ JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopAcceptingTunnels
i2p::context.SetAcceptsTunnels (false); i2p::context.SetAcceptsTunnels (false);
} }
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startAcceptingTunnels
(JNIEnv * env, jclass clazz) {
i2p::context.SetAcceptsTunnels (true);
}
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_onNetworkStateChanged JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_onNetworkStateChanged
(JNIEnv * env, jclass clazz, jboolean isConnected) (JNIEnv * env, jclass clazz, jboolean isConnected)
{ {

3
android/jni/org_purplei2p_i2pd_I2PD_JNI.h

@ -24,6 +24,9 @@ JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopDaemon
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopAcceptingTunnels JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_stopAcceptingTunnels
(JNIEnv *, jclass); (JNIEnv *, jclass);
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startAcceptingTunnels
(JNIEnv *, jclass);
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_onNetworkStateChanged JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_onNetworkStateChanged
(JNIEnv * env, jclass clazz, jboolean isConnected); (JNIEnv * env, jclass clazz, jboolean isConnected);

1
android/res/values/strings.xml

@ -3,6 +3,7 @@
<string name="app_name">i2pd</string> <string name="app_name">i2pd</string>
<string name="action_stop">Stop</string> <string name="action_stop">Stop</string>
<string name="action_graceful_stop">Graceful Stop</string> <string name="action_graceful_stop">Graceful Stop</string>
<string name="action_cancel_graceful_stop">Cancel Graceful Stop</string>
<string name="graceful_stop_is_already_in_progress">Graceful stop is already in progress</string> <string name="graceful_stop_is_already_in_progress">Graceful stop is already in progress</string>
<string name="graceful_stop_is_in_progress">Graceful stop is in progress</string> <string name="graceful_stop_is_in_progress">Graceful stop is in progress</string>
<string name="already_stopped">Already stopped</string> <string name="already_stopped">Already stopped</string>

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

@ -33,6 +33,13 @@ public class DaemonSingleton {
} }
} }
public synchronized void startAcceptingTunnels() {
if(isStartedOkay()){
setState(State.startedOkay);
I2PD_JNI.startAcceptingTunnels();
}
}
private volatile boolean startedOkay; private volatile boolean startedOkay;
public enum State { public enum State {

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

@ -144,14 +144,10 @@ public class I2PDActivity extends Activity {
case MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE: case MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE:
{ {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
Log.e(TAG, "Memory permission granted"); Log.e(TAG, "Memory permission granted");
}
else else
{
Log.e(TAG, "Memory permission declined"); Log.e(TAG, "Memory permission declined");
// TODO: terminate // TODO: terminate
}
return; return;
} }
default: ; default: ;
@ -244,7 +240,16 @@ public class I2PDActivity extends Activity {
i2pdStop(); i2pdStop();
return true; return true;
case R.id.action_graceful_stop: case R.id.action_graceful_stop:
if (getGracefulQuitTimer()!= null)
{
item.setTitle(R.string.action_graceful_stop);
i2pdCancelGracefulStop ();
}
else
{
item.setTitle(R.string.action_cancel_graceful_stop);
i2pdGracefulStop(); i2pdGracefulStop();
}
return true; return true;
} }
@ -308,6 +313,32 @@ public class I2PDActivity extends Activity {
},"gracInit").start(); },"gracInit").start();
} }
private void i2pdCancelGracefulStop()
{
cancelGracefulStop();
Toast.makeText(this, R.string.startedOkay, Toast.LENGTH_SHORT).show();
new Thread(new Runnable()
{
@Override
public void run()
{
try
{
Log.d(TAG, "grac stopping cancel");
if(daemon.isStartedOkay())
daemon.startAcceptingTunnels();
else
i2pdStop();
}
catch(Throwable tr)
{
Log.e(TAG,"",tr);
}
}
},"gracCancel").start();
}
private void rescheduleGraceStop(Timer gracefulQuitTimerOld, long gracefulStopAtMillis) { private void rescheduleGraceStop(Timer gracefulQuitTimerOld, long gracefulStopAtMillis) {
if(gracefulQuitTimerOld!=null)gracefulQuitTimerOld.cancel(); if(gracefulQuitTimerOld!=null)gracefulQuitTimerOld.cancel();
final Timer gracefulQuitTimer = new Timer(true); final Timer gracefulQuitTimer = new Timer(true);

2
android/src/org/purplei2p/i2pd/I2PD_JNI.java

@ -12,6 +12,8 @@ public class I2PD_JNI {
public static native void stopAcceptingTunnels(); public static native void stopAcceptingTunnels();
public static native void startAcceptingTunnels();
public static native void onNetworkStateChanged(boolean isConnected); public static native void onNetworkStateChanged(boolean isConnected);
public static void loadLibraries() { public static void loadLibraries() {

Loading…
Cancel
Save