2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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.
21 #include <package_info.h>
22 #include <package_manager.h>
27 #include "notification-ex/ex_util.h"
33 #define LOG_TAG "NOTIFICATION_EX"
34 #define MAX_PACKAGE_STR_SIZE 512
37 namespace notification {
39 GQuark GetQuarkFromString(string str) {
40 return g_quark_from_string(str.c_str());
43 std::string GetQuarkToString(GQuark quark) {
44 return g_quark_to_string(quark);
49 g_atomic_int_inc(&id);
54 static string appid = "";
55 char appid_buf[MAX_PACKAGE_STR_SIZE] = {0, };
58 LOGI("appid(%s)", appid.c_str());
63 int ret = aul_app_get_appid_bypid(pid, appid_buf, sizeof(appid_buf));
64 if (ret == AUL_R_OK) {
65 appid = string(appid_buf);
68 int last_slash_index = 0;
69 char proc_buf[MAX_PACKAGE_STR_SIZE] = { 0, };
71 snprintf(proc_buf, sizeof(proc_buf), "/proc/%d/cmdline", pid);
73 fd = open(proc_buf, O_RDONLY);
75 LOGE("Fail to get appid (%d)", errno);
79 ret = read(fd, appid_buf, sizeof(appid_buf) - 1);
81 LOGE("Fail to get appid (%d)", errno);
87 for (i = 0 ; i < ret ; i++) {
88 if (appid_buf[i] == '/')
92 if (last_slash_index == (ret - 1)) {
93 LOGE("Fail to get appid (%s)", appid_buf);
97 if (last_slash_index == 0)
98 appid = string(appid_buf);
100 appid = string(&appid_buf[last_slash_index + 1]);
103 LOGI("appid(%s)", appid.c_str());
108 static string pkgid = "";
109 if (!pkgid.empty()) {
110 LOGI("pkgid(%s)", pkgid.c_str());
114 char pkgid_buf[MAX_PACKAGE_STR_SIZE] = {0, };
115 int ret = aul_app_get_pkgid_bypid(getpid(), pkgid_buf, sizeof(pkgid_buf));
117 pkgid = string(pkgid_buf);
122 string GetDomainName() {
123 static string domain_str = "";
124 if (!domain_str.empty()) {
125 LOGI("domain(%s)", domain_str.c_str());
129 string pkgid = GetPkgId();
133 string::size_type pos = pkgid.rfind('.');
134 if (pos != string::npos)
139 domain_str = pkgid.substr(pos);
143 string GetLocaleDirectory() {
144 string pkgid = GetPkgId();
148 static string locale_directory = "";
149 if (!locale_directory.empty()) {
150 LOGI("locale_directory(%s)", locale_directory.c_str());
151 return locale_directory;
154 package_info_h package_info;
155 int err = package_info_create(pkgid.c_str(), &package_info);
156 if (err != PACKAGE_MANAGER_ERROR_NONE) {
157 LOGE("fail to get package info");
160 unique_ptr<package_info_s, decltype(package_info_destroy)*> pkg_ptr(
161 package_info, package_info_destroy);
164 err = package_info_get_root_path(pkg_ptr.get(), &app_root_path);
165 if (err != PACKAGE_MANAGER_ERROR_NONE) {
166 LOGE("Failed to get root path err[%d] path[%p]",
171 string app_root_str(app_root_path);
174 locale_directory = app_root_str + string("/res/locale");
175 return locale_directory;
179 } // namespace notification