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>
37 #include <app_control_internal.h>
38 #include <notification.h>
39 #include <notification_internal.h>
40 #include <notification_text_domain.h>
41 #include <bundle_internal.h>
43 #include <wifi-direct.h>
46 #include "wfd-app-util.h"
48 char *wfd_app_trim_path(const char *filewithpath)
51 char *filename = NULL;
52 if ((filename = strrchr(filewithpath, '/')) == NULL)
53 return (char *) filewithpath;
55 return (filename + 1);
57 static char *filename[100];
60 const char *space = " ";
61 int len = strlen(filewithpath);
64 strptr = (char *) filewithpath + (len - 20);
66 } else if (len < 20) {
67 strptr = (char *) filewithpath;
71 strncpy((char *) filename, space, strlen(space));
72 strncpy((char *) filename + start, strptr, 50);
74 return (char *) filename;
82 return syscall(__NR_gettid);
84 fprintf(stderr, "__NR_gettid is not defined, please include linux/unistd.h ");
89 static void __launch_app_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *data)
91 __WFD_APP_FUNC_ENTER__;
93 if(result == APP_CONTROL_RESULT_FAILED) {
94 WFD_APP_LOG(WFD_APP_LOG_ERROR, "User cancel to reconnect screen mirroring\n");
95 #ifdef WFD_SCREEN_MIRRORING_ENABLED
96 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
99 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control launch result: [%d]\n", result);
102 __WFD_APP_FUNC_EXIT__;
105 static void _move_data_to_app_control(const char *key, const char *val, void *data)
107 __WFD_APP_FUNC_ENTER__;
109 WFD_RET_IF(data == NULL || key == NULL || val == NULL, , "Invialid parameter!");
111 app_control_h control = data;
112 app_control_add_extra_data(control, key, val);
114 __WFD_APP_FUNC_EXIT__;
117 static void _launch_app(char *app_id, void *data)
119 __WFD_APP_FUNC_ENTER__;
120 WFD_RET_IF(app_id == NULL || data == NULL, "Invialid parameter!");
122 int ret = APP_CONTROL_ERROR_NONE;
123 app_control_h control = NULL;
124 ret = app_control_create(&control);
125 if (ret != APP_CONTROL_ERROR_NONE) {
126 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_create() return error : %d", ret);
129 WFD_RET_IF(control == NULL, "Failed to create app_control handle!");
131 app_control_set_operation(control, APP_CONTROL_OPERATION_DEFAULT);
132 app_control_set_app_id(control, app_id);
133 bundle_iterate((bundle *)data, _move_data_to_app_control, control);
135 char *launch_type = (char*)bundle_get_val(data, "-t");
136 if (!strcmp(launch_type, "reconnect_by_connecting_wifi_ap")) {
137 ret = app_control_send_launch_request(control, __launch_app_result_cb, NULL);
139 ret = app_control_send_launch_request(control, NULL, NULL);
142 if (ret != APP_CONTROL_ERROR_NONE) {
143 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
144 app_control_destroy(control);
147 app_control_destroy(control);
149 __WFD_APP_FUNC_EXIT__;
153 #ifdef WFD_SCREEN_MIRRORING_ENABLED
154 void _add_screen_mirroring_activated_indicator(void *user_data)
156 __WFD_APP_FUNC_ENTER__;
157 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
158 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
159 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
161 if (ad->noti_screen_mirroring_play) {
162 notification_delete(ad->noti_screen_mirroring_play);
163 notification_free(ad->noti_screen_mirroring_play);
164 ad->noti_screen_mirroring_play = NULL;
167 if(ad->noti_screen_mirroring_on != NULL) {
168 noti_err = notification_free(ad->noti_screen_mirroring_on);
169 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
172 ad->noti_screen_mirroring_on = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
173 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
175 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
176 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
178 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
179 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
181 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
182 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
184 /* notify the quick panel */
185 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
186 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
188 __WFD_APP_FUNC_EXIT__;
194 #ifdef WFD_SCREEN_MIRRORING_ENABLED
196 * This function let the app add the notification when it is connected
198 * @param[in] user_data the pointer to the main data structure
200 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
202 __WFD_APP_FUNC_ENTER__;
204 int res = NOTIFICATION_ERROR_NONE;
205 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
206 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
208 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
210 if (ad->noti_screen_mirroring_on) {
211 notification_delete(ad->noti_screen_mirroring_on);
212 notification_free(ad->noti_screen_mirroring_on);
213 ad->noti_screen_mirroring_on = NULL;
216 if(ad->noti_screen_mirroring_play != NULL) {
217 noti_err = notification_free(ad->noti_screen_mirroring_play);
218 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
221 ad->noti_screen_mirroring_play = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
222 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
224 char msg[WFD_MAX_SIZE] = {0};
227 app_control_h control;
228 res = app_control_create(&control);
229 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
231 app_control_set_package(control, package_name);
232 app_control_add_extra_data(control, "-t", "notification");
233 res = app_control_to_bundle(control, &b);
234 if (res != APP_CONTROL_ERROR_NONE) {
235 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_to_bundle() return error : %d", res);
236 app_control_destroy(control);
240 res = notification_set_execute_option(ad->noti_screen_mirroring_play, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
241 if (res != NOTIFICATION_ERROR_NONE) {
242 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_execute_option. [%d]", res);
243 app_control_destroy(control);
247 app_control_destroy(control);
249 noti_err = notification_set_layout(ad->noti_screen_mirroring_play, NOTIFICATION_LY_ONGOING_EVENT);
250 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
253 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON, SCREEN_MIRRIONG_NOTI_ICON_PATH);
254 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
256 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_PLAY_ICON_PATH);
257 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
259 /* set the title and content */
260 wfd_app_get_connected_peers(ad);
261 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_TITLE, _("IDS_SMR_BODY_SCREEN_MIRRORING_IS_ENABLED"),
262 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
263 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
265 snprintf(msg, WFD_MAX_SIZE, _("IDS_WIFI_BODY_CONNECTED_TO_PS"), ad->raw_connected_peers[0].ssid);
266 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_CONTENT,
267 msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
268 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
271 notification_set_property(ad->noti_screen_mirroring_play, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
273 /* notify the quick panel */
274 noti_err = notification_insert(ad->noti_screen_mirroring_play, NULL);
275 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
277 __WFD_APP_FUNC_EXIT__;
283 * This function let the app make a change callback for flight mode
285 * @param[in] key the pointer to the key
286 * @param[in] user_data the pointer to the main data structure
288 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
290 __WFD_APP_FUNC_ENTER__;
293 #ifdef WFD_SCREEN_MIRRORING_ENABLED
294 int screen_mirroring_status = 0;
296 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
297 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
299 res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
301 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get flight state from vconf. [%d]\n", res);
305 if (flight_mode == FALSE) {
306 WFD_APP_LOG(WFD_APP_LOG_LOW, "Flight mode is off\n");
310 /* If flight mode is on, turn off WFD */
311 wifi_direct_get_state(&ad->wfd_status);
312 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
313 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is deactivated.\n");
317 /* If connected, disconnect all devices*/
318 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
319 res = wifi_direct_disconnect_all();
320 if (res != WIFI_DIRECT_ERROR_NONE) {
321 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to send disconnection request to all. [%d]\n", res);
326 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deactivating WiFi DIrect..."
327 "Due to Flight Mode is Enabled\n");
328 res = wifi_direct_deactivate();
329 if (res != WIFI_DIRECT_ERROR_NONE) {
330 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
334 #ifdef WFD_SCREEN_MIRRORING_ENABLED
335 /* checking Screen Mirroring */
336 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
338 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
340 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
342 if(screen_mirroring_status > VCONFKEY_SCREEN_MIRRORING_DEACTIVATED) {
343 res = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
345 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
350 __WFD_APP_FUNC_EXIT__;
353 static void _wfd_cpu_limit_mode_changed(keynode_t *node, void *user_data)
355 __WFD_APP_FUNC_ENTER__;
356 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
357 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
359 int screen_mirroring_status = 0;
360 int cup_limit_mode = 0;
362 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
363 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
367 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
368 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
372 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
373 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
377 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
379 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
383 if ((power_mode == SETTING_PSMODE_POWERFUL || power_mode == SETTING_PSMODE_ADVISOR) &&
387 bundle_add(b, "-t", "notification_power_saving_on");
388 _launch_app(PACKAGE_ALLSHARE_CAST, b);
392 __WFD_APP_FUNC_EXIT__;
396 static void _wfd_power_saving_mode_changed(keynode_t *node, void *user_data)
398 __WFD_APP_FUNC_ENTER__;
399 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
400 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
402 int screen_mirroring_status = 0;
403 int cup_limit_mode = 0;
405 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
406 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
410 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
411 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
415 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
417 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
421 if (power_mode == SETTING_PSMODE_SURVIVAL ||
422 power_mode == SETTING_PSMODE_EMERGENCY) {
423 WFD_APP_LOG(WFD_APP_LOG_LOW, "Ultra power saving mode on\n");
426 bundle_add(b, "-t", "quit_by_ultra_power_saving_on");
428 _launch_app(PACKAGE_ALLSHARE_CAST, b);
430 } else if (power_mode == SETTING_PSMODE_POWERFUL ||
431 power_mode == SETTING_PSMODE_ADVISOR){
432 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
433 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
437 if (cup_limit_mode) {
440 bundle_add(b, "-t", "notification_power_saving_on");
441 _launch_app(PACKAGE_ALLSHARE_CAST, b);
446 __WFD_APP_FUNC_EXIT__;
450 static void _wfd_wifi_status_changed(keynode_t *node, void *user_data)
452 __WFD_APP_FUNC_ENTER__;
453 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
454 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
456 #ifdef WFD_SCREEN_MIRRORING_ENABLED
457 int screen_mirroring_status = 0;
459 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
460 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
464 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
465 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
470 if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0)
472 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_WIFI_STATE\n");
476 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
477 if (wifi_status == VCONFKEY_WIFI_CONNECTED) {
478 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi is connected\n");
479 #ifdef WFD_SCREEN_MIRRORING_ENABLED
480 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP;
483 bundle_add(b, "-t", "reconnect_by_connecting_wifi_ap");
485 _launch_app(PACKAGE_ALLSHARE_CAST, b);
488 } else if (VCONFKEY_WIFI_OFF == wifi_status) {
489 /* Deactivate WiFi Direct */
490 WFD_APP_LOG(WFD_APP_LOG_LOW, "Deactivate WiFi Direct...");
493 * Currently, WiFi Direct OFF is handled at net-config.
494 * Also, this patch is added to support ON-DEMAND launch destroy popup.
495 * This patch will handle 5sec deadlock of popup destory from
498 /* wfd_app_client_switch_off(ad); */
500 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
503 __WFD_APP_FUNC_EXIT__;
507 #ifdef WFD_SCREEN_MIRRORING_ENABLED
509 * This function let the app make a change callback for allshare cast
511 * @param[in] key the pointer to the key
512 * @param[in] user_data the pointer to the main data structure
514 static void _wfd_allshare_cast_status_changed(keynode_t *node, void *user_data)
516 __WFD_APP_FUNC_ENTER__;
518 int screen_mirroring_status = 0;
519 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
520 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
522 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
524 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
527 WFD_APP_LOG(WFD_APP_LOG_ERROR, "VCONFKEY_SCREEN_MIRRORING_STATE:%d\n", screen_mirroring_status);
529 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
530 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is connected\n");
531 if (ad->transmit_timer) {
532 ecore_timer_del(ad->transmit_timer);
533 ad->transmit_timer = NULL;
535 /* add connected notification */
536 _add_wfd_peers_connected_notification(ad, PACKAGE_ALLSHARE_CAST);
537 } else if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
538 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is ACTIVATED\n");
539 _add_screen_mirroring_activated_indicator(ad);
541 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
542 if (ad->noti_screen_mirroring_on) {
543 notification_delete(ad->noti_screen_mirroring_on);
544 notification_free(ad->noti_screen_mirroring_on);
545 ad->noti_screen_mirroring_on = NULL;
548 if (ad->noti_screen_mirroring_play) {
549 notification_delete(ad->noti_screen_mirroring_play);
550 notification_free(ad->noti_screen_mirroring_play);
551 ad->noti_screen_mirroring_play = NULL;
557 __WFD_APP_FUNC_EXIT__;
561 static Eina_Bool _wfd_hard_key_down_cb(void *data, int type, void *event)
563 wfd_appdata_t *ad = (wfd_appdata_t *)data;
564 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
567 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Hard Key Pressed CB...");
568 if (NULL == ad || NULL == ev) {
569 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
573 if (!strcmp(ev->keyname, KEY_SELECT)) {
574 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY]KEY_SELECT pressed");
575 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Mac : %s", ad->mac_addr_connecting);
577 if (strnlen(ad->mac_addr_connecting, MACSTR_LENGTH) > 0) {
578 res = wifi_direct_reject_connection(ad->mac_addr_connecting);
579 if (res != WIFI_DIRECT_ERROR_NONE) {
580 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", res);
583 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
586 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY][%s] pressed not Handled",
593 int wfd_app_util_register_hard_key_down_cb(void *data)
595 wfd_appdata_t *ad = (wfd_appdata_t *)data;
598 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
602 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Register hard key down press CB !!!");
603 if (NULL == ad->downkey_handler)
604 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
605 _wfd_hard_key_down_cb, ad);
610 int wfd_app_util_deregister_hard_key_down_cb(void *data)
612 wfd_appdata_t *ad = (wfd_appdata_t *)data;
615 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
618 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deregister hard key down press CB !!!");
619 if (NULL != ad->downkey_handler) {
620 ecore_event_handler_del(ad->downkey_handler);
621 ad->downkey_handler = NULL;
626 int wfd_app_util_register_vconf_callbacks(void *data)
628 wfd_appdata_t *ad = NULL;
632 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid parameter");
638 /* register flight mode */
639 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
640 _wfd_flight_mode_changed, ad);
642 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for flight mode\n");
646 #ifdef WFD_SCREEN_MIRRORING_ENABLED
648 /* TODO: Make proper changes for vconfkey */
649 ret = vconf_notify_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE,
650 _wfd_allshare_cast_status_changed, ad);
652 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for allshare cast\n");
658 ret = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed, ad);
660 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for wifi\n");
665 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed, ad);
667 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for power mode\n");
672 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed, ad);
674 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for cpu limit mode\n");
681 int wfd_app_util_deregister_vconf_callbacks(void *data)
685 /* remove callback for flight mode */
686 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _wfd_flight_mode_changed);
688 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for flight mode\n");
691 #ifdef WFD_SCREEN_MIRRORING_ENABLED
692 /* remove callback for allshare cast */
693 ret = vconf_ignore_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE, _wfd_allshare_cast_status_changed);
695 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for allshare cast\n");
699 /* remove callback for wifi */
700 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed);
702 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for wifi\n");
705 /* remove callback for power mode */
706 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed);
708 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for power mode\n");
711 /* remove callback for cpu limit mode */
712 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed);
714 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for cpu limit mode\n");
721 * This function let the app delete the notification
724 void wfd_app_util_del_notification(wfd_appdata_t *ad)
726 __WFD_APP_FUNC_ENTER__;
727 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
729 /* delete the notification */
730 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
732 noti_err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
733 if (noti_err != NOTIFICATION_ERROR_NONE) {
734 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all_by_type.(%d)\n", noti_err);
738 #ifdef WFD_SCREEN_MIRRORING_ENABLED
739 if (ad->noti_screen_mirroring_on) {
740 noti_err = notification_free(ad->noti_screen_mirroring_on);
741 ad->noti_screen_mirroring_on = NULL;
742 if (noti_err != NOTIFICATION_ERROR_NONE) {
743 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
747 if (ad->noti_screen_mirroring_play) {
748 noti_err = notification_free(ad->noti_screen_mirroring_play);
749 ad->noti_screen_mirroring_play = NULL;
750 if (noti_err != NOTIFICATION_ERROR_NONE) {
751 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
756 #ifdef NOT_CONNECTED_INDICATOR_ICON
757 if (ad->noti_wifi_direct_on) {
758 noti_err = notification_free(ad->noti_wifi_direct_on);
759 ad->noti_wifi_direct_on = NULL;
760 if (noti_err != NOTIFICATION_ERROR_NONE) {
761 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
766 if (ad->noti_wifi_direct_connected) {
767 noti_err = notification_free(ad->noti_wifi_direct_connected);
768 ad->noti_wifi_direct_connected = NULL;
769 if (noti_err != NOTIFICATION_ERROR_NONE) {
770 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
774 __WFD_APP_FUNC_EXIT__;
778 #ifdef NOT_CONNECTED_INDICATOR_ICON
780 * This function let the app add the indicator icon when wfd is activated
782 * @param[in] user_data the pointer to the main data structure
784 void wfd_app_util_add_indicator_icon(void *user_data)
786 __WFD_APP_FUNC_ENTER__;
787 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
788 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
789 WFD_RET_IF(ad->noti_wifi_direct_on, "Indicator already exists");
791 if(ad->noti_wifi_direct_on != NULL) {
792 noti_err = notification_free(ad->noti_wifi_direct_on);
793 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
796 ad->noti_wifi_direct_on = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
797 WFD_RET_IF(NULL == ad->noti_wifi_direct_on, "NULL parameters.\n");
799 noti_err = notification_set_image(ad->noti_wifi_direct_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, WFD_ACTIVATED_NOTI_ICON_PATH);
800 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
802 noti_err = notification_set_property(ad->noti_wifi_direct_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
803 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
805 noti_err = notification_set_display_applist(ad->noti_wifi_direct_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
806 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
808 /* notify the quick panel */
809 noti_err = notification_insert(ad->noti_wifi_direct_on, NULL);
810 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
812 __WFD_APP_FUNC_EXIT__;
817 #ifdef WFD_SCREEN_MIRRORING_ENABLED
819 * This function let the app set VCONFKEY_SCREEN_MIRRORING_STATE to be DEACTIVATED
821 void wfd_app_util_set_screen_mirroring_deactivated(wfd_appdata_t *ad)
823 __WFD_APP_FUNC_ENTER__;
824 WFD_RET_IF(NULL == ad, "NULL == ad!\n");
825 int screen_mirroring_status = -1;
828 /* Reconnect by ap connected, no need to set vconf to DEACTIVATED, allshare cast itself will set ACTIVATED*/
829 if (ad->screen_mirroring_state == WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP) {
830 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
831 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Reconnect screen mirroring by app connected.\n");
835 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
836 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
839 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
840 /* Set the vconf value to DEACTIVATED only when the previous vconf value is CONNECTED.
841 If the previous vconf value is ACTIVATED, it means that the Screen Mirroring UG changed that key already. So no need to change it. */
842 if(screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
843 result = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
845 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
847 notification_status_message_post(_("IDS_SMR_POP_SCREEN_MIRRORING_HAS_BEEN_DISABLED"));
850 __WFD_APP_FUNC_EXIT__;
854 * This function let the app add the notification when it shoule be turned off
856 * @param[in] user_data the pointer to the main data structure
858 void wfd_app_util_add_wfd_turn_off_notification(void *user_data)
860 __WFD_APP_FUNC_ENTER__;
862 int res = NOTIFICATION_ERROR_NONE;
863 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
864 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
866 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
868 /* delete all notifications */
869 wfd_app_util_del_notification(ad);
871 if(ad->noti_wifi_direct_connected!= NULL) {
872 noti_err = notification_free(ad->noti_wifi_direct_connected);
873 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
876 ad->noti_wifi_direct_connected = (notification_h) notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
877 WFD_RET_IF(NULL == ad->noti_wifi_direct_connected, "NULL parameters.\n");
880 app_control_h control;
881 res = app_control_create(&control);
882 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
884 app_control_set_package(control, PACKAGE);
885 app_control_add_extra_data(control, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
886 res = app_control_to_bundle(control, &b);
887 if (res != APP_CONTROL_ERROR_NONE) {
888 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_to_bundle() return error : %d", res);
889 app_control_destroy(control);
893 noti_err = notification_set_execute_option(ad->noti_wifi_direct_connected, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
894 if (noti_err != NOTIFICATION_ERROR_NONE) {
895 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_execute_option. [%d]", noti_err);
896 app_control_destroy(control);
900 app_control_destroy(control);
902 noti_err = notification_set_layout(ad->noti_wifi_direct_connected, NOTIFICATION_LY_ONGOING_EVENT);
903 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
906 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Icon Path: %s\n", WFD_NOTI_ICON_PATH);
907 noti_err = notification_set_image(ad->noti_wifi_direct_connected, NOTIFICATION_IMAGE_TYPE_ICON, WFD_NOTI_ICON_PATH);
908 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
910 noti_err = notification_set_display_applist(ad->noti_wifi_direct_connected, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
911 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
913 noti_err = notification_set_text_domain(ad->noti_wifi_direct_connected, LOCALE_FILE_NAME, LOCALEDIR);
914 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text_domain. [%d]", noti_err);
916 /* set the title and content */
917 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_TITLE,
918 _("IDS_WIFI_BODY_WI_FI_DIRECT_ABB"), "IDS_WIFI_BODY_WI_FI_DIRECT_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
919 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
921 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_CONTENT,
922 _("IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB"),
923 "IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
924 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
926 /* notify the quick panel */
927 noti_err = notification_insert(ad->noti_wifi_direct_connected, NULL);
928 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
930 __WFD_APP_FUNC_EXIT__;
935 void wfd_app_util_del_wfd_connected_notification(wfd_appdata_t *ad)
937 __WFD_APP_FUNC_ENTER__;
938 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
940 /* delete the notification */
941 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
943 noti_err = notification_delete(ad->noti_wifi_direct_connected);
944 if (noti_err != NOTIFICATION_ERROR_NONE) {
945 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
949 if (ad->noti_wifi_direct_connected) {
950 noti_err = notification_free(ad->noti_wifi_direct_connected);
951 ad->noti_wifi_direct_connected = NULL;
952 if (noti_err != NOTIFICATION_ERROR_NONE) {
953 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
957 __WFD_APP_FUNC_EXIT__;