Support multiple instance launch 30/287130/2
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 20 Jan 2023 07:24:04 +0000 (07:24 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 31 Jan 2023 01:53:06 +0000 (01:53 +0000)
When the multiple instance launch is supported, the application ID can
be "<appid>::<instance_id>". This patch checks whether the application ID
has the instance Id or not. If it has the instance ID, the library tries
to find the application info using the real application ID.

Change-Id: I4d72dada5815f359073de860b354cb7bee994b9d
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/pkgmgrinfo_appinfo.c

index ad481a3..9651dab 100644 (file)
@@ -179,11 +179,32 @@ API int pkgmgrinfo_appinfo_get_disabled_appinfo(
                        appid, _getuid(), handle);
 }
 
+static char *__get_real_appid(const char *appid)
+{
+       char *str;
+       char *saveptr;
+       char *token;
+
+       str = strdup(appid);
+       if (str == NULL)
+               return NULL;
+
+       token = strtok_r(str, "::", &saveptr);
+       if (token == NULL)
+               return str;
+
+       LOGD("Real appid = %s", token);
+       token = strdup(token);
+       free(str);
+       return token;
+}
+
 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                pkgmgrinfo_appinfo_h *handle)
 {
        int ret;
        pkgmgrinfo_appinfo_filter_h filter;
+       char *real_appid;
 
        if (appid == NULL || handle == NULL) {
                LOGE("invalid parameter");
@@ -194,10 +215,17 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
        if (ret != PMINFO_R_OK)
                return ret;
 
+       real_appid = __get_real_appid(appid);
+       if (real_appid == NULL) {
+               LOGE("Out of memory");
+               return PMINFO_R_ERROR;
+       }
+
        ret = pkgmgrinfo_appinfo_filter_add_string(filter,
-                       PMINFO_APPINFO_PROP_APP_ID, appid);
+                       PMINFO_APPINFO_PROP_APP_ID, real_appid);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
+               free(real_appid);
                return PMINFO_R_ERROR;
        }
 
@@ -205,6 +233,7 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                        PMINFO_APPINFO_PROP_APP_DISABLE, false);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
+               free(real_appid);
                return PMINFO_R_ERROR;
        }
 
@@ -212,10 +241,12 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                        PMINFO_APPINFO_PROP_PKG_DISABLE, false);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
+               free(real_appid);
                return PMINFO_R_ERROR;
        }
 
-       ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
+       ret = _pkgmgrinfo_get_appinfo(real_appid, uid, filter, handle);
+       free(real_appid);
        pkgmgrinfo_appinfo_filter_destroy(filter);
        return ret;
 }