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>
34 #include <app_control_internal.h>
35 #include <notification.h>
36 #include <notification_internal.h>
37 #include <notification_text_domain.h>
38 #include <bundle_internal.h>
39 #include <app_control.h>
41 #include <wifi-direct.h>
44 #include "wfd-app-util.h"
46 #define KEY_SELECT "XF86Home"
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 int type,
106 const bundle_keyval_t *kv, void *data)
108 __WFD_APP_FUNC_ENTER__;
110 WFD_RET_IF(data == NULL || key == NULL || type == NULL, , "Invialid parameter!");
112 app_control_h control = data;
113 app_control_add_extra_data(control, key, type);
115 __WFD_APP_FUNC_EXIT__;
118 static void _launch_app(char *app_id, void *data)
120 __WFD_APP_FUNC_ENTER__;
121 WFD_RET_IF(app_id == NULL || data == NULL, "Invialid parameter!");
123 int ret = APP_CONTROL_ERROR_NONE;
124 app_control_h control = NULL;
125 ret = app_control_create(&control);
126 if (ret != APP_CONTROL_ERROR_NONE) {
127 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_create() return error : %d", ret);
130 WFD_RET_IF(control == NULL, "Failed to create app_control handle!");
132 app_control_set_operation(control, APP_CONTROL_OPERATION_DEFAULT);
133 app_control_set_app_id(control, app_id);
134 bundle_foreach((bundle *)data, _move_data_to_app_control, control);
136 char *launch_type = NULL;
137 bundle_get_str(data, "-t", &launch_type);
138 if (!strcmp(launch_type, "reconnect_by_connecting_wifi_ap")) {
139 ret = app_control_send_launch_request(control, __launch_app_result_cb, NULL);
141 ret = app_control_send_launch_request(control, NULL, NULL);
144 if (ret != APP_CONTROL_ERROR_NONE) {
145 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
146 app_control_destroy(control);
149 app_control_destroy(control);
151 __WFD_APP_FUNC_EXIT__;
155 #ifdef WFD_SCREEN_MIRRORING_ENABLED
156 void _add_screen_mirroring_activated_indicator(void *user_data)
158 __WFD_APP_FUNC_ENTER__;
159 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
160 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
161 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
163 if (ad->noti_screen_mirroring_play) {
164 notification_delete(ad->noti_screen_mirroring_play);
165 notification_free(ad->noti_screen_mirroring_play);
166 ad->noti_screen_mirroring_play = NULL;
169 if(ad->noti_screen_mirroring_on != NULL) {
170 noti_err = notification_free(ad->noti_screen_mirroring_on);
171 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
174 ad->noti_screen_mirroring_on = notification_create(NOTIFICATION_TYPE_ONGOING);
175 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
177 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
178 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
180 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
181 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
183 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
184 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
186 /* notify the quick panel */
187 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
188 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
190 __WFD_APP_FUNC_EXIT__;
196 #ifdef WFD_SCREEN_MIRRORING_ENABLED
198 * This function let the app add the notification when it is connected
200 * @param[in] user_data the pointer to the main data structure
202 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
204 __WFD_APP_FUNC_ENTER__;
206 int res = NOTIFICATION_ERROR_NONE;
207 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
208 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
210 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
212 if (ad->noti_screen_mirroring_on) {
213 notification_delete(ad->noti_screen_mirroring_on);
214 notification_free(ad->noti_screen_mirroring_on);
215 ad->noti_screen_mirroring_on = NULL;
218 if(ad->noti_screen_mirroring_play != NULL) {
219 noti_err = notification_free(ad->noti_screen_mirroring_play);
220 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
223 ad->noti_screen_mirroring_play = notification_create(NOTIFICATION_TYPE_ONGOING);
224 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
226 char msg[WFD_MAX_SIZE] = {0};
229 app_control_h control;
230 res = app_control_create(&control);
231 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
233 app_control_set_package(control, package_name);
234 app_control_add_extra_data(control, "-t", "notification");
236 res = notification_set_launch_option(ad->noti_screen_mirroring_play, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
237 if (res != NOTIFICATION_ERROR_NONE) {
238 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to otification_set_launch_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_str(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_str(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_str(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_str(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, "XF86Home")) {
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(NOTIFICATION_TYPE_ONGOING);
729 if (noti_err != NOTIFICATION_ERROR_NONE) {
730 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all.(%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_create(NOTIFICATION_TYPE_ONGOING);
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_create(NOTIFICATION_TYPE_ONGOING);
873 WFD_RET_IF(NULL == ad->noti_wifi_direct_connected, "NULL parameters.\n");
875 app_control_h control;
876 res = app_control_create(&control);
877 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
879 app_control_set_package(control, PACKAGE);
880 app_control_add_extra_data(control, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
882 noti_err = notification_set_launch_option(ad->noti_wifi_direct_connected, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
883 if (noti_err != NOTIFICATION_ERROR_NONE) {
884 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_launch_option. [%d]", noti_err);
885 app_control_destroy(control);
889 app_control_destroy(control);
891 noti_err = notification_set_layout(ad->noti_wifi_direct_connected, NOTIFICATION_LY_ONGOING_EVENT);
892 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
895 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Icon Path: %s\n", WFD_NOTI_ICON_PATH);
896 noti_err = notification_set_image(ad->noti_wifi_direct_connected, NOTIFICATION_IMAGE_TYPE_ICON, WFD_NOTI_ICON_PATH);
897 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
899 noti_err = notification_set_display_applist(ad->noti_wifi_direct_connected, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
900 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
902 noti_err = notification_set_text_domain(ad->noti_wifi_direct_connected, LOCALE_FILE_NAME, LOCALEDIR);
903 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text_domain. [%d]", noti_err);
905 /* set the title and content */
906 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_TITLE,
907 _("IDS_WIFI_BODY_WI_FI_DIRECT_ABB"), "IDS_WIFI_BODY_WI_FI_DIRECT_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
908 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
910 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_CONTENT,
911 _("IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB"),
912 "IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
913 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
915 /* notify the quick panel */
916 noti_err = notification_insert(ad->noti_wifi_direct_connected, NULL);
917 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
919 __WFD_APP_FUNC_EXIT__;
924 void wfd_app_util_del_wfd_connected_notification(wfd_appdata_t *ad)
926 __WFD_APP_FUNC_ENTER__;
927 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
929 /* delete the notification */
930 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
932 noti_err = notification_delete(ad->noti_wifi_direct_connected);
933 if (noti_err != NOTIFICATION_ERROR_NONE) {
934 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
938 if (ad->noti_wifi_direct_connected) {
939 noti_err = notification_free(ad->noti_wifi_direct_connected);
940 ad->noti_wifi_direct_connected = NULL;
941 if (noti_err != NOTIFICATION_ERROR_NONE) {
942 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
946 __WFD_APP_FUNC_EXIT__;