Sync from SPIN branch 85/47285/1 tizen_3.0.m1_mobile tizen_3.0.m1_tv accepted/tizen/mobile/20150903.053602 accepted/tizen/tv/20150903.053714 accepted/tizen/wearable/20150903.053835 submit/tizen/20150903.021205 submit/tizen_common/20151023.083358 submit/tizen_common/20151026.085049 tizen_3.0.m1_mobile_release tizen_3.0.m1_tv_release tizen_3.0.m2.a1_mobile_release tizen_3.0.m2.a1_tv_release
authorWootak Jung <wootak.jung@samsung.com>
Wed, 2 Sep 2015 04:14:41 +0000 (13:14 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 2 Sep 2015 04:14:41 +0000 (13:14 +0900)
Change-Id: I106c053fa0e863b3f8dded8708d1ccb29ddbcc79

12 files changed:
CMakeLists.txt
README [new file with mode: 0644]
inc/common.h [moved from include/common.h with 95% similarity]
inc/time_update.h [moved from include/time_update.h with 71% similarity]
packaging/tel-plugin-nitz.spec
src/desc-nitz.c
src/time_update.c
tel-plugin-nitz.manifest
test_src/CMakeLists.txt [new file with mode: 0644]
test_src/nitz_test.c [new file with mode: 0644]
test_src/nitz_test.h [new file with mode: 0644]
test_src/nitz_test.sh [new file with mode: 0755]

index c89fd59..9ea87d7 100644 (file)
@@ -1,7 +1,6 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 PROJECT(nitz-plugin C)
 
-# INCLUDE(FindPkgConfig)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(EXEC_PREFIX "\${prefix}")
 SET(LIBDIR ${LIB_INSTALL_DIR})
@@ -24,7 +23,8 @@ FOREACH(flag ${pkgs_CFLAGS})
 ENDFOREACH(flag)
 
 INCLUDE_DIRECTORIES(
-       ${CMAKE_SOURCE_DIR}/include/
+       ${CMAKE_SOURCE_DIR}/inc/
+       ${CMAKE_SOURCE_DIR}/test_src/
 )
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
@@ -36,6 +36,10 @@ ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"NITZ\"")
 ADD_DEFINITIONS("-DPLUGIN_VERSION=${VERSION}")
 ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))")
 
+IF (TIZEN_FEATURE_TEST_ENABLE)
+       ADD_DEFINITIONS("-DTIZEN_FEATURE_TEST_ENABLE")
+ENDIF (TIZEN_FEATURE_TEST_ENABLE)
+
 IF (TIZEN_FEATURE_NEED_RESTORED_GMT)
        ADD_DEFINITIONS("-DTIZEN_FEATURE_NEED_RESTORED_GMT")
 ENDIF (TIZEN_FEATURE_NEED_RESTORED_GMT)
@@ -48,8 +52,11 @@ SET(SRCS
        src/time_update.c
 )
 
+IF (TIZEN_FEATURE_TEST_ENABLE)
+       ADD_SUBDIRECTORY(test_src)
+ENDIF (TIZEN_FEATURE_TEST_ENABLE)
 # library build
-ADD_LIBRARY(nitz-plugin SHARED ${SRCS})
+ADD_LIBRARY(nitz-plugin SHARED ${SRCS} ${TEST_SRCS})
 TARGET_LINK_LIBRARIES(nitz-plugin ${pkgs_LDFLAGS})
 SET_TARGET_PROPERTIES(nitz-plugin PROPERTIES PREFIX "" OUTPUT_NAME nitz-plugin)
 
@@ -57,4 +64,4 @@ SET_TARGET_PROPERTIES(nitz-plugin PROPERTIES PREFIX "" OUTPUT_NAME nitz-plugin)
 INSTALL(TARGETS nitz-plugin
                LIBRARY DESTINATION ${LIBDIR}/telephony/plugins)
 
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/resources/mcctable.xml DESTINATION /opt/data/etc PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ)
\ No newline at end of file
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/resources/mcctable.xml DESTINATION /opt/data/etc PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ)
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..4e2ec44
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+NITZ time updater plugin
similarity index 95%
rename from include/common.h
rename to inc/common.h
index 9ed5cac..9e113fe 100644 (file)
@@ -53,6 +53,7 @@
 #define filelog(fmt, args...) warn(fmt, ##args);
 #endif
 
