[SM] Setting mobile restrictions by STC 18/140018/6
authorPawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
Fri, 21 Jul 2017 10:37:44 +0000 (12:37 +0200)
committerPawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
Fri, 21 Jul 2017 13:25:01 +0000 (15:25 +0200)
Change-Id: Ie1f0046269e4e08dae0ee7e892b1d7a572299d1e
Signed-off-by: Pawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
setting-smartmanager/smartmanager-data/include/smartmanager-utils.h
setting-smartmanager/smartmanager-data/src/smartmanager-data-usage-mobile-settings.c
setting-smartmanager/smartmanager-data/src/smartmanager-utils.c

index 797ac8635e4bd018fdebda9966a7a3e55e77bfeb..81de58e3fea9361e7a3eb56cf4ebc0673ca9a43c 100644 (file)
 #include <stdbool.h>
 #include <telephony.h>
 
+typedef enum {
+       DATA_RESTRICTION_LIMIT,
+       DATA_RESTRICTION_WARNING_LIMIT
+} data_restriction_type;
+
 void get_data_amount_str(const char *prefix, int64_t num_bytes, char *txt_out, int len_max);
 
 bool get_sim_total_stats(stc_h stc, stc_stats_info_cb stats_cb);
@@ -37,4 +42,6 @@ bool get_imsi_from_telephony_handle(telephony_h handle,
                                                                        char out_buff[], int len_max);
 bool compare_imsis(const char *imsi_a, const char *imsi_b);
 
+void set_mobile_limit_restrictions(stc_h stc_handle, int64_t restriction_limit , data_restriction_type restriction_type);
+
 #endif /* SMARTMANAGER_UTILS_H_ */
index 95f4c8929c1f8ea74039a0c8a83ccbd5def2cf82..abb1aaf9cc1fd9334930d93345d2e9061ebc91e7 100644 (file)
@@ -88,6 +88,17 @@ static Element elements[] = {
                {"Start date",    NULL, ELEMENT_TYPE_START_DATE, NULL}
 };
 
+static void _update_stc_restrictions(Element_Type_E element_type, SmartMgrData *smd)
+{
+       if (element_type == ELEMENT_TYPE_WARNING) {
+               set_mobile_limit_restrictions(smd->stc, smd->sim_1_limits.warning, DATA_RESTRICTION_WARNING_LIMIT);
+       } else if (element_type == ELEMENT_TYPE_LIMIT) {
+               set_mobile_limit_restrictions(smd->stc, smd->sim_1_limits.limit, DATA_RESTRICTION_LIMIT);
+       } else {
+               SLOGE("Unknown element type: %d", element_type);
+       }
+}
+
 static void _update_genlist_limit_item(Element_Type_E element_type, SmartMgrData *smd)
 {
        SETTING_TRACE_BEGIN;
@@ -388,6 +399,7 @@ static void _popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_inf
        Limit_Popup_Data_T *limit_popup_data = (Limit_Popup_Data_T *)data;
 
        _update_genlist_limit_item(limit_popup_data->element_type, limit_popup_data->smd);
+       _update_stc_restrictions(limit_popup_data->element_type, limit_popup_data->smd);
 
        free(limit_popup_data);
        SETTING_TRACE_END;
index ef7c57a06cd3b451f80b02cc3bdf5888378adf7f..96e03de03870833f89bc81d13d9d8756205df82d 100644 (file)
@@ -236,3 +236,74 @@ bool compare_imsis(const char *imsi_a, const char *imsi_b)
 {
        return (0 == safeStrNCmp(imsi_a, imsi_b, 15));
 }
+
+void set_mobile_limit_restrictions(stc_h stc_handle, int64_t restriction_limit, data_restriction_type restriction_type)
+{
+       SETTING_TRACE_BEGIN;
+       int ret = STC_ERROR_NONE;
+       stc_restriction_rule_h rule = NULL;
+
+       ret = stc_restriction_rule_create(stc_handle, &rule);
+       if (STC_ERROR_NONE != ret) {
+               SETTING_TRACE_ERROR("stc_restriction_rule_create() error: %s",
+                                                                       get_error_message(ret));
+               return;
+       }
+
+       ret = stc_restriction_rule_set_app_id(rule, "TOTAL_DATACALL");
+       if (STC_ERROR_NONE != ret) {
+               (void)stc_restriction_rule_destroy(rule);
+               SETTING_TRACE_ERROR("stc_restriction_rule_set_app_id() error: %s",
+                                                                                       get_error_message(ret));
+               return;
+       }
+
+       ret = stc_restriction_rule_set_iface_type(rule, STC_IFACE_DATACALL);
+       if (STC_ERROR_NONE != ret) {
+               (void)stc_restriction_rule_destroy(rule);
+               SETTING_TRACE_ERROR("stc_restriction_rule_set_iface_type() error: %s",
+                                                                                       get_error_message(ret));
+               return;
+       }
+
+       if (restriction_limit > 0 && restriction_limit < G_MAXINT64) {
+               if (restriction_type == DATA_RESTRICTION_LIMIT) {
+                       ret = stc_restriction_rule_set_limit(rule, restriction_limit);
+                       if (STC_ERROR_NONE != ret) {
+                               (void)stc_restriction_rule_destroy(rule);
+                               SETTING_TRACE_ERROR("stc_restriction_rule_set_limit() error: %s",
+                                                                                                       get_error_message(ret));
+                               return;
+                       }
+               } else if (restriction_type == DATA_RESTRICTION_WARNING_LIMIT) {
+                       ret = stc_restriction_rule_set_warning_limit(rule, restriction_limit);
+                       if (STC_ERROR_NONE != ret) {
+                               (void)stc_restriction_rule_destroy(rule);
+                               SETTING_TRACE_ERROR("stc_restriction_rule_set_warning_limit() error: %s",
+                                                                                                       get_error_message(ret));
+                               return;
+                       }
+               }
+       } else {
+               if (restriction_type == DATA_RESTRICTION_LIMIT) {
+                       SETTING_TRACE_ERROR("Incorrect limit.");
+               } else if (restriction_type == DATA_RESTRICTION_WARNING_LIMIT) {
+                       SETTING_TRACE_ERROR("Incorrect warning limit.");
+               }
+
+               (void)stc_restriction_rule_destroy(rule);
+           return;
+       }
+
+       ret = stc_set_restriction(stc_handle, rule);
+       if (STC_ERROR_NONE != ret) {
+               (void)stc_restriction_rule_destroy(rule);
+               SETTING_TRACE_ERROR("stc_set_restriction() error: %s",
+                                                                                       get_error_message(ret));
+               return;
+       }
+
+       (void)stc_restriction_rule_destroy(rule);
+       SETTING_TRACE_END;
+       return;
+}