Keep Android calls active independently of screen and UI
This commit is contained in:
1 parent
33025ae80b
commit
a0b671069a
20 files changed
+930
-571
No files matched your search
+11
-31
@@ -113,7 +113,6 @@ static int instance_init_common(struct UTUN_INSTANCE* instance, struct UASYNC* u
|
||||
instance->client_type = config->global.client_type;
|
||||
instance->keepalive_interval = (uint16_t)(config->global.keepalive_interval > 0 ? config->global.keepalive_interval : 200);
|
||||
instance->client_activity = (instance->client_type == CLIENT_TYPE_MOBILE) ? CLIENT_ACTIVITY_STANDBY : CLIENT_ACTIVITY_ACTIVE;
|
||||
instance->client_activity_timer = NULL;
|
||||
|
||||
// Set my keys
|
||||
if (sc_init_local_keys(&instance->my_keys, config->global.my_public_key_hex, config->global.my_private_key_hex) != SC_OK) {
|
||||
@@ -397,10 +396,6 @@ void utun_instance_destroy(struct UTUN_INSTANCE *instance) {
|
||||
if (instance->ua) uasync_print_resources(instance->ua, "INSTANCE_DESTROY_BEFORE");
|
||||
|
||||
instance->running = 0;
|
||||
if (instance->client_activity_timer) {
|
||||
uasync_cancel_timeout(instance->ua, instance->client_activity_timer);
|
||||
instance->client_activity_timer = NULL;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_SYS, "[DESTROY] A done — diagnose complete");
|
||||
|
||||
/* Phase B: NTP */
|
||||
@@ -1133,32 +1128,17 @@ void utun_fire_peer_sleep_cbk(struct UTUN_INSTANCE* instance, uint64_t peer_node
|
||||
}
|
||||
}
|
||||
|
||||
static void client_activity_timeout_cb(void* arg) {
|
||||
struct UTUN_INSTANCE* instance = (struct UTUN_INSTANCE*)arg;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "client_activity_timer fired: node=%016llx type=%u -> standby",
|
||||
(unsigned long long)instance->node_id, instance->client_type);
|
||||
instance->client_activity_timer = NULL;
|
||||
if (instance->client_type == CLIENT_TYPE_SERVER) return;
|
||||
instance->client_activity = CLIENT_ACTIVITY_STANDBY;
|
||||
utun_fire_activity_cbk(instance, CLIENT_ACTIVITY_STANDBY);
|
||||
}
|
||||
|
||||
/* Явная активность UI/звонка не истекает по таймеру: владелец сообщает завершение сам. */
|
||||
void utun_set_client_activity(struct UTUN_INSTANCE* instance, int active) {
|
||||
if (!instance) return;
|
||||
if (!instance) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "client_activity: missing instance active=%d", active);
|
||||
return;
|
||||
}
|
||||
if (instance->client_type == CLIENT_TYPE_SERVER) return;
|
||||
if (instance->client_activity_timer) {
|
||||
uasync_cancel_timeout(instance->ua, instance->client_activity_timer);
|
||||
instance->client_activity_timer = NULL;
|
||||
}
|
||||
if (active) {
|
||||
instance->client_activity = CLIENT_ACTIVITY_ACTIVE;
|
||||
instance->client_activity_timer = uasync_set_timeout(instance->ua, 600000, instance, client_activity_timeout_cb, "activity_timeout");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "client_activity set ACTIVE, timer restarted 60s node=%016llx type=%u",
|
||||
(unsigned long long)instance->node_id, instance->client_type);
|
||||
} else {
|
||||
instance->client_activity = CLIENT_ACTIVITY_STANDBY;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "client_activity set STANDBY node=%016llx type=%u",
|
||||
(unsigned long long)instance->node_id, instance->client_type);
|
||||
}
|
||||
utun_fire_activity_cbk(instance, active);
|
||||
int state = active ? CLIENT_ACTIVITY_ACTIVE : CLIENT_ACTIVITY_STANDBY;
|
||||
if (instance->client_activity == state) return;
|
||||
instance->client_activity = state;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "client_activity set %s until explicit change node=%016llx type=%u",
|
||||
active ? "ACTIVE" : "STANDBY", (unsigned long long)instance->node_id, instance->client_type);
|
||||
utun_fire_activity_cbk(instance, state);
|
||||
}
|
||||
+1
-1
@@ -241,7 +241,6 @@ struct UTUN_INSTANCE {
|
||||
uint8_t client_type; // CLIENT_TYPE_SERVER/DESKTOP/MOBILE (from config)
|
||||
uint16_t keepalive_interval; // желаемый keepalive (ms), из конфига. для handshake
|
||||
uint8_t client_activity; // CLIENT_ACTIVITY_STANDBY/ACTIVE
|
||||
void* client_activity_timer; // uasync timer handle for inactivity timeout
|
||||
struct utun_activity_cbk_entry* activity_cbks; // подписки на смену client_activity
|
||||
struct peer_sleep_cbk_entry* peer_sleep_cbks; // подписки на смену спячки пира (keepalive)
|
||||
uint8_t standby_enabled; // 1 = standby duty-cycle активен (chatgui-android)
|
||||
@@ -295,6 +294,7 @@ void utun_instance_stop(struct UTUN_INSTANCE *instance);
|
||||
/* Глобальные переключатели создания TUN/топологии для тестов и встраивания. */
|
||||
void utun_instance_set_tun_init_enabled(int enabled);
|
||||
void utun_instance_set_topo_group_enabled(int enabled);
|
||||
/* Состояние активности клиента сохраняется до следующего явного вызова; выполнять в uasync-потоке. */
|
||||
void utun_set_client_activity(struct UTUN_INSTANCE* instance, int active);
|
||||
void utun_add_activity_cbk(struct UTUN_INSTANCE* instance, utun_activity_cbk_fn fn, void* arg);
|
||||
void utun_remove_activity_cbk(struct UTUN_INSTANCE* instance, utun_activity_cbk_fn fn, void* arg);
|
||||
|
||||
Reference in new issue
Block a user