]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Use Android-specific scheduler on Android 6 and later
authorTobias Brunner <tobias@strongswan.org>
Fri, 1 May 2020 09:15:38 +0000 (11:15 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 2 Jun 2020 12:07:06 +0000 (14:07 +0200)
src/frontends/android/app/src/main/jni/libandroidbridge/android_jni.h
src/frontends/android/app/src/main/jni/libandroidbridge/charonservice.c

index 918c14c5ef1ae4f43f44b06e50b892d438e5ee47..3aab3de28bd6eb6c6950ba312a7f4b2824af3dcd 100644 (file)
@@ -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;
 
 /**
index d0f1d35ab3b884f1fa582e5cbf1e402dd28b81ad..a459f9f3aa4c78948cf674ccc67da2d53365ef84 100644 (file)
@@ -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);