4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file implements wifi direct application utils functions.
23 * @file wfd-app-util.c
24 * @author Sungsik Jang (sungsik.jang@samsung.com)
28 #include <linux/unistd.h>
32 #include <Elementary.h>
35 #include <app_control.h>
36 #include <notification.h>
37 #include <notification_internal.h>
39 #include <wifi-direct.h>
42 #include "wfd-app-util.h"
44 char *wfd_app_trim_path(const char *filewithpath)
47 char *filename = NULL;
48 if ((filename = strrchr(filewithpath, '/')) == NULL)
49 return (char *) filewithpath;
51 return (filename + 1);
53 static char *filename[100];
56 const char *space = " ";
57 int len = strlen(filewithpath);
60 strptr = (char *) filewithpath + (len - 20);
62 } else if (len < 20) {
63 strptr = (char *) filewithpath;
67 strncpy((char *) filename, space, strlen(space));
68 strncpy((char *) filename + start, strptr, 50);
70 return (char *) filename;
78 return syscall(__NR_gettid);
80 fprintf(stderr, "__NR_gettid is not defined, please include linux/unistd.h ");
85 static void __launch_app_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *data)
87 __WFD_APP_FUNC_ENTER__;
89 if(result == APP_CONTROL_RESULT_FAILED) {
90 WFD_APP_LOG(WFD_APP_LOG_ERROR, "User cancel to reconnect screen mirroring\n");
91 #ifdef WFD_SCREEN_MIRRORING_ENABLED
92 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
95 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control launch result: [%d]\n", result);
98 __WFD_APP_FUNC_EXIT__;
101 static void _move_data_to_app_control(const char *key, const char *val, void *data)
103 __WFD_APP_FUNC_ENTER__;
105 WFD_RET_IF(data == NULL || key == NULL || val == NULL, , "Invialid parameter!");
107 app_control_h control = data;
108 app_control_add_extra_data(control, key, val);
110 __WFD_APP_FUNC_EXIT__;
113 static void _launch_app(char *app_id, void *data)
115 __WFD_APP_FUNC_ENTER__;
116 WFD_RET_IF(app_id == NULL || data == NULL, "Invialid parameter!");
118 int ret = APP_CONTROL_ERROR_NONE;
119 app_control_h control = NULL;
120 ret = app_control_create(&control);
121 if (ret != APP_CONTROL_ERROR_NONE) {
122 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_create() return error : %d", ret);
125 WFD_RET_IF(control == NULL, "Failed to create app_control handle!");
127 app_control_set_operation(control, APP_CONTROL_OPERATION_DEFAULT);
128 app_control_set_app_id(control, app_id);
129 bundle_iterate((bundle *)data, _move_data_to_app_control, control);
131 char *launch_type = (char*)bundle_get_val(data, "-t");
132 if (!strcmp(launch_type, "reconnect_by_connecting_wifi_ap")) {
133 ret = app_control_send_launch_request(control, __launch_app_result_cb, NULL);
135 ret = app_control_send_launch_request(control, NULL, NULL);
138 if (ret != APP_CONTROL_ERROR_NONE) {
139 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
140 app_control_destroy(control);
143 app_control_destroy(control);
145 __WFD_APP_FUNC_EXIT__;
149 #ifdef WFD_SCREEN_MIRRORING_ENABLED
150 void _add_screen_mirroring_activated_indicator(void *user_data)
152 __WFD_APP_FUNC_ENTER__;
153 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
154 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
155 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
157 if (ad->noti_screen_mirroring_play) {
158 notification_delete(ad->noti_screen_mirroring_play);
159 notification_free(ad->noti_screen_mirroring_play);
160 ad->noti_screen_mirroring_play = NULL;
163 if(ad->noti_screen_mirroring_on != NULL) {
164 noti_err = notification_free(ad->noti_screen_mirroring_on);
165 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
168 ad->noti_screen_mirroring_on = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
169 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
171 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
172 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
174 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
175 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
177 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
178 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
180 /* notify the quick panel */
181 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
182 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
184 __WFD_APP_FUNC_EXIT__;
190 #ifdef WFD_SCREEN_MIRRORING_ENABLED
192 * This function let the app add the notification when it is connected
194 * @param[in] user_data the pointer to the main data structure
196 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
198 __WFD_APP_FUNC_ENTER__;
200 int res = NOTIFICATION_ERROR_NONE;
201 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
202 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
204 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
206 if (ad->noti_screen_mirroring_on) {
207 notification_delete(ad->noti_screen_mirroring_on);
208 notification_free(ad->noti_screen_mirroring_on);
209 ad->noti_screen_mirroring_on = NULL;
212 if(ad->noti_screen_mirroring_play != NULL) {
213 noti_err = notification_free(ad->noti_screen_mirroring_play);
214 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
217 ad->noti_screen_mirroring_play = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
218 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
220 char msg[WFD_MAX_SIZE] = {0};
223 app_control_h control;
224 res = app_control_create(&control);
225 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
227 app_control_set_package(control, package_name);
228 app_control_add_extra_data(control, "-t", "notification");
229 res = app_control_to_bundle(control, &b);
230 if (res != APP_CONTROL_ERROR_NONE) {
231 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_to_bundle() return error : %d", res);
232 app_control_destroy(control);
236 res = notification_set_execute_option(ad->noti_screen_mirroring_play, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
237 if (res != NOTIFICATION_ERROR_NONE) {
238 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_execute_option. [%d]", res);
239 app_control_destroy(control);
243 app_control_destroy(control);
245 noti_err = notification_set_layout(ad->noti_screen_mirroring_play, NOTIFICATION_LY_ONGOING_EVENT);
246 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
249 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON, SCREEN_MIRRIONG_NOTI_ICON_PATH);
250 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
252 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_PLAY_ICON_PATH);
253 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
255 /* set the title and content */
256 wfd_app_get_connected_peers(ad);
257 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_TITLE, _("IDS_SMR_BODY_SCREEN_MIRRORING_IS_ENABLED"),
258 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
259 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
261 snprintf(msg, WFD_MAX_SIZE, _("IDS_WIFI_BODY_CONNECTED_TO_PS"), ad->raw_connected_peers[0].ssid);
262 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_CONTENT,
263 msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
264 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
267 notification_set_property(ad->noti_screen_mirroring_play, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
269 /* notify the quick panel */
270 noti_err = notification_insert(ad->noti_screen_mirroring_play, NULL);
271 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
273 __WFD_APP_FUNC_EXIT__;
279 * This function let the app make a change callback for flight mode
281 * @param[in] key the pointer to the key
282 * @param[in] user_data the pointer to the main data structure
284 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
286 __WFD_APP_FUNC_ENTER__;
289 #ifdef WFD_SCREEN_MIRRORING_ENABLED
290 int screen_mirroring_status = 0;
292 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
293 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
295 res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
297 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get flight state from vconf. [%d]\n", res);
301 if (flight_mode == FALSE) {
302 WFD_APP_LOG(WFD_APP_LOG_LOW, "Flight mode is off\n");
306 /* If flight mode is on, turn off WFD */
307 wifi_direct_get_state(&ad->wfd_status);
308 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
309 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is deactivated.\n");
313 /* If connected, disconnect all devices*/
314 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
315 res = wifi_direct_disconnect_all();
316 if (res != WIFI_DIRECT_ERROR_NONE) {
317 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to send disconnection request to all. [%d]\n", res);
322 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deactivating WiFi DIrect..."
323 "Due to Flight Mode is Enabled\n");
324 res = wifi_direct_deactivate();
325 if (res != WIFI_DIRECT_ERROR_NONE) {
326 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
330 #ifdef WFD_SCREEN_MIRRORING_ENABLED
331 /* checking Screen Mirroring */
332 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
334 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
336 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
338 if(screen_mirroring_status > VCONFKEY_SCREEN_MIRRORING_DEACTIVATED) {
339 res = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
341 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
346 __WFD_APP_FUNC_EXIT__;
349 static void _wfd_cpu_limit_mode_changed(keynode_t *node, void *user_data)
351 __WFD_APP_FUNC_ENTER__;
352 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
353 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
355 int screen_mirroring_status = 0;
356 int cup_limit_mode = 0;
358 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
359 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
363 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
364 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
368 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
369 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
373 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
375 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
379 if ((power_mode == SETTING_PSMODE_POWERFUL || power_mode == SETTING_PSMODE_ADVISOR) &&
383 bundle_add(b, "-t", "notification_power_saving_on");
384 _launch_app(PACKAGE_ALLSHARE_CAST, b);
388 __WFD_APP_FUNC_EXIT__;
392 static void _wfd_power_saving_mode_changed(keynode_t *node, void *user_data)
394 __WFD_APP_FUNC_ENTER__;
395 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
396 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
398 int screen_mirroring_status = 0;
399 int cup_limit_mode = 0;
401 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
402 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
406 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
407 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
411 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
413 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
417 if (power_mode == SETTING_PSMODE_SURVIVAL ||
418 power_mode == SETTING_PSMODE_EMERGENCY) {
419 WFD_APP_LOG(WFD_APP_LOG_LOW, "Ultra power saving mode on\n");
422 bundle_add(b, "-t", "quit_by_ultra_power_saving_on");
424 _launch_app(PACKAGE_ALLSHARE_CAST, b);
426 } else if (power_mode == SETTING_PSMODE_POWERFUL ||
427 power_mode == SETTING_PSMODE_ADVISOR){
428 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
429 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
433 if (cup_limit_mode) {
436 bundle_add(b, "-t", "notification_power_saving_on");
437 _launch_app(PACKAGE_ALLSHARE_CAST, b);
442 __WFD_APP_FUNC_EXIT__;
446 static void _wfd_wifi_status_changed(keynode_t *node, void *user_data)
448 __WFD_APP_FUNC_ENTER__;
449 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
450 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
452 #ifdef WFD_SCREEN_MIRRORING_ENABLED
453 int screen_mirroring_status = 0;
455 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
456 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
460 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
461 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
466 if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0)
468 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_WIFI_STATE\n");
472 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
473 if (wifi_status == VCONFKEY_WIFI_CONNECTED) {
474 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi is connected\n");
475 #ifdef WFD_SCREEN_MIRRORING_ENABLED
476 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP;
479 bundle_add(b, "-t", "reconnect_by_connecting_wifi_ap");
481 _launch_app(PACKAGE_ALLSHARE_CAST, b);
484 } else if (VCONFKEY_WIFI_OFF == wifi_status) {
485 /* Deactivate WiFi Direct */
486 WFD_APP_LOG(WFD_APP_LOG_LOW, "Deactivate WiFi Direct...");
489 * Currently, WiFi Direct OFF is handled at net-config.
490 * Also, this patch is added to support ON-DEMAND launch destroy popup.
491 * This patch will handle 5sec deadlock of popup destory from
494 /* wfd_app_client_switch_off(ad); */
496 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
499 __WFD_APP_FUNC_EXIT__;
503 #ifdef WFD_SCREEN_MIRRORING_ENABLED
505 * This function let the app make a change callback for allshare cast
507 * @param[in] key the pointer to the key
508 * @param[in] user_data the pointer to the main data structure
510 static void _wfd_allshare_cast_status_changed(keynode_t *node, void *user_data)
512 __WFD_APP_FUNC_ENTER__;
514 int screen_mirroring_status = 0;
515 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
516 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
518 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
520 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
523 WFD_APP_LOG(WFD_APP_LOG_ERROR, "VCONFKEY_SCREEN_MIRRORING_STATE:%d\n", screen_mirroring_status);
525 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
526 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is connected\n");
527 if (ad->transmit_timer) {
528 ecore_timer_del(ad->transmit_timer);
529 ad->transmit_timer = NULL;
531 /* add connected notification */
532 _add_wfd_peers_connected_notification(ad, PACKAGE_ALLSHARE_CAST);
533 } else if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
534 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is ACTIVATED\n");
535 _add_screen_mirroring_activated_indicator(ad);
537 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
538 if (ad->noti_screen_mirroring_on) {
539 notification_delete(ad->noti_screen_mirroring_on);
540 notification_free(ad->noti_screen_mirroring_on);
541 ad->noti_screen_mirroring_on = NULL;
544 if (ad->noti_screen_mirroring_play) {
545 notification_delete(ad->noti_screen_mirroring_play);
546 notification_free(ad->noti_screen_mirroring_play);
547 ad->noti_screen_mirroring_play = NULL;
553 __WFD_APP_FUNC_EXIT__;
557 static Eina_Bool _wfd_hard_key_down_cb(void *data, int type, void *event)
559 wfd_appdata_t *ad = (wfd_appdata_t *)data;
560 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
563 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Hard Key Pressed CB...");
564 if (NULL == ad || NULL == ev) {
565 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
569 if (!strcmp(ev->keyname, KEY_SELECT)) {
570 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY]KEY_SELECT pressed");
571 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Mac : %s", ad->mac_addr_connecting);
573 if (strnlen(ad->mac_addr_connecting, MACSTR_LENGTH) > 0) {
574 res = wifi_direct_reject_connection(ad->mac_addr_connecting);
575 if (res != WIFI_DIRECT_ERROR_NONE) {
576 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", res);
579 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
582 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY][%s] pressed not Handled",
589 int wfd_app_util_register_hard_key_down_cb(void *data)
591 wfd_appdata_t *ad = (wfd_appdata_t *)data;
594 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
598 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Register hard key down press CB !!!");
599 if (NULL == ad->downkey_handler)
600 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
601 _wfd_hard_key_down_cb, ad);
606 int wfd_app_util_deregister_hard_key_down_cb(void *data)
608 wfd_appdata_t *ad = (wfd_appdata_t *)data;
611 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
614 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deregister hard key down press CB !!!");
615 if (NULL != ad->downkey_handler) {
616 ecore_event_handler_del(ad->downkey_handler);
617 ad->downkey_handler = NULL;
622 int wfd_app_util_register_vconf_callbacks(void *data)
624 wfd_appdata_t *ad = NULL;
628 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid parameter");
634 /* register flight mode */
635 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
636 _wfd_flight_mode_changed, ad);
638 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for flight mode\n");
642 #ifdef WFD_SCREEN_MIRRORING_ENABLED
644 /* TODO: Make proper changes for vconfkey */
645 ret = vconf_notify_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE,
646 _wfd_allshare_cast_status_changed, ad);
648 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for allshare cast\n");
654 ret = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed, ad);
656 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for wifi\n");
661 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed, ad);
663 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for power mode\n");
668 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed, ad);
670 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for cpu limit mode\n");
677 int wfd_app_util_deregister_vconf_callbacks(void *data)
681 /* remove callback for flight mode */
682 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _wfd_flight_mode_changed);
684 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for flight mode\n");
687 #ifdef WFD_SCREEN_MIRRORING_ENABLED
688 /* remove callback for allshare cast */
689 ret = vconf_ignore_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE, _wfd_allshare_cast_status_changed);
691 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for allshare cast\n");
695 /* remove callback for wifi */
696 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed);
698 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for wifi\n");
701 /* remove callback for power mode */
702 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed);
704 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for power mode\n");
707 /* remove callback for cpu limit mode */
708 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed);
710 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for cpu limit mode\n");
717 * This function let the app delete the notification
720 void wfd_app_util_del_notification(wfd_appdata_t *ad)
722 __WFD_APP_FUNC_ENTER__;
723 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
725 /* delete the notification */
726 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
728 noti_err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
729 if (noti_err != NOTIFICATION_ERROR_NONE) {
730 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all_by_type.(%d)\n", noti_err);
734 #ifdef WFD_SCREEN_MIRRORING_ENABLED
735 if (ad->noti_screen_mirroring_on) {
736 noti_err = notification_free(ad->noti_screen_mirroring_on);
737 ad->noti_screen_mirroring_on = NULL;
738 if (noti_err != NOTIFICATION_ERROR_NONE) {
739 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
743 if (ad->noti_screen_mirroring_play) {
744 noti_err = notification_free(ad->noti_screen_mirroring_play);
745 ad->noti_screen_mirroring_play = NULL;
746 if (noti_err != NOTIFICATION_ERROR_NONE) {
747 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
752 #ifdef NOT_CONNECTED_INDICATOR_ICON
753 if (ad->noti_wifi_direct_on) {
754 noti_err = notification_free(ad->noti_wifi_direct_on);
755 ad->noti_wifi_direct_on = NULL;
756 if (noti_err != NOTIFICATION_ERROR_NONE) {
757 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
762 if (ad->noti_wifi_direct_connected) {
763 noti_err = notification_free(ad->noti_wifi_direct_connected);
764 ad->noti_wifi_direct_connected = NULL;
765 if (noti_err != NOTIFICATION_ERROR_NONE) {
766 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
770 __WFD_APP_FUNC_EXIT__;
774 #ifdef NOT_CONNECTED_INDICATOR_ICON
776 * This function let the app add the indicator icon when wfd is activated
778 * @param[in] user_data the pointer to the main data structure
780 void wfd_app_util_add_indicator_icon(void *user_data)
782 __WFD_APP_FUNC_ENTER__;
783 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
784 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
785 WFD_RET_IF(ad->noti_wifi_direct_on, "Indicator already exists");
787 if(ad->noti_wifi_direct_on != NULL) {
788 noti_err = notification_free(ad->noti_wifi_direct_on);
789 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
792 ad->noti_wifi_direct_on = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
793 WFD_RET_IF(NULL == ad->noti_wifi_direct_on, "NULL parameters.\n");
795 noti_err = notification_set_image(ad->noti_wifi_direct_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, WFD_ACTIVATED_NOTI_ICON_PATH);
796 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
798 noti_err = notification_set_property(ad->noti_wifi_direct_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
799 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
801 noti_err = notification_set_display_applist(ad->noti_wifi_direct_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
802 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
804 /* notify the quick panel */
805 noti_err = notification_insert(ad->noti_wifi_direct_on, NULL);
806 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
808 __WFD_APP_FUNC_EXIT__;
813 #ifdef WFD_SCREEN_MIRRORING_ENABLED
815 * This function let the app set VCONFKEY_SCREEN_MIRRORING_STATE to be DEACTIVATED
817 void wfd_app_util_set_screen_mirroring_deactivated(wfd_appdata_t *ad)
819 __WFD_APP_FUNC_ENTER__;
820 WFD_RET_IF(NULL == ad, "NULL == ad!\n");
821 int screen_mirroring_status = -1;
824 /* Reconnect by ap connected, no need to set vconf to DEACTIVATED, allshare cast itself will set ACTIVATED*/
825 if (ad->screen_mirroring_state == WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP) {
826 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
827 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Reconnect screen mirroring by app connected.\n");
831 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
832 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
835 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
836 /* Set the vconf value to DEACTIVATED only when the previous vconf value is CONNECTED.
837 If the previous vconf value is ACTIVATED, it means that the Screen Mirroring UG changed that key already. So no need to change it. */
838 if(screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
839 result = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
841 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
843 notification_status_message_post(_("IDS_SMR_POP_SCREEN_MIRRORING_HAS_BEEN_DISABLED"));
846 __WFD_APP_FUNC_EXIT__;
850 * This function let the app add the notification when it shoule be turned off
852 * @param[in] user_data the pointer to the main data structure
854 void wfd_app_util_add_wfd_turn_off_notification(void *user_data)
856 __WFD_APP_FUNC_ENTER__;
858 int res = NOTIFICATION_ERROR_NONE;
859 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
860 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
862 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
864 /* delete all notifications */
865 wfd_app_util_del_notification(ad);
867 if(ad->noti_wifi_direct_connected!= NULL) {
868 noti_err = notification_free(ad->noti_wifi_direct_connected);
869 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
872 ad->noti_wifi_direct_connected = (notification_h) notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
873 WFD_RET_IF(NULL == ad->noti_wifi_direct_connected, "NULL parameters.\n");
876 app_control_h control;
877 res = app_control_create(&control);
878 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
880 app_control_set_package(control, PACKAGE);
881 app_control_add_extra_data(control, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
882 res = app_control_to_bundle(control, &b);
883 if (res != APP_CONTROL_ERROR_NONE) {
884 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_to_bundle() return error : %d", res);
885 app_control_destroy(control);
889 noti_err = notification_set_execute_option(ad->noti_wifi_direct_connected, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
890 if (noti_err != NOTIFICATION_ERROR_NONE) {
891 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_execute_option. [%d]", noti_err);
892 app_control_destroy(control);
896 app_control_destroy(control);
898 noti_err = notification_set_layout(ad->noti_wifi_direct_connected, NOTIFICATION_LY_ONGOING_EVENT);
899 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
902 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Icon Path: %s\n", WFD_NOTI_ICON_PATH);
903 noti_err = notification_set_image(ad->noti_wifi_direct_connected, NOTIFICATION_IMAGE_TYPE_ICON, WFD_NOTI_ICON_PATH);
904 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
906 noti_err = notification_set_display_applist(ad->noti_wifi_direct_connected, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
907 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
909 noti_err = notification_set_text_domain(ad->noti_wifi_direct_connected, LOCALE_FILE_NAME, LOCALEDIR);
910 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text_domain. [%d]", noti_err);
912 /* set the title and content */
913 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_TITLE,
914 _("IDS_WIFI_BODY_WI_FI_DIRECT_ABB"), "IDS_WIFI_BODY_WI_FI_DIRECT_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
915 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
917 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_CONTENT,
918 _("IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB"),
919 "IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
920 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
922 /* notify the quick panel */
923 noti_err = notification_insert(ad->noti_wifi_direct_connected, NULL);
924 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
926 __WFD_APP_FUNC_EXIT__;
931 void wfd_app_util_del_wfd_connected_notification(wfd_appdata_t *ad)
933 __WFD_APP_FUNC_ENTER__;
934 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
936 /* delete the notification */
937 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
939 noti_err = notification_delete(ad->noti_wifi_direct_connected);
940 if (noti_err != NOTIFICATION_ERROR_NONE) {
941 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
945 if (ad->noti_wifi_direct_connected) {
946 noti_err = notification_free(ad->noti_wifi_direct_connected);
947 ad->noti_wifi_direct_connected = NULL;
948 if (noti_err != NOTIFICATION_ERROR_NONE) {
949 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
953 __WFD_APP_FUNC_EXIT__;