[Common] Changed way of handling privileges for API versions
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 21 Apr 2016 07:30:54 +0000 (09:30 +0200)
committerLukasz Bardeli <l.bardeli@samsung.com>
Mon, 25 Apr 2016 12:37:24 +0000 (14:37 +0200)
[Feature] privilege_manager_get_mapped_privilege_list function is used to get
  proper mapping of privileges for application version and current platform.
  Such solution replaces hardcoded mapping for 3.0 in utils_api.js file.

[Verification] auto TCT's passrate didn't change.

Change-Id: If39de763d92a4489e56a824bd035ee5db1548df9
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
18 files changed:
packaging/webapi-plugins.spec
src/alarm/alarm_manager.cc
src/application/application_instance.cc
src/archive/archive_instance.cc
src/bookmark/bookmark_instance.cc
src/common/common.gyp
src/common/tools.cc
src/common/tools.h
src/datacontrol/datacontrol_instance.cc
src/filesystem/filesystem_instance.cc
src/messaging/messaging_instance.cc
src/networkbearerselection/networkbearerselection_instance.cc
src/nfc/nfc_instance.cc
src/package/package_instance.cc
src/power/power_instance.cc
src/systemsetting/systemsetting_instance.cc
src/utils/utils_api.js
src/utils/utils_instance.cc

index 51a0351eae7715868b31c30cea0521b2fa32e0c1..7c3f839d6c37c79bcf8d711323da811a55e2abca 100644 (file)
@@ -272,6 +272,7 @@ Source0:    %{name}-%{version}.tar.gz
 
 %endif # tizen_profile_tv
 
+BuildRequires: pkgconfig(security-privilege-manager)
 BuildRequires: ninja
 BuildRequires: pkgconfig(appcore-common)
 BuildRequires: pkgconfig(dlog)
