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 int type,
105 const bundle_keyval_t *kv, void *data)
107 __WFD_APP_FUNC_ENTER__;
109 WFD_RET_IF(data == NULL || key == NULL || type == NULL, , "Invialid parameter!");
111 app_control_h control = data;
112 app_control_add_extra_data(control, key, type);
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_foreach((bundle *)data, _move_data_to_app_control, control);
135 char *launch_type = NULL;
136 bundle_get_str(data, "-t", &launch_type);
137 if (!strcmp(launch_type, "reconnect_by_connecting_wifi_ap")) {
138 ret = app_control_send_launch_request(control, __launch_app_result_cb, NULL);
140 ret = app_control_send_launch_request(control, NULL, NULL);
143 if (ret != APP_CONTROL_ERROR_NONE) {
144 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
145 app_control_destroy(control);
148 app_control_destroy(control);
150 __WFD_APP_FUNC_EXIT__;
154 #ifdef WFD_SCREEN_MIRRORING_ENABLED
155 void _add_screen_mirroring_activated_indicator(void *user_data)
157 __WFD_APP_FUNC_ENTER__;
158 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
159 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
160 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
162 if (ad->noti_screen_mirroring_play) {
163 notification_delete(ad->noti_screen_mirroring_play);
164 notification_free(ad->noti_screen_mirroring_play);
165 ad->noti_screen_mirroring_play = NULL;
168 if(ad->noti_screen_mirroring_on != NULL) {
169 noti_err = notification_free(ad->noti_screen_mirroring_on);
170 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
173 ad->noti_screen_mirroring_on = notification_create(NOTIFICATION_TYPE_ONGOING);
174 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
176 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
177 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
179 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
180 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
182 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
183 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
185 /* notify the quick panel */
186 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
187 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
189 __WFD_APP_FUNC_EXIT__;
195 #ifdef WFD_SCREEN_MIRRORING_ENABLED
197 * This function let the app add the notification when it is connected
199 * @param[in] user_data the pointer to the main data structure
201 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
203 __WFD_APP_FUNC_ENTER__;
205 int res = NOTIFICATION_ERROR_NONE;
206 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
207 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
209 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
211 if (ad->noti_screen_mirroring_on) {
212 notification_delete(ad->noti_screen_mirroring_on);
213 notification_free(ad->noti_screen_mirroring_on);
214 ad->noti_screen_mirroring_on = NULL;
217 if(ad->noti_screen_mirroring_play != NULL) {
218 noti_err = notification_free(ad->noti_screen_mirroring_play);
219 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
222 ad->noti_screen_mirroring_play = notification_create(NOTIFICATION_TYPE_ONGOING);
223 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
225 char msg[WFD_MAX_SIZE] = {0};
228 app_control_h control;
229 res = app_control_create(&control);
230 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
232 app_control_set_package(control, package_name);
233 app_control_add_extra_data(control, "-t", "notification");
235 res = notification_set_launch_option(ad->noti_screen_mirroring_play, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
236 if (res != NOTIFICATION_ERROR_NONE) {
237 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to otification_set_launch_option. [%d]", res);
238 app_control_destroy(control);
242 app_control_destroy(control);
244 noti_err = notification_set_layout(ad->noti_screen_mirroring_play, NOTIFICATION_LY_ONGOING_EVENT);
245 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
248 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON, SCREEN_MIRRIONG_NOTI_ICON_PATH);
249 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
251 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_PLAY_ICON_PATH);
252 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
254 /* set the title and content */
255 wfd_app_get_connected_peers(ad);
256 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_TITLE, _("IDS_SMR_BODY_SCREEN_MIRRORING_IS_ENABLED"),
257 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
258 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
260 snprintf(msg, WFD_MAX_SIZE, _("IDS_WIFI_BODY_CONNECTED_TO_PS"), ad->raw_connected_peers[0].ssid);
261 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_CONTENT,
262 msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
263 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
266 notification_set_property(ad->noti_screen_mirroring_play, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
268 /* notify the quick panel */
269 noti_err = notification_insert(ad->noti_screen_mirroring_play, NULL);
270 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
272 __WFD_APP_FUNC_EXIT__;
278 * This function let the app make a change callback for flight mode
280 * @param[in] key the pointer to the key
281 * @param[in] user_data the pointer to the main data structure
283 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
285 __WFD_APP_FUNC_ENTER__;
288 #ifdef WFD_SCREEN_MIRRORING_ENABLED
289 int screen_mirroring_status = 0;
291 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
292 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
294 res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
296 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get flight state from vconf. [%d]\n", res);
300 if (flight_mode == FALSE) {
301 WFD_APP_LOG(WFD_APP_LOG_LOW, "Flight mode is off\n");
305 /* If flight mode is on, turn off WFD */
306 wifi_direct_get_state(&ad->wfd_status);
307 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
308 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is deactivated.\n");
312 /* If connected, disconnect all devices*/
313 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
314 res = wifi_direct_disconnect_all();
315 if (res != WIFI_DIRECT_ERROR_NONE) {
316 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to send disconnection request to all. [%d]\n", res);
321 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deactivating WiFi DIrect..."
322 "Due to Flight Mode is Enabled\n");
323 res = wifi_direct_deactivate();
324 if (res != WIFI_DIRECT_ERROR_NONE) {
325 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
329 #ifdef WFD_SCREEN_MIRRORING_ENABLED
330 /* checking Screen Mirroring */
331 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
333 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
335 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
337 if(screen_mirroring_status > VCONFKEY_SCREEN_MIRRORING_DEACTIVATED) {
338 res = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
340 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
345 __WFD_APP_FUNC_EXIT__;
348 static void _wfd_cpu_limit_mode_changed(keynode_t *node, void *user_data)
350 __WFD_APP_FUNC_ENTER__;
351 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
352 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
354 int screen_mirroring_status = 0;
355 int cup_limit_mode = 0;
357 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
358 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
362 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
363 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
367 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
368 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
372 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
374 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
378 if ((power_mode == SETTING_PSMODE_POWERFUL || power_mode == SETTING_PSMODE_ADVISOR) &&
382 bundle_add_str(b, "-t", "notification_power_saving_on");
383 _launch_app(PACKAGE_ALLSHARE_CAST, b);
387 __WFD_APP_FUNC_EXIT__;
391 static void _wfd_power_saving_mode_changed(keynode_t *node, void *user_data)
393 __WFD_APP_FUNC_ENTER__;
394 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
395 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
397 int screen_mirroring_status = 0;
398 int cup_limit_mode = 0;
400 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
401 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
405 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
406 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
410 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
412 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
416 if (power_mode == SETTING_PSMODE_SURVIVAL ||
417 power_mode == SETTING_PSMODE_EMERGENCY) {
418 WFD_APP_LOG(WFD_APP_LOG_LOW, "Ultra power saving mode on\n");
421 bundle_add_str(b, "-t", "quit_by_ultra_power_saving_on");
423 _launch_app(PACKAGE_ALLSHARE_CAST, b);
425 } else if (power_mode == SETTING_PSMODE_POWERFUL ||
426 power_mode == SETTING_PSMODE_ADVISOR){
427 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
428 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
432 if (cup_limit_mode) {
435 bundle_add_str(b, "-t", "notification_power_saving_on");
436 _launch_app(PACKAGE_ALLSHARE_CAST, b);
441 __WFD_APP_FUNC_EXIT__;
445 static void _wfd_wifi_status_changed(keynode_t *node, void *user_data)
447 __WFD_APP_FUNC_ENTER__;
448 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
449 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
451 #ifdef WFD_SCREEN_MIRRORING_ENABLED
452 int screen_mirroring_status = 0;
454 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
455 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
459 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
460 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
465 if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0)
467 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_WIFI_STATE\n");
471 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
472 if (wifi_status == VCONFKEY_WIFI_CONNECTED) {
473 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi is connected\n");
474 #ifdef WFD_SCREEN_MIRRORING_ENABLED
475 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP;
478 bundle_add_str(b, "-t", "reconnect_by_connecting_wifi_ap");
480 _launch_app(PACKAGE_ALLSHARE_CAST, b);
483 } else if (VCONFKEY_WIFI_OFF == wifi_status) {
484 /* Deactivate WiFi Direct */
485 WFD_APP_LOG(WFD_APP_LOG_LOW, "Deactivate WiFi Direct...");
488 * Currently, WiFi Direct OFF is handled at net-config.
489 * Also, this patch is added to support ON-DEMAND launch destroy popup.
490 * This patch will handle 5sec deadlock of popup destory from
493 /* wfd_app_client_switch_off(ad); */
495 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
498 __WFD_APP_FUNC_EXIT__;
502 #ifdef WFD_SCREEN_MIRRORING_ENABLED
504 * This function let the app make a change callback for allshare cast
506 * @param[in] key the pointer to the key
507 * @param[in] user_data the pointer to the main data structure
509 static void _wfd_allshare_cast_status_changed(keynode_t *node, void *user_data)
511 __WFD_APP_FUNC_ENTER__;
513 int screen_mirroring_status = 0;
514 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
515 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
517 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
519 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
522 WFD_APP_LOG(WFD_APP_LOG_ERROR, "VCONFKEY_SCREEN_MIRRORING_STATE:%d\n", screen_mirroring_status);
524 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
525 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is connected\n");
526 if (ad->transmit_timer) {
527 ecore_timer_del(ad->transmit_timer);
528 ad->transmit_timer = NULL;
530 /* add connected notification */
531 _add_wfd_peers_connected_notification(ad, PACKAGE_ALLSHARE_CAST);
532 } else if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
533 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is ACTIVATED\n");
534 _add_screen_mirroring_activated_indicator(ad);
536 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
537 if (ad->noti_screen_mirroring_on) {
538 notification_delete(ad->noti_screen_mirroring_on);
539 notification_free(ad->noti_screen_mirroring_on);
540 ad->noti_screen_mirroring_on = NULL;
543 if (ad->noti_screen_mirroring_play) {
544 notification_delete(ad->noti_screen_mirroring_play);
545 notification_free(ad->noti_screen_mirroring_play);
546 ad->noti_screen_mirroring_play = NULL;
552 __WFD_APP_FUNC_EXIT__;
556 static Eina_Bool _wfd_hard_key_down_cb(void *data, int type, void *event)
558 wfd_appdata_t *ad = (wfd_appdata_t *)data;
559 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
562 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Hard Key Pressed CB...");
563 if (NULL == ad || NULL == ev) {
564 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
568 if (!strcmp(ev->keyname, KEY_SELECT)) {
569 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY]KEY_SELECT pressed");
570 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Mac : %s", ad->mac_addr_connecting);
572 if (strnlen(ad->mac_addr_connecting, MACSTR_LENGTH) > 0) {
573 res = wifi_direct_reject_connection(ad->mac_addr_connecting);
574 if (res != WIFI_DIRECT_ERROR_NONE) {
575 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", res);
578 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
581 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY][%s] pressed not Handled",
588 int wfd_app_util_register_hard_key_down_cb(void *data)
590 wfd_appdata_t *ad = (wfd_appdata_t *)data;
593 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
597 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Register hard key down press CB !!!");
598 if (NULL == ad->downkey_handler)
599 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
600 _wfd_hard_key_down_cb, ad);
605 int wfd_app_util_deregister_hard_key_down_cb(void *data)
607 wfd_appdata_t *ad = (wfd_appdata_t *)data;
610 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
613 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deregister hard key down press CB !!!");
614 if (NULL != ad->downkey_handler) {
615 ecore_event_handler_del(ad->downkey_handler);
616 ad->downkey_handler = NULL;
621 int wfd_app_util_register_vconf_callbacks(void *data)
623 wfd_appdata_t *ad = NULL;
627 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid parameter");
633 /* register flight mode */
634 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
635 _wfd_flight_mode_changed, ad);
637 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for flight mode\n");
641 #ifdef WFD_SCREEN_MIRRORING_ENABLED
643 /* TODO: Make proper changes for vconfkey */
644 ret = vconf_notify_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE,
645 _wfd_allshare_cast_status_changed, ad);
647 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for allshare cast\n");
653 ret = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed, ad);
655 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for wifi\n");
660 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed, ad);
662 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for power mode\n");
667 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed, ad);
669 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for cpu limit mode\n");
676 int wfd_app_util_deregister_vconf_callbacks(void *data)
680 /* remove callback for flight mode */
681 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _wfd_flight_mode_changed);
683 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for flight mode\n");
686 #ifdef WFD_SCREEN_MIRRORING_ENABLED
687 /* remove callback for allshare cast */
688 ret = vconf_ignore_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE, _wfd_allshare_cast_status_changed);
690 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for allshare cast\n");
694 /* remove callback for wifi */
695 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed);
697 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for wifi\n");
700 /* remove callback for power mode */
701 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed);
703 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for power mode\n");
706 /* remove callback for cpu limit mode */
707 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed);
709 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for cpu limit mode\n");
716 * This function let the app delete the notification
719 void wfd_app_util_del_notification(wfd_appdata_t *ad)
721 __WFD_APP_FUNC_ENTER__;
722 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
724 /* delete the notification */
725 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
727 noti_err = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
728 if (noti_err != NOTIFICATION_ERROR_NONE) {
729 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all.(%d)\n", noti_err);
733 #ifdef WFD_SCREEN_MIRRORING_ENABLED
734 if (ad->noti_screen_mirroring_on) {
735 noti_err = notification_free(ad->noti_screen_mirroring_on);
736 ad->noti_screen_mirroring_on = NULL;
737 if (noti_err != NOTIFICATION_ERROR_NONE) {
738 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
742 if (ad->noti_screen_mirroring_play) {
743 noti_err = notification_free(ad->noti_screen_mirroring_play);
744 ad->noti_screen_mirroring_play = NULL;
745 if (noti_err != NOTIFICATION_ERROR_NONE) {
746 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
751 #ifdef NOT_CONNECTED_INDICATOR_ICON
752 if (ad->noti_wifi_direct_on) {
753 noti_err = notification_free(ad->noti_wifi_direct_on);
754 ad->noti_wifi_direct_on = NULL;
755 if (noti_err != NOTIFICATION_ERROR_NONE) {
756 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
761 if (ad->noti_wifi_direct_connected) {
762 noti_err = notification_free(ad->noti_wifi_direct_connected);
763 ad->noti_wifi_direct_connected = NULL;
764 if (noti_err != NOTIFICATION_ERROR_NONE) {
765 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
769 __WFD_APP_FUNC_EXIT__;
773 #ifdef NOT_CONNECTED_INDICATOR_ICON
775 * This function let the app add the indicator icon when wfd is activated
777 * @param[in] user_data the pointer to the main data structure
779 void wfd_app_util_add_indicator_icon(void *user_data)
781 __WFD_APP_FUNC_ENTER__;
782 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
783 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
784 WFD_RET_IF(ad->noti_wifi_direct_on, "Indicator already exists");
786 if(ad->noti_wifi_direct_on != NULL) {
787 noti_err = notification_free(ad->noti_wifi_direct_on);
788 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
791 ad->noti_wifi_direct_on = notification_create(NOTIFICATION_TYPE_ONGOING);
792 WFD_RET_IF(NULL == ad->noti_wifi_direct_on, "NULL parameters.\n");
794 noti_err = notification_set_image(ad->noti_wifi_direct_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, WFD_ACTIVATED_NOTI_ICON_PATH);
795 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
797 noti_err = notification_set_property(ad->noti_wifi_direct_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
798 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
800 noti_err = notification_set_display_applist(ad->noti_wifi_direct_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
801 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
803 /* notify the quick panel */
804 noti_err = notification_insert(ad->noti_wifi_direct_on, NULL);
805 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
807 __WFD_APP_FUNC_EXIT__;
812 #ifdef WFD_SCREEN_MIRRORING_ENABLED
814 * This function let the app set VCONFKEY_SCREEN_MIRRORING_STATE to be DEACTIVATED
816 void wfd_app_util_set_screen_mirroring_deactivated(wfd_appdata_t *ad)
818 __WFD_APP_FUNC_ENTER__;
819 WFD_RET_IF(NULL == ad, "NULL == ad!\n");
820 int screen_mirroring_status = -1;
823 /* Reconnect by ap connected, no need to set vconf to DEACTIVATED, allshare cast itself will set ACTIVATED*/
824 if (ad->screen_mirroring_state == WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP) {
825 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
826 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Reconnect screen mirroring by app connected.\n");
830 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
831 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
834 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
835 /* Set the vconf value to DEACTIVATED only when the previous vconf value is CONNECTED.
836 If the previous vconf value is ACTIVATED, it means that the Screen Mirroring UG changed that key already. So no need to change it. */
837 if(screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
838 result = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
840 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
842 notification_status_message_post(_("IDS_SMR_POP_SCREEN_MIRRORING_HAS_BEEN_DISABLED"));
845 __WFD_APP_FUNC_EXIT__;
849 * This function let the app add the notification when it shoule be turned off
851 * @param[in] user_data the pointer to the main data structure
853 void wfd_app_util_add_wfd_turn_off_notification(void *user_data)
855 __WFD_APP_FUNC_ENTER__;
857 int res = NOTIFICATION_ERROR_NONE;
858 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
859 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
861 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
863 /* delete all notifications */
864 wfd_app_util_del_notification(ad);
866 if(ad->noti_wifi_direct_connected!= NULL) {
867 noti_err = notification_free(ad->noti_wifi_direct_connected);
868 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
871 ad->noti_wifi_direct_connected = (notification_h) notification_create(NOTIFICATION_TYPE_ONGOING);
872 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__;