diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2021-06-16 10:57:45 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2021-06-16 11:20:18 +0900 |
commit | c12fb3f6ac38e24d5d29dd533a717d437d26152f (patch) | |
tree | 2a327a7ce9448ddc81de1811c6e4b7dc108c2463 | |
parent | 8fa905b3a1c4eeb5c358eed7430586e257676498 (diff) | |
download | aul-1-c12fb3f6ac38e24d5d29dd533a717d437d26152f.tar.gz aul-1-c12fb3f6ac38e24d5d29dd533a717d437d26152f.tar.bz2 aul-1-c12fb3f6ac38e24d5d29dd533a717d437d26152f.zip |
Add a new function to get lifecycle state
Adds:
- aul_app_lifecycle_get_state()
Requires:
- https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/259845/
- https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/259848/
Change-Id: Ifce2176acf8db447797487314f5116f4292347c9
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | aul/api/aul_app_lifecycle.cc | 42 | ||||
-rw-r--r-- | aul/api/aul_app_lifecycle.h | 13 | ||||
-rw-r--r-- | include/aul_cmd.h | 1 | ||||
-rw-r--r-- | src/aul_cmd.c | 1 | ||||
-rw-r--r-- | tool/aul_test/aul_test.c | 33 |
5 files changed, 88 insertions, 2 deletions
diff --git a/aul/api/aul_app_lifecycle.cc b/aul/api/aul_app_lifecycle.cc index cc33eba7..66606ccb 100644 --- a/aul/api/aul_app_lifecycle.cc +++ b/aul/api/aul_app_lifecycle.cc @@ -107,7 +107,8 @@ extern "C" API int aul_app_lifecycle_deregister_state_changed_cb(void) { return listener.Deregister(); } -extern "C" int aul_app_lifecycle_update_state(aul_app_lifecycle_state_e state) { +extern "C" API int aul_app_lifecycle_update_state( + aul_app_lifecycle_state_e state) { tizen_base::Bundle b; b.Add(AUL_K_STATE, std::to_string(static_cast<int>(state))); aul::Packet packet(APP_LIFECYCLE_UPDATE_STATE, @@ -123,3 +124,42 @@ extern "C" int aul_app_lifecycle_update_state(aul_app_lifecycle_state_e state) { return AUL_R_OK; } + +extern "C" API int aul_app_lifecycle_get_state(const char* app_id, + aul_app_lifecycle_state_e* state) { + if (app_id == nullptr || state == nullptr) { + _E("Invalid prameter"); + return AUL_R_EINVAL; + } + + tizen_base::Bundle b; + b.Add(AUL_K_APPID, app_id); + aul::Packet* recv_pkt = nullptr; + aul::Packet packet(APP_LIFECYCLE_GET_STATE, AUL_SOCK_BUNDLE, b); + try { + aul::Client client(aul::PATH_AMD_SOCK); + int ret = client.Send(packet); + if (ret < 0) + return aul_error_convert(ret); + + ret = client.Recv(&recv_pkt); + if (ret < 0) + return aul_error_convert(ret); + } catch (aul::Exception& e) { + _E("Exception(%s) occurs", e.what()); + return aul_error_convert(e.GetErrorCode()); + } + + std::unique_ptr<aul::Packet> pkt_auto(recv_pkt); + if (recv_pkt->GetCmd() != APP_GET_INFO_OK) { + _E("Failed to get app lifecycle state"); + return AUL_R_ERROR; + } + + tizen_base::Bundle res_b = recv_pkt->DataToBundle(); + std::string val = res_b.GetString(AUL_K_STATE); + if (!val.empty()) + *state = static_cast<aul_app_lifecycle_state_e>(std::stoi(val)); + + return AUL_R_OK; +} diff --git a/aul/api/aul_app_lifecycle.h b/aul/api/aul_app_lifecycle.h index 96a61961..07aa5a5d 100644 --- a/aul/api/aul_app_lifecycle.h +++ b/aul/api/aul_app_lifecycle.h @@ -73,7 +73,7 @@ int aul_app_lifecycle_register_state_changed_cb(aul_app_lifecycle_state_changed_ int aul_app_lifecycle_deregister_state_changed_cb(void); /** - * @breif Updates the state of the application lifecycle. + * @brief Updates the state of the application lifecycle. * @since_tizen 6.5 * @param[in] state The state of the application lifecycle * @return @c 0 on success, @@ -82,6 +82,17 @@ int aul_app_lifecycle_deregister_state_changed_cb(void); */ int aul_app_lifecycle_update_state(aul_app_lifecycle_state_e state); +/** + * @brief Gets the state of the application lifecycle of the given application ID. + * @since_tizen 6.5 + * @param[in] app_id The application ID + * @param[out] state The state of the application lifecycle + * @return @c 0 on success, + * otherwise a negative error value + * @see #aul_app_lifecycle_state_e + */ +int aul_app_lifecycle_get_state(const char *app_id, aul_app_lifecycle_state_e *state); + #ifdef __cplusplus } #endif diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 653ab30f..218a8786 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -199,6 +199,7 @@ enum app_cmd { APP_GET_APP_CONTROL_DEFAULT_APPS = 157, APP_GET_APPID_BY_ALIAS_APPID = 158, APP_GET_APP_CONTROL_DEFAULT_APP = 159, + APP_LIFECYCLE_GET_STATE = 160, APP_CMD_MAX }; diff --git a/src/aul_cmd.c b/src/aul_cmd.c index f4797996..684b7653 100644 --- a/src/aul_cmd.c +++ b/src/aul_cmd.c @@ -201,6 +201,7 @@ API const char *aul_cmd_convert_to_string(int cmd) "APP_GET_APP_CONTROL_DEFAULT_APPS", "APP_GET_APPID_BY_ALIAS_APPID", "APP_GET_APP_CONTROL_DEFAULT_APP", + "APP_LIFECYCLE_GET_STATE", "CUSTOM_COMMAND" }; diff --git a/tool/aul_test/aul_test.c b/tool/aul_test/aul_test.c index 1f0b26b0..d077a157 100644 --- a/tool/aul_test/aul_test.c +++ b/tool/aul_test/aul_test.c @@ -795,6 +795,37 @@ static int get_default_app_test(void) return ret; } +static const char *__get_string_from_lifecycle_state( + aul_app_lifecycle_state_e state) +{ + switch (state) { + case AUL_APP_LIFECYCLE_STATE_INITIALIZED: + return "INITIALIZED"; + case AUL_APP_LIFECYCLE_STATE_CREATED: + return "CREATED"; + case AUL_APP_LIFECYCLE_STATE_RESUMED: + return "RESUMED"; + case AUL_APP_LIFECYCLE_STATE_PAUSED: + return "PAUSED"; + case AUL_APP_LIFECYCLE_STATE_DESTROYED: + return "DESTROYED"; + default: + return "UNKNOWN"; + } +} + +static int get_app_lifecycle_test(void) +{ + aul_app_lifecycle_state_e state; + int ret; + + printf("[aul_app_lifecycle_get_state test] %s\n", gargv[2]); + ret = aul_app_lifecycle_get_state(gargv[2], &state); + printf("result: %d, state: %s\n", + ret, __get_string_from_lifecycle_state(state)); + return ret; +} + static int test_regex() { char *token; @@ -941,6 +972,8 @@ static test_func_t test_func[] = { "[usage] set_default_app_by_operation <operation> <appid>"}, {"get_default_app", get_default_app_test, "aul_get_default_app", "[usage] get_default_appid <operation> <uri> <mime>"}, + {"get_app_lifecycle", get_app_lifecycle_test, "aul_app_lifecycle_get_state", + "[usage] get_app_lifecycle <appid>"}, }; int callfunc(char *testname) |