2 * Copyright (c) 2013 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 * @file launchpad_util.h
18 * @author Tae-Jeong Lee (taejeong.lee@samsung.com)
20 * @brief Api library to support launchpad operation.
23 #ifndef __LAUNCHPAD_UTIL_H_
24 #define __LAUNCHPAD_UTIL_H_
28 #include <privilege-control.h>
29 #include <sys/prctl.h>
31 #include <tzplatform_config.h>
36 #include "menu_db_util.h"
37 #include "simple_util.h"
38 #include "access_control.h"
40 #define _static_ static inline
41 #define WRT_AUL_PR_NAME 16
42 #define PKG_ID_LENGTH 11
43 #define SDK_CODE_COVERAGE "CODE_COVERAGE"
44 #define SDK_DYNAMIC_ANALYSIS "DYNAMIC_ANALYSIS"
45 #define PATH_DA_SO tzplatform_mkpath(TZ_SDK_TOOLS,"da/da_probe.so")
46 #define PATH_DATA "/data"
49 _static_ char** __create_argc_argv(bundle * kb, int *margc);
50 _static_ void __set_sdk_env(app_info_from_db* menu_info, char* str);
51 _static_ int __parser(const char *arg, char *out, int out_size);
52 _static_ void __modify_bundle(bundle * kb, int caller_pid, app_info_from_db * menu_info, int cmd);
53 _static_ void __set_oom();
54 _static_ void __set_env(app_info_from_db * menu_info, bundle * kb);
57 _static_ char** __create_argc_argv(bundle * kb, int *margc)
62 argc = bundle_export_to_argv(kb, &argv);
68 _static_ void __set_sdk_env(app_info_from_db* menu_info, char* str)
70 char buf[MAX_LOCAL_BUFSZ];
73 _D("key : %s / value : %s", AUL_K_SDK, str);
74 /* http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html*/
75 /* GCOV_PREFIX contains the prefix to add to the absolute paths in the
77 /* Prefix can be absolute, or relative. The default is no prefix.
79 /* GCOV_PREFIX_STRIP indicates the how many initial directory names */
80 /* to stripoff the hardwired absolute paths. Default value is 0. */
81 if (strncmp(str, SDK_CODE_COVERAGE, strlen(str)) == 0) {
85 tzplatform_getenv(TZ_USER_APP),_get_pkgname(menu_info));
86 ret = setenv("GCOV_PREFIX", buf, 1);
87 _D("GCOV_PREFIX : %d", ret);
88 ret = setenv("GCOV_PREFIX_STRIP", "4096", 1);
89 _D("GCOV_PREFIX_STRIP : %d", ret);
90 } else if (strncmp(str, SDK_DYNAMIC_ANALYSIS, strlen(str)) == 0) {
91 ret = setenv("LD_PRELOAD", PATH_DA_SO, 1);
92 _D("LD_PRELOAD : %d", ret);
98 * Parsing original app path to retrieve default bundle
100 * -1 : Invalid sequence
101 * -2 : Buffer overflow
104 _static_ int __parser(const char *arg, char *out, int out_size)
108 char *start_out = out;
110 if (arg == NULL || out == NULL) {
111 /* Handles null buffer*/
115 for (i = 0; out_size > 1; i++) {
139 case 2: /* escape start*/
154 case 4: /* character escape*/
155 if (arg[i] == '\0') {
165 if (out != start_out) {
174 return -1; /* error*/
175 case 7: /* terminate*/
193 _static_ void __modify_bundle(bundle * kb, int caller_pid,
194 app_info_from_db * menu_info, int cmd)
196 // warning: unused parameter
199 bundle_del(kb, AUL_K_PKG_NAME);
200 bundle_del(kb, AUL_K_EXEC);
201 bundle_del(kb, AUL_K_PACKAGETYPE);
202 bundle_del(kb, AUL_K_HWACC);
204 /* Parse app_path to retrieve default bundle*/
205 if (cmd == APP_START || cmd == APP_START_RES || cmd == APP_OPEN || cmd ==
209 char exe[MAX_PATH_LEN];
212 ptr = _get_original_app_path(menu_info);
214 flag = __parser(ptr, exe, sizeof(exe));
220 _D("parsing app_path: EXEC - %s\n", exe);
223 flag = __parser(ptr, key, sizeof(key));
229 flag = __parser(ptr, value, sizeof(value));
235 /*bundle_del(kb, key);*/
236 bundle_add(kb, key, value);
238 } else if (flag == 0) {
239 _D("parsing app_path: No arguments\n");
241 _D("parsing app_path: Invalid argument\n");
247 _static_ void __set_oom()
249 char buf[MAX_LOCAL_BUFSZ];
252 /* we should reset oomadj value as default because child
253 * inherits from parent oom_adj*/
254 snprintf(buf, MAX_LOCAL_BUFSZ, "/proc/%d/oom_adj", getpid());
255 fp = fopen(buf, "w");
259 fprintf(fp, "%d", -16);
263 _static_ void __set_env(app_info_from_db * menu_info, bundle * kb)
266 const char **str_array;
270 setenv("PKG_NAME", _get_pkgname(menu_info), 1);
274 str = bundle_get_val(kb, AUL_K_STARTTIME);
276 setenv("APP_START_TIME", str, 1);
279 if (bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
280 str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
281 if (str_array != NULL) {
282 for (i = 0; i < len; i++) {
283 _D("index : [%d]", i);
284 __set_sdk_env(menu_info, (char *)str_array[i]);
288 str = bundle_get_val(kb, AUL_K_SDK);
290 __set_sdk_env(menu_info, (char *)str);
293 if (menu_info->hwacc != NULL) {
294 setenv("HWACC", menu_info->hwacc, 1);
298 #endif // __LAUNCHPAD_UTIL_H_