2 * Copyright (c) 2011 - 2015 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.
17 #ifndef __TIZEN_SYSTEM_RUNTIME_INFO_H__
18 #define __TIZEN_SYSTEM_RUNTIME_INFO_H__
29 * @addtogroup CAPI_SYSTEM_RUNTIME_INFO_MODULE
35 * @brief Enumeration for error codes for runtime information.
39 RUNTIME_INFO_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
40 RUNTIME_INFO_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
41 RUNTIME_INFO_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
42 RUNTIME_INFO_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< An input/output error occurred when read value from system */
43 RUNTIME_INFO_ERROR_REMOTE_IO = TIZEN_ERROR_REMOTE_IO, /**< Remote I/O error occurred */
44 RUNTIME_INFO_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< No permission to use the api */
45 RUNTIME_INFO_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported parameter */
46 RUNTIME_INFO_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA /**< No data available (Since 3.0) */
47 } runtime_info_error_e;
51 * @brief Enumeration for keys for runtime information.
53 * @remarks ~10000 : public key \n
54 * 10001~ : product specific key
57 RUNTIME_INFO_KEY_BLUETOOTH_ENABLED = 2, /**<Indicates whether Bluetooth is enabled. */
58 RUNTIME_INFO_KEY_WIFI_HOTSPOT_ENABLED = 3, /**<Indicates whether Wi-Fi hotspot is enabled. */
59 RUNTIME_INFO_KEY_BLUETOOTH_TETHERING_ENABLED = 4, /**<Indicates whether Bluetooth tethering is enabled. */
60 RUNTIME_INFO_KEY_USB_TETHERING_ENABLED = 5, /**<Indicates whether USB tethering is enabled. */
61 RUNTIME_INFO_KEY_PACKET_DATA_ENABLED = 9, /**<Indicates Whether the packet data through 3G network is enabled. */
62 RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED = 10, /**<Indicates whether data roaming is enabled. */
63 RUNTIME_INFO_KEY_VIBRATION_ENABLED = 12, /**<Indicates whether vibration is enabled. */
64 RUNTIME_INFO_KEY_AUDIO_JACK_CONNECTED = 17, /**<Indicates whether audio jack is connected. */
65 RUNTIME_INFO_KEY_GPS_STATUS = 18, /**<Indicates the current status of GPS. */
66 RUNTIME_INFO_KEY_BATTERY_IS_CHARGING = 19, /**<Indicates the battery is currently charging. */
67 RUNTIME_INFO_KEY_TV_OUT_CONNECTED = 20, /**<Indicates whether TV out is connected. */
68 RUNTIME_INFO_KEY_AUDIO_JACK_STATUS = 21, /**<Indicates the current status of audio jack. */
69 RUNTIME_INFO_KEY_USB_CONNECTED = 23, /**<Indicates whether USB is connected. */
70 RUNTIME_INFO_KEY_CHARGER_CONNECTED = 24, /**<Indicates whether charger is connected. */
71 RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED = 26, /**<Indicates whether auto rotation is enabled. */
76 * @brief Enumeration for Wi-Fi status.
80 RUNTIME_INFO_WIFI_STATUS_DISABLED, /**< Wi-Fi is disabled. */
81 RUNTIME_INFO_WIFI_STATUS_UNCONNECTED, /**< Wi-Fi is enabled and network connection is not established. */
82 RUNTIME_INFO_WIFI_STATUS_CONNECTED, /**< Network connection is established in Wi-Fi network. */
83 } runtime_info_wifi_status_e;
87 * @brief Enumeration for GPS status.
91 RUNTIME_INFO_GPS_STATUS_DISABLED, /**< GPS is disabled. */
92 RUNTIME_INFO_GPS_STATUS_SEARCHING, /**< GPS is searching for satellites. */
93 RUNTIME_INFO_GPS_STATUS_CONNECTED, /**< GPS connection is established. */
94 } runtime_info_gps_status_e;
97 * @brief Enumeration for audio jack status.
101 RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED, /**< Audio jack is not connected */
102 RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE, /**< 3-conductor wire is connected. */
103 RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE, /**< 4-conductor wire is connected. */
104 } runtime_info_audio_jack_status_e;
108 * @brief Called when the runtime information changes.
111 * @param[in] key The type of notification
112 * @param[in] user_data The user data passed from the callback registration function
114 * @pre runtime_info_set_changed_cb() will invoke this callback function.
115 * @see runtime_info_set_changed_cb()
116 * @see runtime_info_unset_changed_cb()
118 typedef void (*runtime_info_changed_cb)(runtime_info_key_e key, void *user_data);
122 * @brief Gets the integer value of the runtime information.
123 * @details This function gets current state of the given key which represents specific runtime information.
126 * @param[in] key The runtime information status key from which data should be read
127 * @param[out] value The current value of the given key
129 * @return @c 0 on success,
130 * otherwise a negative error value
131 * @retval #RUNTIME_INFO_ERROR_NONE Successful
132 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
133 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system
134 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED No permission to use the api
135 * @retval #RUNTIME_INFO_ERROR_NOT_SUPPORTED Not supported parameter
137 int runtime_info_get_value_int(runtime_info_key_e key, int *value);
141 * @brief Gets the boolean value from the runtime information.
142 * @details This function gets current state of the given key which represents specific runtime information.
145 * @param[in] key The runtime information key from which data should be read
146 * @param[out] value The current value of the given key
148 * @return @c 0 on success,
149 * otherwise a negative error value
150 * @retval #RUNTIME_INFO_ERROR_NONE Successful
151 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
152 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system
153 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED No permission to use the api
154 * @retval #RUNTIME_INFO_ERROR_NOT_SUPPORTED Not supported parameter
156 int runtime_info_get_value_bool(runtime_info_key_e key, bool *value);
160 * @brief Gets the double value from the runtime information.
161 * @details This function gets current state of the given key which represents specific runtime information.
164 * @param[in] key The runtime information key from which data should be read
165 * @param[out] value The current value of the given key
167 * @return @c 0 on success,
168 * otherwise a negative error value
169 * @retval #RUNTIME_INFO_ERROR_NONE Successful
170 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
171 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system
172 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED No permission to use the api
173 * @retval #RUNTIME_INFO_ERROR_NOT_SUPPORTED Not supported parameter
175 int runtime_info_get_value_double(runtime_info_key_e key, double *value);
179 * @brief Gets the string value for specified runtime information.
180 * @details This function gets current state of the given key which represents specific runtime information.
183 * @remarks You must release @a value using free().
185 * @param[in] key The runtime information key from which data should be read
186 * @param[out] value The current value of the given key
188 * @return @c 0 on success,
189 * otherwise a negative error value
190 * @retval #RUNTIME_INFO_ERROR_NONE Successful
191 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
192 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system
193 * @retval #RUNTIME_INFO_ERROR_OUT_OF_MEMORY Out of memory
194 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED No permission to use the api
195 * @retval #RUNTIME_INFO_ERROR_NOT_SUPPORTED Not supported parameter
197 int runtime_info_get_value_string(runtime_info_key_e key, char **value);
201 * @brief Registers a change event callback for given runtime information key.
204 * @param[in] key The runtime information type
205 * @param[in] callback The callback function to invoke
206 * @param[in] user_data The user data to be passed to the callback function
208 * @return @c 0 on success,
209 * otherwise a negative error value
210 * @retval #RUNTIME_INFO_ERROR_NONE Successful
211 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
212 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED No permission to use the api
213 * @retval #RUNTIME_INFO_ERROR_NOT_SUPPORTED Not supported parameter
215 * @post runtime_info_changed_cb() will be invoked.
216 * @see runtime_info_unset_changed_cb()
217 * @see runtime_info_changed_cb()
219 int runtime_info_set_changed_cb(runtime_info_key_e key, runtime_info_changed_cb callback, void *user_data);
223 * @brief Unregisters the callback function.
226 * @param[in] key The runtime information type
228 * @return @c 0 on success,
229 * otherwise a negative error value
230 * @retval #RUNTIME_INFO_ERROR_NONE Successful
231 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
233 * @see runtime_info_set_changed_cb()
235 int runtime_info_unset_changed_cb(runtime_info_key_e key);
239 * @brief Structure for memory information.
243 int total; /**< Total memory (KiB) */
244 int used; /**< Used memory (KiB) */
245 int free; /**< Free memory (KiB) */
246 int cache; /**< Cache memory (KiB) */
247 int swap; /**< Swap memory (KiB) */
248 } runtime_memory_info_s;
252 * @brief Gets system memory information.
255 * @param[out] info The system memory information structure
257 * @return @c 0 on success,
258 * otherwise a negative error value
259 * @retval #RUNTIME_INFO_ERROR_NONE Successful
260 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
261 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An Input/Output error occurred while reading from system
263 * @see runtime_info_get_process_memory_info()
265 int runtime_info_get_system_memory_info(runtime_memory_info_s *info);
269 * @brief Structure for memory information per process.
273 int vsz; /**< Virtual memory size (KiB) */
274 int rss; /**< Resident set size (KiB) */
275 int pss; /**< Proportional set size (KiB) */
276 int shared_clean; /**< Not modified and mapped by other processes (KiB) */
277 int shared_dirty; /**< Modified and mapped by other processes (KiB) */
278 int private_clean; /**< Not modified and available only to that process (KiB) */
279 int private_dirty; /**< Modified and available only to that process (KiB) */
280 } process_memory_info_s;
284 * @brief Gets memory information per process.
288 * @privilege %http://tizen.org/privilege/systemmonitor
289 * @remarks You must release @a s value using free(). \n
290 * The size of @a s is the same with @a size.
292 * @param[in] pid The process unique id array
293 * @param[in] size The size of pid array
294 * @param[out] info The memory information structure array of the processes
296 * @return @c 0 on success,
297 * otherwise a negative error value
298 * @retval #RUNTIME_INFO_ERROR_NONE Successful
299 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
300 * @retval #RUNTIME_INFO_ERROR_OUT_OF_MEMORY Not able to allocate memory (for output param/other operations)
301 * @retval #RUNTIME_INFO_ERROR_REMOTE_IO Call to resource daemon failed (dbus errors/resource daemon errors)
302 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An I/O error during dbus message operations
303 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED Process not authorized to request process usage info
305 * @see runtime_info_get_system_memory_info()
307 int runtime_info_get_process_memory_info(int *pid, int size, process_memory_info_s **info);
311 * @brief Structure for CPU usage.
315 double user; /**< Time running un-niced user processes (Percent) */
316 double system; /**< Time running kernel processes (Percent) */
317 double nice; /**< Time running niced user processes (Percent) */
318 double iowait; /**< Time waiting for I/O completion (Percent) */
319 } runtime_cpu_usage_s;
323 * @brief Gets CPU information.
326 * @param[out] usage The CPU usage structure
328 * @return @c 0 on success,
329 * otherwise a negative error value
330 * @retval #RUNTIME_INFO_ERROR_NONE Successful
331 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
332 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An input/output error occurred while reading from system
334 * @see runtime_info_get_process_cpu_usage()
336 int runtime_info_get_cpu_usage(runtime_cpu_usage_s *usage);
340 * @brief Structure for CPU usage per process.
344 int utime; /**< Amount of time that this process has been scheduled in user mode (clock ticks) */
345 int stime; /**< Amount of time that this process has been scheduled in kernel mode (clock ticks) */
346 } process_cpu_usage_s;
350 * @brief Gets CPU usage per process.
354 * @privilege %http://tizen.org/privilege/systemmonitor
355 * @remarks You must release @a s value using free(). \n
356 * The size of @a s is the same with @a size.
358 * @param[in] pid The process unique id array
359 * @param[in] size The size of pid array
360 * @param[out] usage The CPU usage structure array of the processes
362 * @return @c 0 on success,
363 * otherwise a negative error value
364 * @retval #RUNTIME_INFO_ERROR_NONE Successful
365 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
366 * @retval #RUNTIME_INFO_ERROR_OUT_OF_MEMORY Not able to allocate memory (for output param/other operations)
367 * @retval #RUNTIME_INFO_ERROR_REMOTE_IO Call to resource daemon failed (dbus errors/resource daemon errors)
368 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An I/O error occurred (during dbus message operations/other IO operations)
369 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED Process not authorized to request process usage info
371 * @see runtime_info_get_cpu_usage()
373 int runtime_info_get_process_cpu_usage(int *pid, int size, process_cpu_usage_s **usage);
377 * @brief Gets the number of processors.
380 * @param[out] num_core The number of whole processors
382 * @return @c 0 on success,
383 * otherwise a negative error value
384 * @retval #RUNTIME_INFO_ERROR_NONE Successful
385 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
386 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An I/O error occurred (during file open operation)
388 int runtime_info_get_processor_count(int *num_core);
392 * @brief Gets the current frequency of processor.
395 * @param[in] core_idx The index (from 0) of CPU core that you want to know the frequency
396 * @param[out] cpu_freq The current frequency(MHz) of processor
398 * @return @c 0 on success,
399 * otherwise a negative error value
400 * @retval #RUNTIME_INFO_ERROR_NONE Successful
401 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
402 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An I/O error occurred (during file open operation)
403 * @retval #RUNTIME_INFO_ERROR_NO_DATA No data available (Since 3.0)
405 int runtime_info_get_processor_current_frequency(int core_idx, int *cpu_freq);
409 * @brief Gets the max frequency of processor.
412 * @param[in] core_idx The index (from 0) of CPU core that you want to know the frequency
413 * @param[out] cpu_freq The max frequency(MHz) of processor
415 * @return @c 0 on success,
416 * otherwise a negative error value
417 * @retval #RUNTIME_INFO_ERROR_NONE Successful
418 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
419 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An I/O error occurred (during file open operation)
420 * @retval #RUNTIME_INFO_ERROR_NO_DATA No data available (Since 3.0)
422 int runtime_info_get_processor_max_frequency(int core_idx, int *cpu_freq);
426 * @brief Gets the physical memory size.
429 * @param[out] size Physical memory size (KiB)
431 * @return @c 0 on success,
432 * otherwise a negative error value
433 * @retval #RUNTIME_INFO_ERROR_NONE Successful
434 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
435 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An I/O error occurred (during file open operation)
437 int runtime_info_get_physical_memory_size(int *size);
441 * @brief Handle for app usage information.
444 typedef struct app_usages_s *app_usage_h;
448 * @brief Frees an app usage handle.
451 * @param[in] handle App usage handle to free
453 * @return @c 0 on success,
454 * otherwise a negative error value
455 * @retval #RUNTIME_INFO_ERROR_NONE Successful
456 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
458 int runtime_info_app_usage_destroy(app_usage_h handle);
462 * @brief Gets the app count from an app usage handle.
465 * @param[in] handle The app usage handle
466 * @param[out] count The number of apps on the app list
468 * @return @c 0 on success,
469 * otherwise a negative error value
470 * @retval #RUNTIME_INFO_ERROR_NONE Successful
471 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
473 * @see runtime_info_get_all_apps_memory_usage()
474 * @see runtime_info_get_all_apps_cpu_rate()
476 int runtime_info_app_usage_get_count(app_usage_h handle, int *count);
480 * @brief Gets the app ID from an app usage handle.
483 * @remarks You must release @a appid using free().
485 * @param[in] handle The app usage handle
486 * @param[in] index The index in the app list; should be between 0 and @a count - 1 (inclusive), \n
487 * where @a count is provided by runtime_info_app_usage_get_count()
488 * @param[out] appid The app ID
490 * @return @c 0 on success,
491 * otherwise a negative error value
492 * @retval #RUNTIME_INFO_ERROR_NONE Successful
493 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
495 * @see runtime_info_get_all_apps_memory_usage()
496 * @see runtime_info_get_all_apps_cpu_rate()
498 int runtime_info_app_usage_get_appid(app_usage_h handle, int index, char **appid);
502 * @brief Gets resource usage from an app usage handle.
505 * @remarks The meaning of @a usage depends on which function was used to create @a handle.
507 * @param[in] handle The app usage handle
508 * @param[in] index The index in the app list; should be between 0 and @a count - 1 (inclusive), \n
509 * where @a count is provided by runtime_info_app_usage_get_count()
510 * @param[out] usage Resource usage
512 * @return @c 0 on success,
513 * otherwise a negative error value
514 * @retval #RUNTIME_INFO_ERROR_NONE Successful
515 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
517 * @see runtime_info_get_all_apps_memory_usage()
518 * @see runtime_info_get_all_apps_cpu_rate()
520 int runtime_info_app_usage_get_usage(app_usage_h handle, int index, unsigned int *usage);
524 * @brief Gets memory usage of all apps.
528 * @privilege %http://tizen.org/privilege/systemmonitor
529 * @remarks You must release @a usage using runtime_info_app_usage_destroy().
531 * @param[out] usage An array of each app's memory usage (KB)
533 * @return @c 0 on success,
534 * otherwise a negative error value
535 * @retval #RUNTIME_INFO_ERROR_NONE Successful
536 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
537 * @retval #RUNTIME_INFO_ERROR_OUT_OF_MEMORY Not able to allocate memory (for output param/other operations)
538 * @retval #RUNTIME_INFO_ERROR_REMOTE_IO Call to resource daemon failed (dbus errors/resource daemon errors)
539 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An I/O error during dbus message operations
540 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED Process not authorized to request app usage info
541 * @retval #RUNTIME_INFO_ERROR_NO_DATA No app running
544 * #include <runtime_info.h>
546 * void print_memory_usage(void)
550 * app_usage_h mem_usage_handle;
552 * unsigned int usage;
554 * runtime_info_get_all_apps_memory_usage(&mem_usage_handle);
555 * runtime_info_app_usage_get_count(mem_usage_handle, &count);
557 * for (i = 0; i < count; i++) {
558 * runtime_info_app_usage_get_appid(mem_usage_handle, i, &appid);
559 * runtime_info_app_usage_get_usage(mem_usage_handle, i, &usage);
560 * printf("appid = %s, usage = %u KB\n", appid, usage);
564 * runtime_info_app_usage_destroy(mem_usage_handle);
569 int runtime_info_get_all_apps_memory_usage(app_usage_h *usage);
573 * @brief Gets CPU rate of all apps.
577 * @privilege %http://tizen.org/privilege/systemmonitor
578 * @remarks You must release @a rate using runtime_info_app_usage_destroy().
580 * @param[out] rate An array of each app's CPU usage rate (%), the values are rounded down.
582 * @return @c 0 on success,
583 * otherwise a negative error value
584 * @retval #RUNTIME_INFO_ERROR_NONE Successful
585 * @retval #RUNTIME_INFO_ERROR_INVALID_PARAMETER Invalid parameter
586 * @retval #RUNTIME_INFO_ERROR_OUT_OF_MEMORY Not able to allocate memory (for output param/other operations)
587 * @retval #RUNTIME_INFO_ERROR_REMOTE_IO Call to resource daemon failed (dbus errors/resource daemon errors)
588 * @retval #RUNTIME_INFO_ERROR_IO_ERROR An I/O error during dbus message operations
589 * @retval #RUNTIME_INFO_ERROR_PERMISSION_DENIED Process not authorized to request app usage info
590 * @retval #RUNTIME_INFO_ERROR_NO_DATA No app running
593 * #include <runtime_info.h>
595 * void print_cpu_usage(void)
599 * app_usage_h cpu_rate_handle;
603 * runtime_info_get_all_apps_cpu_rate(&cpu_rate_handle);
604 * runtime_info_app_usage_get_count(cpu_rate_handle, &count);
606 * for (i = 0; i < count; i++) {
607 * runtime_info_app_usage_get_appid(cpu_rate_handle, i, &appid);
608 * runtime_info_app_usage_get_usage(cpu_rate_handle, i, &rate);
609 * printf("appid = %s, rate = %u %%\n", appid, rate);
613 * runtime_info_app_usage_destroy(cpu_rate_handle);
618 int runtime_info_get_all_apps_cpu_rate(app_usage_h *rate);
629 #endif /** __TIZEN_SYSTEM_RUNTIME_INFO_H__ */