+API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
+{
+ pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+ if (handle == NULL || installed_time == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
+ return PMINFO_R_ERROR;
+
+ *installed_time = atoi(info->app_info->package_installed_time);
+
+ return PMINFO_R_OK;
+}
+
+static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
+ const char *type, char **appid, char **access)
+{
+ static const char query[] =
+ "SELECT app_id, access FROM package_app_data_control "
+ "WHERE providerid=? AND type=?";
+ int ret;
+ sqlite3_stmt *stmt;
+
+ 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;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ sqlite3_finalize(stmt);
+ if (ret == SQLITE_DONE) {
+ return PMINFO_R_ENOENT;
+ } else {
+ LOGE("step error: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ *appid = strdup((char *)sqlite3_column_text(stmt, 0));
+ if (*appid == NULL) {
+ LOGE("out of memory");
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+ *access = strdup((char *)sqlite3_column_text(stmt, 1));
+ if (*access == NULL) {
+ LOGE("out of memory");
+ free(*appid);
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+
+ sqlite3_finalize(stmt);
+
+ return PMINFO_R_OK;
+}
+
+static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
+ const char *providerid, const char *type,
+ char **appid, char **access)
+{
+ 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_get_datacontrol_info(db, providerid, type, appid,
+ access);
+ sqlite3_close_v2(db);
+
+ return ret;
+}
+
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
+ const char *type, uid_t uid, char **appid, char **access)
+{
+ int ret;
+
+ if (providerid == NULL || type == NULL || appid == NULL ||
+ access == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
+ type, appid, access);
+ if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+ ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
+ type, appid, access);
+
+ /* 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 info of %s", providerid);
+ ret = PMINFO_R_ERROR;
+ }
+
+ return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
+ const char *type, char **appid, char **access)
+{
+ return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
+ type, _getuid(), appid, access);
+}
+
+static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
+ char **appid)
+{
+ static const char query[] =
+ "SELECT app_id FROM package_app_data_control "
+ "WHERE providerid=?";
+ int ret;
+ sqlite3_stmt *stmt;
+
+ 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_step(stmt);
+ if (ret != SQLITE_ROW) {
+ sqlite3_finalize(stmt);
+ if (ret == SQLITE_DONE) {
+ return PMINFO_R_ENOENT;
+ } else {
+ LOGE("step error: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ *appid = strdup((char *)sqlite3_column_text(stmt, 0));
+
+ sqlite3_finalize(stmt);
+
+ if (*appid == NULL) {
+ LOGE("out of memory");
+ return PMINFO_R_ERROR;
+ }
+
+ return PMINFO_R_OK;
+}
+
+static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
+ const char *providerid, char **appid)
+{
+ 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_get_datacontrol_appid(db, providerid, appid);
+ sqlite3_close_v2(db);
+
+ return ret;
+}
+
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
+ uid_t uid, char **appid)
+{
+ int ret;
+
+ if (providerid == NULL || appid == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
+ appid);
+ if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+ ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
+ appid);
+
+ /* 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 appid of %s", providerid);
+ ret = PMINFO_R_ERROR;
+ }
+
+ return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
+{
+ return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
+}
+
+static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
+ const char *providerid, const char *type, char **appid,
+ bool *is_trusted)
+{
+ static const char query[] =
+ "SELECT app_id, trusted FROM package_app_data_control "
+ "WHERE providerid=? AND type=?";
+ int ret;
+ sqlite3_stmt *stmt;
+
+ 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;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ sqlite3_finalize(stmt);
+ if (ret == SQLITE_DONE) {
+ return PMINFO_R_ENOENT;
+ } else {
+ LOGE("step error: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ *appid = strdup((char *)sqlite3_column_text(stmt, 0));
+ *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
+
+ sqlite3_finalize(stmt);
+
+ if (*appid == NULL) {
+ LOGE("out of memory");
+ return PMINFO_R_ERROR;
+ }
+
+ return PMINFO_R_OK;
+}
+
+static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
+ const char *providerid, const char *type, char **appid,
+ bool *is_trusted)
+{
+ 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_get_datacontrol_trusted_info(db, providerid, type, appid,
+ is_trusted);
+ sqlite3_close_v2(db);
+
+ return ret;
+}
+
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
+ const char *providerid, const char *type, uid_t uid,
+ char **appid, bool *is_trusted)
+{
+ int ret;
+
+ if (providerid == NULL || type == NULL || appid == NULL ||
+ is_trusted == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ 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)