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__;
115 WFD_RET_IF(data == NULL || key == NULL || type == 0, , "Invialid parameter!");
117 app_control_h control = data;
119 if (type == BUNDLE_TYPE_STR) {
120 bundle_keyval_get_basic_val((bundle_keyval_t *) kv, &ptr, &size);
121 buff = malloc(sizeof(char) * size + 1);
122 snprintf(buff, size + 1, "%s", ((char*) ptr));
123 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR -KEY: %s, VAL: %s, SIZE: %d", key, buff, size);
125 app_control_add_extra_data(control, key, buff);
127 } else if (type == BUNDLE_TYPE_BYTE) {
128 bundle_keyval_get_basic_val((bundle_keyval_t *) kv, &ptr, &size);
129 buff = malloc(sizeof(char) * size + 1);
130 snprintf(buff, size + 1, "%s", ((char*) ptr));
131 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR -KEY: %s, VAL: %s, SIZE: %d", key, buff, size);
133 app_control_add_extra_data(control, key, buff);
135 } else if (type == BUNDLE_TYPE_STR_ARRAY) {
138 unsigned int len = 0;
139 size_t *element_size = NULL;
140 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Found STR_ARRAY -KEY: %s", key);
141 bundle_keyval_get_array_val((bundle_keyval_t *) kv, &array, &len, &element_size);
142 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-Array len: %d", len);
143 for (i = 0; i < len; i++) {
144 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-%s", (char*)array[i]);
146 app_control_add_extra_data(control, key, (char*)array[i]);
150 __WFD_APP_FUNC_EXIT__;
153 static void _launch_app(char *app_id, void *data)
155 __WFD_APP_FUNC_ENTER__;
156 WFD_RET_IF(app_id == NULL || data == NULL, "Invialid parameter!");
158 int ret = APP_CONTROL_ERROR_NONE;
159 app_control_h control = NULL;
160 ret = app_control_create(&control);
161 if (ret != APP_CONTROL_ERROR_NONE) {
162 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_create() return error : %d", ret);
165 WFD_RET_IF(control == NULL, "Failed to create app_control handle!");
167 app_control_set_operation(control, APP_CONTROL_OPERATION_DEFAULT);
168 app_control_set_app_id(control, app_id);
169 bundle_foreach((bundle *)data, _move_data_to_app_control, control);
171 char *launch_type = NULL;
172 bundle_get_str(data, "-t", &launch_type);
173 if (!strcmp(launch_type, "reconnect_by_connecting_wifi_ap"))
174 ret = app_control_send_launch_request(control, __launch_app_result_cb, NULL);
176 ret = app_control_send_launch_request(control, NULL, NULL);
178 if (ret != APP_CONTROL_ERROR_NONE) {
179 WFD_APP_LOG(WFD_APP_LOG_ERROR, "app_control_send_launch_request() is failed : %d", ret);
180 app_control_destroy(control);
183 app_control_destroy(control);
185 __WFD_APP_FUNC_EXIT__;
189 #ifdef WFD_SCREEN_MIRRORING_ENABLED
190 void _add_screen_mirroring_activated_indicator(void *user_data)
192 __WFD_APP_FUNC_ENTER__;
193 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
194 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
195 WFD_RET_IF(ad->noti_screen_mirroring_on, "Indicator noti_screen_mirroring_on already exists");
197 if (ad->noti_screen_mirroring_play) {
198 notification_delete(ad->noti_screen_mirroring_play);
199 notification_free(ad->noti_screen_mirroring_play);
200 ad->noti_screen_mirroring_play = NULL;
203 if (ad->noti_screen_mirroring_on != NULL) {
204 noti_err = notification_free(ad->noti_screen_mirroring_on);
205 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
208 ad->noti_screen_mirroring_on = notification_create(NOTIFICATION_TYPE_ONGOING);
209 WFD_RET_IF(NULL == ad->noti_screen_mirroring_on, "NULL parameters.\n");
211 noti_err = notification_set_image(ad->noti_screen_mirroring_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_ICON_PATH);
212 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
214 noti_err = notification_set_property(ad->noti_screen_mirroring_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
215 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
217 noti_err = notification_set_display_applist(ad->noti_screen_mirroring_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
218 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
220 /* notify the quick panel */
221 noti_err = notification_insert(ad->noti_screen_mirroring_on, NULL);
222 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
224 __WFD_APP_FUNC_EXIT__;
230 #ifdef WFD_SCREEN_MIRRORING_ENABLED
232 * This function let the app add the notification when it is connected
234 * @param[in] user_data the pointer to the main data structure
236 void _add_wfd_peers_connected_notification(void *user_data, char* package_name)
238 __WFD_APP_FUNC_ENTER__;
240 int res = NOTIFICATION_ERROR_NONE;
241 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
242 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
244 WFD_RET_IF(NULL == ad || NULL == package_name, "NULL parameters.\n");
246 if (ad->noti_screen_mirroring_on) {
247 notification_delete(ad->noti_screen_mirroring_on);
248 notification_free(ad->noti_screen_mirroring_on);
249 ad->noti_screen_mirroring_on = NULL;
252 if (ad->noti_screen_mirroring_play != NULL) {
253 noti_err = notification_free(ad->noti_screen_mirroring_play);
254 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
257 ad->noti_screen_mirroring_play = notification_create(NOTIFICATION_TYPE_ONGOING);
258 WFD_RET_IF(NULL == ad->noti_screen_mirroring_play, "NULL parameters.\n");
260 char msg[WFD_MAX_SIZE] = {0};
263 app_control_h control;
264 res = app_control_create(&control);
265 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
267 app_control_set_package(control, package_name);
268 app_control_add_extra_data(control, "-t", "notification");
270 res = notification_set_launch_option(ad->noti_screen_mirroring_play, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
271 if (res != NOTIFICATION_ERROR_NONE) {
272 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to otification_set_launch_option. [%d]", res);
273 app_control_destroy(control);
277 app_control_destroy(control);
279 noti_err = notification_set_layout(ad->noti_screen_mirroring_play, NOTIFICATION_LY_ONGOING_EVENT);
280 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
283 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON, SCREEN_MIRRIONG_NOTI_ICON_PATH);
284 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
286 noti_err = notification_set_image(ad->noti_screen_mirroring_play, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, SCREEN_MIRRIONG_INDICATOR_PLAY_ICON_PATH);
287 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
289 /* set the title and content */
290 wfd_app_get_connected_peers(ad);
291 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_TITLE, D_("IDS_SMR_BODY_SCREEN_MIRRORING_IS_ENABLED"),
292 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
293 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
295 snprintf(msg, WFD_MAX_SIZE, D_("IDS_WIFI_BODY_CONNECTED_TO_PS"), ad->raw_connected_peers[0].ssid);
296 noti_err = notification_set_text(ad->noti_screen_mirroring_play, NOTIFICATION_TEXT_TYPE_CONTENT,
297 msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
298 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
301 notification_set_property(ad->noti_screen_mirroring_play, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
303 /* notify the quick panel */
304 noti_err = notification_insert(ad->noti_screen_mirroring_play, NULL);
305 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
307 __WFD_APP_FUNC_EXIT__;
313 * This function let the app make a change callback for flight mode
315 * @param[in] key the pointer to the key
316 * @param[in] user_data the pointer to the main data structure
318 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
320 __WFD_APP_FUNC_ENTER__;
323 #ifdef WFD_SCREEN_MIRRORING_ENABLED
324 int screen_mirroring_status = 0;
326 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
327 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
329 res = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
331 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get flight state from vconf. [%d]\n", res);
335 if (flight_mode == FALSE) {
336 WFD_APP_LOG(WFD_APP_LOG_LOW, "Flight mode is off\n");
340 /* If flight mode is on, turn off WFD */
341 wifi_direct_get_state(&ad->wfd_status);
342 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
343 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is deactivated.\n");
347 /* If connected, disconnect all devices*/
348 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
349 res = wifi_direct_disconnect_all();
350 if (res != WIFI_DIRECT_ERROR_NONE) {
351 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to send disconnection request to all. [%d]\n", res);
356 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deactivating WiFi DIrect..."
357 "Due to Flight Mode is Enabled\n");
358 res = wifi_direct_deactivate();
359 if (res != WIFI_DIRECT_ERROR_NONE) {
360 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
364 #ifdef WFD_SCREEN_MIRRORING_ENABLED
365 /* checking Screen Mirroring */
366 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
367 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
369 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
371 if (screen_mirroring_status > VCONFKEY_SCREEN_MIRRORING_DEACTIVATED) {
372 res = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
374 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
378 __WFD_APP_FUNC_EXIT__;
381 static void _wfd_cpu_limit_mode_changed(keynode_t *node, void *user_data)
383 __WFD_APP_FUNC_ENTER__;
384 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
385 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
387 int screen_mirroring_status = 0;
388 int cup_limit_mode = 0;
390 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
391 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
395 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
396 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
400 if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
401 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
405 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0) {
406 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
410 if ((power_mode == SETTING_PSMODE_POWERFUL || power_mode == SETTING_PSMODE_ADVISOR) &&
414 bundle_add_str(b, "-t", "notification_power_saving_on");
415 _launch_app(PACKAGE_ALLSHARE_CAST, b);
419 __WFD_APP_FUNC_EXIT__;
423 static void _wfd_power_saving_mode_changed(keynode_t *node, void *user_data)
425 __WFD_APP_FUNC_ENTER__;
426 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
427 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
429 int screen_mirroring_status = 0;
430 int cup_limit_mode = 0;
432 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
433 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
437 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
438 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
442 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_mode) < 0) {
443 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PSMODE\n");
447 if (power_mode == SETTING_PSMODE_SURVIVAL ||
448 power_mode == SETTING_PSMODE_EMERGENCY) {
449 WFD_APP_LOG(WFD_APP_LOG_LOW, "Ultra power saving mode on\n");
452 bundle_add_str(b, "-t", "quit_by_ultra_power_saving_on");
454 _launch_app(PACKAGE_ALLSHARE_CAST, b);
456 } else if (power_mode == SETTING_PSMODE_POWERFUL ||
457 power_mode == SETTING_PSMODE_ADVISOR){
458 if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &cup_limit_mode) < 0) {
459 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU\n");
463 if (cup_limit_mode) {
466 bundle_add_str(b, "-t", "notification_power_saving_on");
467 _launch_app(PACKAGE_ALLSHARE_CAST, b);
472 __WFD_APP_FUNC_EXIT__;
476 static void _wfd_wifi_status_changed(keynode_t *node, void *user_data)
478 __WFD_APP_FUNC_ENTER__;
479 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
480 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
482 #ifdef WFD_SCREEN_MIRRORING_ENABLED
483 int screen_mirroring_status = 0;
485 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0) {
486 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
490 if (screen_mirroring_status != VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
491 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
496 if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0) {
497 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_WIFI_STATE\n");
501 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
502 if (wifi_status == VCONFKEY_WIFI_CONNECTED) {
503 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi is connected\n");
504 #ifdef WFD_SCREEN_MIRRORING_ENABLED
505 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP;
508 bundle_add_str(b, "-t", "reconnect_by_connecting_wifi_ap");
510 _launch_app(PACKAGE_ALLSHARE_CAST, b);
513 } else if (VCONFKEY_WIFI_OFF == wifi_status) {
514 /* Deactivate WiFi Direct */
515 WFD_APP_LOG(WFD_APP_LOG_LOW, "Deactivate WiFi Direct...");
518 * Currently, WiFi Direct OFF is handled at net-config.
519 * Also, this patch is added to support ON-DEMAND launch destroy popup.
520 * This patch will handle 5sec deadlock of popup destroy from
523 /* wfd_app_client_switch_off(ad); */
525 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi state is [%d]\n", wifi_status);
528 __WFD_APP_FUNC_EXIT__;
532 #ifdef WFD_SCREEN_MIRRORING_ENABLED
534 * This function let the app make a change callback for allshare cast
536 * @param[in] key the pointer to the key
537 * @param[in] user_data the pointer to the main data structure
539 static void _wfd_allshare_cast_status_changed(keynode_t *node, void *user_data)
541 __WFD_APP_FUNC_ENTER__;
543 int screen_mirroring_status = 0;
544 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
545 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
547 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
548 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
550 WFD_APP_LOG(WFD_APP_LOG_ERROR, "VCONFKEY_SCREEN_MIRRORING_STATE:%d\n", screen_mirroring_status);
552 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
553 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is connected\n");
554 if (ad->transmit_timer) {
555 ecore_timer_del(ad->transmit_timer);
556 ad->transmit_timer = NULL;
558 /* add connected notification */
559 _add_wfd_peers_connected_notification(ad, PACKAGE_ALLSHARE_CAST);
560 } else if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
561 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is ACTIVATED\n");
562 _add_screen_mirroring_activated_indicator(ad);
564 WFD_APP_LOG(WFD_APP_LOG_LOW, "Allshare cast is not connected\n");
565 if (ad->noti_screen_mirroring_on) {
566 notification_delete(ad->noti_screen_mirroring_on);
567 notification_free(ad->noti_screen_mirroring_on);
568 ad->noti_screen_mirroring_on = NULL;
571 if (ad->noti_screen_mirroring_play) {
572 notification_delete(ad->noti_screen_mirroring_play);
573 notification_free(ad->noti_screen_mirroring_play);
574 ad->noti_screen_mirroring_play = NULL;
580 __WFD_APP_FUNC_EXIT__;
584 static Eina_Bool _wfd_hard_key_down_cb(void *data, int type, void *event)
586 wfd_appdata_t *ad = (wfd_appdata_t *)data;
587 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
590 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Hard Key Pressed CB...");
591 if (NULL == ad || NULL == ev) {
592 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
596 if (!strcmp(ev->keyname, "XF86Home")) {
597 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY]KEY_SELECT pressed");
598 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Mac : %s", ad->mac_addr_connecting);
600 if (strnlen(ad->mac_addr_connecting, MACSTR_LENGTH) > 0) {
601 res = wifi_direct_reject_connection(ad->mac_addr_connecting);
602 if (res != WIFI_DIRECT_ERROR_NONE)
603 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", res);
605 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
608 WFD_APP_LOG(WFD_APP_LOG_HIGH, "[KEY][%s] pressed not Handled",
615 int wfd_app_util_register_hard_key_down_cb(void *data)
617 wfd_appdata_t *ad = (wfd_appdata_t *)data;
620 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
624 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Register hard key down press CB !!!");
625 if (NULL == ad->downkey_handler)
626 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
627 _wfd_hard_key_down_cb, ad);
632 int wfd_app_util_deregister_hard_key_down_cb(void *data)
634 wfd_appdata_t *ad = (wfd_appdata_t *)data;
637 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid AppData parameter");
640 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Deregister hard key down press CB !!!");
641 if (NULL != ad->downkey_handler) {
642 ecore_event_handler_del(ad->downkey_handler);
643 ad->downkey_handler = NULL;
648 int wfd_app_util_register_vconf_callbacks(void *data)
650 wfd_appdata_t *ad = NULL;
654 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Invalid parameter");
660 /* register flight mode */
661 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
662 _wfd_flight_mode_changed, ad);
664 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for flight mode\n");
668 #ifdef WFD_SCREEN_MIRRORING_ENABLED
670 /* TODO: Make proper changes for vconfkey */
671 ret = vconf_notify_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE,
672 _wfd_allshare_cast_status_changed, ad);
674 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for allshare cast\n");
680 ret = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed, ad);
682 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for wifi\n");
687 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed, ad);
689 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for power mode\n");
694 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed, ad);
696 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf callback for cpu limit mode\n");
703 int wfd_app_util_deregister_vconf_callbacks(void *data)
707 /* remove callback for flight mode */
708 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _wfd_flight_mode_changed);
710 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for flight mode\n");
712 #ifdef WFD_SCREEN_MIRRORING_ENABLED
713 /* remove callback for allshare cast */
714 ret = vconf_ignore_key_changed(VCONFKEY_SCREEN_MIRRORING_STATE, _wfd_allshare_cast_status_changed);
716 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for allshare cast\n");
719 /* remove callback for wifi */
720 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_wifi_status_changed);
722 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for wifi\n");
724 /* remove callback for power mode */
725 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, _wfd_power_saving_mode_changed);
727 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for power mode\n");
729 /* remove callback for cpu limit mode */
730 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, _wfd_cpu_limit_mode_changed);
732 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to ignore vconf key callback for cpu limit mode\n");
738 * This function let the app delete the notification
741 void wfd_app_util_del_notification(wfd_appdata_t *ad)
743 __WFD_APP_FUNC_ENTER__;
744 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
746 /* delete the notification */
747 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
749 noti_err = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
750 if (noti_err != NOTIFICATION_ERROR_NONE) {
751 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete_all.(%d)\n", noti_err);
755 #ifdef WFD_SCREEN_MIRRORING_ENABLED
756 if (ad->noti_screen_mirroring_on) {
757 noti_err = notification_free(ad->noti_screen_mirroring_on);
758 ad->noti_screen_mirroring_on = NULL;
759 if (noti_err != NOTIFICATION_ERROR_NONE)
760 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
763 if (ad->noti_screen_mirroring_play) {
764 noti_err = notification_free(ad->noti_screen_mirroring_play);
765 ad->noti_screen_mirroring_play = NULL;
766 if (noti_err != NOTIFICATION_ERROR_NONE)
767 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
771 #ifdef NOT_CONNECTED_INDICATOR_ICON
772 if (ad->noti_wifi_direct_on) {
773 noti_err = notification_free(ad->noti_wifi_direct_on);
774 ad->noti_wifi_direct_on = NULL;
775 if (noti_err != NOTIFICATION_ERROR_NONE)
776 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
780 if (ad->noti_wifi_direct_connected) {
781 noti_err = notification_free(ad->noti_wifi_direct_connected);
782 ad->noti_wifi_direct_connected = NULL;
783 if (noti_err != NOTIFICATION_ERROR_NONE)
784 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
787 __WFD_APP_FUNC_EXIT__;
791 #ifdef NOT_CONNECTED_INDICATOR_ICON
793 * This function let the app add the indicator icon when wfd is activated
795 * @param[in] user_data the pointer to the main data structure
797 void wfd_app_util_add_indicator_icon(void *user_data)
799 __WFD_APP_FUNC_ENTER__;
800 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
801 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
802 WFD_RET_IF(ad->noti_wifi_direct_on, "Indicator already exists");
804 if (ad->noti_wifi_direct_on != NULL) {
805 noti_err = notification_free(ad->noti_wifi_direct_on);
806 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
809 ad->noti_wifi_direct_on = notification_create(NOTIFICATION_TYPE_ONGOING);
810 WFD_RET_IF(NULL == ad->noti_wifi_direct_on, "NULL parameters.\n");
812 noti_err = notification_set_image(ad->noti_wifi_direct_on, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, WFD_ACTIVATED_NOTI_ICON_PATH);
813 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
815 noti_err = notification_set_property(ad->noti_wifi_direct_on, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
816 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_property. [%d]", noti_err);
818 noti_err = notification_set_display_applist(ad->noti_wifi_direct_on, NOTIFICATION_DISPLAY_APP_INDICATOR);
819 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
821 /* notify the quick panel */
822 noti_err = notification_insert(ad->noti_wifi_direct_on, NULL);
823 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
825 __WFD_APP_FUNC_EXIT__;
830 #ifdef WFD_SCREEN_MIRRORING_ENABLED
832 * This function let the app set VCONFKEY_SCREEN_MIRRORING_STATE to be DEACTIVATED
834 void wfd_app_util_set_screen_mirroring_deactivated(wfd_appdata_t *ad)
836 __WFD_APP_FUNC_ENTER__;
837 WFD_RET_IF(NULL == ad, "NULL == ad!\n");
838 int screen_mirroring_status = -1;
841 /* Reconnect by ap connected, no need to set vconf to DEACTIVATED, allshare cast itself will set ACTIVATED*/
842 if (ad->screen_mirroring_state == WFD_POP_SCREEN_MIRROR_DISCONNECT_BY_RECONNECT_WIFI_AP) {
843 ad->screen_mirroring_state = WFD_POP_SCREEN_MIRROR_NONE;
844 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Reconnect screen mirroring by app connected.\n");
848 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
849 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
851 WFD_APP_LOG(WFD_APP_LOG_LOW, "screen_mirroring_status: %d\n", screen_mirroring_status);
852 /* Set the vconf value to DEACTIVATED only when the previous vconf value is CONNECTED.
853 If the previous vconf value is ACTIVATED, it means that the Screen Mirroring UG changed that key already. So no need to change it. */
854 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_CONNECTED) {
855 result = vconf_set_int(VCONFKEY_SCREEN_MIRRORING_STATE, VCONFKEY_SCREEN_MIRRORING_DEACTIVATED);
857 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to set vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
859 notification_status_message_post(D_("IDS_SMR_POP_SCREEN_MIRRORING_HAS_BEEN_DISABLED"));
862 __WFD_APP_FUNC_EXIT__;
866 * This function let the app add the notification when it shoule be turned off
868 * @param[in] user_data the pointer to the main data structure
870 void wfd_app_util_add_wfd_turn_off_notification(void *user_data)
872 __WFD_APP_FUNC_ENTER__;
874 int res = NOTIFICATION_ERROR_NONE;
875 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
876 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
878 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
880 /* delete all notifications */
881 wfd_app_util_del_notification(ad);
883 if (ad->noti_wifi_direct_connected != NULL) {
884 noti_err = notification_free(ad->noti_wifi_direct_connected);
885 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_free. [%d]", noti_err);
888 ad->noti_wifi_direct_connected = (notification_h) notification_create(NOTIFICATION_TYPE_ONGOING);
889 WFD_RET_IF(NULL == ad->noti_wifi_direct_connected, "NULL parameters.\n");
891 app_control_h control;
892 res = app_control_create(&control);
893 WFD_RET_IF(res != APP_CONTROL_ERROR_NONE, "app_control_create() return error : %d", res);
895 app_control_set_app_id(control, PACKAGE);
896 app_control_add_extra_data(control, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
898 noti_err = notification_set_launch_option(ad->noti_wifi_direct_connected, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, control);
899 if (noti_err != NOTIFICATION_ERROR_NONE) {
900 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to notification_set_launch_option. [%d]", noti_err);
901 app_control_destroy(control);
905 app_control_destroy(control);
907 noti_err = notification_set_layout(ad->noti_wifi_direct_connected, NOTIFICATION_LY_ONGOING_EVENT);
908 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_layout. [%d]", noti_err);
911 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Icon Path: %s\n", WFD_NOTI_ICON_PATH);
912 noti_err = notification_set_image(ad->noti_wifi_direct_connected, NOTIFICATION_IMAGE_TYPE_ICON, WFD_NOTI_ICON_PATH);
913 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_image. [%d]", noti_err);
915 noti_err = notification_set_display_applist(ad->noti_wifi_direct_connected, NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
916 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Unable to notification_set_display_applist. [%d]", noti_err);
918 noti_err = notification_set_text_domain(ad->noti_wifi_direct_connected, LOCALE_FILE_NAME, LOCALEDIR);
919 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text_domain. [%d]", noti_err);
921 /* set the title and content */
922 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_TITLE,
923 D_("IDS_WIFI_BODY_WI_FI_DIRECT_ABB"), "IDS_WIFI_BODY_WI_FI_DIRECT_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
924 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
926 noti_err = notification_set_text(ad->noti_wifi_direct_connected, NOTIFICATION_TEXT_TYPE_CONTENT,
927 D_("IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB"),
928 "IDS_WIFI_BODY_DISABLE_WI_FI_DIRECT_AFTER_USE_ABB", NOTIFICATION_VARIABLE_TYPE_NONE);
929 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_set_text. [%d]", noti_err);
931 /* notify the quick panel */
932 noti_err = notification_insert(ad->noti_wifi_direct_connected, NULL);
933 WFD_RET_IF(noti_err != NOTIFICATION_ERROR_NONE, "Failed to notification_insert. [%d]", noti_err);
935 __WFD_APP_FUNC_EXIT__;
940 void wfd_app_util_del_wfd_connected_notification(wfd_appdata_t *ad)
942 __WFD_APP_FUNC_ENTER__;
943 WFD_RET_IF(NULL == ad, "NULL parameters.\n");
945 /* delete the notification */
946 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
948 noti_err = notification_delete(ad->noti_wifi_direct_connected);
949 if (noti_err != NOTIFICATION_ERROR_NONE) {
950 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
954 if (ad->noti_wifi_direct_connected) {
955 noti_err = notification_free(ad->noti_wifi_direct_connected);
956 ad->noti_wifi_direct_connected = NULL;
957 if (noti_err != NOTIFICATION_ERROR_NONE)
958 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
961 __WFD_APP_FUNC_EXIT__;