index cd341041c8ec992123ddb47066da4aaf929dcc2e..5a66ba6f9fec1cba692d948c801e58cba9a73941 100755 (executable)
@@ -37,7 +37,7 @@ namespace alarm {
 
 namespace {
 const int kDateSize = 22; //"yyy mm dd hh mm ss dd" e.g 115 11 28 11 25 50 -1
-const std::string kPrivilegeAlarm = "http://tizen.org/privilege/alarm.get";
+const std::string kPrivilegeAlarm = "http://tizen.org/privilege/alarm";
 
 const std::string kAlarmRelative = "AlarmRelative";
 const std::string kAlarmAbsolute = "AlarmAbsolute";
index 3364901d54868b15ef9d514153f7037215d59038..67ff539d538debac1ecd87ff9f61ae14db343669 100755 (executable)
@@ -28,10 +28,10 @@ namespace application {
 
 namespace {
 // The privileges that are required in Application API
-const std::string kPrivilegeAppManagerCertificate = "http://tizen.org/privilege/notexist";
+const std::string kPrivilegeAppManagerCertificate = "http://tizen.org/privilege/appmanager.certificate";
 const std::string kPrivilegeAppManagerKill = "http://tizen.org/privilege/appmanager.kill";
-const std::string kPrivilegeApplicationInfo = "http://tizen.org/privilege/packagemanager.info";
-const std::string kPrivilegeApplicationLaunch = "http://tizen.org/privilege/appmanager.launch";
+const std::string kPrivilegeApplicationInfo = "http://tizen.org/privilege/application.info";
+const std::string kPrivilegeApplicationLaunch = "http://tizen.org/privilege/application.launch";
 }  // namespace
 
 using namespace common;
index 8cf1af7f3377b41ecaa559848c085dff3a102bab..ce6870338379a6266afc5eb62a61a54376922e18 100755 (executable)
@@ -38,8 +38,8 @@ using common::tools::ReportSuccess;
 using common::tools::ReportError;
 
 namespace {
-const std::string kPrivilegeFilesystemRead  = "http://tizen.org/privilege/systemsettings.admin";
-const std::string kPrivilegeFilesystemWrite  = "http://tizen.org/privilege/systemsettings.admin";
+const std::string kPrivilegeFilesystemRead  = "http://tizen.org/privilege/filesystem.read";
+const std::string kPrivilegeFilesystemWrite  = "http://tizen.org/privilege/filesystem.write";
 
 const std::string kArchiveFileEntryOptDest = "destination";
 const std::string kArchiveFileEntryOptStrip = "stripSourceDirectory";
index 14bd0340d218b3dd283957e19d9a5ad9d5c866de..7f8e4bd883616d9e42ca9b9340d9978319a66dfb 100755 (executable)
@@ -37,8 +37,8 @@ namespace {
   const char kParentId[] = "parentId";
   const char kUrl[] = "url";
 
-  const std::string kPrivilegeBookmarkRead = "http://tizen.org/privilege/bookmark.admin";
-  const std::string kPrivilegeBookmarkWrite = "http://tizen.org/privilege/bookmark.admin";
+  const std::string kPrivilegeBookmarkRead = "http://tizen.org/privilege/bookmark.read";
+  const std::string kPrivilegeBookmarkWrite = "http://tizen.org/privilege/bookmark.write";
 }  // namespace
 
 BookmarkInstance::BookmarkInstance() {
index f89186c4b01a6a6019779c9a71f534642cee14e0..a4e9414cbeaade6df1556e88e8270e19a65c8fe7 100644 (file)
@@ -74,6 +74,7 @@
               'capi-appfw-app-manager',
               'capi-appfw-package-manager',
               'storage',
+              'security-privilege-manager',
             ]
           },
           'conditions': [
index 9a8b8e0fee95fbc4109314adfb53e4de16ff5a2f..9b468847ca7450e1934fb50d4b4f3cb1dc0d9873 100644 (file)
 
 #include "common/tools.h"
 
+#include <privilegemgr/privilege_manager.h>
+#include <app_manager.h>
+#include <pkgmgr-info.h>
+
 #ifdef PRIVILEGE_USE_DB
 #include <sqlite3.h>
 #include "common/current_application.h"
@@ -253,20 +257,115 @@ class AccessControl {
 
 } // namespace
 
+
 PlatformResult CheckAccess(const std::string& privilege) {
   return CheckAccess(std::vector<std::string>{privilege});
 }
 
 PlatformResult CheckAccess(const std::vector<std::string>& privileges) {
   LoggerD("Enter");
-  if (AccessControl::GetInstance().CheckAccess(privileges)) {
-    return PlatformResult(ErrorCode::NO_ERROR);
-  } else {
-    for (const auto& privilege : privileges) {
-      LoggerD("Access to privilege: %s has been denied.", privilege.c_str());
+
+  std::string api_version;
+  PlatformResult res = common::tools::GetPkgApiVersion(&api_version);
+  if (res.IsError()) {
+    return res;
+  }
+  LoggerD("Application api version: %s", api_version.c_str());
+
+  for (auto input_priv : privileges) {
+    LoggerD("Input privilege: %s", input_priv.c_str());
+    GList *input_glist = nullptr;
+    GList *mapped_glist = nullptr;
+
+    SCOPE_EXIT {
+      g_list_free(input_glist);
+      g_list_free(mapped_glist);
+    };
+
+    input_glist = g_list_append(input_glist, (void*)input_priv.c_str());
+    int ret = privilege_manager_get_mapped_privilege_list(api_version.c_str(),
+                                                          PRVMGR_PACKAGE_TYPE_WRT,
+                                                          input_glist,
+                                                          &mapped_glist);
+    if (ret != PRVMGR_ERR_NONE) {
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get mapped privilege list");
+    }
+
+    LoggerD("Mapped privileges:");
+    std::vector<std::string> mapped_vector;
+    auto push_elem = [](gpointer data, gpointer user_data) -> void {
+      if (data && user_data) {
+        std::vector<std::string>* mapped_vector =
+            static_cast<std::vector<std::string>*>(user_data);
+        char* char_data = static_cast<char*>(data);
+        mapped_vector->push_back(char_data);
+        LoggerD("mapped to: %s", char_data);
+      }
+    };
+    g_list_foreach (mapped_glist, push_elem, &mapped_vector);
+
+    if (!AccessControl::GetInstance().CheckAccess(mapped_vector)){
+      for (const auto& mapped_priv : mapped_vector) {
+        LoggerD("Access to privilege: %s has been denied.", mapped_priv.c_str());
+      }
+      return PlatformResult(ErrorCode::SECURITY_ERR, "Permission denied");
+    }
+  }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult GetPkgApiVersion(std::string* api_version) {
+  LoggerD("Entered");
+
+  char* app_id = nullptr;
+  char* pkgid = nullptr;
+  char* api_ver = nullptr;
+  app_info_h app_handle = nullptr;
+  pkgmgrinfo_pkginfo_h pkginfo_handle = nullptr;
+
+  SCOPE_EXIT {
+    if (app_id) {
+      free(app_id);
     }
-    return PlatformResult(ErrorCode::SECURITY_ERR, "Permission denied");
+    if (pkgid) {
+      free(pkgid);
+    }
+    if (app_handle) {
+      app_info_destroy(app_handle);
+    }
+    if (pkginfo_handle) {
+      pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
+    }
+  };
+
+  pid_t pid = getpid();
+  int ret = app_manager_get_app_id(pid, &app_id);
+  if (ret != APP_MANAGER_ERROR_NONE) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get app id");
   }
+
+  ret = app_info_create(app_id, &app_handle);
+  if (ret != APP_MANAGER_ERROR_NONE) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get app info");
+  }
+
+  ret = app_info_get_package(app_handle, &pkgid);
+  if ((ret != APP_MANAGER_ERROR_NONE) || (pkgid == nullptr)) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get pkg id");
+  }
+
+  ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, getuid(), &pkginfo_handle);
+  if (ret != PMINFO_R_OK) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get pkginfo_h");
+  }
+
+  ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo_handle, &api_ver);
+  if (ret != PMINFO_R_OK) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get api version");
+  }
+
+  *api_version = api_ver;
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
 std::string GetErrorString(int error_code) {
index fcd986897abcce044d7b531192da2f52cad63783..c3df3a98405bf39e06f876bf8b27ff5402dccd3f 100644 (file)
@@ -35,6 +35,7 @@ void ReportError(const PlatformResult& error, picojson::object* out);
 
 common::PlatformResult CheckAccess(const std::string& privilege);
 common::PlatformResult CheckAccess(const std::vector<std::string>& privileges);
+common::PlatformResult GetPkgApiVersion(std::string* api_version);
 
 #define CHECK_PRIVILEGE_ACCESS(privilege, out) \
 do { \
index 7e71cebda416e3542a13e9962e27917143a78b44..cfb1521bc038de3491f4bafd00bd2962858a7ee1 100755 (executable)
@@ -37,7 +37,7 @@ namespace datacontrol {
 
 namespace {
 // The privileges that required in Datacontrol API
-const std::string kPrivilegeDatacontrol = "http://tizen.org/privilege/datasharing";
+const std::string kPrivilegeDatacontrol = "http://tizen.org/privilege/datacontrol.consumer";
 
 }  // namespace
 
index df1d003a66e2f9d6e688e9ea3c118784fd4e3f2e..54b0a2e17cc560f9b606512da2a6664e5c7ff4a1 100644 (file)
@@ -30,8 +30,8 @@ namespace filesystem {
 
 namespace {
 // The privileges that required in Filesystem API
-const std::string kPrivilegeFilesystemRead = "http://tizen.org/privilege/systemsettings.admin";
-const std::string kPrivilegeFilesystemWrite = "http://tizen.org/privilege/systemsettings.admin";
+const std::string kPrivilegeFilesystemRead = "http://tizen.org/privilege/filesystem.read";
+const std::string kPrivilegeFilesystemWrite = "http://tizen.org/privilege/filesystem.write";
 }
 
 using namespace common;
index 1b7d18c989791fc9c03b008e9482f26e389da5c0..cd656a7c311c16f1a95399277dfe40bf1dcbc1c8 100755 (executable)
@@ -120,8 +120,8 @@ auto getServiceIdFromJSON = [](picojson::object& data) -> int {
     }
 };
 
-const std::string kPrivilegeMessagingRead  = "http://tizen.org/privilege/message.read";
-const std::string kPrivilegeMessagingWrite = "http://tizen.org/privilege/message.write";
+const std::string kPrivilegeMessagingRead  = "http://tizen.org/privilege/messaging.read";
+const std::string kPrivilegeMessagingWrite = "http://tizen.org/privilege/messaging.write";
 
 const long kDumbCallbackId= -1;
 }
index 6e3921460f34ac3b913f65568e48688cd6f54764..809c83610b8f80ef7addacfe800b2ce1e632b52c 100644 (file)
@@ -29,7 +29,7 @@ namespace networkbearerselection {
 
 namespace {
 // The privileges that required in NetworkBearerSelection API
-const std::string kPrivilegeNetworkBearerSelection = "http://tizen.org/privilege/network.set";
+const std::string kPrivilegeNetworkBearerSelection = "http://tizen.org/privilege/networkbearerselection";
 const std::string kPrivilegeInternet = "http://tizen.org/privilege/internet";
 const std::vector<std::string> kNbsPrivileges{kPrivilegeNetworkBearerSelection, kPrivilegeInternet};
 
index f29a2984634ed3db16fb0101a7746a360be60be9..781f90e80f1317d1f2b0c06fee4b625450b523a5 100644 (file)
@@ -40,9 +40,9 @@ namespace {
 
 const std::string kPrivilegeNfcAdmin = "http://tizen.org/privilege/nfc.admin";
 const std::string kPrivilegeNfcCardEmulation = "http://tizen.org/privilege/nfc.cardemulation";
-const std::string kPrivilegeNfcCommon = "http://tizen.org/privilege/nfc";
-const std::string kPrivilegeNfcP2P = "http://tizen.org/privilege/nfc";
-const std::string kPrivilegeNfcTag = "http://tizen.org/privilege/nfc";
+const std::string kPrivilegeNfcCommon = "http://tizen.org/privilege/nfc.common";
+const std::string kPrivilegeNfcP2P = "http://tizen.org/privilege/nfc.p2p";
+const std::string kPrivilegeNfcTag = "http://tizen.org/privilege/nfc.tag";
 
 } // namespace
 
index d7b5f53b2608d742e8174972643997c935eccf8f..81250763ddd975d290a777a37bc260e8e8f006e5 100644 (file)
@@ -40,7 +40,7 @@ using common::PlatformResult;
 
 namespace {
 // The privileges that required in Package API
-const std::string kPrivilegePackageInstall = "http://tizen.org/privilege/packagemanager.admin";
+const std::string kPrivilegePackageInstall = "http://tizen.org/privilege/packagemanager.install";
 const std::string kPrivilegePackageInfo = "http://tizen.org/privilege/packagemanager.info";
 }  // namespace
 
index 6d7d2df7ce3a90922a16e2eeab300123db0cd927..a4b566ded4bf6cd3cbb4b2a74629ce6ebabb6ade 100755 (executable)
@@ -34,7 +34,7 @@ namespace power {
 
 namespace {
 // The privileges that required in Power API
-const std::string kPrivilegePower = "http://tizen.org/privilege/display";
+const std::string kPrivilegePower = "http://tizen.org/privilege/power";
 
 const std::map<std::string, PowerResource> kPowerResourceMap = {
     {"SCREEN", POWER_RESOURCE_SCREEN},
index c95fbcae3fe7400e2a11385c997941e5d8573195..55d6891d0c769799ba020d86646f8b6659d446c5 100644 (file)
@@ -36,7 +36,7 @@ const std::string SETTING_LOCK_SCREEN = "LOCK_SCREEN";
 const std::string SETTING_INCOMING_CALL = "INCOMING_CALL";
 const std::string SETTING_NOTIFICATION_EMAIL = "NOTIFICATION_EMAIL";
 
-const std::string kPrivilegeSetting = "http://tizen.org/privilege/systemsettings.admin";
+const std::string kPrivilegeSetting = "http://tizen.org/privilege/setting";
 }
 
 using namespace common;
index 038ecaefd39eb94b34589a052327191f05a49d02..76206062d85b02d1075fae7662f0844524139470 100644 (file)
@@ -72,18 +72,18 @@ function Utils() {
     ACCOUNT_READ: 'http://tizen.org/privilege/account.read',
     ACCOUNT_WRITE: 'http://tizen.org/privilege/account.write',
     ALARM: 'http://tizen.org/privilege/alarm.get',
-    APPLICATION_INFO: 'http://tizen.org/privilege/packagemanager.info',
-    APPLICATION_LAUNCH: 'http://tizen.org/privilege/appmanager.launch',
-    APPMANAGER_CERTIFICATE: 'http://tizen.org/privilege/notexist',
+    APPLICATION_INFO: 'http://tizen.org/privilege/application.info',
+    APPLICATION_LAUNCH: 'http://tizen.org/privilege/application.launch',
+    APPMANAGER_CERTIFICATE: 'http://tizen.org/privilege/appmanager.certificate',
     APPMANAGER_KILL: 'http://tizen.org/privilege/appmanager.kill',
-    BLUETOOTH_ADMIN: 'http://tizen.org/privilege/bluetooth',
-    BLUETOOTH_GAP: 'http://tizen.org/privilege/bluetooth',
-    BLUETOOTH_HEALTH: 'http://tizen.org/privilege/bluetooth',
-    BLUETOOTH_SPP: 'http://tizen.org/privilege/bluetooth',
-    BLUETOOTHMANAGER: 'http://tizen.org/privilege/bluetooth.admin',
+    BLUETOOTH_ADMIN: 'http://tizen.org/privilege/bluetooth.admin',
+    BLUETOOTH_GAP: 'http://tizen.org/privilege/bluetooth.gap',
+    BLUETOOTH_HEALTH: 'http://tizen.org/privilege/bluetooth.health',
+    BLUETOOTH_SPP: 'http://tizen.org/privilege/bluetooth.spp',
+    BLUETOOTHMANAGER: 'http://tizen.org/privilege/bluetoothmanager',
     BLUETOOTH: 'http://tizen.org/privilege/bluetooth',
-    BOOKMARK_READ: 'http://tizen.org/privilege/bookmark.admin',
-    BOOKMARK_WRITE: 'http://tizen.org/privilege/bookmark.admin',
+    BOOKMARK_READ: 'http://tizen.org/privilege/bookmark.read',
+    BOOKMARK_WRITE: 'http://tizen.org/privilege/bookmark.write',
     CALENDAR_READ: 'http://tizen.org/privilege/calendar.read',
     CALENDAR_WRITE: 'http://tizen.org/privilege/calendar.write',
     CALLHISTORY_READ: 'http://tizen.org/privilege/callhistory.read',
@@ -93,36 +93,38 @@ function Utils() {
     CONTENT_READ: 'http://tizen.org/privilege/content.write',
     CONTENT_WRITE: 'http://tizen.org/privilege/content.write',
     D2D_DATASHARING: 'http://tizen.org/privilege/d2d.datasharing',
-    DATACONTROL_CONSUMER: 'http://tizen.org/privilege/datasharing',
-    DATASYNC: 'http://tizen.org/privilege/notexist',
+    DATACONTROL_CONSUMER: 'http://tizen.org/privilege/datacontrol.consumer',
+    DATASYNC: 'http://tizen.org/privilege/datasync',
     DOWNLOAD: 'http://tizen.org/privilege/download',
-    FILESYSTEM_READ: 'http://tizen.org/privilege/systemsettings.admin',
-    FILESYSTEM_WRITE: 'http://tizen.org/privilege/systemsettings.admin',
+    FILESYSTEM_READ: 'http://tizen.org/privilege/filesystem.read',
+    FILESYSTEM_WRITE: 'http://tizen.org/privilege/filesystem.write',
     HEALTHINFO: 'http://tizen.org/privilege/healthinfo',
     INTERNET: 'http://tizen.org/privilege/internet',
     LED: 'http://tizen.org/privilege/led',
     LOCATION: 'http://tizen.org/privilege/location',
     MEDIACONTROLLER_SERVER: 'http://tizen.org/privilege/mediacontroller.server',
     MEDIACONTROLLER_CLIENT: 'http://tizen.org/privilege/mediacontroller.client',
-    MESSAGING_READ: 'http://tizen.org/privilege/message.read',
-    MESSAGING_WRITE: 'http://tizen.org/privilege/message.write',
-    NETWORKBEARERSELECTION: 'http://tizen.org/privilege/network.set',
+    MESSAGING_READ: 'http://tizen.org/privilege/messaging.read',
+    MESSAGING_WRITE: 'http://tizen.org/privilege/messaging.write',
+    NETWORKBEARERSELECTION: 'http://tizen.org/privilege/networkbearerselection',
     NFC_ADMIN: 'http://tizen.org/privilege/nfc.admin',
     NFC_CARDEMULATION: 'http://tizen.org/privilege/nfc.cardemulation',
-    NFC_COMMON: 'http://tizen.org/privilege/nfc',
-    NFC_P2P: 'http://tizen.org/privilege/nfc',
-    NFC_TAG: 'http://tizen.org/privilege/nfc',
+    NFC_COMMON: 'http://tizen.org/privilege/nfc.common',
+    NFC_P2P: 'http://tizen.org/privilege/nfc.p2p',
+    NFC_TAG: 'http://tizen.org/privilege/nfc.tag',
     NOTIFICATION: 'http://tizen.org/privilege/notification',
     PACKAGE_INFO: 'http://tizen.org/privilege/packagemanager.info',
-    PACKAGEMANAGER_INSTALL: 'http://tizen.org/privilege/packagemanager.admin',
-    POWER: 'http://tizen.org/privilege/display',
+    PACKAGEMANAGER_INSTALL: 'http://tizen.org/privilege/packagemanager.install',
+    POWER: 'http://tizen.org/privilege/power',
     PUSH: 'http://tizen.org/privilege/push',
     SECUREELEMENT: 'http://tizen.org/privilege/secureelement',
-    SETTING: 'http://tizen.org/privilege/systemsettings.admin',
-    SYSTEM: 'http://tizen.org/privilege/telephony',
-    SYSTEMMANAGER: 'http://tizen.org/privilege/telephony',
+    SETTING_ADMIN: 'http://tizen.org/privilege/systemsettings.admin',
+    SETTING: 'http://tizen.org/privilege/setting',
+    SYSTEM: 'http://tizen.org/privilege/system',
+    SYSTEMMANAGER: 'http://tizen.org/privilege/systemmanager',
     TELEPHONY: 'http://tizen.org/privilege/telephony',
-    VOLUME_SET: 'http://tizen.org/privilege/volume.set'
+    VOLUME_SET: 'http://tizen.org/privilege/volume.set',
+    WEBSETTING: 'http://tizen.org/privilege/websetting'
   };
 
   Object.freeze(privilege);
index 96a7e4ed1685515bc80eae40dad630455c8dc84d..be751eeb5e03ec087ea87ce60c1713f937e999fa 100644 (file)
@@ -6,8 +6,6 @@
 #include <sys/types.h>
 #include <utility>
 #include <unistd.h>
-#include <app_manager.h>
-#include <pkgmgr-info.h>
 
 #include "common/logger.h"
 #include "common/scope_exit.h"
@@ -44,63 +42,11 @@ UtilsInstance::UtilsInstance() {
 void UtilsInstance::GetPkgApiVersion(const picojson::value& args, picojson::object& out) {
   LoggerD("Entered");
 
-  char* app_id = nullptr;
-  char* pkgid = nullptr;
-  app_info_h app_handle = nullptr;
-  pkgmgrinfo_pkginfo_h pkginfo_handle = nullptr;
-  char *api_version = nullptr;
-
-  SCOPE_EXIT {
-    if (app_id) {
-      free(app_id);
-    }
-    if (pkgid) {
-      free(pkgid);
-    }
-    if (app_handle) {
-      app_info_destroy(app_handle);
-    }
-    if (pkginfo_handle) {
-      pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
-    }
-  };
-
-  pid_t pid = getpid();
-  int ret = app_manager_get_app_id(pid, &app_id);
-  if (ret != APP_MANAGER_ERROR_NONE) {
-    LoggerE("Failed to get app id");
-    ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get app id"), &out);
-    return;
-  }
-
-  ret = app_info_create(app_id, &app_handle);
-  if (ret != APP_MANAGER_ERROR_NONE) {
-    LoggerE("Fail to get app info");
-    ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Fail to get app info"), &out);
-    return;
+  std::string api_version;
+  PlatformResult ret = common::tools::GetPkgApiVersion(&api_version);
+  if (ret.IsError()) {
+    ReportError(ret, &out);
   }
-
-  ret = app_info_get_package(app_handle, &pkgid);
-  if ((ret != APP_MANAGER_ERROR_NONE) || (pkgid == nullptr)) {
-    LoggerE("Fail to get pkg id");
-    ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Fail to get pkg id"), &out);
-    return;
-  }
-
-  ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, getuid(), &pkginfo_handle);
-  if (ret != PMINFO_R_OK) {
-    LoggerE("Fail to get pkginfo_h");
-    ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Fail to get pkginfo_h"), &out);
-    return;
-  }
-
-  ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo_handle, &api_version);
-  if (ret != PMINFO_R_OK) {
-    LoggerE("Fail to get api version");
-    ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Fail to get api version"), &out);
-    return;
-  }
-
   ReportSuccess(picojson::value(api_version), out);
 }