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 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)
144 value->b = vconf_value;
149 int runtime_info_tvout_connected_set_event_cb(void)
151 return runtime_info_vconf_set_event_cb(VCONF_TVOUT_CONNECTED, RUNTIME_INFO_KEY_TV_OUT_CONNECTED, 0);
154 void runtime_info_tvout_connected_unset_event_cb(void)
156 runtime_info_vconf_unset_event_cb(VCONF_TVOUT_CONNECTED, 0);
160 int runtime_info_audio_jack_status_get_value(runtime_info_value_h value)
165 ret = runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK_STATUS, &vconf_value);
166 if (ret != RUNTIME_INFO_ERROR_NONE)
169 switch (vconf_value) {
170 case VCONFKEY_SYSMAN_EARJACK_3WIRE:
171 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE;
174 case VCONFKEY_SYSMAN_EARJACK_4WIRE:
175 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE;
179 value->i = RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED;
186 int runtime_info_audio_jack_status_set_event_cb(void)
188 return runtime_info_vconf_set_event_cb(VCONF_AUDIO_JACK_STATUS, RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, 2);
191 void runtime_info_audio_jack_status_unset_event_cb(void)
193 runtime_info_vconf_unset_event_cb(VCONF_AUDIO_JACK_STATUS, 2);
196 int runtime_info_usb_connected_get_value(runtime_info_value_h value)
201 ret = runtime_info_vconf_get_value_int(VCONF_USB_CONNECTED, &vconf_value);
202 if (ret != RUNTIME_INFO_ERROR_NONE)
205 switch (vconf_value) {
206 case VCONFKEY_SYSMAN_USB_DISCONNECTED:
210 case VCONFKEY_SYSMAN_USB_CONNECTED:
214 case VCONFKEY_SYSMAN_USB_AVAILABLE:
219 return RUNTIME_INFO_ERROR_IO_ERROR;
225 int runtime_info_usb_connected_set_event_cb(void)
227 return runtime_info_vconf_set_event_cb(VCONF_USB_CONNECTED, RUNTIME_INFO_KEY_USB_CONNECTED, 0);
230 void runtime_info_usb_connected_unset_event_cb(void)
232 runtime_info_vconf_unset_event_cb(VCONF_USB_CONNECTED, 0);
235 int runtime_info_charger_connected_get_value(runtime_info_value_h value)
240 ret = runtime_info_vconf_get_value_int(VCONF_CHARGER_CONNECTED, &vconf_value);
241 if (ret != RUNTIME_INFO_ERROR_NONE)
244 switch (vconf_value) {
245 case VCONFKEY_SYSMAN_CHARGER_DISCONNECTED:
249 case VCONFKEY_SYSMAN_CHARGER_CONNECTED:
254 return RUNTIME_INFO_ERROR_IO_ERROR;
260 int runtime_info_charger_connected_set_event_cb(void)
262 return runtime_info_vconf_set_event_cb(VCONF_CHARGER_CONNECTED, RUNTIME_INFO_KEY_CHARGER_CONNECTED, 0);
265 void runtime_info_charger_connected_unset_event_cb(void)
267 runtime_info_vconf_unset_event_cb(VCONF_CHARGER_CONNECTED, 0);
270 int runtime_info_get_frequency_cpufreq(int core_idx, char *type, int *cpu_freq)
277 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
279 if (!type || !cpu_freq)
280 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
282 snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_%s_freq",
284 cpufreq_fp = fopen(path, "r");
286 //LCOV_EXCL_START : fallback routine
287 if (cpufreq_fp == NULL) {
289 _I("Fail to get the information about core%d. Get the core0's instead",
291 snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu0/cpufreq/scaling_%s_freq",
293 cpufreq_fp = fopen(path, "r");
296 if (cpufreq_fp == NULL) {
297 _E("IO_ERROR(0x%08x) : failed to open cpufreq file",
298 RUNTIME_INFO_ERROR_IO_ERROR);
299 return RUNTIME_INFO_ERROR_IO_ERROR;
304 if (!fscanf(cpufreq_fp, "%d", &result)) {
305 //LCOV_EXCL_START : system error
306 _E("IO_ERROR(0x%08x) : there is no information in the cpuinfo file",
307 RUNTIME_INFO_ERROR_IO_ERROR);
309 return RUNTIME_INFO_ERROR_IO_ERROR;
313 *cpu_freq = result / 1000;
315 return RUNTIME_INFO_ERROR_NONE;
318 //LCOV_EXCL_START : fallback routine
319 int runtime_info_get_frequency_cpuinfo(int core_idx, int *cpu_freq)
328 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
331 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
333 cpuinfo_fp = fopen("/proc/cpuinfo", "r");
334 if (cpuinfo_fp == NULL) {
335 _E("Fail to open cpuinfo");
336 return RUNTIME_INFO_ERROR_IO_ERROR;
339 while (fgets(line, sizeof(line), cpuinfo_fp) != NULL) {
340 if (strncmp(line, "cpu MHz", 7))
343 if (cur_core == core_idx) {
344 /* String format in the cpuinfo : "cpu MHz : 1234" */
345 start = strchr(line, ':') + 2;
347 while (*start >= '0' && *start <= '9') {
348 acc_freq = (acc_freq * 10) + (*start - '0');
352 *cpu_freq = acc_freq;
354 return RUNTIME_INFO_ERROR_NONE;
360 return RUNTIME_INFO_ERROR_NO_DATA;