2 * Copyright (c) 2018 Samsung Electronics Co.
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 src/common/policy/PkgInfo.cpp
18 * @author Tomasz Swierczek <t.swierczek@samsung.com>
19 * @brief Implementation of PkgInfo (sub)classes
25 #include <pkgmgr-info.h>
31 void AulPkgInfo::fetch(const std::string &pkgId, uid_t uid) {
33 memset(buffer, 0, sizeof(buffer));
34 int ret = aul_app_get_appid_bypid(getpid(), buffer, sizeof(buffer) - 1);
36 m_mainAppId = std::string(buffer);
38 ALOGE("aul_app_get_appid_bypid failed");
40 ret = aul_app_get_pkgname_bypid(getpid(), buffer, sizeof(buffer));
42 m_pkgLabel = std::string(buffer);
44 ALOGE("aul_app_get_pkgname_bypid failed");
49 void PkgMgrPkgInfo::fetch(const std::string &pkgId, uid_t uid) {
50 pkgmgrinfo_pkginfo_h handle = nullptr;
51 int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &handle);
52 if (ret != PMINFO_R_OK) {
53 ALOGE("pkgmgrinfo_pkginfo_get_usr_pkginfo failed for " << pkgId << " with " << ret);
57 ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &mainAppId);
58 if (ret != PMINFO_R_OK) {
59 ALOGE("pkgmgrinfo_pkginfo_get_mainappid failed with " << ret);
60 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
64 m_mainAppId = mainAppId;
67 ret = pkgmgrinfo_pkginfo_get_label(handle, &pkgLabel);
68 if (ret != PMINFO_R_OK) {
69 ALOGE("pkgmgrinfo_pkginfo_get_label failed with " << ret);
70 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
74 m_pkgLabel = pkgLabel;
76 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
81 } // namespace AskUser