Retrieve privileges when getting appcontrol 44/318744/3
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 8 Oct 2024 00:50:40 +0000 (09:50 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 8 Oct 2024 05:33:27 +0000 (14:33 +0900)
API added for getting appcontrol information from appinfo handle

 pkgmgrinfo_appinfo_foreach_appcontrol_v3
 pkgmgrinfo_appinfo_foreach_remote_appcontrol_v3
 pkgmgrinfo_appinfo_appcontrol_get_operation
 pkgmgrinfo_appinfo_appcontrol_get_uri
 pkgmgrinfo_appinfo_appcontrol_get_mime
 pkgmgrinfo_appinfo_appcontrol_get_id
 pkgmgrinfo_appinfo_appcontrol_foreach_privilege

Change-Id: Ic7e8be59aa2bcf2d72bf970d38e4a12b178ef6e8
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
include/pkgmgr-info.h
include/pkgmgrinfo_type.h
src/pkgmgrinfo_appinfo.c
src/server/appinfo_internal.cc

index d0eea1a56fe7f1ee7409a6326ab9c777d0cc78de..59b184372d4a70ea34f79bf6ea625600dfe99d3e 100644 (file)
@@ -7260,6 +7260,328 @@ static int get_pkg_archive_dependency(const char *path, pkgmgrinfo_pkg_dependenc
 int pkgmgrinfo_archiveinfo_foreach_dependency(pkgmgrinfo_archiveinfo_h handle,
                pkgmgrinfo_pkg_dependency_list_cb callback, void *user_data);
 
+/**
+ * @fn int pkgmgrinfo_appinfo_foreach_appcontrol_v3(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_control_list_cb_v3 appcontrol_func, void *user_data);
+ * @fn int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v3(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_control_list_cb_v3 appcontrol_func, void *user_data);
+ * @brief      This API gets the list of app-control for a particular application
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ * @param[in]  handle          pointer to the application info handle.
+ * @param[in]  appcontrol_func callback function for list
+ * @param[in]   user_data      user data to be passed to callback function
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ERROR  internal error
+ * @pre                pkgmgrinfo_appinfo_get_appinfo()
+ * @post       pkgmgrinfo_appinfo_destroy_appinfo()
+ * @code
+static int appcontrol_cb(pkgmgrinfo_appinfo_app_control_h app_control, void *user_data)
+{
+       int* counts = (int*)user_data;
+       (*counts)++;
+
+       return 0;
+}
+
+static int list_appcontrol_info(const char *appid)
+{
+       int ret = 0;
+       int counts = 0;
+       pkgmgrinfo_appinfo_h handle;
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_appinfo_foreach_appcontrol_v3(handle, appcontrol_cb, &counts);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       printf("appcontrol counts : %d\n", counts);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_appinfo_foreach_appcontrol_v3(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_control_list_cb_v3 appcontrol_func,
+               void *user_data);
+int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v3(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_control_list_cb_v3 appcontrol_func,
+               void *user_data);
+
+/**
+ * @fn int pkgmgrinfo_appinfo_appcontrol_get_operation(
+ *             pkgmgrinfo_appinfo_app_control_h handle,
+ *             const char **operation)
+ * @brief      This API gets the operation of app-control
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in] handle           pointer to the app control handle.
+ * @param[out] operation       pointer to hold operation
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ENOENT no valid data
+ * @pre                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @post       None
+ * @see                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @code
+static int appcontrol_cb(pkgmgrinfo_appinfo_app_control_h app_control, void *user_data)
+{
+       int ret = 0;
+       const char* operation = NULL;
+       ret = pkgmgrinfo_appinfo_appcontrol_get_operation(app_control, &operation);
+       if (ret == PMINFO_R_OK) {
+               printf("operation : %s\n", operation);
+       }
+
+       return 0;
+}
+
+static int list_appcontrol_info(const char *appid)
+{
+       int ret = 0;
+       pkgmgrinfo_appinfo_h handle;
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_appinfo_foreach_appcontrol_v3(handle, appcontrol_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_appinfo_appcontrol_get_operation(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               const char **operation);
+
+/**
+ * @fn int pkgmgrinfo_appinfo_appcontrol_get_uri(
+ *             pkgmgrinfo_appinfo_app_control_h handle,
+ *             const char **uri)
+ * @brief      This API gets the uri of app-control
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in] handle           pointer to the app control handle.
+ * @param[out] uri             pointer to hold uri
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ENOENT no valid data
+ * @pre                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @post       None
+ * @see                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @code
+static int appcontrol_cb(pkgmgrinfo_appinfo_app_control_h app_control, void *user_data)
+{
+       int ret = 0;
+       const char* uri = NULL;
+       ret = pkgmgrinfo_appinfo_appcontrol_get_uri(app_control, &uri);
+       if (ret == PMINFO_R_OK) {
+               printf("uri : %s\n", uri);
+       }
+
+       return 0;
+}
+
+static int list_appcontrol_info(const char *appid)
+{
+       int ret = 0;
+       pkgmgrinfo_appinfo_h handle;
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_appinfo_foreach_appcontrol_v3(handle, appcontrol_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_appinfo_appcontrol_get_uri(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               const char **uri);
+
+/**
+ * @fn int pkgmgrinfo_appinfo_appcontrol_get_mime(
+ *             pkgmgrinfo_appinfo_app_control_h handle,
+ *             const char **mime)
+ * @brief      This API gets the mime of app-control
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in] handle           pointer to the app control handle.
+ * @param[out] mime            pointer to hold mime
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ENOENT no valid data
+ * @pre                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @post       None
+ * @see                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @code
+static int appcontrol_cb(pkgmgrinfo_appinfo_app_control_h app_control, void *user_data)
+{
+       int ret = 0;
+       const char* mime = NULL;
+       ret = pkgmgrinfo_appinfo_appcontrol_get_mime(app_control, &mime);
+       if (ret == PMINFO_R_OK) {
+               printf("mime : %s\n", mime);
+       }
+
+       return 0;
+}
+
+static int list_appcontrol_info(const char *appid)
+{
+       int ret = 0;
+       pkgmgrinfo_appinfo_h handle;
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_appinfo_foreach_appcontrol_v3(handle, appcontrol_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_appinfo_appcontrol_get_mime(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               const char **mime);
+
+/**
+ * @fn int pkgmgrinfo_appinfo_appcontrol_get_id(
+ *             pkgmgrinfo_appinfo_app_control_h handle,
+ *             const char **id)
+ * @brief      This API gets the id of app-control
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in] handle           pointer to the app control handle.
+ * @param[out] id              pointer to hold id
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ENOENT no valid data
+ * @pre                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @post       None
+ * @see                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @code
+static int appcontrol_cb(pkgmgrinfo_appinfo_app_control_h app_control, void *user_data)
+{
+       int ret = 0;
+       const char* id = NULL;
+       ret = pkgmgrinfo_appinfo_appcontrol_get_id(app_control, &id);
+       if (ret == PMINFO_R_OK) {
+               printf("id : %s\n", id);
+       }
+
+       return 0;
+}
+
+static int list_appcontrol_info(const char *appid)
+{
+       int ret = 0;
+       pkgmgrinfo_appinfo_h handle;
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_appinfo_foreach_appcontrol_v3(handle, appcontrol_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_appinfo_appcontrol_get_id(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               const char **id);
+
+
+/**
+ * @fn int pkgmgrinfo_appinfo_appcontrol_foreach_privilege(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+               void *user_data)
+ * @brief      This API gets the id of app-control
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in] handle           pointer to the app control handle.
+ * @param[in] privilege_func   callback function for list
+ * @param[in] user_data                user data to be passed to callback function
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @pre                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @post       None
+ * @see                pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ * @code
+static int appcontrol_privilege_cb(const char *privilege_name, void *user_data)
+{
+       printf("privilege : %s\n", privilege_name);
+
+       return 0;
+}
+
+static int appcontrol_cb(pkgmgrinfo_appinfo_app_control_h app_control, void *user_data)
+{
+       int ret = 0;
+       ret = pkgmgrinfo_appinfo_appcontrol_foreach_privilege(app_control, appcontrol_privilege_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               printf("Failed to get appcontrol's privilege\n");
+       }
+
+       return 0;
+}
+
+static int list_appcontrol_info(const char *appid)
+{
+       int ret = 0;
+       pkgmgrinfo_appinfo_h handle;
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_appinfo_foreach_appcontrol_v3(handle, appcontrol_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_appinfo_appcontrol_foreach_privilege(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+               void *user_data);
+
 /**
  * @pkgmgrinfo client API end
 **/
index 7f83f1645897fc17c39800cb2017230a8777dfb4..4710ff1b94f3aafa9a698d5401fec2b3354a2525 100644 (file)
@@ -232,6 +232,11 @@ typedef void *pkgmgrinfo_archiveinfo_h;
  */
 typedef void *required_privilege_h;
 
+/**
+ * @brief A handle to get app control information
+ */
+typedef void *pkgmgrinfo_appinfo_app_control_h;
+
 /**
  * @brief type definition.
  */
@@ -455,6 +460,21 @@ typedef int (*pkgmgrinfo_app_control_list_cb) (const char *operation, const char
 typedef int (*pkgmgrinfo_app_control_list_cb_v2) (const char *operation,
                const char *uri, const char *mime, const char *id,
                void *user_data);
+/**
+ * @fn int (*pkgmgrinfo_app_control_list_cb_v3) (pkgmgrinfo_appinfo_app_control_h app_control, void *user_data)
+ *
+ * @brief Specifies the type of function passed to pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ *
+ * @param[in] app_control The handle of the app-control
+ * @param[in] user_data   The user data passed from pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ *
+ * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative.\n
+ *
+ * @see  pkgmgrinfo_appinfo_foreach_appcontrol_v3()
+ */
+typedef int (*pkgmgrinfo_app_control_list_cb_v3) (
+               pkgmgrinfo_appinfo_app_control_h app_control,
+               void *user_data);
 
 /**
  * @fn int (*pkgmgrinfo_app_background_category_list_cb) (const char *category_name, void *user_data)
index 8ea2611e1ddde83155266a4cb947272379937c02..464d2f5e114f089626dc5b097c1046a754edd668 100644 (file)
@@ -2812,3 +2812,153 @@ API int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2(
 
        return PMINFO_R_OK;
 }
+
+API int pkgmgrinfo_appinfo_foreach_appcontrol_v3(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_control_list_cb_v3 appcontrol_func,
+               void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(appcontrol_func == NULL,
+                       PMINFO_R_EINVAL, "Callback function is NULL");
+       int ret;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       appcontrol_x *appcontrol;
+       GList *tmp;
+
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
+               appcontrol = (appcontrol_x *)tmp->data;
+               if (appcontrol == NULL ||
+                               !strcasecmp(appcontrol->visibility,
+                                               "remote-only"))
+                       continue;
+               ret = appcontrol_func(appcontrol, user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v3(
+               pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_control_list_cb_v3 appcontrol_func,
+               void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(appcontrol_func == NULL,
+                       PMINFO_R_EINVAL, "Callback function is NULL");
+       int ret;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       appcontrol_x *appcontrol;
+       GList *tmp;
+
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
+               appcontrol = (appcontrol_x *)tmp->data;
+               if (appcontrol == NULL ||
+                               !strcasecmp(appcontrol->visibility,
+                                               "local-only"))
+                       continue;
+               ret = appcontrol_func(appcontrol, user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_appcontrol_get_operation(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               const char **operation) {
+       appcontrol_x *app_control = (appcontrol_x *)handle;
+
+       if (app_control == NULL || operation == NULL) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (app_control->operation == NULL)
+               return PMINFO_R_ENOENT;
+       *operation = app_control->operation;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_appcontrol_get_uri(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               const char **uri) {
+       appcontrol_x *app_control = (appcontrol_x *)handle;
+
+       if (app_control == NULL || uri == NULL) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (app_control->uri == NULL)
+               return PMINFO_R_ENOENT;
+       *uri = app_control->uri;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_appcontrol_get_mime(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               const char **mime) {
+       appcontrol_x *app_control = (appcontrol_x *)handle;
+
+       if (app_control == NULL || mime == NULL) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (app_control->mime == NULL)
+               return PMINFO_R_ENOENT;
+       *mime = app_control->mime;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_appcontrol_get_id(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               const char **id) {
+       appcontrol_x *app_control = (appcontrol_x *)handle;
+
+       if (app_control == NULL || id == NULL) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (app_control->id == NULL)
+               return PMINFO_R_ENOENT;
+       *id = app_control->id;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_appcontrol_foreach_privilege(
+               pkgmgrinfo_appinfo_app_control_h handle,
+               pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+               void *user_data) {
+       int ret;
+       GList *tmp_list;
+       appcontrol_x *app_control = (appcontrol_x *)handle;
+
+       if (app_control == NULL || privilege_func == NULL) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       for (tmp_list = app_control->privileges; tmp_list != NULL;
+                       tmp_list = g_list_next(tmp_list)) {
+               ret = privilege_func((char *)tmp_list->data, user_data);
+               if (ret != 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}
index c44508b476b5d8047007fd5a863b72086e0e756e..429816cb6da55f7e6d7e6c24766e131f9816fea4 100644 (file)
@@ -44,45 +44,6 @@ char* GetCString(int idx, const tizen_base::Database::Result::Record& rec) {
   return strdup(str->c_str());
 }
 
-void ParseAppControl(GList** appcontrol,
-    const char* appcontrol_str, const char* visibility, const char* id) {
-  char* dup;
-  char* token;
-  char* ptr = nullptr;
-  appcontrol_x* ac;
-
-  if (appcontrol_str == nullptr)
-    return;
-
-  dup = strdup(appcontrol_str);
-  if (dup == nullptr) {
-    _LOGE("out of memory");
-    return;
-  }
-
-  do {
-    ac = static_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
-    if (ac == nullptr) {
-      _LOGE("out of memory");
-      break;
-    }
-    token = strtok_r(dup, "|", &ptr);
-    if (token && strcmp(token, "NULL"))
-      ac->operation = strdup(token);
-    token = strtok_r(nullptr, "|", &ptr);
-    if (token && strcmp(token, "NULL"))
-      ac->uri = strdup(token);
-    token = strtok_r(nullptr, "|", &ptr);
-    if (token && strcmp(token, "NULL"))
-      ac->mime = strdup(token);
-    ac->visibility = strdup(visibility);
-    ac->id = strdup(id);
-    *appcontrol = g_list_prepend(*appcontrol, ac);
-  } while ((token = strtok_r(nullptr, ";", &ptr)));
-
-  free(dup);
-}
-
 int GetSplashScreens(const tizen_base::Database& db,
     const char* appid, GList** splashscreens) {
   auto q = std::move(tizen_base::Database::Sql(
@@ -148,6 +109,72 @@ int GetMetadata(const tizen_base::Database& db,
   return PMINFO_R_OK;
 }
 
+GList* GetAppControlPrivileges(const tizen_base::Database& db,
+    const char* app_id, const char* app_control) {
+  auto q = std::move(tizen_base::Database::Sql(
+      "SELECT privilege "
+      "FROM package_app_app_control_privilege "
+      "WHERE app_id=? AND app_control=?")
+      .Bind(app_id)
+      .Bind(app_control));
+
+  auto r = db.Exec(q);
+  if (!r) {
+    _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
+    return nullptr;
+  }
+
+  GList* privileges = nullptr;
+  for (const auto& rec : r) {
+    char* val = GetCString(0, rec);
+    if (val)
+      privileges = g_list_prepend(privileges, (gpointer)val);
+  }
+
+  return privileges;
+}
+
+void ParseAppControl(const tizen_base::Database& db, GList** appcontrol,
+    const char* appcontrol_str, const char* visibility,
+    const char* id, const char* appid) {
+  char* dup;
+  char* token;
+  char* ptr = nullptr;
+  appcontrol_x* ac;
+
+  if (appcontrol_str == nullptr)
+    return;
+
+  dup = strdup(appcontrol_str);
+  if (dup == nullptr) {
+    _LOGE("out of memory");
+    return;
+  }
+
+  do {
+    ac = static_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
+    if (ac == nullptr) {
+      _LOGE("out of memory");
+      break;
+    }
+    token = strtok_r(dup, "|", &ptr);
+    if (token && strcmp(token, "NULL"))
+      ac->operation = strdup(token);
+    token = strtok_r(nullptr, "|", &ptr);
+    if (token && strcmp(token, "NULL"))
+      ac->uri = strdup(token);
+    token = strtok_r(nullptr, "|", &ptr);
+    if (token && strcmp(token, "NULL"))
+      ac->mime = strdup(token);
+    ac->visibility = strdup(visibility);
+    ac->id = strdup(id);
+    ac->privileges = GetAppControlPrivileges(db, appid, appcontrol_str);
+    *appcontrol = g_list_prepend(*appcontrol, ac);
+  } while ((token = strtok_r(nullptr, ";", &ptr)));
+
+  free(dup);
+}
+
 int GetAppControl(const tizen_base::Database& db,
     const char* appid, GList** appcontrol) {
   auto q = std::move(tizen_base::Database::Sql(
@@ -162,8 +189,8 @@ int GetAppControl(const tizen_base::Database& db,
   }
 
   for (const auto& rec : r) {
-    ParseAppControl(appcontrol, rec.GetString(0)->c_str(),
-        rec.GetString(1)->c_str(), rec.GetString(2)->c_str());
+    ParseAppControl(db, appcontrol, rec.GetString(0)->c_str(),
+        rec.GetString(1)->c_str(), rec.GetString(2)->c_str(), appid);
   }
 
   return PMINFO_R_OK;