From: Tobias Brunner Date: Fri, 1 May 2020 09:15:38 +0000 (+0200) Subject: android: Use Android-specific scheduler on Android 6 and later X-Git-Tag: 5.9.0dr1~9^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b4c4123c25c3d83a8904ddac137fc760c98bf60;p=thirdparty%2Fstrongswan.git android: Use Android-specific scheduler on Android 6 and later --- diff --git a/src/frontends/android/app/src/main/jni/libandroidbridge/android_jni.h b/src/frontends/android/app/src/main/jni/libandroidbridge/android_jni.h index 918c14c5ef..3aab3de28b 100644 --- a/src/frontends/android/app/src/main/jni/libandroidbridge/android_jni.h +++ b/src/frontends/android/app/src/main/jni/libandroidbridge/android_jni.h @@ -58,6 +58,7 @@ typedef enum { ANDROID_JELLY_BEAN_MR1 = 17, ANDROID_JELLY_BEAN_MR2 = 18, ANDROID_LOLLIPOP = 21, + ANDROID_MARSHMALLOW = 23, } android_sdk_version_t; /** diff --git a/src/frontends/android/app/src/main/jni/libandroidbridge/charonservice.c b/src/frontends/android/app/src/main/jni/libandroidbridge/charonservice.c index d0f1d35ab3..a459f9f3aa 100644 --- a/src/frontends/android/app/src/main/jni/libandroidbridge/charonservice.c +++ b/src/frontends/android/app/src/main/jni/libandroidbridge/charonservice.c @@ -27,6 +27,7 @@ #include "backend/android_creds.h" #include "backend/android_fetcher.h" #include "backend/android_private_key.h" +#include "backend/android_scheduler.h" #include "backend/android_service.h" #include "kernel/android_ipsec.h" #include "kernel/android_net.h" @@ -93,6 +94,11 @@ struct private_charonservice_t { * Sockets that were bypassed and we keep track for */ linked_list_t *sockets; + + /** + * Default scheduler if we don't use it + */ + scheduler_t *default_scheduler; }; /** @@ -574,6 +580,15 @@ static void charonservice_init(JNIEnv *env, jobject service, jobject builder, ); charonservice = &this->public; + if (android_sdk_version >= ANDROID_MARSHMALLOW) + { + /* use a custom scheduler so the app is woken when jobs have to run. + * we can't destroy the default scheduler here due to the scheduler + * job that's operating on it, so we stash it away until later */ + this->default_scheduler = lib->scheduler; + lib->scheduler = android_scheduler_create(service); + } + lib->plugins->add_static_features(lib->plugins, "androidbridge", features, countof(features), TRUE, NULL, NULL); @@ -600,6 +615,7 @@ static void charonservice_deinit(JNIEnv *env) { private_charonservice_t *this = (private_charonservice_t*)charonservice; + DESTROY_IF(this->default_scheduler); this->network_manager->destroy(this->network_manager); this->sockets->destroy(this->sockets); this->builder->destroy(this->builder);