From 77ba9ad43fb225dea0064bf2433e1e8cd9775fcd Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 27 Oct 2026 21:18:29 +0100 Subject: [PATCH] Expose Android phone state posting through the C bridge API --- .../jni_bridge/android_jni_bridge.c | 41 +++++++++++-------- .../jni_bridge/android_jni_bridge.h | 4 ++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/tools/chatgui-android/jni_bridge/android_jni_bridge.c b/tools/chatgui-android/jni_bridge/android_jni_bridge.c index 54d8fcbc4..65fc64744 100644 --- a/tools/chatgui-android/jni_bridge/android_jni_bridge.c +++ b/tools/chatgui-android/jni_bridge/android_jni_bridge.c @@ -1370,6 +1370,28 @@ int utun_bridge_set_active(int active) { return instance_lite_set_active(active); } +struct phone_state_request { struct UTUN_INSTANCE* inst; int state; unsigned policy; }; +static void phone_state_execute(void* arg) { + struct phone_state_request* req = arg; + call_set_phone_state(req->inst, req->state, req->policy); u_free(req); +} + +int utun_bridge_set_phone_state(int state, unsigned policy) { + struct UTUN_INSTANCE* inst = instance_lite_get_instance(); + struct UASYNC* ua = instance_lite_get_uasync(); + if (!inst || !ua || !uasync_is_running(ua) || state < 0 || state > 2 || policy > 31) { + DEBUG_WARN(DEBUG_CATEGORY_CALL, "phone state JNI unavailable state=%d policy=%u", state, policy); return -1; + } + struct phone_state_request* req = u_calloc(1, sizeof(*req)); + struct posted_task* task = u_calloc(1, sizeof(*task)); + if (!req || !task) { + DEBUG_ERROR(DEBUG_CATEGORY_CALL, "phone state JNI allocation failed"); u_free(req); u_free(task); return -1; + } + req->inst = inst; req->state = state; req->policy = policy; + task->callback = phone_state_execute; task->arg = req; uasync_post_reserved(ua, task); + return 0; +} + static void bridge_notify_network_active_trampoline(void* arg) { (void)arg; bridge_log(BLEV_DEBUG, "network activity notified to standby"); @@ -2874,27 +2896,10 @@ JNIEXPORT void JNICALL Java_com_utun_chat_data_NativeLib_nativeCallContinue( bridge_call_id_action((uint64_t)callId, "continue", call_continue_trampoline); } -struct phone_state_request { struct UTUN_INSTANCE* inst; int state; unsigned policy; }; -static void phone_state_execute(void* arg) { - struct phone_state_request* req = arg; - call_set_phone_state(req->inst, req->state, req->policy); u_free(req); -} - JNIEXPORT void JNICALL Java_com_utun_chat_data_NativeLib_nativeSetPhoneState( JNIEnv* env, jobject thiz, jint state, jint policy) { (void)env; (void)thiz; - struct UTUN_INSTANCE* inst = instance_lite_get_instance(); - struct UASYNC* ua = instance_lite_get_uasync(); - if (!inst || !ua || !uasync_is_running(ua) || state < 0 || state > 2 || policy < 0 || policy > 31) { - DEBUG_WARN(DEBUG_CATEGORY_CALL, "phone state JNI unavailable state=%d", state); return; - } - struct phone_state_request* req = u_calloc(1, sizeof(*req)); - struct posted_task* task = u_calloc(1, sizeof(*task)); - if (!req || !task) { - DEBUG_ERROR(DEBUG_CATEGORY_CALL, "phone state JNI allocation failed"); u_free(req); u_free(task); return; - } - req->inst = inst; req->state = state; req->policy = (unsigned)policy; - task->callback = phone_state_execute; task->arg = req; uasync_post_reserved(ua, task); + utun_bridge_set_phone_state(state, (unsigned)policy); } /* ── P2P аудио-звонок (медиа) ── */ diff --git a/tools/chatgui-android/jni_bridge/android_jni_bridge.h b/tools/chatgui-android/jni_bridge/android_jni_bridge.h index 1e93c25af..b0d047ac8 100644 --- a/tools/chatgui-android/jni_bridge/android_jni_bridge.h +++ b/tools/chatgui-android/jni_bridge/android_jni_bridge.h @@ -258,6 +258,10 @@ void utun_bridge_on_network_change(void); int utun_bridge_set_active(int active); +/* Состояние SIM: state=0 UNKNOWN/1 IDLE/2 BUSY, policy — маска call_policy (0..31). + * 0 — задача поставлена, -1 — отказ; caller исключает stop/restart во время постановки. */ +int utun_bridge_set_phone_state(int state, unsigned policy); + /* Поставить уведомление standby в uasync; досрочный wake только в SLEEP после min_sleep. */ void utun_bridge_notify_network_active(void);