2 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #ifdef SCREEN_READER_MOBILE
23 #include <device/battery.h>
24 #include <device/display.h>
25 #include <device/callback.h>
26 #include <bluetooth.h>
27 #include <tapi_common.h>
28 #include <TelNetwork.h>
31 #include <notification.h>
32 #include <notification_list.h>
34 #include "screen_reader.h"
35 #include "screen_reader_tts.h"
36 #include "smart_notification.h"
39 #define MAX_SIM_COUNT 2
40 #define DATE_TIME_BUFFER_SIZE 26
42 TapiHandle *tapi_handle[MAX_SIM_COUNT + 1] = {0, };
44 static void device_system_cb(device_callback_e type, void *value, void *user_data);
47 static void tapi_init(void)
50 char **cp_list = tel_get_cp_name_list();
54 ERROR("cp name list is null");
59 for(i = 0; cp_list[i]; ++i)
61 tapi_handle[i] = tel_init(cp_list[i]);
62 DEBUG("CP_LIST %d = %s", i, cp_list[i]);
68 * @brief Initializer for smart notifications
71 void system_notifications_init(void)
73 DEBUG("******************** START ********************");
77 device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb, NULL);
78 // BATTERY CHARGING/NOT-CHARGING
79 device_add_callback(DEVICE_CALLBACK_BATTERY_CHARGING, device_system_cb, NULL);
81 device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb, NULL);
83 ret = bt_initialize();
84 if (ret != BT_ERROR_NONE)
86 ERROR("ret == %d", ret);
89 ret = wifi_initialize();
90 if (ret != WIFI_ERROR_NONE)
92 ERROR("ret == %d", ret);
98 DEBUG(" ********************* END ********************* ");
102 * @brief Initializer for smart notifications
105 void system_notifications_shutdown(void)
110 device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb);
111 // BATTERY CHARGING/NOT-CHARGING
112 device_remove_callback(DEVICE_CALLBACK_BATTERY_CHARGING, device_system_cb);
114 device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb);
116 ret = bt_deinitialize();
117 if (ret != BT_ERROR_NONE)
119 ERROR("ret == %d", ret);
122 ret = wifi_deinitialize();
123 if (ret != WIFI_ERROR_NONE)
125 ERROR("ret == %d", ret);
131 * @brief Device system callback handler
133 * @param type Device callback type
134 * @param value UNUSED
135 * @param user_data UNUSED
137 static void device_system_cb(device_callback_e type, void *value, void *user_data)
139 if(type == DEVICE_CALLBACK_BATTERY_LEVEL)
141 device_battery_level_e status;
142 if(device_battery_get_level_status(&status))
144 ERROR("Cannot get battery level status");
148 if(status == DEVICE_BATTERY_LEVEL_LOW)
150 tts_speak(_("IDS_SYSTEM_BATTERY_LOW"), EINA_TRUE);
152 else if(status == DEVICE_BATTERY_LEVEL_CRITICAL)
154 tts_speak(_("IDS_SYSTEM_BATTERY_CRITICAL"), EINA_TRUE);
156 else if(status == DEVICE_BATTERY_LEVEL_FULL)
158 tts_speak(_("IDS_SYSTEM_BATTERY_FULL"), EINA_TRUE);
161 else if(type == DEVICE_CALLBACK_BATTERY_CHARGING)
164 if(device_battery_is_charging(&charging))
166 ERROR("Cannot check if battery is charging");
172 tts_speak(_("IDS_SYSTEM_CHARGING"), EINA_FALSE);
176 tts_speak(_("IDS_SYSTEM_NOT_CHARGING"), EINA_FALSE);
179 else if(type == DEVICE_CALLBACK_DISPLAY_STATE)
181 display_state_e state;
182 if(device_display_get_state(&state))
184 ERROR("Cannot check if battery is charging");
188 if(state == DISPLAY_STATE_NORMAL)
190 tts_speak(_("IDS_SYSTEM_SCREEN_ON"), EINA_FALSE);
192 else if(state == DISPLAY_STATE_SCREEN_OFF)
194 tts_speak(_("IDS_SYSTEM_SCREEN_OFF"), EINA_FALSE);
199 // ******************************** Indicator info ********************************** //
201 static int _read_text_get(char *key)
206 ret = vconf_get_bool(key, &read_text);
209 ERROR("ret == %d", ret);
217 void device_time_get(void)
219 char buffer[DATE_TIME_BUFFER_SIZE];
220 int disp_12_24 = VCONFKEY_TIME_FORMAT_12;
223 struct tm *timeinfo = NULL;
225 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_TIME))
231 timeinfo = localtime ( &rawtime );
234 ERROR("localtime returns NULL");
238 ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &disp_12_24);
241 ERROR("ret == %d", ret);
244 if (disp_12_24 == VCONFKEY_TIME_FORMAT_24)
246 strftime(buffer, DATE_TIME_BUFFER_SIZE, "Current time: %H %M",
251 strftime(buffer, DATE_TIME_BUFFER_SIZE, "Current time: %I %M %p",
255 DEBUG("Text to say: %s", buffer);
256 tts_speak(buffer, EINA_FALSE);
260 char *device_error_to_string(int e)
264 case DEVICE_ERROR_NONE:
265 return "DEVICE_ERROR_NONE";
268 case DEVICE_ERROR_OPERATION_FAILED:
269 return "DEVICE_ERROR_OPERATION_FAILED";
272 case DEVICE_ERROR_PERMISSION_DENIED:
273 return "DEVICE_ERROR_PERMISSION_DENIED";
276 case DEVICE_ERROR_INVALID_PARAMETER:
277 return "DEVICE_ERROR_INVALID_PARAMETER";
280 case DEVICE_ERROR_ALREADY_IN_PROGRESS:
281 return "DEVICE_ERROR_ALREADY_IN_PROGRESS";
284 case DEVICE_ERROR_NOT_SUPPORTED:
285 return "DEVICE_ERROR_NOT_SUPPORTED";
288 case DEVICE_ERROR_RESOURCE_BUSY:
289 return "DEVICE_ERROR_RESOURCE_BUSY";
292 case DEVICE_ERROR_NOT_INITIALIZED:
293 return "DEVICE_ERROR_NOT_INITIALIZED";
297 return _("IDS_SYSTEM_NETWORK_SERVICE_UNKNOWN");
302 void device_battery_get(void)
305 char *charging_text = NULL;
307 bool is_charging = false;
310 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_BATTERY))
315 ret = device_battery_is_charging(&is_charging);
316 if (ret != DEVICE_ERROR_NONE)
318 ERROR("ret == %s", device_error_to_string(ret));
323 charging_text = _("IDS_SYSTEM_BATTERY_INFO_CHARGING");
330 ret = device_battery_get_percent(&percent);
331 if (ret != DEVICE_ERROR_NONE)
333 ERROR("ret == %s", device_error_to_string(ret));
339 if (!asprintf(&buffer, "%s %s", charging_text, _("IDS_SYSTEM_BATTERY_FULLY_CHARGED_STR")))
341 ERROR("Buffer length == 0");
347 if (!asprintf(&buffer, "%s %d %% %s", charging_text, percent, _("IDS_SYSTEM_BATTERY_INFO_BATTERY_STR")))
349 ERROR("Buffer length == 0");
357 ERROR("buf == NULL");
361 DEBUG("Text to say: %s", buffer);
362 tts_speak(buffer, EINA_FALSE);
367 static void _signal_strength_sim_get(void)
372 int sim_card_count = 0;
373 Eina_Strbuf *str_buf = NULL;
375 int service_type = TAPI_NETWORK_SERVICE_TYPE_UNKNOWN;
376 char *service_type_text = NULL;
378 str_buf = eina_strbuf_new();
380 for (i = 0; tapi_handle[i]; ++i)
385 for (i = 0; tapi_handle[i]; ++i)
387 ret = tel_get_property_int(tapi_handle[i], TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, &val);
388 if (ret != TAPI_API_SUCCESS)
390 ERROR("Can not get %s",TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL);
394 if (sim_card_count > 1)
395 eina_strbuf_append_printf(str_buf, "%s %d %s %d; ", _("IDS_SYSTEM_SIGNAL_SIMCARD"), i + 1, _("IDS_SYSTEM_SIGNAL_STRENGTH"), val);
397 eina_strbuf_append_printf(str_buf, "%s %d; ", _("IDS_SYSTEM_SIGNAL_STRENGTH"), val);
398 DEBUG("sim: %d TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL %d", i, val);
401 ret = tel_get_property_int(tapi_handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type);
402 if (ret != TAPI_API_SUCCESS)
404 ERROR("Can not get %s",TAPI_PROP_NETWORK_SERVICE_TYPE);
409 case TAPI_NETWORK_SERVICE_TYPE_UNKNOWN:
410 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_UNKNOWN");
413 case TAPI_NETWORK_SERVICE_TYPE_NO_SERVICE:
414 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_NO_SERVICE");
417 case TAPI_NETWORK_SERVICE_TYPE_EMERGENCY:
418 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_EMERGENCY");
421 case TAPI_NETWORK_SERVICE_TYPE_SEARCH:
422 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_SEARCHING");
425 case TAPI_NETWORK_SERVICE_TYPE_2G:
426 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_2G");
429 case TAPI_NETWORK_SERVICE_TYPE_2_5G:
430 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_25G");
433 case TAPI_NETWORK_SERVICE_TYPE_2_5G_EDGE:
434 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_EDGE");
437 case TAPI_NETWORK_SERVICE_TYPE_3G:
438 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_3G");
441 case TAPI_NETWORK_SERVICE_TYPE_HSDPA:
442 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_HSDPA");
445 case TAPI_NETWORK_SERVICE_TYPE_LTE:
446 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_LTE");
450 eina_strbuf_append_printf(str_buf, " Service type: %s.", service_type_text);
453 buffer = eina_strbuf_string_steal(str_buf);
455 DEBUG("Text to say: %s", buffer);
456 tts_speak(buffer, EINA_FALSE);
458 eina_strbuf_string_free(str_buf);
462 static void _signal_strength_wifi_get(void)
467 char *wifi_text = NULL;
468 bool wifi_activated = false;
471 ret = wifi_is_activated(&wifi_activated);
472 if(ret != WIFI_ERROR_NONE)
474 ERROR("ret == %d", ret);
480 ret = wifi_get_connected_ap(&ap);
481 if(ret != WIFI_ERROR_NONE)
483 ERROR("ret == %d", ret);
489 DEBUG("Text to say: %s %s",_("IDS_SYSTEM_NETWORK_TYPE_WIFI"), "Not connected");
491 if (!asprintf(&buffer, " %s, %s", _("IDS_SYSTEM_NETWORK_TYPE_WIFI"), "Not connected"))
493 ERROR("buffer length == 0");
497 tts_speak(buffer, EINA_FALSE);
502 ret = wifi_ap_get_rssi(ap, &val);
503 if(ret != WIFI_ERROR_NONE)
505 ERROR("ret == %d", ret);
513 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_NO_SIGNAL");
517 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_POOR");
521 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_WEAK");
525 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_MEDIUM");
529 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_GOOD");
533 if (!asprintf(&buffer, " %s, %s", _("IDS_SYSTEM_NETWORK_TYPE_WIFI"), wifi_text))
535 ERROR("buffer length == 0");
540 DEBUG("Text to say: %s", buffer);
541 tts_speak(buffer, EINA_FALSE);
547 void device_signal_strenght_get(void)
549 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_SIGNAL_STRENGHT))
553 _signal_strength_sim_get();
554 _signal_strength_wifi_get();
557 void device_missed_events_get(void)
559 notification_list_h list = NULL;
560 notification_list_h elem = NULL;
561 notification_h noti = NULL;
563 char *noti_count_text = NULL;
565 int current_noti_count = 0;
568 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_MISSED_EVENTS))
573 ret = notification_get_list(NOTIFICATION_TYPE_NONE, -1, &list);
574 if (ret != NOTIFICATION_ERROR_NONE)
576 ERROR("ret == %d", ret);
580 elem = notification_list_get_head(list);
584 noti = notification_list_get_data(elem);
585 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, ¬i_count_text);
590 current_noti_count = atoi(noti_count_text);
591 if(current_noti_count > 0)
593 noti_count += current_noti_count;
605 elem = notification_list_get_next(elem);
610 DEBUG(_("IDS_SYSTEM_NOTIFICATIONS_UNREAD_0"));
611 tts_speak(_("IDS_SYSTEM_NOTIFICATIONS_UNREAD_0"), EINA_FALSE);
613 else if(noti_count == 1)
615 DEBUG(_("IDS_SYSTEM_NOTIFICATIONS_UNREAD_1"));
616 tts_speak(_("IDS_SYSTEM_NOTIFICATIONS_UNREAD_1"), EINA_FALSE);
620 DEBUG("%d %s", noti_count, _("IDS_SYSTEM_NOTIFICATIONS_UNREAD_MANY"));
622 if (asprintf(&buffer, "%d %s", noti_count, _("IDS_SYSTEM_NOTIFICATIONS_UNREAD_MANY")))
624 ERROR("buffer length equals 0");
627 tts_speak(buffer, EINA_FALSE);
631 ret = notification_free_list(list);
632 if(ret != NOTIFICATION_ERROR_NONE)
634 ERROR("ret == %d", ret);
638 void device_date_get(void)
640 char buffer[DATE_TIME_BUFFER_SIZE];
641 int date_format = SETTING_DATE_FORMAT_DD_MM_YYYY;
644 struct tm *timeinfo = NULL;
646 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_DATE))
652 timeinfo = localtime ( &rawtime );
655 ERROR("localtime returns NULL");
659 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%Y:%m:%d %H:%M:%S", timeinfo);
661 ret = vconf_get_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, &date_format);
664 ERROR("ret == %d", ret);
669 case SETTING_DATE_FORMAT_DD_MM_YYYY:
670 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%d %B %Y", timeinfo);
673 case SETTING_DATE_FORMAT_MM_DD_YYYY:
674 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%B %d %Y", timeinfo);
677 case SETTING_DATE_FORMAT_YYYY_MM_DD:
678 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%Y %B %d", timeinfo);
681 case SETTING_DATE_FORMAT_YYYY_DD_MM:
682 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%Y %d %B", timeinfo);
686 DEBUG("Text to say: %s", buffer);
687 tts_speak(buffer, EINA_FALSE);
690 static bool bonded_device_count_cb(bt_device_info_s *device_info, void *user_data)
692 int *device_count = (int *)user_data;
699 static bool bonded_device_get_cb(bt_device_info_s *device_info, void *user_data)
701 char **device_name = (char **)user_data;
703 if(asprintf(device_name, "%s connected", device_info->remote_name))
705 ERROR("buffer length == 0");
711 void device_bluetooth_get(void)
714 int device_count = 0;
716 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_BLUETOOTH))
721 bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
722 int ret = bt_adapter_get_state(&adapter_state);
723 if (ret != BT_ERROR_NONE)
725 ERROR("ret == %d", ret);
729 if (adapter_state == BT_ADAPTER_DISABLED)
731 DEBUG("Text to say: %s", _("IDS_SYSTEM_BT_BLUETOOTH_OFF"));
732 tts_speak(_("IDS_SYSTEM_BT_BLUETOOTH_OFF"), EINA_FALSE);
737 bt_adapter_foreach_bonded_device(bonded_device_count_cb, (void *)&device_count);
739 if(device_count == 0)
741 if (!asprintf(&buffer, _("IDS_SYSTEM_BT_NO_DEVICES_CONNECTED")))
743 ERROR("buffer length == 0");
746 else if(device_count == 1)
748 bt_adapter_foreach_bonded_device(bonded_device_get_cb, &buffer);
752 if (asprintf(&buffer, "%d %s", device_count,
753 _("IDS_SYSTEM_BT_DEVICES_CONNECTED_COUNT")))
755 ERROR("buffer length == 0");
759 DEBUG("Text to say: %s", buffer);
760 tts_speak(buffer, EINA_FALSE);