2 * Network Configuration Module
4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <vconf-keys.h>
26 #include "wifi-state.h"
28 #define NTP_SERVER "pool.ntp.org"
29 #define CONNMAN_GLOBAL_SETTING "/var/lib/connman/settings"
31 static void __netconfig_clock_clear_timeserver(void)
33 GKeyFile *keyfile = NULL;
35 keyfile = netconfig_keyfile_load(CONNMAN_GLOBAL_SETTING);
40 g_key_file_remove_key(keyfile, "global", "Timeservers", NULL);
42 netconfig_keyfile_save(keyfile, CONNMAN_GLOBAL_SETTING);
45 static gboolean __netconfig_clock_clear_timeserver_timer(gpointer data)
47 INFO("Clear NTP server");
49 __netconfig_clock_clear_timeserver();
54 static void __netconfig_clock_set_timeserver(const char *server)
56 DBusMessage* reply = NULL;
57 char param1[] = "string:Timeservers";
59 char *param_array[] = {NULL, NULL, NULL};
61 param2 = g_strdup_printf("variant:array:string:%s", server);
63 param_array[0] = param1;
64 param_array[1] = param2;
66 reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
67 CONNMAN_MANAGER_PATH, CONNMAN_CLOCK_INTERFACE,
68 "SetProperty", param_array);
70 ERR("Failed to configure NTP server");
74 dbus_message_unref(reply);
77 static void __netconfig_clock(
78 enum netconfig_wifi_service_state state, void *user_data)
80 gboolean automatic_time_update = 0;
81 guint timeserver_clear_timer = 0;
83 if (state != NETCONFIG_WIFI_CONNECTED)
87 VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL,
88 &automatic_time_update);
90 if (automatic_time_update == FALSE) {
91 INFO("Automatic time update is not set (%d)", automatic_time_update);
95 __netconfig_clock_set_timeserver((const char *)NTP_SERVER);
97 netconfig_start_timer_seconds(5, __netconfig_clock_clear_timeserver_timer,
98 NULL, ×erver_clear_timer);
101 static struct netconfig_wifi_state_notifier netconfig_clock_notifier = {
102 .netconfig_wifi_state_changed = __netconfig_clock,
106 void netconfig_clock_init(void)
108 netconfig_wifi_state_notifier_register(&netconfig_clock_notifier);
111 void netconfig_clock_deinit(void)
113 netconfig_wifi_state_notifier_unregister(&netconfig_clock_notifier);