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>
40 #include <wifi-direct.h>
43 #include "wfd-app-util.h"
45 #define KEY_SELECT "XF86Home"
47 char *wfd_app_trim_path(const char *filewithpath)
50 char *filename = NULL;
51 if ((filename = strrchr(filewithpath, '/')) == NULL)
52 return (char *) filewithpath;
54 return (filename + 1);
56 static char *filename[100];
59 const char *space = " ";
60 int len = strlen(filewithpath);
63 strptr = (char *) filewithpath + (len - 20);
65 } else if (len < 20) {
66 strptr = (char *) filewithpath;
70 strncpy((char *) filename, space, strlen(space));
71 strncpy((char *) filename + start, strptr, 50);
73 return (char *) filename;
81 return syscall(__NR_gettid);
83 fprintf(stderr, "__NR_gettid is not defined, please include linux/unistd.h ");
88 static void __launch_app_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *data)
90 __WFD_APP_FUNC_ENTER__;
92 if(result == APP_CONTROL_RESULT_FAILED) {
93 WFD_APP_LOG(WFD_APP_LOG_ERROR, "User cancel to reconnect screen mirroring\n");
94 #ifdef WFD_SCREEN_MIRRORING_ENABLED
95 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
98 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control launch result: [%d]\n", result);
101 __WFD_APP_FUNC_EXIT__;
104 static void _move_data_to_app_control(const char *key, const char *val, void *data)
106 __WFD_APP_FUNC_ENTER__;
108 WFD_RET_IF(data == NULL || key == NULL || val == NULL, , "Invialid parameter!");
110 app_control_h control = data;
111 app_control_add_extra_data(control, key, val);
113 __WFD_APP_FUNC_EXIT__;
116 static void _launch_app(char *app_id, void *data)
118 __WFD_APP_FUNC_ENTER__;
119 WFD_RET_IF(app_id == NULL || data == NULL, "Invialid parameter!");
121 int ret = APP_CONTROL_ERROR_NONE;
122 app_control_h control = NULL;
123 ret = app_control_create(&control);
124 if (ret != APP_CONTROL_ERROR_NONE) {
125 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_create() return error : %d", ret);
128 WFD_RET_IF(control == NULL, "Failed to create app_control handle!");
130 app_control_set_operation(control, APP_CONTROL_OPERATION_DEFAULT);
131 app_control_set_app_id(control, app_id);
132 bundle_iterate((bundle *)data, _move_data_to_app_control, control);
134 char *launch_type = (char*)bundle_get_val(data, "-t");
135 if (!strcmp(launch_type, "reconnect_by_connecting_wifi_ap")) {
136 ret = app_control_send_launch_request(control, __launch_app_result_cb, NULL);
138 ret = app_control_send_launch_request(control, NULL, NULL);
141 if (ret != APP_CONTROL_ERROR_NONE) {
142 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
143 app_control_destroy(control);
146 app_control_destroy(control);
148 __WFD_APP_FUNC_EXIT__;
152 #ifdef WFD_SCREEN_MIRRORING_ENABLED
153 void _add_screen_mirroring_activated_indicator(void *user_data)
155 __WFD_APP_FUNC_ENTER__;
156 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
157 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
158 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
160 if (ad->noti_screen_mirroring_play) {
161 notification_delete(ad->noti_screen_mirroring_play);
162 notification_free(ad->noti_screen_mirroring_play);
163 ad->noti_screen_mirroring_play = NULL;
166 if(ad->noti_screen_mirroring_on != NULL) {
167 noti_err = notification_free(ad->noti_screen_mirroring_on);
168 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
171 ad->noti_screen_mirroring_on = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
172 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
174 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
175 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
177 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
178 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
180 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
181 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
183 /* notify the quick panel */
184 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
185 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
187 __WFD_APP_FUNC_EXIT__;
193 #ifdef WFD_SCREEN_MIRRORING_ENABLED
195 * This function let the app add the notification when it is connected
197 * @param[in] user_data the pointer to the main data structure
199 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
201 __WFD_APP_FUNC_ENTER__;
203 int res = NOTIFICATION_ERROR_NONE;
204 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
205 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
207 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
209 if (ad->noti_screen_mirroring_on) {
210 notification_delete(ad->noti_screen_mirroring_on);
211 notification_free(ad->noti_screen_mirroring_on);
212 ad->noti_screen_mirroring_on = NULL;
215 if(ad->noti_screen_mirroring_play != NULL) {
216 noti_err = notification_free(ad->noti_screen_mirroring_play);
217 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
220 ad->noti_screen_mirroring_play = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
221 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
223 char msg[WFD_MAX_SIZE] = {0};
226 app_control_h control;
227 res = app_control_create(&control);
228 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
230 app_control_set_package(control, package_name);
231 app_control_add_extra_data(control, "-t", "notification");
232 res = app_control_to_bundle(control, &b);
233 if (res != APP_CONTROL_ERROR_NONE) {
234 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_to_bundle() return error : %d", res);
235 app_control_destroy(control);
239 res = notification_set_execute_option(ad->noti_screen_mirroring_play, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
240 if (res != NOTIFICATION_ERROR_NONE) {
241 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_execute_option. [%d]", res);
242 app_control_destroy(control);
246 app_control_destroy(control);
248 noti_err = notification_set_layout(ad->noti_screen_mirroring_play, NOTIFICATION_LY_ONGOING_EVENT);
249 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
252 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON, SCREEN_MIRRIONG_NOTI_ICON_PATH);
253 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
255 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_PLAY_ICON_PATH);
256 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
258 /* set the title and content */
259 wfd_app_get_connected_peers(ad);
260 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_TITLE, _("IDS_SMR_BODY_SCREEN_MIRRORING_IS_ENABLED"),
261 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
262 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
264 snprintf(msg, WFD_MAX_SIZE, _("IDS_WIFI_BODY_CONNECTED_TO_PS"), ad->raw_connected_peers[0].ssid);
265 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_CONTENT,
266 msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
267 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
270 notification_set_property(ad->noti_screen_mirroring_play, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
272 /* notify the quick panel */
273 noti_err = notification_insert(ad->noti_screen_mirroring_play, NULL);
274 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
276 __WFD_APP_FUNC_EXIT__;
282 * This function let the app make a change callback for flight mode
284 * @param[in] key the pointer to the key
285 * @param[in] user_data the pointer to the main data structure
287 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
289 __WFD_APP_FUNC_ENTER__;
292 #ifdef WFD_SCREEN_MIRRORING_ENABLED
293 int screen_mirroring_status = 0;
295 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
296 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
298 res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
300 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get flight state from vconf. [%d]\n", res);
304 if (flight_mode == FALSE) {
305 WFD_APP_LOG(WFD_APP_LOG_LOW, "Flight mode is off\n");
309 /* If flight mode is on, turn off WFD */
310 wifi_direct_get_state(&ad->wfd_status);
311 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
312 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is deactivated.\n");
316 /* If connected, disconnect all devices*/
317 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
318 res = wifi_direct_disconnect_all();
319 if (res != WIFI_DIRECT_ERROR_NONE) {
320 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to send disconnection request to all. [%d]\n", res);
325 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deactivating WiFi DIrect..."
326 "Due to Flight Mode is Enabled\n");
327 res = wifi_direct_deactivate();
328 if (res != WIFI_DIRECT_ERROR_NONE) {
329 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
333 #ifdef WFD_SCREEN_MIRRORING_ENABLED
334 /* checking Screen Mirroring */
335 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
337 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
339 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
341 if(screen_mirroring_status > VCONFKEY_SCREEN_MIRRORING_DEACTIVATED) {
342 res = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
344 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
349 __WFD_APP_FUNC_EXIT__;
352 static void _wfd_cpu_limit_mode_changed(keynode_t *node, void *user_data)
354 __WFD_APP_FUNC_ENTER__;
355 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
356 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
358 int screen_mirroring_status = 0;
359 int cup_limit_mode = 0;
361 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
362 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
366 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
367 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
371 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
372 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
376 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
378 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
382 if ((power_mode == SETTING_PSMODE_POWERFUL || power_mode == SETTING_PSMODE_ADVISOR) &&
386 bundle_add(b, "-t", "notification_power_saving_on");
387 _launch_app(PACKAGE_ALLSHARE_CAST, b);
391 __WFD_APP_FUNC_EXIT__;
395 static void _wfd_power_saving_mode_changed(keynode_t *node, void *user_data)
397 __WFD_APP_FUNC_ENTER__;
398 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
399 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
401 int screen_mirroring_status = 0;
402 int cup_limit_mode = 0;
404 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
405 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
409 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
410 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
414 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
416 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
420 if (power_mode == SETTING_PSMODE_SURVIVAL ||
421 power_mode == SETTING_PSMODE_EMERGENCY) {
422 WFD_APP_LOG(WFD_APP_LOG_LOW, "Ultra power saving mode on\n");
425 bundle_add(b, "-t", "quit_by_ultra_power_saving_on");
427 _launch_app(PACKAGE_ALLSHARE_CAST, b);
429 } else if (power_mode == SETTING_PSMODE_POWERFUL ||
430 power_mode == SETTING_PSMODE_ADVISOR){
431 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
432 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
436 if (cup_limit_mode) {
439 bundle_add(b, "-t", "notification_power_saving_on");
440 _launch_app(PACKAGE_ALLSHARE_CAST, b);
445 __WFD_APP_FUNC_EXIT__;
449 static void _wfd_wifi_status_changed(keynode_t *node, void *user_data)
451 __WFD_APP_FUNC_ENTER__;
452 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
453 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
455 #ifdef WFD_SCREEN_MIRRORING_ENABLED
456 int screen_mirroring_status = 0;
458 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
459 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
463 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
464 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
469 if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0)
471 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_WIFI_STATE\n");
475 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
476 if (wifi_status == VCONFKEY_WIFI_CONNECTED) {
477 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi is connected\n");
478 #ifdef WFD_SCREEN_MIRRORING_ENABLED
479 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP;
482 bundle_add(b, "-t", "reconnect_by_connecting_wifi_ap");
484 _launch_app(PACKAGE_ALLSHARE_CAST, b);
487 } else if (VCONFKEY_WIFI_OFF == wifi_status) {
488 /* Deactivate WiFi Direct */
489 WFD_APP_LOG(WFD_APP_LOG_LOW, "Deactivate WiFi Direct...");
492 * Currently, WiFi Direct OFF is handled at net-config.
493 * Also, this patch is added to support ON-DEMAND launch destroy popup.
494 * This patch will handle 5sec deadlock of popup destory from
497 /* wfd_app_client_switch_off(ad); */
499 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
502 __WFD_APP_FUNC_EXIT__;
506 #ifdef WFD_SCREEN_MIRRORING_ENABLED
508 * This function let the app make a change callback for allshare cast
510 * @param[in] key the pointer to the key
511 * @param[in] user_data the pointer to the main data structure
513 static void _wfd_allshare_cast_status_changed(keynode_t *node, void *user_data)
515 __WFD_APP_FUNC_ENTER__;
517 int screen_mirroring_status = 0;
518 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
519 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
521 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
523 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
526 WFD_APP_LOG(WFD_APP_LOG_ERROR, "VCONFKEY_SCREEN_MIRRORING_STATE:%d\n", screen_mirroring_status);
528 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
529 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is connected\n");
530 if (ad->transmit_timer) {
531 ecore_timer_del(ad->transmit_timer);
532 ad->transmit_timer = NULL;
534 /* add connected notification */
535 _add_wfd_peers_connected_notification(ad, PACKAGE_ALLSHARE_CAST);
536 } else if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
537 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is ACTIVATED\n");
538 _add_screen_mirroring_activated_indicator(ad);
540 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
541 if (ad->noti_screen_mirroring_on) {
542 notification_delete(ad->noti_screen_mirroring_on);
543 notification_free(ad->noti_screen_mirroring_on);
544 ad->noti_screen_mirroring_on = NULL;
547 if (ad->noti_screen_mirroring_play) {
548 notification_delete(ad->noti_screen_mirroring_play);
549 notification_free(ad->noti_screen_mirroring_play);
550 ad->noti_screen_mirroring_play = NULL;
556 __WFD_APP_FUNC_EXIT__;
560 static Eina_Bool _wfd_hard_key_down_cb(void *data, int type, void *event)
562 wfd_appdata_t *ad = (wfd_appdata_t *)data;
563 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
566 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Hard Key Pressed CB...");
567 if (NULL == ad || NULL == ev) {
568 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
572 if (!strcmp(ev->keyname, KEY_SELECT)) {
573 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY]KEY_SELECT pressed");
574 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Mac : %s", ad->mac_addr_connecting);
576 if (strnlen(ad->mac_addr_connecting, MACSTR_LENGTH) > 0) {
577 res = wifi_direct_reject_connection(ad->mac_addr_connecting);
578 if (res != WIFI_DIRECT_ERROR_NONE) {
579 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", res);
582 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
585 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY][%s] pressed not Handled",
592 int wfd_app_util_register_hard_key_down_cb(void *data)
594 wfd_appdata_t *ad = (wfd_appdata_t *)data;
597 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
601 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Register hard key down press CB !!!");
602 if (NULL == ad->downkey_handler)
603 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
604 _wfd_hard_key_down_cb, ad);
609 int wfd_app_util_deregister_hard_key_down_cb(void *data)
611 wfd_appdata_t *ad = (wfd_appdata_t *)data;
614 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
617 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deregister hard key down press CB !!!");
618 if (NULL != ad->downkey_handler) {
619 ecore_event_handler_del(ad->downkey_handler);
620 ad->downkey_handler = NULL;
625 int wfd_app_util_register_vconf_callbacks(void *data)
627 wfd_appdata_t *ad = NULL;
631 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid parameter");
637 /* register flight mode */
638 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
639 _wfd_flight_mode_changed, ad);
641 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for flight mode\n");
645 #ifdef WFD_SCREEN_MIRRORING_ENABLED
647 /* TODO: Make proper changes for vconfkey */
648 ret = vconf_notify_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE,
649 _wfd_allshare_cast_status_changed, ad);
651 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for allshare cast\n");
657 ret = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed, ad);
659 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for wifi\n");
664 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed, ad);
666 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for power mode\n");
671 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed, ad);
673 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for cpu limit mode\n");
680 int wfd_app_util_deregister_vconf_callbacks(void *data)
684 /* remove callback for flight mode */
685 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _wfd_flight_mode_changed);
687 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for flight mode\n");
690 #ifdef WFD_SCREEN_MIRRORING_ENABLED
691 /* remove callback for allshare cast */
692 ret = vconf_ignore_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE, _wfd_allshare_cast_status_changed);
694 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for allshare cast\n");
698 /* remove callback for wifi */
699 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed);
701 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for wifi\n");
704 /* remove callback for power mode */
705 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed);
707 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for power mode\n");
710 /* remove callback for cpu limit mode */
711 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed);
713 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for cpu limit mode\n");
720 * This function let the app delete the notification
723 void wfd_app_util_del_notification(wfd_appdata_t *ad)
725 __WFD_APP_FUNC_ENTER__;
726 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
728 /* delete the notification */
729 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
731 noti_err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
732 if (noti_err != NOTIFICATION_ERROR_NONE) {
733 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all_by_type.(%d)\n", noti_err);
737 #ifdef WFD_SCREEN_MIRRORING_ENABLED
738 if (ad->noti_screen_mirroring_on) {
739 noti_err = notification_free(ad->noti_screen_mirroring_on);
740 ad->noti_screen_mirroring_on = NULL;
741 if (noti_err != NOTIFICATION_ERROR_NONE) {
742 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
746 if (ad->noti_screen_mirroring_play) {
747 noti_err = notification_free(ad->noti_screen_mirroring_play);
748 ad->noti_screen_mirroring_play = NULL;
749 if (noti_err != NOTIFICATION_ERROR_NONE) {
750 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
755 #ifdef NOT_CONNECTED_INDICATOR_ICON
756 if (ad->noti_wifi_direct_on) {
757 noti_err = notification_free(ad->noti_wifi_direct_on);
758 ad->noti_wifi_direct_on = NULL;
759 if (noti_err != NOTIFICATION_ERROR_NONE) {
760 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
765 if (ad->noti_wifi_direct_connected) {
766 noti_err = notification_free(ad->noti_wifi_direct_connected);
767 ad->noti_wifi_direct_connected = NULL;
768 if (noti_err != NOTIFICATION_ERROR_NONE) {
769 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
773 __WFD_APP_FUNC_EXIT__;
777 #ifdef NOT_CONNECTED_INDICATOR_ICON
779 * This function let the app add the indicator icon when wfd is activated
781 * @param[in] user_data the pointer to the main data structure
783 void wfd_app_util_add_indicator_icon(void *user_data)
785 __WFD_APP_FUNC_ENTER__;
786 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
787 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
788 WFD_RET_IF(ad->noti_wifi_direct_on, "Indicator already exists");
790 if(ad->noti_wifi_direct_on != NULL) {
791 noti_err = notification_free(ad->noti_wifi_direct_on);
792 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
795 ad->noti_wifi_direct_on = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
796 WFD_RET_IF(NULL == ad->noti_wifi_direct_on, "NULL parameters.\n");
798 noti_err = notification_set_image(ad->noti_wifi_direct_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, WFD_ACTIVATED_NOTI_ICON_PATH);
799 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
801 noti_err = notification_set_property(ad->noti_wifi_direct_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
802 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
804 noti_err = notification_set_display_applist(ad->noti_wifi_direct_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
805 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
807 /* notify the quick panel */
808 noti_err = notification_insert(ad->noti_wifi_direct_on, NULL);
809 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
811 __WFD_APP_FUNC_EXIT__;
816 #ifdef WFD_SCREEN_MIRRORING_ENABLED
818 * This function let the app set VCONFKEY_SCREEN_MIRRORING_STATE to be DEACTIVATED
820 void wfd_app_util_set_screen_mirroring_deactivated(wfd_appdata_t *ad)
822 __WFD_APP_FUNC_ENTER__;
823 WFD_RET_IF(NULL == ad, "NULL == ad!\n");
824 int screen_mirroring_status = -1;
827 /* Reconnect by ap connected, no need to set vconf to DEACTIVATED, allshare cast itself will set ACTIVATED*/
828 if (ad->screen_mirroring_state == WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP) {
829 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
830 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Reconnect screen mirroring by app connected.\n");
834 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
835 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
838 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
839 /* Set the vconf value to DEACTIVATED only when the previous vconf value is CONNECTED.
840 If the previous vconf value is ACTIVATED, it means that the Screen Mirroring UG changed that key already. So no need to change it. */
841 if(screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
842 result = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
844 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
846 notification_status_message_post(_("IDS_SMR_POP_SCREEN_MIRRORING_HAS_BEEN_DISABLED"));
849 __WFD_APP_FUNC_EXIT__;
853 * This function let the app add the notification when it shoule be turned off
855 * @param[in] user_data the pointer to the main data structure
857 void wfd_app_util_add_wfd_turn_off_notification(void *user_data)
859 __WFD_APP_FUNC_ENTER__;
861 int res = NOTIFICATION_ERROR_NONE;
862 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
863 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
865 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
867 /* delete all notifications */
868 wfd_app_util_del_notification(ad);
870 if(ad->noti_wifi_direct_connected!= NULL) {
871 noti_err = notification_free(ad->noti_wifi_direct_connected);
872 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
875 ad->noti_wifi_direct_connected = (notification_h) notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
876 WFD_RET_IF(NULL == ad->noti_wifi_direct_connected, "NULL parameters.\n");
879 app_control_h control;
880 res = app_control_create(&control);
881 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
883 app_control_set_package(control, PACKAGE);
884 app_control_add_extra_data(control, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
885 res = app_control_to_bundle(control, &b);
886 if (res != APP_CONTROL_ERROR_NONE) {
887 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_to_bundle() return error : %d", res);
888 app_control_destroy(control);
892 noti_err = notification_set_execute_option(ad->noti_wifi_direct_connected, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
893 if (noti_err != NOTIFICATION_ERROR_NONE) {
894 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_execute_option. [%d]", noti_err);
895 app_control_destroy(control);
899 app_control_destroy(control);
901 noti_err = notification_set_layout(ad->noti_wifi_direct_connected, NOTIFICATION_LY_ONGOING_EVENT);
902 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
905 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Icon Path: %s\n", WFD_NOTI_ICON_PATH);
906 noti_err = notification_set_image(ad->noti_wifi_direct_connected, NOTIFICATION_IMAGE_TYPE_ICON, WFD_NOTI_ICON_PATH);
907 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
909 noti_err = notification_set_display_applist(ad->noti_wifi_direct_connected, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
910 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
912 noti_err = notification_set_text_domain(ad->noti_wifi_direct_connected, LOCALE_FILE_NAME, LOCALEDIR);
913 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text_domain. [%d]", noti_err);
915 /* set the title and content */
916 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_TITLE,
917 _("IDS_WIFI_BODY_WI_FI_DIRECT_ABB"), "IDS_WIFI_BODY_WI_FI_DIRECT_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
918 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
920 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_CONTENT,
921 _("IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB"),
922 "IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
923 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
925 /* notify the quick panel */
926 noti_err = notification_insert(ad->noti_wifi_direct_connected, NULL);
927 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
929 __WFD_APP_FUNC_EXIT__;
934 void wfd_app_util_del_wfd_connected_notification(wfd_appdata_t *ad)
936 __WFD_APP_FUNC_ENTER__;
937 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
939 /* delete the notification */
940 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
942 noti_err = notification_delete(ad->noti_wifi_direct_connected);
943 if (noti_err != NOTIFICATION_ERROR_NONE) {
944 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
948 if (ad->noti_wifi_direct_connected) {
949 noti_err = notification_free(ad->noti_wifi_direct_connected);
950 ad->noti_wifi_direct_connected = NULL;
951 if (noti_err != NOTIFICATION_ERROR_NONE) {
952 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
956 __WFD_APP_FUNC_EXIT__;