+#define NITZ_TIMEZONE_SELECT_WAITING_TIMEOUT 20
 #define NITZ_TIMEZONE_MAX_LEN 64
 
 struct nitz_custom_data {
@@ -64,6 +65,7 @@ struct nitz_custom_data {
        char *plmn;
        GHashTable *mcctable_hash;
 
+       guint timezone_sel_timer_id;
        GQueue *nitz_pending_queue;
        CoreObject *co_network;
        TcorePlugin *plugin;
similarity index 71%
rename from include/time_update.h
rename to inc/time_update.h
index 7ad3246..f309858 100644 (file)
 
 int nitz_apply_tzfile (const char *tzfilename);
 gboolean nitz_is_auto_timezone (void);
-gboolean nitz_time_update (const struct tnoti_network_timeinfo *time_info, struct nitz_custom_data *data, gint delay);
-GList * nitz_get_tzlist(char *iso, const struct tnoti_network_timeinfo *ti);
-gboolean nitz_set_time (time_t tt_gmt_nitz);
+gboolean nitz_is_iso_changed(char *cur_iso);
+void nitz_set_iso(char *iso);
+gboolean nitz_time_update (const struct tnoti_network_timeinfo *time_info, struct nitz_custom_data *data, struct timespec curtime);
+GList *nitz_get_tzlist(char *iso);
+GList *nitz_get_tzlist_by_offset(char *iso, const struct tnoti_network_timeinfo *ti);
+gboolean nitz_set_time (struct timespec new_time, struct timespec curtime);
 
 #endif
index 030980f..ef9a9e4 100644 (file)
@@ -1,13 +1,16 @@
+%define test_enable 0
+%define test_bindir /opt/usr/devel/usr/bin
+
 %define major 0
 %define minor 1
-%define patchlevel 70
+%define patchlevel 71
 
 Name:       tel-plugin-nitz
 Summary:    nitz plugin for telephony
 Version:    %{major}.%{minor}.%{patchlevel}
 Release:    1
 Group:      System/Libraries
-License:    Apache
+License:    Apache-2.0
 Source0:    tel-plugin-nitz-%{version}.tar.gz
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
@@ -46,4 +49,7 @@ rm -rf %{buildroot}
 %manifest tel-plugin-nitz.manifest
 %defattr(644,system,system,-)
 %{_libdir}/telephony/plugins/*
+%if 0%{?test_enable}
+%{test_bindir}/nitz_test.sh
+%endif
 /opt/data/etc/mcctable.xml
index 0f21cdc..3d11c02 100644 (file)
@@ -31,6 +31,9 @@
 
 #include "common.h"
 #include "time_update.h"
+#ifdef TIZEN_FEATURE_TEST_ENABLE
+#include "nitz_test.h"
+#endif
 
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
@@ -44,6 +47,7 @@
 
 #define VCONFKEY_WECONN_ALL_CONNECTED  "memory/private/weconn/all_connected"
 #define VCONFKEY_SAP_CONNECTION_TYPE   "memory/private/sap/conn_type"
+#define PROP_NET_NITZ_TIMEZONE                 "nitz_timezone"
 
 typedef enum SapConnType {
        SAP_ALL = 0x00, /* All connectivity */
@@ -60,7 +64,7 @@ struct nitz_time_update_s {
 
        struct tnoti_network_timeinfo *timeinfo;
        struct nitz_custom_data *custom_data;
-       time_t start_time;
+       struct timespec curtime;
 };
 
 static void __load_XML(char *docname, char *groupname, void **i_doc, void **i_root_node)
@@ -145,13 +149,14 @@ char *__nitz_get_country_code_for_mcc(char *operator_mcc, struct nitz_custom_dat
 
 static enum ConnMode __nitz_get_device_connection_mode(void)
 {
+#ifndef TIZEN_FEATURE_COMPANION_MODE_ENABLE
+       return CONN_MODE_STANDALONE;
+#else
        int all_connected = FALSE;
        int sap_conn_type = 0;
 
-#ifdef TIZEN_FEATURE_COMPANION_MODE_ENABLE
        vconf_get_int(VCONFKEY_WECONN_ALL_CONNECTED, &all_connected);
        vconf_get_int(VCONFKEY_SAP_CONNECTION_TYPE, &sap_conn_type);
-#endif
        info("(%s : %d) (%s : %d)", VCONFKEY_WECONN_ALL_CONNECTED, all_connected, VCONFKEY_SAP_CONNECTION_TYPE, sap_conn_type);
 
        if (!all_connected) {
@@ -170,23 +175,72 @@ static enum ConnMode __nitz_get_device_connection_mode(void)
                }
        }
        return CONN_MODE_UNKNOWN;
+#endif
+}
+
+static gboolean __nitz_is_airplain_mode(void)
+{
+       gboolean flightmode = FALSE;
+       vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flightmode);
+       return flightmode;
+}
+
+static gboolean _on_timeout_timezone_nitz_not_update(gpointer user_cb_data)
+{
+       struct nitz_custom_data *custom_data = user_cb_data;
+
+       if(!custom_data)
+               return G_SOURCE_REMOVE;
+
+       if(CONN_MODE_COMPAINION == __nitz_get_device_connection_mode()) {
+               info("device is in companion mode! do not ask to user");
+       } else if (FALSE == nitz_is_auto_timezone()) {
+               info("Already manual timezone! do not ask to user");
+       } else if (TRUE == __nitz_is_airplain_mode()) {
+               info("Flight Mode! do not ask to user");
+       } else {
+               info("nitz not updated. ask to user");
+               tcore_object_set_property(custom_data->co_network,
+                       PROP_NET_NITZ_TIMEZONE, "user_selection_required");
+       }
+
+       custom_data->timezone_sel_timer_id = 0;
+       return G_SOURCE_REMOVE;
+}
+
+static void _wait_nitz_and_timezone_select_by_user(struct nitz_custom_data *custom_data)
+{
+       if(!custom_data)
+               return;
+
+       custom_data->timezone_sel_timer_id = g_timeout_add_seconds(NITZ_TIMEZONE_SELECT_WAITING_TIMEOUT,
+               _on_timeout_timezone_nitz_not_update, custom_data);
+       dbg("Add timer(%d) timeout(%d)", custom_data->timezone_sel_timer_id, NITZ_TIMEZONE_SELECT_WAITING_TIMEOUT);
 }
 
-static gboolean  _check_area_changed(char *iso)
+static void _stop_nitz_waiting(struct nitz_custom_data *custom_data)
 {
-       char *saved_iso = NULL;
-       gboolean area_changed = TRUE;
+       if (custom_data && custom_data->timezone_sel_timer_id != 0) {
+               gboolean ret;
 
-       saved_iso = vconf_get_str(VCONFKEY_TELEPHONY_PRIVATE_NITZ_ISO);
-       if (saved_iso) {
-               info("saved iso:[%s], mcc iso:[%s]", saved_iso, iso);
-               if (g_ascii_strcasecmp(saved_iso, iso) == 0)
-                       area_changed = FALSE;
+               ret = g_source_remove(custom_data->timezone_sel_timer_id);
+               if (FALSE == ret)
+                       warn("g_source_remove fail");
+               else
+                       dbg("Stopped");
 
-               free(saved_iso);
+               custom_data->timezone_sel_timer_id = 0;
        }
+}
+
+static void _check_fix_multi_time_zone(struct nitz_custom_data *custom_data,
+       int mcc, char *iso, char *timezone_name)
+{
+       if (!custom_data || !iso)
+               return;
 
-       return area_changed;
+       info("We have no way to select timezone. waiting NITZ and ask to user.");
+       _wait_nitz_and_timezone_select_by_user(custom_data);
 }
 
 static void _check_fix_time_zone(struct nitz_custom_data *custom_data)
@@ -241,17 +295,19 @@ static void _check_fix_time_zone(struct nitz_custom_data *custom_data)
        mcc = atoi(mcc_str);
        iso = __nitz_get_country_code_for_mcc(mcc_str, custom_data);
        if (iso) {
-               tz_list = nitz_get_tzlist(iso, NULL);
+               tz_list = nitz_get_tzlist(iso);
                tz_count =  g_list_length(tz_list);
                dbg("tz_count - %d", tz_count);
                if (tz_count > 0) {
-                       if (_check_area_changed(iso)) {
+                       if (nitz_is_iso_changed(iso)) {
                                timezone_name = tz_list->data;
                                if (tz_count > 1) {
-                                       info("Multi timezone, Can not select (Need gmtoff, dmtoff, ...");
+                                       info(" Multi timezone");
+                                       _check_fix_multi_time_zone(custom_data, mcc, iso, timezone_name);
                                } else {
                                        info("Single timezone. Apply (mcc:[%d] iso:[%s] zone:[%s])", mcc, iso, timezone_name);
-                                       nitz_apply_tzfile(timezone_name);
+                                       nitz_apply_tzfile (timezone_name);
+                                       _stop_nitz_waiting(custom_data);
                                }
                        } else {
                                info("Same Area. Do not change timezone now");
@@ -264,6 +320,20 @@ static void _check_fix_time_zone(struct nitz_custom_data *custom_data)
                dbg("country code is NULL for mcc %d", mcc);
        }
 
+       switch (mcc) {
+               case 1:
+               case 999:
+                       info("Exceptional mcc(%d). do not ask timezone to user", mcc);
+                       mcc = -1;
+               break;
+               default:
+               break;
+       }
+       if (mcc >= 0) {
+               info("Cannot find. Timezone for mcc:[%d]. Ask to user", mcc);
+               _wait_nitz_and_timezone_select_by_user(custom_data);
+               nitz_set_iso(iso);
+       }
 EXIT:
        g_list_free_full(tz_list, g_free);
        g_free(iso);
@@ -274,21 +344,10 @@ static gboolean _update_network_timeinfo(gpointer user_data)
        struct nitz_time_update_s *time_update = user_data;
        struct tnoti_network_timeinfo *timeinfo = NULL;
        struct nitz_custom_data *custom_data = NULL;
-       time_t current_time = 0;
-       gint delay = 0;
 
        if  (!time_update)
                return FALSE;
 
-       if (nitz_is_auto_timezone()) {
-               /* Time update delay is calculated only for Automatic time update mode.
-                * For manual time update mode, we can't rely on system time for current time to derive offset/delay
-                */
-               time(&current_time);
-               delay = current_time - time_update->start_time;
-               info("Enqueued_timestamp[%u] Dequeued_timestamp[%u] delay[%d]", time_update->start_time, current_time, delay);
-       }
-
        timeinfo = time_update->timeinfo;
        custom_data = time_update->custom_data;
        custom_data->nitz_updated = TRUE;
@@ -315,7 +374,9 @@ static gboolean _update_network_timeinfo(gpointer user_data)
                g_strlcpy(timeinfo->plmn, custom_data->plmn, strlen(custom_data->plmn)+1);
        }
 
-       nitz_time_update(timeinfo, custom_data, delay);
+       if (nitz_time_update(timeinfo, custom_data, time_update->curtime)) {
+               _stop_nitz_waiting(custom_data);
+       }
 
        g_free(timeinfo);
        g_free(time_update);
@@ -421,6 +482,9 @@ static enum tcore_hook_return on_hook_network_timeinfo(Server *s, CoreObject *so
        struct nitz_time_update_s *time_update;
        struct tnoti_network_timeinfo *timeinfo = data;
        struct nitz_custom_data *custom_data = user_data;
+       struct timespec curtime;
+
+       clock_gettime(CLOCK_REALTIME, &curtime);
 
        filelog("NITZ !! (time(NULL) = %u)", (unsigned int)time(NULL));
 
@@ -439,13 +503,14 @@ static enum tcore_hook_return on_hook_network_timeinfo(Server *s, CoreObject *so
        time_update->custom_data = custom_data;
        time_update->timeinfo = g_memdup(timeinfo, sizeof(struct tnoti_network_timeinfo));
        time_update->co_network = source;
+       time_update->curtime.tv_sec = curtime.tv_sec;
+       time_update->curtime.tv_nsec = curtime.tv_nsec;
 
        if (g_queue_is_empty(custom_data->nitz_pending_queue)) {
                info("No pending NITZ");
                g_idle_add(_process_nitz_pending, custom_data);
        }
        info("Add nitz info to queue");
-       time(&time_update->start_time);
        g_queue_push_tail(custom_data->nitz_pending_queue, time_update);
 
        return TCORE_HOOK_RETURN_CONTINUE;
@@ -526,6 +591,10 @@ static gboolean on_init(TcorePlugin *p)
        if (modems_count == 2)
                vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT2, on_vconf_sim_slot_state, data);
 
+#ifdef TIZEN_FEATURE_TEST_ENABLE
+       nitz_test_init(p);
+#endif
+
        return TRUE;
 }
 
@@ -537,6 +606,10 @@ static void on_unload(TcorePlugin *p)
 
        dbg("i'm unload");
 
+#ifdef TIZEN_FEATURE_TEST_ENABLE
+       nitz_test_deinit(p);
+#endif
+
        data = tcore_plugin_ref_user_data(p);
        if (!data)
                return;
@@ -558,6 +631,8 @@ static void on_unload(TcorePlugin *p)
        if (modems_count == 2)
                vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT2, on_vconf_sim_slot_state);
 
+       if (data->timezone_sel_timer_id != 0)
+               g_source_remove(data->timezone_sel_timer_id);
        free(data);
 }
 
index faf8ce4..9e5c38c 100644 (file)
@@ -55,6 +55,37 @@ gboolean nitz_is_auto_timezone(void)
        }
 }
 
