+int __pkginfo_check_installed_storage(package_x *pkginfo)
+{
+ char buf[MAX_QUERY_LEN] = {'\0'};
+ int ret;
+
+ retvm_if(pkginfo->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
+ retvm_if(pkginfo->installed_storage == NULL, PMINFO_R_ERROR,
+ "installed_storage is NULL\n");
+
+ if (strcmp(pkginfo->installed_storage, "installed_external") == 0) {
+ snprintf(buf, MAX_QUERY_LEN - 1, "%s", pkginfo->external_path);
+ ret = access(buf, R_OK);
+ if (ret != 0) {
+ _LOGE("can not access [%s] - %d", buf, ret);
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ return PMINFO_R_OK;
+}
+
+int __appinfo_check_installed_storage(application_x *appinfo)
+{
+ retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR,
+ "installed_storage is NULL\n");
+
+ if (strcmp(appinfo->installed_storage, "installed_external") == 0) {
+ retvm_if(appinfo->external_path == NULL, PMINFO_R_ERROR,
+ "external path is NULL\n");
+ if (access(appinfo->external_path, R_OK) != 0) {
+ _LOGE("can not access [%s]", appinfo->external_path);
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ return PMINFO_R_OK;
+}
+
+#define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
+#define BUSY_WAITING_MAX 20 /* wait for max 1 sec */
+static int __db_busy_handler(void *data, int count)
+{
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ } else {
+ /* sqlite3_prepare_v2 will return SQLITE_BUSY */
+ return 0;
+ }
+}
+
+int __open_db(const char *path, sqlite3 **db, int flags)
+{
+ int ret;
+
+ ret = sqlite3_open_v2(path, db, flags, NULL);
+ if (ret != SQLITE_OK)
+ return ret;
+
+ ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
+ if (ret != SQLITE_OK) {
+ _LOGE("failed to register busy handler: %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ return ret;
+}