}
thread_local bool calling_appinfo_cb = false;
+thread_local aul_app_info* current_info = nullptr;
int GetRunningAppInfoWithCb(int cmd, uid_t uid, aul_app_info_iter_fn cb,
void* user_data) {
if (cb == nullptr)
if (SetAppInfo(&info, b) != 0)
break;
+ current_info = &info;
cb(&info, user_data);
+ current_info = nullptr;
}
calling_appinfo_cb = false;
return calling_appinfo_cb;
}
+extern "C" int aul_app_get_status_from_current_appinfo(const char* appid,
+ int* status) {
+ if (appid == nullptr || status == nullptr)
+ return AUL_R_EINVAL;
+
+ if (current_info == nullptr)
+ return AUL_R_ERROR;
+
+ if (strcmp(appid, current_info->appid) != 0)
+ return AUL_R_ERROR;
+
+ *status = current_info->status;
+ return AUL_R_OK;
+}
+
+extern "C" int aul_app_get_status_bypid_from_current_appinfo(int pid,
+ int* status) {
+ if (pid < 1 || status == nullptr)
+ return AUL_R_EINVAL;
+
+ if (current_info == nullptr)
+ return AUL_R_ERROR;
+
+ if (current_info->pid != pid)
+ return AUL_R_ERROR;
+
+ *status = current_info->status;
+ return AUL_R_OK;
+}
+
extern "C" API int aul_app_get_pid(const char* appid) {
return aul_app_get_pid_for_uid(appid, getuid());
}
bool aul_is_calling_appinfo_cb();
+int aul_app_get_status_from_current_appinfo(const char *appid, int *status);
+
+int aul_app_get_status_bypid_from_current_appinfo(int pid, int *status);
+
#ifdef __cplusplus
}
#endif
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("=====================================================================");
+ int status = -1;
+ aul_app_get_status_bypid_from_current_appinfo(pid, &status);
+ if (status != -1)
+ return status;
}
return AppRequest(APP_GET_STATUS, uid)
}
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("=====================================================================");
+ int status = -1;
+ aul_app_get_status_from_current_appinfo(appid, &status);
+ if (status != -1 && status != STATUS_VISIBLE)
+ return status;
}
return AppRequest(APP_GET_STATUS_BY_APPID, uid)