#include <aul.h>
#include <aul_app_lifecycle.h>
#include <aul_cmd.h>
+#include <aul_sock.h>
#include <bundle_cpp.h>
#include <errno.h>
return 0;
}
+static int __dispatch_app_lifecycle_get_state(request_h req) {
+ bundle* kb = _request_get_bundle(req);
+ if (kb == nullptr) {
+ _E("Failed to get bundle");
+ return -EINVAL;
+ }
+
+ tizen_base::Bundle b(kb, false, false);
+ b.Delete(AUL_K_STATE);
+
+ std::string app_id = b.GetString(AUL_K_APPID);
+ uid_t target_uid = _request_get_target_uid(req);
+ app_status_h app_status = _app_status_find_by_appid(app_id.c_str(),
+ target_uid);
+ if (app_status == nullptr) {
+ aul_sock_send_bundle_with_fd(_request_remove_fd(req), APP_GET_INFO_ERROR,
+ b.GetHandle(), AUL_SOCK_NOREPLY);
+ return -1;
+ }
+
+ int pid = _app_status_get_pid(app_status);
+ auto& inst = AppLifecycleManager::GetInst();
+ auto info = inst.Find(pid);
+ if (info == nullptr) {
+ _E("Failed to find app lifecycle info. pid(%d)", pid);
+ aul_sock_send_bundle_with_fd(_request_remove_fd(req), APP_GET_INFO_ERROR,
+ b.GetHandle(), AUL_SOCK_NOREPLY);
+ return -1;
+ }
+
+ b.Add(AUL_K_STATE, std::to_string(info->GetState()));
+ aul_sock_send_bundle_with_fd(_request_remove_fd(req), APP_GET_INFO_OK,
+ b.GetHandle(), AUL_SOCK_NOREPLY);
+ _W("app_id(%s), pid(%d), state(%d)", app_id.c_str(), pid, info->GetState());
+ return 0;
+}
+
int _app_lifecycle_init(void) {
_W("APP_LIFECYCLE_INIT");
.cmd = APP_LIFECYCLE_UPDATE_STATE,
.callback = __dispatch_app_lifecycle_update_state
},
+ {
+ .cmd = APP_LIFECYCLE_GET_STATE,
+ .callback = __dispatch_app_lifecycle_get_state
+ },
};
int ret = _request_register_cmds(dispatch_table, ARRAY_SIZE(dispatch_table));