Add a fallback about finding appinfo 79/294679/2
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 23 Jun 2023 06:38:34 +0000 (06:38 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 23 Jun 2023 06:42:28 +0000 (06:42 +0000)
If finding appinfo is failed, amd tries to insert the appinfo using
pkgmgr-info API. If it's failed, amd returns -ENOENT error.

Change-Id: I26076167bd157db7a4ec4f2d52b59e08185f6425
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_appinfo.c
src/lib/amd_appinfo.h
src/lib/amd_launch.c

index 6d41f6d..f9ca66d 100644 (file)
@@ -2090,6 +2090,35 @@ int _appinfo_insert(uid_t uid, const char *pkgid)
        return 0;
 }
 
+int _appinfo_insert_appinfo(uid_t uid, const char *appid)
+{
+       int ret;
+       struct user_appinfo *info;
+       pkgmgrinfo_appinfo_h handle;
+
+       info = __find_user_appinfo(uid);
+       if (info == NULL) {
+               _E("Failed to find user appinfo. uid(%d)", uid);
+               return -1;
+       }
+
+       if (g_hash_table_contains(info->tbl, appid)) {
+               _W("Already exists. uid(%u), appid(%s)", uid, appid);
+               return 0;
+       }
+
+       ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
+       if (ret != PMINFO_R_OK) {
+               _E("Failed to get appinfo. %u:%s, error(%d)", uid, appid, ret);
+               return -1;
+       }
+
+       ret = __insert_appinfo(handle, info);
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+       return ret;
+}
+
 const char *_appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
 {
        if (!c) {
index 2a5c3fa..6f00671 100644 (file)
@@ -102,6 +102,8 @@ void _appinfo_fini(void);
 
 int _appinfo_insert(uid_t uid, const char *pkgid);
 
+int _appinfo_insert_appinfo(uid_t uid, const char *appid);
+
 struct appinfo *_appinfo_find(uid_t caller_uid, const char *appid);
 
 const char *_appinfo_get_value(const struct appinfo *c, enum appinfo_type type);
index ec89bf6..e2b27df 100644 (file)
@@ -2876,8 +2876,16 @@ static int __prepare_starting_app(struct launch_s *handle, request_h req,
        handle->appid = appid;
        handle->ai = _appinfo_find(target_uid, appid);
        if (handle->ai == NULL) {
-               _E("Failed to find appinfo of %s", appid);
-               return -ENOENT;
+               _E("Failed to find appinfo. %u:%s", target_uid, appid);
+               if (_appinfo_insert_appinfo(target_uid, appid) != 0)
+                       return -ENOENT;
+
+               handle->ai = _appinfo_find(target_uid, appid);
+               if (handle->ai == NULL) {
+                       _E("[SECOND] Failed to find appinfo. %u:%s",
+                                       target_uid, appid);
+                       return -ENOENT;
+               }
        }
 
        ret = __check_executable(handle->ai);