diff options
Diffstat (limited to 'notification-ex/ex_util.cc')
-rw-r--r-- | notification-ex/ex_util.cc | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/notification-ex/ex_util.cc b/notification-ex/ex_util.cc index dca6606..a7ddcaf 100644 --- a/notification-ex/ex_util.cc +++ b/notification-ex/ex_util.cc @@ -16,7 +16,6 @@ #include <dlog.h> #include <aul.h> -#include <aul.h> #include <fcntl.h> #include <unistd.h> @@ -34,66 +33,67 @@ using namespace std; namespace notification { namespace util { - GQuark GetQuarkFromString(string str) { - return g_quark_from_string(str.c_str()); - } +GQuark GetQuarkFromString(string str) { + return g_quark_from_string(str.c_str()); +} - std::string GetQuarkToString(GQuark quark) { - return g_quark_to_string(quark); - } +std::string GetQuarkToString(GQuark quark) { + return g_quark_to_string(quark); +} + +string GetAppId() { + static string appid = ""; + char appid_buf[MAX_PACKAGE_STR_SIZE] = {0, }; - string GetAppId() { - static string appid = ""; - char appid_buf[MAX_PACKAGE_STR_SIZE] = {0, }; + if (!appid.empty()) { + LOGI("appid(%s)", appid.c_str()); + return appid; + } - if (!appid.empty()) { - LOGI("appid(%s)", appid.c_str()); - return appid; + int pid = getpid(); + int ret = aul_app_get_appid_bypid(pid, appid_buf, sizeof(appid_buf)); + if (ret == AUL_R_OK) { + appid = string(appid_buf); + } else { + int fd, i; + int last_slash_index = 0; + char proc_buf[MAX_PACKAGE_STR_SIZE] = { 0, }; + + snprintf(proc_buf, sizeof(proc_buf), "/proc/%d/cmdline", pid); + + fd = open(proc_buf, O_RDONLY); + if (fd < 0) { + LOGE("Fail to get appid (%d)", errno); + return ""; } - int pid = getpid(); - int ret = aul_app_get_appid_bypid(pid, appid_buf, sizeof(appid_buf)); - if (ret == AUL_R_OK) { - appid = string(appid_buf); - } else { - int fd, i; - int last_slash_index = 0; - char proc_buf[MAX_PACKAGE_STR_SIZE] = { 0, }; - - snprintf(proc_buf, sizeof(proc_buf), "/proc/%d/cmdline", pid); - - fd = open(proc_buf, O_RDONLY); - if (fd < 0) { - LOGE("Fail to get appid (%d)", errno); - return ""; - } - - ret = read(fd, appid_buf, sizeof(appid_buf) - 1); - if (ret <= 0) { - LOGE("Fail to get appid (%d)", errno); - close(fd); - return ""; - } + ret = read(fd, appid_buf, sizeof(appid_buf) - 1); + if (ret <= 0) { + LOGE("Fail to get appid (%d)", errno); close(fd); + return ""; + } + close(fd); - for (i = 0 ; i < ret ; i++) { - if (appid_buf[i] == '/') - last_slash_index = i; - } - - if (last_slash_index == (ret - 1)) { - LOGE("Fail to get appid (%s)", appid_buf); - return ""; - } + for (i = 0 ; i < ret ; i++) { + if (appid_buf[i] == '/') + last_slash_index = i; + } - if (last_slash_index == 0) - appid = string(appid_buf); - else - appid = string(&appid_buf[last_slash_index + 1]); + if (last_slash_index == (ret - 1)) { + LOGE("Fail to get appid (%s)", appid_buf); + return ""; } - LOGI("appid(%s)", appid.c_str()); - return appid; + if (last_slash_index == 0) + appid = string(appid_buf); + else + appid = string(&appid_buf[last_slash_index + 1]); } + + LOGI("appid(%s)", appid.c_str()); + return appid; +} + } // namespace util } // namespace watchface_complication |