Languages

Menu
Sites
Language
System events: Turning Wifi off triggers SYSTEM_EVENT_WIFI_STATE with EVENT_VAL_WIFI_ON

Hi there,

I'm working on a native C service application for wearables with API version 4.0.

I found a strange behaviour of the system event EVENT_KEY_WIFI_STATE.
When I disconnect from WIFI the subscribe_wifi_state_callback is called twice.
In the first subscribe_wifi_state_callback the log prints EVENT_VAL_WIFI_ON. (This is unexpected and shouldn't be triggered!)
In the second subscribe_wifi_state_callback the log prints EVENT_VAL_WIFI_OFF.
When I connect again the subscribe_wifi_state_callback is called once and the log prints "EVENT_VAL_WIFI_ON".

I'm out of ideas and hope someone can help. Thanks

To reproduce the issue, I included a code snippet. You can simply copy this as e.g. service.c in the service template

 

#include <tizen.h>
#include <service_app.h>
#include "service2.h"
#include <bundle.h>
#include <app_control.h>
#include <app_event.h>
#include <dlog.h>

#define TAG "ZZZZZZZEAS"

void subscribe_wifi_state_callback(const char *event_name, bundle *event_data, void *user_data){
    char *value;

    int ret = bundle_get_str(event_data, EVENT_KEY_WIFI_STATE, &value);
    dlog_print(DLOG_INFO, TAG, "bundle_get_str ret value: %d", ret);

    if(ret == BUNDLE_ERROR_NONE){
        dlog_print(DLOG_INFO, TAG, "subscribe_wifi_state_callback, Value: %s", value);
    }
}

bool service_app_create(void *data)
{
    //////////////////////// Register the event handler for Wifi state
    event_handler_h handler_wifi_state;

    int ret = event_add_event_handler(SYSTEM_EVENT_WIFI_STATE, subscribe_wifi_state_callback, NULL, &handler_wifi_state);
    dlog_print(DLOG_INFO, TAG, "event_add_event_handler SYSTEM_EVENT_WIFI_STATE ret value: [%d]", ret);

    if (ret != EVENT_ERROR_NONE){
        dlog_print(DLOG_ERROR, TAG, "event_add_event_handler SYSTEM_EVENT_WIFI_STATE err: [%d]", ret);
    }
    return true;
}

void service_app_terminate(void *data)
{
    // Todo: add your code here.
    return;
}

void service_app_control(app_control_h app_control, void *data)
{
    // Todo: add your code here.
    return;
}

static void
service_app_lang_changed(app_event_info_h event_info, void *user_data)
{
    /*APP_EVENT_LANGUAGE_CHANGED*/
    return;
}

static void
service_app_region_changed(app_event_info_h event_info, void *user_data)
{
    /*APP_EVENT_REGION_FORMAT_CHANGED*/
}

static void
service_app_low_battery(app_event_info_h event_info, void *user_data)
{
    /*APP_EVENT_LOW_BATTERY*/
}

static void
service_app_low_memory(app_event_info_h event_info, void *user_data)
{
    /*APP_EVENT_LOW_MEMORY*/
}

int main(int argc, char* argv[])
{
    char ad[50] = {0,};
    service_app_lifecycle_callback_s event_callback;
    app_event_handler_h handlers[5] = {NULL, };

    event_callback.create = service_app_create;
    event_callback.terminate = service_app_terminate;
    event_callback.app_control = service_app_control;

    service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
    service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
    service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
    service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);

    return service_app_main(argc, argv, &event_callback, ad);
}