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
**/
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;
+}
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(
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(
}
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;