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.
25 #include "notification-ex/ex_util.h"
31 #define LOG_TAG "NOTIFICATION_EX"
32 #define MAX_PACKAGE_STR_SIZE 512
35 namespace notification {
37 GQuark GetQuarkFromString(string str) {
38 return g_quark_from_string(str.c_str());
41 std::string GetQuarkToString(GQuark quark) {
42 return g_quark_to_string(quark);
46 static string appid = "";
47 char appid_buf[MAX_PACKAGE_STR_SIZE] = {0, };
50 LOGI("appid(%s)", appid.c_str());
55 int ret = aul_app_get_appid_bypid(pid, appid_buf, sizeof(appid_buf));
56 if (ret == AUL_R_OK) {
57 appid = string(appid_buf);
60 int last_slash_index = 0;
61 char proc_buf[MAX_PACKAGE_STR_SIZE] = { 0, };
63 snprintf(proc_buf, sizeof(proc_buf), "/proc/%d/cmdline", pid);
65 fd = open(proc_buf, O_RDONLY);
67 LOGE("Fail to get appid (%d)", errno);
71 ret = read(fd, appid_buf, sizeof(appid_buf) - 1);
73 LOGE("Fail to get appid (%d)", errno);
79 for (i = 0 ; i < ret ; i++) {
80 if (appid_buf[i] == '/')
84 if (last_slash_index == (ret - 1)) {
85 LOGE("Fail to get appid (%s)", appid_buf);
89 if (last_slash_index == 0)
90 appid = string(appid_buf);
92 appid = string(&appid_buf[last_slash_index + 1]);
95 LOGI("appid(%s)", appid.c_str());
99 } // namespace watchface_complication