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);
124 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to allocate memory");
125 __WFD_APP_FUNC_EXIT__;
128 snprintf(buff, size + 1, "%s", ((char*) ptr));
129 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR -KEY: %s, VAL: %s, SIZE: %zu", key, buff, size);
131 app_control_add_extra_data(control, key, buff);
133 } else if (type == BUNDLE_TYPE_BYTE) {
134 bundle_keyval_get_basic_val((bundle_keyval_t *) kv, &ptr, &size);
135 buff = malloc(sizeof(char) * size + 1);
137 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to allocate memory");
138 __WFD_APP_FUNC_EXIT__;
141 snprintf(buff, size + 1, "%s", ((char*) ptr));
142 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR -KEY: %s, VAL: %s, SIZE: %zu", key, buff, size);
144 app_control_add_extra_data(control, key, buff);
146 } else if (type == BUNDLE_TYPE_STR_ARRAY) {
149 unsigned int len = 0;
150 size_t *element_size = NULL;
151 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR_ARRAY -KEY: %s", key);
152 bundle_keyval_get_array_val((bundle_keyval_t *) kv, &array, &len, &element_size);
153 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-Array len: %d", len);
154 for (i = 0; i < len; i++) {
155 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-%s", (char*)array[i]);
157 app_control_add_extra_data(control, key, (char*)array[i]);
161 __WFD_APP_FUNC_EXIT__;
164 static void _launch_app(char *app_id, void *data)
166 __WFD_APP_FUNC_ENTER__;
167 WFD_RET_IF(app_id == NULL || data == NULL, "Invialid parameter!");
169 int ret = APP_CONTROL_ERROR_NONE;
170 app_control_h control = NULL;
171 ret = app_control_create(&control);
172 if (ret != APP_CONTROL_ERROR_NONE) {
173 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_create() return error : %d", ret);
176 WFD_RET_IF(control == NULL, "Failed to create app_control handle!");
178 app_control_set_operation(control, APP_CONTROL_OPERATION_DEFAULT);
179 app_control_set_app_id(control, app_id);
180 bundle_foreach((bundle *)data, _move_data_to_app_control, control);
182 char *launch_type = NULL;
183 bundle_get_str(data, "-t", &launch_type);
184 if (!strcmp(launch_type, "reconnect_by_connecting_wifi_ap"))
185 ret = app_control_send_launch_request(control, __launch_app_result_cb, NULL);
187 ret = app_control_send_launch_request(control, NULL, NULL);
189 if (ret != APP_CONTROL_ERROR_NONE) {
190 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
191 app_control_destroy(control);
194 app_control_destroy(control);
196 __WFD_APP_FUNC_EXIT__;
200 #ifdef WFD_SCREEN_MIRRORING_ENABLED
201 void _add_screen_mirroring_activated_indicator(void *user_data)
203 __WFD_APP_FUNC_ENTER__;
204 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
205 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
206 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
208 if (ad->noti_screen_mirroring_play) {
209 notification_delete(ad->noti_screen_mirroring_play);
210 notification_free(ad->noti_screen_mirroring_play);
211 ad->noti_screen_mirroring_play = NULL;
214 if (ad->noti_screen_mirroring_on != NULL) {
215 noti_err = notification_free(ad->noti_screen_mirroring_on);
216 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
219 ad->noti_screen_mirroring_on = notification_create(NOTIFICATION_TYPE_ONGOING);
220 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
222 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
223 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
225 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
226 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
228 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
229 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
231 /* notify the quick panel */
232 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
233 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
235 __WFD_APP_FUNC_EXIT__;
241 #ifdef WFD_SCREEN_MIRRORING_ENABLED
243 * This function let the app add the notification when it is connected
245 * @param[in] user_data the pointer to the main data structure
247 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
249 __WFD_APP_FUNC_ENTER__;
251 int res = NOTIFICATION_ERROR_NONE;
252 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
253 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
255 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
257 if (ad->noti_screen_mirroring_on) {
258 notification_delete(ad->noti_screen_mirroring_on);
259 notification_free(ad->noti_screen_mirroring_on);
260 ad->noti_screen_mirroring_on = NULL;
263 if (ad->noti_screen_mirroring_play != NULL) {
264 noti_err = notification_free(ad->noti_screen_mirroring_play);
265 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
268 ad->noti_screen_mirroring_play = notification_create(NOTIFICATION_TYPE_ONGOING);
269 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
271 char msg[WFD_MAX_SIZE] = {0};
274 app_control_h control;
275 res = app_control_create(&control);
276 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
278 app_control_set_package(control, package_name);
279 app_control_add_extra_data(control, "-t", "notification");
281 res = notification_set_launch_option(ad->noti_screen_mirroring_play, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
282 if (res != NOTIFICATION_ERROR_NONE) {
283 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to otification_set_launch_option. [%d]", res);
284 app_control_destroy(control);
288 app_control_destroy(control);
290 noti_err = notification_set_layout(ad->noti_screen_mirroring_play, NOTIFICATION_LY_ONGOING_EVENT);
291 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
294 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON, SCREEN_MIRRIONG_NOTI_ICON_PATH);
295 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
297 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_PLAY_ICON_PATH);
298 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
300 /* set the title and content */
301 wfd_app_get_connected_peers(ad);
302 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_TITLE, D_("IDS_SMR_BODY_SCREEN_MIRRORING_IS_ENABLED"),
303 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
304 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
306 snprintf(msg, WFD_MAX_SIZE, D_("IDS_WIFI_BODY_CONNECTED_TO_PS"), ad->raw_connected_peers[0].ssid);
307 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_CONTENT,
308 msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
309 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
312 notification_set_property(ad->noti_screen_mirroring_play, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
314 /* notify the quick panel */
315 noti_err = notification_insert(ad->noti_screen_mirroring_play, NULL);
316 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
318 __WFD_APP_FUNC_EXIT__;
324 * This function let the app make a change callback for flight mode
326 * @param[in] key the pointer to the key
327 * @param[in] user_data the pointer to the main data structure
329 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
331 __WFD_APP_FUNC_ENTER__;
334 #ifdef WFD_SCREEN_MIRRORING_ENABLED
335 int screen_mirroring_status = 0;
337 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
338 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
340 res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
342 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get flight state from vconf. [%d]\n", res);
346 if (flight_mode == FALSE) {
347 WFD_APP_LOG(WFD_APP_LOG_LOW, "Flight mode is off\n");
351 /* If flight mode is on, turn off WFD */
352 wifi_direct_get_state(&ad->wfd_status);
353 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
354 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is deactivated.\n");
358 /* If connected, disconnect all devices*/
359 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
360 res = wifi_direct_disconnect_all();
361 if (res != WIFI_DIRECT_ERROR_NONE) {
362 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to send disconnection request to all. [%d]\n", res);
367 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deactivating WiFi DIrect..."
368 "Due to Flight Mode is Enabled\n");
369 res = wifi_direct_deactivate();
370 if (res != WIFI_DIRECT_ERROR_NONE) {
371 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
375 #ifdef WFD_SCREEN_MIRRORING_ENABLED
376 /* checking Screen Mirroring */
377 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
378 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
380 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
382 if (screen_mirroring_status > VCONFKEY_SCREEN_MIRRORING_DEACTIVATED) {
383 res = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
385 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
389 __WFD_APP_FUNC_EXIT__;
392 static void _wfd_cpu_limit_mode_changed(keynode_t *node, void *user_data)
394 __WFD_APP_FUNC_ENTER__;
395 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
396 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
398 int screen_mirroring_status = 0;
399 int cup_limit_mode = 0;
401 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
402 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
406 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
407 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
411 if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
412 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
416 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0) {
417 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
421 if ((power_mode == SETTING_PSMODE_POWERFUL || power_mode == SETTING_PSMODE_ADVISOR) &&
425 bundle_add_str(b, "-t", "notification_power_saving_on");
426 _launch_app(PACKAGE_ALLSHARE_CAST, b);
430 __WFD_APP_FUNC_EXIT__;
434 static void _wfd_power_saving_mode_changed(keynode_t *node, void *user_data)
436 __WFD_APP_FUNC_ENTER__;
437 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
438 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
440 int screen_mirroring_status = 0;
441 int cup_limit_mode = 0;
443 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
444 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
448 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
449 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
453 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0) {
454 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
458 if (power_mode == SETTING_PSMODE_SURVIVAL ||
459 power_mode == SETTING_PSMODE_EMERGENCY) {
460 WFD_APP_LOG(WFD_APP_LOG_LOW, "Ultra power saving mode on\n");
463 bundle_add_str(b, "-t", "quit_by_ultra_power_saving_on");
465 _launch_app(PACKAGE_ALLSHARE_CAST, b);
467 } else if (power_mode == SETTING_PSMODE_POWERFUL ||
468 power_mode == SETTING_PSMODE_ADVISOR){
469 if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
470 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
474 if (cup_limit_mode) {
477 bundle_add_str(b, "-t", "notification_power_saving_on");
478 _launch_app(PACKAGE_ALLSHARE_CAST, b);
483 __WFD_APP_FUNC_EXIT__;
487 static void _wfd_wifi_status_changed(keynode_t *node, void *user_data)
489 __WFD_APP_FUNC_ENTER__;
490 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
491 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
493 #ifdef WFD_SCREEN_MIRRORING_ENABLED
494 int screen_mirroring_status = 0;
496 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
497 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
501 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
502 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
507 if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0) {
508 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_WIFI_STATE\n");
512 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
513 if (wifi_status == VCONFKEY_WIFI_CONNECTED) {
514 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi is connected\n");
515 #ifdef WFD_SCREEN_MIRRORING_ENABLED
516 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP;
519 bundle_add_str(b, "-t", "reconnect_by_connecting_wifi_ap");
521 _launch_app(PACKAGE_ALLSHARE_CAST, b);
524 } else if (VCONFKEY_WIFI_OFF == wifi_status) {
525 /* Deactivate WiFi Direct */
526 WFD_APP_LOG(WFD_APP_LOG_LOW, "Deactivate WiFi Direct...");
529 * Currently, WiFi Direct OFF is handled at net-config.
530 * Also, this patch is added to support ON-DEMAND launch destroy popup.
531 * This patch will handle 5sec deadlock of popup destroy from
534 /* wfd_app_client_switch_off(ad); */
536 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
539 __WFD_APP_FUNC_EXIT__;
543 #ifdef WFD_SCREEN_MIRRORING_ENABLED
545 * This function let the app make a change callback for allshare cast
547 * @param[in] key the pointer to the key
548 * @param[in] user_data the pointer to the main data structure
550 static void _wfd_allshare_cast_status_changed(keynode_t *node, void *user_data)
552 __WFD_APP_FUNC_ENTER__;
554 int screen_mirroring_status = 0;
555 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
556 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
558 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
559 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
561 WFD_APP_LOG(WFD_APP_LOG_ERROR, "VCONFKEY_SCREEN_MIRRORING_STATE:%d\n", screen_mirroring_status);
563 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
564 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is connected\n");
565 if (ad->transmit_timer) {
566 ecore_timer_del(ad->transmit_timer);
567 ad->transmit_timer = NULL;
569 /* add connected notification */
570 _add_wfd_peers_connected_notification(ad, PACKAGE_ALLSHARE_CAST);
571 } else if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
572 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is ACTIVATED\n");
573 _add_screen_mirroring_activated_indicator(ad);
575 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
576 if (ad->noti_screen_mirroring_on) {
577 notification_delete(ad->noti_screen_mirroring_on);
578 notification_free(ad->noti_screen_mirroring_on);
579 ad->noti_screen_mirroring_on = NULL;
582 if (ad->noti_screen_mirroring_play) {
583 notification_delete(ad->noti_screen_mirroring_play);
584 notification_free(ad->noti_screen_mirroring_play);
585 ad->noti_screen_mirroring_play = NULL;
591 __WFD_APP_FUNC_EXIT__;
595 static Eina_Bool _wfd_hard_key_down_cb(void *data, int type, void *event)
597 wfd_appdata_t *ad = (wfd_appdata_t *)data;
598 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
601 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Hard Key Pressed CB...");
602 if (NULL == ad || NULL == ev) {
603 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
607 if (!strcmp(ev->keyname, "XF86Home")) {
608 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY]KEY_SELECT pressed");
609 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Mac : %s", ad->mac_addr_connecting);
611 if (strnlen(ad->mac_addr_connecting, MACSTR_LENGTH) > 0) {
612 res = wifi_direct_reject_connection(ad->mac_addr_connecting);
613 if (res != WIFI_DIRECT_ERROR_NONE)
614 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", res);
616 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
619 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY][%s] pressed not Handled",
626 int wfd_app_util_register_hard_key_down_cb(void *data)
628 wfd_appdata_t *ad = (wfd_appdata_t *)data;
631 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
635 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Register hard key down press CB !!!");
636 if (NULL == ad->downkey_handler)
637 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
638 _wfd_hard_key_down_cb, ad);
643 int wfd_app_util_deregister_hard_key_down_cb(void *data)
645 wfd_appdata_t *ad = (wfd_appdata_t *)data;
648 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
651 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deregister hard key down press CB !!!");
652 if (NULL != ad->downkey_handler) {
653 ecore_event_handler_del(ad->downkey_handler);
654 ad->downkey_handler = NULL;
659 int wfd_app_util_register_vconf_callbacks(void *data)
661 wfd_appdata_t *ad = NULL;
665 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid parameter");
671 /* register flight mode */
672 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
673 _wfd_flight_mode_changed, ad);
675 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for flight mode\n");
679 #ifdef WFD_SCREEN_MIRRORING_ENABLED
681 /* TODO: Make proper changes for vconfkey */
682 ret = vconf_notify_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE,
683 _wfd_allshare_cast_status_changed, ad);
685 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for allshare cast\n");
691 ret = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed, ad);
693 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for wifi\n");
698 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed, ad);
700 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for power mode\n");
705 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed, ad);
707 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for cpu limit mode\n");
714 int wfd_app_util_deregister_vconf_callbacks(void *data)
718 /* remove callback for flight mode */
719 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _wfd_flight_mode_changed);
721 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");
730 /* remove callback for wifi */
731 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed);
733 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for wifi\n");
735 /* remove callback for power mode */
736 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed);
738 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for power mode\n");
740 /* remove callback for cpu limit mode */
741 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed);
743 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for cpu limit mode\n");
749 * This function let the app delete the notification
752 void wfd_app_util_del_notification(wfd_appdata_t *ad)
754 __WFD_APP_FUNC_ENTER__;
755 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
757 /* delete the notification */
758 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
760 noti_err = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
761 if (noti_err != NOTIFICATION_ERROR_NONE) {
762 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all.(%d)\n", noti_err);
766 #ifdef WFD_SCREEN_MIRRORING_ENABLED
767 if (ad->noti_screen_mirroring_on) {
768 noti_err = notification_free(ad->noti_screen_mirroring_on);
769 ad->noti_screen_mirroring_on = NULL;
770 if (noti_err != NOTIFICATION_ERROR_NONE)
771 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
774 if (ad->noti_screen_mirroring_play) {
775 noti_err = notification_free(ad->noti_screen_mirroring_play);
776 ad->noti_screen_mirroring_play = NULL;
777 if (noti_err != NOTIFICATION_ERROR_NONE)
778 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
782 #ifdef NOT_CONNECTED_INDICATOR_ICON
783 if (ad->noti_wifi_direct_on) {
784 noti_err = notification_free(ad->noti_wifi_direct_on);
785 ad->noti_wifi_direct_on = NULL;
786 if (noti_err != NOTIFICATION_ERROR_NONE)
787 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
791 if (ad->noti_wifi_direct_connected) {
792 noti_err = notification_free(ad->noti_wifi_direct_connected);
793 ad->noti_wifi_direct_connected = NULL;
794 if (noti_err != NOTIFICATION_ERROR_NONE)
795 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
798 __WFD_APP_FUNC_EXIT__;
802 #ifdef NOT_CONNECTED_INDICATOR_ICON
804 * This function let the app add the indicator icon when wfd is activated
806 * @param[in] user_data the pointer to the main data structure
808 void wfd_app_util_add_indicator_icon(void *user_data)
810 __WFD_APP_FUNC_ENTER__;
811 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
812 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
813 WFD_RET_IF(ad->noti_wifi_direct_on, "Indicator already exists");
815 if (ad->noti_wifi_direct_on != NULL) {
816 noti_err = notification_free(ad->noti_wifi_direct_on);
817 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
820 ad->noti_wifi_direct_on = notification_create(NOTIFICATION_TYPE_ONGOING);
821 WFD_RET_IF(NULL == ad->noti_wifi_direct_on, "NULL parameters.\n");
823 noti_err = notification_set_image(ad->noti_wifi_direct_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, WFD_ACTIVATED_NOTI_ICON_PATH);
824 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
826 noti_err = notification_set_property(ad->noti_wifi_direct_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
827 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
829 noti_err = notification_set_display_applist(ad->noti_wifi_direct_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
830 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
832 /* notify the quick panel */
833 noti_err = notification_insert(ad->noti_wifi_direct_on, NULL);
834 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
836 __WFD_APP_FUNC_EXIT__;
841 #ifdef WFD_SCREEN_MIRRORING_ENABLED
843 * This function let the app set VCONFKEY_SCREEN_MIRRORING_STATE to be DEACTIVATED
845 void wfd_app_util_set_screen_mirroring_deactivated(wfd_appdata_t *ad)
847 __WFD_APP_FUNC_ENTER__;
848 WFD_RET_IF(NULL == ad, "NULL == ad!\n");
849 int screen_mirroring_status = -1;
852 /* Reconnect by ap connected, no need to set vconf to DEACTIVATED, allshare cast itself will set ACTIVATED*/
853 if (ad->screen_mirroring_state == WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP) {
854 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
855 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Reconnect screen mirroring by app connected.\n");
859 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
860 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
862 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
863 /* Set the vconf value to DEACTIVATED only when the previous vconf value is CONNECTED.
864 If the previous vconf value is ACTIVATED, it means that the Screen Mirroring UG changed that key already. So no need to change it. */
865 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
866 result = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
868 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
870 notification_status_message_post(D_("IDS_SMR_POP_SCREEN_MIRRORING_HAS_BEEN_DISABLED"));
873 __WFD_APP_FUNC_EXIT__;
877 * This function let the app add the notification when it shoule be turned off
879 * @param[in] user_data the pointer to the main data structure
881 void wfd_app_util_add_wfd_turn_off_notification(void *user_data)
883 __WFD_APP_FUNC_ENTER__;
885 int res = NOTIFICATION_ERROR_NONE;
886 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
887 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
889 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
891 /* delete all notifications */
892 wfd_app_util_del_notification(ad);
894 if (ad->noti_wifi_direct_connected != NULL) {
895 noti_err = notification_free(ad->noti_wifi_direct_connected);
896 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
899 ad->noti_wifi_direct_connected = (notification_h) notification_create(NOTIFICATION_TYPE_ONGOING);
900 WFD_RET_IF(NULL == ad->noti_wifi_direct_connected, "NULL parameters.\n");
902 app_control_h control;
903 res = app_control_create(&control);
904 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
906 app_control_set_app_id(control, PACKAGE);
907 app_control_add_extra_data(control, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
909 noti_err = notification_set_launch_option(ad->noti_wifi_direct_connected, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
910 if (noti_err != NOTIFICATION_ERROR_NONE) {
911 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_launch_option. [%d]", noti_err);
912 app_control_destroy(control);
916 app_control_destroy(control);
918 noti_err = notification_set_layout(ad->noti_wifi_direct_connected, NOTIFICATION_LY_ONGOING_EVENT);
919 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
922 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Icon Path: %s\n", WFD_NOTI_ICON_PATH);
923 noti_err = notification_set_image(ad->noti_wifi_direct_connected, NOTIFICATION_IMAGE_TYPE_ICON, WFD_NOTI_ICON_PATH);
924 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
926 noti_err = notification_set_display_applist(ad->noti_wifi_direct_connected, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
927 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
929 noti_err = notification_set_text_domain(ad->noti_wifi_direct_connected, LOCALE_FILE_NAME, LOCALEDIR);
930 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text_domain. [%d]", noti_err);
932 /* set the title and content */
933 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_TITLE,
934 D_("IDS_WIFI_BODY_WI_FI_DIRECT_ABB"), "IDS_WIFI_BODY_WI_FI_DIRECT_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
935 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
937 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_CONTENT,
938 D_("IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB"),
939 "IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
940 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
942 /* notify the quick panel */
943 noti_err = notification_insert(ad->noti_wifi_direct_connected, NULL);
944 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
946 __WFD_APP_FUNC_EXIT__;
951 void wfd_app_util_del_wfd_connected_notification(wfd_appdata_t *ad)
953 __WFD_APP_FUNC_ENTER__;
954 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
956 /* delete the notification */
957 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
959 noti_err = notification_delete(ad->noti_wifi_direct_connected);
960 if (noti_err != NOTIFICATION_ERROR_NONE) {
961 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
965 if (ad->noti_wifi_direct_connected) {
966 noti_err = notification_free(ad->noti_wifi_direct_connected);
967 ad->noti_wifi_direct_connected = NULL;
968 if (noti_err != NOTIFICATION_ERROR_NONE)
969 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
972 __WFD_APP_FUNC_EXIT__;