Add SDcard password confirm popup
[platform/core/security/ode.git] / server / launchpad.cpp
1 /*
2  *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16 #include <unistd.h>
17 #include <signal.h>
18 #include <sys/types.h>
19
20 #include <aul.h>
21 #include <klay/exception.h>
22 #include <klay/audit/logger.h>
23
24 #include "launchpad.h"
25
26 Launchpad::Launchpad(const uid_t uid) :
27         user(uid)
28 {
29         if (user == 0) {
30                 throw runtime::Exception("No logined user for launching app");
31         }
32 }
33
34 bool Launchpad::isRunning(const std::string& appid)
35 {
36         return ::aul_app_is_running_for_uid(appid.c_str(), user);
37 }
38
39 void Launchpad::launch(const std::string& appid)
40 {
41         launch(appid, AppBundle());
42 }
43
44 void Launchpad::launch(const std::string& appid, const AppBundle& bundle)
45 {
46         if (::aul_launch_app_for_uid(appid.c_str(), bundle.get(), user) < 0) {
47                 throw runtime::Exception("Failed to launch app " + appid);
48         }
49 }
50
51 void Launchpad::resume(const std::string& appid)
52 {
53         if (::aul_resume_app_for_uid(appid.c_str(), user) < 0) {
54                 throw runtime::Exception("Failed to resume app " + appid);
55         }
56 }
57
58 void Launchpad::terminate(const std::string& appid)
59 {
60         int pid = ::aul_app_get_pid_for_uid(appid.c_str(), user);
61         if (pid > 0) {
62                 if (::aul_terminate_pid_for_uid(pid, user) < 0) {
63                         WARN("Failed to terminate app PID=" + std::to_string(pid));
64                         ::kill(pid, SIGKILL);
65                 }
66         }
67 }