Enable app_manager_is_running and add retry logic on failure 65/234265/3
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 25 May 2020 02:35:05 +0000 (11:35 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 27 May 2020 08:08:08 +0000 (17:08 +0900)
Change-Id: I3f32c7e8ef93e96b1ca57276c89748e3f11e6e4a

src/multi_assistant_service.c

index 8ae416a..6438333 100644 (file)
@@ -923,17 +923,21 @@ int mas_get_client_pid_by_appid(const char *appid)
                }
        }
 
-#ifdef CHECK_APP_IS_RUNNING
+       int retry_num = 0;
+       bool succeeded = false;
        bool running = false;
-       if (appid && 0 == app_manager_is_running(appid, &running)) {
-               if (!running) {
-                       MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d",
-                               (appid ? appid : "NULL"), ret, running);
-                       mas_client_deinitialize(ret);
-                       ret = -1;
-               }
+       if (appid) {
+               do {
+                       succeeded = (0 == app_manager_is_running(appid, &running));
+                       if (succeeded && !running) {
+                               MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d",
+                                       (appid ? appid : "NULL"), ret, running);
+                               mas_client_deinitialize(ret);
+                               ret = -1;
+                       }
+                       if (!succeeded) usleep(10000);
+               } while(!succeeded && retry_num++ < 3);
        }
-#endif
 
        return ret;
 }
@@ -948,17 +952,21 @@ const char* mas_get_client_appid_by_pid(int pid)
                ret = client->appid;
        }
 
-#ifdef CHECK_APP_IS_RUNNING
+       int retry_num = 0;
+       bool succeeded = false;
        bool running = false;
-       if (ret && 0 == app_manager_is_running(ret, &running)) {
-               if (!running) {
-                       MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d",
-                               pid, (ret ? ret : "NULL"), running);
-                       mas_client_deinitialize(pid);
-                       ret = NULL;
-               }
+       if (ret) {
+               do {
+                       succeeded = (0 == app_manager_is_running(ret, &running));
+                       if (succeeded && !running) {
+                               MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d",
+                                       pid, (ret ? ret : "NULL"), running);
+                               mas_client_deinitialize(pid);
+                               ret = NULL;
+                       }
+                       if (!succeeded) usleep(10000);
+               } while(!succeeded && retry_num++ < 3);
        }
-#endif
 
        return ret;
 }