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})
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}")
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)
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)
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)
--- /dev/null
+NITZ time updater plugin
#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 {
char *plmn;
GHashTable *mcctable_hash;
+ guint timezone_sel_timer_id;
GQueue *nitz_pending_queue;
CoreObject *co_network;
TcorePlugin *plugin;
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
+%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
%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
#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>
#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 */
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)
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) {
}
}
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)
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");
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);
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(¤t_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;
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);
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));
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;
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;
}
dbg("i'm unload");
+#ifdef TIZEN_FEATURE_TEST_ENABLE
+ nitz_test_deinit(p);
+#endif
+
data = tcore_plugin_ref_user_data(p);
if (!data)
return;
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);
}
}
}
+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;
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()) {
/*
* - 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);
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;
}
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;
}
}
- 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;
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,};
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);
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;
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) {
}
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;
* 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)
<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>
+
--- /dev/null
+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
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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
--- /dev/null
+#!/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