Add allowed calls feature 29/91329/1 accepted/tizen/common/20161010.145746 accepted/tizen/ivi/20161010.082932 accepted/tizen/mobile/20161010.082907 submit/tizen/20161010.023052
authorWootak Jung <wootak.jung@samsung.com>
Fri, 7 Oct 2016 05:20:56 +0000 (14:20 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Fri, 7 Oct 2016 05:20:56 +0000 (14:20 +0900)
- supporting dnd allowed calls option

Change-Id: Ic64dc5c705721498aaf0a1348b625ca15ce4739f

common/include/callmgr-util.h
common/src/callmgr-util.c
module/include/callmgr-contact.h
module/src/callmgr-contact.c
packaging/call-manager.spec
service/src/callmgr-core.c

index 1bd7efa..6e0f521 100644 (file)
@@ -146,7 +146,7 @@ int _callmgr_util_launch_ciss(const char* number, int sim_slot);
 int _callmgr_util_is_recording_progress(gboolean *is_recording);
 int _callmgr_util_is_video_recording_progress(gboolean *is_recording);
 
-int _callmgr_util_check_disturbing_setting(gboolean *is_do_not_disturb);
+int _callmgr_util_check_disturbing_setting(const char *number, gboolean *is_do_not_disturb);
 
 gboolean _callmgr_util_check_access_control(cynara *p_cynara, GDBusMethodInvocation *invoc, const char *label, const char *perm);
 
index e37460d..0db3680 100644 (file)
@@ -805,50 +805,64 @@ int _callmgr_util_launch_ciss(const char* number, int sim_slot)
        return 0;
 }
 
-int _callmgr_util_check_disturbing_setting(gboolean *is_do_not_disturb)
+int _callmgr_util_check_disturbing_setting(const char *number, gboolean *is_do_not_disturb)
 {
        notification_system_setting_h system_setting = NULL;
-       notification_setting_h setting = NULL;
-       gboolean do_not_disturb = false;
-       bool do_not_disturb_except = false;
-       int err = NOTIFICATION_ERROR_NONE;
+       gboolean do_not_disturb = FALSE;
        int ret = 0;
+       int allowed_calls = 0;
 
-       ret = _callmgr_vconf_is_do_not_disturb(&do_not_disturb);
-       if (ret == -2) {
-               err = notification_system_setting_load_system_setting(&system_setting);
-               if (err!= NOTIFICATION_ERROR_NONE || system_setting == NULL) {
-                       err("notification_system_setting_load_system_setting failed [%d]\n", err);
-                       goto out;
-               }
-               notification_system_setting_get_do_not_disturb(system_setting, (bool *)&do_not_disturb);
-       }
+       *is_do_not_disturb = FALSE;
 
-       info("do_not_disturb [%d]", do_not_disturb);
+       ret = notification_system_setting_load_system_setting(&system_setting);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               err("notification_system_setting_load_system_setting() failed [%d][%s]", ret, get_error_message(ret));
+               return 0;
+       }
 
-       if(do_not_disturb) {
-               err = notification_setting_get_setting_by_package_name(CALLUI_PKG_NAME, &setting);
-               if(err != NOTIFICATION_ERROR_NONE || setting == NULL) {
-                       err("notification_setting_get_setting_by_package_name failed [%d]", err);
-                       goto out;
-               }
+       ret = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               err("notification_system_setting_get_do_not_disturb() failed [%d][%s]", ret, get_error_message(ret));
+               return 0;
+       }
 
-               notification_setting_get_do_not_disturb_except(setting, &do_not_disturb_except);
-               dbg("do_not_disturb_excepted [%d]", do_not_disturb_except);
+       info("Do not disturb [%s]", do_not_disturb ? "ON" : "OFF");
 