+gboolean nitz_is_iso_changed(char *iso)
+{
+       char *saved_iso = NULL;
+       gboolean area_changed = TRUE;
+
+       saved_iso = vconf_get_str (VCONFKEY_TELEPHONY_NITZ_ISO);
+       if (saved_iso) {
+               info("saved iso:[%s], mcc iso:[%s]", saved_iso, iso);
+               if (g_ascii_strcasecmp(saved_iso, iso) == 0) {
+                       area_changed = FALSE;
+               }
+               free(saved_iso);
+       }
+       return area_changed;
+}
+
+void nitz_set_iso(char *iso)
+{
+       int ret = 0;
+
+       if (!iso)
+               return;
+
+       ret = vconf_set_str (VCONFKEY_TELEPHONY_NITZ_ISO, iso);
+       if (ret < 0) {
+               warn("Fail to save iso:[%s]. ret=%d", iso, ret);
+       } else {
+               info("iso saved:[%s]", iso);
+       }
+}
+
 static int nitz_get_uptime(void)
 {
        struct sysinfo sys_info;
@@ -67,11 +98,11 @@ static int nitz_get_uptime(void)
        return 0;
 }
 
-gboolean nitz_set_time(time_t new_time)
+gboolean nitz_set_time(struct timespec newtime, struct timespec curtime)
 {
        int ret = 0;
 
-       vconf_set_int(VCONFKEY_TELEPHONY_NITZ_GMT, new_time);
+       vconf_set_int(VCONFKEY_TELEPHONY_NITZ_GMT, newtime.tv_sec);
        vconf_set_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, nitz_get_uptime());
 
        if (!nitz_is_auto_timezone()) {
@@ -82,18 +113,19 @@ gboolean nitz_set_time(time_t new_time)
        /*
         *  - Apply system time(GMT)
         */
-       info("[TIMESTAMP][Before] NITZ GMT Time = %ld", new_time);
+       info ("[TIMESTAMP][Before] New Time[secs = %lu, nsecs = %lu], Current Time[secs = %lu, nsecs = %lu]",
+               newtime.tv_sec, newtime.tv_nsec, curtime.tv_sec, curtime.tv_nsec);
 
        /* Acquire lock */
        ret = device_power_request_lock(POWER_LOCK_CPU, 0);
        if (ret < 0)
                err("ret : (0x%x)", ret);
 
-       ret = alarmmgr_set_systime(new_time);
-       if (ret < 0)
-               info("[TIMESTAMP] alarmmgr_set_systime fail. (ret=%d)", ret);
-       else
-               info("[TIMESTAMP][After] alarm_set_time(%ld) success", new_time);
+       if (alarmmgr_set_systime_with_propagation_delay(newtime, curtime) != ALARMMGR_RESULT_SUCCESS) {
+               info ("[TIMESTAMP] alarmmgr_set_systime_with_propagation_delay fail. (ret=%d)", ret);
+       } else {
+               info ("[TIMESTAMP][After] alarmmgr_set_systime_with_propagation_delay success");
+       }
 
        /* Release lock */
        ret = device_power_release_lock(POWER_LOCK_CPU);
@@ -108,14 +140,27 @@ gboolean nitz_apply_tzfile(const char *tzfilename)
        char current_tz[BUF_SIZE] = {0, };
        int ret = -1;
        ssize_t len;
+       char *current = NULL;
 
        if (!tzfilename) {
                err("tzfilename is NULL");
                return FALSE;
        }
 
+       current = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE);
+       if (current) {
+               if (g_strcmp0(tzfilename, current)) {
+                       ret = vconf_set_str (VCONFKEY_TELEPHONY_NITZ_ZONE, tzfilename);
+               } else {
+                       dbg("Same timezone - current[%s], tzfilename[%s]", current, tzfilename);
+               }
+               free(current);
+       } else {
+               ret = vconf_set_str (VCONFKEY_TELEPHONY_NITZ_ZONE, tzfilename);
+       }
+
        if (!nitz_is_auto_timezone()) {
-               info("[TIMESTAMP] Automatic time update was disabled. We don't need to set time");
+               info("[TIMESTAMP] Automatic time update was disabled. We don't need to set timezone");
                return FALSE;
        }
 
