2 * Copyright (c) 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
18 #include <sys/types.h>
20 #include <unordered_map>
22 #include <system_settings.h>
23 #include <klay/auth/user.h>
24 #include <klay/audit/logger.h>
27 #include "launchpad.h"
29 #include "rmi/app-proxy.h"
37 std::vector<ApplicationInfo> list;
41 std::unordered_map<int, IteratorData> iteratorMap;
42 int newIteratorId = 0;
46 AppProxy::AppProxy(KrateControlContext& ctx) :
49 context.registerParametricMethod(this, "", (AppProxy::AppInfo)(AppProxy::getAppInfo)(std::string, std::string));
51 context.registerParametricMethod(this, "", (int)(AppProxy::createIterator)(std::string));
52 context.registerParametricMethod(this, "", (AppProxy::AppInfo)(AppProxy::getIteratorValue)(int));
53 context.registerParametricMethod(this, "", (bool)(AppProxy::nextIterator)(int));
54 context.registerParametricMethod(this, "", (int)(AppProxy::destroyIterator)(int));
56 context.registerParametricMethod(this, "", (int)(AppProxy::launch)(std::string, AppProxy::Bundle));
57 context.registerParametricMethod(this, "", (int)(AppProxy::resume)(std::string, std::string));
58 context.registerParametricMethod(this, "", (int)(AppProxy::terminate)(std::string, std::string));
59 context.registerParametricMethod(this, "", (int)(AppProxy::isRunning)(std::string, std::string));
66 AppProxy::AppInfo AppProxy::getAppInfo(const std::string& name, const std::string& appid)
71 runtime::User user(name);
72 ApplicationInfo appinfo(appid, user.getUid());
75 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
77 appInfo.locale = "No locale";
79 appInfo.locale = locale;
85 appInfo.package = appinfo.getPackage();
86 appInfo.type = appinfo.getType();
87 appInfo.icon = appinfo.getIcon();
88 appInfo.label = appinfo.getLabel();
89 appInfo.componentType = appinfo.getComponentType();
90 appInfo.isNoDisplayed = appinfo.isNoDisplayed();
91 appInfo.isTaskManaged = appinfo.isTaskManaged();
92 } catch (runtime::Exception& e) {
93 ERROR("Failed to retrieve application info installed in the krate: " + appid);
99 int AppProxy::createIterator(const std::string& name)
103 PackageManager& packman = PackageManager::instance();
104 runtime::User user(name);
107 iteratorId = newIteratorId;
110 data.list = packman.getAppList(user.getUid());
113 iteratorMap.insert(std::make_pair(iteratorId, data));
115 if (++newIteratorId < 0) {
118 } catch (runtime::Exception& e) {
119 ERROR("Failed to retrieve package info installed in the krate");
124 AppProxy::AppInfo AppProxy::getIteratorValue(int iterator)
128 auto it = iteratorMap.find(iterator);
129 if (it == iteratorMap.end()) {
132 if (it->second.current >= it->second.list.size()) {
136 const ApplicationInfo& appinfo = it->second.list.at(it->second.current);
139 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
140 if (locale == NULL) {
141 appInfo.locale = "No locale";
143 appInfo.locale = locale;
147 appInfo.krate = it->second.krate;
148 appInfo.id = appinfo.getId();
149 appInfo.package = appinfo.getPackage();
150 appInfo.type = appinfo.getType();
151 appInfo.icon = appinfo.getIcon();
152 appInfo.label = appinfo.getLabel();
153 appInfo.componentType = appinfo.getComponentType();
154 appInfo.isNoDisplayed = appinfo.isNoDisplayed();
155 appInfo.isTaskManaged = appinfo.isTaskManaged();
160 bool AppProxy::nextIterator(int iterator)
162 auto it = iteratorMap.find(iterator);
163 if (it != iteratorMap.end()) {
164 if (++it->second.current < it->second.list.size()) {
171 int AppProxy::destroyIterator(int iterator)
173 auto it = iteratorMap.find(iterator);
174 if (it != iteratorMap.end()) {
175 iteratorMap.erase(it);
181 int AppProxy::launch(const std::string& name, const AppProxy::Bundle& bundle)
184 runtime::User user(name);
187 if (!bundle.operation.empty()) {
188 b.add("__APP_SVC_OP_TYPE__", bundle.operation);
190 if (!bundle.uri.empty()) {
191 b.add("__APP_SVC_URI__", bundle.uri);
193 if (!bundle.mime.empty()) {
194 b.add("__APP_SVC_MIME__", bundle.mime);
196 if (!bundle.category.empty()) {
197 b.add("__APP_SVC_CATEGORY__", bundle.category);
200 for (Bundle::Extra extra : bundle.extraData) {
201 if (extra.value.size() > 1) {
202 b.add(extra.key, extra.value);
203 } else if (extra.value.size() == 1) {
204 b.add(extra.key, extra.value.at(0));
208 Launchpad launchpad(user.getUid());
209 launchpad.launch(bundle.appId, b);
210 } catch (runtime::Exception& e) {
211 ERROR("Failed to launch app in the krate");
217 int AppProxy::resume(const std::string& name, const std::string& appid)
220 runtime::User user(name);
221 Launchpad launchpad(user.getUid());
222 launchpad.resume(appid);
223 } catch (runtime::Exception& e) {
224 ERROR("Failed to terminate app in the krate");
230 int AppProxy::terminate(const std::string& name, const std::string& appid)
233 runtime::User user(name);
234 Launchpad launchpad(user.getUid());
235 launchpad.terminate(appid);
236 } catch (runtime::Exception& e) {
237 ERROR("Failed to terminate app in the krate");
243 bool AppProxy::isRunning(const std::string& name, const std::string& appid)
246 runtime::User user(name);
247 Launchpad launchpad(user.getUid());
248 return launchpad.isRunning(appid);
249 } catch (runtime::Exception& e) {
250 ERROR("Failed to get app running state in the krate");