-               if (do_not_disturb_except)
+       if (do_not_disturb) {
+               notification_system_setting_get_dnd_allow_exceptions(system_setting,
+                       NOTIFICATION_DND_ALLOWED_CALLS, &allowed_calls);
+               dbg("Allowed calls option [%s]",
+                               allowed_calls == NOTIFICATION_DND_ALLOWED_CALLS_EVERYONE ? "Everyone"
+                               : allowed_calls == NOTIFICATION_DND_ALLOWED_CALLS_CONTACT ? "Contacts only"
+                               : allowed_calls == NOTIFICATION_DND_ALLOWED_CALLS_FAVORITE ? "Favorite contacts only"
+                               : "Nobody");
+               if (allowed_calls == NOTIFICATION_DND_ALLOWED_CALLS_EVERYONE) {
                        *is_do_not_disturb = FALSE;
-               else
+               } else if (allowed_calls == NOTIFICATION_DND_ALLOWED_CALLS_CONTACT) {
+                       int person_id = -1;
+                       _callmgr_ct_get_person_id_by_num(number, &person_id);
+                       if (person_id != -1) {
+                               dbg("Do not disturb ON. but allow the number stored in contacts");
+                               *is_do_not_disturb = FALSE;
+                       } else {
+                               *is_do_not_disturb = TRUE;
+                       }
+               } else if (allowed_calls == NOTIFICATION_DND_ALLOWED_CALLS_FAVORITE) {
+                       int is_favorite = -1;
+                       _callmgr_ct_get_is_favorite_by_num(number, &is_favorite);
+                       if (is_favorite == 1) {
+                               dbg("Do not disturb ON. but allow the number stored in favorite contacts");
+                               *is_do_not_disturb = FALSE;
+                       } else {
+                               *is_do_not_disturb = TRUE;
+                       }
+               } else {
                        *is_do_not_disturb = TRUE;
+               }
        } else {
                *is_do_not_disturb = FALSE;
        }
-out:
-       if (system_setting)
-               notification_system_setting_free_system_setting(system_setting);
-       if (setting)
-               notification_setting_free_notification(setting);
 
+       notification_system_setting_free_system_setting(system_setting);
        return 0;
 }
-
index d48e356..4800111 100644 (file)
@@ -69,8 +69,12 @@ typedef struct {
        cm_ct_plog_presentation presentation;
 } cm_ct_plog_data_t;
 
+int _callmgr_contact_init();
+int _callmgr_contact_deinit();
 int _callmgr_ct_add_ct_info(const char *phone_number, unsigned int call_id, callmgr_contact_info_t **o_contact_out_info);
 int _callmgr_ct_get_person_id(unsigned int call_id, int *o_person_id);
+int _callmgr_ct_get_person_id_by_num(const char *phone_number, int *person_id);
+int _callmgr_ct_get_is_favorite_by_num(const char *phone_number, int *is_favorite);
 int _callmgr_ct_get_caller_ringtone_path(unsigned int call_id, char **o_caller_ringtone_path);
 int _callmgr_ct_delete_ct_info(unsigned int call_id);
 int _callmgr_ct_get_ct_info(unsigned int call_id, callmgr_contact_info_t **o_contact_info_out);
