2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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>
33 #include <livebox-service.h>
35 #include "client_life.h"
39 #include "slave_life.h"
40 #include "critical_log.h"
48 static void lcd_state_cb(keynode_t *node, void *user_data)
54 xmonitor_handle_state_changes();
57 HAPI int setting_is_lcd_off(void)
61 if (vconf_get_int(VCONFKEY_PM_STATE, &state) != 0) {
62 ErrPrint("Idle lock state is not valid\n");
63 state = VCONFKEY_PM_STATE_NORMAL; /* UNLOCK */
66 DbgPrint("State: %d, (%d:lcdoff, %d:sleep)\n", state, VCONFKEY_PM_STATE_LCDOFF, VCONFKEY_PM_STATE_SLEEP);
67 return state == VCONFKEY_PM_STATE_LCDOFF || state == VCONFKEY_PM_STATE_SLEEP;
70 static void power_off_cb(keynode_t *node, void *user_data)
73 CRITICAL_LOG("Terminated(vconf)\n");
75 if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) {
76 ErrPrint("Failed to get power off status (%d)\n", val);
80 if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
83 fd = creat("/tmp/.stop.provider", 0644);
84 if (fd < 0 || close(fd) < 0) {
85 ErrPrint("stop.provider [%s]\n", strerror(errno));
88 vconf_set_bool(VCONFKEY_MASTER_STARTED, 0);
90 ecore_main_loop_quit();
92 ErrPrint("Unknown power state: %d\n", val);
96 static void region_changed_cb(keynode_t *node, void *user_data)
101 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
106 setenv("LC_CTYPE", region, 1);
107 setenv("LC_NUMERIC", region, 1);
108 setenv("LC_TIME", region, 1);
109 setenv("LC_COLLATE", region, 1);
110 setenv("LC_MONETARY", region, 1);
111 setenv("LC_PAPER", region, 1);
112 setenv("LC_NAME", region, 1);
113 setenv("LC_ADDRESS", region, 1);
114 setenv("LC_TELEPHONE", region, 1);
115 setenv("LC_MEASUREMENT", region, 1);
116 setenv("LC_IDENTIFICATION", region, 1);
118 r = setlocale(LC_ALL, "");
120 ErrPrint("Failed to change region\n");
126 static void lang_changed_cb(keynode_t *node, void *user_data)
131 lang = vconf_get_str(VCONFKEY_LANGSET);
136 setenv("LANG", lang, 1);
137 setenv("LC_MESSAGES", lang, 1);
139 r = setlocale(LC_ALL, "");
141 ErrPrint("Failed to change locale\n");
144 DbgPrint("Locale: %s\n", setlocale(LC_ALL, NULL));
148 static void ail_info_cb(keynode_t *node, void *user_data)
150 Eina_List *inst_list;
152 struct inst_info *inst;
156 struct pkg_info *info;
163 event = vconf_get_str(VCONFKEY_AIL_INFO_STATE);
168 len = strlen("update:");
169 if (!strncasecmp(event, "update:", len)) {
174 DbgPrint("AppId: [%s]\n", appid);
176 enabled = package_is_enabled(appid);
178 DbgPrint("AppId: %s, %d\n", appid, enabled);
189 pkg_list = (Eina_List *)package_list();
190 EINA_LIST_FOREACH(pkg_list, l, info) {
192 pkgname = livebox_service_mainappid(package_name(info));
197 if (strcmp(appid, pkgname)) {
201 DbgPrint("Package disabled: %s (%s)\n", pkgname, appid);
204 inst_list = package_instance_list(info);
205 EINA_LIST_FOREACH_SAFE(inst_list, j, n, inst) {
206 instance_destroy(inst, INSTANCE_DESTROY_DEFAULT);
214 HAPI int setting_init(void)
218 ret = vconf_notify_key_changed(VCONFKEY_PM_STATE, lcd_state_cb, NULL);
220 ErrPrint("Failed to add vconf for lock state: %d\n", ret);
223 ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb, NULL);
225 ErrPrint("Failed to add vconf for power state: %d \n", ret);
228 ret = vconf_notify_key_changed(VCONFKEY_LANGSET, lang_changed_cb, NULL);
230 ErrPrint("Failed to add vconf for lang change: %d\n", ret);
233 ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb, NULL);
235 ErrPrint("Failed to add vconf for region change: %d\n", ret);
238 ret = vconf_notify_key_changed(VCONFKEY_AIL_INFO_STATE, ail_info_cb, NULL);
240 ErrPrint("Failed to add vconf for ail info state: %d\n", ret);
243 lang_changed_cb(NULL, NULL);
244 region_changed_cb(NULL, NULL);
248 HAPI int setting_fini(void)
252 ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb);
254 ErrPrint("Failed to ignore vconf key (%d)\n", ret);
257 ret = vconf_ignore_key_changed(VCONFKEY_LANGSET, lang_changed_cb);
259 ErrPrint("Failed to ignore vconf key (%d)\n", ret);
262 ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE, lcd_state_cb);
264 ErrPrint("Failed to ignore vconf key (%d)\n", ret);
267 ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb);
269 ErrPrint("Failed to ignore vconf key (%d)\n", ret);
272 ret = vconf_ignore_key_changed(VCONFKEY_AIL_INFO_STATE, ail_info_cb);
274 ErrPrint("Failed to ignore vconf key (%d)\n", ret);