2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <sys/types.h>
28 #include "include/ss_data.h"
33 #include <sys/ioctl.h>
34 #include <linux/rtc.h>
37 #include <ITapiMisc.h>
39 static const char default_rtc0[] = "/dev/rtc0";
40 static const char default_rtc1[] = "/dev/rtc1";
41 static const char default_localtime[] = "/opt/etc/localtime";
43 char *substring(const char *str, size_t begin, size_t len)
45 if (str == 0 || strlen(str) == 0 || strlen(str) < begin
46 || strlen(str) < (begin + len))
49 return strndup(str + begin, len);
52 int handle_timezone(char *str)
56 const char *sympath = default_localtime;
60 const char *tzpath = str;
62 PRT_TRACE("TZPATH = %s\n", tzpath);
64 /* unlink current link
65 * eg. rm /opt/etc/localtime */
66 if (stat(sympath, &sts) == -1 && errno == ENOENT) {
69 ret = unlink(sympath);
71 PRT_TRACE("unlink error : [%d]%s\n", ret,
75 PRT_TRACE("unlink success\n");
80 * eg. ln -s /usr/share/zoneinfo/Asia/Seoul /opt/etc/localtime */
81 ret = symlink(tzpath, sympath);
83 PRT_TRACE("symlink error : [%d]%s\n", ret, strerror(errno));
86 PRT_TRACE("symlink success\n");
93 * TODO : error handling code should be added here.
95 int handle_date(char *str)
104 tmp = (long int)atoi(str);
105 timet = (time_t) tmp;
107 PRT_TRACE("ctime = %s", ctime(&timet));
108 vconf_set_int(VCONFKEY_SYSTEM_TIMECHANGE, timet);
113 int set_datetime_action(int argc, char **argv)
116 unsigned int pm_state;
119 if (vconf_get_int(VCONFKEY_PM_STATE, &ret) != 0)
120 PRT_TRACE("Fail to get vconf value for pm state\n");
128 pm_lock_state(pm_state, STAY_CUR_STATE, 0);
129 ret = handle_date(argv[0]);
130 pm_unlock_state(pm_state, STAY_CUR_STATE);
134 int set_timezone_action(int argc, char **argv)
137 unsigned int pm_state;
140 if (vconf_get_int(VCONFKEY_PM_STATE, &ret) != 0)
141 PRT_TRACE("Fail to get vconf value for pm state\n");
149 pm_lock_state(pm_state, STAY_CUR_STATE, 0);
150 ret = handle_timezone(argv[0]);
151 pm_unlock_state(pm_state, STAY_CUR_STATE);
155 int ss_time_manager_init(void)
157 ss_action_entry_add_internal(PREDEF_SET_DATETIME, set_datetime_action,
159 ss_action_entry_add_internal(PREDEF_SET_TIMEZONE, set_timezone_action,