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_EARJACK;
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 ret = runtime_info_vconf_get_value_bool(VCONF_VIBRATION_ENABLED, &vconf_value);
76 if (ret == RUNTIME_INFO_ERROR_NONE)
77 value->b = (bool)vconf_value;
82 int runtime_info_vibration_enabled_set_event_cb(void)
84 return runtime_info_vconf_set_event_cb(VCONF_VIBRATION_ENABLED, RUNTIME_INFO_KEY_VIBRATION_ENABLED, 0);
87 void runtime_info_vibration_enabled_unset_event_cb(void)
89 runtime_info_vconf_unset_event_cb(VCONF_VIBRATION_ENABLED, 0);
92 int runtime_info_auto_rotation_enabled_get_value(runtime_info_value_h value)
97 ret = runtime_info_vconf_get_value_bool(VCONF_ROTATION_LOCK_ENABLED, &vconf_value);
98 if (ret == RUNTIME_INFO_ERROR_NONE)
99 value->b = (bool)vconf_value;
104 int runtime_info_auto_rotation_enabled_set_event_cb(void)
106 return runtime_info_vconf_set_event_cb(VCONF_ROTATION_LOCK_ENABLED, RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, 0);
109 void runtime_info_auto_rotation_enabled_unset_event_cb(void)
111 runtime_info_vconf_unset_event_cb(VCONF_ROTATION_LOCK_ENABLED, 0);
114 int runtime_info_battery_charging_get_value(runtime_info_value_h value)
119 ret = runtime_info_vconf_get_value_int(VCONF_BATTERY_CHARGING, &vconf_value);
120 if (ret == RUNTIME_INFO_ERROR_NONE)
121 value->b = vconf_value;
126 int runtime_info_battery_charging_set_event_cb(void)
128 return runtime_info_vconf_set_event_cb(VCONF_BATTERY_CHARGING, RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, 0);
131 void runtime_info_battery_charging_unset_event_cb(void)
133 runtime_info_vconf_unset_event_cb(VCONF_BATTERY_CHARGING, 0);
137 int runtime_info_tvout_connected_get_value(runtime_info_value_h value)
142 ret = runtime_info_vconf_get_value_int(VCONF_TVOUT_CONNECTED, &vconf_value);
143 if (ret != RUNTIME_INFO_ERROR_NONE)
146 switch (vconf_value) {
147 case VCONFKEY_SYSMAN_EARJACK_TVOUT:
159 int runtime_info_tvout_connected_set_event_cb(void)
161 return runtime_info_vconf_set_event_cb(VCONF_TVOUT_CONNECTED, RUNTIME_INFO_KEY_TV_OUT_CONNECTED, 1);
164 void runtime_info_tvout_connected_unset_event_cb(void)
166 runtime_info_vconf_unset_event_cb(VCONF_TVOUT_CONNECTED, 1);
170 int runtime_info_audio_jack_status_get_value(runtime_info_value_h value)
175 ret = runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK_STATUS, &vconf_value);
176 if (ret != RUNTIME_INFO_ERROR_NONE)
179 switch (vconf_value) {
180 case VCONFKEY_SYSMAN_EARJACK_3WIRE:
181 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE;
184 case VCONFKEY_SYSMAN_EARJACK_4WIRE:
185 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE;
189 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED;
196 int runtime_info_audio_jack_status_set_event_cb(void)
198 return runtime_info_vconf_set_event_cb(VCONF_AUDIO_JACK_STATUS, RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, 2);
201 void runtime_info_audio_jack_status_unset_event_cb(void)
203 runtime_info_vconf_unset_event_cb(VCONF_AUDIO_JACK_STATUS, 2);
206 int runtime_info_usb_connected_get_value(runtime_info_value_h value)
211 ret = runtime_info_vconf_get_value_int(VCONF_USB_CONNECTED, &vconf_value);
212 if (ret != RUNTIME_INFO_ERROR_NONE)
215 switch (vconf_value) {
216 case VCONFKEY_SYSMAN_USB_DISCONNECTED:
220 case VCONFKEY_SYSMAN_USB_CONNECTED:
224 case VCONFKEY_SYSMAN_USB_AVAILABLE:
229 return RUNTIME_INFO_ERROR_IO_ERROR;
235 int runtime_info_usb_connected_set_event_cb(void)
237 return runtime_info_vconf_set_event_cb(VCONF_USB_CONNECTED, RUNTIME_INFO_KEY_USB_CONNECTED, 0);
240 void runtime_info_usb_connected_unset_event_cb(void)
242 runtime_info_vconf_unset_event_cb(VCONF_USB_CONNECTED, 0);
245 int runtime_info_charger_connected_get_value(runtime_info_value_h value)
250 ret = runtime_info_vconf_get_value_int(VCONF_CHARGER_CONNECTED, &vconf_value);
251 if (ret != RUNTIME_INFO_ERROR_NONE)
254 switch (vconf_value) {
255 case VCONFKEY_SYSMAN_CHARGER_DISCONNECTED:
259 case VCONFKEY_SYSMAN_CHARGER_CONNECTED:
264 return RUNTIME_INFO_ERROR_IO_ERROR;
270 int runtime_info_charger_connected_set_event_cb(void)
272 return runtime_info_vconf_set_event_cb(VCONF_CHARGER_CONNECTED, RUNTIME_INFO_KEY_CHARGER_CONNECTED, 0);
275 void runtime_info_charger_connected_unset_event_cb(void)
277 runtime_info_vconf_unset_event_cb(VCONF_CHARGER_CONNECTED, 0);
280 int runtime_info_get_frequency_cpufreq(int core_idx, char *type, int *cpu_freq)
287 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
289 if (!type || !cpu_freq)
290 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
292 snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_%s_freq",
294 cpufreq_fp = fopen(path, "r");
295 if (cpufreq_fp == NULL) {
297 _I("Fail to get the information about core%d. Get the core0's instead",
299 snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu0/cpufreq/scaling_%s_freq",
301 cpufreq_fp = fopen(path, "r");
304 if (cpufreq_fp == NULL) {
305 _E("IO_ERROR(0x%08x) : failed to open cpufreq file",
306 RUNTIME_INFO_ERROR_IO_ERROR);
307 return RUNTIME_INFO_ERROR_IO_ERROR;
311 if (!fscanf(cpufreq_fp, "%d", &result)) {
312 _E("IO_ERROR(0x%08x) : there is no information in the cpuinfo file",
313 RUNTIME_INFO_ERROR_IO_ERROR);
315 return RUNTIME_INFO_ERROR_IO_ERROR;
318 *cpu_freq = result / 1000;
320 return RUNTIME_INFO_ERROR_NONE;
323 int runtime_info_get_frequency_cpuinfo(int core_idx, int *cpu_freq)
332 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
335 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
337 cpuinfo_fp = fopen("/proc/cpuinfo", "r");
338 if (cpuinfo_fp == NULL) {
339 _E("Fail to open cpuinfo");
340 return RUNTIME_INFO_ERROR_IO_ERROR;
343 while (fgets(line, sizeof(line), cpuinfo_fp) != NULL) {
344 if (strncmp(line, "cpu MHz", 7))
347 if (cur_core == core_idx) {
348 /* String format in the cpuinfo : "cpu MHz : 1234" */
349 start = strchr(line, ':') + 2;
351 while (*start >= '0' && *start <= '9') {
352 acc_freq = (acc_freq * 10) + (*start - '0');
356 *cpu_freq = acc_freq;
358 return RUNTIME_INFO_ERROR_NONE;
364 return RUNTIME_INFO_ERROR_NOT_SUPPORTED;