@@ -169,7 +214,7 @@ static gboolean __update_timezone_by_offset(const struct tnoti_network_timeinfo
        gboolean ret = FALSE;
        gboolean found = FALSE;
 
-       tz_list = nitz_get_tzlist(iso, ti);
+       tz_list = nitz_get_tzlist_by_offset(iso, ti);
        tz_count = g_list_length(tz_list);
        if (tz_count == 1) {
                timezone_name = tz_list ? tz_list->data : NULL;
@@ -205,20 +250,22 @@ static gboolean __update_timezone_by_offset(const struct tnoti_network_timeinfo
                }
        }
 
-       if (found)
-               ret = nitz_apply_tzfile(timezone_name);
-       else
+       if (found) {
+               ret = nitz_apply_tzfile (timezone_name);
+               nitz_set_iso(iso);
+       } else {
                info("[TIMESTAMP] Fail to find timezone");
+       }
 
        g_list_free_full(tz_list, g_free);
        return ret;
 }
 
 static gboolean __update_time(const struct tnoti_network_timeinfo *ti,
-       struct nitz_custom_data *data, gint delay)
+       struct nitz_custom_data *data, struct timespec curtime)
 {
        struct tm tm_time;
-       time_t tt_gmt_nitz;
+       struct timespec newtime = {0,};
 
        memset(&tm_time, 0, sizeof(struct tm));
        tm_time.tm_year = ti->year - 1900 + 2000;
@@ -230,20 +277,12 @@ static gboolean __update_time(const struct tnoti_network_timeinfo *ti,
        tm_time.tm_wday = ti->wday;
        tm_time.tm_isdst = ti->dstoff;
 
-       tt_gmt_nitz = timegm(&tm_time)+delay;
-#ifdef TIZEN_FEATURE_NEED_RESTORED_GMT
-       /*
-        * Need to set GMT+0 time.
-        * but, in case of IMC-modem, CP send the time applied GMT.(e.g., GMT+9 in Korea)
-        * so, restore GMT+0 time.
-        */
-       tt_gmt_nitz -= ti->gmtoff * 60;
-#endif
-
-       return nitz_set_time(tt_gmt_nitz);
+       newtime.tv_sec = timegm (&tm_time);
+       return nitz_set_time(newtime, curtime);
 }
 
-static gboolean __update_timezone(const struct tnoti_network_timeinfo *ti, struct nitz_custom_data *data)
+static gboolean __update_timezone(const struct tnoti_network_timeinfo *ti,
+       struct nitz_custom_data *data)
 {
        int mcc = -1;
        char mcc_str[4] = {0,};
@@ -252,6 +291,9 @@ static gboolean __update_timezone(const struct tnoti_network_timeinfo *ti, struc
        memcpy(mcc_str, ti->plmn, 3);
        mcc = atoi(mcc_str);
 
+       /*
+        * Find tzfile
+        */
        if (mcc >= 0) {
                char *iso = __nitz_get_country_code_for_mcc(mcc_str, data);
                ret = __update_timezone_by_offset(ti, iso);
@@ -261,7 +303,54 @@ static gboolean __update_timezone(const struct tnoti_network_timeinfo *ti, struc
        return ret;
 }
 
-GList *nitz_get_tzlist(char *iso, const struct tnoti_network_timeinfo *ti)
+GList * nitz_get_tzlist(char *iso)
+{
+       char* timezone_name = 0;
+       UEnumeration* enum_tz = 0;
+       UErrorCode ec = U_ZERO_ERROR;
+       const UChar* timezone_id = 0;
+       int timezone_id_len = 0;
+       int offset = 0;
+       gboolean in_dst = 0;
+       GList *tz_list = NULL;
+       UCalendar *cal = NULL;
+       unsigned int offset_hash = 0;
+       gboolean dup_check[48][2]; // offset*2, dst
+
+       enum_tz = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, iso, NULL, &ec);
+       memset(dup_check, FALSE, sizeof(dup_check));
+
+       while (1) {
+               if (enum_tz == NULL) {
+                       break;
+               }
+               timezone_id = uenum_unext(enum_tz, &timezone_id_len, &ec);
+               if (timezone_id == NULL)
+                       break;
+
+               cal = ucal_open(timezone_id, u_strlen(timezone_id), uloc_getDefault(), UCAL_TRADITIONAL, &ec);
+               in_dst = ucal_inDaylightTime(cal, &ec);
+               offset = ucal_get(cal, UCAL_ZONE_OFFSET, &ec);
+               offset_hash = (offset/1800000) + 24;
+               ucal_close(cal);
+
+               dbg("TZ DST:[%d] TZ offset:[%d] offset_hash:[%d]", in_dst, offset, offset_hash);
+               if (dup_check[offset_hash][in_dst] == TRUE) {
+                       dbg("Ignore Duplicated");
+                       continue;
+               }
+               dup_check[offset_hash][in_dst] = TRUE;
+
+               timezone_name = (char *)g_malloc0(NITZ_TIMEZONE_MAX_LEN);
+               u_UCharsToChars(timezone_id, timezone_name, NITZ_TIMEZONE_MAX_LEN);
+               tz_list = g_list_append(tz_list, timezone_name);
+               info("[TIMESTAMP] ISO:[%s] offset:[%d], Available TZ:[%s]", iso, offset, timezone_name);
+       }
+       uenum_close(enum_tz);
+       return tz_list;
+}
+
+GList *nitz_get_tzlist_by_offset(char *iso, const struct tnoti_network_timeinfo *ti)
 {
        char *timezone_name = 0;
        UEnumeration *enum_tz = 0;
@@ -278,7 +367,8 @@ GList *nitz_get_tzlist(char *iso, const struct tnoti_network_timeinfo *ti)
                dbg("offset = %d", offset);
                enum_tz = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, iso, &offset, &ec);
        } else {
-               enum_tz = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, iso, NULL, &ec);
+               err("Invalid offset");
+               return NULL;
        }
 
        while (1) {
@@ -299,7 +389,7 @@ GList *nitz_get_tzlist(char *iso, const struct tnoti_network_timeinfo *ti)
 }
 
 gboolean nitz_time_update(const struct tnoti_network_timeinfo *time_info,
-       struct nitz_custom_data *data, gint delay)
+       struct nitz_custom_data *data, struct timespec curtime)
 {
        gboolean ret_time, ret_tz;
 
@@ -320,7 +410,7 @@ gboolean nitz_time_update(const struct tnoti_network_timeinfo *time_info,
         *      1. Time
         *      2. Timezone
         */
-       ret_time = __update_time(time_info, data, delay);
+       ret_time = __update_time(time_info, data, curtime);
        ret_tz = __update_timezone(time_info, data);
 
        if (ret_time || ret_tz)
index 97e8c31..42880e3 100644 (file)
@@ -1,5 +1,9 @@
 <manifest>
-       <request>
-               <domain name="_"/>
-       </request>
+ <assign>
+       <filesystem path="/opt/usr/devel/usr/bin/nitz_test.sh" label="_" exec_label="none"/>
+ </assign>
+ <request>
+  <domain name="_"/>
+ </request>
 </manifest>
+
diff --git a/test_src/CMakeLists.txt b/test_src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b617ea6
--- /dev/null
@@ -0,0 +1,5 @@
+SET(TEST_SRCS
+       ${CMAKE_CURRENT_SOURCE_DIR}/nitz_test.c
+       PARENT_SCOPE
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/nitz_test.sh DESTINATION ${TIZEN_TEST_BIN_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ)
\ No newline at end of file
diff --git a/test_src/nitz_test.c b/test_src/nitz_test.c
new file mode 100644 (file)
index 0000000..f8d1a73
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ * tel-plugin-nitz
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Ja-young Gu <jygu@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nitz_test.h"
+
+#include "common.h"
+#include "time_update.h"
+
+#include <glib.h>
+#include <string.h>
+#include <vconf.h>
+#include <plugin.h>
+
+#define NITZ_VCONF_LAUNCH_TEST0        "memory/private/telephony/nitz_test0"
+#define NITZ_VCONF_LAUNCH_TEST1        "memory/private/telephony/nitz_test1"
+#define NITZ_VCONF_LAUNCH_TEST2        "memory/private/telephony/nitz_test2"
+
+/* FIXME: Make better APIs in plugin */
+extern enum ConnMode __nitz_get_device_connection_mode(void);
+extern void _check_fix_time_zone(struct nitz_custom_data *custom_data);
+
+static void on_hook_test0(keynode_t *node, void *user_data);
+static void on_hook_test1(keynode_t *node, void *user_data);
+static void on_hook_test2(keynode_t *node, void *user_data);
+
+void on_hook_test0(keynode_t *node, void *user_data)
+{
+       int rv = 0;
+
+       if (vconf_get_int(NITZ_VCONF_LAUNCH_TEST0, &rv) == 0
+               && rv == 1) {
+
+               struct nitz_custom_data *custom_data = tcore_plugin_ref_user_data((TcorePlugin *)user_data);
+               struct tnoti_network_timeinfo *timeinfo;
+               char *test_plmn = "31000";
+               struct timespec curtime= {0,};
+
+               clock_gettime(CLOCK_REALTIME, &curtime);
+               dbg("[RUNNING TEST] on_hook_test0()");
+
+               timeinfo = g_malloc0(sizeof(struct tnoti_network_timeinfo));
+
+               timeinfo->year = 14;
+               timeinfo->month = 11;
+               timeinfo->day = 2;
+               timeinfo->hour = 5;
+               timeinfo->minute = 59;
+               timeinfo->second = 19;
+               timeinfo->wday = 6;
+               timeinfo->gmtoff = -240;
+               timeinfo->dstoff = 1;
+               timeinfo->isdst = 1;
+               g_strlcpy(timeinfo->plmn, test_plmn, 7);
+
+               filelog("NITZ !! (time(NULL) = %u)", (unsigned int)time(NULL));
+
+               dbg(" +- %04d-%02d-%02d %02d:%02d:%02d wday=%d",
+                               timeinfo->year, timeinfo->month, timeinfo->day,
+                               timeinfo->hour, timeinfo->minute, timeinfo->second,
+                               timeinfo->wday);
+               dbg(" +- GMT-offset:%d, DST-offset:%d, is_dst:%d",
+                               timeinfo->gmtoff, timeinfo->dstoff, timeinfo->isdst);
+
+               custom_data->nitz_updated = TRUE;
+               custom_data->need_fix_zone = FALSE;
+
+               if(CONN_MODE_COMPAINION == __nitz_get_device_connection_mode()) {
+                       dbg("device is in companion mode! ignore NITZ update");
+                       g_free(timeinfo);
+                       return;
+               }
+
+               nitz_time_update(timeinfo, custom_data, curtime);
+               g_free(timeinfo);
+       } /* End Test */
+}
+
+void on_hook_test1(keynode_t *node, void *user_data)
+{
+       struct nitz_custom_data *custom_data = tcore_plugin_ref_user_data((TcorePlugin *)user_data);
+       struct tnoti_network_change *info = NULL;
+       gboolean is_mcc_changed = FALSE;
+       char *test_plmn = "310470";
+
+       test_plmn = vconf_get_str(NITZ_VCONF_LAUNCH_TEST1);
+       if (test_plmn == NULL) {
+               err("PLMN is NULL");
+               return;
+       }
+
+       if (strlen(test_plmn) == 0) {
+               dbg("Invalid data");
+               g_free(test_plmn);
+               return;
+       }
+
+       dbg("[RUNNING TEST] on_hook_test1()");
+
+       info = g_malloc0(sizeof(struct tnoti_network_change));
+       g_strlcpy(info->plmn, test_plmn, 7);
+       dbg("testplmn : %s", test_plmn);
+
+       if ((custom_data->plmn && strncmp(info->plmn, custom_data->plmn, 3))
+               || (!custom_data->plmn)) {
+               dbg("MCC change (%s) -> (%s)", custom_data->plmn?custom_data->plmn:"", info->plmn);
+               g_free(custom_data->plmn);
+               custom_data->plmn = g_strdup(info->plmn);
+               is_mcc_changed = TRUE;
+       }
+
+       if (is_mcc_changed) {
+               if(CONN_MODE_COMPAINION == __nitz_get_device_connection_mode()) {
+                       dbg("device is in companion mode! ignore MCC change");
+               } else {
+                       custom_data->need_fix_zone = TRUE;
+                       _check_fix_time_zone(custom_data);
+               }
+       }
+
+       g_free(info);
+       g_free(test_plmn);
+}
+
+void on_hook_test2(keynode_t *node, void *user_data)
+{
+
+       int rv = 0;
+
+       if (vconf_get_int(NITZ_VCONF_LAUNCH_TEST2, &rv) == 0
+               && rv == 1) {
+
+               struct nitz_custom_data *custom_data = tcore_plugin_ref_user_data((TcorePlugin *)user_data);
+               struct tnoti_network_timeinfo *timeinfo;
+               char *test_plmn = "31000";
+               struct timespec curtime= {0,};
+
+               clock_gettime(CLOCK_REALTIME, &curtime);
+               dbg("[RUNNING TEST] on_hook_test2()");
+
+               timeinfo = g_malloc0(sizeof(struct tnoti_network_timeinfo));
+
+               timeinfo->year = 14;
+               timeinfo->month = 11;
+               timeinfo->day = 2;
+               timeinfo->hour = 6;
+               timeinfo->minute = 0;
+               timeinfo->second = 9;
+               timeinfo->wday = 6;
+               timeinfo->gmtoff = -300;
+               timeinfo->dstoff = 0;
+               timeinfo->isdst = 1;
+               g_strlcpy(timeinfo->plmn, test_plmn, 7);
+
+               filelog("NITZ !! (time(NULL) = %u)", (unsigned int)time(NULL));
+
+               dbg(" +- %04d-%02d-%02d %02d:%02d:%02d wday=%d",
+                               timeinfo->year, timeinfo->month, timeinfo->day,
+                               timeinfo->hour, timeinfo->minute, timeinfo->second,
+                               timeinfo->wday);
+               dbg(" +- GMT-offset:%d, DST-offset:%d, is_dst:%d",
+                               timeinfo->gmtoff, timeinfo->dstoff, timeinfo->isdst);
+
+               custom_data->nitz_updated = TRUE;
+               custom_data->need_fix_zone = FALSE;
+
+               if(CONN_MODE_COMPAINION == __nitz_get_device_connection_mode()) {
+                       dbg("device is in companion mode! ignore NITZ update");
+                       g_free(timeinfo);
+                       return;
+               }
+
+               nitz_time_update(timeinfo, custom_data, curtime);
+               g_free(timeinfo);
+       } /* End Test */
+}
+
+void nitz_test_init(TcorePlugin *plugin)
+{
+       vconf_notify_key_changed(NITZ_VCONF_LAUNCH_TEST0, on_hook_test0, plugin);
+       vconf_notify_key_changed(NITZ_VCONF_LAUNCH_TEST1, on_hook_test1, plugin);
+       vconf_notify_key_changed(NITZ_VCONF_LAUNCH_TEST2, on_hook_test2, plugin);
+}
+
+void nitz_test_deinit(TcorePlugin *plugin)
+{
+       vconf_ignore_key_changed(NITZ_VCONF_LAUNCH_TEST0, on_hook_test0);
+       vconf_ignore_key_changed(NITZ_VCONF_LAUNCH_TEST1, on_hook_test1);
+       vconf_ignore_key_changed(NITZ_VCONF_LAUNCH_TEST2, on_hook_test2);
+}
diff --git a/test_src/nitz_test.h b/test_src/nitz_test.h
new file mode 100644 (file)
index 0000000..bfa79e2
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * tel-plugin-nitz
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Ja-young Gu <jygu@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <tcore.h>
+
+void nitz_test_init(TcorePlugin *plugin);
+
+void nitz_test_deinit(TcorePlugin *plugin);
\ No newline at end of file
diff --git a/test_src/nitz_test.sh b/test_src/nitz_test.sh
new file mode 100755 (executable)
index 0000000..063b8bb
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+#------------------------
+# tel-plugin-nitz
+#------------------------
+
+## Launch test0
+function launch_test0() {
+#      vconftool set -t int memory/private/telephony/nitz_test0 1 -i -f -s tizen::vconf::platform::rw
+}
+
+## Launch test1
+function launch_test1() {
+#      vconftool set -t string memory/private/telephony/nitz_test1 "$1" -i -f -s tizen::vconf::platform::rw
+}
+
+## Launch test2
+function launch_test2() {
+#      vconftool set -t int memory/private/telephony/nitz_test2 1 -i -f -s tizen::vconf::platform::rw
+}
+
+launch_test0
+
+launch_test1 "310471"
+
+launch_test2