Add a new function to get lifecycle state 45/259845/2
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 16 Jun 2021 01:57:45 +0000 (10:57 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 16 Jun 2021 02:20:18 +0000 (11:20 +0900)
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>
aul/api/aul_app_lifecycle.cc
aul/api/aul_app_lifecycle.h
include/aul_cmd.h
src/aul_cmd.c
tool/aul_test/aul_test.c

index cc33eba..66606cc 100644 (file)
@@ -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;
+}
index 96a6196..07aa5a5 100644 (file)
@@ -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
index 653ab30..218a878 100644 (file)
@@ -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
 };
index f479799..684b765 100644 (file)
@@ -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"
        };
index 1f0b26b..d077a15 100644 (file)
@@ -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)