From b694820847ce25dd74d465aeac91ee89db7304c3 Mon Sep 17 00:00:00 2001 From: Kairong Yin Date: Fri, 2 Nov 2012 10:36:22 +0800 Subject: [PATCH] Apply time and date auto-update via Sim Card(Rebase) Change-Id: I9ebc846a8b1b3994ca89400a8af48fdf486c8914 --- setting-time/src/setting-time-main.c | 129 +++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/setting-time/src/setting-time-main.c b/setting-time/src/setting-time-main.c index c13a78f..35e1578 100755 --- a/setting-time/src/setting-time-main.c +++ b/setting-time/src/setting-time-main.c @@ -560,6 +560,48 @@ static int setting_time_main_create(void *cb) &err); bool auto_flag = value; + if(auto_flag) //do special process only when auto mode + { + //to read TAPI vconfs + int ret = 0; + int t_nitz = 0; + int t_offset = 0; + ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_GMT, &t_nitz); + ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, &t_offset); + char *tzpath = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE); + if (ret == 0 && !isEmptyStr(tzpath)) + { + //1.to update timezone + char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1]; + safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4); + g_strlcat(tz_path, tzpath, sizeof(tz_path)); + SETTING_TRACE("full tz_path:%s", tz_path); + ret = sysman_set_timezone(tz_path); + if (ret < 0) { + SETTING_TRACE("tzpath is not valid."); + } else + SETTING_TRACE("sysman_set_timezone - successful : %s \n", tz_path); + if (!__setting_set_city_tzone(tzpath)) { + SETTING_TRACE("__setting_set_city_tzone ERROR") + } + if (get_city_name(tzpath)) { + SETTING_TRACE(">>>>>> RESULT : %s", get_city_name_result()); + } + char* city = get_city_name_result(); + SETTING_TRACE("city:%s", city); + ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city); + + // 2.to set current time + int t_uptime = 0; + FILE *fp = fopen("/proc/uptime", "r"); + fscanf(fp, "%d", &t_uptime); + SETTING_TRACE("t_nitz:%d, t_offset:%d, t_uptime:%d", t_nitz, t_offset, t_uptime); + time_t t_current = t_nitz + t_uptime - t_offset; + SETTING_TRACE("t_current:%d", t_current); + ret = sysman_set_datetime(t_current); + } + } + /* UI automatic */ if (!isEmulBin()) { ad->data_auto = @@ -930,6 +972,7 @@ setting_time_main_launch_worldclock_result_ug_cb(ui_gadget_h ug, } else { SETTING_TRACE("tzpath : %s", tzpath ); } + SETTING_TRACE("city : %s", city ); /* --------------------------------------------------------------------- */ char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1]; @@ -1147,6 +1190,84 @@ static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj, ad->pop = NULL; } } +static void __time_auto_update(void *data) +{ + setting_retm_if(data == NULL, "Data parameter is NULL"); + SettingTimeUG *ad = (SettingTimeUG *) data; + int err; + setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, + SETTING_ON_OFF_BTN_ON, &err); + if (ad->data_tz) { + setting_disable_genlist_item(ad->data_tz->item); + } + + if (ad->data_time) { + ad->data_time->isItemDisableFlag = FALSE; + setting_disable_evas_object(ad->data_time->eo_check); + setting_disable_genlist_item(ad->data_time->item); + } + + int ret = 0; + + int t_nitz = 0; + int t_offset = 0; + ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_GMT, &t_nitz); + ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, &t_offset); + char *tzpath = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE); + if (ret != 0 || isEmptyStr(tzpath)) + { + setting_create_simple_popup(ad, ad->win_get, + NULL, _("TAPI doesn't support this sim card to update time automatically!")); + return; + } + ret = 0;//reset.. + + // a.time zone + SETTING_TRACE("tz_path:%s", tzpath); + + char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1]; + safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4); + g_strlcat(tz_path, tzpath, sizeof(tz_path)); + SETTING_TRACE("full tz_path:%s", tz_path); + ret = sysman_set_timezone(tz_path); + if (ret < 0) { + SETTING_TRACE("tzpath is not valid."); + return; + } else + SETTING_TRACE("sysman_set_timezone - successful : %s \n", tz_path); + if (!__setting_set_city_tzone(tzpath)) { + SETTING_TRACE("__setting_set_city_tzone ERROR") + return; + } + if (get_city_name(tzpath)) { + SETTING_TRACE(">>>>>> RESULT : %s", get_city_name_result()); + } + char* city = get_city_name_result(); + SETTING_TRACE("city:%s", city); + ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city); + setting_retm_if(ret != 0, "set vconf failed"); + setting_update_timezone(ad); + + // b.TIME AND DATE + int t_uptime = 0; + FILE *fp = fopen("/proc/uptime", "r"); + fscanf(fp, "%d", &t_uptime); + SETTING_TRACE("t_nitz:%d, t_offset:%d, t_uptime:%d", t_nitz, t_offset, t_uptime); + time_t t_current = t_nitz + t_uptime - t_offset; + SETTING_TRACE("t_current:%d", t_current); + ret = sysman_set_datetime(t_current); + setting_retm_if(ret == -1, "sysman_set_datetime call failed"); + //ad->changed_time = t_current; + if (ad->data_time) { + struct tm ts_ret; + struct tm *ts = localtime_r(&t_current, &ts_ret); + ret_if(!ts); + elm_datetime_value_set(ad->data_time->eo_check, &ts_ret); + } + + // c.heynoti_publish + heynoti_publish(SETTING_TIME_CHANGED); +} static void setting_time_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info) @@ -1188,6 +1309,7 @@ setting_time_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info) } } else { +#if UN_SUPPORT_TIME_DYNAMIC_UPDATE ad->pop = setting_create_popup_with_btn(ad, ad->win_get, NULL, _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"), @@ -1196,6 +1318,9 @@ setting_time_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info) dgettext("sys_string", "IDS_COM_SK_OK"), _("IDS_COM_SK_CANCEL")); +#else + __time_auto_update(ad); +#endif } } } @@ -1262,6 +1387,7 @@ static void setting_time_main_mouse_up_Gendial_list_cb(void *data, Evas_Object * } } else { + #if UN_SUPPORT_TIME_DYNAMIC_UPDATE ad->pop = setting_create_popup_with_btn(ad, ad->win_get, NULL, _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"), @@ -1269,6 +1395,9 @@ static void setting_time_main_mouse_up_Gendial_list_cb(void *data, Evas_Object * 0, 2, dgettext("sys_string", "IDS_COM_SK_OK"), _("IDS_COM_SK_CANCEL")); + #else + __time_auto_update(ad); + #endif } } else if (!safeStrCmp("IDS_ST_BODY_TIME_FORMAT", list_item->keyStr) -- 2.7.4