Fix getting AppInfo 08/271108/3
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 15 Feb 2022 09:42:32 +0000 (18:42 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 16 Feb 2022 00:50:53 +0000 (00:50 +0000)
If the pid parameter is equal to the current process ID, AppInfo::Get()
tries to get a package ID and a root path using pre-initialized information.
If calling aul_app_get_pkgid_bypid() or calling aul_get_preinit_root_path()
is failed, the method tries to get the application information using pkgmgr-info API.

Change-Id: I43c2261dc4822c66b61cccd2c7db066858c19709
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
aul/app_info/app_info.cc

index cac07dd..fe3dd9e 100644 (file)
@@ -84,7 +84,19 @@ AppInfo* AppInfo::Get(int pid) {
   if (ret != AUL_R_OK)
     return nullptr;
 
-  return Get(app_id, getuid());
+  if (pid != getpid())
+    return Get(app_id, getuid());
+
+  char pkg_id[256] = { 0, };
+  ret = aul_app_get_appid_bypid(pid, pkg_id, sizeof(pkg_id));
+  if (ret != AUL_R_OK)
+    return Get(app_id, getuid());
+
+  const char* root_path = aul_get_preinit_root_path();
+  if (root_path == nullptr)
+    return Get(app_id, getuid());
+
+  return Builder().SetAppId(app_id).SetPkgId(pkg_id).SetRootPath(root_path);
 }
 
 AppInfo::AppInfo(std::string app_id, std::string pkg_id, std::string root_path)