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>
38 static const char default_rtc0[] = "/dev/rtc0";
39 static const char default_rtc1[] = "/dev/rtc1";
40 static const char default_localtime[] = "/opt/etc/localtime";
42 char *substring(const char *str, size_t begin, size_t len)
44 if (str == 0 || strlen(str) == 0 || strlen(str) < begin
45 || strlen(str) < (begin + len))
48 return strndup(str + begin, len);
51 int handle_timezone(char *str)
55 const char *sympath = default_localtime;
59 const char *tzpath = str;
61 PRT_TRACE("TZPATH = %s\n", tzpath);
63 /* unlink current link
64 * eg. rm /opt/etc/localtime */
65 if (stat(sympath, &sts) == -1 && errno == ENOENT) {
68 ret = unlink(sympath);
70 PRT_TRACE("unlink error : [%d]%s\n", ret,
74 PRT_TRACE("unlink success\n");
79 * eg. ln -s /usr/share/zoneinfo/Asia/Seoul /opt/etc/localtime */
80 ret = symlink(tzpath, sympath);
82 PRT_TRACE("symlink error : [%d]%s\n", ret, strerror(errno));
85 PRT_TRACE("symlink success\n");
92 * TODO : error handling code should be added here.
94 int handle_date(char *str)
103 tmp = (long int)atoi(str);
104 timet = (time_t) tmp;
106 PRT_TRACE("ctime = %s", ctime(&timet));
107 vconf_set_int(VCONFKEY_SYSTEM_TIMECHANGE, timet);
112 int set_datetime_action(int argc, char **argv)
115 unsigned int pm_state;
118 if (vconf_get_int(VCONFKEY_PM_STATE, &ret) != 0)
119 PRT_TRACE("Fail to get vconf value for pm state\n");
127 pm_lock_state(pm_state, STAY_CUR_STATE, 0);
128 ret = handle_date(argv[0]);
129 pm_unlock_state(pm_state, STAY_CUR_STATE);
133 int set_timezone_action(int argc, char **argv)
136 unsigned int pm_state;
139 if (vconf_get_int(VCONFKEY_PM_STATE, &ret) != 0)
140 PRT_TRACE("Fail to get vconf value for pm state\n");
148 pm_lock_state(pm_state, STAY_CUR_STATE, 0);
149 ret = handle_timezone(argv[0]);
150 pm_unlock_state(pm_state, STAY_CUR_STATE);
154 int ss_time_manager_init(void)
156 ss_action_entry_add_internal(PREDEF_SET_DATETIME, set_datetime_action,
158 ss_action_entry_add_internal(PREDEF_SET_TIMEZONE, set_timezone_action,