4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (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));
74 strncpy((char *) filename + start, strptr, 50);
76 return (char *) filename;
84 return syscall(__NR_gettid);
86 fprintf(stderr, "__NR_gettid is not defined, please include linux/unistd.h ");
91 static void __launch_app_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *data)
93 __WFD_APP_FUNC_ENTER__;
95 if (result == APP_CONTROL_RESULT_FAILED) {
96 WFD_APP_LOG(WFD_APP_LOG_ERROR, "User cancel to reconnect screen mirroring\n");
97 #ifdef WFD_SCREEN_MIRRORING_ENABLED
98 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
101 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control launch result: [%d]\n", result);
104 __WFD_APP_FUNC_EXIT__;
107 static void _move_data_to_app_control(const char *key, const int type,
108 const bundle_keyval_t *kv, void *data)
110 __WFD_APP_FUNC_ENTER__;
116 WFD_RET_IF(data == NULL || key == NULL || type == 0, , "Invialid parameter!");
118 app_control_h control = data;
120 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);
179 if (ret != APP_CONTROL_ERROR_NONE) {
180 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
181 app_control_destroy(control);
184 app_control_destroy(control);
186 __WFD_APP_FUNC_EXIT__;
190 #ifdef WFD_SCREEN_MIRRORING_ENABLED
191 void _add_screen_mirroring_activated_indicator(void *user_data)
193 __WFD_APP_FUNC_ENTER__;
194 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
195 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
196 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
198 if (ad->noti_screen_mirroring_play) {
199 notification_delete(ad->noti_screen_mirroring_play);
200 notification_free(ad->noti_screen_mirroring_play);
201 ad->noti_screen_mirroring_play = NULL;
204 if (ad->noti_screen_mirroring_on != NULL) {
205 noti_err = notification_free(ad->noti_screen_mirroring_on);
206 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
209 ad->noti_screen_mirroring_on = notification_create(NOTIFICATION_TYPE_ONGOING);
210 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
212 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
213 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
215 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
216 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
218 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
219 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
221 /* notify the quick panel */
222 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
223 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
225 __WFD_APP_FUNC_EXIT__;
231 #ifdef WFD_SCREEN_MIRRORING_ENABLED
233 * This function let the app add the notification when it is connected
235 * @param[in] user_data the pointer to the main data structure
237 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
239 __WFD_APP_FUNC_ENTER__;
241 int res = NOTIFICATION_ERROR_NONE;
242 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
243 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
245 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
247 if (ad->noti_screen_mirroring_on) {
248 notification_delete(ad->noti_screen_mirroring_on);
249 notification_free(ad->noti_screen_mirroring_on);
250 ad->noti_screen_mirroring_on = NULL;
253 if (ad->noti_screen_mirroring_play != NULL) {
254 noti_err = notification_free(ad->noti_screen_mirroring_play);
255 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
258 ad->noti_screen_mirroring_play = notification_create(NOTIFICATION_TYPE_ONGOING);
259 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
261 char msg[WFD_MAX_SIZE] = {0};
264 app_control_h control;
265 res = app_control_create(&control);
266 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
268 app_control_set_package(control, package_name);
269 app_control_add_extra_data(control, "-t", "notification");
271 res = notification_set_launch_option(ad->noti_screen_mirroring_play, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
272 if (res != NOTIFICATION_ERROR_NONE) {
273 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to otification_set_launch_option. [%d]", res);
274 app_control_destroy(control);
278 app_control_destroy(control);
280 noti_err = notification_set_layout(ad->noti_screen_mirroring_play, NOTIFICATION_LY_ONGOING_EVENT);
281 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
284 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON, SCREEN_MIRRIONG_NOTI_ICON_PATH);
285 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
287 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_PLAY_ICON_PATH);
288 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
290 /* set the title and content */
291 wfd_app_get_connected_peers(ad);
292 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_TITLE, D_("IDS_SMR_BODY_SCREEN_MIRRORING_IS_ENABLED"),
293 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
294 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
296 snprintf(msg, WFD_MAX_SIZE, D_("IDS_WIFI_BODY_CONNECTED_TO_PS"), ad->raw_connected_peers[0].ssid);
297 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_CONTENT,
298 msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
299 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
302 notification_set_property(ad->noti_screen_mirroring_play, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
304 /* notify the quick panel */
305 noti_err = notification_insert(ad->noti_screen_mirroring_play, NULL);
306 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
308 __WFD_APP_FUNC_EXIT__;
314 * This function let the app make a change callback for flight mode
316 * @param[in] key the pointer to the key
317 * @param[in] user_data the pointer to the main data structure
319 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
321 __WFD_APP_FUNC_ENTER__;
324 #ifdef WFD_SCREEN_MIRRORING_ENABLED
325 int screen_mirroring_status = 0;
327 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
328 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
330 res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
332 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get flight state from vconf. [%d]\n", res);
336 if (flight_mode == FALSE) {
337 WFD_APP_LOG(WFD_APP_LOG_LOW, "Flight mode is off\n");
341 /* If flight mode is on, turn off WFD */
342 wifi_direct_get_state(&ad->wfd_status);
343 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
344 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is deactivated.\n");
348 /* If connected, disconnect all devices*/
349 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
350 res = wifi_direct_disconnect_all();
351 if (res != WIFI_DIRECT_ERROR_NONE) {
352 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to send disconnection request to all. [%d]\n", res);
357 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deactivating WiFi DIrect..."
358 "Due to Flight Mode is Enabled\n");
359 res = wifi_direct_deactivate();
360 if (res != WIFI_DIRECT_ERROR_NONE) {
361 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
365 #ifdef WFD_SCREEN_MIRRORING_ENABLED
366 /* checking Screen Mirroring */
367 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
368 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
370 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
372 if (screen_mirroring_status > VCONFKEY_SCREEN_MIRRORING_DEACTIVATED) {
373 res = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
375 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
379 __WFD_APP_FUNC_EXIT__;
382 static void _wfd_cpu_limit_mode_changed(keynode_t *node, void *user_data)
384 __WFD_APP_FUNC_ENTER__;
385 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
386 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
388 int screen_mirroring_status = 0;
389 int cup_limit_mode = 0;
391 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
392 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
396 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
397 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
401 if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
402 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
406 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0) {
407 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
411 if ((power_mode == SETTING_PSMODE_POWERFUL || power_mode == SETTING_PSMODE_ADVISOR) &&
415 bundle_add_str(b, "-t", "notification_power_saving_on");
416 _launch_app(PACKAGE_ALLSHARE_CAST, b);
420 __WFD_APP_FUNC_EXIT__;
424 static void _wfd_power_saving_mode_changed(keynode_t *node, void *user_data)
426 __WFD_APP_FUNC_ENTER__;
427 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
428 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
430 int screen_mirroring_status = 0;
431 int cup_limit_mode = 0;
433 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
434 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
438 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
439 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
443 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0) {
444 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
448 if (power_mode == SETTING_PSMODE_SURVIVAL ||
449 power_mode == SETTING_PSMODE_EMERGENCY) {
450 WFD_APP_LOG(WFD_APP_LOG_LOW, "Ultra power saving mode on\n");
453 bundle_add_str(b, "-t", "quit_by_ultra_power_saving_on");
455 _launch_app(PACKAGE_ALLSHARE_CAST, b);
457 } else if (power_mode == SETTING_PSMODE_POWERFUL ||
458 power_mode == SETTING_PSMODE_ADVISOR){
459 if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
460 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
464 if (cup_limit_mode) {
467 bundle_add_str(b, "-t", "notification_power_saving_on");
468 _launch_app(PACKAGE_ALLSHARE_CAST, b);
473 __WFD_APP_FUNC_EXIT__;
477 static void _wfd_wifi_status_changed(keynode_t *node, void *user_data)
479 __WFD_APP_FUNC_ENTER__;
480 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
481 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
483 #ifdef WFD_SCREEN_MIRRORING_ENABLED
484 int screen_mirroring_status = 0;
486 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
487 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
491 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
492 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
497 if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0) {
498 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_WIFI_STATE\n");
502 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
503 if (wifi_status == VCONFKEY_WIFI_CONNECTED) {
504 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi is connected\n");
505 #ifdef WFD_SCREEN_MIRRORING_ENABLED
506 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP;
509 bundle_add_str(b, "-t", "reconnect_by_connecting_wifi_ap");
511 _launch_app(PACKAGE_ALLSHARE_CAST, b);
514 } else if (VCONFKEY_WIFI_OFF == wifi_status) {
515 /* Deactivate WiFi Direct */
516 WFD_APP_LOG(WFD_APP_LOG_LOW, "Deactivate WiFi Direct...");
519 * Currently, WiFi Direct OFF is handled at net-config.
520 * Also, this patch is added to support ON-DEMAND launch destroy popup.
521 * This patch will handle 5sec deadlock of popup destroy from
524 /* wfd_app_client_switch_off(ad); */
526 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
529 __WFD_APP_FUNC_EXIT__;
533 #ifdef WFD_SCREEN_MIRRORING_ENABLED
535 * This function let the app make a change callback for allshare cast
537 * @param[in] key the pointer to the key
538 * @param[in] user_data the pointer to the main data structure
540 static void _wfd_allshare_cast_status_changed(keynode_t *node, void *user_data)
542 __WFD_APP_FUNC_ENTER__;
544 int screen_mirroring_status = 0;
545 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
546 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
548 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
549 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
551 WFD_APP_LOG(WFD_APP_LOG_ERROR, "VCONFKEY_SCREEN_MIRRORING_STATE:%d\n", screen_mirroring_status);
553 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
554 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is connected\n");
555 if (ad->transmit_timer) {
556 ecore_timer_del(ad->transmit_timer);
557 ad->transmit_timer = NULL;
559 /* add connected notification */
560 _add_wfd_peers_connected_notification(ad, PACKAGE_ALLSHARE_CAST);
561 } else if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
562 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is ACTIVATED\n");
563 _add_screen_mirroring_activated_indicator(ad);
565 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
566 if (ad->noti_screen_mirroring_on) {
567 notification_delete(ad->noti_screen_mirroring_on);
568 notification_free(ad->noti_screen_mirroring_on);
569 ad->noti_screen_mirroring_on = NULL;
572 if (ad->noti_screen_mirroring_play) {
573 notification_delete(ad->noti_screen_mirroring_play);
574 notification_free(ad->noti_screen_mirroring_play);
575 ad->noti_screen_mirroring_play = NULL;
581 __WFD_APP_FUNC_EXIT__;
585 static Eina_Bool _wfd_hard_key_down_cb(void *data, int type, void *event)
587 wfd_appdata_t *ad = (wfd_appdata_t *)data;
588 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
591 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Hard Key Pressed CB...");
592 if (NULL == ad || NULL == ev) {
593 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
597 if (!strcmp(ev->keyname, "XF86Home")) {
598 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY]KEY_SELECT pressed");
599 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Mac : %s", ad->mac_addr_connecting);
601 if (strnlen(ad->mac_addr_connecting, MACSTR_LENGTH) > 0) {
602 res = wifi_direct_reject_connection(ad->mac_addr_connecting);
603 if (res != WIFI_DIRECT_ERROR_NONE)
604 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", res);
606 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
609 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY][%s] pressed not Handled",
616 int wfd_app_util_register_hard_key_down_cb(void *data)
618 wfd_appdata_t *ad = (wfd_appdata_t *)data;
621 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
625 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Register hard key down press CB !!!");
626 if (NULL == ad->downkey_handler)
627 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
628 _wfd_hard_key_down_cb, ad);
633 int wfd_app_util_deregister_hard_key_down_cb(void *data)
635 wfd_appdata_t *ad = (wfd_appdata_t *)data;
638 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
641 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deregister hard key down press CB !!!");
642 if (NULL != ad->downkey_handler) {
643 ecore_event_handler_del(ad->downkey_handler);
644 ad->downkey_handler = NULL;
649 int wfd_app_util_register_vconf_callbacks(void *data)
651 wfd_appdata_t *ad = NULL;
655 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid parameter");
661 /* register flight mode */
662 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
663 _wfd_flight_mode_changed, ad);
665 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for flight mode\n");
669 #ifdef WFD_SCREEN_MIRRORING_ENABLED
671 /* TODO: Make proper changes for vconfkey */
672 ret = vconf_notify_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE,
673 _wfd_allshare_cast_status_changed, ad);
675 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for allshare cast\n");
681 ret = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed, ad);
683 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for wifi\n");
688 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed, ad);
690 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for power mode\n");
695 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed, ad);
697 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for cpu limit mode\n");
704 int wfd_app_util_deregister_vconf_callbacks(void *data)
708 /* remove callback for flight mode */
709 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _wfd_flight_mode_changed);
711 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for flight mode\n");
713 #ifdef WFD_SCREEN_MIRRORING_ENABLED
714 /* remove callback for allshare cast */
715 ret = vconf_ignore_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE, _wfd_allshare_cast_status_changed);
717 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for allshare cast\n");
720 /* remove callback for wifi */
721 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed);
723 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for wifi\n");
725 /* remove callback for power mode */
726 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed);
728 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for power mode\n");
730 /* remove callback for cpu limit mode */
731 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed);
733 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for cpu limit mode\n");
739 * This function let the app delete the notification
742 void wfd_app_util_del_notification(wfd_appdata_t *ad)
744 __WFD_APP_FUNC_ENTER__;
745 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
747 /* delete the notification */
748 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
750 noti_err = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
751 if (noti_err != NOTIFICATION_ERROR_NONE) {
752 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all.(%d)\n", noti_err);
756 #ifdef WFD_SCREEN_MIRRORING_ENABLED
757 if (ad->noti_screen_mirroring_on) {
758 noti_err = notification_free(ad->noti_screen_mirroring_on);
759 ad->noti_screen_mirroring_on = NULL;
760 if (noti_err != NOTIFICATION_ERROR_NONE)
761 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
764 if (ad->noti_screen_mirroring_play) {
765 noti_err = notification_free(ad->noti_screen_mirroring_play);
766 ad->noti_screen_mirroring_play = NULL;
767 if (noti_err != NOTIFICATION_ERROR_NONE)
768 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
772 #ifdef NOT_CONNECTED_INDICATOR_ICON
773 if (ad->noti_wifi_direct_on) {
774 noti_err = notification_free(ad->noti_wifi_direct_on);
775 ad->noti_wifi_direct_on = NULL;
776 if (noti_err != NOTIFICATION_ERROR_NONE)
777 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
781 if (ad->noti_wifi_direct_connected) {
782 noti_err = notification_free(ad->noti_wifi_direct_connected);
783 ad->noti_wifi_direct_connected = NULL;
784 if (noti_err != NOTIFICATION_ERROR_NONE)
785 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
788 __WFD_APP_FUNC_EXIT__;
792 #ifdef NOT_CONNECTED_INDICATOR_ICON
794 * This function let the app add the indicator icon when wfd is activated
796 * @param[in] user_data the pointer to the main data structure
798 void wfd_app_util_add_indicator_icon(void *user_data)
800 __WFD_APP_FUNC_ENTER__;
801 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
802 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
803 WFD_RET_IF(ad->noti_wifi_direct_on, "Indicator already exists");
805 if (ad->noti_wifi_direct_on != NULL) {
806 noti_err = notification_free(ad->noti_wifi_direct_on);
807 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
810 ad->noti_wifi_direct_on = notification_create(NOTIFICATION_TYPE_ONGOING);
811 WFD_RET_IF(NULL == ad->noti_wifi_direct_on, "NULL parameters.\n");
813 noti_err = notification_set_image(ad->noti_wifi_direct_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, WFD_ACTIVATED_NOTI_ICON_PATH);
814 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
816 noti_err = notification_set_property(ad->noti_wifi_direct_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
817 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
819 noti_err = notification_set_display_applist(ad->noti_wifi_direct_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
820 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
822 /* notify the quick panel */
823 noti_err = notification_insert(ad->noti_wifi_direct_on, NULL);
824 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
826 __WFD_APP_FUNC_EXIT__;
831 #ifdef WFD_SCREEN_MIRRORING_ENABLED
833 * This function let the app set VCONFKEY_SCREEN_MIRRORING_STATE to be DEACTIVATED
835 void wfd_app_util_set_screen_mirroring_deactivated(wfd_appdata_t *ad)
837 __WFD_APP_FUNC_ENTER__;
838 WFD_RET_IF(NULL == ad, "NULL == ad!\n");
839 int screen_mirroring_status = -1;
842 /* Reconnect by ap connected, no need to set vconf to DEACTIVATED, allshare cast itself will set ACTIVATED*/
843 if (ad->screen_mirroring_state == WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP) {
844 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
845 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Reconnect screen mirroring by app connected.\n");
849 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
850 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
852 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
853 /* Set the vconf value to DEACTIVATED only when the previous vconf value is CONNECTED.
854 If the previous vconf value is ACTIVATED, it means that the Screen Mirroring UG changed that key already. So no need to change it. */
855 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
856 result = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
858 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
860 notification_status_message_post(D_("IDS_SMR_POP_SCREEN_MIRRORING_HAS_BEEN_DISABLED"));
863 __WFD_APP_FUNC_EXIT__;
867 * This function let the app add the notification when it shoule be turned off
869 * @param[in] user_data the pointer to the main data structure
871 void wfd_app_util_add_wfd_turn_off_notification(void *user_data)
873 __WFD_APP_FUNC_ENTER__;
875 int res = NOTIFICATION_ERROR_NONE;
876 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
877 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
879 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
881 /* delete all notifications */
882 wfd_app_util_del_notification(ad);
884 if (ad->noti_wifi_direct_connected != NULL) {
885 noti_err = notification_free(ad->noti_wifi_direct_connected);
886 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
889 ad->noti_wifi_direct_connected = (notification_h) notification_create(NOTIFICATION_TYPE_ONGOING);
890 WFD_RET_IF(NULL == ad->noti_wifi_direct_connected, "NULL parameters.\n");
892 app_control_h control;
893 res = app_control_create(&control);
894 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
896 app_control_set_app_id(control, PACKAGE);
897 app_control_add_extra_data(control, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
899 noti_err = notification_set_launch_option(ad->noti_wifi_direct_connected, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
900 if (noti_err != NOTIFICATION_ERROR_NONE) {
901 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_launch_option. [%d]", noti_err);
902 app_control_destroy(control);
906 app_control_destroy(control);
908 noti_err = notification_set_layout(ad->noti_wifi_direct_connected, NOTIFICATION_LY_ONGOING_EVENT);
909 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
912 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Icon Path: %s\n", WFD_NOTI_ICON_PATH);
913 noti_err = notification_set_image(ad->noti_wifi_direct_connected, NOTIFICATION_IMAGE_TYPE_ICON, WFD_NOTI_ICON_PATH);
914 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
916 noti_err = notification_set_display_applist(ad->noti_wifi_direct_connected, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
917 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
919 noti_err = notification_set_text_domain(ad->noti_wifi_direct_connected, LOCALE_FILE_NAME, LOCALEDIR);
920 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text_domain. [%d]", noti_err);
922 /* set the title and content */
923 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_TITLE,
924 D_("IDS_WIFI_BODY_WI_FI_DIRECT_ABB"), "IDS_WIFI_BODY_WI_FI_DIRECT_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
925 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
927 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_CONTENT,
928 D_("IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB"),
929 "IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
930 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
932 /* notify the quick panel */
933 noti_err = notification_insert(ad->noti_wifi_direct_connected, NULL);
934 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
936 __WFD_APP_FUNC_EXIT__;
941 void wfd_app_util_del_wfd_connected_notification(wfd_appdata_t *ad)
943 __WFD_APP_FUNC_ENTER__;
944 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
946 /* delete the notification */
947 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
949 noti_err = notification_delete(ad->noti_wifi_direct_connected);
950 if (noti_err != NOTIFICATION_ERROR_NONE) {
951 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
955 if (ad->noti_wifi_direct_connected) {
956 noti_err = notification_free(ad->noti_wifi_direct_connected);
957 ad->noti_wifi_direct_connected = NULL;
958 if (noti_err != NOTIFICATION_ERROR_NONE)
959 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
962 __WFD_APP_FUNC_EXIT__;