Add a retrying logic for loading appinfo 62/277562/6
authorChanggyu Choi <changyu.choi@samsung.com>
Fri, 8 Jul 2022 07:30:04 +0000 (16:30 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 11 Jul 2022 05:12:08 +0000 (14:12 +0900)
If calling pkgmgrinfo_appinfo_get_usr_installed_list_full() is failed,
AMD adds a timer to retry loading appinfo. The interval of the timer is
5 seconds. The maximum retrying number is 20. If it exceeds the maximum count,
AMD terminates itself.

Change-Id: Ie1291737f68c1d24928e132c2b774360bafb150a
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/lib/amd_appinfo.c

index f6aab0b..6d41f6d 100644 (file)
@@ -79,11 +79,18 @@ struct callback_info {
        void *user_data;
 };
 
+struct load_retry_info {
+       uid_t uid;
+       unsigned int retrying_cnt;
+       guint timer;
+};
+
 static pkgmgr_client *pc;
 static GHashTable *user_tbl;
 static GHashTable *pkg_pending;
 static GList *app_event_list;
 static int gles = 1;
+static struct load_retry_info __load_retry_info;
 
 static void __free_appinfo_splash_image(gpointer data)
 {
@@ -1889,6 +1896,46 @@ static void __fini_package_event_handler(void)
        pkgmgr_client_free(pc);
 }
 
+static gboolean __retry_appinfo_load_cb(gpointer data)
+{
+       struct load_retry_info *info = (struct load_retry_info *)data;
+
+       info->retrying_cnt++;
+       _E("Retrying count: %u", info->retrying_cnt);
+
+       if (_appinfo_load(info->uid) == 0) {
+               info->retrying_cnt = 0;
+               info->timer = 0;
+               return G_SOURCE_REMOVE;
+       }
+
+       if (info->retrying_cnt == 20) {
+               _E("Failed to load appinfo. uid(%u)", info->uid);
+               exit(-1);
+               return G_SOURCE_REMOVE;
+       }
+
+       return G_SOURCE_CONTINUE;
+}
+
+static void __retry_to_load_appinfo(uid_t uid) {
+       __load_retry_info.uid = uid;
+       if (__load_retry_info.timer != 0)
+               return;
+
+       __load_retry_info.timer = g_timeout_add(5000, __retry_appinfo_load_cb,
+                       &__load_retry_info);
+}
+
+static void __dispose_retry_info() {
+       if (__load_retry_info.timer) {
+               g_source_remove(__load_retry_info.timer);
+               __load_retry_info.timer = 0;
+       }
+
+       __load_retry_info.retrying_cnt = 0;
+}
+
 static int __dispatch_amd_reload_appinfo(request_h req)
 {
        uid_t uid = _request_get_target_uid(req);
@@ -1903,6 +1950,7 @@ static int __dispatch_amd_reload_appinfo(request_h req)
        } else {
                info = __create_user_appinfo(uid);
                if (!info) {
+                       __retry_to_load_appinfo(uid);
                        _request_send_result(req, -1);
                        return -1;
                }
@@ -1921,9 +1969,11 @@ static int __dispatch_amd_reload_appinfo(request_h req)
                _E("Failed to get installed list. uid(%u), error(%d)",
                                uid, ret);
                __remove_user_appinfo(uid);
+               __retry_to_load_appinfo(uid);
        } else {
                _noti_send(AMD_NOTI_MSG_APPINFO_RELOAD, (int)uid, 0, NULL,
                                NULL);
+               __dispose_retry_info();
        }
 
        _request_send_result(req, ret);
@@ -2205,9 +2255,11 @@ int _appinfo_load(uid_t uid)
        info = __add_user_appinfo(uid);
        if (info == NULL) {
                _W("Failed to load appinfo - %d", uid);
+               __retry_to_load_appinfo(uid);
                return -1;
        }
 
+       __dispose_retry_info();
        _noti_send(AMD_NOTI_MSG_APPINFO_LOAD, (int)uid, 0, NULL, NULL);
        _D("loaded appinfo table for uid(%d)", uid);
        return 0;