index 5529125..3af5cf3 100644 (file)
@@ -158,7 +158,7 @@ static int __callmgr_ct_get_group_ringtone(int person_id, callmgr_contact_info_t
                        err = contacts_db_get_record(_contacts_group._uri, group_id , &group_record);
 
                        if (CONTACTS_ERROR_NONE != err) {
-                               err("contacts_db_get_record(contact) error %d", err);
+                               err("contacts_db_get_record(contact) error %d(%s)", err, get_error_message(err));
                        } else {
                                /* Get group ringtone path */
                                err = contacts_record_get_str(group_record, _contacts_group.ringtone_path, &ringtone_path);
@@ -215,7 +215,62 @@ static int __callmgr_ct_get_caller_ringtone(int person_id, callmgr_contact_info_
        return 0;
 }
 
-static int __callmgr_ct_get_person_id_by_num(const char *phone_number, int *person_id)
+int _callmgr_ct_get_is_favorite_by_num(const char *phone_number, int *is_favorite)
+{
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+       contacts_record_h record = NULL;
+       contacts_error_e err = CONTACTS_ERROR_NONE;
+       bool b_favorite = FALSE;
+       unsigned int projection[] = {
+                _contacts_person_number.is_favorite,
+       };
+       CM_RETURN_VAL_IF_FAIL(phone_number, -1);
+       CM_RETURN_VAL_IF_FAIL(is_favorite, -1);
+
+       if (contacts_query_create(_contacts_person_number._uri, &query) != CONTACTS_ERROR_NONE) {
+               err("contacts_query_create is error");
+       } else if (contacts_filter_create(_contacts_person_number._uri, &filter) != CONTACTS_ERROR_NONE) {
+               err("contacts_filter_create is error");
+       } else if (contacts_filter_add_str(filter, _contacts_person_number.number_filter, CONTACTS_MATCH_EXACTLY, phone_number) != CONTACTS_ERROR_NONE) {
+               err("contacts_filter_add_str is error");
+       } else if (contacts_query_set_filter(query, filter) != CONTACTS_ERROR_NONE) {
+               err("contacts_query_set_filter is error");
+       } else if (contacts_query_set_projection(query, projection, sizeof(projection)/sizeof(unsigned int)) != CONTACTS_ERROR_NONE) {
+               err("contacts_query_set_projection is error");
+       } else if (contacts_query_set_distinct(query, TRUE) != CONTACTS_ERROR_NONE) {
+               err("contacts_query_set_distinct is error");
+       }
+
+       err = contacts_db_get_records_with_query(query, 0, 0, &list);
+
+       if (CONTACTS_ERROR_NONE == err) {
+               contacts_list_first(list);
+
+               while (CONTACTS_ERROR_NONE == contacts_list_get_current_record_p(list, &record)) {
+                       contacts_record_get_bool(record, _contacts_person_number.is_favorite, &b_favorite);
+                       *is_favorite = b_favorite;
+                       info("is_favorite %d", *is_favorite);
+                       err = contacts_list_next(list);
+                       if (CONTACTS_ERROR_NONE != err)
+                               break;
+               }
+       }
+
+       if (list) {
+               err = contacts_list_destroy(list, TRUE);
+               if (err != CONTACTS_ERROR_NONE) {
+                       err("contacts_list_destroy is error");
+               }
+       }
+       contacts_filter_destroy(filter);
+       contacts_query_destroy(query);
+
+       return 0;
+}
+
+int _callmgr_ct_get_person_id_by_num(const char *phone_number, int *person_id)
 {
        contacts_query_h query = NULL;
        contacts_filter_h filter = NULL;
@@ -272,21 +327,13 @@ int _callmgr_ct_add_ct_info(const char *phone_number, unsigned int call_id, call
 {
        callmgr_contact_info_t *contact_info = NULL;
        int person_id = -1;
-       contacts_error_e err = CONTACTS_ERROR_NONE;
 
        contact_info = (callmgr_contact_info_t*)calloc(1, sizeof(callmgr_contact_info_t));
        CM_RETURN_VAL_IF_FAIL(contact_info, -1);
 
        _callmgr_ct_delete_ct_info(call_id);
 
-       err = contacts_connect();
-       if (CONTACTS_ERROR_NONE != err) {
-               err("contacts_connect is error : %d", err);
-               g_free(contact_info);
-               return -1;
-       }
-
-       __callmgr_ct_get_person_id_by_num(phone_number, &person_id);
+       _callmgr_ct_get_person_id_by_num(phone_number, &person_id);
        if (-1 == person_id) {
                err("no contact saved for this number in db");
        } else {
@@ -306,7 +353,6 @@ int _callmgr_ct_add_ct_info(const char *phone_number, unsigned int call_id, call
        contact_info->log_reject_type = CM_CT_PLOG_REJECT_TYPE_NONE_E;
        g_ct_list = g_slist_append(g_ct_list, contact_info);
 
-       contacts_disconnect();
        *o_contact_out_info = contact_info;
        return 0;
 }
@@ -408,10 +454,10 @@ int _callmgr_ct_add_log(cm_ct_plog_data_t *log_data)
 {
        int ret = -1;
        time_t current_time;
-       int log_ret = CONTACTS_ERROR_NONE;
        char service_type[4] = {0, };
        gboolean is_datalock = FALSE;
        callmgr_contact_info_t *contact_info = NULL;
+       contacts_record_h log_record = NULL;
        CM_RETURN_VAL_IF_FAIL(log_data, -1);
 
        dbg("_callmgr_ct_add_log: type(%d)", log_data->log_type);
@@ -430,43 +476,32 @@ int _callmgr_ct_add_log(cm_ct_plog_data_t *log_data)
 
        current_time = time(NULL);
 
-       log_ret = contacts_connect();
-       if (log_ret != CONTACTS_ERROR_NONE) {
-               err("contacts_connect is failed[%d]", log_ret);
-               contacts_disconnect();
-               return -1;
+       g_snprintf(service_type, sizeof(service_type), "%03d", log_data->presentation);
+       warn("service_type : %s", service_type);
+
+       dbg("data->active_sim_slot_id %d", log_data->sim_slot);
+       if (contacts_record_create(_contacts_phone_log._uri, &log_record) != CONTACTS_ERROR_NONE) {
+               err("contacts_record_create is failed");
+       } else if (contacts_record_set_str(log_record, _contacts_phone_log.address, contact_info->number) != CONTACTS_ERROR_NONE) {
+               err("contacts_record_set_str(Number) is failed");
+       } else if (contacts_record_set_int(log_record, _contacts_phone_log.log_time, (current_time)) != CONTACTS_ERROR_NONE) {  /* Log time is call end time*/
+               err("contacts_record_set_int(Time) is failed");
+       } else if (contacts_record_set_int(log_record, _contacts_phone_log.log_type, log_data->log_type) != CONTACTS_ERROR_NONE) {
+               err("contacts_record_set_int(Type) is failed");
+       } else if (contacts_record_set_int(log_record, _contacts_phone_log.extra_data1, log_data->call_duration) != CONTACTS_ERROR_NONE) {
+               err("contacts_record_set_int(Duration) is failed");
+       } else if (contacts_record_set_int(log_record, _contacts_phone_log.person_id, contact_info->person_id) != CONTACTS_ERROR_NONE) {
+               err("contacts_record_set_int(person id) is failed");
+       } else if (contacts_record_set_str(log_record, _contacts_phone_log.extra_data2, service_type) != CONTACTS_ERROR_NONE) {
+               err("contacts_record_set_int(extra_data2) is failed");
+       } else if (contacts_record_set_int(log_record, _contacts_phone_log.sim_slot_no, log_data->sim_slot) != CONTACTS_ERROR_NONE) {
+               err("contacts_record_set_int(person id) is failed");
+       } else if (contacts_db_insert_record(log_record, NULL) != CONTACTS_ERROR_NONE) {
+               err("contacts_db_insert_record is failed");
        } else {
-               contacts_record_h log_record = NULL;
-
-               g_snprintf(service_type, sizeof(service_type), "%03d", log_data->presentation);
-               warn("service_type : %s", service_type);
-
-               dbg("data->active_sim_slot_id %d", log_data->sim_slot);
-               if (contacts_record_create(_contacts_phone_log._uri, &log_record) != CONTACTS_ERROR_NONE) {
-                       err("contacts_record_create is failed");
-               } else if (contacts_record_set_str(log_record, _contacts_phone_log.address, contact_info->number) != CONTACTS_ERROR_NONE) {
-                       err("contacts_record_set_str(Number) is failed");
-               } else if (contacts_record_set_int(log_record, _contacts_phone_log.log_time, (current_time)) != CONTACTS_ERROR_NONE) {  /* Log time is call end time*/
-                       err("contacts_record_set_int(Time) is failed");
-               } else if (contacts_record_set_int(log_record, _contacts_phone_log.log_type, log_data->log_type) != CONTACTS_ERROR_NONE) {
-                       err("contacts_record_set_int(Type) is failed");
-               } else if (contacts_record_set_int(log_record, _contacts_phone_log.extra_data1, log_data->call_duration) != CONTACTS_ERROR_NONE) {
-                       err("contacts_record_set_int(Duration) is failed");
-               } else if (contacts_record_set_int(log_record, _contacts_phone_log.person_id, contact_info->person_id) != CONTACTS_ERROR_NONE) {
-                       err("contacts_record_set_int(person id) is failed");
-               } else if (contacts_record_set_str(log_record, _contacts_phone_log.extra_data2, service_type) != CONTACTS_ERROR_NONE) {
-                       err("contacts_record_set_int(extra_data2) is failed");
-               } else if (contacts_record_set_int(log_record, _contacts_phone_log.sim_slot_no, log_data->sim_slot) != CONTACTS_ERROR_NONE) {
-                       err("contacts_record_set_int(person id) is failed");
-               } else if (contacts_db_insert_record(log_record, NULL) != CONTACTS_ERROR_NONE) {
-                       err("contacts_db_insert_record is failed");
-               } else {
-                       info("Call log is added successfully");
-               }
-               contacts_record_destroy(log_record, TRUE);
+               info("Call log is added successfully");
        }
-
-       contacts_disconnect();
+       contacts_record_destroy(log_record, TRUE);
 
        if ((log_data->log_type == CM_CT_PLOG_TYPE_VOICE_INCOMING_UNSEEN_E)
                || (log_data->log_type == CM_CT_PLOG_TYPE_VIDEO_INCOMING_UNSEEN_E)) {
@@ -509,16 +544,9 @@ static int __callmgr_ct_get_missed_call_count(void)
        int missed_cnt = 0;
        contacts_query_h query = NULL;
        contacts_filter_h filter = NULL;
-       int log_ret = CONTACTS_ERROR_NONE;
 
        dbg("__callmgr_ct_get_missed_call_count");
 
-       log_ret = contacts_connect();
-       if (log_ret != CONTACTS_ERROR_NONE) {
-               err("contacts_connect is failed with err[%d] ", log_ret);
-               return -1;
-       }
-
        if (contacts_query_create(_contacts_phone_log._uri, &query) != CONTACTS_ERROR_NONE) {
                err("contacts_query_create failed");
        } else if (contacts_filter_create(_contacts_phone_log._uri, &filter) != CONTACTS_ERROR_NONE) {
@@ -537,7 +565,6 @@ static int __callmgr_ct_get_missed_call_count(void)
 
        contacts_filter_destroy(filter);
        contacts_query_destroy(query);
-       contacts_disconnect();
 
        return missed_cnt;
 }
@@ -716,10 +743,6 @@ static void __callmgr_ct_add_notification(int missed_cnt)
                err("Fail to notification_set_led : %d", noti_err);
        }
 
-       if (contacts_connect() != CONTACTS_ERROR_NONE) {
-               err("contacts_connect is error");
-       }
-
        if (contacts_query_create(_contacts_phone_log._uri, &query) != CONTACTS_ERROR_NONE) {
                err("contacts_query_create is error");
        } else if (contacts_filter_create(_contacts_phone_log._uri, &filter) != CONTACTS_ERROR_NONE) {
@@ -900,7 +923,6 @@ static void __callmgr_ct_add_notification(int missed_cnt)
        }
        contacts_filter_destroy(filter);
        contacts_query_destroy(query);
-       contacts_disconnect();
 
        noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_LOCK | NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_TICKER;
        noti_err = notification_set_display_applist(noti, noti_flags);
@@ -1099,19 +1121,9 @@ static void __callmgr_ct_add_rec_reject_notification(char *number, int person_id
                }
 
                if (person_id >= 1) {
-                       contacts_error_e err = CONTACTS_ERROR_NONE;
-
                        char *disp_str = NULL;
 
-                       err = contacts_connect();
-                       if (err != CONTACTS_ERROR_NONE) {
-                               err("contacts_connect is failed[%d]", err);
-                               disp_str = g_strdup(_("IDS_CALL_BODY_UNKNOWN"));
-                       } else {
-                               __callmgr_ct_get_caller_info(person_id, &disp_str, &disp_img_path);
-                       }
-
-                       contacts_disconnect();
+                       __callmgr_ct_get_caller_info(person_id, &disp_str, &disp_img_path);
 
                        noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, disp_str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        g_free(disp_str);
@@ -1228,19 +1240,30 @@ static void __callmgr_ct_add_rec_reject_notification(char *number, int person_id
 int _callmgr_ct_get_call_name(unsigned int call_id, char **call_name)
 {
        int person_id = -1;
-       contacts_error_e err = CONTACTS_ERROR_NONE;
        CM_RETURN_VAL_IF_FAIL(call_name, -1);
 
-       err = contacts_connect();
+       _callmgr_ct_get_person_id(call_id, &person_id);
+       __callmgr_ct_get_caller_name(person_id, call_name);
+
+       return 0;
+}
 
+int _callmgr_contact_init()
+{
+       contacts_error_e err = CONTACTS_ERROR_NONE;
+
+       err = contacts_connect();
        if (err != CONTACTS_ERROR_NONE) {
-               err("contacts_connect is failed[%d]", err);
-       } else {
-               _callmgr_ct_get_person_id(call_id, &person_id);
-               __callmgr_ct_get_caller_name(person_id, call_name);
+               err("contacts_connect() failed [%d](%s)", err, get_error_message(err));
+               return FALSE;
        }
 
-       contacts_disconnect();
-       return 0;
+       dbg("contact init success");
+       return TRUE;
 }
 
+int _callmgr_contact_deinit()
+{
+       contacts_disconnect();
+       return TRUE;
+}
index 8190c91..f40f36c 100755 (executable)
@@ -1,6 +1,6 @@
 %define major 0
 %define minor 1
-%define patchlevel 74
+%define patchlevel 75
 %define ext_feature 0
 
 Name:           call-manager
index 29e46ab..bd9d0dd 100644 (file)
@@ -1227,7 +1227,7 @@ static void __callmgr_core_process_telephony_events(cm_telephony_event_type_e ev
                                        _callmgr_vconf_is_bike_mode_enabled(&is_bike_mode_enabled);
                                        _callmgr_vconf_is_low_battery(&is_low_battery);
 
-                                       _callmgr_util_check_disturbing_setting(&is_do_not_disturb);
+                                       _callmgr_util_check_disturbing_setting(number, &is_do_not_disturb);
                                        _callmgr_telephony_get_call_count(core_data->telephony_handle, &call_cnt);
                                        if((is_blocked_num == TRUE)
                                                || (is_rec_blocked == TRUE)
@@ -2050,6 +2050,9 @@ int _callmgr_core_init(callmgr_core_data_t **o_core_data)
        if (!core_data->vr_handle)
                err("core_data->vr_handle is NULL");
 
+       if (_callmgr_contact_init() != TRUE)
+               err("contact init failed");
+
        *o_core_data = core_data;
 
        _callmgr_ct_set_missed_call_notification();
@@ -2070,6 +2073,7 @@ int _callmgr_core_deinit(callmgr_core_data_t *core_data)
 #ifdef TIZEN_SOUND_ROUTING_FEATURE
        _callmgr_core_shutdown_dbus_call_routing_status();
 #endif
+       _callmgr_contact_deinit();
        g_free(core_data);
        return 0;
 }