+
+ ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
+ providerid, type, appid, is_trusted);
+ if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+ ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
+ providerid, type, appid, is_trusted);
+
+ /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
+ * implementation, return PMINFO_R_ERROR. This should be
+ * modified later...
+ */
+ if (ret == PMINFO_R_ENOENT) {
+ LOGE("no datacontrol trusted info of %s", providerid);
+ ret = PMINFO_R_ERROR;
+ }
+
+ return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
+ const char *type, char **appid, bool *is_trusted)
+{
+ return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
+ type, _getuid(), appid, is_trusted);
+}
+
+static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
+ const char *providerid, const char *type,
+ pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
+{
+ static const char query[] =
+ "SELECT privilege FROM package_app_data_control_privilege "
+ "WHERE providerid=? AND type=?";
+ int ret;
+ sqlite3_stmt *stmt;
+ int count = 0;
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("prepare failed: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+
+ ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
+ if (ret != SQLITE_OK) {
+ LOGE("bind failed: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+
+ ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
+ if (ret != SQLITE_OK) {
+ LOGE("bind failed: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ count++;
+ ret = callback((const char *)sqlite3_column_text(stmt, 0),
+ user_data);
+ if (ret < 0)
+ break;
+ }
+
+ sqlite3_finalize(stmt);
+
+ return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
+}
+
+static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
+ const char *providerid, const char *type,
+ pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
+{
+ int ret;
+ char *dbpath;
+ sqlite3 *db;
+
+ dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
+ if (dbpath == NULL)
+ return PMINFO_R_ERROR;
+
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
+ free(dbpath);
+ if (ret != SQLITE_OK) {
+ LOGE("open db failed: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+
+ ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
+ callback, user_data);
+ sqlite3_close_v2(db);
+
+ return ret;
+}
+
+API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
+ const char *providerid, const char *type,
+ pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+ void *user_data, uid_t uid)
+{
+ int ret;
+
+ if (providerid == NULL || type == NULL || privilege_func == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
+ providerid, type, privilege_func, user_data);
+ if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+ ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
+ providerid, type, privilege_func, user_data);
+
+ if (ret == PMINFO_R_ENOENT)
+ ret = PMINFO_R_OK;
+
+ return ret;
+}
+
+API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
+ const char *providerid, const char *type,
+ pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+ void *user_data)
+{
+ return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
+ providerid, type, privilege_func, user_data, _getuid());
+}
+
+API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
+{
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+ retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+
+ pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+ if (info->app_info->support_mode)
+ *support_mode = atoi(info->app_info->support_mode);
+ else
+ *support_mode = 0;
+