4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #ifndef __DD_DEVICED__
21 #define __DD_DEVICED__
26 #include <sys/types.h>
27 #include "dd-deviced-managed.h"
31 * @defgroup CAPI_SYSTEM_DEVICED_UTIL_MODULE Util
32 * @ingroup CAPI_SYSTEM_DEVICED
33 * @section CAPI_SYSTEM_DEVICED_UTIL_MODULE_HEADER Required Header
34 * \#include <dd-deviced.h>
42 * @addtogroup CAPI_SYSTEM_DEVICED_UTIL_MODULE
47 * @brief Policy for low memory
50 OOM_LIKELY, /**< For miscellaneous applications */
51 OOM_IGNORE /**< For daemons */
54 #define CRASH_TICKET_PATH "/opt/usr/share/crash/ticket"
55 #define FORCED_DUMP_DIR_PATH "/opt/usr/media/SLP_debug"
56 #define FORCED_DUMP_ZIP_PATH "/opt/usr/media/SLP_debug/zip"
59 * @brief Logs dump type
62 AP_DUMP = 0, /**< Application logs dump */
63 CP_DUMP = 1, /**< Modem logs dump */
64 ALL_DUMP = 2 /**< All logs dump - application and modem */
70 * @fn int deviced_get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size)
71 * @brief This API is used to get the file name of command line of the process from the proc fs.
72 * Caller process MUST allocate enough memory for the cmdline parameter. \n
73 * Its size should be assigned to cmdline_size. \n
74 * Internally it reads the 1st argument of /proc/{pid}/cmdline and copies it to cmdline.
75 * @param[in] pid pid of the process that you want to get the file name of command line
76 * @param[out] cmdline command line of the process that you want to get the file name <br>
77 * Callers should allocate memory to this parameter before calling this function.
78 * The allocated memory size must be large enough to store the file name.
79 * The result will include the terminating null byte('\0') at the end of the string.
80 * @param[in] cmdline_size
81 * @return 0 on success, negative value if failed.\n
82 * If the size of cmdline is smaller than the result, it will return -75 and \n
83 * errno will be set as EOVERFLOW. \n
84 * If the function cannot open /proc/%d/cmdline file then it will return -3 and \n
85 * errno will be set as ESRCH.
87 int deviced_get_cmdline_name(pid_t pid, char *cmdline,
91 * @fn int deviced_get_apppath(pid_t pid, char *app_path, size_t app_path_size)
92 * @brief This API is used to get the execution path of the process specified by the pid parameter.\n
93 * Caller process MUST allocate enough memory for the app_path parameter. \n
94 * Its size should be assigned to app_path_size. \n
95 * Internally it reads a link of /proc/{pid}/exe and copies the path to app_path.
96 * @param[in] pid pid of the process that you want to get the executed path
97 * @param[out] app_path the executed file path of the process <br>
98 * Callers should allocate memory to this parameter before calling this function.
99 * The allocated memory size must be large enough to store the executed file path.
100 * The result will include the terminating null byte('\0') at the end of the string.
101 * @param[in] app_path_size allocated memory size of char *app_path
102 * @return 0 on success, -1 if failed. \n
103 * If the size of app_path is smaller than the result, it will return -1 and \n
104 * errno will be set as EOVERFLOW.
106 int deviced_get_apppath(pid_t pid, char *app_path, size_t app_path_size);
111 * @fn int deviced_conf_set_mempolicy(enum mem_policy mempol)
112 * @brief This API is used to set the policy of the current process when the phone has low available memory.
113 * @param[in] mempol oom adjust value which you want to set
114 * @return 0 on success, -1 if failed.
115 * @see deviced_conf_set_mempolicy_bypid()
116 * @retval -1 operation error
117 * @retval -EBADMSG - dbus error (in case of any error on the bus)
118 * @retval -EINVAL no mandatory parameters
119 * @retval -ESRCH incorrect sender process id
121 int deviced_conf_set_mempolicy(enum mem_policy mempol);
124 * @fn int deviced_conf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol)
125 * @brief This API is used to set the policy of the given process when the phone has low available memory.
126 * @param[in] pid process id which you want to set
127 * @param[in] mempol oom adjust value which you want to set
128 * @return 0 on success, -1 if failed.
129 * @retval -1 operation error
130 * @retval -EBADMSG - dbus error (in case of any error on the bus)
131 * @retval -EINVAL no mandatory parameters
132 * @retval -ESRCH incorrect sender process id
134 int deviced_conf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol);
137 * @fn int deviced_conf_set_permanent(void)
138 * @brief This API is used to set itself as a permanent process.\n
139 * If the permanent process is dead, system server will relaunch the process automatically.
140 * @return 0 on success, -1 if failed.
141 * @see deviced_conf_set_permanent_bypid()
145 * ret = deviced_conf_set_permanent();
147 * printf("Fail to set a process as permanent\n");
151 int deviced_conf_set_permanent(void);
154 * @fn int deviced_conf_set_permanent_bypid(pid_t pid)
155 * @brief This API is used to set a given process as permanent.\n
156 * If the permanent process is dead, system server will relaunch the process automatically.
157 * @param[in] pid proces id
158 * @return 0 on success, -1 if failed.
159 * @see deviced_set_permanent()
163 * ret = deviced_conf_set_permanent_bypid(pid);
165 * printf("Fail to set a process(%d) as permanent\n",pid);
169 int deviced_conf_set_permanent_bypid(pid_t pid);
172 * @fn int deviced_conf_set_vip(pid_t pid)
173 * @brief This API is used to set a process which has pid as Very Important Process(VIP) .\n
174 * If the VIP process is dead, restarter program will be run. \n
175 * Restarter program may kill almost processes and run rc.local scripts again.
176 * @param[in] pid process id to be vip
177 * @return 0 on success, -1 if failed.
178 * @see sysconf_is_vip
182 * ret = deviced_conf_set_vip(pid);
184 * printf("Fail to set a process(%d) as VIP\n",pid);
188 int deviced_conf_set_vip(pid_t pid);
191 * @fn int deviced_conf_is_vip(pid_t pid)
192 * @brief This API is used to verify that process which has pid is Very Important Process(VIP) or not.
193 * @param[in] pid process id to be vip
194 * @return 1 if given process if vip process, otherwise 0 is returned.
195 * @see deviced_conf_set_vip
199 * ret = deviced_conf_is_vip(pid);
201 * printf("process(%d) is Very Important Process\n",pid);
205 int deviced_conf_is_vip(pid_t pid);
208 * @fn int deviced_set_timezone(char *tzpath_str)
209 * @brief This API sets system timezone.
210 * @param[in] tzpath_str path to timezone definition file
211 * @return 0 on success, negative value if failed.
212 * @retval -1 operation error
213 * @retval -EBADMSG dbus error (in case of any error on the bus)
214 * @retval -EINVAL no mandatory parameters
215 * @retval -ESRCH incorrect sender process id
217 int deviced_set_timezone(char *tzpath_str);
220 * @fn int deviced_call_predef_action(const char *type, int num, ...)
221 * @brief This API calls predefined systemd action.
222 * Internally it send message through SYSTEM_NOTI_SOCKET_PATH (/tmp/sn) UNIX socket to systemd.
223 * @param[in] type systemd action type name
224 * @param[in] num input parameters count. num cannot exceed SYSTEM_NOTI_MAXARG (16).
225 * @param[in] ... action input parameters. List of the parameters depends on action type.
226 * @return 0 on success, -1 if failed.
227 * If the action type is not set (is blank) or num > SYSTEM_NOTI_MAXARG it will return -1
228 * and errno will be set as EINVAL.
230 int deviced_call_predef_action(const char *type, int num, ...);
233 * @fn int deviced_change_flightmode(int mode)
234 * @brief This API call notifies about flight mode.
235 * @return 0 or positive value on success and negative value if failed.
236 * @retval -1 operation error
237 * @retval -EBADMSG dbus error (in case of any error on the bus)
238 * @retval -EINVAL no mandatory parameters
239 * @retval -ESRCH incorrect sender process id
241 int deviced_change_flightmode(int mode);
244 * @fn int deviced_inform_foregrd(void)
245 * @brief This API call notifies that current process is running in foreground.
246 * @return 0 or positive value on success and negative value if failed.
247 * @retval -1 operation error
248 * @retval -EBADMSG dbus error (in case of any error on the bus)
249 * @retval -EINVAL no mandatory parameters
250 * @retval -ESRCH incorrect sender process id
252 int deviced_inform_foregrd(void);
255 * @fn int deviced_inform_backgrd(void)
256 * @brief This API call notifies that current process is running in background.
257 * @return 0 or positive value on success and negative value if failed.
258 * @retval -1 operation error
259 * @retval -EBADMSG dbus error (in case of any error on the bus)
260 * @retval -EINVAL no mandatory parameters
261 * @retval -ESRCH incorrect sender process id
263 int deviced_inform_backgrd(void);
266 * @fn int deviced_inform_active(pid_t pid)
267 * @brief This API call notifies deviced daemon that given process (pid) is active.
268 * @param[in] pid process pid
269 * @return 0 or positive value on success and negative value if failed.
270 * @retval -1 operation error
271 * @retval -EBADMSG dbus error (in case of any error on the bus)
272 * @retval -EINVAL no mandatory parameters
273 * @retval -ESRCH incorrect sender process id
275 int deviced_inform_active(pid_t pid);
278 * @fn int deviced_inform_active(pid_t pid)
279 * @brief This API call notifies deviced daemon that given process (pid) is inactive.
280 * @param[in] pid process pid
281 * @return 0 or positive value on success and negative value if failed.
282 * @retval -1 operation error
283 * @retval -EBADMSG dbus error (in case of any error on the bus)
284 * @retval -EINVAL no mandatory parameters
285 * @retval -ESRCH incorrect sender process id
287 int deviced_inform_inactive(pid_t pid);
290 * @fn int deviced_request_poweroff(void)
291 * @brief This API call requests deviced daemon to launch "system poweroff popup".
292 * @return 0 or positive value on success and negative value if failed.
293 * @retval -1 operation error
294 * @retval -EBADMSG dbus error (in case of any error on the bus)
295 * @retval -EINVAL no mandatory parameters
296 * @retval -ESRCH incorrect sender process id
298 int deviced_request_poweroff(void);
301 * @fn deviced_request_entersleep(void)
302 * @brief This API call requests deviced daemon to enter system into sleep mode.
303 * @return 0 or positive value on success and negative value if failed.
304 * @retval -EBADMSG dbus error (in case of any error on the bus)
305 * @retval -EINVAL no mandatory parameters
306 * @retval -ESRCH incorrect sender process id
308 int deviced_request_entersleep(void);
311 * @fn int deviced_request_leavesleep(void)
312 * @brief This API calls requests deviced daemon to leave by system "sleep" mode and enter into "normal" mode.
313 * @return 0 or positive value on success and negative value if failed.
314 * @retval -EBADMSG dbus error (in case of any error on the bus)
315 * @retval -EINVAL no mandatory parameters
316 * @retval -ESRCH incorrect sender process id
318 int deviced_request_leavesleep(void);
321 * @fn int deviced_request_reboot(void)
322 * @brief This API call requests deviced daemon to initiate system reboot.
323 * @return 0 on success and negative value if failed.
324 * @retval -EBADMSG dbus error (in case of any error on the bus)
325 * @retval -EINVAL no mandatory parameters
326 * @retval -ESRCH incorrect sender process id
328 int deviced_request_reboot(void);
331 * @fn int deviced_request_set_cpu_max_frequency(int val)
332 * @brief This API call requests deviced daemon to set maximum CPU frequency.
333 * @param[in] val maximum CPU frequency to be set.
334 * @return 0 or positive value on success and negative value if failed.
335 * @retval -1 operation error
336 * @retval -EBADMSG - dbus error (in case of any error on the bus)
338 int deviced_request_set_cpu_max_frequency(int val);
341 * @fn int deviced_request_set_cpu_min_frequency(int val)
342 * @brief This API call requests deviced daemon to set minimum CPU frequency.
343 * @param[in] val minimum CPU frequency to be set
344 * @return 0 or positive value on success and negative value if failed.
345 * @retval -1 operation error
346 * @retval -EBADMSG dbus error (in case of any error on the bus)
348 int deviced_request_set_cpu_min_frequency(int val);
351 * @fn int deviced_release_cpu_max_frequency(void)
352 * @brief This API call releases limit of maximum CPU frequency set by deviced_request_set_cpu_max_frequency() API.
353 * @return 0 or positive value on success and negative value if failed.
354 * @retval -1 operation error
355 * @retval -EBADMSG dbus error (in case of any error on the bus)
357 int deviced_release_cpu_max_frequency(void);
360 * @fn int deviced_release_cpu_min_frequency(void)
361 * @brief This API calls releases limit of minimum CPU frequency set by deviced_request_set_cpu_min_frequency() API.
362 * @return 0 or positive value on success and negative value if failed.
363 * @retval -1 operation error
364 * @retval -EBADMSG dbus error (in case of any error on the bus)
366 int deviced_release_cpu_min_frequency(void);
369 * @fn int deviced_request_set_factory_mode(int val)
370 * @brief This API call requests systemd daemon to enter system into factory mode.
371 * @param[in] val factory mode level.\n
372 * 0 - "off" factory mode\n
373 * 1 - "on" factory mode.
374 * @return 0 or positive value on success and negative value if failed.
375 * @retval -1 operation error
376 * @retval -EBADMSG dbus error (in case of any error on the bus)
377 * @retval -EINVAL no mandatory parameters
378 * @retval -ESRCH incorrect sender process id
380 int deviced_request_set_factory_mode(int val);
383 * @fn int deviced_request_dump_log(int type)
384 * @brief This API call force dumps all application, modem or application + modem logs.
385 * - if type is equal AP_DUMP application log dump will be created.
386 * - if type is equal CP_DUMP modem logs dump will be created
387 * - if dump type is equal ALL_DUMP application and modem logs dump will be created
388 * @param[in] type dump type.
389 * @return 0 or positive value on success and negative value if failed.
390 * @retval -1 operation error
391 * @retval -EBADMSG dbus error (in case of any error on the bus)
394 int deviced_request_dump_log(int type);
397 * @fn int deviced_request_delete_dump(char *ticket)
398 * @brief This API call removes all dump data for given ticket from /opt/usr/share/crash/ticket directory.
399 * @param[in] ticket ticket name.
400 * @return 1 on success and negative value if failed.
401 * @retval -1 operation error
402 * @retval -EBADMSG dbus error (in case of any error on the bus)
404 int deviced_request_delete_dump(char *ticket);
413 #endif /* __DD_DEVICED__ */