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
17 #include <sys/types.h>
19 #include <system_settings.h>
20 #include <klay/auth/user.h>
21 #include <klay/audit/logger.h>
25 #include "rmi/package-proxy.h"
29 PackageProxy::PackageProxy(KrateControlContext& ctx) :
32 context.registerParametricMethod(this, "", (PackageProxy::PackageInfo)(PackageProxy::getPackageInfo)(std::string, std::string));
33 context.registerParametricMethod(this, "", (std::vector<std::string>)(PackageProxy::getPackageList)(std::string));
35 context.registerParametricMethod(this, "", (int)(PackageProxy::install)(std::string, std::string));
36 context.registerParametricMethod(this, "", (int)(PackageProxy::uninstall)(std::string, std::string));
39 PackageProxy::~PackageProxy()
43 PackageProxy::PackageInfo PackageProxy::getPackageInfo(const std::string& name, const std::string& pkgid)
45 PackageProxy::PackageInfo package;
48 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
50 locale = strdup("No locale");
55 package.locale = locale;
60 runtime::User user(name);
61 ::PackageInfo pkginfo(pkgid, user.getUid());
63 package.type = pkginfo.getType();
64 package.icon = pkginfo.getIcon();
65 package.label = pkginfo.getLabel();
66 package.description = pkginfo.getDescription();
68 package.author.name = pkginfo.getAuthorName();
69 package.author.email = pkginfo.getAuthorEmail();
70 package.author.href = pkginfo.getAuthorHref();
72 package.version = pkginfo.getVersion();
73 package.apiVersion = pkginfo.getApiVersion();
74 package.mainAppId = pkginfo.getMainAppId();
76 package.isSystem = pkginfo.isSystem();
77 package.isRemovable = pkginfo.isRemovable();
78 package.isPreload = pkginfo.isPreload();
79 } catch (runtime::Exception& e) {
80 ERROR("Failed to retrieve package info installed in the krate");
86 std::vector<std::string> PackageProxy::getPackageList(const std::string& name)
89 runtime::User user(name);
90 PackageManager& packman = PackageManager::instance();
91 return packman.getPackageList(user.getUid());
92 } catch (runtime::Exception& e) {
93 ERROR("Failed to retrieve package info installed in the krate");
95 return std::vector<std::string>();
99 int PackageProxy::install(const std::string& name, const std::string& pkgpath)
102 runtime::User user(name);
103 PackageManager& packman = PackageManager::instance();
104 packman.installPackage(pkgpath, user.getUid());
105 } catch (runtime::Exception& e) {
106 ERROR("Failed to install package in the krate");
113 int PackageProxy::uninstall(const std::string& name, const std::string& pkgid)
116 runtime::User user(name);
117 PackageManager& packman = PackageManager::instance();
118 packman.uninstallPackage(pkgid, user.getUid());
119 } catch (runtime::Exception& e) {
120 ERROR("Failed to uninstall package of pkgid in the krate");