From: Piotr Kosko Date: Fri, 15 May 2015 10:18:56 +0000 (+0200) Subject: [Badge] Removed package API calls X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a47d72481b1b6e32fe79afb957963b12698f5b5;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Badge] Removed package API calls [Feature] Removed usage of pakage API, badge API supports checking if application is installed on device. [Verification] Code compiles without errors. Passrate of TCTs increased to 96.15% Change-Id: Icb55cd464ad09a2485b3d5f3ee51b693339093ba Signed-off-by: Piotr Kosko --- diff --git a/src/badge/badge.gyp b/src/badge/badge.gyp index da96e285..7fc986e4 100644 --- a/src/badge/badge.gyp +++ b/src/badge/badge.gyp @@ -24,7 +24,6 @@ 'packages': [ 'aul', 'badge', - 'capi-appfw-package-manager', 'vconf', ] }, diff --git a/src/badge/badge_manager.cc b/src/badge/badge_manager.cc index b10dcb14..2f014214 100644 --- a/src/badge/badge_manager.cc +++ b/src/badge/badge_manager.cc @@ -8,8 +8,6 @@ #include #include #include -#include -#include #include #include "badge/badge_instance.h" @@ -40,52 +38,21 @@ BadgeManager::~BadgeManager() { PlatformResult BadgeManager::SetBadgeCount(const std::string& app_id, unsigned int count) { + LoggerD("Entered"); + LoggerD("app_id : %s ", app_id.c_str()); int ret = BADGE_ERROR_SERVICE_NOT_READY; bool badge_exist = false; const char *app_id_str = app_id.c_str(); - if (!IsAppInstalled(app_id)) { - LoggerE("fail to get pkgId"); - return PlatformResult(ErrorCode::INVALID_VALUES_ERR, - "InvalidValues error : app_id"); - } - - ret = badge_is_existing(app_id_str, &badge_exist); - if (ret != BADGE_ERROR_NONE) { - LoggerE("Unknown error : %d", ret); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"); - } - - if (!badge_exist) { - PlatformResult status = CheckPermisionForCreatingBadge(app_id_str); - if (status.IsError()) return status; - - ret = badge_create(app_id_str, app_id_str); - LoggerD("badge create : %", ret); - - if (ret == BADGE_ERROR_PERMISSION_DENIED) { - LoggerE("Security error"); - return PlatformResult(ErrorCode::SECURITY_ERR, "Security error"); -#ifdef PROFILE_WEARABLE - } else if (ret == BADGE_ERROR_INVALID_DATA) { -#else - } else if (ret == BADGE_ERROR_INVALID_PARAMETER) { -#endif - LoggerE("Invalid values error"); - return PlatformResult(ErrorCode::INVALID_VALUES_ERR, - "Invalid values error"); - } else if (ret != BADGE_ERROR_NONE && ret != BADGE_ERROR_ALREADY_EXIST) { - LoggerE("Unknown error"); - return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Unknown error"); - } - } - ret = badge_set_count(app_id_str, count); LoggerE("set ret : %d count :%d ", ret, count); if (ret == BADGE_ERROR_PERMISSION_DENIED) { LoggerE("Security error"); return PlatformResult(ErrorCode::SECURITY_ERR, "Security error"); + } else if (ret == BADGE_ERROR_NOT_EXIST) { + LoggerE("Application is not installed"); + return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Application is not installed"); #ifdef PROFILE_WEARABLE } else if (ret == BADGE_ERROR_INVALID_DATA) { #else @@ -104,38 +71,28 @@ PlatformResult BadgeManager::SetBadgeCount(const std::string& app_id, PlatformResult BadgeManager::GetBadgeCount(const std::string& app_id, unsigned int *count) { + LoggerD("Entered"); + LoggerD("app_id %s" , app_id.c_str()); assert(count); int ret = BADGE_ERROR_SERVICE_NOT_READY; bool badge_exist = false; - if (!IsAppInstalled(app_id)) { - LoggerE("fail to get pkgId"); - return PlatformResult(ErrorCode::INVALID_VALUES_ERR, - "InvalidValues error : app_id"); - } - ret = badge_is_existing(app_id.c_str(), &badge_exist); - if (ret != BADGE_ERROR_NONE) { - LoggerE("Unknown error : %d", ret); - return PlatformResult(ErrorCode::UNKNOWN_ERR, - "Platform error while checking badge."); - } - LoggerD("badge exist : %d", badge_exist); - - if (!badge_exist) { - return PlatformResult(ErrorCode::UNKNOWN_ERR, - "badge not exist. app_id: " + app_id); - } *count = 0; ret = badge_get_count(app_id.c_str(), count); + LoggerE("get ret : %d count :%d ", ret, count); + switch (ret) { case BADGE_ERROR_NONE: - LoggerD("success get ret : %d count : ", *count); + LoggerD("success get ret : %d count : %d", *count); return PlatformResult(ErrorCode::NO_ERROR); case BADGE_ERROR_PERMISSION_DENIED: LoggerE("Security error"); return PlatformResult(ErrorCode::SECURITY_ERR, "Security error."); + case BADGE_ERROR_NOT_EXIST: + LoggerE("Application is not installed"); + return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Application is not installed"); #ifdef PROFILE_WEARABLE case BADGE_ERROR_INVALID_DATA: #else @@ -202,172 +159,5 @@ void BadgeManager::badge_changed_cb(unsigned int action, const char *pkgname, } } -bool BadgeManager::IsAppInstalled(const std::string &app_id) { - int ret = PACKAGE_MANAGER_ERROR_NONE; - pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo; - if (app_id.empty()) { - return false; - } - ret = pkgmgrinfo_appinfo_get_appinfo(app_id.c_str(), &pkgmgrinfo_appinfo); - if (ret != PMINFO_R_OK) { - return false; - } - return true; -} - -PlatformResult BadgeManager::CheckPermisionForCreatingBadge( - const char *app_id) { - if (!app_id) { - LoggerE("InvalidValues error : app_id"); - return PlatformResult(ErrorCode::INVALID_VALUES_ERR, - "InvalidValues error : app_id"); - } - - char *caller_appid = NULL; - caller_appid = GetPkgnameByPid(); - - if (!caller_appid) { - LoggerE("fail to get caller pkgId"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, - "Platform error while getting caller pkgId."); - } - - char *caller_pkgname = NULL; - caller_pkgname = GetPkgnameByAppid(caller_appid); - if (!caller_pkgname) { - if (caller_appid) { - free(caller_appid); - } - LoggerE("fail to get caller pkgId"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, - "Platform error while getting caller pkgId."); - } - - char *pkgname = NULL; - pkgname = GetPkgnameByAppid(app_id); - if (!pkgname) { - if (caller_appid) { - free(caller_appid); - } - if (caller_pkgname) { - free(caller_pkgname); - } - LoggerE("fail to get pkgId"); - return PlatformResult(ErrorCode::INVALID_VALUES_ERR, - "InvalidValues error : app_id"); - } - - bool flag = true; - if (IsSameCertInfo(caller_pkgname, pkgname) != 1) { - LoggerE("The author signature is not match"); - flag = false; - } - - if (caller_appid) { - free(caller_appid); - } - if (caller_pkgname) { - free(caller_pkgname); - } - if (pkgname) { - free(pkgname); - } - - if (!flag) { - LoggerE("Security error - cannot create badge"); - return PlatformResult(ErrorCode::SECURITY_ERR, - "Security error - cannot create badge"); - } - - return PlatformResult(ErrorCode::NO_ERROR); -} - -char *BadgeManager::GetPkgnameByAppid(const char *app_id) { - char *pkg_id = NULL; - int ret = PACKAGE_MANAGER_ERROR_NONE; - if (!app_id) { - LoggerE("app_id is null"); - return NULL; - } - - ret = package_manager_get_package_id_by_app_id(app_id, &pkg_id); - if (ret != PACKAGE_MANAGER_ERROR_NONE) { - LoggerE("fail to get caller pkg_id : ", ret); - return NULL; - } - if (!pkg_id) { - LoggerE("fail to get caller pkg_id"); - return NULL; - } - - return pkg_id; -} - -char *BadgeManager::GetPkgnameByPid() { - char *pkgname = NULL; - int pid = 0; - int ret = AUL_R_OK; - int fd = 0; - long max = 4096; - - pid = getpid(); - pkgname = static_cast(malloc(max)); - if (!pkgname) { - LoggerE("fail to alloc memory"); - return NULL; - } - memset(pkgname, 0x00, max); - - ret = aul_app_get_pkgname_bypid(pid, pkgname, max); - if (ret != AUL_R_OK) { - fd = open("/proc/self/cmdline", O_RDONLY); - if (fd < 0) { - free(pkgname); - return NULL; - } - - ret = read(fd, pkgname, max - 1); - if (ret <= 0) { - close(fd); - free(pkgname); - return NULL; - } - - close(fd); - } - - if (pkgname[0] == '\0') { - free(pkgname); - return NULL; - } else - return pkgname; -} - -int BadgeManager::IsSameCertInfo(const char *caller, const char *pkgname) { - int ret = PACKAGE_MANAGER_ERROR_NONE; - package_manager_compare_result_type_e compare_result = - PACKAGE_MANAGER_COMPARE_MISMATCH; - - if (!caller) { - return 0; - } - if (!pkgname) { - return 0; - } - - LoggerE("pkgname : %d caller : ", pkgname, caller); - - ret = package_manager_compare_package_cert_info(pkgname, caller, - &compare_result); - - LoggerE("result : %d %d", ret, compare_result); - if (ret == PACKAGE_MANAGER_ERROR_NONE && - compare_result == PACKAGE_MANAGER_COMPARE_MATCH) { - return 1; - } - - return 0; -} - } // namespace badge } // namespace extension diff --git a/src/badge/badge_manager.h b/src/badge/badge_manager.h index 19f64882..912225ad 100644 --- a/src/badge/badge_manager.h +++ b/src/badge/badge_manager.h @@ -36,12 +36,6 @@ class BadgeManager { static void badge_changed_cb(unsigned int, const char*, unsigned int, void*); private: - common::PlatformResult CheckPermisionForCreatingBadge(const char* app_id); - char* GetPkgnameByAppid(const char* app_id); - char* GetPkgnameByPid(); - int IsSameCertInfo(const char* caller, const char* pkgname); - bool IsAppInstalled(const std::string& app_id); - BadgeInstance& instance_; bool is_cb_registered_;