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>
42 #include <wifi-direct.h>
45 #include "wfd-app-util.h"
47 #define KEY_SELECT "XF86Home"
49 char *wfd_app_trim_path(const char *filewithpath)
52 char *filename = NULL;
53 if ((filename = strrchr(filewithpath, '/')) == NULL)
54 return (char *) filewithpath;
56 return (filename + 1);
58 static char *filename[100];
61 const char *space = " ";
62 int len = strlen(filewithpath);
65 strptr = (char *) filewithpath + (len - 20);
67 } else if (len < 20) {
68 strptr = (char *) filewithpath;
72 strncpy((char *) filename, space, strlen(space));
73 strncpy((char *) filename + start, strptr, 50);
75 return (char *) filename;
83 return syscall(__NR_gettid);
85 fprintf(stderr, "__NR_gettid is not defined, please include linux/unistd.h ");
90 static void __launch_app_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *data)
92 __WFD_APP_FUNC_ENTER__;
94 if(result == APP_CONTROL_RESULT_FAILED) {
95 WFD_APP_LOG(WFD_APP_LOG_ERROR, "User cancel to reconnect screen mirroring\n");
96 #ifdef WFD_SCREEN_MIRRORING_ENABLED
97 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
100 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control launch result: [%d]\n", result);
103 __WFD_APP_FUNC_EXIT__;
106 static void _move_data_to_app_control(const char *key, const int type,
107 const bundle_keyval_t *kv, void *data)
109 __WFD_APP_FUNC_ENTER__;
112 unsigned int size = 0;
115 WFD_RET_IF(data == NULL || key == NULL || type == 0, , "Invialid parameter!");
117 app_control_h control = data;
119 if (type == BUNDLE_TYPE_STR)
121 bundle_keyval_get_basic_val((bundle_keyval_t *) kv, &ptr, &size);
122 buff = malloc(sizeof(char)* size + 1);
123 snprintf(buff, size + 1, "%s", ((char*) ptr));
124 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR -KEY: %s, VAL: %s, SIZE: %d", key, buff, size);
126 app_control_add_extra_data(control, key, buff);
128 } else if (type == BUNDLE_TYPE_BYTE) {
129 bundle_keyval_get_basic_val((bundle_keyval_t *) kv, &ptr, &size);
130 buff = malloc(sizeof(char)* size + 1);
131 snprintf(buff, size + 1, "%s", ((char*) ptr));
132 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR -KEY: %s, VAL: %s, SIZE: %d", key, buff, size);
134 app_control_add_extra_data(control, key, buff);
136 } else if (type == BUNDLE_TYPE_STR_ARRAY) {
139 unsigned int len = 0;
140 size_t *element_size = NULL;
141 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR_ARRAY -KEY: %s", key);
142 bundle_keyval_get_array_val((bundle_keyval_t *) kv, &array, &len, &element_size);
143 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-Array len: %d", len);
144 for (i = 0; i < len; i++) {
145 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-%s", (char*)array[i]);
147 app_control_add_extra_data(control, key, (char*)array[i]);
151 __WFD_APP_FUNC_EXIT__;
154 static void _launch_app(char *app_id, void *data)
156 __WFD_APP_FUNC_ENTER__;
157 WFD_RET_IF(app_id == NULL || data == NULL, "Invialid parameter!");
159 int ret = APP_CONTROL_ERROR_NONE;
160 app_control_h control = NULL;
161 ret = app_control_create(&control);
162 if (ret != APP_CONTROL_ERROR_NONE) {
163 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_create() return error : %d", ret);
166 WFD_RET_IF(control == NULL, "Failed to create app_control handle!");
168 app_control_set_operation(control, APP_CONTROL_OPERATION_DEFAULT);
169 app_control_set_app_id(control, app_id);
170 bundle_foreach((bundle *)data, _move_data_to_app_control, control);
172 char *launch_type = NULL;
173 bundle_get_str(data, "-t", &launch_type);
174 if (!strcmp(launch_type, "reconnect_by_connecting_wifi_ap")) {
175 ret = app_control_send_launch_request(control, __launch_app_result_cb, NULL);
177 ret = app_control_send_launch_request(control, NULL, NULL);
180 if (ret != APP_CONTROL_ERROR_NONE) {
181 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
182 app_control_destroy(control);
185 app_control_destroy(control);
187 __WFD_APP_FUNC_EXIT__;
191 #ifdef WFD_SCREEN_MIRRORING_ENABLED
192 void _add_screen_mirroring_activated_indicator(void *user_data)
194 __WFD_APP_FUNC_ENTER__;
195 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
196 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
197 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
199 if (ad->noti_screen_mirroring_play) {
200 notification_delete(ad->noti_screen_mirroring_play);
201 notification_free(ad->noti_screen_mirroring_play);
202 ad->noti_screen_mirroring_play = NULL;
205 if(ad->noti_screen_mirroring_on != NULL) {
206 noti_err = notification_free(ad->noti_screen_mirroring_on);
207 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
210 ad->noti_screen_mirroring_on = notification_create(NOTIFICATION_TYPE_ONGOING);
211 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
213 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
214 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
216 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
217 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
219 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
220 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
222 /* notify the quick panel */
223 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
224 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
226 __WFD_APP_FUNC_EXIT__;
232 #ifdef WFD_SCREEN_MIRRORING_ENABLED
234 * This function let the app add the notification when it is connected
236 * @param[in] user_data the pointer to the main data structure
238 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
240 __WFD_APP_FUNC_ENTER__;
242 int res = NOTIFICATION_ERROR_NONE;
243 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
244 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
246 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
248 if (ad->noti_screen_mirroring_on) {
249 notification_delete(ad->noti_screen_mirroring_on);
250 notification_free(ad->noti_screen_mirroring_on);
251 ad->noti_screen_mirroring_on = NULL;
254 if(ad->noti_screen_mirroring_play != NULL) {
255 noti_err = notification_free(ad->noti_screen_mirroring_play);
256 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
259 ad->noti_screen_mirroring_play = notification_create(NOTIFICATION_TYPE_ONGOING);
260 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
262 char msg[WFD_MAX_SIZE] = {0};
265 app_control_h control;
266 res = app_control_create(&control);
267 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
269 app_control_set_package(control, package_name);
270 app_control_add_extra_data(control, "-t", "notification");
272 res = notification_set_launch_option(ad->noti_screen_mirroring_play, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
273 if (res != NOTIFICATION_ERROR_NONE) {
274 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to otification_set_launch_option. [%d]", res);
275 app_control_destroy(control);
279 app_control_destroy(control);
281 noti_err = notification_set_layout(ad->noti_screen_mirroring_play, NOTIFICATION_LY_ONGOING_EVENT);
282 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
285 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON, SCREEN_MIRRIONG_NOTI_ICON_PATH);
286 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
288 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_PLAY_ICON_PATH);
289 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
291 /* set the title and content */
292 wfd_app_get_connected_peers(ad);
293 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_TITLE, D_("IDS_SMR_BODY_SCREEN_MIRRORING_IS_ENABLED"),
294 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
295 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
297 snprintf(msg, WFD_MAX_SIZE, D_("IDS_WIFI_BODY_CONNECTED_TO_PS"), ad->raw_connected_peers[0].ssid);
298 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_CONTENT,
299 msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
300 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
303 notification_set_property(ad->noti_screen_mirroring_play, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
305 /* notify the quick panel */
306 noti_err = notification_insert(ad->noti_screen_mirroring_play, NULL);
307 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
309 __WFD_APP_FUNC_EXIT__;
315 * This function let the app make a change callback for flight mode
317 * @param[in] key the pointer to the key
318 * @param[in] user_data the pointer to the main data structure
320 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
322 __WFD_APP_FUNC_ENTER__;
325 #ifdef WFD_SCREEN_MIRRORING_ENABLED
326 int screen_mirroring_status = 0;
328 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
329 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
331 res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
333 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get flight state from vconf. [%d]\n", res);
337 if (flight_mode == FALSE) {
338 WFD_APP_LOG(WFD_APP_LOG_LOW, "Flight mode is off\n");
342 /* If flight mode is on, turn off WFD */
343 wifi_direct_get_state(&ad->wfd_status);
344 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
345 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is deactivated.\n");
349 /* If connected, disconnect all devices*/
350 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
351 res = wifi_direct_disconnect_all();
352 if (res != WIFI_DIRECT_ERROR_NONE) {
353 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to send disconnection request to all. [%d]\n", res);
358 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deactivating WiFi DIrect..."
359 "Due to Flight Mode is Enabled\n");
360 res = wifi_direct_deactivate();
361 if (res != WIFI_DIRECT_ERROR_NONE) {
362 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
366 #ifdef WFD_SCREEN_MIRRORING_ENABLED
367 /* checking Screen Mirroring */
368 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
370 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
372 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
374 if(screen_mirroring_status > VCONFKEY_SCREEN_MIRRORING_DEACTIVATED) {
375 res = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
377 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
382 __WFD_APP_FUNC_EXIT__;
385 static void _wfd_cpu_limit_mode_changed(keynode_t *node, void *user_data)
387 __WFD_APP_FUNC_ENTER__;
388 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
389 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
391 int screen_mirroring_status = 0;
392 int cup_limit_mode = 0;
394 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
395 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
399 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
400 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
404 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
405 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
409 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
411 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
415 if ((power_mode == SETTING_PSMODE_POWERFUL || power_mode == SETTING_PSMODE_ADVISOR) &&
419 bundle_add_str(b, "-t", "notification_power_saving_on");
420 _launch_app(PACKAGE_ALLSHARE_CAST, b);
424 __WFD_APP_FUNC_EXIT__;
428 static void _wfd_power_saving_mode_changed(keynode_t *node, void *user_data)
430 __WFD_APP_FUNC_ENTER__;
431 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
432 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
434 int screen_mirroring_status = 0;
435 int cup_limit_mode = 0;
437 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
438 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
442 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
443 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
447 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0)
449 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
453 if (power_mode == SETTING_PSMODE_SURVIVAL ||
454 power_mode == SETTING_PSMODE_EMERGENCY) {
455 WFD_APP_LOG(WFD_APP_LOG_LOW, "Ultra power saving mode on\n");
458 bundle_add_str(b, "-t", "quit_by_ultra_power_saving_on");
460 _launch_app(PACKAGE_ALLSHARE_CAST, b);
462 } else if (power_mode == SETTING_PSMODE_POWERFUL ||
463 power_mode == SETTING_PSMODE_ADVISOR){
464 if(vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
465 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
469 if (cup_limit_mode) {
472 bundle_add_str(b, "-t", "notification_power_saving_on");
473 _launch_app(PACKAGE_ALLSHARE_CAST, b);
478 __WFD_APP_FUNC_EXIT__;
482 static void _wfd_wifi_status_changed(keynode_t *node, void *user_data)
484 __WFD_APP_FUNC_ENTER__;
485 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
486 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
488 #ifdef WFD_SCREEN_MIRRORING_ENABLED
489 int screen_mirroring_status = 0;
491 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
492 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
496 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
497 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
502 if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0)
504 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_WIFI_STATE\n");
508 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
509 if (wifi_status == VCONFKEY_WIFI_CONNECTED) {
510 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi is connected\n");
511 #ifdef WFD_SCREEN_MIRRORING_ENABLED
512 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP;
515 bundle_add_str(b, "-t", "reconnect_by_connecting_wifi_ap");
517 _launch_app(PACKAGE_ALLSHARE_CAST, b);
520 } else if (VCONFKEY_WIFI_OFF == wifi_status) {
521 /* Deactivate WiFi Direct */
522 WFD_APP_LOG(WFD_APP_LOG_LOW, "Deactivate WiFi Direct...");
525 * Currently, WiFi Direct OFF is handled at net-config.
526 * Also, this patch is added to support ON-DEMAND launch destroy popup.
527 * This patch will handle 5sec deadlock of popup destory from
530 /* wfd_app_client_switch_off(ad); */
532 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
535 __WFD_APP_FUNC_EXIT__;
539 #ifdef WFD_SCREEN_MIRRORING_ENABLED
541 * This function let the app make a change callback for allshare cast
543 * @param[in] key the pointer to the key
544 * @param[in] user_data the pointer to the main data structure
546 static void _wfd_allshare_cast_status_changed(keynode_t *node, void *user_data)
548 __WFD_APP_FUNC_ENTER__;
550 int screen_mirroring_status = 0;
551 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
552 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
554 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
556 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
559 WFD_APP_LOG(WFD_APP_LOG_ERROR, "VCONFKEY_SCREEN_MIRRORING_STATE:%d\n", screen_mirroring_status);
561 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
562 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is connected\n");
563 if (ad->transmit_timer) {
564 ecore_timer_del(ad->transmit_timer);
565 ad->transmit_timer = NULL;
567 /* add connected notification */
568 _add_wfd_peers_connected_notification(ad, PACKAGE_ALLSHARE_CAST);
569 } else if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
570 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is ACTIVATED\n");
571 _add_screen_mirroring_activated_indicator(ad);
573 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
574 if (ad->noti_screen_mirroring_on) {
575 notification_delete(ad->noti_screen_mirroring_on);
576 notification_free(ad->noti_screen_mirroring_on);
577 ad->noti_screen_mirroring_on = NULL;
580 if (ad->noti_screen_mirroring_play) {
581 notification_delete(ad->noti_screen_mirroring_play);
582 notification_free(ad->noti_screen_mirroring_play);
583 ad->noti_screen_mirroring_play = NULL;
589 __WFD_APP_FUNC_EXIT__;
593 static Eina_Bool _wfd_hard_key_down_cb(void *data, int type, void *event)
595 wfd_appdata_t *ad = (wfd_appdata_t *)data;
596 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
599 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Hard Key Pressed CB...");
600 if (NULL == ad || NULL == ev) {
601 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
605 if (!strcmp(ev->keyname, "XF86Home")) {
606 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY]KEY_SELECT pressed");
607 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Mac : %s", ad->mac_addr_connecting);
609 if (strnlen(ad->mac_addr_connecting, MACSTR_LENGTH) > 0) {
610 res = wifi_direct_reject_connection(ad->mac_addr_connecting);
611 if (res != WIFI_DIRECT_ERROR_NONE) {
612 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", res);
615 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
618 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY][%s] pressed not Handled",
625 int wfd_app_util_register_hard_key_down_cb(void *data)
627 wfd_appdata_t *ad = (wfd_appdata_t *)data;
630 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
634 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Register hard key down press CB !!!");
635 if (NULL == ad->downkey_handler)
636 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
637 _wfd_hard_key_down_cb, ad);
642 int wfd_app_util_deregister_hard_key_down_cb(void *data)
644 wfd_appdata_t *ad = (wfd_appdata_t *)data;
647 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
650 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deregister hard key down press CB !!!");
651 if (NULL != ad->downkey_handler) {
652 ecore_event_handler_del(ad->downkey_handler);
653 ad->downkey_handler = NULL;
658 int wfd_app_util_register_vconf_callbacks(void *data)
660 wfd_appdata_t *ad = NULL;
664 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid parameter");
670 /* register flight mode */
671 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
672 _wfd_flight_mode_changed, ad);
674 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for flight mode\n");
678 #ifdef WFD_SCREEN_MIRRORING_ENABLED
680 /* TODO: Make proper changes for vconfkey */
681 ret = vconf_notify_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE,
682 _wfd_allshare_cast_status_changed, ad);
684 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for allshare cast\n");
690 ret = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed, ad);
692 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for wifi\n");
697 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed, ad);
699 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for power mode\n");
704 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed, ad);
706 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for cpu limit mode\n");
713 int wfd_app_util_deregister_vconf_callbacks(void *data)
717 /* remove callback for flight mode */
718 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _wfd_flight_mode_changed);
720 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for flight mode\n");
723 #ifdef WFD_SCREEN_MIRRORING_ENABLED
724 /* remove callback for allshare cast */
725 ret = vconf_ignore_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE, _wfd_allshare_cast_status_changed);
727 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for allshare cast\n");
731 /* remove callback for wifi */
732 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed);
734 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for wifi\n");
737 /* remove callback for power mode */
738 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed);
740 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for power mode\n");
743 /* remove callback for cpu limit mode */
744 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed);
746 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for cpu limit mode\n");
753 * This function let the app delete the notification
756 void wfd_app_util_del_notification(wfd_appdata_t *ad)
758 __WFD_APP_FUNC_ENTER__;
759 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
761 /* delete the notification */
762 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
764 noti_err = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
765 if (noti_err != NOTIFICATION_ERROR_NONE) {
766 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all.(%d)\n", noti_err);
770 #ifdef WFD_SCREEN_MIRRORING_ENABLED
771 if (ad->noti_screen_mirroring_on) {
772 noti_err = notification_free(ad->noti_screen_mirroring_on);
773 ad->noti_screen_mirroring_on = NULL;
774 if (noti_err != NOTIFICATION_ERROR_NONE) {
775 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
779 if (ad->noti_screen_mirroring_play) {
780 noti_err = notification_free(ad->noti_screen_mirroring_play);
781 ad->noti_screen_mirroring_play = NULL;
782 if (noti_err != NOTIFICATION_ERROR_NONE) {
783 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
788 #ifdef NOT_CONNECTED_INDICATOR_ICON
789 if (ad->noti_wifi_direct_on) {
790 noti_err = notification_free(ad->noti_wifi_direct_on);
791 ad->noti_wifi_direct_on = NULL;
792 if (noti_err != NOTIFICATION_ERROR_NONE) {
793 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
798 if (ad->noti_wifi_direct_connected) {
799 noti_err = notification_free(ad->noti_wifi_direct_connected);
800 ad->noti_wifi_direct_connected = NULL;
801 if (noti_err != NOTIFICATION_ERROR_NONE) {
802 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
806 __WFD_APP_FUNC_EXIT__;
810 #ifdef NOT_CONNECTED_INDICATOR_ICON
812 * This function let the app add the indicator icon when wfd is activated
814 * @param[in] user_data the pointer to the main data structure
816 void wfd_app_util_add_indicator_icon(void *user_data)
818 __WFD_APP_FUNC_ENTER__;
819 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
820 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
821 WFD_RET_IF(ad->noti_wifi_direct_on, "Indicator already exists");
823 if(ad->noti_wifi_direct_on != NULL) {
824 noti_err = notification_free(ad->noti_wifi_direct_on);
825 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
828 ad->noti_wifi_direct_on = notification_create(NOTIFICATION_TYPE_ONGOING);
829 WFD_RET_IF(NULL == ad->noti_wifi_direct_on, "NULL parameters.\n");
831 noti_err = notification_set_image(ad->noti_wifi_direct_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, WFD_ACTIVATED_NOTI_ICON_PATH);
832 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
834 noti_err = notification_set_property(ad->noti_wifi_direct_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
835 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
837 noti_err = notification_set_display_applist(ad->noti_wifi_direct_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
838 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
840 /* notify the quick panel */
841 noti_err = notification_insert(ad->noti_wifi_direct_on, NULL);
842 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
844 __WFD_APP_FUNC_EXIT__;
849 #ifdef WFD_SCREEN_MIRRORING_ENABLED
851 * This function let the app set VCONFKEY_SCREEN_MIRRORING_STATE to be DEACTIVATED
853 void wfd_app_util_set_screen_mirroring_deactivated(wfd_appdata_t *ad)
855 __WFD_APP_FUNC_ENTER__;
856 WFD_RET_IF(NULL == ad, "NULL == ad!\n");
857 int screen_mirroring_status = -1;
860 /* Reconnect by ap connected, no need to set vconf to DEACTIVATED, allshare cast itself will set ACTIVATED*/
861 if (ad->screen_mirroring_state == WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP) {
862 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
863 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Reconnect screen mirroring by app connected.\n");
867 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
868 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
871 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
872 /* Set the vconf value to DEACTIVATED only when the previous vconf value is CONNECTED.
873 If the previous vconf value is ACTIVATED, it means that the Screen Mirroring UG changed that key already. So no need to change it. */
874 if(screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
875 result = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
877 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
879 notification_status_message_post(D_("IDS_SMR_POP_SCREEN_MIRRORING_HAS_BEEN_DISABLED"));
882 __WFD_APP_FUNC_EXIT__;
886 * This function let the app add the notification when it shoule be turned off
888 * @param[in] user_data the pointer to the main data structure
890 void wfd_app_util_add_wfd_turn_off_notification(void *user_data)
892 __WFD_APP_FUNC_ENTER__;
894 int res = NOTIFICATION_ERROR_NONE;
895 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
896 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
898 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
900 /* delete all notifications */
901 wfd_app_util_del_notification(ad);
903 if(ad->noti_wifi_direct_connected!= NULL) {
904 noti_err = notification_free(ad->noti_wifi_direct_connected);
905 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
908 ad->noti_wifi_direct_connected = (notification_h) notification_create(NOTIFICATION_TYPE_ONGOING);
909 WFD_RET_IF(NULL == ad->noti_wifi_direct_connected, "NULL parameters.\n");
911 app_control_h control;
912 res = app_control_create(&control);
913 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
915 app_control_set_package(control, PACKAGE);
916 app_control_add_extra_data(control, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
918 noti_err = notification_set_launch_option(ad->noti_wifi_direct_connected, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
919 if (noti_err != NOTIFICATION_ERROR_NONE) {
920 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_launch_option. [%d]", noti_err);
921 app_control_destroy(control);
925 app_control_destroy(control);
927 noti_err = notification_set_layout(ad->noti_wifi_direct_connected, NOTIFICATION_LY_ONGOING_EVENT);
928 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
931 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Icon Path: %s\n", WFD_NOTI_ICON_PATH);
932 noti_err = notification_set_image(ad->noti_wifi_direct_connected, NOTIFICATION_IMAGE_TYPE_ICON, WFD_NOTI_ICON_PATH);
933 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
935 noti_err = notification_set_display_applist(ad->noti_wifi_direct_connected, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
936 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
938 noti_err = notification_set_text_domain(ad->noti_wifi_direct_connected, LOCALE_FILE_NAME, LOCALEDIR);
939 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text_domain. [%d]", noti_err);
941 /* set the title and content */
942 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_TITLE,
943 D_("IDS_WIFI_BODY_WI_FI_DIRECT_ABB"), "IDS_WIFI_BODY_WI_FI_DIRECT_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
944 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
946 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_CONTENT,
947 D_("IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB"),
948 "IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
949 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
951 /* notify the quick panel */
952 noti_err = notification_insert(ad->noti_wifi_direct_connected, NULL);
953 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
955 __WFD_APP_FUNC_EXIT__;
960 void wfd_app_util_del_wfd_connected_notification(wfd_appdata_t *ad)
962 __WFD_APP_FUNC_ENTER__;
963 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
965 /* delete the notification */
966 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
968 noti_err = notification_delete(ad->noti_wifi_direct_connected);
969 if (noti_err != NOTIFICATION_ERROR_NONE) {
970 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
974 if (ad->noti_wifi_direct_connected) {
975 noti_err = notification_free(ad->noti_wifi_direct_connected);
976 ad->noti_wifi_direct_connected = NULL;
977 if (noti_err != NOTIFICATION_ERROR_NONE) {
978 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
982 __WFD_APP_FUNC_EXIT__;