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.
17 #ifndef SCREEN_READER_TV
21 #include <device/battery.h>
22 #include <device/display.h>
23 #include <device/callback.h>
24 #include <bluetooth.h>
25 #include <tapi_common.h>
26 #include <TelNetwork.h>
29 #include <notification.h>
30 #include <notification_list.h>
32 #include "screen_reader.h"
33 #include "screen_reader_tts.h"
34 #include "smart_notification.h"
37 #define MAX_SIM_COUNT 2
38 #define DATE_TIME_BUFFER_SIZE 26
40 TapiHandle *tapi_handle[MAX_SIM_COUNT + 1] = { 0, };
42 static void device_system_cb(device_callback_e type, void *value, void *user_data);
44 static void tapi_init(void)
47 char **cp_list = tel_get_cp_name_list();
50 ERROR("cp name list is null");
55 for (i = 0; cp_list[i]; ++i) {
56 tapi_handle[i] = tel_init(cp_list[i]);
57 DEBUG("CP_LIST %d = %s", i, cp_list[i]);
63 * @brief Initializer for smart notifications
66 void system_notifications_init(void)
68 DEBUG("******************** START ********************");
72 device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb, NULL);
73 // BATTERY CHARGING/NOT-CHARGING
74 device_add_callback(DEVICE_CALLBACK_BATTERY_CHARGING, device_system_cb, NULL);
76 device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb, NULL);
78 ret = bt_initialize();
79 if (ret != BT_ERROR_NONE) {
80 ERROR("ret == %d", ret);
83 ret = wifi_initialize();
84 if (ret != WIFI_ERROR_NONE) {
85 ERROR("ret == %d", ret);
90 DEBUG(" ********************* END ********************* ");
94 * @brief Initializer for smart notifications
97 void system_notifications_shutdown(void)
102 device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb);
103 // BATTERY CHARGING/NOT-CHARGING
104 device_remove_callback(DEVICE_CALLBACK_BATTERY_CHARGING, device_system_cb);
106 device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb);
108 ret = bt_deinitialize();
109 if (ret != BT_ERROR_NONE) {
110 ERROR("ret == %d", ret);
113 ret = wifi_deinitialize();
114 if (ret != WIFI_ERROR_NONE) {
115 ERROR("ret == %d", ret);
121 * @brief Device system callback handler
123 * @param type Device callback type
124 * @param value UNUSED
125 * @param user_data UNUSED
127 static void device_system_cb(device_callback_e type, void *value, void *user_data)
129 if (type == DEVICE_CALLBACK_BATTERY_LEVEL) {
130 device_battery_level_e status;
131 if (device_battery_get_level_status(&status)) {
132 ERROR("Cannot get battery level status");
136 if (status == DEVICE_BATTERY_LEVEL_LOW) {
137 tts_speak(_("IDS_SYSTEM_BATTERY_LOW"), EINA_TRUE);
138 } else if (status == DEVICE_BATTERY_LEVEL_CRITICAL) {
139 tts_speak(_("IDS_SYSTEM_BATTERY_CRITICAL"), EINA_TRUE);
140 } else if (status == DEVICE_BATTERY_LEVEL_FULL) {
141 tts_speak(_("IDS_SYSTEM_BATTERY_FULL"), EINA_TRUE);
143 } else if (type == DEVICE_CALLBACK_BATTERY_CHARGING) {
145 if (device_battery_is_charging(&charging)) {
146 ERROR("Cannot check if battery is charging");
151 tts_speak(_("IDS_SYSTEM_NOT_CHARGING"), EINA_FALSE);
152 } else if (type == DEVICE_CALLBACK_DISPLAY_STATE) {
153 display_state_e state;
154 if (device_display_get_state(&state)) {
155 ERROR("Cannot check if battery is charging");
159 if (state == DISPLAY_STATE_NORMAL) {
160 tts_speak(_("IDS_SYSTEM_SCREEN_ON"), EINA_FALSE);
161 } else if (state == DISPLAY_STATE_SCREEN_OFF) {
162 tts_speak(_("IDS_SYSTEM_SCREEN_OFF"), EINA_FALSE);
167 // ******************************** Indicator info ********************************** //
169 static int _read_text_get(char *key)
174 ret = vconf_get_bool(key, &read_text);
176 ERROR("ret == %d", ret);
183 void device_time_get(void)
185 char buffer[DATE_TIME_BUFFER_SIZE];
186 int disp_12_24 = VCONFKEY_TIME_FORMAT_12;
189 struct tm *timeinfo = NULL;
191 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_TIME)) {
196 timeinfo = localtime(&rawtime);
198 ERROR("localtime returns NULL");
202 ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &disp_12_24);
204 ERROR("ret == %d", ret);
207 if (disp_12_24 == VCONFKEY_TIME_FORMAT_24) {
208 strftime(buffer, DATE_TIME_BUFFER_SIZE, "Current time: %H %M", timeinfo);
210 strftime(buffer, DATE_TIME_BUFFER_SIZE, "Current time: %I %M %p", timeinfo);
213 DEBUG("Text to say: %s", buffer);
214 tts_speak(buffer, EINA_FALSE);
217 char *device_error_to_string(int e)
220 case DEVICE_ERROR_NONE:
221 return "DEVICE_ERROR_NONE";
224 case DEVICE_ERROR_OPERATION_FAILED:
225 return "DEVICE_ERROR_OPERATION_FAILED";
228 case DEVICE_ERROR_PERMISSION_DENIED:
229 return "DEVICE_ERROR_PERMISSION_DENIED";
232 case DEVICE_ERROR_INVALID_PARAMETER:
233 return "DEVICE_ERROR_INVALID_PARAMETER";
236 case DEVICE_ERROR_ALREADY_IN_PROGRESS:
237 return "DEVICE_ERROR_ALREADY_IN_PROGRESS";
240 case DEVICE_ERROR_NOT_SUPPORTED:
241 return "DEVICE_ERROR_NOT_SUPPORTED";
244 case DEVICE_ERROR_RESOURCE_BUSY:
245 return "DEVICE_ERROR_RESOURCE_BUSY";
248 case DEVICE_ERROR_NOT_INITIALIZED:
249 return "DEVICE_ERROR_NOT_INITIALIZED";
253 return _("IDS_SYSTEM_NETWORK_SERVICE_UNKNOWN");
258 void device_battery_get(void)
261 char *charging_text = NULL;
263 bool is_charging = false;
266 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_BATTERY)) {
270 ret = device_battery_is_charging(&is_charging);
271 if (ret != DEVICE_ERROR_NONE) {
272 ERROR("ret == %s", device_error_to_string(ret));
276 charging_text = _("IDS_SYSTEM_BATTERY_INFO_CHARGING");
281 ret = device_battery_get_percent(&percent);
282 if (ret != DEVICE_ERROR_NONE) {
283 ERROR("ret == %s", device_error_to_string(ret));
287 if (percent == 100) {
288 ret = asprintf(&buffer, "%s %s", charging_text, _("IDS_SYSTEM_BATTERY_FULLY_CHARGED_STR"));
291 ERROR("Buffer length == 0");
293 } else if (ret < 0) {
294 ERROR("Buffer == NULL");
298 ret = asprintf(&buffer, "%s %d %% %s", charging_text, percent, _("IDS_SYSTEM_BATTERY_INFO_BATTERY_STR"));
301 ERROR("Buffer length == 0");
304 ERROR("Buffer == NULL");
310 ERROR("buf == NULL");
314 DEBUG("Text to say: %s", buffer);
315 tts_speak(buffer, EINA_FALSE);
319 static void _signal_strength_sim_get(void)
324 int sim_card_count = 0;
325 Eina_Strbuf *str_buf = NULL;
327 int service_type = TAPI_NETWORK_SERVICE_TYPE_UNKNOWN;
328 char *service_type_text = NULL;
330 str_buf = eina_strbuf_new();
332 for (i = 0; tapi_handle[i]; ++i) {
336 for (i = 0; tapi_handle[i]; ++i) {
337 ret = tel_get_property_int(tapi_handle[i], TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, &val);
338 if (ret != TAPI_API_SUCCESS) {
339 ERROR("Can not get %s", TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL);
343 if (sim_card_count > 1)
344 eina_strbuf_append_printf(str_buf, "%s %d %s %d; ", _("IDS_SYSTEM_SIGNAL_SIMCARD"), i + 1, _("IDS_SYSTEM_SIGNAL_STRENGTH"), val);
346 eina_strbuf_append_printf(str_buf, "%s %d; ", _("IDS_SYSTEM_SIGNAL_STRENGTH"), val);
347 DEBUG("sim: %d TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL %d", i, val);
349 ret = tel_get_property_int(tapi_handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type);
350 if (ret != TAPI_API_SUCCESS) {
351 ERROR("Can not get %s", TAPI_PROP_NETWORK_SERVICE_TYPE);
354 switch (service_type) {
355 case TAPI_NETWORK_SERVICE_TYPE_UNKNOWN:
356 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_UNKNOWN");
359 case TAPI_NETWORK_SERVICE_TYPE_NO_SERVICE:
360 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_NO_SERVICE");
363 case TAPI_NETWORK_SERVICE_TYPE_EMERGENCY:
364 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_EMERGENCY");
367 case TAPI_NETWORK_SERVICE_TYPE_SEARCH:
368 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_SEARCHING");
371 case TAPI_NETWORK_SERVICE_TYPE_2G:
372 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_2G");
375 case TAPI_NETWORK_SERVICE_TYPE_2_5G:
376 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_25G");
379 case TAPI_NETWORK_SERVICE_TYPE_2_5G_EDGE:
380 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_EDGE");
383 case TAPI_NETWORK_SERVICE_TYPE_3G:
384 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_3G");
387 case TAPI_NETWORK_SERVICE_TYPE_HSDPA:
388 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_HSDPA");
391 case TAPI_NETWORK_SERVICE_TYPE_LTE:
392 service_type_text = _("IDS_SYSTEM_NETWORK_SERVICE_LTE");
396 eina_strbuf_append_printf(str_buf, " Service type: %s.", service_type_text);
399 buffer = eina_strbuf_string_steal(str_buf);
401 DEBUG("Text to say: %s", buffer);
402 tts_speak(buffer, EINA_FALSE);
404 eina_strbuf_string_free(str_buf);
408 static void _signal_strength_wifi_get(void)
413 char *wifi_text = NULL;
414 bool wifi_activated = false;
417 ret = wifi_is_activated(&wifi_activated);
418 if (ret != WIFI_ERROR_NONE) {
419 ERROR("ret == %d", ret);
423 if (wifi_activated) {
424 ret = wifi_get_connected_ap(&ap);
425 if (ret != WIFI_ERROR_NONE) {
426 ERROR("ret == %d", ret);
431 DEBUG("Text to say: %s %s", _("IDS_SYSTEM_NETWORK_TYPE_WIFI"), "Not connected");
433 ret = asprintf(&buffer, " %s, %s", _("IDS_SYSTEM_NETWORK_TYPE_WIFI"), "Not connected");
436 ERROR("Buffer length == 0");
438 } else if (ret < 0) {
439 ERROR("Buffer == NULL");
443 tts_speak(buffer, EINA_FALSE);
448 ret = wifi_ap_get_rssi(ap, &val);
449 if (ret != WIFI_ERROR_NONE) {
450 ERROR("ret == %d", ret);
457 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_NO_SIGNAL");
461 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_POOR");
465 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_WEAK");
469 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_MEDIUM");
473 wifi_text = _("IDS_SYSTEM_WIFI_SIGNAL_GOOD");
477 if (!asprintf(&buffer, " %s, %s", _("IDS_SYSTEM_NETWORK_TYPE_WIFI"), wifi_text)) {
478 ERROR("buffer length == 0");
483 DEBUG("Text to say: %s", buffer);
484 tts_speak(buffer, EINA_FALSE);
490 void device_signal_strenght_get(void)
492 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_SIGNAL_STRENGHT)) {
495 _signal_strength_sim_get();
496 _signal_strength_wifi_get();
499 void device_missed_events_get(void)
501 notification_list_h list = NULL;
502 notification_list_h elem = NULL;
503 notification_h noti = NULL;
505 char *noti_count_text = NULL;
507 int current_noti_count = 0;
510 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_MISSED_EVENTS)) {
514 ret = notification_get_list(NOTIFICATION_TYPE_NONE, -1, &list);
515 if (ret != NOTIFICATION_ERROR_NONE) {
516 ERROR("ret == %d", ret);
520 elem = notification_list_get_head(list);
523 noti = notification_list_get_data(elem);
524 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, ¬i_count_text);
526 if (noti_count_text) {
527 current_noti_count = atoi(noti_count_text);
528 if (current_noti_count > 0) {
529 noti_count += current_noti_count;
537 elem = notification_list_get_next(elem);
540 if (noti_count == 0) {
541 tts_speak(_("IDS_SYSTEM_NOTIFICATIONS_UNREAD_0"), EINA_FALSE);
542 } else if (noti_count == 1) {
543 tts_speak(_("IDS_SYSTEM_NOTIFICATIONS_UNREAD_1"), EINA_FALSE);
545 DEBUG("%d %s", noti_count, _("IDS_SYSTEM_NOTIFICATIONS_UNREAD_MANY"));
547 if (asprintf(&buffer, "%d %s", noti_count, _("IDS_SYSTEM_NOTIFICATIONS_UNREAD_MANY"))) {
548 ERROR("buffer length equals 0");
551 tts_speak(buffer, EINA_FALSE);
555 ret = notification_free_list(list);
556 if (ret != NOTIFICATION_ERROR_NONE) {
557 ERROR("ret == %d", ret);
561 void device_date_get(void)
563 char buffer[DATE_TIME_BUFFER_SIZE];
564 int date_format = SETTING_DATE_FORMAT_DD_MM_YYYY;
567 struct tm *timeinfo = NULL;
569 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_DATE)) {
574 timeinfo = localtime(&rawtime);
576 ERROR("localtime returns NULL");
580 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%Y:%m:%d %H:%M:%S", timeinfo);
582 ret = vconf_get_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, &date_format);
584 ERROR("ret == %d", ret);
587 switch (date_format) {
588 case SETTING_DATE_FORMAT_DD_MM_YYYY:
589 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%d %B %Y", timeinfo);
592 case SETTING_DATE_FORMAT_MM_DD_YYYY:
593 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%B %d %Y", timeinfo);
596 case SETTING_DATE_FORMAT_YYYY_MM_DD:
597 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%Y %B %d", timeinfo);
600 case SETTING_DATE_FORMAT_YYYY_DD_MM:
601 strftime(buffer, DATE_TIME_BUFFER_SIZE, "%Y %d %B", timeinfo);
605 DEBUG("Text to say: %s", buffer);
606 tts_speak(buffer, EINA_FALSE);
609 static bool bonded_device_count_cb(bt_device_info_s * device_info, void *user_data)
611 int *device_count = (int *)user_data;
618 static bool bonded_device_get_cb(bt_device_info_s * device_info, void *user_data)
620 char **device_name = (char **)user_data;
622 if (asprintf(device_name, "%s connected", device_info->remote_name)) {
623 ERROR("buffer length == 0");
629 void device_bluetooth_get(void)
632 int device_count = 0;
634 if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_BLUETOOTH)) {
638 bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
639 int ret = bt_adapter_get_state(&adapter_state);
640 if (ret != BT_ERROR_NONE) {
641 ERROR("ret == %d", ret);
645 if (adapter_state == BT_ADAPTER_DISABLED) {
646 DEBUG("Text to say: %s", _("IDS_SYSTEM_BT_BLUETOOTH_OFF"));
647 tts_speak(_("IDS_SYSTEM_BT_BLUETOOTH_OFF"), EINA_FALSE);
650 bt_adapter_foreach_bonded_device(bonded_device_count_cb, (void *)&device_count);
652 if (device_count == 0) {
653 if (!asprintf(&buffer, _("IDS_SYSTEM_BT_NO_DEVICES_CONNECTED"))) {
654 ERROR("buffer length == 0");
656 } else if (device_count == 1) {
657 bt_adapter_foreach_bonded_device(bonded_device_get_cb, &buffer);
659 if (asprintf(&buffer, "%d %s", device_count, _("IDS_SYSTEM_BT_DEVICES_CONNECTED_COUNT"))) {
660 ERROR("buffer length == 0");
664 DEBUG("Text to say: %s", buffer);
665 tts_speak(buffer, EINA_FALSE);