Fix bug about app_control 42/190242/6
authormk5004.lee <mk5004.lee@samsung.com>
Fri, 28 Sep 2018 10:56:04 +0000 (19:56 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 2 Oct 2018 05:13:28 +0000 (05:13 +0000)
- watchface_editor_launch_setup_app()

Change-Id: Ia90e559e80924998965d1fd055aa8aa2a9f0aeee
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
watchface-complication-provider/watchface-complication-provider.cc
watchface-editor/watchface-editor.cc

index 680ef8f..faa7d36 100644 (file)
@@ -265,8 +265,8 @@ extern "C" EXPORT_API int watchface_complication_provider_setup_is_editing(
   if (!watchface_complication::util::CheckWatchFeatureEnabled())
     return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
 
-  if (handle == NULL) {
-    LOGE("handle is null");
+  if (handle == NULL || is_editing == NULL) {
+    LOGE("Null parameter");
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
@@ -295,15 +295,35 @@ extern "C" EXPORT_API int watchface_complication_provider_setup_get_context(
   if (!watchface_complication::util::CheckWatchFeatureEnabled())
     return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
 
-  ret = app_control_get_extra_data(handle, SETUP_CONTEXT_DATA_KEY, &value);
+  if (handle == NULL || context == NULL) {
+    LOGE("Null parameter");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = app_control_get_extra_data(handle, SETUP_EDITOR_APPID_KEY, &value);
   if (ret != APP_CONTROL_ERROR_NONE) {
     if (ret == APP_CONTROL_ERROR_OUT_OF_MEMORY) {
       LOGE("Out of memory");
       return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
     }
-    LOGE("Fail to get context data (%d)", ret);
+    LOGE("Fail to get setup editor appid (%d)", ret);
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
+  free(value);
+
+  ret = app_control_get_extra_data(handle, SETUP_CONTEXT_DATA_KEY, &value);
+  if (ret != APP_CONTROL_ERROR_NONE) {
+    if (ret == APP_CONTROL_ERROR_OUT_OF_MEMORY) {
+      LOGE("Out of memory");
+      return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+    } else if (ret == APP_CONTROL_ERROR_KEY_NOT_FOUND) {
+      *context = NULL;
+      return WATCHFACE_COMPLICATION_ERROR_NONE;
+    } else {
+      LOGE("Fail to get context data (%d)", ret);
+      return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+    }
+  }
 
   data = bundle_decode(reinterpret_cast<const bundle_raw*>(value),
     strlen(value));
index a399258..32ea597 100644 (file)
@@ -484,15 +484,15 @@ extern "C" EXPORT_API int watchface_editor_is_setup_app_exist(
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
-static int _add_extra_data(app_control_h* service, const char* key,
+static int _add_extra_data(app_control_h service, const char* key,
     const char* value) {
-  int ret = app_control_add_extra_data(*service, key, value);
+  int ret = app_control_add_extra_data(service, key, value);
   if (ret != APP_CONTROL_ERROR_NONE) {
     if (ret == APP_CONTROL_ERROR_OUT_OF_MEMORY) {
-      LOGE("Fail to get context data");
+      LOGE("Fail to add extra data - out of memory");
       return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
     }
-    LOGE("Fail to get context data");
+    LOGE("Fail to add extra data %d", ret);
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
   return WATCHFACE_COMPLICATION_ERROR_NONE;
@@ -520,32 +520,39 @@ extern "C" EXPORT_API int watchface_editor_launch_setup_app(
   }
 
   LOGI("LAUNCH !!! %s", appid.c_str());
-  context_data = (ed->GetContext()).get();
-  app_control_set_app_id(service, appid.c_str());
+  int ret = app_control_set_app_id(service, appid.c_str());
+  if (ret != APP_CONTROL_ERROR_NONE) {
+    LOGE("Fail to set appid");
+    app_control_destroy(service);
+    return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
+  }
 
-  int ret = _add_extra_data(&service, SETUP_EDITOR_APPID_KEY,
+  ret = _add_extra_data(service, SETUP_EDITOR_APPID_KEY,
       util::GetAppId().c_str());
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) {
-    LOGE("Fail to add appid ");
+    LOGE("Fail to add setup appid ");
     app_control_destroy(service);
     return ret;
   }
 
   snprintf(ed_id, sizeof(ed_id), "%d", ed->GetEditableId());
   LOGI("add ed_id %s", ed_id);
-  ret = _add_extra_data(&service, SETUP_EDITABLE_ID_KEY, ed_id);
+  ret = _add_extra_data(service, SETUP_EDITABLE_ID_KEY, ed_id);
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) {
     LOGE("Fail to add ed_id %s", ed_id);
     app_control_destroy(service);
     return ret;
   }
 
-  ret = _add_extra_data(&service, SETUP_CONTEXT_DATA_KEY,
-      context_data == nullptr ? "" : context_data->ToString());
-  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) {
-    LOGE("Fail to add setup_context_data %d", ret);
-    app_control_destroy(service);
-    return ret;
+  context_data = (ed->GetContext()).get();
+  if (context_data != nullptr) {
+    ret = _add_extra_data(service, SETUP_CONTEXT_DATA_KEY,
+        context_data->ToString());
+    if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) {
+      LOGE("Fail to add setup_context_data %d", ret);
+      app_control_destroy(service);
+      return ret;
+    }
   }
 
   ret = app_control_send_launch_request(service, NULL, NULL);