Print warning messages 81/301381/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 15 Nov 2023 06:30:58 +0000 (15:30 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 15 Nov 2023 06:30:58 +0000 (15:30 +0900)
Currently, product developers are using the aul_app_get_status() API in
the aul_app_info_iter_fn callback function.
This behavior has an adverse effect on AMD latency.
This patch adds the output of a warning message to the developer when
the aul_app_get_status() API is used within the aul_app_info_iter_fn callback.
Whether or not to call the callback was processed using thread local storage.

Change-Id: Iacb5ff451775b340e88cbd39ca20ff845321a89d
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/pkginfo.cc
src/status.cc

index 307980d..b0503e7 100644 (file)
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include "pkginfo_internal.h"
+
 #include <bundle_cpp.h>
 #include <bundle_internal.h>
 #include <glib-unix.h>
@@ -26,6 +28,7 @@
 #include <exception>
 #include <memory>
 #include <string>
+#include <thread>
 
 #include "app_request.h"
 #include "aul_api.h"
@@ -243,6 +246,7 @@ int SetAppInfo(aul_app_info* info, const tizen_base::Bundle& b) {
   return 0;
 }
 
+thread_local bool calling_appinfo_cb = false;
 int GetRunningAppInfoWithCb(int cmd, uid_t uid, aul_app_info_iter_fn cb,
     void* user_data) {
   if (cb == nullptr)
@@ -253,6 +257,7 @@ int GetRunningAppInfoWithCb(int cmd, uid_t uid, aul_app_info_iter_fn cb,
   if (ret != AUL_R_OK)
     return ret;
 
+  calling_appinfo_cb = true;
   aul_app_info info;
   for (auto const& b : results) {
     if (SetAppInfo(&info, b) != 0)
@@ -260,6 +265,7 @@ int GetRunningAppInfoWithCb(int cmd, uid_t uid, aul_app_info_iter_fn cb,
 
     cb(&info, user_data);
   }
+  calling_appinfo_cb = false;
 
   return AUL_R_OK;
 }
@@ -286,6 +292,10 @@ int GetPkgIdFromDB(int pid, char* buf, int len, uid_t uid) {
 
 }  // namespace
 
+extern "C" bool aul_is_calling_appinfo_cb() {
+  return calling_appinfo_cb;
+}
+
 extern "C" API int aul_app_get_pid(const char* appid) {
   return aul_app_get_pid_for_uid(appid, getuid());
 }
index e40ee1c..27d1b03 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "app_request.h"
 #include "aul/common/exception.hh"
+#include "pkginfo_internal.h"
 
 using namespace aul::internal;
 
@@ -207,6 +208,12 @@ extern "C" API int aul_app_get_status_bypid_for_uid(int pid, uid_t uid) {
   if (pid == getpid())
     return context.GetStatus();
 
+  if (aul_is_calling_appinfo_cb()) {
+    _E("=====================================================================");
+    _E("=> Do not use this function within the aul_app_info_iter_fn callback.");
+    _E("=====================================================================");
+  }
+
   return AppRequest(APP_GET_STATUS, uid)
       .SetPid(pid)
       .SendSimply();
@@ -222,6 +229,14 @@ extern "C" API int aul_app_get_status_for_uid(const char* appid, uid_t uid) {
     return AUL_R_EINVAL;
   }
 
+  if (aul_is_calling_appinfo_cb()) {
+    _E("=====================================================================");
+    _E("=> Do not use this function within the aul_app_info_iter_fn callback.");
+    _E("=> The status info is already included in the aul_app_info structure.");
+    _E("=> If you want focused pid information, use the aul_window_get_focused_pid() function.");
+    _E("=====================================================================");
+  }
+
   return AppRequest(APP_GET_STATUS_BY_APPID, uid)
       .SetAppId(appid)
       .SendSimply();