2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
24 #include <runtime_info.h>
25 #include <runtime_info_private.h>
27 static const char *VCONF_AUDIO_JACK = VCONFKEY_SYSMAN_EARJACK;
28 static const char *VCONF_VIBRATION_ENABLED = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
29 static const char *VCONF_ROTATION_LOCK_ENABLED = VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL;
30 static const char *VCONF_BATTERY_CHARGING = VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW;
31 static const char *VCONF_TVOUT_CONNECTED = VCONFKEY_SYSMAN_HDMI;
32 static const char *VCONF_AUDIO_JACK_STATUS = VCONFKEY_SYSMAN_EARJACK;
33 static const char *VCONF_USB_CONNECTED = VCONFKEY_SYSMAN_USB_STATUS;
34 static const char *VCONF_CHARGER_CONNECTED = VCONFKEY_SYSMAN_CHARGER_STATUS;
37 int runtime_info_audiojack_get_value(runtime_info_value_h value)
42 ret = runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK, &vconf_value);
43 if (ret != RUNTIME_INFO_ERROR_NONE)
46 switch (vconf_value) {
47 case VCONFKEY_SYSMAN_EARJACK_3WIRE:
48 case VCONFKEY_SYSMAN_EARJACK_4WIRE:
60 int runtime_info_audiojack_set_event_cb(void)
62 return runtime_info_vconf_set_event_cb(VCONF_AUDIO_JACK, RUNTIME_INFO_KEY_AUDIO_JACK_CONNECTED, 0);
65 void runtime_info_audiojack_unset_event_cb(void)
67 runtime_info_vconf_unset_event_cb(VCONF_AUDIO_JACK, 0);
70 int runtime_info_vibration_enabled_get_value(runtime_info_value_h value)
75 RETURN_ERROR_IF_NOT_SUPPORTED("http://tizen.org/feature/feedback.vibration");
77 ret = runtime_info_vconf_get_value_bool(VCONF_VIBRATION_ENABLED, &vconf_value);
78 if (ret == RUNTIME_INFO_ERROR_NONE)
79 value->b = (bool)vconf_value;
84 int runtime_info_vibration_enabled_set_event_cb(void)
86 return runtime_info_vconf_set_event_cb(VCONF_VIBRATION_ENABLED, RUNTIME_INFO_KEY_VIBRATION_ENABLED, 0);
89 void runtime_info_vibration_enabled_unset_event_cb(void)
91 runtime_info_vconf_unset_event_cb(VCONF_VIBRATION_ENABLED, 0);
94 int runtime_info_auto_rotation_enabled_get_value(runtime_info_value_h value)
99 RETURN_ERROR_IF_NOT_SUPPORTED("http://tizen.org/feature/screen.auto_rotation");
101 ret = runtime_info_vconf_get_value_bool(VCONF_ROTATION_LOCK_ENABLED, &vconf_value);
102 if (ret == RUNTIME_INFO_ERROR_NONE)
103 value->b = (bool)vconf_value;
108 int runtime_info_auto_rotation_enabled_set_event_cb(void)
110 return runtime_info_vconf_set_event_cb(VCONF_ROTATION_LOCK_ENABLED, RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, 0);
113 void runtime_info_auto_rotation_enabled_unset_event_cb(void)
115 runtime_info_vconf_unset_event_cb(VCONF_ROTATION_LOCK_ENABLED, 0);
118 int runtime_info_battery_charging_get_value(runtime_info_value_h value)
123 RETURN_ERROR_IF_NOT_SUPPORTED("http://tizen.org/feature/battery");
125 ret = runtime_info_vconf_get_value_int(VCONF_BATTERY_CHARGING, &vconf_value);
126 if (ret == RUNTIME_INFO_ERROR_NONE)
127 value->b = vconf_value;
132 int runtime_info_battery_charging_set_event_cb(void)
134 return runtime_info_vconf_set_event_cb(VCONF_BATTERY_CHARGING, RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, 0);
137 void runtime_info_battery_charging_unset_event_cb(void)
139 runtime_info_vconf_unset_event_cb(VCONF_BATTERY_CHARGING, 0);
143 int runtime_info_tvout_connected_get_value(runtime_info_value_h value)
149 ret = system_info_get_platform_bool("http://tizen.org/feature/screen.output.hdmi", &supported);
150 if (ret != SYSTEM_INFO_ERROR_NONE)
151 return RUNTIME_INFO_ERROR_IO_ERROR;
153 ret = system_info_get_platform_bool("http://tizen.org/feature/screen.output.rca", &supported);
154 if (ret != SYSTEM_INFO_ERROR_NONE)
155 return RUNTIME_INFO_ERROR_IO_ERROR;
157 return RUNTIME_INFO_ERROR_NOT_SUPPORTED;
160 ret = runtime_info_vconf_get_value_int(VCONF_TVOUT_CONNECTED, &vconf_value);
161 if (ret == RUNTIME_INFO_ERROR_NONE)
162 value->b = vconf_value;
167 int runtime_info_tvout_connected_set_event_cb(void)
169 return runtime_info_vconf_set_event_cb(VCONF_TVOUT_CONNECTED, RUNTIME_INFO_KEY_TV_OUT_CONNECTED, 0);
172 void runtime_info_tvout_connected_unset_event_cb(void)
174 runtime_info_vconf_unset_event_cb(VCONF_TVOUT_CONNECTED, 0);
178 int runtime_info_audio_jack_status_get_value(runtime_info_value_h value)
183 ret = runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK_STATUS, &vconf_value);
184 if (ret != RUNTIME_INFO_ERROR_NONE)
187 switch (vconf_value) {
188 case VCONFKEY_SYSMAN_EARJACK_3WIRE:
189 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE;
192 case VCONFKEY_SYSMAN_EARJACK_4WIRE:
193 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE;
197 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED;
204 int runtime_info_audio_jack_status_set_event_cb(void)
206 return runtime_info_vconf_set_event_cb(VCONF_AUDIO_JACK_STATUS, RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, 2);
209 void runtime_info_audio_jack_status_unset_event_cb(void)
211 runtime_info_vconf_unset_event_cb(VCONF_AUDIO_JACK_STATUS, 2);
214 int runtime_info_usb_connected_get_value(runtime_info_value_h value)
219 ret = runtime_info_vconf_get_value_int(VCONF_USB_CONNECTED, &vconf_value);
220 if (ret != RUNTIME_INFO_ERROR_NONE)
223 switch (vconf_value) {
224 case VCONFKEY_SYSMAN_USB_DISCONNECTED:
228 case VCONFKEY_SYSMAN_USB_CONNECTED:
232 case VCONFKEY_SYSMAN_USB_AVAILABLE:
237 return RUNTIME_INFO_ERROR_IO_ERROR;
243 int runtime_info_usb_connected_set_event_cb(void)
245 return runtime_info_vconf_set_event_cb(VCONF_USB_CONNECTED, RUNTIME_INFO_KEY_USB_CONNECTED, 0);
248 void runtime_info_usb_connected_unset_event_cb(void)
250 runtime_info_vconf_unset_event_cb(VCONF_USB_CONNECTED, 0);
253 int runtime_info_charger_connected_get_value(runtime_info_value_h value)
258 RETURN_ERROR_IF_NOT_SUPPORTED("http://tizen.org/feature/battery");
260 ret = runtime_info_vconf_get_value_int(VCONF_CHARGER_CONNECTED, &vconf_value);
261 if (ret != RUNTIME_INFO_ERROR_NONE)
264 switch (vconf_value) {
265 case VCONFKEY_SYSMAN_CHARGER_DISCONNECTED:
269 case VCONFKEY_SYSMAN_CHARGER_CONNECTED:
274 return RUNTIME_INFO_ERROR_IO_ERROR;
280 int runtime_info_charger_connected_set_event_cb(void)
282 return runtime_info_vconf_set_event_cb(VCONF_CHARGER_CONNECTED, RUNTIME_INFO_KEY_CHARGER_CONNECTED, 0);
285 void runtime_info_charger_connected_unset_event_cb(void)
287 runtime_info_vconf_unset_event_cb(VCONF_CHARGER_CONNECTED, 0);
290 int runtime_info_get_frequency_cpufreq(int core_idx, char *type, int *cpu_freq)
297 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
299 if (!type || !cpu_freq)
300 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
302 snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_%s_freq",
304 cpufreq_fp = fopen(path, "r");
306 //LCOV_EXCL_START : fallback routine
307 if (cpufreq_fp == NULL) {
309 _I("Fail to get the information about core%d. Get the core0's instead",
311 snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu0/cpufreq/scaling_%s_freq",
313 cpufreq_fp = fopen(path, "r");
316 if (cpufreq_fp == NULL) {
317 _E("IO_ERROR(0x%08x) : failed to open cpufreq file",
318 RUNTIME_INFO_ERROR_IO_ERROR);
319 return RUNTIME_INFO_ERROR_IO_ERROR;
324 if (!fscanf(cpufreq_fp, "%d", &result)) {
325 //LCOV_EXCL_START : system error
326 _E("IO_ERROR(0x%08x) : there is no information in the cpuinfo file",
327 RUNTIME_INFO_ERROR_IO_ERROR);
329 return RUNTIME_INFO_ERROR_IO_ERROR;
333 *cpu_freq = result / 1000;
335 return RUNTIME_INFO_ERROR_NONE;
338 //LCOV_EXCL_START : fallback routine
339 int runtime_info_get_frequency_cpuinfo(int core_idx, int *cpu_freq)
348 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
351 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
353 cpuinfo_fp = fopen("/proc/cpuinfo", "r");
354 if (cpuinfo_fp == NULL) {
355 _E("Fail to open cpuinfo");
356 return RUNTIME_INFO_ERROR_IO_ERROR;
359 while (fgets(line, sizeof(line), cpuinfo_fp) != NULL) {
360 if (strncmp(line, "cpu MHz", 7))
363 if (cur_core == core_idx) {
364 /* String format in the cpuinfo : "cpu MHz : 1234" */
365 start = strchr(line, ':') + 2;
367 while (*start >= '0' && *start <= '9') {
368 acc_freq = (acc_freq * 10) + (*start - '0');
372 *cpu_freq = acc_freq;
374 return RUNTIME_INFO_ERROR_NONE;
380 return RUNTIME_INFO_ERROR_NO_DATA;