2 * Copyright (c) 2000 - 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.
20 #include <syspopup_caller.h>
22 #include <sys/resource.h>
23 #include <bundle_internal.h>
25 #include "process_mgr.h"
27 #include "dbus_util.h"
29 #define LOCKD_VOICE_CALL_PKG_NAME "org.tizen.call-ui"
30 #define LOCKD_VIDEO_CALL_PKG_NAME "org.tizen.vtmain"
32 #define NICE_VALUE_PWLOCK -5
33 #define NICE_VALUE_LOCKSCREEN -20
37 typedef struct _launch_info_s {
47 static int _try_to_launch(const char *appid, const char *key, const char *value, after_func afn)
57 _E("Failed to create a bundle");
60 bundle_add(b, key, value);
63 pid = aul_launch_app(appid, b);
64 if (b) bundle_free(b);
66 _D("Succeed to launch %s", appid);
75 static Eina_Bool _must_launch_cb(void *data)
77 launch_info_s *launch_info = data;
80 retv_if(!launch_info, ECORE_CALLBACK_CANCEL);
82 pid = _try_to_launch(launch_info->appid, launch_info->key, launch_info->value, launch_info->afn);
87 retv_if(pid == AUL_R_ECOMM, ECORE_CALLBACK_RENEW);
88 retv_if(pid == AUL_R_ETERMINATING, ECORE_CALLBACK_RENEW);
89 if (pid == AUL_R_ERROR) {
91 && 0 == launch_info->cfn(launch_info->appid, launch_info->key, launch_info->value, (void *) launch_info->cfn, (void *) launch_info->afn))
93 _D("change func has set the next appid");
95 _E("change func has returned error");
100 return ECORE_CALLBACK_RENEW;
103 free(launch_info->appid);
104 free(launch_info->key);
105 free(launch_info->value);
107 return ECORE_CALLBACK_CANCEL;
112 void process_mgr_must_launch(const char *appid, const char *key, const char *value, change_func cfn, after_func afn)
114 Ecore_Timer *timer = NULL;
115 launch_info_s *launch_info = NULL;
118 _D("Must launch %s", appid);
120 pid = _try_to_launch(appid, key, value, afn);
123 _E("Failed the first try to launch %s", appid);
125 launch_info = calloc(1, sizeof(launch_info_s));
126 ret_if(!launch_info);
128 if (appid) launch_info->appid = strdup(appid);
129 if (key) launch_info->key = strdup(key);
130 if (value) launch_info->value = strdup(value);
131 launch_info->cfn = cfn;
132 launch_info->afn = afn;
134 timer = ecore_timer_add(0.1f, _must_launch_cb, launch_info);
136 _E("cannot add a timer for must_launch");
137 free(launch_info->appid);
138 free(launch_info->key);
139 free(launch_info->value);
146 static int _try_to_open(const char *appid, after_func afn)
152 pid = aul_open_app(appid);
154 _D("Succeed to open %s", appid);
163 static Eina_Bool _must_open_cb(void *data)
165 launch_info_s *launch_info = data;
168 retv_if(!launch_info, ECORE_CALLBACK_CANCEL);
170 pid = _try_to_open(launch_info->appid, launch_info->afn);
175 retv_if(pid == AUL_R_ECOMM, ECORE_CALLBACK_RENEW);
176 retv_if(pid == AUL_R_ETERMINATING, ECORE_CALLBACK_RENEW);
177 if (pid == AUL_R_ERROR) {
178 if (launch_info->cfn && 0 == launch_info->cfn(launch_info->appid, NULL, NULL, launch_info->cfn, launch_info->afn)) {
179 _D("change func has set the next appid");
181 _E("change func has returned error");
186 return ECORE_CALLBACK_RENEW;
189 free(launch_info->appid);
191 return ECORE_CALLBACK_CANCEL;
196 void process_mgr_must_open(const char *appid, change_func cfn, after_func afn)
198 Ecore_Timer *timer = NULL;
199 launch_info_s *launch_info = NULL;
202 _D("Must open %s", appid);
204 pid = _try_to_open(appid, afn);
207 _E("Failed the first try to open %s", appid);
209 launch_info = calloc(1, sizeof(launch_info_s));
210 ret_if(!launch_info);
212 if (appid) launch_info->appid = strdup(appid);
213 launch_info->cfn = cfn;
214 launch_info->afn = afn;
216 timer = ecore_timer_add(0.1f, _must_open_cb, launch_info);
218 _E("cannot add a timer for must_launch");
219 free(launch_info->appid);
226 static int _try_to_syspopup_launch(const char *appid, const char *key, const char *value, after_func afn)
235 bundle_add(b, key, value);
238 pid = aul_launch_app("org.tizen.volume", b);
239 if (b) bundle_free(b);
241 _D("Succeed to launch %s", appid);
250 static Eina_Bool _must_syspopup_launch_cb(void *data)
252 launch_info_s *launch_info = data;
255 retv_if(!launch_info, ECORE_CALLBACK_CANCEL);
257 pid = _try_to_syspopup_launch(launch_info->appid, launch_info->key, launch_info->value, launch_info->afn);
262 retv_if(pid == AUL_R_ECOMM, ECORE_CALLBACK_RENEW);
263 retv_if(pid == AUL_R_ETERMINATING, ECORE_CALLBACK_RENEW);
264 if (pid == AUL_R_ERROR) {
266 && 0 == launch_info->cfn(launch_info->appid, launch_info->key, launch_info->value, launch_info->cfn, launch_info->afn)) {
267 _D("change func has set the next appid");
269 _E("change func has returned error");
274 return ECORE_CALLBACK_RENEW;
277 free(launch_info->appid);
278 free(launch_info->key);
279 free(launch_info->value);
281 return ECORE_CALLBACK_CANCEL;
286 void process_mgr_must_syspopup_launch(const char *appid, const char *key, const char *value, change_func cfn, after_func afn)
288 Ecore_Timer *timer = NULL;
289 launch_info_s *launch_info = NULL;
292 _D("Must launch %s", appid);
294 pid = _try_to_syspopup_launch(appid, key, value, afn);
297 _E("Failed the first try to launch %s", appid);
299 launch_info = calloc(1, sizeof(launch_info_s));
300 ret_if(!launch_info);
302 if (appid) launch_info->appid = strdup(appid);
303 if (key) launch_info->key = strdup(key);
304 if (value) launch_info->value = strdup(value);
305 launch_info->cfn = cfn;
306 launch_info->afn = afn;
308 timer = ecore_timer_add(0.1f, _must_syspopup_launch_cb, launch_info);
310 _E("cannot add a timer for must_launch");
311 free(launch_info->appid);
312 free(launch_info->key);
313 free(launch_info->value);
320 static Eina_Bool _set_lock_priority_cb(void *data)
324 prio = getpriority(PRIO_PROCESS, (pid_t)data);
325 if (prio == NICE_VALUE_LOCKSCREEN) {
326 _D("%s (%d: %d)\n", "setpriority Success", (pid_t)data, prio);
327 return ECORE_CALLBACK_CANCEL;
330 if (setpriority(PRIO_PROCESS, (pid_t)data, NICE_VALUE_LOCKSCREEN) < 0 ) {
331 _D("error : %d", errno);
332 return ECORE_CALLBACK_CANCEL;
335 return ECORE_CALLBACK_RENEW;
340 static Eina_Bool _set_pwlock_priority_cb(void *data)
344 prio = getpriority(PRIO_PROCESS, (pid_t)data);
345 if (prio == NICE_VALUE_PWLOCK) {
346 _D("%s (%d: %d)\n", "setpriority Success", (pid_t)data, prio);
347 return ECORE_CALLBACK_CANCEL;
350 if (setpriority(PRIO_PROCESS, (pid_t)data, NICE_VALUE_PWLOCK) < 0 ) {
351 _D("error : %d", errno);
352 return ECORE_CALLBACK_CANCEL;
355 return ECORE_CALLBACK_RENEW;
360 int process_mgr_set_lock_priority(int pid)
362 return !ecore_timer_add(1.0f, _set_lock_priority_cb, (void *)pid);
367 int process_mgr_set_pwlock_priority(int pid)
369 return !ecore_timer_add(1.0f, _set_pwlock_priority_cb, (void *)pid);
374 void process_mgr_terminate_app(int pid, int state)
376 _D("process_mgr_terminate_app, state:%d\n", state);
380 _D("Terminate Lock app(pid : %d)", pid);
381 aul_terminate_pid(pid);
388 extern int aul_kill_pid(int pid);
389 void process_mgr_kill_app(int pid)
391 _D ("process_mgr_kill_app [pid:%d]..", pid);
397 int process_mgr_validate_app(int pid)
399 char buf[BUF_SIZE_128] = {0, };
401 /* Check pid is invalid. */
402 if (aul_app_get_pkgname_bypid(pid, buf, sizeof(buf)) < 0) {
403 _D("no such pkg by pid %d\n", pid);
405 _SECURE_D("appid = %s, pid = %d\n", buf, pid);
406 if (aul_app_is_running(buf) == TRUE) {
407 _D("%s [pid = %d] is running\n", buf, pid);
410 _SECURE_D("[pid = %d] is exist but %s is not running\n", pid, buf);
419 int process_mgr_validate_call(int pid)
421 char buf[BUF_SIZE_128] = {0, };
423 /* Check pid is invalid. */
424 if (aul_app_get_pkgname_bypid(pid, buf, sizeof(buf)) < 0) {
425 _D("no such pkg by pid %d", pid);
427 _SECURE_D("appid = %s, pid = %d", buf, pid);
428 if ((!strncmp(buf, LOCKD_VOICE_CALL_PKG_NAME, strlen(buf)))
429 || (!strncmp(buf, LOCKD_VIDEO_CALL_PKG_NAME, strlen(buf)))) {