From d7ec8c471dedac4270490a87589ba10be045d969 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Mon, 15 Aug 2022 16:32:42 +0800 Subject: [PATCH 01/31] 0815updated Signed-off-by: lin_xiangrong Change-Id: I155f683a91feb4ddcf798c56b1277ceb4ca656a6 --- .../inner_api/include/form_host_interface.h | 10 +++ interfaces/inner_api/src/form_host_stub.cpp | 23 ++++++ .../inner_api/src/form_provider_proxy.cpp | 45 ++++++++++++ .../inner_api/src/form_provider_stub.cpp | 32 +++++++++ services/include/form_host_record.h | 8 +++ services/include/form_task_mgr.h | 21 +++++- services/src/form_provider_mgr.cpp | 70 +++++++++++++++++++ 7 files changed, 208 insertions(+), 1 deletion(-) diff --git a/interfaces/inner_api/include/form_host_interface.h b/interfaces/inner_api/include/form_host_interface.h index e765f0857f..12a9233a06 100644 --- a/interfaces/inner_api/include/form_host_interface.h +++ b/interfaces/inner_api/include/form_host_interface.h @@ -64,6 +64,13 @@ public: * @param result Share form result. */ virtual void OnShareFormResponse(int64_t requestCode, int32_t result) = 0; + + /** + * @brief Request to give back a Form after size changed. + * @param formInfo Form info. + */ + virtual void OnSizeChanged(const FormJsInfo &formInfo) = 0; + enum class Message { // ipc id 1-1000 for kit // ipc id 1001-2000 for DMS @@ -82,6 +89,9 @@ public: // ipc id for share form response(3685) FORM_HOST_ON_SHARE_FORM_RESPONSE, + + //ipc id for change form size(3686) + FORM_HOST_ON_SIZE_CHANGED, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/src/form_host_stub.cpp b/interfaces/inner_api/src/form_host_stub.cpp index 7bb0a16ee7..86cd16863e 100644 --- a/interfaces/inner_api/src/form_host_stub.cpp +++ b/interfaces/inner_api/src/form_host_stub.cpp @@ -38,6 +38,11 @@ FormHostStub::FormHostStub() &FormHostStub::HandleOnAcquireState; memberFuncMap_[static_cast(IFormHost::Message::FORM_HOST_ON_SHARE_FORM_RESPONSE)] = &FormHostStub::HandleOnShareFormResponse; +<<<<<<< HEAD +======= + memberFuncMap_[static_cast(IFormHost::Message::FORM_HOST_ON_SIZE_CHANGED)] = + &FormHostStub::HandleOnSizeChanged; +>>>>>>> d6ccdb1... clean_temp+++ } FormHostStub::~FormHostStub() @@ -155,5 +160,23 @@ int32_t FormHostStub::HandleOnShareFormResponse(MessageParcel &data, MessageParc reply.WriteInt32(ERR_OK); return ERR_OK; } + +/** + * @brief handle OnSizeChanged event. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int FormHostStub::HandleOnSizeChanged(MessageParcel &data, MessageParcel &reply) +{ + std::unique_ptr formInfo(data.ReadParcelable()); + if (!formInfo) { + HILOG_ERROR("%{public}s, failed to ReadParcelable", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + OnSizeChanged(*formInfo); + reply.WriteInt32(ERR_OK); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/src/form_provider_proxy.cpp b/interfaces/inner_api/src/form_provider_proxy.cpp index 5a9c1b0668..60153401a9 100644 --- a/interfaces/inner_api/src/form_provider_proxy.cpp +++ b/interfaces/inner_api/src/form_provider_proxy.cpp @@ -398,6 +398,51 @@ int FormProviderProxy::AcquireState(const Want &wantArg, const std::string &prov return ERR_OK; } +/** + * @brief Notify provider when the form want to change the size. + * @param formId The Id of the form to update. + * @param want the want of the request containing the new formDimensionNum. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ +int FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Want &want, + const sptr &callerToken) +{ + MessageParcel data; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (!data.WriteInt64(formId)) { + HILOG_ERROR("%{public}s, failed to write formId", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteParcelable(&want)) { + HILOG_ERROR("%{public}s, failed to write want", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteRemoteObject(callerToken)) { + HILOG_ERROR("%{public}s, failed to write callerToken", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + int error; + MessageParcel reply; + MessageOption option; + error = Remote()->SendRequest( + static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_SIZE_CHANGE), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + return error; + } + return ERR_OK; +} + template int FormProviderProxy::GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos) { diff --git a/interfaces/inner_api/src/form_provider_stub.cpp b/interfaces/inner_api/src/form_provider_stub.cpp index 7afb2f46fd..c161f45e78 100644 --- a/interfaces/inner_api/src/form_provider_stub.cpp +++ b/interfaces/inner_api/src/form_provider_stub.cpp @@ -44,6 +44,11 @@ FormProviderStub::FormProviderStub() &FormProviderStub::HandleAcquireState; memberFuncMap_[static_cast(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_SHARE_FOMR_INFO)] = &FormProviderStub::HandleAcquireShareFormData; +<<<<<<< HEAD +======= + memberFuncMap_[static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_SIZE_CHANGE)] = + &FormProviderStub::HandleNotifyFormSizeChaned; +>>>>>>> d6ccdb1... clean_temp+++ } FormProviderStub::~FormProviderStub() @@ -317,5 +322,32 @@ int32_t FormProviderStub::HandleAcquireShareFormData(MessageParcel &data, Messag return ERR_OK; } + +/** + * @brief handle the form size change. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int FormProviderStub::HandleNotifyFormSizeChaned(MessageParcel &data, MessageParcel &reply) +{ + int64_t formId = data.ReadInt64(); + + std::unique_ptr want(data.ReadParcelable()); + if (!want) { + HILOG_ERROR("%{public}s fail, ReadParcelable failed", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + sptr client = data.ReadRemoteObject(); + if (client == nullptr) { + HILOG_ERROR("%{public}s, failed to get remote object.", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + int32_t result = NotifyFormSizeChanged(formId, *want, client); + reply.WriteInt32(result); + return result; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/include/form_host_record.h b/services/include/form_host_record.h index 8e03388c1a..8abc229352 100644 --- a/services/include/form_host_record.h +++ b/services/include/form_host_record.h @@ -114,6 +114,14 @@ public: * @param record Form record. */ void OnUpdate(int64_t id, const FormRecord &record); + + /** + * @brief Send form data after size changed to form host. + * @param formId The Id of the form. + * @param record Form record. + */ + void OnSizeChanged(int64_t formId, const FormRecord &record); + /** * Send form uninstall message to form host. * diff --git a/services/include/form_task_mgr.h b/services/include/form_task_mgr.h index 24994189a5..5cb6e0fe7c 100644 --- a/services/include/form_task_mgr.h +++ b/services/include/form_task_mgr.h @@ -178,6 +178,16 @@ public: * @param result The error code of this share. */ void PostFormShareSendResponse(int64_t formShareRequestCode, int32_t result); + + /** + * @brief Post notify form size change to form provider(task). + * @param formId The form id. + * @param want The want of notifyFormSizeChanged. + * @param dimensionNum The dimension id of the new form. + * @param remoteObject Form provider proxy object. + */ + void PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const Want &want, const sptr &remoteObject); private: /** * @brief Acquire form data from form provider. @@ -297,7 +307,16 @@ private: */ void AcquireStateBack(AppExecFwk::FormState state, const AAFwk::Want &want, const sptr &remoteObject); - + + /** + * @brief Handle notify form size change to form provider. + * @param formId The form id. + * @param want The want of notifyFormSizeChanged. + * @param dimensionNum The dimension id of the new form. + * @param remoteObject Form provider proxy object. + */ + void NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const Want &want, const sptr &remoteObject); /** * @brief Create form data for form host. * @param formId The Id of the form. diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index ab2b2fecf2..e17057fc10 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -95,6 +95,76 @@ ErrCode FormProviderMgr::AcquireForm(const int64_t formId, const FormProviderInf return ERR_OK; } +/** + * @brief handle for resize form event from provider. + * @param formId The id of the form. + * @param providerFormInfo provider form info. + * @return Returns ERR_OK on success, others on failure. + */ +ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, const FormProviderInfo &formProviderInfo) +{ + HILOG_INFO("%{public}s called, formId:%{public}" PRId64 ".", __func__, formId); + + FormRecord formRecord; + bool isGetFormRecord = FormDataMgr::GetInstance().GetFormRecord(formId, formRecord); + if (!isGetFormRecord) { + HILOG_ERROR("%{public}s fail, not exist such form, formId:%{public}" PRId64 "", __func__, formId); + return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; + } + + int32_t dimensionId = want.GetIntParam(Constants::PARAM_FORM_DIMENSION_KEY, 0); + if(dimensionId == 0) { + HILOG_ERROR("%{public}s fail, the dimensionId is wrong, formId:%{public}" PRId64 "", __func__, formId); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + + formRecord.specification = dimensionId; + // db save + + FormHostRecord clientHost; + bool isGetFormHostRecord = FormDataMgr::GetInstance().GetFormHostRecord(formId, clientHost); + if (!isGetFormHostRecord) { + HILOG_ERROR("%{public}s fail, clientHost is null", __func__); + return ERR_APPEXECFWK_FORM_COMMON_CODE; + } + + FormProviderData formProviderData = formProviderInfo.GetFormData(); + + if (formRecord.versionUpgrade) { + formRecord.formProviderInfo.SetFormData(formProviderData); + formRecord.formProviderInfo.SetUpgradeFlg(true); + } else { + nlohmann::json addJsonData = formProviderData.GetData(); + formRecord.formProviderInfo.MergeData(addJsonData); + // merge image + auto formData = formRecord.formProviderInfo.GetFormData(); + formData.SetImageDataState(formProviderData.GetImageDataState()); + formData.SetImageDataMap(formProviderData.GetImageDataMap()); + formRecord.formProviderInfo.SetFormData(formData); + } + + formRecord.isInited = true; + formRecord.needRefresh = false; + FormDataMgr::GetInstance().SetFormCacheInited(formId, true); + + if (clientHost.Contains(formId)) { + formRecord.formProviderInfo = formProviderInfo; + clientHost.OnSizeChanged(formId, formRecord); + } + + if (formRecord.formProviderInfo.NeedCache()) { + std::string jsonData = formRecord.formProviderInfo.GetFormDataString(); + HILOG_DEBUG("%{public}s jsonData:%{public}s.", __func__, jsonData.c_str()); + FormCacheMgr::GetInstance().AddData(formId, jsonData); + } else { + FormCacheMgr::GetInstance().DeleteData(formId); + } + + // the resize form is successfully + return ERR_OK; + +} + /** * @brief Refresh form. * -- Gitee From 6e729ae49c5580aab50fc9b5546660b6eb9c7740 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Mon, 15 Aug 2022 16:55:13 +0800 Subject: [PATCH 02/31] temp Signed-off-by: lin_xiangrong Change-Id: Idcbc99f80b29bc3612fe5a5b24f4f5a7a482f98b --- interfaces/inner_api/include/form_constants.h | 1 + interfaces/inner_api/include/form_provider_interface.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/interfaces/inner_api/include/form_constants.h b/interfaces/inner_api/include/form_constants.h index 6ca9164aef..557f6d62f0 100644 --- a/interfaces/inner_api/include/form_constants.h +++ b/interfaces/inner_api/include/form_constants.h @@ -147,6 +147,7 @@ namespace Constants { constexpr const char* ACQUIRE_TYPE = "form_acquire_form"; constexpr int32_t ACQUIRE_TYPE_CREATE_FORM = 1; constexpr int32_t ACQUIRE_TYPE_RECREATE_FORM = 2; + constexpr int32_t ACQUIRE_TYPE_RESIZE_FORM = 3; constexpr int32_t DELETE_FORM = 3; constexpr int32_t RELEASE_FORM = 8; diff --git a/interfaces/inner_api/include/form_provider_interface.h b/interfaces/inner_api/include/form_provider_interface.h index b53f66697e..2da2ba8950 100644 --- a/interfaces/inner_api/include/form_provider_interface.h +++ b/interfaces/inner_api/include/form_provider_interface.h @@ -114,6 +114,16 @@ public: virtual int AcquireState(const Want &wantArg, const std::string &provider, const Want &want, const sptr &callerToken) = 0; + /** + * @brief Notify provider when the form want to change the size. + * @param formId The Id of the form to change size. + * @param want Indicates the structure containing form info. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, + const sptr &callerToken) = 0; + /** * @brief Acquire to share form information data. This is sync API. * @param formId The Id of the from. -- Gitee From ee0d44f43e7a3caa05148c5d90ee5e5c511201be Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Mon, 15 Aug 2022 16:32:42 +0800 Subject: [PATCH 03/31] temp2 Signed-off-by: lin_xiangrong Change-Id: If38195b8d8d0f88a033249a2eda287d2c386d746 --- interfaces/inner_api/src/form_host_stub.cpp | 5 +++++ interfaces/inner_api/src/form_provider_stub.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/interfaces/inner_api/src/form_host_stub.cpp b/interfaces/inner_api/src/form_host_stub.cpp index 86cd16863e..b2fc3567d0 100644 --- a/interfaces/inner_api/src/form_host_stub.cpp +++ b/interfaces/inner_api/src/form_host_stub.cpp @@ -39,6 +39,11 @@ FormHostStub::FormHostStub() memberFuncMap_[static_cast(IFormHost::Message::FORM_HOST_ON_SHARE_FORM_RESPONSE)] = &FormHostStub::HandleOnShareFormResponse; <<<<<<< HEAD +<<<<<<< HEAD +======= + memberFuncMap_[static_cast(IFormHost::Message::FORM_HOST_ON_SIZE_CHANGED)] = + &FormHostStub::HandleOnSizeChanged; +>>>>>>> d6ccdb1... clean_temp+++ ======= memberFuncMap_[static_cast(IFormHost::Message::FORM_HOST_ON_SIZE_CHANGED)] = &FormHostStub::HandleOnSizeChanged; diff --git a/interfaces/inner_api/src/form_provider_stub.cpp b/interfaces/inner_api/src/form_provider_stub.cpp index c161f45e78..1df2fb02e6 100644 --- a/interfaces/inner_api/src/form_provider_stub.cpp +++ b/interfaces/inner_api/src/form_provider_stub.cpp @@ -45,6 +45,11 @@ FormProviderStub::FormProviderStub() memberFuncMap_[static_cast(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_SHARE_FOMR_INFO)] = &FormProviderStub::HandleAcquireShareFormData; <<<<<<< HEAD +<<<<<<< HEAD +======= + memberFuncMap_[static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_SIZE_CHANGE)] = + &FormProviderStub::HandleNotifyFormSizeChaned; +>>>>>>> d6ccdb1... clean_temp+++ ======= memberFuncMap_[static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_SIZE_CHANGE)] = &FormProviderStub::HandleNotifyFormSizeChaned; -- Gitee From a62e0e8e892d0039f7145b9e843e83ec5b98f3f7 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Mon, 8 Aug 2022 10:07:02 +0800 Subject: [PATCH 04/31] temp3 Signed-off-by: lin_xiangrong Change-Id: I7afc3e704349cb1444c0c7a267fa96c7bf095a4d --- BUILD.gn | 2 +- .../js/napi/formHost/napi_form_host.cpp | 207 ++++++++++++++++++ frameworks/js/napi/formHost/napi_form_host.h | 11 + .../inner_api/include/form_mgr_interface.h | 10 + interfaces/inner_api/include/form_mgr_proxy.h | 21 +- interfaces/inner_api/include/form_mgr_stub.h | 8 + interfaces/inner_api/src/form_host_stub.cpp | 8 - interfaces/inner_api/src/form_mgr_proxy.cpp | 41 ++++ interfaces/inner_api/src/form_mgr_stub.cpp | 27 +++ .../inner_api/src/form_provider_stub.cpp | 8 - interfaces/kits/native/include/form_mgr.h | 9 + interfaces/kits/native/src/form_mgr.cpp | 47 +++- services/include/form_mgr_adapter.h | 9 + services/include/form_mgr_service.h | 9 + services/src/form_mgr_service.cpp | 20 ++ 15 files changed, 412 insertions(+), 25 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index ce300bd054..2653850333 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -264,4 +264,4 @@ group("fms_services_target") { if (ability_runtime_graphics) { deps = [ ":fms_target" ] } -} +} \ No newline at end of file diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index 962395a034..6a4f36696d 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -3392,3 +3392,210 @@ void JsFormHost::InnerShareForm( FormHostClient::GetInstance()->RemoveShareFormCallback(requestCode); } } + +/** + * @brief Call native kit function: formSizeChanged + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] asyncCallbackInfo Reference, callback info via Node-API + * + * @return void + */ +static void InnerFormSizeChanged(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) +{ + HILOG_DEBUG("%{public}s called.", __func__); + asyncCallbackInfo->result = FormMgr::GetInstance().NotifyFormSizeChanged(asyncCallbackInfo->formId, + asyncCallbackInfo->newDimension, FormHostClient::GetInstance()); + HILOG_DEBUG("%{public}s, end", __func__); +} + +/** + * @brief The implementation of Node-API interface: formSizeChanged + * + * @param[in] env The environment that the Node-API call is invoked under + * @param[out] info An opaque datatype that is passed to a callback function + * + * @return This is an opaque pointer that is used to represent a JavaScript value + */ +napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_THREE; + napi_value argv[ARGS_SIZE_THREE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc < ARGS_SIZE_TWO || argc > ARGS_SIZE_THREE) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + return nullptr; + } + HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); + + // Check the value type of the formId argument + napi_valuetype valueType; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ZERO], &valueType)); + if (valueType != napi_string) { + AsyncErrMsgCallbackInfo *asyncErrorInfo = new + AsyncErrMsgCallbackInfo { + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .callbackValue = argv[ARGS_SIZE_TWO], + .code = ERR_APPEXECFWK_FORM_INVALID_FORM_ID, + .type = 0 + }; + + if (argc == ARGS_SIZE_THREE) { + asyncErrorInfo->type = CALLBACK_FLG; + } else { + asyncErrorInfo->type = PROMISE_FLG; + } + return RetErrMsg(asyncErrorInfo); + } + + // Check the value type of the size argument + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ONE], &valueType)); + if (valueType != napi_string) { + AsyncErrMsgCallbackInfo *asyncErrorInfo = new + AsyncErrMsgCallbackInfo { + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .callbackValue = argv[ARGS_SIZE_TWO], + .code = ERR_APPEXECFWK_FORM_RELEASE_FLG_ERR, //the wrong errorCode + .type = 0 + }; + + if (argc == ARGS_SIZE_THREE) { + asyncErrorInfo->type = CALLBACK_FLG; + } else { + asyncErrorInfo->type = PROMISE_FLG; + } + return RetErrMsg(asyncErrorInfo); + } + + // Check the value of the formId argument + std::string strFormId = GetStringFromNAPI(env, argv[ARGS_SIZE_ZERO]); + int64_t formId; + HILOG_ERROR("%{public}s, form id ", strFormId.c_str()); + if (!ConvertStringToInt64(strFormId, formId)) { + AsyncErrMsgCallbackInfo *asyncErrorInfo = new + AsyncErrMsgCallbackInfo { + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .callbackValue = argv[1], + .code = ERR_APPEXECFWK_FORM_FORM_ID_NUM_ERR, + .type = 0 + }; + + if (argc == ARGS_SIZE_THREE) { + asyncErrorInfo->type = CALLBACK_FLG; + } else { + asyncErrorInfo->type = PROMISE_FLG; + } + return RetErrMsg(asyncErrorInfo); + } + + // Get the value of the size argument + std::string newDimension = GetStringFromNAPI(env, argv[ARGS_SIZE_ONE]); + + AsyncFormResizeCallbackInfo *asyncCallbackInfo = new + AsyncFormResizeCallbackInfo { + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .formId = 0, + .newDimension = "", + .result = 0, + }; + asyncCallbackInfo->formId = formId; + asyncCallbackInfo->newDimension = newDimension; + + if (argc == ARGS_SIZE_THREE) { + HILOG_INFO("%{public}s, asyncCallback.", __func__); + + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arguments[2] type of deleteForm is incorrect, " + "expected type is function."); + + napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; + InnerFormSizeChanged(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; + HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + + if (asyncCallbackInfo->callback != nullptr) { + napi_value result[ARGS_SIZE_TWO] = {0}; + InnerCreateCallbackRetMsg(env, asyncCallbackInfo->result, result); + napi_value callback; + napi_value undefined; + napi_get_undefined(env, &undefined); + napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); + napi_value callResult; + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &callResult); + napi_delete_reference(env, asyncCallbackInfo->callback); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *)asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + return NapiGetResult(env, 1); + } else { + HILOG_INFO("%{public}s, promise.", __func__); + napi_deferred deferred; + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + asyncCallbackInfo->deferred = deferred; + + napi_value resourceName; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, + nullptr, + resourceName, + [](napi_env env, void *data) { + HILOG_INFO("%{public}s, promise running", __func__); + AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; + InnerFormSizeChanged(env, asyncCallbackInfo); + }, + [](napi_env env, napi_status status, void *data) { + HILOG_INFO("%{public}s, promise complete", __func__); + AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; + + napi_value result; + InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &result); + if (asyncCallbackInfo->result == ERR_OK) { + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + } else { + napi_reject_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + }, + (void *)asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + return promise; + } +} diff --git a/frameworks/js/napi/formHost/napi_form_host.h b/frameworks/js/napi/formHost/napi_form_host.h index 888fad9566..2ba4067b2e 100644 --- a/frameworks/js/napi/formHost/napi_form_host.h +++ b/frameworks/js/napi/formHost/napi_form_host.h @@ -156,6 +156,16 @@ struct AsyncGetFormsInfoCallbackInfo { int result; }; +struct AsyncFormResizeCallbackInfo { + napi_env env; + napi_async_work asyncWork; + napi_deferred deferred; + napi_ref callback; + int64_t formId; + std::string newDimension; + int result; +}; + napi_value NAPI_DeleteForm(napi_env env, napi_callback_info info); napi_value NAPI_ReleaseForm(napi_env env, napi_callback_info info); napi_value NAPI_RequestForm(napi_env env, napi_callback_info info); @@ -173,6 +183,7 @@ napi_value NAPI_NotifyFormsVisible(napi_env env, napi_callback_info info); napi_value NAPI_NotifyFormsEnableUpdate(napi_env env, napi_callback_info info); napi_value NAPI_GetAllFormsInfo(napi_env env, napi_callback_info info); napi_value NAPI_GetFormsInfo(napi_env env, napi_callback_info info); +napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info); using ShareFormTask = std::function; class JsFormHost { diff --git a/interfaces/inner_api/include/form_mgr_interface.h b/interfaces/inner_api/include/form_mgr_interface.h index b9de748528..0322db96d8 100644 --- a/interfaces/inner_api/include/form_mgr_interface.h +++ b/interfaces/inner_api/include/form_mgr_interface.h @@ -332,6 +332,15 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int32_t RecvFormShareInfoFromRemote(const FormShareInfo &info) = 0; + + /** + * @brief notify form rto change size with formId and newDimension, send formId and new Dimension to form manager service. + * @param formId The Id of the forms to delete. + * @param newDimension the newDimension of the form to reSize + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) = 0; enum class Message { // ipc id 1-1000 for kit @@ -377,6 +386,7 @@ public: FORM_MGR_SHARE_FORM, FORM_MGR_RECV_FORM_SHARE_INFO_FROM_REMOTE, FORM_MGR_START_ABILITY, + FORM_MGR_NOTIFY_FORM_SIZE_CHANGED, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/include/form_mgr_proxy.h b/interfaces/inner_api/include/form_mgr_proxy.h index f1626ecf5b..67835536ee 100644 --- a/interfaces/inner_api/include/form_mgr_proxy.h +++ b/interfaces/inner_api/include/form_mgr_proxy.h @@ -278,14 +278,23 @@ public: std::vector &formInfos) override; /** - * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. - * The bundle name will be retrieved by form service manager. - * @param moduleName the module that the formInfos have to belong to. - * @param formInfos Return the forms' information of the calling bundle name - * @return Returns ERR_OK on success, others on failure. - */ + * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. + * The bundle name will be retrieved by form service manager. + * @param moduleName the module that the formInfos have to belong to. + * @param formInfos Return the forms' information of the calling bundle name + * @return Returns ERR_OK on success, others on failure. + */ int32_t GetFormsInfo(const std::string &moduleName, std::vector &formInfos) override; + /** + * @brief notify form rto change size with formId and newDimension, send formId and new Dimension to form manager service. + * @param formId The Id of the forms to delete. + * @param newDimension the newDimension of the form to reSize + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; + /** * @brief Check if the request of publishing a form is supported by the host. * @return Returns true if the request is supported and false otherwise. diff --git a/interfaces/inner_api/include/form_mgr_stub.h b/interfaces/inner_api/include/form_mgr_stub.h index af888a78e0..8bde63d640 100644 --- a/interfaces/inner_api/include/form_mgr_stub.h +++ b/interfaces/inner_api/include/form_mgr_stub.h @@ -301,6 +301,14 @@ private: */ int32_t HandleStartAbility(MessageParcel &data, MessageParcel &reply); + /** + * @brief Handle NitifyFormSizeChangde message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t HandleNotifyFormSizeChanged(MessageParcel &data, MessageParcel &reply); + private: using FormMgrFunc = int32_t (FormMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/src/form_host_stub.cpp b/interfaces/inner_api/src/form_host_stub.cpp index b2fc3567d0..25f9b7aef1 100644 --- a/interfaces/inner_api/src/form_host_stub.cpp +++ b/interfaces/inner_api/src/form_host_stub.cpp @@ -38,16 +38,8 @@ FormHostStub::FormHostStub() &FormHostStub::HandleOnAcquireState; memberFuncMap_[static_cast(IFormHost::Message::FORM_HOST_ON_SHARE_FORM_RESPONSE)] = &FormHostStub::HandleOnShareFormResponse; -<<<<<<< HEAD -<<<<<<< HEAD -======= memberFuncMap_[static_cast(IFormHost::Message::FORM_HOST_ON_SIZE_CHANGED)] = &FormHostStub::HandleOnSizeChanged; ->>>>>>> d6ccdb1... clean_temp+++ -======= - memberFuncMap_[static_cast(IFormHost::Message::FORM_HOST_ON_SIZE_CHANGED)] = - &FormHostStub::HandleOnSizeChanged; ->>>>>>> d6ccdb1... clean_temp+++ } FormHostStub::~FormHostStub() diff --git a/interfaces/inner_api/src/form_mgr_proxy.cpp b/interfaces/inner_api/src/form_mgr_proxy.cpp index 746d4f6091..237ff7bfcc 100644 --- a/interfaces/inner_api/src/form_mgr_proxy.cpp +++ b/interfaces/inner_api/src/form_mgr_proxy.cpp @@ -1133,6 +1133,47 @@ int32_t FormMgrProxy::GetFormsInfo(const std::string &moduleName, std::vector &callerToken) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteInt64(formId)) { + HILOG_ERROR("%{public}s, failed to write formId", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteRemoteObject(callerToken)) { + HILOG_ERROR("%{public}s, failed to write callerToken", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteInt32(dimensionNum)) { + HILOG_ERROR("%{public}s, failed to write dimensionNum", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option; + int error = Remote()->SendRequest( + static_cast(IFormMgr::Message::FORM_MGR_NOTIFY_FORM_SIZE_CHANGED), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + return ERR_APPEXECFWK_FORM_SEND_FMS_MSG; + } + return reply.ReadInt32(); +} + bool FormMgrProxy::IsRequestPublishFormSupported() { HILOG_INFO("%{public}s start.", __func__); diff --git a/interfaces/inner_api/src/form_mgr_stub.cpp b/interfaces/inner_api/src/form_mgr_stub.cpp index 13ad7a50b5..75156e2f89 100644 --- a/interfaces/inner_api/src/form_mgr_stub.cpp +++ b/interfaces/inner_api/src/form_mgr_stub.cpp @@ -112,6 +112,8 @@ FormMgrStub::FormMgrStub() &FormMgrStub::HandleIsRequestPublishFormSupported; memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_START_ABILITY)] = &FormMgrStub::HandleStartAbility; + memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_NOTIFY_FORM_SIZE_CHANGED)] = + &FormMgrStub::HandleNotifyFormSizeChanged; } FormMgrStub::~FormMgrStub() @@ -903,6 +905,31 @@ int32_t FormMgrStub::HandleStartAbility(MessageParcel &data, MessageParcel &repl return result; } +/** + * @brief Handle NitifyFormSizeChangde message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int32_t FormMgrStub::HandleNotifyFormSizeChanged(MessageParcel &data, MessageParcel &reply) +{ + int64_t formId = data.ReadInt64(); + sptr client = data.ReadRemoteObject(); + if(client == nullptr) { + return ERR_APPEXECFWK_PARCEL_ERROR; + } + int32_t dimensionNum = data.ReadInt32(); + + int32_t result = NotifyFormSizeChanged(formId, dimensionNum, client); + + reply.WriteInt32(result); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("%{public}s, failed to write result", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return result; +} + /** * @brief Write a parcelabe vector objects to the proxy node. * @param parcelableVector Indicates the objects to be write. diff --git a/interfaces/inner_api/src/form_provider_stub.cpp b/interfaces/inner_api/src/form_provider_stub.cpp index 1df2fb02e6..92c5e2d868 100644 --- a/interfaces/inner_api/src/form_provider_stub.cpp +++ b/interfaces/inner_api/src/form_provider_stub.cpp @@ -44,16 +44,8 @@ FormProviderStub::FormProviderStub() &FormProviderStub::HandleAcquireState; memberFuncMap_[static_cast(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_SHARE_FOMR_INFO)] = &FormProviderStub::HandleAcquireShareFormData; -<<<<<<< HEAD -<<<<<<< HEAD -======= memberFuncMap_[static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_SIZE_CHANGE)] = &FormProviderStub::HandleNotifyFormSizeChaned; ->>>>>>> d6ccdb1... clean_temp+++ -======= - memberFuncMap_[static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_SIZE_CHANGE)] = - &FormProviderStub::HandleNotifyFormSizeChaned; ->>>>>>> d6ccdb1... clean_temp+++ } FormProviderStub::~FormProviderStub() diff --git a/interfaces/kits/native/include/form_mgr.h b/interfaces/kits/native/include/form_mgr.h index ef2cfb399c..01265f9624 100644 --- a/interfaces/kits/native/include/form_mgr.h +++ b/interfaces/kits/native/include/form_mgr.h @@ -392,6 +392,15 @@ public: */ bool CheckFMSReady(); + /** + * @brief notify form to size changed with formId and newDimension, send formId and new Dimension to form manager service. + * @param formId The Id of the forms to delete. + * @param newDimension the newDimension of the form to reSize + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ + int NotifyFormSizeChanged(const int64_t formId, std::string newDimension, const sptr &callerToken); + private: /** * @brief Connect form manager service. diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index c01c63acd9..03bdaf8913 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -366,8 +366,8 @@ int FormMgr::SetNextRefreshTime(const int64_t formId, const int64_t nextTime) { HILOG_INFO("%{public}s called.", __func__); - if (nextTime < (Constants::MIN_NEXT_TIME / Constants::SEC_PER_MIN)) { - HILOG_ERROR("next time less than 5 mins"); + if (nextTime < Constants::MIN_NEXT_TIME) { + HILOG_ERROR("next time less than 300 seconds."); return ERR_APPEXECFWK_FORM_INVALID_REFRESH_TIME; } @@ -981,5 +981,48 @@ bool FormMgr::CheckFMSReady() return true; } + +/** + * @brief Resize forms with formId and newDimension, send formId and new Dimension to form manager service. + * @param formId The Id of the forms to delete. + * @param newDimension the newDimension of the form to reSize + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimension, const sptr &callerToken) +{ + HILOG_INFO("%{public}s called.", __func__); + // check fms recover status + if (FormMgr::GetRecoverStatus() == Constants::IN_RECOVERING) { + HILOG_ERROR("%{public}s error, form is in recover status, can't do action on form.", __func__); + return ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR; + } + + // check formId + if (formId <= 0) { + HILOG_ERROR("%{public}s error, the passed in formId can't be negative or zero.", __func__); + return ERR_APPEXECFWK_FORM_INVALID_FORM_ID; + } + + // check new Dimension + int32_t dimensionNum = 0; + // for(std::map::iterator it = Constants::DIMENSION_MAP.begin(); it != Constants::DIMENSION_MAP.end(); it++) + // { + // if(it->second == newDimension) + // dimensionNum = it->first; + // } + if(dimensionNum == 0) + { + HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); + return ERR_APPEXECFWK_FORM_INVALID_FORM_ID; // errorCode + } + + int errCode = Connect(); + if (errCode != ERR_OK) { + HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode); + return errCode; + } + return remoteProxy_->NotifyFormSizeChanged(formId, dimensionNum, callerToken); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index e46abfd06e..6a42255dd3 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -322,6 +322,15 @@ public: * @return Returns ERR_OK on success, others on failure. */ int UpdateRouterAction(const int64_t formId, std::string &action); + + /** + * @brief Notify the form to change size. + * @param formId Indicates the ID of the form. + * @param dimensionNum The new dimension num of the form. + * @param callerToken Host client. + * @return Returns ERR_OK on success, others on failure. + */ + int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken); private: /** * @brief Get form configure info. diff --git a/services/include/form_mgr_service.h b/services/include/form_mgr_service.h index f7e63e1f8b..696fba0079 100644 --- a/services/include/form_mgr_service.h +++ b/services/include/form_mgr_service.h @@ -358,6 +358,15 @@ public: * @return Returns ERR_OK on success, others on failure. */ int Dump(int fd, const std::vector &args) override; + + /** + * @brief notify that the form size has been changed + * @param formId the formId + * @param dimensionNum the new dimensionNum of the form + * @param callerToken token of the ability that initially calls this function. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; private: enum class DumpKey { KEY_DUMP_HELP = 0, diff --git a/services/src/form_mgr_service.cpp b/services/src/form_mgr_service.cpp index ffee67dfb9..597edf7138 100644 --- a/services/src/form_mgr_service.cpp +++ b/services/src/form_mgr_service.cpp @@ -913,5 +913,25 @@ void FormMgrService::HiDumpFormInfoByFormId(const std::string &args, std::string } DumpFormInfoByFormId(formId, result); } + +/** + * @brief notify that the form size has been changed + * @param formId the formId + * @param dimensionNum the new dimensionNum of the form + * @param callerToken token of the ability that initially calls this function. + * @return Returns ERR_OK on success, others on failure. + */ +int32_t FormMgrService::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) +{ + HILOG_INFO("%{public}s called.", __func__); + + ErrCode ret = CheckFormPermission(); + if (ret != ERR_OK) { + HILOG_ERROR("%{public}s fail, release form permission denied", __func__); + return ret; + } + + return FormMgrAdapter::GetInstance().NotifyFormSizeChanged(formId, dimensionNum, callerToken); +} } // namespace AppExecFwk } // namespace OHOS -- Gitee From 936e1e62df5ac2cb84bca2c71f98fe425ac4d0de Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Thu, 11 Aug 2022 09:54:11 +0800 Subject: [PATCH 05/31] temp4 Signed-off-by: lin_xiangrong Change-Id: Ib7596d5de29067487b3e31b67977978331f63ecf --- BUILD.gn | 1 + interfaces/inner_api/include/form_constants.h | 2 +- .../include/form_provider_interface.h | 13 +++ .../inner_api/include/form_provider_proxy.h | 10 ++ .../inner_api/include/form_provider_stub.h | 7 +- .../form_notify_size_change_connection.h | 51 ++++++++++ services/include/form_task_mgr.h | 7 ++ services/src/form_mgr_adapter.cpp | 94 +++++++++++++++++++ .../form_notify_size_change_connection.cpp | 63 +++++++++++++ services/src/form_task_mgr.cpp | 48 ++++++++++ 10 files changed, 294 insertions(+), 2 deletions(-) create mode 100644 services/include/form_notify_size_change_connection.h create mode 100644 services/src/form_notify_size_change_connection.cpp diff --git a/BUILD.gn b/BUILD.gn index 2653850333..e936e768f6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -60,6 +60,7 @@ ohos_shared_library("libfms") { "services/src/form_mgr_adapter.cpp", "services/src/form_mgr_service.cpp", "services/src/form_msg_event_connection.cpp", + "services/src/form_notify_size_change_connection.cpp", "services/src/form_provider_mgr.cpp", "services/src/form_refresh_connection.cpp", "services/src/form_refresh_limiter.cpp", diff --git a/interfaces/inner_api/include/form_constants.h b/interfaces/inner_api/include/form_constants.h index 557f6d62f0..1eeadace8e 100644 --- a/interfaces/inner_api/include/form_constants.h +++ b/interfaces/inner_api/include/form_constants.h @@ -128,7 +128,7 @@ namespace Constants { {5, "2*1"} }; constexpr int32_t DIM_KEY_MIN = 1; - constexpr int32_t DIM_KEY_MAX = 4; + constexpr int32_t DIM_KEY_MAX = 5; constexpr int32_t MAX_FORMS = 512; constexpr int32_t MAX_RECORD_PER_APP = 256; constexpr int32_t MAX_TEMP_FORMS = 256; diff --git a/interfaces/inner_api/include/form_provider_interface.h b/interfaces/inner_api/include/form_provider_interface.h index 2da2ba8950..0ba870d9cb 100644 --- a/interfaces/inner_api/include/form_provider_interface.h +++ b/interfaces/inner_api/include/form_provider_interface.h @@ -113,6 +113,16 @@ public: */ virtual int AcquireState(const Want &wantArg, const std::string &provider, const Want &want, const sptr &callerToken) = 0; + + /** + * @brief Notify provider when the form want to change the size. + * @param formId The Id of the form to update. + * @param want the want of the request containing the new formDimensionNum. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, + const sptr &callerToken) = 0; /** * @brief Notify provider when the form want to change the size. @@ -165,6 +175,9 @@ public: // ipc id for Acquire provider share form info (3059) FORM_ACQUIRE_PROVIDER_SHARE_FOMR_INFO, + + // ipc id for notifying the form size change (3060) + FORM_PROVIDER_NOTIFY_FORM_SIZE_CHANGE, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/include/form_provider_proxy.h b/interfaces/inner_api/include/form_provider_proxy.h index ac59be0cb8..2bf4e08cba 100644 --- a/interfaces/inner_api/include/form_provider_proxy.h +++ b/interfaces/inner_api/include/form_provider_proxy.h @@ -115,6 +115,16 @@ public: */ virtual int AcquireState(const Want &wantArg, const std::string &provider, const Want &want, const sptr &callerToken) override; + + /** + * @brief Notify provider when the form want to change the size. + * @param formId The Id of the form to update. + * @param want the want of the request containing the new form dimensionNum. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, + const sptr &callerToken) override; /** * @brief Acquire to share form information data. This is sync API. diff --git a/interfaces/inner_api/include/form_provider_stub.h b/interfaces/inner_api/include/form_provider_stub.h index 76533c78c5..b63c8ef7a7 100644 --- a/interfaces/inner_api/include/form_provider_stub.h +++ b/interfaces/inner_api/include/form_provider_stub.h @@ -104,11 +104,16 @@ private: /** * @brief Handle request provider share form info message. + */ + int32_t HandleAcquireShareFormData(MessageParcel &data, MessageParcel &reply); + + /** + * @brief handle the form size change. * @param data input param. * @param reply output param. * @return Returns ERR_OK on success, others on failure. */ - int32_t HandleAcquireShareFormData(MessageParcel &data, MessageParcel &reply); + int HandleNotifyFormSizeChaned(MessageParcel &data, MessageParcel &reply); private: using FormProviderFunc = int32_t (FormProviderStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/services/include/form_notify_size_change_connection.h b/services/include/form_notify_size_change_connection.h new file mode 100644 index 0000000000..b3ee3c5bde --- /dev/null +++ b/services/include/form_notify_size_change_connection.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FORM_FWK_FORM_NOTIFY_SIZE_CHANGE_CONNECTION_H +#define OHOS_FORM_FWK_FORM_NOTIFY_SIZE_CHANGE_CONNECTION_H + +#include "form_ability_connection.h" + +namespace OHOS { +namespace AppExecFwk { + +/** + * @class FormNotifySizeChangedConnection + * Form notify to change size connection stub + */ +class FormNotifySizeChangedConnection : public FormAbilityConnection { +public: + FormNotifySizeChangedConnection(const int64_t formId, const int32_t dimensionNum, + const std::string &bundleName, const std::string &abilityName); + virtual ~FormNotifySizeChangedConnection() = default; + + /** + * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. + * @param element service ability's ElementName. + * @param remoteObject the session proxy of service ability. + * @param resultCode ERR_OK on success, others on failure. + */ + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + +private: + int64_t formId_ = -1; + int32_t dimensionNum_ = -1; + DISALLOW_COPY_AND_MOVE(FormNotifySizeChangedConnection); +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif //OHOS_FORM_FWK_FORM_NOTIFY_SIZE_CHANGE_CONNECTION_H diff --git a/services/include/form_task_mgr.h b/services/include/form_task_mgr.h index 5cb6e0fe7c..f49763d436 100644 --- a/services/include/form_task_mgr.h +++ b/services/include/form_task_mgr.h @@ -178,7 +178,10 @@ public: * @param result The error code of this share. */ void PostFormShareSendResponse(int64_t formShareRequestCode, int32_t result); +<<<<<<< HEAD +======= +>>>>>>> 4125775... clean_temp+ /** * @brief Post notify form size change to form provider(task). * @param formId The form id. @@ -187,7 +190,11 @@ public: * @param remoteObject Form provider proxy object. */ void PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, +<<<<<<< HEAD const Want &want, const sptr &remoteObject); +======= + const Want &want, const sptr &remoteObject) +>>>>>>> 4125775... clean_temp+ private: /** * @brief Acquire form data from form provider. diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 4d150353cc..c3dbd970f4 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -24,6 +24,7 @@ #endif #include "form_acquire_connection.h" #include "form_acquire_state_connection.h" +#include "form_notify_size_change_connection.h" #include "form_ams_helper.h" #include "form_bms_helper.h" #include "form_cache_mgr.h" @@ -2393,5 +2394,98 @@ bool FormMgrAdapter::IsRequestPublishFormSupported() } return true; } + +/** + * @brief Notify the form to change size. + * @param formId Indicates the ID of the form. + * @param dimensionNum The new dimension num of the form. + * @param callerToken Host client. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) +{ + HILOG_INFO("%{public}s called.", __func__); + if (formId <= 0 || callerToken == nullptr) { + HILOG_ERROR("%{public}s, releaseForm invalid param", __func__); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + + FormRecord dbRecord; + if (FormDbCache::GetInstance().GetDBRecord(formId, dbRecord) != ERR_OK) { + HILOG_ERROR("%{public}s, not exist such db form:%{public}" PRId64 "", __func__, formId); + return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; + } + + FormRecord record; + FormDataMgr::GetInstance().GetFormRecord(formId, record); + + if(dimensionNum == record.specification) + { + HILOG_ERROR("This form want to change to the same size."); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; /*errorCode*/ + } + + std::vector formInfos {}; + ErrCode errCode = FormInfoMgr::GetInstance().GetFormsInfoByModule(record.bundleName, record.moduleName, formInfos); + if (errCode != ERR_OK) { + HILOG_ERROR("GetFormsInfoByModule, failed to get form config info."); + return ERR_APPEXECFWK_FORM_GET_INFO_FAILED; + } + + FormInfo formInfo; + if(record.formName.empty()) + { + for (const auto &form : formInfos) { + if (form.defaultFlag) { + formInfo = form; + HILOG_DEBUG("GetFormInfo end."); + break; + } + } + } else { + for (const auto &form : formInfos) { + if (form.name == record.formName) { + formInfo = form; + HILOG_DEBUG("GetFormInfo end."); + break; + } + } + } + + bool isResizeable = true; + /*bool isResizeable = formInfo.isResizeble;*/ + if(!isResizeable) + { + HILOG_ERROR("This form isn't resizeable, failed to changed form size."); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; /*errorCode*/ + } + + bool isSupportFormDimension = false; + for(auto iter : formInfo.supportDimensions) + { + if(dimensionNum == iter) + isSupportFormDimension = true; + } + if(!isSupportFormDimension) + { + HILOG_ERROR("This form soesn't support the new dimension."); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; /*errorCode*/ + } + + sptr formNotifySizeChangedConnection = + new FormNotifySizeChangedConnection(formId, dimensionNum, record.bundleName, record.abilityName); + + Want want; + want.AddFlags(Want::FLAG_ABILITY_FORM_ENABLED); + want.SetElementName(record.bundleName, record.abilityName); + ErrCode errorCode = FormAmsHelper::GetInstance().ConnectServiceAbility(want, formNotifySizeChangedConnection); + if (errorCode != ERR_OK) { + HILOG_ERROR("%{public}s fail, ConnectServiceAbility failed.", __func__); + return ERR_APPEXECFWK_FORM_BIND_PROVIDER_FAILED; + } + + return ERR_OK; +} + } // namespace AppExecFwk } // namespace OHOS diff --git a/services/src/form_notify_size_change_connection.cpp b/services/src/form_notify_size_change_connection.cpp new file mode 100644 index 0000000000..345ea85c63 --- /dev/null +++ b/services/src/form_notify_size_change_connection.cpp @@ -0,0 +1,63 @@ + +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "form_notify_size_change_connection.h" + +#include + +#include "form_constants.h" +#include "form_supply_callback.h" +#include "form_task_mgr.h" +#include "hilog_wrapper.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +FormNotifySizeChangedConnection::FormNotifySizeChangedConnection(const int64_t formId, const int32_t dimensionNum, + const std::string &bundleName, const std::string &abilityName) + : formId_(formId), dimensionNum_(dimensionNum) +{ + SetProviderKey(bundleName, abilityName); +} +/** + * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. + * + * @param element Service ability's ElementName. + * @param remoteObject The session proxy of service ability. + * @param resultCode ERR_OK on success, others on failure. + */ +void FormNotifySizeChangedConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) +{ + HILOG_INFO("%{public}s called.", __func__); + if (resultCode != ERR_OK) { + HILOG_ERROR("%{public}s, abilityName:%{public}s, formId:%{public}" PRId64 ", resultCode:%{public}d", + __func__, element.GetAbilityName().c_str(), formId_, resultCode); + return; + } + FormSupplyCallback::GetInstance()->AddConnection(this); + int32_t dimensionNum = dimensionNum_; + if(dimensionNum == -1) + { + HILOG_ERROR("%{public}s error, the dimension info is wrong", __func__); + return; + } + Want newWant; + newWant.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId()); + FormTaskMgr::GetInstance().PostNotifyFormSizeChanged(formId_, dimensionNum, newWant, remoteObject); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/src/form_task_mgr.cpp b/services/src/form_task_mgr.cpp index 53c97fb3cc..73559c6699 100644 --- a/services/src/form_task_mgr.cpp +++ b/services/src/form_task_mgr.cpp @@ -328,6 +328,26 @@ void FormTaskMgr::PostFormShareSendResponse(int64_t formShareRequestCode, int32_ HILOG_INFO("%{public}s end", __func__); } +/** + * @brief Post notify form size change to form provider(task). + * @param formId The form id. + * @param want The want of notifyFormSizeChanged. + * @param dimensionNum The dimension id of the new form. + * @param remoteObject Form provider proxy object. + */ +void FormTaskMgr::PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const Want &want, const sptr &remoteObject) +{ + if (eventHandler_ == nullptr) { + HILOG_ERROR("%{public}s fail, event handler invalidate", __func__); + return; + } + auto notifyFormSizeChangedFunc = [formId, dimensionNum, want, remoteObject]() { + FormTaskMgr::GetInstance().NotifyProviderFormSizeChanged(formId,dimensionNum,want,remoteObject); + }; + eventHandler_->PostTask(notifyFormSizeChangedFunc, Form_TASK_DELAY_TIME); +} + /** * @brief Acquire form data from form provider. * @param formId The Id of the from. @@ -621,6 +641,34 @@ void FormTaskMgr::AcquireStateBack(AppExecFwk::FormState state, const AAFwk::Wan HILOG_INFO("%{public}s end", __func__); } +/** + * @brief Handle notify form size change to form provider. + * @param formId The form id. + * @param want The want of notifyFormSizeChanged. + * @param dimensionNum The dimension id of the new form. + * @param remoteObject Form provider proxy object. + */ +void FormTaskMgr::NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const Want &want, const sptr &remoteObject) +{ + HILOG_INFO("%{public}s called.", __func__); + + long connectId = want.GetLongParam(Constants::FORM_CONNECT_ID, 0); + sptr formProviderProxy = iface_cast(remoteObject); + if (formProviderProxy == nullptr) { + FormSupplyCallback::GetInstance()->RemoveConnection(connectId); + HILOG_ERROR("%{public}s fail, failed to get formProviderProxy", __func__); + return; + } + + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, dimensionNum); + int error = formProviderProxy->NotifyFormSizeChanged(formId, want, FormSupplyCallback::GetInstance()); + if (error != ERR_OK) { + FormSupplyCallback::GetInstance()->RemoveConnection(connectId); + HILOG_ERROR("%{public}s fail, Failed to notify form update.", __func__); + } +} + /** * @brief Create form data for form host. * @param formId The Id of the form. -- Gitee From 42a1550c3371429883ed534bcf2c6bced1680e7c Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Mon, 15 Aug 2022 14:48:48 +0800 Subject: [PATCH 06/31] temp5 Signed-off-by: lin_xiangrong Change-Id: I0b1d24652f6750e0aedf1e266f2629df7276e452 --- interfaces/inner_api/include/form_constants.h | 1 + .../inner_api/include/form_host_proxy.h | 7 +++ interfaces/inner_api/include/form_host_stub.h | 8 ++++ interfaces/inner_api/include/form_js_info.h | 1 + interfaces/inner_api/src/form_host_proxy.cpp | 28 +++++++++++ interfaces/inner_api/src/form_js_info.cpp | 5 ++ .../kits/native/include/form_host_client.h | 8 ++++ .../kits/native/src/form_host_client.cpp | 27 +++++++++++ services/include/form_host_callback.h | 8 ++++ services/include/form_provider_mgr.h | 8 ++++ services/include/form_task_mgr.h | 16 +++++++ services/src/form_host_callback.cpp | 26 ++++++++++ services/src/form_host_record.cpp | 15 ++++++ services/src/form_provider_mgr.cpp | 4 ++ services/src/form_supply_callback.cpp | 2 + services/src/form_task_mgr.cpp | 47 +++++++++++++++++++ tempfile | 0 17 files changed, 211 insertions(+) create mode 100644 tempfile diff --git a/interfaces/inner_api/include/form_constants.h b/interfaces/inner_api/include/form_constants.h index 1eeadace8e..ce7e58c541 100644 --- a/interfaces/inner_api/include/form_constants.h +++ b/interfaces/inner_api/include/form_constants.h @@ -149,6 +149,7 @@ namespace Constants { constexpr int32_t ACQUIRE_TYPE_RECREATE_FORM = 2; constexpr int32_t ACQUIRE_TYPE_RESIZE_FORM = 3; + constexpr int32_t DELETE_FORM = 3; constexpr int32_t RELEASE_FORM = 8; constexpr int32_t RELEASE_CACHED_FORM = 9; diff --git a/interfaces/inner_api/include/form_host_proxy.h b/interfaces/inner_api/include/form_host_proxy.h index 0496832ecf..e7ce7ec3ef 100644 --- a/interfaces/inner_api/include/form_host_proxy.h +++ b/interfaces/inner_api/include/form_host_proxy.h @@ -65,6 +65,13 @@ public: * @param result Share form result. */ void OnShareFormResponse(int64_t requestCode, int32_t result) override; + + /** + * @brief Request to give back a Form after size changed. + * @param formInfo Form info. + */ + virtual void OnSizeChanged(const FormJsInfo &formInfo) override; + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/interfaces/inner_api/include/form_host_stub.h b/interfaces/inner_api/include/form_host_stub.h index 698963c474..4b8a5efa90 100644 --- a/interfaces/inner_api/include/form_host_stub.h +++ b/interfaces/inner_api/include/form_host_stub.h @@ -80,6 +80,14 @@ private: * @return Returns ERR_OK on success, others on failure. */ int32_t HandleOnShareFormResponse(MessageParcel &data, MessageParcel &reply); + + /** + * @brief handle OnSizeChanged message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int HandleOnSizeChanged(MessageParcel &data, MessageParcel &reply); private: using FormHostFunc = int32_t (FormHostStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/include/form_js_info.h b/interfaces/inner_api/include/form_js_info.h index d6e8ffff57..9b5db1fc49 100644 --- a/interfaces/inner_api/include/form_js_info.h +++ b/interfaces/inner_api/include/form_js_info.h @@ -39,6 +39,7 @@ struct FormJsInfo : public Parcelable { std::string formData; std::map> imageDataMap; FormProviderData formProviderData; + int32_t specification; std::string htmlPath; std::string cssPath; diff --git a/interfaces/inner_api/src/form_host_proxy.cpp b/interfaces/inner_api/src/form_host_proxy.cpp index 59841d5123..fe3a360cf4 100644 --- a/interfaces/inner_api/src/form_host_proxy.cpp +++ b/interfaces/inner_api/src/form_host_proxy.cpp @@ -75,6 +75,34 @@ void FormHostProxy::OnUpdate(const FormJsInfo &formInfo) } } +/** + * @brief Request to give back a Form after form size changed. + * @param formInfo Form info. + */ +void FormHostProxy::OnSizeChanged(const FormJsInfo &formInfo) +{ + int error; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + } + + if (!data.WriteParcelable(&formInfo)) { + HILOG_ERROR("%{public}s, failed to write formInfo", __func__); + } + + error = Remote()->SendRequest( + static_cast(IFormHost::Message::FORM_HOST_ON_SIZE_CHANGED), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + } +} /** * @brief Form provider is uninstalled diff --git a/interfaces/inner_api/src/form_js_info.cpp b/interfaces/inner_api/src/form_js_info.cpp index f5e0833d74..924aae144b 100644 --- a/interfaces/inner_api/src/form_js_info.cpp +++ b/interfaces/inner_api/src/form_js_info.cpp @@ -25,6 +25,7 @@ bool FormJsInfo::ReadFromParcel(Parcel &parcel) formName = Str16ToStr8(parcel.ReadString16()); bundleName = Str16ToStr8(parcel.ReadString16()); abilityName = Str16ToStr8(parcel.ReadString16()); + specification = parcel.ReadInt32(); formTempFlag = parcel.ReadBool(); jsFormCodePath = Str16ToStr8(parcel.ReadString16()); @@ -76,6 +77,10 @@ bool FormJsInfo::Marshalling(Parcel &parcel) const if (!parcel.WriteString16(Str8ToStr16(abilityName))) { return false; } + // write specification + if (!parcel.WriteInt32(specification)) { + return false; + } // write tempFlag if (!parcel.WriteBool(formTempFlag)) { diff --git a/interfaces/kits/native/include/form_host_client.h b/interfaces/kits/native/include/form_host_client.h index 33ab322377..95cc757657 100644 --- a/interfaces/kits/native/include/form_host_client.h +++ b/interfaces/kits/native/include/form_host_client.h @@ -138,6 +138,14 @@ public: * @param requestCode The request code of this share form. */ void RemoveShareFormCallback(int64_t requestCode); + + /** + * @brief Request to give back a form after form size changed. + * @param formJsInfo Form js info. + * @return none. + */ + virtual void OnSizeChanged(const FormJsInfo &formJsInfo); + private: static std::mutex instanceMutex_; static sptr instance_; diff --git a/interfaces/kits/native/src/form_host_client.cpp b/interfaces/kits/native/src/form_host_client.cpp index a5a7296bee..4c057ccdcd 100644 --- a/interfaces/kits/native/src/form_host_client.cpp +++ b/interfaces/kits/native/src/form_host_client.cpp @@ -316,5 +316,32 @@ void FormHostClient::RemoveShareFormCallback(int64_t requestCode) } HILOG_INFO("%{public}s end.", __func__); } + +/** + * @brief Request to give back a form after form size changed. + * @param formJsInfo Form js info. + * @return none. + */ +void FormHostClient::OnSizeChanged(const FormJsInfo &formJsInfo) +{ + HILOG_INFO("%{public}s called.", __func__); + HILOG_INFO("Imamge number is %{public}zu.", formJsInfo.imageDataMap.size()); + int64_t formId = formJsInfo.formId; + if (formId < 0) { + HILOG_ERROR("%{public}s error, the passed form id can't be negative.", __func__); + return; + } + std::lock_guard lock(callbackMutex_); + auto iter = formCallbackMap_.find(formId); + if (iter == formCallbackMap_.end()) { + HILOG_ERROR("%{public}s error, not find formId:%{public}s.", __func__, std::to_string(formId).c_str()); + return; + } + for (const auto& callback : iter->second) { + HILOG_INFO("%{public}s, formId: %{public}" PRId64 ", jspath: %{public}s, data: %{public}s", + __func__, formId, formJsInfo.jsFormCodePath.c_str(), formJsInfo.formData.c_str()); + callback->ProcessFormUpdate(formJsInfo); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_host_callback.h b/services/include/form_host_callback.h index 7e752632a5..4f85ecfb38 100644 --- a/services/include/form_host_callback.h +++ b/services/include/form_host_callback.h @@ -51,6 +51,14 @@ public: * @return Returns ERR_OK on success, others on failure. */ void OnUpdate(const int64_t formId, const FormRecord &record, const sptr &callerToken); + /** + * @brief Request to give back a Form after size changed. + * @param formId The Id of the form whose size is changed. + * @param record Form info. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ + void OnSizeChanged(const int64_t formId, const FormRecord &record, const sptr &callerToken); /** * @brief Form provider is uninstalled. diff --git a/services/include/form_provider_mgr.h b/services/include/form_provider_mgr.h index 61f1542de6..83b627219e 100644 --- a/services/include/form_provider_mgr.h +++ b/services/include/form_provider_mgr.h @@ -58,6 +58,14 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode UpdateForm(const int64_t formId, FormRecord &formRecord, const FormProviderData &formProviderData); + /** + * @brief handle for resize form event from provider. + * @param formId The id of the form. + * *@param want The want of the form to resize. + * @param providerFormInfo provider form info. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode ResizeForm(const int64_t formId, const Want &want, const FormProviderInfo &formProviderInfo); /** * @brief Refresh form. * @param formId The form id. diff --git a/services/include/form_task_mgr.h b/services/include/form_task_mgr.h index f49763d436..4e06b27eda 100644 --- a/services/include/form_task_mgr.h +++ b/services/include/form_task_mgr.h @@ -119,6 +119,14 @@ public: */ void PostUpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr &remoteObject); + /** + * @brief Post form data to form host(task) when change form size. + * @param formId The Id of the form. + * @param record form record. + * @param remoteObject Form provider proxy object. + */ + void PostSizeChangedTaskToHost(const int64_t formId, const FormRecord &record, const sptr &remoteObject); + /** * @brief Handel form host died(task). * @param remoteHost Form host proxy object. @@ -266,6 +274,14 @@ private: */ void UpdateTaskToHost(const int64_t formId, const FormRecord &record, const sptr &remoteObject); + /** + * @brief Post form data to form host when change form size. + * @param formId The Id of the form. + * @param record form record. + * @param remoteObject Form provider proxy object. + */ + void SizeChangedTaskToHost(const int64_t formId, const FormRecord &record, const sptr &remoteObject); + /** * @brief Handle form host died. * @param remoteHost Form host proxy object. diff --git a/services/src/form_host_callback.cpp b/services/src/form_host_callback.cpp index 70a3c2cc6e..a9615b6160 100644 --- a/services/src/form_host_callback.cpp +++ b/services/src/form_host_callback.cpp @@ -61,6 +61,32 @@ void FormHostCallback::OnUpdate(const int64_t formId, const FormRecord &record, FormTaskMgr::GetInstance().PostUpdateTaskToHost(formId, record, callerToken); } +/** + * @brief Request to give back a Form after size changed. + * @param formId The Id of the form whose size is changed. + * @param record Form info. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ +void FormHostCallback::OnSizeChanged(const int64_t formId, const FormRecord &record, const sptr &callerToken) +{ + HILOG_INFO("%{public}s start.", __func__); + + // check formId + if (formId < 0) { + HILOG_ERROR("%{public}s: OnSizeChanged invalid param, formId:%{public}" PRId64 ".", __func__, formId); + return; + } + + if (callerToken == nullptr) { + HILOG_ERROR("%{public}s: callerToken can not be NULL", __func__); + return; + } + + // post updateTask to host + FormTaskMgr::GetInstance().PostSizeChangedTaskToHost(formId, record, callerToken); +} + /** * @brief Form provider is uninstalled * @param formIds The Id list of the forms. diff --git a/services/src/form_host_record.cpp b/services/src/form_host_record.cpp index 7b06ac66ad..23d3e91bea 100644 --- a/services/src/form_host_record.cpp +++ b/services/src/form_host_record.cpp @@ -170,6 +170,21 @@ void FormHostRecord::OnUpdate(int64_t id, const FormRecord &record) formHostCallback_->OnUpdate(id, record, formHostClient_); } +/** + * @brief Send form data after size changed to form host. + * @param formId The Id of the form. + * @param record Form record. + */ +void FormHostRecord::OnSizeChanged(int64_t formId, const FormRecord &record) +{ + HILOG_DEBUG("FormHostRecord OnSizeChanged"); + if (formHostCallback_ == nullptr) { + HILOG_ERROR("%{public}s: formHostCallback_ can not be NULL", __func__); + return; + } + formHostCallback_->OnSizeChanged(formId, record, formHostClient_); +} + /** * @brief Send form uninstall message to form host. * @param formIds The id list of the form. diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index e17057fc10..02c41fc916 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -118,7 +118,11 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons return ERR_APPEXECFWK_FORM_INVALID_PARAM; } +<<<<<<< HEAD formRecord.specification = dimensionId; +======= + FormRecord.specfication = dimensionId; +>>>>>>> 6821172... clean_temp // db save FormHostRecord clientHost; diff --git a/services/src/form_supply_callback.cpp b/services/src/form_supply_callback.cpp index 13cfac71fc..39af026771 100644 --- a/services/src/form_supply_callback.cpp +++ b/services/src/form_supply_callback.cpp @@ -75,6 +75,8 @@ int FormSupplyCallback::OnAcquire(const FormProviderInfo &formProviderInfo, cons return FormProviderMgr::GetInstance().AcquireForm(formId, formProviderInfo); case Constants::ACQUIRE_TYPE_RECREATE_FORM: return FormProviderMgr::GetInstance().UpdateForm(formId, formProviderInfo); + case Constants::ACQUIRE_TYPE_RESIZE_FORM: + return FormProviderMgr::GetInstance().ResizeForm(formId, want, formProviderInfo); default: HILOG_WARN("%{public}s warning, onAcquired type: %{public}d", __func__, type); } diff --git a/services/src/form_task_mgr.cpp b/services/src/form_task_mgr.cpp index 73559c6699..8bc12a1f2f 100644 --- a/services/src/form_task_mgr.cpp +++ b/services/src/form_task_mgr.cpp @@ -171,6 +171,29 @@ void FormTaskMgr::PostUpdateTaskToHost(const int64_t formId, const FormRecord &r eventHandler_->PostTask(updateTaskToHostFunc, FORM_TASK_DELAY_TIME); } +/** + * @brief Post form data to form host(task) when change form size. + * @param formId The Id of the form. + * @param record form record. + * @param remoteObject Form provider proxy object. + */ +void FormTaskMgr::PostSizeChangedTaskToHost(const int64_t formId, const FormRecord &record, + const sptr &remoteObject) +{ + HILOG_INFO("%{public}s called.", __func__); + + if (eventHandler_ == nullptr) { + HILOG_ERROR("%{public}s fail, event handler invalidate.", __func__); + return; + } + + HILOG_DEBUG("%{public}s, post the task of sizeChangedTaskToHostFunc.", __func__); + auto sizeChangedTaskToHostFunc = [formId, record, remoteObject]() { + FormTaskMgr::GetInstance().SizeChangedTaskToHost(formId, record, remoteObject); + }; + eventHandler_->PostTask(sizeChangedTaskToHostFunc, FORM_TASK_DELAY_TIME); +} + /** * @brief Acquire form data from form provider. * @param formId The Id of the form. @@ -508,6 +531,29 @@ void FormTaskMgr::UpdateTaskToHost(const int64_t formId, const FormRecord &recor HILOG_INFO("%{public}s end.", __func__); } +/** + * @brief Post form data to form host when change form size. + * @param formId The Id of the form. + * @param record form record. + * @param remoteObject Form provider proxy object. + */ +void FormTaskMgr::SizeChangedTaskToHost(const int64_t formId, const FormRecord &record, + const sptr &remoteObject) +{ + HILOG_INFO("%{public}s start.", __func__); + + sptr remoteFormHost = iface_cast(remoteObject); + if (remoteFormHost == nullptr) { + HILOG_ERROR("%{public}s fail, Failed to get form host proxy.", __func__); + return; + } + + HILOG_DEBUG("%{public}s, FormTaskMgr remoteFormHost OnUpdate.", __func__); + remoteFormHost->OnSizeChanged(CreateFormJsInfo(formId, record)); + + HILOG_INFO("%{public}s end.", __func__); +} + /** * @brief Handle form host died. * @param remoteHost Form host proxy object. @@ -683,6 +729,7 @@ FormJsInfo FormTaskMgr::CreateFormJsInfo(const int64_t formId, const FormRecord form.bundleName = record.bundleName; form.abilityName = record.abilityName; form.formName = record.formName; + form.specification = record.specification; form.formTempFlag = record.formTempFlag; form.jsFormCodePath = record.jsFormCodePath; form.formData = record.formProviderInfo.GetFormDataString(); diff --git a/tempfile b/tempfile new file mode 100644 index 0000000000..e69de29bb2 -- Gitee From 5fda0d88bedfe5975187bc965baf3c3b07533919 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 16 Aug 2022 08:53:08 +0800 Subject: [PATCH 07/31] tempOK Signed-off-by: lin_xiangrong Change-Id: I106fb43c88a77df5996313366b6d530db0872124 --- interfaces/inner_api/include/form_provider_interface.h | 10 ---------- interfaces/inner_api/include/form_provider_proxy.h | 2 +- services/include/form_task_mgr.h | 7 ------- services/src/form_provider_mgr.cpp | 4 ---- services/src/form_task_mgr.cpp | 8 +++++--- 5 files changed, 6 insertions(+), 25 deletions(-) diff --git a/interfaces/inner_api/include/form_provider_interface.h b/interfaces/inner_api/include/form_provider_interface.h index 0ba870d9cb..e762cdd69b 100644 --- a/interfaces/inner_api/include/form_provider_interface.h +++ b/interfaces/inner_api/include/form_provider_interface.h @@ -124,16 +124,6 @@ public: virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, const sptr &callerToken) = 0; - /** - * @brief Notify provider when the form want to change the size. - * @param formId The Id of the form to change size. - * @param want Indicates the structure containing form info. - * @param callerToken Caller ability token. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, - const sptr &callerToken) = 0; - /** * @brief Acquire to share form information data. This is sync API. * @param formId The Id of the from. diff --git a/interfaces/inner_api/include/form_provider_proxy.h b/interfaces/inner_api/include/form_provider_proxy.h index 2bf4e08cba..a5fa5d8b86 100644 --- a/interfaces/inner_api/include/form_provider_proxy.h +++ b/interfaces/inner_api/include/form_provider_proxy.h @@ -124,7 +124,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, - const sptr &callerToken) override; + const sptr &callerToken) override; /** * @brief Acquire to share form information data. This is sync API. diff --git a/services/include/form_task_mgr.h b/services/include/form_task_mgr.h index 4e06b27eda..302d98ffff 100644 --- a/services/include/form_task_mgr.h +++ b/services/include/form_task_mgr.h @@ -186,10 +186,7 @@ public: * @param result The error code of this share. */ void PostFormShareSendResponse(int64_t formShareRequestCode, int32_t result); -<<<<<<< HEAD -======= ->>>>>>> 4125775... clean_temp+ /** * @brief Post notify form size change to form provider(task). * @param formId The form id. @@ -198,11 +195,7 @@ public: * @param remoteObject Form provider proxy object. */ void PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, -<<<<<<< HEAD const Want &want, const sptr &remoteObject); -======= - const Want &want, const sptr &remoteObject) ->>>>>>> 4125775... clean_temp+ private: /** * @brief Acquire form data from form provider. diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index 02c41fc916..e17057fc10 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -118,11 +118,7 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons return ERR_APPEXECFWK_FORM_INVALID_PARAM; } -<<<<<<< HEAD formRecord.specification = dimensionId; -======= - FormRecord.specfication = dimensionId; ->>>>>>> 6821172... clean_temp // db save FormHostRecord clientHost; diff --git a/services/src/form_task_mgr.cpp b/services/src/form_task_mgr.cpp index 8bc12a1f2f..a59699e6e6 100644 --- a/services/src/form_task_mgr.cpp +++ b/services/src/form_task_mgr.cpp @@ -368,7 +368,7 @@ void FormTaskMgr::PostNotifyFormSizeChanged(const int64_t formId, const int32_t auto notifyFormSizeChangedFunc = [formId, dimensionNum, want, remoteObject]() { FormTaskMgr::GetInstance().NotifyProviderFormSizeChanged(formId,dimensionNum,want,remoteObject); }; - eventHandler_->PostTask(notifyFormSizeChangedFunc, Form_TASK_DELAY_TIME); + eventHandler_->PostTask(notifyFormSizeChangedFunc, FORM_TASK_DELAY_TIME); } /** @@ -707,8 +707,10 @@ void FormTaskMgr::NotifyProviderFormSizeChanged(const int64_t formId, const int3 return; } - want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, dimensionNum); - int error = formProviderProxy->NotifyFormSizeChanged(formId, want, FormSupplyCallback::GetInstance()); + Want newWant(want); + newWant.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, dimensionNum); + + int error = formProviderProxy->NotifyFormSizeChanged(formId, newWant, FormSupplyCallback::GetInstance()); if (error != ERR_OK) { FormSupplyCallback::GetInstance()->RemoveConnection(connectId); HILOG_ERROR("%{public}s fail, Failed to notify form update.", __func__); -- Gitee From 77ce1f39063ecc422a6cc8b1554fe39d7770f149 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 16 Aug 2022 18:26:22 +0800 Subject: [PATCH 08/31] temp Signed-off-by: lin_xiangrong Change-Id: Ia846101bcf4d41f68f7defd2f1bb76de079f6e5c --- interfaces/kits/native/src/form_mgr.cpp | 12 ++++++------ services/src/form_mgr_adapter.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index 03bdaf8913..ab0722109f 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -1006,15 +1006,15 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimensio // check new Dimension int32_t dimensionNum = 0; - // for(std::map::iterator it = Constants::DIMENSION_MAP.begin(); it != Constants::DIMENSION_MAP.end(); it++) - // { - // if(it->second == newDimension) - // dimensionNum = it->first; - // } + for(std::map::const_iterator it = Constants::DIMENSION_MAP.begin(); it != Constants::DIMENSION_MAP.end(); it++) + { + if(it->second == newDimension) + dimensionNum = it->first; + } if(dimensionNum == 0) { HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); - return ERR_APPEXECFWK_FORM_INVALID_FORM_ID; // errorCode + return ERR_APPEXECFWK_FORM_INVALID_PARAM; } int errCode = Connect(); diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index c3dbd970f4..9f6fdfde04 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2422,7 +2422,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di if(dimensionNum == record.specification) { HILOG_ERROR("This form want to change to the same size."); - return ERR_APPEXECFWK_FORM_INVALID_PARAM; /*errorCode*/ + return ERR_APPEXECFWK_FORM_INVALID_PARAM; } std::vector formInfos {}; @@ -2457,7 +2457,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di if(!isResizeable) { HILOG_ERROR("This form isn't resizeable, failed to changed form size."); - return ERR_APPEXECFWK_FORM_INVALID_PARAM; /*errorCode*/ + return ERR_APPEXECFWK_FORM_INVALID_PARAM; } bool isSupportFormDimension = false; -- Gitee From f5cb9c642ca582acb1fc402fca609ae190102b92 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Thu, 18 Aug 2022 17:09:07 +0800 Subject: [PATCH 09/31] form_size Signed-off-by: lin_xiangrong Change-Id: Ib2b7ff94a3fd10ab5f159ee67047550fbaf6d276 --- frameworks/js/napi/formHost/native_module.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/js/napi/formHost/native_module.cpp b/frameworks/js/napi/formHost/native_module.cpp index a0ea7460c2..d2621b0d1c 100644 --- a/frameworks/js/napi/formHost/native_module.cpp +++ b/frameworks/js/napi/formHost/native_module.cpp @@ -77,6 +77,7 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("notifyFormsEnableUpdate", NAPI_NotifyFormsEnableUpdate), DECLARE_NAPI_FUNCTION("getAllFormsInfo", NAPI_GetAllFormsInfo), DECLARE_NAPI_FUNCTION("getFormsInfo", NAPI_GetFormsInfo), + DECLARE_NAPI_FUNCTION("NotifyFormSizeChange", NAPI_NotifyFormSizeChanged), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties)); HILOG_INFO("napi_moudule Init end..."); -- Gitee From 492756187a60a20c3abb7ec2c6ff088c8d1cd5b0 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 23 Aug 2022 10:41:09 +0800 Subject: [PATCH 10/31] formResize Signed-off-by: lin_xiangrong Change-Id: I810a707caf6332ed0e15a974705286c898b6b12b --- services/include/form_data_mgr.h | 8 ++++++++ services/src/form_data_mgr.cpp | 20 ++++++++++++++++++++ services/src/form_mgr_adapter.cpp | 6 ------ services/src/form_provider_mgr.cpp | 4 ++-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/services/include/form_data_mgr.h b/services/include/form_data_mgr.h index f9bad5d2f4..43fb70fe98 100644 --- a/services/include/form_data_mgr.h +++ b/services/include/form_data_mgr.h @@ -436,6 +436,14 @@ public: */ ErrCode SetRecordVisible(int64_t matchedFormId, bool isVisible); + /** + * @brief set form specification. + * @param formId form id. + * @param dspecification the specification + * @return Returns true if this function is successfully called; returns false otherwise. + */ + ErrCode SetRecordSpecification(int64_t formId, int32_t specification); + /** * @brief add request publish form info. * @param formId The form id of the form to publish. diff --git a/services/src/form_data_mgr.cpp b/services/src/form_data_mgr.cpp index f533dc5e60..6dd9d839d6 100644 --- a/services/src/form_data_mgr.cpp +++ b/services/src/form_data_mgr.cpp @@ -1304,6 +1304,26 @@ ErrCode FormDataMgr::SetRecordVisible(int64_t matchedFormId, bool isVisible) return ERR_OK; } +/** + * @brief set form specification. + * @param formId form id. + * @param specification the specification + * @return Returns true if this function is successfully called; returns false otherwise. + */ +ErrCode FormDataMgr::SetRecordSpecification(int64_t formId, int32_t specification) +{ + HILOG_INFO("%{public}s, set form specification", __func__); + std::lock_guard lock(formRecordMutex_); + auto info = formRecords_.find(formId); + if (info == formRecords_.end()) { + HILOG_ERROR("%{public}s, form info not find", __func__); + return ERR_APPEXECFWK_FORM_INVALID_FORM_ID; + } + info->second.specification = specification; + HILOG_DEBUG("set specification to %{public}d, formId: %{public}" PRId64 " ", specification, formId); + return ERR_OK; +} + /** * @brief delete forms by userId. * diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 9f6fdfde04..9b6dbb4257 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2410,12 +2410,6 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di return ERR_APPEXECFWK_FORM_INVALID_PARAM; } - FormRecord dbRecord; - if (FormDbCache::GetInstance().GetDBRecord(formId, dbRecord) != ERR_OK) { - HILOG_ERROR("%{public}s, not exist such db form:%{public}" PRId64 "", __func__, formId); - return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; - } - FormRecord record; FormDataMgr::GetInstance().GetFormRecord(formId, record); diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index e17057fc10..3285aa0e53 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -118,8 +118,8 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons return ERR_APPEXECFWK_FORM_INVALID_PARAM; } - formRecord.specification = dimensionId; - // db save + //update the specification of formRecord + FormDataMgr::GetInstance().SetRecordSpecification(formId,dimensionId); FormHostRecord clientHost; bool isGetFormHostRecord = FormDataMgr::GetInstance().GetFormHostRecord(formId, clientHost); -- Gitee From a1e1ab19c4de3df2b23ae52b2ad625e948b73283 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 23 Aug 2022 14:45:52 +0800 Subject: [PATCH 11/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I67c1ca0009a0490a95356f0d681187d55e6fab1f --- .../js/napi/formHost/napi_form_host.cpp | 4 ++-- interfaces/inner_api/include/form_constants.h | 1 - .../inner_api/include/form_host_interface.h | 2 +- .../inner_api/include/form_mgr_interface.h | 6 +++-- interfaces/inner_api/include/form_mgr_proxy.h | 20 +++++++++-------- interfaces/inner_api/include/form_mgr_stub.h | 2 +- interfaces/inner_api/src/form_mgr_proxy.cpp | 6 +++-- interfaces/inner_api/src/form_mgr_stub.cpp | 2 +- .../inner_api/src/form_provider_proxy.cpp | 2 +- interfaces/kits/native/include/form_mgr.h | 3 ++- interfaces/kits/native/src/form_mgr.cpp | 12 +++++----- services/include/form_mgr_service.h | 3 ++- services/src/form_mgr_adapter.cpp | 22 ++++++++----------- tempfile | 0 14 files changed, 44 insertions(+), 41 deletions(-) delete mode 100644 tempfile diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index 6a4f36696d..34685a26cd 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -3465,7 +3465,7 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) .deferred = nullptr, .callback = nullptr, .callbackValue = argv[ARGS_SIZE_TWO], - .code = ERR_APPEXECFWK_FORM_RELEASE_FLG_ERR, //the wrong errorCode + .code = ERR_APPEXECFWK_FORM_INVALID_PARAM, .type = 0 }; @@ -3479,7 +3479,7 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) // Check the value of the formId argument std::string strFormId = GetStringFromNAPI(env, argv[ARGS_SIZE_ZERO]); - int64_t formId; + int64_t formId = 0; HILOG_ERROR("%{public}s, form id ", strFormId.c_str()); if (!ConvertStringToInt64(strFormId, formId)) { AsyncErrMsgCallbackInfo *asyncErrorInfo = new diff --git a/interfaces/inner_api/include/form_constants.h b/interfaces/inner_api/include/form_constants.h index ce7e58c541..1eeadace8e 100644 --- a/interfaces/inner_api/include/form_constants.h +++ b/interfaces/inner_api/include/form_constants.h @@ -149,7 +149,6 @@ namespace Constants { constexpr int32_t ACQUIRE_TYPE_RECREATE_FORM = 2; constexpr int32_t ACQUIRE_TYPE_RESIZE_FORM = 3; - constexpr int32_t DELETE_FORM = 3; constexpr int32_t RELEASE_FORM = 8; constexpr int32_t RELEASE_CACHED_FORM = 9; diff --git a/interfaces/inner_api/include/form_host_interface.h b/interfaces/inner_api/include/form_host_interface.h index 12a9233a06..a7e8645b2f 100644 --- a/interfaces/inner_api/include/form_host_interface.h +++ b/interfaces/inner_api/include/form_host_interface.h @@ -90,7 +90,7 @@ public: // ipc id for share form response(3685) FORM_HOST_ON_SHARE_FORM_RESPONSE, - //ipc id for change form size(3686) + // ipc id for change form size(3686) FORM_HOST_ON_SIZE_CHANGED, }; }; diff --git a/interfaces/inner_api/include/form_mgr_interface.h b/interfaces/inner_api/include/form_mgr_interface.h index 0322db96d8..6e575a9c7d 100644 --- a/interfaces/inner_api/include/form_mgr_interface.h +++ b/interfaces/inner_api/include/form_mgr_interface.h @@ -334,13 +334,15 @@ public: virtual int32_t RecvFormShareInfoFromRemote(const FormShareInfo &info) = 0; /** - * @brief notify form rto change size with formId and newDimension, send formId and new Dimension to form manager service. + * @brief notify form rto change size with formId and newDimension, + * send formId and new Dimension to form manager service. * @param formId The Id of the forms to delete. * @param newDimension the newDimension of the form to reSize * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) = 0; + virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) = 0; enum class Message { // ipc id 1-1000 for kit diff --git a/interfaces/inner_api/include/form_mgr_proxy.h b/interfaces/inner_api/include/form_mgr_proxy.h index 67835536ee..ed553fc42e 100644 --- a/interfaces/inner_api/include/form_mgr_proxy.h +++ b/interfaces/inner_api/include/form_mgr_proxy.h @@ -278,22 +278,24 @@ public: std::vector &formInfos) override; /** - * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. - * The bundle name will be retrieved by form service manager. - * @param moduleName the module that the formInfos have to belong to. - * @param formInfos Return the forms' information of the calling bundle name - * @return Returns ERR_OK on success, others on failure. - */ - int32_t GetFormsInfo(const std::string &moduleName, std::vector &formInfos) override; + * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. + * The bundle name will be retrieved by form service manager. + * @param filter Filter that contains attributes that the formInfos have to have. + * @param formInfos Return the forms' information of the calling bundle name + * @return Returns ERR_OK on success, others on failure. + */ + int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector &formInfos) override; /** - * @brief notify form rto change size with formId and newDimension, send formId and new Dimension to form manager service. + * @brief notify form change size with formId and newDimension, + * send formId and new Dimension to form manager service. * @param formId The Id of the forms to delete. * @param newDimension the newDimension of the form to reSize * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; + virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) override; /** * @brief Check if the request of publishing a form is supported by the host. diff --git a/interfaces/inner_api/include/form_mgr_stub.h b/interfaces/inner_api/include/form_mgr_stub.h index 8bde63d640..6cb7f56645 100644 --- a/interfaces/inner_api/include/form_mgr_stub.h +++ b/interfaces/inner_api/include/form_mgr_stub.h @@ -302,7 +302,7 @@ private: int32_t HandleStartAbility(MessageParcel &data, MessageParcel &reply); /** - * @brief Handle NitifyFormSizeChangde message. + * @brief Handle NotifyFormSizeChanged message. * @param data input param. * @param reply output param. * @return Returns ERR_OK on success, others on failure. diff --git a/interfaces/inner_api/src/form_mgr_proxy.cpp b/interfaces/inner_api/src/form_mgr_proxy.cpp index 237ff7bfcc..00a9769e0e 100644 --- a/interfaces/inner_api/src/form_mgr_proxy.cpp +++ b/interfaces/inner_api/src/form_mgr_proxy.cpp @@ -1134,13 +1134,15 @@ int32_t FormMgrProxy::GetFormsInfo(const std::string &moduleName, std::vector &callerToken) +int FormMgrProxy::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) { MessageParcel data; if (!WriteInterfaceToken(data)) { diff --git a/interfaces/inner_api/src/form_mgr_stub.cpp b/interfaces/inner_api/src/form_mgr_stub.cpp index 75156e2f89..b38bf44325 100644 --- a/interfaces/inner_api/src/form_mgr_stub.cpp +++ b/interfaces/inner_api/src/form_mgr_stub.cpp @@ -915,7 +915,7 @@ int32_t FormMgrStub::HandleNotifyFormSizeChanged(MessageParcel &data, MessagePar { int64_t formId = data.ReadInt64(); sptr client = data.ReadRemoteObject(); - if(client == nullptr) { + if (client == nullptr) { return ERR_APPEXECFWK_PARCEL_ERROR; } int32_t dimensionNum = data.ReadInt32(); diff --git a/interfaces/inner_api/src/form_provider_proxy.cpp b/interfaces/inner_api/src/form_provider_proxy.cpp index 60153401a9..e485b47573 100644 --- a/interfaces/inner_api/src/form_provider_proxy.cpp +++ b/interfaces/inner_api/src/form_provider_proxy.cpp @@ -406,7 +406,7 @@ int FormProviderProxy::AcquireState(const Want &wantArg, const std::string &prov * @return Returns ERR_OK on success, others on failure. */ int FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Want &want, - const sptr &callerToken) + const sptr &callerToken) { MessageParcel data; diff --git a/interfaces/kits/native/include/form_mgr.h b/interfaces/kits/native/include/form_mgr.h index 01265f9624..2471748e50 100644 --- a/interfaces/kits/native/include/form_mgr.h +++ b/interfaces/kits/native/include/form_mgr.h @@ -393,7 +393,8 @@ public: bool CheckFMSReady(); /** - * @brief notify form to size changed with formId and newDimension, send formId and new Dimension to form manager service. + * @brief notify form to size changed with formId and newDimension, + * send formId and new Dimension to form manager service. * @param formId The Id of the forms to delete. * @param newDimension the newDimension of the form to reSize * @param callerToken Caller ability token. diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index ab0722109f..b1d4861218 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -989,7 +989,8 @@ bool FormMgr::CheckFMSReady() * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ -int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimension, const sptr &callerToken) +int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimension, + const sptr &callerToken) { HILOG_INFO("%{public}s called.", __func__); // check fms recover status @@ -1006,13 +1007,12 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimensio // check new Dimension int32_t dimensionNum = 0; - for(std::map::const_iterator it = Constants::DIMENSION_MAP.begin(); it != Constants::DIMENSION_MAP.end(); it++) - { - if(it->second == newDimension) + for (std::map::const_iterator it = Constants::DIMENSION_MAP.begin(); + it != Constants::DIMENSION_MAP.end(); it++) { + if (it->second == newDimension) dimensionNum = it->first; } - if(dimensionNum == 0) - { + if (dimensionNum == 0) { HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } diff --git a/services/include/form_mgr_service.h b/services/include/form_mgr_service.h index 696fba0079..b52ebb54d8 100644 --- a/services/include/form_mgr_service.h +++ b/services/include/form_mgr_service.h @@ -366,7 +366,8 @@ public: * @param callerToken token of the ability that initially calls this function. * @return Returns ERR_OK on success, others on failure. */ - int32_t NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; + int32_t NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) override; private: enum class DumpKey { KEY_DUMP_HELP = 0, diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 9b6dbb4257..ab31e97ad4 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2402,7 +2402,8 @@ bool FormMgrAdapter::IsRequestPublishFormSupported() * @param callerToken Host client. * @return Returns ERR_OK on success, others on failure. */ -int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) +int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) { HILOG_INFO("%{public}s called.", __func__); if (formId <= 0 || callerToken == nullptr) { @@ -2413,8 +2414,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di FormRecord record; FormDataMgr::GetInstance().GetFormRecord(formId, record); - if(dimensionNum == record.specification) - { + if (dimensionNum == record.specification) { HILOG_ERROR("This form want to change to the same size."); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } @@ -2427,8 +2427,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di } FormInfo formInfo; - if(record.formName.empty()) - { + if(record.formName.empty()) { for (const auto &form : formInfos) { if (form.defaultFlag) { formInfo = form; @@ -2446,22 +2445,20 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di } } + //isResizeable is the param of form record bool isResizeable = true; - /*bool isResizeable = formInfo.isResizeble;*/ - if(!isResizeable) - { + + if (!isResizeable) { HILOG_ERROR("This form isn't resizeable, failed to changed form size."); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } bool isSupportFormDimension = false; - for(auto iter : formInfo.supportDimensions) - { + for (auto iter : formInfo.supportDimensions) { if(dimensionNum == iter) isSupportFormDimension = true; } - if(!isSupportFormDimension) - { + if (!isSupportFormDimension) { HILOG_ERROR("This form soesn't support the new dimension."); return ERR_APPEXECFWK_FORM_INVALID_PARAM; /*errorCode*/ } @@ -2480,6 +2477,5 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di return ERR_OK; } - } // namespace AppExecFwk } // namespace OHOS diff --git a/tempfile b/tempfile deleted file mode 100644 index e69de29bb2..0000000000 -- Gitee From e6fc48f86e798c4ec527df7a6e5baeb19a45a1e2 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 23 Aug 2022 15:50:07 +0800 Subject: [PATCH 12/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I68c669578a00a560305aad631e4125af3b036ed0 --- BUILD.gn | 2 +- .../js/napi/formHost/napi_form_host.cpp | 315 ++++++++++-------- interfaces/inner_api/include/form_mgr_proxy.h | 4 +- interfaces/kits/native/src/form_mgr.cpp | 6 +- ... => form_notify_size_changed_connection.h} | 3 +- services/include/form_task_mgr.h | 7 +- services/src/form_host_callback.cpp | 3 +- services/src/form_mgr_adapter.cpp | 8 +- services/src/form_mgr_service.cpp | 3 +- ...> form_notify_size_changed_connection.cpp} | 5 +- services/src/form_provider_mgr.cpp | 7 +- services/src/form_task_mgr.cpp | 6 +- 12 files changed, 209 insertions(+), 160 deletions(-) rename services/include/{form_notify_size_change_connection.h => form_notify_size_changed_connection.h} (96%) rename services/src/{form_notify_size_change_connection.cpp => form_notify_size_changed_connection.cpp} (96%) diff --git a/BUILD.gn b/BUILD.gn index e936e768f6..20b7d67e6f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -60,7 +60,7 @@ ohos_shared_library("libfms") { "services/src/form_mgr_adapter.cpp", "services/src/form_mgr_service.cpp", "services/src/form_msg_event_connection.cpp", - "services/src/form_notify_size_change_connection.cpp", + "services/src/form_notify_size_changed_connection.cpp", "services/src/form_provider_mgr.cpp", "services/src/form_refresh_connection.cpp", "services/src/form_refresh_limiter.cpp", diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index 34685a26cd..f7a07b1174 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -2200,9 +2200,21 @@ napi_value ParseFormStateInfo(napi_env env, FormStateInfo &stateInfo) return formStateInfoObject; } -void AcquireFormStateCallbackComplete(napi_env env, AsyncAcquireFormStateCallbackInfo *const asyncCallbackInfo) +void AcquireFormStateCallbackComplete(uv_work_t *work, int32_t status) { HILOG_INFO("%{public}s, onAcquireFormState back", __func__); + if (work == nullptr) { + HILOG_ERROR("work == nullptr."); + return; + } + auto *asyncCallbackInfo = static_cast(work->data); + if (asyncCallbackInfo == nullptr) { + HILOG_ERROR("asyncCallbackInfo == nullptr."); + delete work; + return; + } + napi_env env = asyncCallbackInfo->env; + if (asyncCallbackInfo->callback != nullptr) { napi_value callback; napi_value callbackValues[ARGS_SIZE_TWO] = {nullptr, nullptr}; @@ -2216,12 +2228,29 @@ void AcquireFormStateCallbackComplete(napi_env env, AsyncAcquireFormStateCallbac napi_call_function(env, nullptr, callback, ARGS_SIZE_TWO, callbackValues, &callResult); napi_delete_reference(env, asyncCallbackInfo->callback); } + + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; + delete work; + work = nullptr; HILOG_INFO("%{public}s, onAcquireFormState back done", __func__); } -void AcquireFormStatePromiseComplete(napi_env env, AsyncAcquireFormStateCallbackInfo *const asyncCallbackInfo) +void AcquireFormStatePromiseComplete(uv_work_t *work, int32_t status) { HILOG_INFO("%{public}s, onAcquireFormState back", __func__); + if (work == nullptr) { + HILOG_ERROR("%{public}s, work == nullptr.", __func__); + return; + } + auto *asyncCallbackInfo = static_cast(work->data); + if (asyncCallbackInfo == nullptr) { + HILOG_ERROR("asyncCallbackInfo == nullptr."); + delete work; + return; + } + napi_env env = asyncCallbackInfo->env; + if (asyncCallbackInfo->result != ERR_OK) { napi_value result; InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &result); @@ -2230,6 +2259,11 @@ void AcquireFormStatePromiseComplete(napi_env env, AsyncAcquireFormStateCallback napi_value result = ParseFormStateInfo(env, asyncCallbackInfo->stateInfo); napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); } + + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; + delete work; + work = nullptr; HILOG_INFO("%{public}s, onAcquireFormState back done", __func__); } @@ -2241,13 +2275,7 @@ public: asyncCallbackInfo_ = asyncCallbackInfo; } - virtual ~FormStateCallbackClient() - { - if (asyncCallbackInfo_ != nullptr) { - delete asyncCallbackInfo_; - asyncCallbackInfo_ = nullptr; - } - } + virtual ~FormStateCallbackClient() = default; void ProcessAcquireState(FormState state) override { @@ -2255,13 +2283,34 @@ public: return; } asyncCallbackInfo_->stateInfo.state = state; + + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(asyncCallbackInfo_->env, &loop); + if (loop == nullptr) { + HILOG_ERROR("%{public}s, loop == nullptr.", __func__); + return; + } + + auto *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + HILOG_ERROR("%{public}s, work == nullptr.", __func__); + return; + } + work->data = asyncCallbackInfo_; + + int32_t result = 0; if (asyncCallbackInfo_->callbackType == CALLBACK_FLG) { - AcquireFormStateCallbackComplete(asyncCallbackInfo_->env, asyncCallbackInfo_); + result = uv_queue_work(loop, work, [](uv_work_t *work) {}, AcquireFormStateCallbackComplete); } else { - AcquireFormStatePromiseComplete(asyncCallbackInfo_->env, asyncCallbackInfo_); + result = uv_queue_work(loop, work, [](uv_work_t *work) {}, AcquireFormStatePromiseComplete); + } + // When uv_queue_work returns 0, asyncCallbackInfo_ and work will be freed in the callback function. + if (result != 0) { + delete asyncCallbackInfo_; + asyncCallbackInfo_ = nullptr; + delete work; + work = nullptr; } - delete asyncCallbackInfo_; - asyncCallbackInfo_ = nullptr; } private: @@ -3274,125 +3323,6 @@ napi_value NAPI_GetFormsInfo(napi_env env, napi_callback_info info) return NapiGetResult(env, 1); } -int64_t SystemTimeMillis() noexcept -{ - struct timespec t; - t.tv_sec = 0; - t.tv_nsec = 0; - clock_gettime(CLOCK_MONOTONIC, &t); - return static_cast(((t.tv_sec) * NANOSECONDS + t.tv_nsec) / MICROSECONDS); -} - -class ShareFormCallBackClient : public ShareFormCallBack, - public std::enable_shared_from_this { -public: - explicit ShareFormCallBackClient(ShareFormTask &&task) : task_(std::move(task)) - { - handler_ = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); - } - - virtual ~ShareFormCallBackClient() = default; - - void ProcessShareFormResponse(int32_t result) override - { - if (handler_) { - handler_->PostSyncTask([client = shared_from_this(), result] () { - client->task_(result); - }); - } - } - -private: - ShareFormTask task_; - std::shared_ptr handler_; -}; - -void JsFormHost::Finalizer(NativeEngine* engine, void* data, void* hint) -{ - HILOG_INFO("JsFormHost::Finalizer is called"); - std::unique_ptr(static_cast(data)); -} - -NativeValue* JsFormHost::ShareForm(NativeEngine* engine, NativeCallbackInfo* info) -{ - JsFormHost* me = OHOS::AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnShareForm(*engine, *info) : nullptr; -} - -NativeValue* JsFormHost::OnShareForm(NativeEngine &engine, NativeCallbackInfo &info) -{ - HILOG_INFO("%{public}s is called", __FUNCTION__); - int32_t errCode = ERR_OK; - if (info.argc > ARGS_SIZE_THREE || info.argc < ARGS_SIZE_TWO) { - HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); - errCode = ERR_ADD_INVALID_PARAM; - } - - std::string strFormId = - ::GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[0])); - std::string remoteDeviceId = - ::GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[1])); - // The promise form has only two parameters - decltype(info.argc) unwrapArgc = 2; - - int64_t formId; - if (!ConvertStringToInt64(strFormId, formId)) { - HILOG_ERROR("%{public}s, convert string formId to int64 failed.", __func__); - errCode = ERR_COMMON; - } - if (formId == 0 || remoteDeviceId.empty()) { - errCode = ERR_COMMON; - } - - NativeValue* lastParam = (info.argc <= unwrapArgc) ? nullptr : info.argv[unwrapArgc]; - NativeValue* result = nullptr; - - std::unique_ptr uasyncTask = - AbilityRuntime::CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, nullptr, &result); - std::shared_ptr asyncTask = std::move(uasyncTask); - - ShareFormTask task = [&engine, asyncTask](int32_t code) { - HILOG_INFO("%{public}s, task complete code: %{public}d", __func__, code); - if (code == ERR_OK) { - asyncTask->Resolve(engine, engine.CreateUndefined()); - } else { - auto retCode = QueryRetCode(code); - auto retMsg = QueryRetMsg(retCode); - asyncTask->Reject(engine, AbilityRuntime::CreateJsError(engine, retCode, retMsg)); - } - }; - - if (errCode != ERR_OK) { - asyncTask->Reject(engine, AbilityRuntime::CreateJsError(engine, errCode, "Invalidate params.")); - } else { - InnerShareForm(engine, asyncTask, std::move(task), formId, remoteDeviceId); - } - - return result; -} - -void JsFormHost::InnerShareForm( - NativeEngine &engine, - const std::shared_ptr &asyncTask, - ShareFormTask &&task, - int64_t formId, - const std::string &remoteDeviceId) -{ - auto shareFormCallback = std::make_shared(std::move(task)); - int64_t requestCode = SystemTimeMillis(); - FormHostClient::GetInstance()->AddShareFormCallback(shareFormCallback, requestCode); - - ErrCode ret = FormMgr::GetInstance().ShareForm( - formId, remoteDeviceId, FormHostClient::GetInstance(), requestCode); - if (ret != ERR_OK) { - HILOG_INFO("%{public}s, share form failed.", __func__); - auto retCode = QueryRetCode(ret); - auto retMsg = QueryRetMsg(retCode); - asyncTask->Reject(engine, AbilityRuntime::CreateJsError(engine, retCode, retMsg)); - FormHostClient::GetInstance()->RemoveShareFormCallback(requestCode); - } -} - /** * @brief Call native kit function: formSizeChanged * @@ -3404,7 +3334,7 @@ void JsFormHost::InnerShareForm( static void InnerFormSizeChanged(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) { HILOG_DEBUG("%{public}s called.", __func__); - asyncCallbackInfo->result = FormMgr::GetInstance().NotifyFormSizeChanged(asyncCallbackInfo->formId, + asyncCallbackInfo->result = FormMgr::GetInstance().NotifyFormSizeChanged(asyncCallbackInfo->formId, asyncCallbackInfo->newDimension, FormHostClient::GetInstance()); HILOG_DEBUG("%{public}s, end", __func__); } @@ -3599,3 +3529,122 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) return promise; } } + +int64_t SystemTimeMillis() noexcept +{ + struct timespec t; + t.tv_sec = 0; + t.tv_nsec = 0; + clock_gettime(CLOCK_MONOTONIC, &t); + return static_cast(((t.tv_sec) * NANOSECONDS + t.tv_nsec) / MICROSECONDS); +} + +class ShareFormCallBackClient : public ShareFormCallBack, + public std::enable_shared_from_this { +public: + explicit ShareFormCallBackClient(ShareFormTask &&task) : task_(std::move(task)) + { + handler_ = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); + } + + virtual ~ShareFormCallBackClient() = default; + + void ProcessShareFormResponse(int32_t result) override + { + if (handler_) { + handler_->PostSyncTask([client = shared_from_this(), result] () { + client->task_(result); + }); + } + } + +private: + ShareFormTask task_; + std::shared_ptr handler_; +}; + +void JsFormHost::Finalizer(NativeEngine* engine, void* data, void* hint) +{ + HILOG_INFO("JsFormHost::Finalizer is called"); + std::unique_ptr(static_cast(data)); +} + +NativeValue* JsFormHost::ShareForm(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsFormHost* me = OHOS::AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnShareForm(*engine, *info) : nullptr; +} + +NativeValue* JsFormHost::OnShareForm(NativeEngine &engine, NativeCallbackInfo &info) +{ + HILOG_INFO("%{public}s is called", __FUNCTION__); + int32_t errCode = ERR_OK; + if (info.argc > ARGS_SIZE_THREE || info.argc < ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + errCode = ERR_ADD_INVALID_PARAM; + } + + std::string strFormId = + ::GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[0])); + std::string remoteDeviceId = + ::GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[1])); + // The promise form has only two parameters + decltype(info.argc) unwrapArgc = 2; + + int64_t formId; + if (!ConvertStringToInt64(strFormId, formId)) { + HILOG_ERROR("%{public}s, convert string formId to int64 failed.", __func__); + errCode = ERR_COMMON; + } + if (formId == 0 || remoteDeviceId.empty()) { + errCode = ERR_COMMON; + } + + NativeValue* lastParam = (info.argc <= unwrapArgc) ? nullptr : info.argv[unwrapArgc]; + NativeValue* result = nullptr; + + std::unique_ptr uasyncTask = + AbilityRuntime::CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, nullptr, &result); + std::shared_ptr asyncTask = std::move(uasyncTask); + + ShareFormTask task = [&engine, asyncTask](int32_t code) { + HILOG_INFO("%{public}s, task complete code: %{public}d", __func__, code); + if (code == ERR_OK) { + asyncTask->Resolve(engine, engine.CreateUndefined()); + } else { + auto retCode = QueryRetCode(code); + auto retMsg = QueryRetMsg(retCode); + asyncTask->Reject(engine, AbilityRuntime::CreateJsError(engine, retCode, retMsg)); + } + }; + + if (errCode != ERR_OK) { + asyncTask->Reject(engine, AbilityRuntime::CreateJsError(engine, errCode, "Invalidate params.")); + } else { + InnerShareForm(engine, asyncTask, std::move(task), formId, remoteDeviceId); + } + + return result; +} + +void JsFormHost::InnerShareForm( + NativeEngine &engine, + const std::shared_ptr &asyncTask, + ShareFormTask &&task, + int64_t formId, + const std::string &remoteDeviceId) +{ + auto shareFormCallback = std::make_shared(std::move(task)); + int64_t requestCode = SystemTimeMillis(); + FormHostClient::GetInstance()->AddShareFormCallback(shareFormCallback, requestCode); + + ErrCode ret = FormMgr::GetInstance().ShareForm( + formId, remoteDeviceId, FormHostClient::GetInstance(), requestCode); + if (ret != ERR_OK) { + HILOG_INFO("%{public}s, share form failed.", __func__); + auto retCode = QueryRetCode(ret); + auto retMsg = QueryRetMsg(retCode); + asyncTask->Reject(engine, AbilityRuntime::CreateJsError(engine, retCode, retMsg)); + FormHostClient::GetInstance()->RemoveShareFormCallback(requestCode); + } +} \ No newline at end of file diff --git a/interfaces/inner_api/include/form_mgr_proxy.h b/interfaces/inner_api/include/form_mgr_proxy.h index ed553fc42e..d768710ca3 100644 --- a/interfaces/inner_api/include/form_mgr_proxy.h +++ b/interfaces/inner_api/include/form_mgr_proxy.h @@ -287,14 +287,14 @@ public: int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector &formInfos) override; /** - * @brief notify form change size with formId and newDimension, + * @brief notify form change size with formId and newDimension, * send formId and new Dimension to form manager service. * @param formId The Id of the forms to delete. * @param newDimension the newDimension of the form to reSize * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; /** diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index b1d4861218..13ed75a202 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -1009,9 +1009,9 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimensio int32_t dimensionNum = 0; for (std::map::const_iterator it = Constants::DIMENSION_MAP.begin(); it != Constants::DIMENSION_MAP.end(); it++) { - if (it->second == newDimension) - dimensionNum = it->first; - } + if (it->second == newDimension) + dimensionNum = it->first; + } if (dimensionNum == 0) { HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); return ERR_APPEXECFWK_FORM_INVALID_PARAM; diff --git a/services/include/form_notify_size_change_connection.h b/services/include/form_notify_size_changed_connection.h similarity index 96% rename from services/include/form_notify_size_change_connection.h rename to services/include/form_notify_size_changed_connection.h index b3ee3c5bde..68638cbee8 100644 --- a/services/include/form_notify_size_change_connection.h +++ b/services/include/form_notify_size_changed_connection.h @@ -20,7 +20,6 @@ namespace OHOS { namespace AppExecFwk { - /** * @class FormNotifySizeChangedConnection * Form notify to change size connection stub @@ -48,4 +47,4 @@ private: } // namespace AppExecFwk } // namespace OHOS -#endif //OHOS_FORM_FWK_FORM_NOTIFY_SIZE_CHANGE_CONNECTION_H +#endif // OHOS_FORM_FWK_FORM_NOTIFY_SIZE_CHANGE_CONNECTION_H diff --git a/services/include/form_task_mgr.h b/services/include/form_task_mgr.h index 302d98ffff..a229d6a841 100644 --- a/services/include/form_task_mgr.h +++ b/services/include/form_task_mgr.h @@ -125,7 +125,8 @@ public: * @param record form record. * @param remoteObject Form provider proxy object. */ - void PostSizeChangedTaskToHost(const int64_t formId, const FormRecord &record, const sptr &remoteObject); + void PostSizeChangedTaskToHost(const int64_t formId, const FormRecord &record, + const sptr &remoteObject); /** * @brief Handel form host died(task). @@ -194,7 +195,7 @@ public: * @param dimensionNum The dimension id of the new form. * @param remoteObject Form provider proxy object. */ - void PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + void PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const Want &want, const sptr &remoteObject); private: /** @@ -331,7 +332,7 @@ private: * @param dimensionNum The dimension id of the new form. * @param remoteObject Form provider proxy object. */ - void NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + void NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const Want &want, const sptr &remoteObject); /** * @brief Create form data for form host. diff --git a/services/src/form_host_callback.cpp b/services/src/form_host_callback.cpp index a9615b6160..90ceef82e3 100644 --- a/services/src/form_host_callback.cpp +++ b/services/src/form_host_callback.cpp @@ -68,7 +68,8 @@ void FormHostCallback::OnUpdate(const int64_t formId, const FormRecord &record, * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ -void FormHostCallback::OnSizeChanged(const int64_t formId, const FormRecord &record, const sptr &callerToken) +void FormHostCallback::OnSizeChanged(const int64_t formId, const FormRecord &record, + const sptr &callerToken) { HILOG_INFO("%{public}s start.", __func__); diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index ab31e97ad4..d16c1739a8 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2427,7 +2427,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di } FormInfo formInfo; - if(record.formName.empty()) { + if (record.formName.empty()) { for (const auto &form : formInfos) { if (form.defaultFlag) { formInfo = form; @@ -2445,7 +2445,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di } } - //isResizeable is the param of form record + // isResizeable is the param of form record bool isResizeable = true; if (!isResizeable) { @@ -2455,12 +2455,12 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di bool isSupportFormDimension = false; for (auto iter : formInfo.supportDimensions) { - if(dimensionNum == iter) + if (dimensionNum == iter) isSupportFormDimension = true; } if (!isSupportFormDimension) { HILOG_ERROR("This form soesn't support the new dimension."); - return ERR_APPEXECFWK_FORM_INVALID_PARAM; /*errorCode*/ + return ERR_APPEXECFWK_FORM_INVALID_PARAM; } sptr formNotifySizeChangedConnection = diff --git a/services/src/form_mgr_service.cpp b/services/src/form_mgr_service.cpp index 597edf7138..dcdd046ff1 100644 --- a/services/src/form_mgr_service.cpp +++ b/services/src/form_mgr_service.cpp @@ -921,7 +921,8 @@ void FormMgrService::HiDumpFormInfoByFormId(const std::string &args, std::string * @param callerToken token of the ability that initially calls this function. * @return Returns ERR_OK on success, others on failure. */ -int32_t FormMgrService::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) +int32_t FormMgrService::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) { HILOG_INFO("%{public}s called.", __func__); diff --git a/services/src/form_notify_size_change_connection.cpp b/services/src/form_notify_size_changed_connection.cpp similarity index 96% rename from services/src/form_notify_size_change_connection.cpp rename to services/src/form_notify_size_changed_connection.cpp index 345ea85c63..fcc197beaa 100644 --- a/services/src/form_notify_size_change_connection.cpp +++ b/services/src/form_notify_size_changed_connection.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "form_notify_size_change_connection.h" +#include "form_notify_size_changed_connection.h" #include @@ -50,8 +50,7 @@ void FormNotifySizeChangedConnection::OnAbilityConnectDone( } FormSupplyCallback::GetInstance()->AddConnection(this); int32_t dimensionNum = dimensionNum_; - if(dimensionNum == -1) - { + if (dimensionNum == -1) { HILOG_ERROR("%{public}s error, the dimension info is wrong", __func__); return; } diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index 3285aa0e53..19c24749af 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -113,13 +113,13 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons } int32_t dimensionId = want.GetIntParam(Constants::PARAM_FORM_DIMENSION_KEY, 0); - if(dimensionId == 0) { + if (dimensionId == 0) { HILOG_ERROR("%{public}s fail, the dimensionId is wrong, formId:%{public}" PRId64 "", __func__, formId); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } - //update the specification of formRecord - FormDataMgr::GetInstance().SetRecordSpecification(formId,dimensionId); + // update the specification of formRecord + FormDataMgr::GetInstance().SetRecordSpecification(formId, dimensionId); FormHostRecord clientHost; bool isGetFormHostRecord = FormDataMgr::GetInstance().GetFormHostRecord(formId, clientHost); @@ -162,7 +162,6 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons // the resize form is successfully return ERR_OK; - } /** diff --git a/services/src/form_task_mgr.cpp b/services/src/form_task_mgr.cpp index a59699e6e6..dde299b9c0 100644 --- a/services/src/form_task_mgr.cpp +++ b/services/src/form_task_mgr.cpp @@ -358,7 +358,7 @@ void FormTaskMgr::PostFormShareSendResponse(int64_t formShareRequestCode, int32_ * @param dimensionNum The dimension id of the new form. * @param remoteObject Form provider proxy object. */ -void FormTaskMgr::PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, +void FormTaskMgr::PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const Want &want, const sptr &remoteObject) { if (eventHandler_ == nullptr) { @@ -366,7 +366,7 @@ void FormTaskMgr::PostNotifyFormSizeChanged(const int64_t formId, const int32_t return; } auto notifyFormSizeChangedFunc = [formId, dimensionNum, want, remoteObject]() { - FormTaskMgr::GetInstance().NotifyProviderFormSizeChanged(formId,dimensionNum,want,remoteObject); + FormTaskMgr::GetInstance().NotifyProviderFormSizeChanged(formId, dimensionNum, want, remoteObject); }; eventHandler_->PostTask(notifyFormSizeChangedFunc, FORM_TASK_DELAY_TIME); } @@ -694,7 +694,7 @@ void FormTaskMgr::AcquireStateBack(AppExecFwk::FormState state, const AAFwk::Wan * @param dimensionNum The dimension id of the new form. * @param remoteObject Form provider proxy object. */ -void FormTaskMgr::NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, +void FormTaskMgr::NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const Want &want, const sptr &remoteObject) { HILOG_INFO("%{public}s called.", __func__); -- Gitee From 809b766472acc7e830bacf88f6360c1027375740 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 23 Aug 2022 16:11:53 +0800 Subject: [PATCH 13/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: Ib461615a03db5518d215d43e516c4bcefe3a9dc0 --- interfaces/kits/native/src/form_mgr.cpp | 2 +- services/src/form_mgr_adapter.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index 13ed75a202..54ca3a5e82 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -1011,7 +1011,7 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimensio it != Constants::DIMENSION_MAP.end(); it++) { if (it->second == newDimension) dimensionNum = it->first; - } + } if (dimensionNum == 0) { HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); return ERR_APPEXECFWK_FORM_INVALID_PARAM; diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index d16c1739a8..00f3c5be4b 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -24,7 +24,7 @@ #endif #include "form_acquire_connection.h" #include "form_acquire_state_connection.h" -#include "form_notify_size_change_connection.h" +#include "form_notify_size_changed_connection.h" #include "form_ams_helper.h" #include "form_bms_helper.h" #include "form_cache_mgr.h" -- Gitee From 529f916bc1b8634939ca829e8f6cf25be6a6a99d Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 24 Aug 2022 15:35:02 +0800 Subject: [PATCH 14/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I095320ad6963a61f30c07d8ffe708962a622a1e5 --- BUILD.gn | 2 +- .../js/napi/formHost/napi_form_host.cpp | 10 +-- frameworks/js/napi/formHost/napi_form_host.h | 2 +- interfaces/inner_api/include/form_mgr_proxy.h | 6 +- interfaces/kits/native/include/form_mgr.h | 4 +- interfaces/kits/native/src/form_mgr.cpp | 14 ++-- services/include/form_mgr_adapter.h | 9 +++ services/src/form_mgr_adapter.cpp | 63 +++++++++++------- test/mock/include/mock_form_mgr_proxy.h | 2 + test/mock/include/mock_form_mgr_service.h | 2 + .../form_mgr_proxy_test.cpp | 23 +++++++ .../form_mgr_stub_test/form_mgr_stub_test.cpp | 36 ++++++++++ test/unittest/form_mgr_test/form_mgr_test.cpp | 66 +++++++++++++++++++ 13 files changed, 197 insertions(+), 42 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 20b7d67e6f..278c40bd38 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -265,4 +265,4 @@ group("fms_services_target") { if (ability_runtime_graphics) { deps = [ ":fms_target" ] } -} \ No newline at end of file +} diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index f7a07b1174..37aa87adf3 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -3335,7 +3335,7 @@ static void InnerFormSizeChanged(napi_env env, AsyncFormResizeCallbackInfo* cons { HILOG_DEBUG("%{public}s called.", __func__); asyncCallbackInfo->result = FormMgr::GetInstance().NotifyFormSizeChanged(asyncCallbackInfo->formId, - asyncCallbackInfo->newDimension, FormHostClient::GetInstance()); + asyncCallbackInfo->dimensionId, FormHostClient::GetInstance()); HILOG_DEBUG("%{public}s, end", __func__); } @@ -3433,7 +3433,9 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) // Get the value of the size argument std::string newDimension = GetStringFromNAPI(env, argv[ARGS_SIZE_ONE]); - + int64_t dimensionNum = 0; + ConvertStringToInt64(newDimension, dimensionNum); + int32_t dimensionId = dimensionNum; AsyncFormResizeCallbackInfo *asyncCallbackInfo = new AsyncFormResizeCallbackInfo { .env = env, @@ -3441,11 +3443,11 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) .deferred = nullptr, .callback = nullptr, .formId = 0, - .newDimension = "", + .dimensionId = 0, .result = 0, }; asyncCallbackInfo->formId = formId; - asyncCallbackInfo->newDimension = newDimension; + asyncCallbackInfo->dimensionId = dimensionId; if (argc == ARGS_SIZE_THREE) { HILOG_INFO("%{public}s, asyncCallback.", __func__); diff --git a/frameworks/js/napi/formHost/napi_form_host.h b/frameworks/js/napi/formHost/napi_form_host.h index 2ba4067b2e..57682a8023 100644 --- a/frameworks/js/napi/formHost/napi_form_host.h +++ b/frameworks/js/napi/formHost/napi_form_host.h @@ -162,7 +162,7 @@ struct AsyncFormResizeCallbackInfo { napi_deferred deferred; napi_ref callback; int64_t formId; - std::string newDimension; + int32_t dimensionId; int result; }; diff --git a/interfaces/inner_api/include/form_mgr_proxy.h b/interfaces/inner_api/include/form_mgr_proxy.h index d768710ca3..64cc3fa551 100644 --- a/interfaces/inner_api/include/form_mgr_proxy.h +++ b/interfaces/inner_api/include/form_mgr_proxy.h @@ -278,7 +278,7 @@ public: std::vector &formInfos) override; /** - * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. + *@brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. * The bundle name will be retrieved by form service manager. * @param filter Filter that contains attributes that the formInfos have to have. * @param formInfos Return the forms' information of the calling bundle name @@ -287,14 +287,14 @@ public: int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector &formInfos) override; /** - * @brief notify form change size with formId and newDimension, + * @brief notify form change size with formId and newDimension, * send formId and new Dimension to form manager service. * @param formId The Id of the forms to delete. * @param newDimension the newDimension of the form to reSize * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; /** diff --git a/interfaces/kits/native/include/form_mgr.h b/interfaces/kits/native/include/form_mgr.h index 2471748e50..9e010bef66 100644 --- a/interfaces/kits/native/include/form_mgr.h +++ b/interfaces/kits/native/include/form_mgr.h @@ -396,11 +396,11 @@ public: * @brief notify form to size changed with formId and newDimension, * send formId and new Dimension to form manager service. * @param formId The Id of the forms to delete. - * @param newDimension the newDimension of the form to reSize + * @param dimensionId the newDimension of the form to reSize * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - int NotifyFormSizeChanged(const int64_t formId, std::string newDimension, const sptr &callerToken); + int NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, const sptr &callerToken); private: /** diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index 54ca3a5e82..90ca997fdb 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -985,11 +985,11 @@ bool FormMgr::CheckFMSReady() /** * @brief Resize forms with formId and newDimension, send formId and new Dimension to form manager service. * @param formId The Id of the forms to delete. - * @param newDimension the newDimension of the form to reSize + * @param dimensionId the newDimension of the form to reSize * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ -int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimension, +int FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, const sptr &callerToken) { HILOG_INFO("%{public}s called.", __func__); @@ -1006,13 +1006,13 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimensio } // check new Dimension - int32_t dimensionNum = 0; + bool dimensionSign = false; for (std::map::const_iterator it = Constants::DIMENSION_MAP.begin(); it != Constants::DIMENSION_MAP.end(); it++) { - if (it->second == newDimension) - dimensionNum = it->first; + if (it->first == dimensionId) + dimensionSign = true; } - if (dimensionNum == 0) { + if (!dimensionSign) { HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } @@ -1022,7 +1022,7 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, std::string newDimensio HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode); return errCode; } - return remoteProxy_->NotifyFormSizeChanged(formId, dimensionNum, callerToken); + return remoteProxy_->NotifyFormSizeChanged(formId, dimensionId, callerToken); } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index 6a42255dd3..3c1f50ecce 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -323,6 +323,14 @@ public: */ int UpdateRouterAction(const int64_t formId, std::string &action); + /** + * @brief Get form info by form record. + * @param formRecord The form record. + * @param formInfos Return the form' information of the specify bundle name and module name. + * @return Returns ERR_OK on success, others on failure. + */ + int GetFormInfoByFormRecord(FormRecord & formrecord, FormInfo & formInfo); + /** * @brief Notify the form to change size. * @param formId Indicates the ID of the form. @@ -634,6 +642,7 @@ private: */ ErrCode AcquireFormStateCheck(const std::string &bundleName, const std::string &abilityName, const Want &want, std::string &provider); + }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 00f3c5be4b..8f473f331e 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2396,38 +2396,21 @@ bool FormMgrAdapter::IsRequestPublishFormSupported() } /** - * @brief Notify the form to change size. - * @param formId Indicates the ID of the form. - * @param dimensionNum The new dimension num of the form. - * @param callerToken Host client. + * @brief Get form info by form record. + * @param formRecord The form record. + * @param formInfos Return the form' information of the specify bundle name and module name. * @return Returns ERR_OK on success, others on failure. */ -int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, - const sptr &callerToken) +int FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & formInfo) { - HILOG_INFO("%{public}s called.", __func__); - if (formId <= 0 || callerToken == nullptr) { - HILOG_ERROR("%{public}s, releaseForm invalid param", __func__); - return ERR_APPEXECFWK_FORM_INVALID_PARAM; - } - - FormRecord record; - FormDataMgr::GetInstance().GetFormRecord(formId, record); - - if (dimensionNum == record.specification) { - HILOG_ERROR("This form want to change to the same size."); - return ERR_APPEXECFWK_FORM_INVALID_PARAM; - } - std::vector formInfos {}; - ErrCode errCode = FormInfoMgr::GetInstance().GetFormsInfoByModule(record.bundleName, record.moduleName, formInfos); + ErrCode errCode = FormInfoMgr::GetInstance().GetFormsInfoByModule(formRecord.bundleName, formRecord.moduleName, formInfos); if (errCode != ERR_OK) { HILOG_ERROR("GetFormsInfoByModule, failed to get form config info."); return ERR_APPEXECFWK_FORM_GET_INFO_FAILED; } - FormInfo formInfo; - if (record.formName.empty()) { + if (formRecord.formName.empty()) { for (const auto &form : formInfos) { if (form.defaultFlag) { formInfo = form; @@ -2437,7 +2420,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di } } else { for (const auto &form : formInfos) { - if (form.name == record.formName) { + if (form.name == formRecord.formName) { formInfo = form; HILOG_DEBUG("GetFormInfo end."); break; @@ -2445,6 +2428,38 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di } } + return ERR_OK; +} + +/** + * @brief Notify the form to change size. + * @param formId Indicates the ID of the form. + * @param dimensionNum The new dimension num of the form. + * @param callerToken Host client. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) +{ + HILOG_INFO("%{public}s called.", __func__); + if (formId <= 0 || callerToken == nullptr) { + HILOG_ERROR("%{public}s, releaseForm invalid param", __func__); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + + FormRecord record; + FormDataMgr::GetInstance().GetFormRecord(formId, record); + + if (dimensionNum == record.specification) { + HILOG_ERROR("This form want to change to the same size."); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + + FormInfo formInfo; + ErrCode errCode = GetFormInfoByFormRecord(record, formInfo); + if(errCode != ERR_OK) + return errCode; + // isResizeable is the param of form record bool isResizeable = true; diff --git a/test/mock/include/mock_form_mgr_proxy.h b/test/mock/include/mock_form_mgr_proxy.h index 3eecb4e91a..b59775d85e 100644 --- a/test/mock/include/mock_form_mgr_proxy.h +++ b/test/mock/include/mock_form_mgr_proxy.h @@ -27,6 +27,8 @@ public: MOCK_METHOD2(GetFormsInfo, int(const std::string &moduleName, std::vector &formInfos)); MOCK_METHOD0(IsRequestPublishFormSupported, bool()); MOCK_METHOD2(StartAbility, int32_t(const Want &want, const sptr &callerToken)); + MOCK_METHOD3(NotifyFormSizeChanged, int(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken)); }; } } diff --git a/test/mock/include/mock_form_mgr_service.h b/test/mock/include/mock_form_mgr_service.h index 55e586ccf3..f9ffe0af80 100644 --- a/test/mock/include/mock_form_mgr_service.h +++ b/test/mock/include/mock_form_mgr_service.h @@ -68,6 +68,8 @@ public: MOCK_METHOD2(UpdateRouterAction, int(const int64_t formId, std::string &action)); MOCK_METHOD4(ShareForm, int32_t(int64_t, const std::string&, const sptr&, int64_t)); MOCK_METHOD1(RecvFormShareInfoFromRemote, int32_t(const FormShareInfo&)); + MOCK_METHOD3(NotifyFormSizeChanged, int32_t(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken)); }; } } diff --git a/test/unittest/form_mgr_proxy_test/form_mgr_proxy_test.cpp b/test/unittest/form_mgr_proxy_test/form_mgr_proxy_test.cpp index b40a68cfc4..22ebe19165 100644 --- a/test/unittest/form_mgr_proxy_test/form_mgr_proxy_test.cpp +++ b/test/unittest/form_mgr_proxy_test/form_mgr_proxy_test.cpp @@ -167,4 +167,27 @@ HWTEST_F(FormMgrProxyTest, FormMgrProxyTest_0005, TestSize.Level1) { EXPECT_EQ(result, ERR_APPEXECFWK_PARCEL_ERROR); GTEST_LOG_(INFO) << "FormMgrProxyTest_0005 test ends"; } + +/** + * @tc.name: FormMgrProxyTest_0006 + * @tc.desc: Verify NotifyFormSizeChanged + * @tc.type: FUNC + * @tc.require: #I5MLR5 + */ +HWTEST_F(FormMgrProxyTest, FormMgrProxyTest_0006, TestSize.Level1) { + GTEST_LOG_(INFO) << "FormMgrProxyTest_0006 starts"; + // initialize input parameters. + int64_t form_Id = 1; + int32_t dimensionNum = 1; + sptr token = new (std::nothrow) MockFormToken(); + + EXPECT_CALL(*mockFormMgrService, NotifyFormSizeChanged(_, _, _)) + .Times(1) + .WillOnce(Return(0)); + // test. + bool result = formMgrProxy->NotifyFormSizeChanged(form_Id, dimensionNum, token); + // expect result. + EXPECT_EQ(result, 0); + GTEST_LOG_(INFO) << "FormMgrProxyTest_0006 test ends"; +} } \ No newline at end of file diff --git a/test/unittest/form_mgr_stub_test/form_mgr_stub_test.cpp b/test/unittest/form_mgr_stub_test/form_mgr_stub_test.cpp index 140086ba2f..c08b67bfa3 100644 --- a/test/unittest/form_mgr_stub_test/form_mgr_stub_test.cpp +++ b/test/unittest/form_mgr_stub_test/form_mgr_stub_test.cpp @@ -191,4 +191,40 @@ HWTEST_F(FormMgrStubTest, FormMgrStubTest_0004, TestSize.Level1) { EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "FormMgrStubTest_0004 ends"; } + +/** + * @tc.name: FormMgrStubTest_0005 + * @tc.desc: Verify HandleNotifyFormSizeChanged + * @tc.type: FUNC + * @tc.require: #I5MLR5 + */ +HWTEST_F(FormMgrStubTest, FormMgrStubTest_0005, TestSize.Level1) { + GTEST_LOG_(INFO) << "FormMgrStubTest_0005 starts"; + // initialize input parameters. + MessageParcel data; + MessageParcel reply; + + int64_t formId = 1; + sptr token = new (std::nothrow) MockFormToken(); + int32_t dimensionNum = 1; + + // write in formId + data.WriteInt64(formId); + // write in token + data.WriteRemoteObject(token); + // write in dimensionNum + data.WriteInt32(dimensionNum); + EXPECT_CALL(*mockFormMgrService, NotifyFormSizeChanged(_, _, _)) + .Times(1) + .WillOnce(Return(0)); + // test. + int32_t errCode = mockFormMgrService->HandleNotifyFormSizeChanged(data, reply); + // check errorcode + EXPECT_EQ(ERR_OK, errCode); + // check resulting infos. + int32_t result; + reply.ReadInt32(result); + EXPECT_EQ(result, 0); + GTEST_LOG_(INFO) << "FormMgrStubTest_0005 ends"; +} } \ No newline at end of file diff --git a/test/unittest/form_mgr_test/form_mgr_test.cpp b/test/unittest/form_mgr_test/form_mgr_test.cpp index b3902c0d19..7a9ff5c707 100644 --- a/test/unittest/form_mgr_test/form_mgr_test.cpp +++ b/test/unittest/form_mgr_test/form_mgr_test.cpp @@ -156,4 +156,70 @@ HWTEST_F(FormMgrTest, FormMgrTest_0004, TestSize.Level1) { EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "FormMgrTest_0004 test ends"; } + +/** + * @tc.name: FormMgrTest_0005 + * @tc.desc: Verify NotifyFormSizeChanged while the dimensionId and formId are valid + * @tc.type: FUNC + * @tc.require: #I5MLR5 + */ +HWTEST_F(FormMgrTest, FormMgrTest_0005, TestSize.Level1) { + GTEST_LOG_(INFO) << "FormMgrTest_0005 starts"; + // initialize input parameters. + int64_t form_Id = 1; + int32_t dimensionId = 1; + sptr token = new (std::nothrow) MockFormToken(); + + EXPECT_CALL(*mockProxy, NotifyFormSizeChanged(_, _, _)) + .Times(1) + .WillOnce(Return(0)); + + int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(form_Id, dimensionId, token); + EXPECT_EQ(result, 0); + GTEST_LOG_(INFO) << "FormMgrTest_0005 test ends"; +} + +/** + * @tc.name: FormMgrTest_0006 + * @tc.desc: Verify NotifyFormSizeChanged while the formId is invalid + * @tc.type: FUNC + * @tc.require: #I5MLR5 + */ +HWTEST_F(FormMgrTest, FormMgrTest_0006, TestSize.Level1) { + GTEST_LOG_(INFO) << "FormMgrTest_0006 starts"; + // initialize input parameters. + int64_t form_Id = 0; + int32_t dimensionId = 1; + sptr token = new (std::nothrow) MockFormToken(); + + EXPECT_CALL(*mockProxy, NotifyFormSizeChanged(_, _, _)) + .Times(1) + .WillOnce(Return(0)); + + int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(form_Id, dimensionId, token); + EXPECT_EQ(result, 2293768); + GTEST_LOG_(INFO) << "FormMgrTest_0006 test ends"; +} + +/** + * @tc.name: FormMgrTest_0007 + * @tc.desc: Verify NotifyFormSizeChanged while the dimensionId is invalid + * @tc.type: FUNC + * @tc.require: #I5MLR5 + */ +HWTEST_F(FormMgrTest, FormMgrTest_0007, TestSize.Level1) { + GTEST_LOG_(INFO) << "FormMgrTest_0007 starts"; + // initialize input parameters. + int64_t form_Id = 1; + int32_t dimensionId = 0; + sptr token = new (std::nothrow) MockFormToken(); + + EXPECT_CALL(*mockProxy, NotifyFormSizeChanged(_, _, _)) + .Times(1) + .WillOnce(Return(0)); + + int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(form_Id, dimensionId, token); + EXPECT_EQ(result, 2293767); + GTEST_LOG_(INFO) << "FormMgrTest_0007 test ends"; +} } // namespace \ No newline at end of file -- Gitee From 4ab39e1ce5ed312a69b081867c555b0e03a18127 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 24 Aug 2022 15:48:49 +0800 Subject: [PATCH 15/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I783c36fef65a6b05905dcbb115016739af8f8337 --- interfaces/inner_api/include/form_mgr_proxy.h | 6 +++--- interfaces/kits/native/src/form_mgr.cpp | 2 +- services/include/form_mgr_adapter.h | 1 - services/include/form_notify_size_changed_connection.h | 2 +- services/src/form_mgr_adapter.cpp | 7 ++++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/interfaces/inner_api/include/form_mgr_proxy.h b/interfaces/inner_api/include/form_mgr_proxy.h index 64cc3fa551..d768710ca3 100644 --- a/interfaces/inner_api/include/form_mgr_proxy.h +++ b/interfaces/inner_api/include/form_mgr_proxy.h @@ -278,7 +278,7 @@ public: std::vector &formInfos) override; /** - *@brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. + * @brief This function is called by formProvider and gets forms info by the bundle name of the calling ability. * The bundle name will be retrieved by form service manager. * @param filter Filter that contains attributes that the formInfos have to have. * @param formInfos Return the forms' information of the calling bundle name @@ -287,14 +287,14 @@ public: int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector &formInfos) override; /** - * @brief notify form change size with formId and newDimension, + * @brief notify form change size with formId and newDimension, * send formId and new Dimension to form manager service. * @param formId The Id of the forms to delete. * @param newDimension the newDimension of the form to reSize * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; /** diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index 90ca997fdb..ff83f55d2a 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -1011,7 +1011,7 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, it != Constants::DIMENSION_MAP.end(); it++) { if (it->first == dimensionId) dimensionSign = true; - } + } if (!dimensionSign) { HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); return ERR_APPEXECFWK_FORM_INVALID_PARAM; diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index 3c1f50ecce..eae2752357 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -642,7 +642,6 @@ private: */ ErrCode AcquireFormStateCheck(const std::string &bundleName, const std::string &abilityName, const Want &want, std::string &provider); - }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_notify_size_changed_connection.h b/services/include/form_notify_size_changed_connection.h index 68638cbee8..ba69712cca 100644 --- a/services/include/form_notify_size_changed_connection.h +++ b/services/include/form_notify_size_changed_connection.h @@ -26,7 +26,7 @@ namespace AppExecFwk { */ class FormNotifySizeChangedConnection : public FormAbilityConnection { public: - FormNotifySizeChangedConnection(const int64_t formId, const int32_t dimensionNum, + FormNotifySizeChangedConnection(const int64_t formId, const int32_t dimensionNum, const std::string &bundleName, const std::string &abilityName); virtual ~FormNotifySizeChangedConnection() = default; diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 8f473f331e..8dc5ce8493 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2404,7 +2404,8 @@ bool FormMgrAdapter::IsRequestPublishFormSupported() int FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & formInfo) { std::vector formInfos {}; - ErrCode errCode = FormInfoMgr::GetInstance().GetFormsInfoByModule(formRecord.bundleName, formRecord.moduleName, formInfos); + ErrCode errCode = FormInfoMgr::GetInstance().GetFormsInfoByModule(formRecord.bundleName, + formRecord.moduleName, formInfos); if (errCode != ERR_OK) { HILOG_ERROR("GetFormsInfoByModule, failed to get form config info."); return ERR_APPEXECFWK_FORM_GET_INFO_FAILED; @@ -2420,7 +2421,7 @@ int FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & } } else { for (const auto &form : formInfos) { - if (form.name == formRecord.formName) { + if (form.name == formecord.formName) { formInfo = form; HILOG_DEBUG("GetFormInfo end."); break; @@ -2457,7 +2458,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di FormInfo formInfo; ErrCode errCode = GetFormInfoByFormRecord(record, formInfo); - if(errCode != ERR_OK) + if (errCode != ERR_OK) return errCode; // isResizeable is the param of form record -- Gitee From 8858d378bcdc7e5198af2fcefca994249f90527f Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 24 Aug 2022 16:07:49 +0800 Subject: [PATCH 16/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I3bca08aecb77e42649741b70678aa4f8046b2917 --- interfaces/kits/native/src/form_mgr.cpp | 5 +++-- services/src/form_mgr_adapter.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index ff83f55d2a..3774a7c81b 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -1009,9 +1009,10 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, bool dimensionSign = false; for (std::map::const_iterator it = Constants::DIMENSION_MAP.begin(); it != Constants::DIMENSION_MAP.end(); it++) { - if (it->first == dimensionId) + if (it->first == dimensionId) { dimensionSign = true; - } + } + } if (!dimensionSign) { HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); return ERR_APPEXECFWK_FORM_INVALID_PARAM; diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 8dc5ce8493..cb01a5b5fd 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2421,7 +2421,7 @@ int FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & } } else { for (const auto &form : formInfos) { - if (form.name == formecord.formName) { + if (form.name == formRecord.formName) { formInfo = form; HILOG_DEBUG("GetFormInfo end."); break; -- Gitee From 2ffbfd8c9493142978d6d2fd0acf2700d85667d7 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Thu, 25 Aug 2022 09:25:20 +0800 Subject: [PATCH 17/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I8d5805a00afe86445e47872c58234d2cfa0815a2 --- test/mock/include/mock_form_host_client.h | 6 ++++++ test/mock/include/mock_form_provider_client.h | 9 +++++++++ test/mock/src/mock_form_host_client.cpp | 6 ++++++ test/mock/src/mock_form_provider_client.cpp | 15 +++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/test/mock/include/mock_form_host_client.h b/test/mock/include/mock_form_host_client.h index 63465c810f..f2967fee0f 100644 --- a/test/mock/include/mock_form_host_client.h +++ b/test/mock/include/mock_form_host_client.h @@ -88,6 +88,12 @@ public: * @param result Share form result. */ virtual void OnShareFormResponse(int64_t requestCode, int32_t result) override; + + /** + * @brief Request to give back a Form after size changed. + * @param formInfo Form info. + */ + virtual void OnSizeChanged(const FormJsInfo &formInfo) override; private: Semaphore sem_; DISALLOW_COPY_AND_MOVE(MockFormHostClient); diff --git a/test/mock/include/mock_form_provider_client.h b/test/mock/include/mock_form_provider_client.h index 86f8785e54..f5a333787f 100644 --- a/test/mock/include/mock_form_provider_client.h +++ b/test/mock/include/mock_form_provider_client.h @@ -106,6 +106,15 @@ private: virtual int FireFormEvent(const int64_t formId, const std::string &message, const Want &want, const sptr &callerToken) override; + /** + * @brief Notify provider when the form want to change the size. + * @param formId The Id of the form to update. + * @param want the want of the request containing the new formDimensionNum. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, + const sptr &callerToken) override; /** * @brief Acquire form state to form provider. * @param wantArg The want of onAcquireFormState. diff --git a/test/mock/src/mock_form_host_client.cpp b/test/mock/src/mock_form_host_client.cpp index 695ffd5f24..a7f7cd707c 100644 --- a/test/mock/src/mock_form_host_client.cpp +++ b/test/mock/src/mock_form_host_client.cpp @@ -71,5 +71,11 @@ void MockFormHostClient::OnShareFormResponse(int64_t requestCode, int32_t result HILOG_DEBUG("MockFormHostClient OnShareFormResponse"); PostVoid(); } + +void MockFormHostClient::OnSizeChanged(const FormJsInfo &formInfo) +{ + HILOG_DEBUG("MockFormHostClient OnSizeChanged"); + PostVoid(); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/src/mock_form_provider_client.cpp b/test/mock/src/mock_form_provider_client.cpp index c5706a5e55..1fca5c0c4a 100644 --- a/test/mock/src/mock_form_provider_client.cpp +++ b/test/mock/src/mock_form_provider_client.cpp @@ -139,6 +139,21 @@ int MockFormProviderClient::FireFormEvent(const int64_t formId, const std::strin return ERR_OK; } +/** + * @brief Notify provider when the form want to change the size. + * @param formId The Id of the form to update. + * @param want the want of the request containing the new formDimensionNum. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. + */ +int MockFormProviderClient::NotifyFormSizeChanged(const int64_t formId, const Want &want, + const sptr &callerToken) +{ + HILOG_DEBUG("notify form size changed"); + return ERR_OK; +} + + /** * @brief Acquire form state to form provider. * @param wantArg The want of onAcquireFormState. -- Gitee From de7b3b24f72aead7348c7826912627bd9ed3b75f Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Mon, 29 Aug 2022 16:41:54 +0800 Subject: [PATCH 18/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: Ib3214161b6a5fb57888723e7ac1a3255129f1274 --- .../js/napi/formHost/napi_form_host.cpp | 214 +++++++----------- .../inner_api/include/form_host_proxy.h | 2 +- interfaces/inner_api/include/form_host_stub.h | 2 +- interfaces/inner_api/include/form_js_info.h | 4 - interfaces/inner_api/include/form_mgr_proxy.h | 2 +- interfaces/inner_api/include/form_mgr_stub.h | 2 +- .../inner_api/include/form_provider_proxy.h | 4 +- .../inner_api/include/form_provider_stub.h | 2 +- interfaces/inner_api/src/form_host_proxy.cpp | 11 +- interfaces/inner_api/src/form_host_stub.cpp | 4 +- interfaces/inner_api/src/form_mgr_proxy.cpp | 22 +- interfaces/inner_api/src/form_mgr_stub.cpp | 4 +- .../inner_api/src/form_provider_proxy.cpp | 5 +- .../inner_api/src/form_provider_stub.cpp | 4 +- .../kits/native/src/form_host_client.cpp | 5 +- services/include/form_ability_connection.h | 2 +- .../form_notify_size_changed_connection.h | 2 +- services/src/form_mgr_adapter.cpp | 16 +- services/src/form_provider_mgr.cpp | 8 +- .../fms_form_mgr_release_form_test.cpp | 1 + 20 files changed, 116 insertions(+), 200 deletions(-) diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index 37aa87adf3..ff99b33e3a 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -3323,144 +3323,19 @@ napi_value NAPI_GetFormsInfo(napi_env env, napi_callback_info info) return NapiGetResult(env, 1); } -/** - * @brief Call native kit function: formSizeChanged - * - * @param[in] env The environment that the Node-API call is invoked under - * @param[out] asyncCallbackInfo Reference, callback info via Node-API - * - * @return void - */ static void InnerFormSizeChanged(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) { - HILOG_DEBUG("%{public}s called.", __func__); - asyncCallbackInfo->result = FormMgr::GetInstance().NotifyFormSizeChanged(asyncCallbackInfo->formId, - asyncCallbackInfo->dimensionId, FormHostClient::GetInstance()); - HILOG_DEBUG("%{public}s, end", __func__); + HILOG_DEBUG("InnerFormSizeChanged called."); + if(asyncCallbackInfo != nullptr) + asyncCallbackInfo->result = FormMgr::GetInstance().NotifyFormSizeChanged(asyncCallbackInfo->formId, + asyncCallbackInfo->dimensionId, FormHostClient::GetInstance()); + HILOG_DEBUG("InnerFormSizeChanged end"); } -/** - * @brief The implementation of Node-API interface: formSizeChanged - * - * @param[in] env The environment that the Node-API call is invoked under - * @param[out] info An opaque datatype that is passed to a callback function - * - * @return This is an opaque pointer that is used to represent a JavaScript value - */ -napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) +napi_value NotifyFormSizeChangedCallback(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) { - HILOG_INFO("%{public}s called.", __func__); - - // Check the number of the arguments - size_t argc = ARGS_SIZE_THREE; - napi_value argv[ARGS_SIZE_THREE] = {nullptr}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); - if (argc < ARGS_SIZE_TWO || argc > ARGS_SIZE_THREE) { - HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); - return nullptr; - } - HILOG_INFO("%{public}s, argc = [%{public}zu]", __func__, argc); - - // Check the value type of the formId argument - napi_valuetype valueType; - NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ZERO], &valueType)); - if (valueType != napi_string) { - AsyncErrMsgCallbackInfo *asyncErrorInfo = new - AsyncErrMsgCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - .callback = nullptr, - .callbackValue = argv[ARGS_SIZE_TWO], - .code = ERR_APPEXECFWK_FORM_INVALID_FORM_ID, - .type = 0 - }; - - if (argc == ARGS_SIZE_THREE) { - asyncErrorInfo->type = CALLBACK_FLG; - } else { - asyncErrorInfo->type = PROMISE_FLG; - } - return RetErrMsg(asyncErrorInfo); - } - - // Check the value type of the size argument - valueType = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ONE], &valueType)); - if (valueType != napi_string) { - AsyncErrMsgCallbackInfo *asyncErrorInfo = new - AsyncErrMsgCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - .callback = nullptr, - .callbackValue = argv[ARGS_SIZE_TWO], - .code = ERR_APPEXECFWK_FORM_INVALID_PARAM, - .type = 0 - }; - - if (argc == ARGS_SIZE_THREE) { - asyncErrorInfo->type = CALLBACK_FLG; - } else { - asyncErrorInfo->type = PROMISE_FLG; - } - return RetErrMsg(asyncErrorInfo); - } - - // Check the value of the formId argument - std::string strFormId = GetStringFromNAPI(env, argv[ARGS_SIZE_ZERO]); - int64_t formId = 0; - HILOG_ERROR("%{public}s, form id ", strFormId.c_str()); - if (!ConvertStringToInt64(strFormId, formId)) { - AsyncErrMsgCallbackInfo *asyncErrorInfo = new - AsyncErrMsgCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - .callback = nullptr, - .callbackValue = argv[1], - .code = ERR_APPEXECFWK_FORM_FORM_ID_NUM_ERR, - .type = 0 - }; - - if (argc == ARGS_SIZE_THREE) { - asyncErrorInfo->type = CALLBACK_FLG; - } else { - asyncErrorInfo->type = PROMISE_FLG; - } - return RetErrMsg(asyncErrorInfo); - } - - // Get the value of the size argument - std::string newDimension = GetStringFromNAPI(env, argv[ARGS_SIZE_ONE]); - int64_t dimensionNum = 0; - ConvertStringToInt64(newDimension, dimensionNum); - int32_t dimensionId = dimensionNum; - AsyncFormResizeCallbackInfo *asyncCallbackInfo = new - AsyncFormResizeCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - .callback = nullptr, - .formId = 0, - .dimensionId = 0, - .result = 0, - }; - asyncCallbackInfo->formId = formId; - asyncCallbackInfo->dimensionId = dimensionId; - - if (argc == ARGS_SIZE_THREE) { - HILOG_INFO("%{public}s, asyncCallback.", __func__); - - // Check the value type of the arguments - valueType = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType)); - NAPI_ASSERT(env, valueType == napi_function, "The arguments[2] type of deleteForm is incorrect, " - "expected type is function."); - - napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); - - napi_value resourceName; + HILOG_DEBUG("NotifyFormSizeChangedCallback."); + napi_value resourceName; napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work( env, @@ -3493,8 +3368,11 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) &asyncCallbackInfo->asyncWork); NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); return NapiGetResult(env, 1); - } else { - HILOG_INFO("%{public}s, promise.", __func__); +} + +napi_value NotifyFormSizeChangedPromise(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) +{ + HILOG_DEBUG("NotifyFormSizeChangedPromise."); napi_deferred deferred; napi_value promise; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); @@ -3529,6 +3407,72 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) &asyncCallbackInfo->asyncWork); napi_queue_async_work(env, asyncCallbackInfo->asyncWork); return promise; +} + +napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) +{ + HILOG_DEBUG("NAPI_NotifyFormSizeChanged called."); + + // Check the number of the arguments + size_t argc = ARGS_SIZE_THREE; + napi_value argv[ARGS_SIZE_THREE] = { nullptr }; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc < ARGS_SIZE_TWO || argc > ARGS_SIZE_THREE) { + HILOG_ERROR("NAPI_NotifyFormSizeChanged, wrong number of arguments."); + return nullptr; + } + + int32_t callbackType = (argc == ARGS_SIZE_THREE) ? CALLBACK_FLG : PROMISE_FLG; + + // Check the value type of the formId argument + napi_valuetype valueType; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ZERO], &valueType)); + if (valueType != napi_string) { + return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_INVALID_FORM_ID, callbackType, argv[ARGS_SIZE_TWO])); + } + + // Check the value type of the size argument + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ONE], &valueType)); + if (valueType != napi_string) { + return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_INVALID_PARAM, callbackType, argv[ARGS_SIZE_TWO])); + } + + // Check the value of the formId argument + std::string strFormId = GetStringFromNAPI(env, argv[ARGS_SIZE_ZERO]); + int64_t formId = 0; + HILOG_ERROR("%{public}s, form id ", strFormId.c_str()); + if (!ConvertStringToInt64(strFormId, formId)) { + return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_FORM_ID_NUM_ERR, callbackType, argv[ARGS_SIZE_ONE])); + } + + // Get the value of the size argument + std::string newDimension = GetStringFromNAPI(env, argv[ARGS_SIZE_ONE]); + int64_t dimensionNum = 0; + ConvertStringToInt64(newDimension, dimensionNum); + int32_t dimensionId = dimensionNum; + AsyncFormResizeCallbackInfo *asyncCallbackInfo = new + AsyncFormResizeCallbackInfo { + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + .callback = nullptr, + .formId = 0, + .dimensionId = 0, + .result = 0, + }; + asyncCallbackInfo->formId = formId; + asyncCallbackInfo->dimensionId = dimensionId; + + if (argc == ARGS_SIZE_THREE) { + // Check the value type of the arguments + valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "The arg[2] type is incorrect, expected type is function."); + napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); + return NotifyFormSizeChangedCallback(env, asyncCallbackInfo); + } else { + return NotifyFormSizeChangedPromise(env ,asyncCallbackInfo); } } diff --git a/interfaces/inner_api/include/form_host_proxy.h b/interfaces/inner_api/include/form_host_proxy.h index e7ce7ec3ef..c0c9edc9b3 100644 --- a/interfaces/inner_api/include/form_host_proxy.h +++ b/interfaces/inner_api/include/form_host_proxy.h @@ -70,7 +70,7 @@ public: * @brief Request to give back a Form after size changed. * @param formInfo Form info. */ - virtual void OnSizeChanged(const FormJsInfo &formInfo) override; + void OnSizeChanged(const FormJsInfo &formInfo) override; private: template diff --git a/interfaces/inner_api/include/form_host_stub.h b/interfaces/inner_api/include/form_host_stub.h index 4b8a5efa90..5b9220bdf0 100644 --- a/interfaces/inner_api/include/form_host_stub.h +++ b/interfaces/inner_api/include/form_host_stub.h @@ -87,7 +87,7 @@ private: * @param reply output param. * @return Returns ERR_OK on success, others on failure. */ - int HandleOnSizeChanged(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnSizeChanged(MessageParcel &data, MessageParcel &reply); private: using FormHostFunc = int32_t (FormHostStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/include/form_js_info.h b/interfaces/inner_api/include/form_js_info.h index 9b5db1fc49..2a25b61bec 100644 --- a/interfaces/inner_api/include/form_js_info.h +++ b/interfaces/inner_api/include/form_js_info.h @@ -41,10 +41,6 @@ struct FormJsInfo : public Parcelable { FormProviderData formProviderData; int32_t specification; - std::string htmlPath; - std::string cssPath; - std::string jsPath; - std::string fileReousePath; std::string formSrc; FormWindow formWindow; uint32_t versionCode = 0; diff --git a/interfaces/inner_api/include/form_mgr_proxy.h b/interfaces/inner_api/include/form_mgr_proxy.h index d768710ca3..e37459cb68 100644 --- a/interfaces/inner_api/include/form_mgr_proxy.h +++ b/interfaces/inner_api/include/form_mgr_proxy.h @@ -294,7 +294,7 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; /** diff --git a/interfaces/inner_api/include/form_mgr_stub.h b/interfaces/inner_api/include/form_mgr_stub.h index 6cb7f56645..8ec9a725a4 100644 --- a/interfaces/inner_api/include/form_mgr_stub.h +++ b/interfaces/inner_api/include/form_mgr_stub.h @@ -307,7 +307,7 @@ private: * @param reply output param. * @return Returns ERR_OK on success, others on failure. */ - int32_t HandleNotifyFormSizeChanged(MessageParcel &data, MessageParcel &reply); + ErrCode HandleNotifyFormSizeChanged(MessageParcel &data, MessageParcel &reply); private: using FormMgrFunc = int32_t (FormMgrStub::*)(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/inner_api/include/form_provider_proxy.h b/interfaces/inner_api/include/form_provider_proxy.h index a5fa5d8b86..086d5da059 100644 --- a/interfaces/inner_api/include/form_provider_proxy.h +++ b/interfaces/inner_api/include/form_provider_proxy.h @@ -123,8 +123,8 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, - const sptr &callerToken) override; + ErrCode NotifyFormSizeChanged(const int64_t formId, const Want &want, + const sptr &callerToken) override; /** * @brief Acquire to share form information data. This is sync API. diff --git a/interfaces/inner_api/include/form_provider_stub.h b/interfaces/inner_api/include/form_provider_stub.h index b63c8ef7a7..455d5d05c4 100644 --- a/interfaces/inner_api/include/form_provider_stub.h +++ b/interfaces/inner_api/include/form_provider_stub.h @@ -113,7 +113,7 @@ private: * @param reply output param. * @return Returns ERR_OK on success, others on failure. */ - int HandleNotifyFormSizeChaned(MessageParcel &data, MessageParcel &reply); + ErrCode HandleNotifyFormSizeChaned(MessageParcel &data, MessageParcel &reply); private: using FormProviderFunc = int32_t (FormProviderStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/src/form_host_proxy.cpp b/interfaces/inner_api/src/form_host_proxy.cpp index fe3a360cf4..537d08fadc 100644 --- a/interfaces/inner_api/src/form_host_proxy.cpp +++ b/interfaces/inner_api/src/form_host_proxy.cpp @@ -75,26 +75,21 @@ void FormHostProxy::OnUpdate(const FormJsInfo &formInfo) } } -/** - * @brief Request to give back a Form after form size changed. - * @param formInfo Form info. - */ void FormHostProxy::OnSizeChanged(const FormJsInfo &formInfo) { - int error; MessageParcel data; MessageParcel reply; MessageOption option; if (!WriteInterfaceToken(data)) { - HILOG_ERROR("%{public}s, failed to write interface token", __func__); + HILOG_ERROR("failed to write interface token"); } if (!data.WriteParcelable(&formInfo)) { - HILOG_ERROR("%{public}s, failed to write formInfo", __func__); + HILOG_ERROR("failed to write formInfo"); } - error = Remote()->SendRequest( + ErrCode error = Remote()->SendRequest( static_cast(IFormHost::Message::FORM_HOST_ON_SIZE_CHANGED), data, reply, diff --git a/interfaces/inner_api/src/form_host_stub.cpp b/interfaces/inner_api/src/form_host_stub.cpp index 25f9b7aef1..032c5102ab 100644 --- a/interfaces/inner_api/src/form_host_stub.cpp +++ b/interfaces/inner_api/src/form_host_stub.cpp @@ -164,11 +164,11 @@ int32_t FormHostStub::HandleOnShareFormResponse(MessageParcel &data, MessageParc * @param reply output param. * @return Returns ERR_OK on success, others on failure. */ -int FormHostStub::HandleOnSizeChanged(MessageParcel &data, MessageParcel &reply) +ErrCode FormHostStub::HandleOnSizeChanged(MessageParcel &data, MessageParcel &reply) { std::unique_ptr formInfo(data.ReadParcelable()); if (!formInfo) { - HILOG_ERROR("%{public}s, failed to ReadParcelable", __func__); + HILOG_ERROR("failed to ReadParcelable"); return ERR_APPEXECFWK_PARCEL_ERROR; } OnSizeChanged(*formInfo); diff --git a/interfaces/inner_api/src/form_mgr_proxy.cpp b/interfaces/inner_api/src/form_mgr_proxy.cpp index 00a9769e0e..6615290dcd 100644 --- a/interfaces/inner_api/src/form_mgr_proxy.cpp +++ b/interfaces/inner_api/src/form_mgr_proxy.cpp @@ -1133,44 +1133,36 @@ int32_t FormMgrProxy::GetFormsInfo(const std::string &moduleName, std::vector &callerToken) { MessageParcel data; if (!WriteInterfaceToken(data)) { - HILOG_ERROR("%{public}s, failed to write interface token", __func__); + HILOG_ERROR("failed to write interface token"); return ERR_APPEXECFWK_PARCEL_ERROR; } if (!data.WriteInt64(formId)) { - HILOG_ERROR("%{public}s, failed to write formId", __func__); + HILOG_ERROR("failed to write formId"); return ERR_APPEXECFWK_PARCEL_ERROR; } if (!data.WriteRemoteObject(callerToken)) { - HILOG_ERROR("%{public}s, failed to write callerToken", __func__); + HILOG_ERROR("failed to write callerToken"); return ERR_APPEXECFWK_PARCEL_ERROR; } if (!data.WriteInt32(dimensionNum)) { - HILOG_ERROR("%{public}s, failed to write dimensionNum", __func__); + HILOG_ERROR("failed to write dimensionNum"); return ERR_APPEXECFWK_PARCEL_ERROR; } MessageParcel reply; MessageOption option; - int error = Remote()->SendRequest( + ErrCode error = Remote()->SendRequest( static_cast(IFormMgr::Message::FORM_MGR_NOTIFY_FORM_SIZE_CHANGED), data, reply, option); if (error != ERR_OK) { - HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + HILOG_ERROR("failed to SendRequest: %{public}d",error); return ERR_APPEXECFWK_FORM_SEND_FMS_MSG; } return reply.ReadInt32(); diff --git a/interfaces/inner_api/src/form_mgr_stub.cpp b/interfaces/inner_api/src/form_mgr_stub.cpp index b38bf44325..2c7135a113 100644 --- a/interfaces/inner_api/src/form_mgr_stub.cpp +++ b/interfaces/inner_api/src/form_mgr_stub.cpp @@ -911,7 +911,7 @@ int32_t FormMgrStub::HandleStartAbility(MessageParcel &data, MessageParcel &repl * @param reply output param. * @return Returns ERR_OK on success, others on failure. */ -int32_t FormMgrStub::HandleNotifyFormSizeChanged(MessageParcel &data, MessageParcel &reply) +ErrCode FormMgrStub::HandleNotifyFormSizeChanged(MessageParcel &data, MessageParcel &reply) { int64_t formId = data.ReadInt64(); sptr client = data.ReadRemoteObject(); @@ -920,7 +920,7 @@ int32_t FormMgrStub::HandleNotifyFormSizeChanged(MessageParcel &data, MessagePar } int32_t dimensionNum = data.ReadInt32(); - int32_t result = NotifyFormSizeChanged(formId, dimensionNum, client); + ErrCode result = NotifyFormSizeChanged(formId, dimensionNum, client); reply.WriteInt32(result); if (!reply.WriteInt32(result)) { diff --git a/interfaces/inner_api/src/form_provider_proxy.cpp b/interfaces/inner_api/src/form_provider_proxy.cpp index e485b47573..cc4b5ba8be 100644 --- a/interfaces/inner_api/src/form_provider_proxy.cpp +++ b/interfaces/inner_api/src/form_provider_proxy.cpp @@ -405,7 +405,7 @@ int FormProviderProxy::AcquireState(const Want &wantArg, const std::string &prov * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ -int FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Want &want, +ErrCode FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Want &want, const sptr &callerToken) { MessageParcel data; @@ -428,10 +428,9 @@ int FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Want &w return ERR_APPEXECFWK_PARCEL_ERROR; } - int error; MessageParcel reply; MessageOption option; - error = Remote()->SendRequest( + ErrCode error = Remote()->SendRequest( static_cast(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_SIZE_CHANGE), data, reply, diff --git a/interfaces/inner_api/src/form_provider_stub.cpp b/interfaces/inner_api/src/form_provider_stub.cpp index 92c5e2d868..986bec79c8 100644 --- a/interfaces/inner_api/src/form_provider_stub.cpp +++ b/interfaces/inner_api/src/form_provider_stub.cpp @@ -326,7 +326,7 @@ int32_t FormProviderStub::HandleAcquireShareFormData(MessageParcel &data, Messag * @param reply output param. * @return Returns ERR_OK on success, others on failure. */ -int FormProviderStub::HandleNotifyFormSizeChaned(MessageParcel &data, MessageParcel &reply) +ErrCode FormProviderStub::HandleNotifyFormSizeChaned(MessageParcel &data, MessageParcel &reply) { int64_t formId = data.ReadInt64(); @@ -342,7 +342,7 @@ int FormProviderStub::HandleNotifyFormSizeChaned(MessageParcel &data, MessagePar return ERR_APPEXECFWK_PARCEL_ERROR; } - int32_t result = NotifyFormSizeChanged(formId, *want, client); + ErrCode result = NotifyFormSizeChanged(formId, *want, client); reply.WriteInt32(result); return result; } diff --git a/interfaces/kits/native/src/form_host_client.cpp b/interfaces/kits/native/src/form_host_client.cpp index 4c057ccdcd..56a54b68d5 100644 --- a/interfaces/kits/native/src/form_host_client.cpp +++ b/interfaces/kits/native/src/form_host_client.cpp @@ -324,7 +324,7 @@ void FormHostClient::RemoveShareFormCallback(int64_t requestCode) */ void FormHostClient::OnSizeChanged(const FormJsInfo &formJsInfo) { - HILOG_INFO("%{public}s called.", __func__); + HILOG_DEBUG("OnSizeChanged called."); HILOG_INFO("Imamge number is %{public}zu.", formJsInfo.imageDataMap.size()); int64_t formId = formJsInfo.formId; if (formId < 0) { @@ -340,7 +340,8 @@ void FormHostClient::OnSizeChanged(const FormJsInfo &formJsInfo) for (const auto& callback : iter->second) { HILOG_INFO("%{public}s, formId: %{public}" PRId64 ", jspath: %{public}s, data: %{public}s", __func__, formId, formJsInfo.jsFormCodePath.c_str(), formJsInfo.formData.c_str()); - callback->ProcessFormUpdate(formJsInfo); + if (callback != nullptr) + callback->ProcessFormUpdate(formJsInfo); } } } // namespace AppExecFwk diff --git a/services/include/form_ability_connection.h b/services/include/form_ability_connection.h index aa4172f454..1a10014ba3 100644 --- a/services/include/form_ability_connection.h +++ b/services/include/form_ability_connection.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/include/form_notify_size_changed_connection.h b/services/include/form_notify_size_changed_connection.h index ba69712cca..000ce992e7 100644 --- a/services/include/form_notify_size_changed_connection.h +++ b/services/include/form_notify_size_changed_connection.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index cb01a5b5fd..f49b8a11b8 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2395,12 +2395,6 @@ bool FormMgrAdapter::IsRequestPublishFormSupported() return true; } -/** - * @brief Get form info by form record. - * @param formRecord The form record. - * @param formInfos Return the form' information of the specify bundle name and module name. - * @return Returns ERR_OK on success, others on failure. - */ int FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & formInfo) { std::vector formInfos {}; @@ -2432,13 +2426,6 @@ int FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & return ERR_OK; } -/** - * @brief Notify the form to change size. - * @param formId Indicates the ID of the form. - * @param dimensionNum The new dimension num of the form. - * @param callerToken Host client. - * @return Returns ERR_OK on success, others on failure. - */ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) { @@ -2471,8 +2458,9 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di bool isSupportFormDimension = false; for (auto iter : formInfo.supportDimensions) { - if (dimensionNum == iter) + if (dimensionNum == iter) { isSupportFormDimension = true; + } } if (!isSupportFormDimension) { HILOG_ERROR("This form soesn't support the new dimension."); diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index 19c24749af..4ea3e72de1 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -121,10 +121,10 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons // update the specification of formRecord FormDataMgr::GetInstance().SetRecordSpecification(formId, dimensionId); - FormHostRecord clientHost; - bool isGetFormHostRecord = FormDataMgr::GetInstance().GetFormHostRecord(formId, clientHost); - if (!isGetFormHostRecord) { - HILOG_ERROR("%{public}s fail, clientHost is null", __func__); + std::vector clientHosts; + FormDataMgr::GetInstance().GetFormHostRecord(formId, clientHosts); + if (clientHosts.empty()) { + HILOG_ERROR("%{public}s fail, clientHosst is empty", __func__); return ERR_APPEXECFWK_FORM_COMMON_CODE; } diff --git a/test/unittest/fms_form_mgr_release_form_test/fms_form_mgr_release_form_test.cpp b/test/unittest/fms_form_mgr_release_form_test/fms_form_mgr_release_form_test.cpp index 7510789bfb..26cdd2e5de 100644 --- a/test/unittest/fms_form_mgr_release_form_test/fms_form_mgr_release_form_test.cpp +++ b/test/unittest/fms_form_mgr_release_form_test/fms_form_mgr_release_form_test.cpp @@ -1,3 +1,4 @@ + /* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); -- Gitee From 9c78674b8cd44d9b446615176ec80d89c31d15e2 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Mon, 29 Aug 2022 17:06:37 +0800 Subject: [PATCH 19/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I2ce5104a3cfa96a7c5414024bdb2c340c4eb4ee5 --- interfaces/inner_api/src/form_mgr_stub.cpp | 8 +------ .../inner_api/src/form_provider_proxy.cpp | 17 +++++---------- .../inner_api/src/form_provider_stub.cpp | 10 ++------- interfaces/kits/native/include/form_mgr.h | 2 +- interfaces/kits/native/src/form_mgr.cpp | 21 +++++++------------ services/src/form_provider_mgr.cpp | 6 +++--- 6 files changed, 19 insertions(+), 45 deletions(-) diff --git a/interfaces/inner_api/src/form_mgr_stub.cpp b/interfaces/inner_api/src/form_mgr_stub.cpp index 2c7135a113..6f00a7a455 100644 --- a/interfaces/inner_api/src/form_mgr_stub.cpp +++ b/interfaces/inner_api/src/form_mgr_stub.cpp @@ -905,12 +905,6 @@ int32_t FormMgrStub::HandleStartAbility(MessageParcel &data, MessageParcel &repl return result; } -/** - * @brief Handle NitifyFormSizeChangde message. - * @param data input param. - * @param reply output param. - * @return Returns ERR_OK on success, others on failure. - */ ErrCode FormMgrStub::HandleNotifyFormSizeChanged(MessageParcel &data, MessageParcel &reply) { int64_t formId = data.ReadInt64(); @@ -924,7 +918,7 @@ ErrCode FormMgrStub::HandleNotifyFormSizeChanged(MessageParcel &data, MessagePar reply.WriteInt32(result); if (!reply.WriteInt32(result)) { - HILOG_ERROR("%{public}s, failed to write result", __func__); + HILOG_ERROR("failed to write result"); return ERR_APPEXECFWK_PARCEL_ERROR; } return result; diff --git a/interfaces/inner_api/src/form_provider_proxy.cpp b/interfaces/inner_api/src/form_provider_proxy.cpp index cc4b5ba8be..4aa9743245 100644 --- a/interfaces/inner_api/src/form_provider_proxy.cpp +++ b/interfaces/inner_api/src/form_provider_proxy.cpp @@ -398,33 +398,26 @@ int FormProviderProxy::AcquireState(const Want &wantArg, const std::string &prov return ERR_OK; } -/** - * @brief Notify provider when the form want to change the size. - * @param formId The Id of the form to update. - * @param want the want of the request containing the new formDimensionNum. - * @param callerToken Caller ability token. - * @return Returns ERR_OK on success, others on failure. - */ ErrCode FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Want &want, const sptr &callerToken) { MessageParcel data; if (!WriteInterfaceToken(data)) { - HILOG_ERROR("%{public}s, failed to write interface token", __func__); + HILOG_ERROR("failed to write interface token"); return ERR_APPEXECFWK_PARCEL_ERROR; } if (!data.WriteInt64(formId)) { - HILOG_ERROR("%{public}s, failed to write formId", __func__); + HILOG_ERROR("failed to write formId"); return ERR_APPEXECFWK_PARCEL_ERROR; } if (!data.WriteParcelable(&want)) { - HILOG_ERROR("%{public}s, failed to write want", __func__); + HILOG_ERROR("failed to write want"); return ERR_APPEXECFWK_PARCEL_ERROR; } if (!data.WriteRemoteObject(callerToken)) { - HILOG_ERROR("%{public}s, failed to write callerToken", __func__); + HILOG_ERROR("failed to write callerToken"); return ERR_APPEXECFWK_PARCEL_ERROR; } @@ -436,7 +429,7 @@ ErrCode FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Wan reply, option); if (error != ERR_OK) { - HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + HILOG_ERROR("failed to SendRequest: %{public}d",error); return error; } return ERR_OK; diff --git a/interfaces/inner_api/src/form_provider_stub.cpp b/interfaces/inner_api/src/form_provider_stub.cpp index 986bec79c8..5166951625 100644 --- a/interfaces/inner_api/src/form_provider_stub.cpp +++ b/interfaces/inner_api/src/form_provider_stub.cpp @@ -320,25 +320,19 @@ int32_t FormProviderStub::HandleAcquireShareFormData(MessageParcel &data, Messag return ERR_OK; } -/** - * @brief handle the form size change. - * @param data input param. - * @param reply output param. - * @return Returns ERR_OK on success, others on failure. - */ ErrCode FormProviderStub::HandleNotifyFormSizeChaned(MessageParcel &data, MessageParcel &reply) { int64_t formId = data.ReadInt64(); std::unique_ptr want(data.ReadParcelable()); if (!want) { - HILOG_ERROR("%{public}s fail, ReadParcelable failed", __func__); + HILOG_ERROR("ReadParcelable failed"); return ERR_APPEXECFWK_PARCEL_ERROR; } sptr client = data.ReadRemoteObject(); if (client == nullptr) { - HILOG_ERROR("%{public}s, failed to get remote object.", __func__); + HILOG_ERROR("failed to get remote object."); return ERR_APPEXECFWK_PARCEL_ERROR; } diff --git a/interfaces/kits/native/include/form_mgr.h b/interfaces/kits/native/include/form_mgr.h index 9e010bef66..f12d84e2e4 100644 --- a/interfaces/kits/native/include/form_mgr.h +++ b/interfaces/kits/native/include/form_mgr.h @@ -400,7 +400,7 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - int NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, const sptr &callerToken); + ErrCode NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, const sptr &callerToken); private: /** diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index 3774a7c81b..03da72c30b 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -982,26 +982,19 @@ bool FormMgr::CheckFMSReady() return true; } -/** - * @brief Resize forms with formId and newDimension, send formId and new Dimension to form manager service. - * @param formId The Id of the forms to delete. - * @param dimensionId the newDimension of the form to reSize - * @param callerToken Caller ability token. - * @return Returns ERR_OK on success, others on failure. - */ -int FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, +ErrCode FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, const sptr &callerToken) { - HILOG_INFO("%{public}s called.", __func__); + HILOG_DEBUG("NotifyFormSizeChanged called."); // check fms recover status if (FormMgr::GetRecoverStatus() == Constants::IN_RECOVERING) { - HILOG_ERROR("%{public}s error, form is in recover status, can't do action on form.", __func__); + HILOG_ERROR("form is in recover status, can't do action on form."); return ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR; } // check formId if (formId <= 0) { - HILOG_ERROR("%{public}s error, the passed in formId can't be negative or zero.", __func__); + HILOG_ERROR("the passed in formId can't be negative or zero."); return ERR_APPEXECFWK_FORM_INVALID_FORM_ID; } @@ -1014,13 +1007,13 @@ int FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, } } if (!dimensionSign) { - HILOG_ERROR("%{public}s error, the passed new dimension is invalid.", __func__); + HILOG_ERROR("the passed new dimension is invalid."); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } - int errCode = Connect(); + ErrCode errCode = Connect(); if (errCode != ERR_OK) { - HILOG_ERROR("%{public}s failed errCode:%{public}d.", __func__, errCode); + HILOG_ERROR("failed errCode:%{public}d.",errCode); return errCode; } return remoteProxy_->NotifyFormSizeChanged(formId, dimensionId, callerToken); diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index 4ea3e72de1..6c057acf1f 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -147,9 +147,9 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons formRecord.needRefresh = false; FormDataMgr::GetInstance().SetFormCacheInited(formId, true); - if (clientHost.Contains(formId)) { - formRecord.formProviderInfo = formProviderInfo; - clientHost.OnSizeChanged(formId, formRecord); + formRecord.formProviderInfo = formProviderInfo; + for (auto &iter : clientHosts) { + iter.OnAcquire(formId, formRecord); } if (formRecord.formProviderInfo.NeedCache()) { -- Gitee From 5b7ce7b05f8106e8e5c6b79ae95a4986eb6ca504 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Mon, 29 Aug 2022 17:11:01 +0800 Subject: [PATCH 20/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: Ib1ddc70e70cc176f3efa4f84a91c5870aa220a53 --- frameworks/js/napi/formHost/napi_form_host.cpp | 5 +++-- interfaces/inner_api/src/form_mgr_proxy.cpp | 4 ++-- interfaces/inner_api/src/form_provider_proxy.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index ff99b33e3a..717974d856 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -3326,9 +3326,10 @@ napi_value NAPI_GetFormsInfo(napi_env env, napi_callback_info info) static void InnerFormSizeChanged(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) { HILOG_DEBUG("InnerFormSizeChanged called."); - if(asyncCallbackInfo != nullptr) + if (asyncCallbackInfo != nullptr) { asyncCallbackInfo->result = FormMgr::GetInstance().NotifyFormSizeChanged(asyncCallbackInfo->formId, asyncCallbackInfo->dimensionId, FormHostClient::GetInstance()); + } HILOG_DEBUG("InnerFormSizeChanged end"); } @@ -3472,7 +3473,7 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); return NotifyFormSizeChangedCallback(env, asyncCallbackInfo); } else { - return NotifyFormSizeChangedPromise(env ,asyncCallbackInfo); + return NotifyFormSizeChangedPromise(env, asyncCallbackInfo); } } diff --git a/interfaces/inner_api/src/form_mgr_proxy.cpp b/interfaces/inner_api/src/form_mgr_proxy.cpp index 6615290dcd..99b0d34e26 100644 --- a/interfaces/inner_api/src/form_mgr_proxy.cpp +++ b/interfaces/inner_api/src/form_mgr_proxy.cpp @@ -1134,7 +1134,7 @@ int32_t FormMgrProxy::GetFormsInfo(const std::string &moduleName, std::vector &callerToken) + const sptr &callerToken) { MessageParcel data; if (!WriteInterfaceToken(data)) { @@ -1162,7 +1162,7 @@ ErrCode FormMgrProxy::NotifyFormSizeChanged(const int64_t formId, const int32_t reply, option); if (error != ERR_OK) { - HILOG_ERROR("failed to SendRequest: %{public}d",error); + HILOG_ERROR("failed to SendRequest: %{public}d", error); return ERR_APPEXECFWK_FORM_SEND_FMS_MSG; } return reply.ReadInt32(); diff --git a/interfaces/inner_api/src/form_provider_proxy.cpp b/interfaces/inner_api/src/form_provider_proxy.cpp index 4aa9743245..b7a1fed9f5 100644 --- a/interfaces/inner_api/src/form_provider_proxy.cpp +++ b/interfaces/inner_api/src/form_provider_proxy.cpp @@ -399,7 +399,7 @@ int FormProviderProxy::AcquireState(const Want &wantArg, const std::string &prov } ErrCode FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Want &want, - const sptr &callerToken) + const sptr &callerToken) { MessageParcel data; -- Gitee From 70f12cf1d373f3914c6e5497c49b7aad25670fa3 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 30 Aug 2022 09:03:11 +0800 Subject: [PATCH 21/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I28b91f916e77278ea60121725b09e79e18f7e67f --- interfaces/inner_api/src/form_host_proxy.cpp | 2 +- interfaces/inner_api/src/form_host_stub.cpp | 6 --- .../inner_api/src/form_provider_proxy.cpp | 2 +- .../kits/native/src/form_host_client.cpp | 13 ++--- interfaces/kits/native/src/form_mgr.cpp | 8 +-- services/include/form_ability_connection.h | 2 +- services/include/form_host_callback.h | 1 + services/include/form_mgr_adapter.h | 4 +- services/include/form_mgr_service.h | 2 +- services/src/form_data_mgr.cpp | 10 +--- services/src/form_host_callback.cpp | 15 ++---- services/src/form_host_record.cpp | 7 +-- services/src/form_mgr_adapter.cpp | 12 ++--- services/src/form_mgr_service.cpp | 15 ++---- .../form_notify_size_changed_connection.cpp | 19 +++---- services/src/form_provider_mgr.cpp | 16 ++---- services/src/form_task_mgr.cpp | 52 ++++--------------- 17 files changed, 53 insertions(+), 133 deletions(-) diff --git a/interfaces/inner_api/src/form_host_proxy.cpp b/interfaces/inner_api/src/form_host_proxy.cpp index 537d08fadc..9c465aff9b 100644 --- a/interfaces/inner_api/src/form_host_proxy.cpp +++ b/interfaces/inner_api/src/form_host_proxy.cpp @@ -95,7 +95,7 @@ void FormHostProxy::OnSizeChanged(const FormJsInfo &formInfo) reply, option); if (error != ERR_OK) { - HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + HILOG_ERROR("failed to SendRequest: %{public}d", error); } } diff --git a/interfaces/inner_api/src/form_host_stub.cpp b/interfaces/inner_api/src/form_host_stub.cpp index 032c5102ab..bd7bf1397a 100644 --- a/interfaces/inner_api/src/form_host_stub.cpp +++ b/interfaces/inner_api/src/form_host_stub.cpp @@ -158,12 +158,6 @@ int32_t FormHostStub::HandleOnShareFormResponse(MessageParcel &data, MessageParc return ERR_OK; } -/** - * @brief handle OnSizeChanged event. - * @param data input param. - * @param reply output param. - * @return Returns ERR_OK on success, others on failure. - */ ErrCode FormHostStub::HandleOnSizeChanged(MessageParcel &data, MessageParcel &reply) { std::unique_ptr formInfo(data.ReadParcelable()); diff --git a/interfaces/inner_api/src/form_provider_proxy.cpp b/interfaces/inner_api/src/form_provider_proxy.cpp index b7a1fed9f5..2938ca6357 100644 --- a/interfaces/inner_api/src/form_provider_proxy.cpp +++ b/interfaces/inner_api/src/form_provider_proxy.cpp @@ -429,7 +429,7 @@ ErrCode FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Wan reply, option); if (error != ERR_OK) { - HILOG_ERROR("failed to SendRequest: %{public}d",error); + HILOG_ERROR("failed to SendRequest: %{public}d", error); return error; } return ERR_OK; diff --git a/interfaces/kits/native/src/form_host_client.cpp b/interfaces/kits/native/src/form_host_client.cpp index 56a54b68d5..7bd8bf25b7 100644 --- a/interfaces/kits/native/src/form_host_client.cpp +++ b/interfaces/kits/native/src/form_host_client.cpp @@ -317,29 +317,24 @@ void FormHostClient::RemoveShareFormCallback(int64_t requestCode) HILOG_INFO("%{public}s end.", __func__); } -/** - * @brief Request to give back a form after form size changed. - * @param formJsInfo Form js info. - * @return none. - */ void FormHostClient::OnSizeChanged(const FormJsInfo &formJsInfo) { HILOG_DEBUG("OnSizeChanged called."); HILOG_INFO("Imamge number is %{public}zu.", formJsInfo.imageDataMap.size()); int64_t formId = formJsInfo.formId; if (formId < 0) { - HILOG_ERROR("%{public}s error, the passed form id can't be negative.", __func__); + HILOG_ERROR("the passed form id can't be negative."); return; } std::lock_guard lock(callbackMutex_); auto iter = formCallbackMap_.find(formId); if (iter == formCallbackMap_.end()) { - HILOG_ERROR("%{public}s error, not find formId:%{public}s.", __func__, std::to_string(formId).c_str()); + HILOG_ERROR("not find formId:%{public}s.", std::to_string(formId).c_str()); return; } for (const auto& callback : iter->second) { - HILOG_INFO("%{public}s, formId: %{public}" PRId64 ", jspath: %{public}s, data: %{public}s", - __func__, formId, formJsInfo.jsFormCodePath.c_str(), formJsInfo.formData.c_str()); + HILOG_INFO("formId: %{public}" PRId64 ", jspath: %{public}s, data: %{public}s", + formId, formJsInfo.jsFormCodePath.c_str(), formJsInfo.formData.c_str()); if (callback != nullptr) callback->ProcessFormUpdate(formJsInfo); } diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index 03da72c30b..6199aa6a47 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -366,8 +366,8 @@ int FormMgr::SetNextRefreshTime(const int64_t formId, const int64_t nextTime) { HILOG_INFO("%{public}s called.", __func__); - if (nextTime < Constants::MIN_NEXT_TIME) { - HILOG_ERROR("next time less than 300 seconds."); + if (nextTime < (Constants::MIN_NEXT_TIME / Constants::SEC_PER_MIN)) { + HILOG_ERROR("next time less than 5 mins"); return ERR_APPEXECFWK_FORM_INVALID_REFRESH_TIME; } @@ -983,7 +983,7 @@ bool FormMgr::CheckFMSReady() } ErrCode FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, - const sptr &callerToken) + const sptr &callerToken) { HILOG_DEBUG("NotifyFormSizeChanged called."); // check fms recover status @@ -1013,7 +1013,7 @@ ErrCode FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId ErrCode errCode = Connect(); if (errCode != ERR_OK) { - HILOG_ERROR("failed errCode:%{public}d.",errCode); + HILOG_ERROR("failed errCode:%{public}d.", errCode); return errCode; } return remoteProxy_->NotifyFormSizeChanged(formId, dimensionId, callerToken); diff --git a/services/include/form_ability_connection.h b/services/include/form_ability_connection.h index 1a10014ba3..aa4172f454 100644 --- a/services/include/form_ability_connection.h +++ b/services/include/form_ability_connection.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/include/form_host_callback.h b/services/include/form_host_callback.h index 4f85ecfb38..e24ec8d1ff 100644 --- a/services/include/form_host_callback.h +++ b/services/include/form_host_callback.h @@ -51,6 +51,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ void OnUpdate(const int64_t formId, const FormRecord &record, const sptr &callerToken); + /** * @brief Request to give back a Form after size changed. * @param formId The Id of the form whose size is changed. diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index eae2752357..c9f306fc86 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -329,7 +329,7 @@ public: * @param formInfos Return the form' information of the specify bundle name and module name. * @return Returns ERR_OK on success, others on failure. */ - int GetFormInfoByFormRecord(FormRecord & formrecord, FormInfo & formInfo); + ErrCode GetFormInfoByFormRecord(FormRecord & formrecord, FormInfo & formInfo); /** * @brief Notify the form to change size. @@ -338,7 +338,7 @@ public: * @param callerToken Host client. * @return Returns ERR_OK on success, others on failure. */ - int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken); + ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken); private: /** * @brief Get form configure info. diff --git a/services/include/form_mgr_service.h b/services/include/form_mgr_service.h index b52ebb54d8..9c30e0da8a 100644 --- a/services/include/form_mgr_service.h +++ b/services/include/form_mgr_service.h @@ -366,7 +366,7 @@ public: * @param callerToken token of the ability that initially calls this function. * @return Returns ERR_OK on success, others on failure. */ - int32_t NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken) override; private: enum class DumpKey { diff --git a/services/src/form_data_mgr.cpp b/services/src/form_data_mgr.cpp index 6dd9d839d6..7466a7c042 100644 --- a/services/src/form_data_mgr.cpp +++ b/services/src/form_data_mgr.cpp @@ -1304,19 +1304,13 @@ ErrCode FormDataMgr::SetRecordVisible(int64_t matchedFormId, bool isVisible) return ERR_OK; } -/** - * @brief set form specification. - * @param formId form id. - * @param specification the specification - * @return Returns true if this function is successfully called; returns false otherwise. - */ ErrCode FormDataMgr::SetRecordSpecification(int64_t formId, int32_t specification) { - HILOG_INFO("%{public}s, set form specification", __func__); + HILOG_DEBUG("set form specification"); std::lock_guard lock(formRecordMutex_); auto info = formRecords_.find(formId); if (info == formRecords_.end()) { - HILOG_ERROR("%{public}s, form info not find", __func__); + HILOG_ERROR("form info not find"); return ERR_APPEXECFWK_FORM_INVALID_FORM_ID; } info->second.specification = specification; diff --git a/services/src/form_host_callback.cpp b/services/src/form_host_callback.cpp index 90ceef82e3..821af47438 100644 --- a/services/src/form_host_callback.cpp +++ b/services/src/form_host_callback.cpp @@ -61,26 +61,19 @@ void FormHostCallback::OnUpdate(const int64_t formId, const FormRecord &record, FormTaskMgr::GetInstance().PostUpdateTaskToHost(formId, record, callerToken); } -/** - * @brief Request to give back a Form after size changed. - * @param formId The Id of the form whose size is changed. - * @param record Form info. - * @param callerToken Caller ability token. - * @return Returns ERR_OK on success, others on failure. - */ void FormHostCallback::OnSizeChanged(const int64_t formId, const FormRecord &record, - const sptr &callerToken) + const sptr &callerToken) { - HILOG_INFO("%{public}s start.", __func__); + HILOG_DEBUG("OnSizeChanged start."); // check formId if (formId < 0) { - HILOG_ERROR("%{public}s: OnSizeChanged invalid param, formId:%{public}" PRId64 ".", __func__, formId); + HILOG_ERROR("OnSizeChanged invalid param, formId:%{public}" PRId64 ".", formId); return; } if (callerToken == nullptr) { - HILOG_ERROR("%{public}s: callerToken can not be NULL", __func__); + HILOG_ERROR("callerToken can not be NULL"); return; } diff --git a/services/src/form_host_record.cpp b/services/src/form_host_record.cpp index 23d3e91bea..49f9cd9be1 100644 --- a/services/src/form_host_record.cpp +++ b/services/src/form_host_record.cpp @@ -170,16 +170,11 @@ void FormHostRecord::OnUpdate(int64_t id, const FormRecord &record) formHostCallback_->OnUpdate(id, record, formHostClient_); } -/** - * @brief Send form data after size changed to form host. - * @param formId The Id of the form. - * @param record Form record. - */ void FormHostRecord::OnSizeChanged(int64_t formId, const FormRecord &record) { HILOG_DEBUG("FormHostRecord OnSizeChanged"); if (formHostCallback_ == nullptr) { - HILOG_ERROR("%{public}s: formHostCallback_ can not be NULL", __func__); + HILOG_ERROR("formHostCallback_ can not be NULL"); return; } formHostCallback_->OnSizeChanged(formId, record, formHostClient_); diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index f49b8a11b8..d1cd44f7c9 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2395,7 +2395,7 @@ bool FormMgrAdapter::IsRequestPublishFormSupported() return true; } -int FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & formInfo) +ErrCode FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & formInfo) { std::vector formInfos {}; ErrCode errCode = FormInfoMgr::GetInstance().GetFormsInfoByModule(formRecord.bundleName, @@ -2426,12 +2426,12 @@ int FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & return ERR_OK; } -int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, - const sptr &callerToken) +ErrCode FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) { - HILOG_INFO("%{public}s called.", __func__); + HILOG_DEBUG("NotifyFormSizeChanged called."); if (formId <= 0 || callerToken == nullptr) { - HILOG_ERROR("%{public}s, releaseForm invalid param", __func__); + HILOG_ERROR("invalid param"); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } @@ -2475,7 +2475,7 @@ int FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t di want.SetElementName(record.bundleName, record.abilityName); ErrCode errorCode = FormAmsHelper::GetInstance().ConnectServiceAbility(want, formNotifySizeChangedConnection); if (errorCode != ERR_OK) { - HILOG_ERROR("%{public}s fail, ConnectServiceAbility failed.", __func__); + HILOG_ERROR("ConnectServiceAbility failed."); return ERR_APPEXECFWK_FORM_BIND_PROVIDER_FAILED; } diff --git a/services/src/form_mgr_service.cpp b/services/src/form_mgr_service.cpp index dcdd046ff1..fb03da1241 100644 --- a/services/src/form_mgr_service.cpp +++ b/services/src/form_mgr_service.cpp @@ -914,21 +914,14 @@ void FormMgrService::HiDumpFormInfoByFormId(const std::string &args, std::string DumpFormInfoByFormId(formId, result); } -/** - * @brief notify that the form size has been changed - * @param formId the formId - * @param dimensionNum the new dimensionNum of the form - * @param callerToken token of the ability that initially calls this function. - * @return Returns ERR_OK on success, others on failure. - */ -int32_t FormMgrService::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, - const sptr &callerToken) +ErrCode FormMgrService::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken) { - HILOG_INFO("%{public}s called.", __func__); + HILOG_DEBUG("NotifyFormSizeChanged called."); ErrCode ret = CheckFormPermission(); if (ret != ERR_OK) { - HILOG_ERROR("%{public}s fail, release form permission denied", __func__); + HILOG_ERROR("release form permission denied"); return ret; } diff --git a/services/src/form_notify_size_changed_connection.cpp b/services/src/form_notify_size_changed_connection.cpp index fcc197beaa..5b8de5a8a9 100644 --- a/services/src/form_notify_size_changed_connection.cpp +++ b/services/src/form_notify_size_changed_connection.cpp @@ -1,6 +1,5 @@ - /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -32,26 +31,20 @@ FormNotifySizeChangedConnection::FormNotifySizeChangedConnection(const int64_t f { SetProviderKey(bundleName, abilityName); } -/** - * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. - * - * @param element Service ability's ElementName. - * @param remoteObject The session proxy of service ability. - * @param resultCode ERR_OK on success, others on failure. - */ + void FormNotifySizeChangedConnection::OnAbilityConnectDone( const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) { - HILOG_INFO("%{public}s called.", __func__); + HILOG_DEBUG("OnAbilityConnectDone called."); if (resultCode != ERR_OK) { - HILOG_ERROR("%{public}s, abilityName:%{public}s, formId:%{public}" PRId64 ", resultCode:%{public}d", - __func__, element.GetAbilityName().c_str(), formId_, resultCode); + HILOG_ERROR("abilityName:%{public}s, formId:%{public}" PRId64 ", resultCode:%{public}d", + element.GetAbilityName().c_str(), formId_, resultCode); return; } FormSupplyCallback::GetInstance()->AddConnection(this); int32_t dimensionNum = dimensionNum_; if (dimensionNum == -1) { - HILOG_ERROR("%{public}s error, the dimension info is wrong", __func__); + HILOG_ERROR("the dimension info is wrong"); return; } Want newWant; diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index 6c057acf1f..bb7bd63a52 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -95,26 +95,20 @@ ErrCode FormProviderMgr::AcquireForm(const int64_t formId, const FormProviderInf return ERR_OK; } -/** - * @brief handle for resize form event from provider. - * @param formId The id of the form. - * @param providerFormInfo provider form info. - * @return Returns ERR_OK on success, others on failure. - */ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, const FormProviderInfo &formProviderInfo) { - HILOG_INFO("%{public}s called, formId:%{public}" PRId64 ".", __func__, formId); + HILOG_INFO("ResizeForm called, formId:%{public}" PRId64 ".", formId); FormRecord formRecord; bool isGetFormRecord = FormDataMgr::GetInstance().GetFormRecord(formId, formRecord); if (!isGetFormRecord) { - HILOG_ERROR("%{public}s fail, not exist such form, formId:%{public}" PRId64 "", __func__, formId); + HILOG_ERROR("Don't exist such form, formId:%{public}" PRId64 "", formId); return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; } int32_t dimensionId = want.GetIntParam(Constants::PARAM_FORM_DIMENSION_KEY, 0); if (dimensionId == 0) { - HILOG_ERROR("%{public}s fail, the dimensionId is wrong, formId:%{public}" PRId64 "", __func__, formId); + HILOG_ERROR("the dimensionId is wrong, formId:%{public}" PRId64 "", formId); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } @@ -124,7 +118,7 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons std::vector clientHosts; FormDataMgr::GetInstance().GetFormHostRecord(formId, clientHosts); if (clientHosts.empty()) { - HILOG_ERROR("%{public}s fail, clientHosst is empty", __func__); + HILOG_ERROR("clientHost is empty"); return ERR_APPEXECFWK_FORM_COMMON_CODE; } @@ -154,7 +148,7 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons if (formRecord.formProviderInfo.NeedCache()) { std::string jsonData = formRecord.formProviderInfo.GetFormDataString(); - HILOG_DEBUG("%{public}s jsonData:%{public}s.", __func__, jsonData.c_str()); + HILOG_DEBUG("jsonData:%{public}s.", jsonData.c_str()); FormCacheMgr::GetInstance().AddData(formId, jsonData); } else { FormCacheMgr::GetInstance().DeleteData(formId); diff --git a/services/src/form_task_mgr.cpp b/services/src/form_task_mgr.cpp index dde299b9c0..886570c5b2 100644 --- a/services/src/form_task_mgr.cpp +++ b/services/src/form_task_mgr.cpp @@ -171,19 +171,13 @@ void FormTaskMgr::PostUpdateTaskToHost(const int64_t formId, const FormRecord &r eventHandler_->PostTask(updateTaskToHostFunc, FORM_TASK_DELAY_TIME); } -/** - * @brief Post form data to form host(task) when change form size. - * @param formId The Id of the form. - * @param record form record. - * @param remoteObject Form provider proxy object. - */ void FormTaskMgr::PostSizeChangedTaskToHost(const int64_t formId, const FormRecord &record, const sptr &remoteObject) { - HILOG_INFO("%{public}s called.", __func__); + HILOG_DEBUG("PostSizeChangedTaskToHost called."); if (eventHandler_ == nullptr) { - HILOG_ERROR("%{public}s fail, event handler invalidate.", __func__); + HILOG_ERROR("event handler invalidate."); return; } @@ -351,18 +345,11 @@ void FormTaskMgr::PostFormShareSendResponse(int64_t formShareRequestCode, int32_ HILOG_INFO("%{public}s end", __func__); } -/** - * @brief Post notify form size change to form provider(task). - * @param formId The form id. - * @param want The want of notifyFormSizeChanged. - * @param dimensionNum The dimension id of the new form. - * @param remoteObject Form provider proxy object. - */ void FormTaskMgr::PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const Want &want, const sptr &remoteObject) { if (eventHandler_ == nullptr) { - HILOG_ERROR("%{public}s fail, event handler invalidate", __func__); + HILOG_ERROR("event handler invalidate"); return; } auto notifyFormSizeChangedFunc = [formId, dimensionNum, want, remoteObject]() { @@ -371,12 +358,6 @@ void FormTaskMgr::PostNotifyFormSizeChanged(const int64_t formId, const int32_t eventHandler_->PostTask(notifyFormSizeChangedFunc, FORM_TASK_DELAY_TIME); } -/** - * @brief Acquire form data from form provider. - * @param formId The Id of the from. - * @param want The want of the request. - * @param remoteObject Form provider proxy object. - */ void FormTaskMgr::AcquireProviderFormInfo(const int64_t formId, const Want &want, const sptr &remoteObject) { @@ -531,27 +512,21 @@ void FormTaskMgr::UpdateTaskToHost(const int64_t formId, const FormRecord &recor HILOG_INFO("%{public}s end.", __func__); } -/** - * @brief Post form data to form host when change form size. - * @param formId The Id of the form. - * @param record form record. - * @param remoteObject Form provider proxy object. - */ void FormTaskMgr::SizeChangedTaskToHost(const int64_t formId, const FormRecord &record, const sptr &remoteObject) { - HILOG_INFO("%{public}s start.", __func__); + HILOG_DEBUG("SizeChangedTaskToHost start."); sptr remoteFormHost = iface_cast(remoteObject); if (remoteFormHost == nullptr) { - HILOG_ERROR("%{public}s fail, Failed to get form host proxy.", __func__); + HILOG_ERROR("Failed to get form host proxy."); return; } - HILOG_DEBUG("%{public}s, FormTaskMgr remoteFormHost OnUpdate.", __func__); + HILOG_DEBUG("FormTaskMgr remoteFormHost OnUpdate."); remoteFormHost->OnSizeChanged(CreateFormJsInfo(formId, record)); - HILOG_INFO("%{public}s end.", __func__); + HILOG_DEBUG("SizeChangedTaskToHost end."); } /** @@ -687,23 +662,16 @@ void FormTaskMgr::AcquireStateBack(AppExecFwk::FormState state, const AAFwk::Wan HILOG_INFO("%{public}s end", __func__); } -/** - * @brief Handle notify form size change to form provider. - * @param formId The form id. - * @param want The want of notifyFormSizeChanged. - * @param dimensionNum The dimension id of the new form. - * @param remoteObject Form provider proxy object. - */ void FormTaskMgr::NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const Want &want, const sptr &remoteObject) { - HILOG_INFO("%{public}s called.", __func__); + HILOG_DEBUG("NotifyProviderFormSizeChange called."); long connectId = want.GetLongParam(Constants::FORM_CONNECT_ID, 0); sptr formProviderProxy = iface_cast(remoteObject); if (formProviderProxy == nullptr) { FormSupplyCallback::GetInstance()->RemoveConnection(connectId); - HILOG_ERROR("%{public}s fail, failed to get formProviderProxy", __func__); + HILOG_ERROR("failed to get formProviderProxy"); return; } @@ -713,7 +681,7 @@ void FormTaskMgr::NotifyProviderFormSizeChanged(const int64_t formId, const int3 int error = formProviderProxy->NotifyFormSizeChanged(formId, newWant, FormSupplyCallback::GetInstance()); if (error != ERR_OK) { FormSupplyCallback::GetInstance()->RemoveConnection(connectId); - HILOG_ERROR("%{public}s fail, Failed to notify form update.", __func__); + HILOG_ERROR("Failed to notify form update."); } } -- Gitee From 0b6f9764f8f54b3dfb9c279f5c7d00a7706649c8 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 30 Aug 2022 09:59:30 +0800 Subject: [PATCH 22/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I8c6ea19e74030e0132882afff5ac9cf64bd97d6c --- services/include/form_mgr_adapter.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index c9f306fc86..09aa6047f6 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -338,7 +338,8 @@ public: * @param callerToken Host client. * @return Returns ERR_OK on success, others on failure. */ - ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, const sptr &callerToken); + ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + const sptr &callerToken); private: /** * @brief Get form configure info. -- Gitee From f875b7b749593e2f97b1bb35b2f0d69257270618 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Tue, 30 Aug 2022 15:49:23 +0800 Subject: [PATCH 23/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: Ib37d134c3af0b49ecc32d5c9744c68bd7e98623f --- .../js/napi/formHost/napi_form_host.cpp | 54 +++++++++---------- services/include/form_mgr_adapter.h | 2 +- .../form_notify_size_changed_connection.h | 8 +-- services/src/form_provider_mgr.cpp | 8 +-- .../form_mgr_proxy_test.cpp | 4 +- test/unittest/form_mgr_test/form_mgr_test.cpp | 12 ++--- 6 files changed, 42 insertions(+), 46 deletions(-) diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index 717974d856..3fba1d75b6 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -3336,30 +3336,30 @@ static void InnerFormSizeChanged(napi_env env, AsyncFormResizeCallbackInfo* cons napi_value NotifyFormSizeChangedCallback(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) { HILOG_DEBUG("NotifyFormSizeChangedCallback."); - napi_value resourceName; - napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_value resource; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resource); napi_create_async_work( env, nullptr, - resourceName, + resource, [](napi_env env, void *data) { - HILOG_INFO("%{public}s, napi_create_async_work running", __func__); + HILOG_INFO("napi_create_async_work running"); AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; InnerFormSizeChanged(env, asyncCallbackInfo); }, [](napi_env env, napi_status status, void *data) { AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; - HILOG_INFO("%{public}s, napi_create_async_work complete", __func__); + HILOG_INFO("napi_create_async_work complete"); if (asyncCallbackInfo->callback != nullptr) { napi_value result[ARGS_SIZE_TWO] = {0}; InnerCreateCallbackRetMsg(env, asyncCallbackInfo->result, result); napi_value callback; - napi_value undefined; - napi_get_undefined(env, &undefined); + napi_value undefinedValue; + napi_get_undefined(env, &undefinedValue); napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); - napi_value callResult; - napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &callResult); + napi_value resultCode; + napi_call_function(env, undefinedValue, callback, ARGS_SIZE_TWO, result, &resultCode); napi_delete_reference(env, asyncCallbackInfo->callback); } napi_delete_async_work(env, asyncCallbackInfo->asyncWork); @@ -3375,31 +3375,31 @@ napi_value NotifyFormSizeChangedPromise(napi_env env, AsyncFormResizeCallbackInf { HILOG_DEBUG("NotifyFormSizeChangedPromise."); napi_deferred deferred; - napi_value promise; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + napi_value promiseValue; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promiseValue)); asyncCallbackInfo->deferred = deferred; - napi_value resourceName; - napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); + napi_value resource; + napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resource); napi_create_async_work( env, nullptr, - resourceName, + resource, [](napi_env env, void *data) { - HILOG_INFO("%{public}s, promise running", __func__); + HILOG_INFO("promise running"); AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; InnerFormSizeChanged(env, asyncCallbackInfo); }, [](napi_env env, napi_status status, void *data) { - HILOG_INFO("%{public}s, promise complete", __func__); + HILOG_INFO("promise complete"); AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; - napi_value result; - InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &result); + napi_value resultCode; + InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &resultCode); if (asyncCallbackInfo->result == ERR_OK) { - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, resultCode); } else { - napi_reject_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_reject_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, resultCode); } napi_delete_async_work(env, asyncCallbackInfo->asyncWork); delete asyncCallbackInfo; @@ -3407,7 +3407,7 @@ napi_value NotifyFormSizeChangedPromise(napi_env env, AsyncFormResizeCallbackInf (void *)asyncCallbackInfo, &asyncCallbackInfo->asyncWork); napi_queue_async_work(env, asyncCallbackInfo->asyncWork); - return promise; + return promiseValue; } napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) @@ -3428,32 +3428,28 @@ napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) // Check the value type of the formId argument napi_valuetype valueType; NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ZERO], &valueType)); - if (valueType != napi_string) { + if (valueType != napi_string) return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_INVALID_FORM_ID, callbackType, argv[ARGS_SIZE_TWO])); - } // Check the value type of the size argument valueType = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ONE], &valueType)); - if (valueType != napi_string) { + if (valueType != napi_string) return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_INVALID_PARAM, callbackType, argv[ARGS_SIZE_TWO])); - } // Check the value of the formId argument std::string strFormId = GetStringFromNAPI(env, argv[ARGS_SIZE_ZERO]); int64_t formId = 0; HILOG_ERROR("%{public}s, form id ", strFormId.c_str()); - if (!ConvertStringToInt64(strFormId, formId)) { + if (!ConvertStringToInt64(strFormId, formId)) return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_FORM_ID_NUM_ERR, callbackType, argv[ARGS_SIZE_ONE])); - } // Get the value of the size argument std::string newDimension = GetStringFromNAPI(env, argv[ARGS_SIZE_ONE]); int64_t dimensionNum = 0; ConvertStringToInt64(newDimension, dimensionNum); int32_t dimensionId = dimensionNum; - AsyncFormResizeCallbackInfo *asyncCallbackInfo = new - AsyncFormResizeCallbackInfo { + AsyncFormResizeCallbackInfo *asyncCallbackInfo = new AsyncFormResizeCallbackInfo { .env = env, .asyncWork = nullptr, .deferred = nullptr, diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index 09aa6047f6..f87f235259 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -329,7 +329,7 @@ public: * @param formInfos Return the form' information of the specify bundle name and module name. * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetFormInfoByFormRecord(FormRecord & formrecord, FormInfo & formInfo); + ErrCode GetFormInfoByFormRecord(FormRecord &formrecord, FormInfo &formInfo); /** * @brief Notify the form to change size. diff --git a/services/include/form_notify_size_changed_connection.h b/services/include/form_notify_size_changed_connection.h index 000ce992e7..4a2bd3e7a7 100644 --- a/services/include/form_notify_size_changed_connection.h +++ b/services/include/form_notify_size_changed_connection.h @@ -23,7 +23,7 @@ namespace AppExecFwk { /** * @class FormNotifySizeChangedConnection * Form notify to change size connection stub - */ + */\ class FormNotifySizeChangedConnection : public FormAbilityConnection { public: FormNotifySizeChangedConnection(const int64_t formId, const int32_t dimensionNum, @@ -32,9 +32,9 @@ public: /** * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. - * @param element service ability's ElementName. - * @param remoteObject the session proxy of service ability. - * @param resultCode ERR_OK on success, others on failure. + * @param element Service ability's ElementName. + * @param remoteObject The session proxy of service ability. + * @param resultCode return ERR_OK on success, others on failure. */ void OnAbilityConnectDone( const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index bb7bd63a52..def55d4f0b 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -124,10 +124,7 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons FormProviderData formProviderData = formProviderInfo.GetFormData(); - if (formRecord.versionUpgrade) { - formRecord.formProviderInfo.SetFormData(formProviderData); - formRecord.formProviderInfo.SetUpgradeFlg(true); - } else { + if (!formRecord.versionUpgrade) { nlohmann::json addJsonData = formProviderData.GetData(); formRecord.formProviderInfo.MergeData(addJsonData); // merge image @@ -135,6 +132,9 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons formData.SetImageDataState(formProviderData.GetImageDataState()); formData.SetImageDataMap(formProviderData.GetImageDataMap()); formRecord.formProviderInfo.SetFormData(formData); + } else { + formRecord.formProviderInfo.SetFormData(formProviderData); + formRecord.formProviderInfo.SetUpgradeFlg(true); } formRecord.isInited = true; diff --git a/test/unittest/form_mgr_proxy_test/form_mgr_proxy_test.cpp b/test/unittest/form_mgr_proxy_test/form_mgr_proxy_test.cpp index 22ebe19165..b87cf2ce6f 100644 --- a/test/unittest/form_mgr_proxy_test/form_mgr_proxy_test.cpp +++ b/test/unittest/form_mgr_proxy_test/form_mgr_proxy_test.cpp @@ -177,7 +177,7 @@ HWTEST_F(FormMgrProxyTest, FormMgrProxyTest_0005, TestSize.Level1) { HWTEST_F(FormMgrProxyTest, FormMgrProxyTest_0006, TestSize.Level1) { GTEST_LOG_(INFO) << "FormMgrProxyTest_0006 starts"; // initialize input parameters. - int64_t form_Id = 1; + int64_t formId = 1; int32_t dimensionNum = 1; sptr token = new (std::nothrow) MockFormToken(); @@ -185,7 +185,7 @@ HWTEST_F(FormMgrProxyTest, FormMgrProxyTest_0006, TestSize.Level1) { .Times(1) .WillOnce(Return(0)); // test. - bool result = formMgrProxy->NotifyFormSizeChanged(form_Id, dimensionNum, token); + bool result = formMgrProxy->NotifyFormSizeChanged(formId, dimensionNum, token); // expect result. EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "FormMgrProxyTest_0006 test ends"; diff --git a/test/unittest/form_mgr_test/form_mgr_test.cpp b/test/unittest/form_mgr_test/form_mgr_test.cpp index 7a9ff5c707..4437ea047e 100644 --- a/test/unittest/form_mgr_test/form_mgr_test.cpp +++ b/test/unittest/form_mgr_test/form_mgr_test.cpp @@ -166,7 +166,7 @@ HWTEST_F(FormMgrTest, FormMgrTest_0004, TestSize.Level1) { HWTEST_F(FormMgrTest, FormMgrTest_0005, TestSize.Level1) { GTEST_LOG_(INFO) << "FormMgrTest_0005 starts"; // initialize input parameters. - int64_t form_Id = 1; + int64_t formId = 1; int32_t dimensionId = 1; sptr token = new (std::nothrow) MockFormToken(); @@ -174,7 +174,7 @@ HWTEST_F(FormMgrTest, FormMgrTest_0005, TestSize.Level1) { .Times(1) .WillOnce(Return(0)); - int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(form_Id, dimensionId, token); + int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(formId, dimensionId, token); EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "FormMgrTest_0005 test ends"; } @@ -188,7 +188,7 @@ HWTEST_F(FormMgrTest, FormMgrTest_0005, TestSize.Level1) { HWTEST_F(FormMgrTest, FormMgrTest_0006, TestSize.Level1) { GTEST_LOG_(INFO) << "FormMgrTest_0006 starts"; // initialize input parameters. - int64_t form_Id = 0; + int64_t formId = 0; int32_t dimensionId = 1; sptr token = new (std::nothrow) MockFormToken(); @@ -196,7 +196,7 @@ HWTEST_F(FormMgrTest, FormMgrTest_0006, TestSize.Level1) { .Times(1) .WillOnce(Return(0)); - int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(form_Id, dimensionId, token); + int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(formId, dimensionId, token); EXPECT_EQ(result, 2293768); GTEST_LOG_(INFO) << "FormMgrTest_0006 test ends"; } @@ -210,7 +210,7 @@ HWTEST_F(FormMgrTest, FormMgrTest_0006, TestSize.Level1) { HWTEST_F(FormMgrTest, FormMgrTest_0007, TestSize.Level1) { GTEST_LOG_(INFO) << "FormMgrTest_0007 starts"; // initialize input parameters. - int64_t form_Id = 1; + int64_t formId = 1; int32_t dimensionId = 0; sptr token = new (std::nothrow) MockFormToken(); @@ -218,7 +218,7 @@ HWTEST_F(FormMgrTest, FormMgrTest_0007, TestSize.Level1) { .Times(1) .WillOnce(Return(0)); - int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(form_Id, dimensionId, token); + int32_t result = FormMgr::GetInstance().NotifyFormSizeChanged(formId, dimensionId, token); EXPECT_EQ(result, 2293767); GTEST_LOG_(INFO) << "FormMgrTest_0007 test ends"; } -- Gitee From 8b9b6c94b9fced8c9fc7c139ffcfe2ca1c4c9f6e Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 31 Aug 2022 11:11:50 +0800 Subject: [PATCH 24/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I1ab265cecb3ef9c0b4b2034318530b8f8230632a --- .../js/napi/formHost/napi_form_host.cpp | 208 +++++------------- frameworks/js/napi/formHost/napi_form_host.h | 13 +- frameworks/js/napi/formHost/native_module.cpp | 2 +- interfaces/inner_api/include/form_mgr_proxy.h | 2 +- .../include/form_provider_interface.h | 2 +- .../inner_api/include/form_provider_proxy.h | 2 +- .../kits/native/include/form_host_client.h | 2 +- services/include/form_mgr_adapter.h | 2 +- .../form_notify_size_changed_connection.h | 2 +- services/src/form_mgr_adapter.cpp | 2 +- 10 files changed, 68 insertions(+), 169 deletions(-) diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index 3fba1d75b6..01ee598ff3 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -3323,156 +3323,6 @@ napi_value NAPI_GetFormsInfo(napi_env env, napi_callback_info info) return NapiGetResult(env, 1); } -static void InnerFormSizeChanged(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) -{ - HILOG_DEBUG("InnerFormSizeChanged called."); - if (asyncCallbackInfo != nullptr) { - asyncCallbackInfo->result = FormMgr::GetInstance().NotifyFormSizeChanged(asyncCallbackInfo->formId, - asyncCallbackInfo->dimensionId, FormHostClient::GetInstance()); - } - HILOG_DEBUG("InnerFormSizeChanged end"); -} - -napi_value NotifyFormSizeChangedCallback(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) -{ - HILOG_DEBUG("NotifyFormSizeChangedCallback."); - napi_value resource; - napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resource); - napi_create_async_work( - env, - nullptr, - resource, - [](napi_env env, void *data) { - HILOG_INFO("napi_create_async_work running"); - AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; - InnerFormSizeChanged(env, asyncCallbackInfo); - }, - [](napi_env env, napi_status status, void *data) { - AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; - HILOG_INFO("napi_create_async_work complete"); - - if (asyncCallbackInfo->callback != nullptr) { - napi_value result[ARGS_SIZE_TWO] = {0}; - InnerCreateCallbackRetMsg(env, asyncCallbackInfo->result, result); - napi_value callback; - napi_value undefinedValue; - napi_get_undefined(env, &undefinedValue); - napi_get_reference_value(env, asyncCallbackInfo->callback, &callback); - napi_value resultCode; - napi_call_function(env, undefinedValue, callback, ARGS_SIZE_TWO, result, &resultCode); - napi_delete_reference(env, asyncCallbackInfo->callback); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - return NapiGetResult(env, 1); -} - -napi_value NotifyFormSizeChangedPromise(napi_env env, AsyncFormResizeCallbackInfo* const asyncCallbackInfo) -{ - HILOG_DEBUG("NotifyFormSizeChangedPromise."); - napi_deferred deferred; - napi_value promiseValue; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promiseValue)); - asyncCallbackInfo->deferred = deferred; - - napi_value resource; - napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resource); - napi_create_async_work( - env, - nullptr, - resource, - [](napi_env env, void *data) { - HILOG_INFO("promise running"); - AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; - InnerFormSizeChanged(env, asyncCallbackInfo); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("promise complete"); - AsyncFormResizeCallbackInfo *asyncCallbackInfo = (AsyncFormResizeCallbackInfo *)data; - - napi_value resultCode; - InnerCreatePromiseRetMsg(env, asyncCallbackInfo->result, &resultCode); - if (asyncCallbackInfo->result == ERR_OK) { - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, resultCode); - } else { - napi_reject_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, resultCode); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); - return promiseValue; -} - -napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info) -{ - HILOG_DEBUG("NAPI_NotifyFormSizeChanged called."); - - // Check the number of the arguments - size_t argc = ARGS_SIZE_THREE; - napi_value argv[ARGS_SIZE_THREE] = { nullptr }; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); - if (argc < ARGS_SIZE_TWO || argc > ARGS_SIZE_THREE) { - HILOG_ERROR("NAPI_NotifyFormSizeChanged, wrong number of arguments."); - return nullptr; - } - - int32_t callbackType = (argc == ARGS_SIZE_THREE) ? CALLBACK_FLG : PROMISE_FLG; - - // Check the value type of the formId argument - napi_valuetype valueType; - NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ZERO], &valueType)); - if (valueType != napi_string) - return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_INVALID_FORM_ID, callbackType, argv[ARGS_SIZE_TWO])); - - // Check the value type of the size argument - valueType = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ONE], &valueType)); - if (valueType != napi_string) - return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_INVALID_PARAM, callbackType, argv[ARGS_SIZE_TWO])); - - // Check the value of the formId argument - std::string strFormId = GetStringFromNAPI(env, argv[ARGS_SIZE_ZERO]); - int64_t formId = 0; - HILOG_ERROR("%{public}s, form id ", strFormId.c_str()); - if (!ConvertStringToInt64(strFormId, formId)) - return RetErrMsg(InitErrMsg(env, ERR_APPEXECFWK_FORM_FORM_ID_NUM_ERR, callbackType, argv[ARGS_SIZE_ONE])); - - // Get the value of the size argument - std::string newDimension = GetStringFromNAPI(env, argv[ARGS_SIZE_ONE]); - int64_t dimensionNum = 0; - ConvertStringToInt64(newDimension, dimensionNum); - int32_t dimensionId = dimensionNum; - AsyncFormResizeCallbackInfo *asyncCallbackInfo = new AsyncFormResizeCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - .callback = nullptr, - .formId = 0, - .dimensionId = 0, - .result = 0, - }; - asyncCallbackInfo->formId = formId; - asyncCallbackInfo->dimensionId = dimensionId; - - if (argc == ARGS_SIZE_THREE) { - // Check the value type of the arguments - valueType = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_TWO], &valueType)); - NAPI_ASSERT(env, valueType == napi_function, "The arg[2] type is incorrect, expected type is function."); - napi_create_reference(env, argv[ARGS_SIZE_TWO], REF_COUNT, &asyncCallbackInfo->callback); - return NotifyFormSizeChangedCallback(env, asyncCallbackInfo); - } else { - return NotifyFormSizeChangedPromise(env, asyncCallbackInfo); - } -} - int64_t SystemTimeMillis() noexcept { struct timespec t; @@ -3590,4 +3440,62 @@ void JsFormHost::InnerShareForm( asyncTask->Reject(engine, AbilityRuntime::CreateJsError(engine, retCode, retMsg)); FormHostClient::GetInstance()->RemoveShareFormCallback(requestCode); } +} + +NativeValue* JsFormHost::ResizeForm(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsFormHost* me = OHOS::AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnResizeForm(*engine, *info) : nullptr; +} + +NativeValue* JsFormHost::OnResizeForm(NativeEngine &engine, NativeCallbackInfo &info) +{ + HILOG_DEBUG("OnResizeForm is called"); + int32_t errCode = ERR_OK; + if (info.argc > ARGS_SIZE_THREE || info.argc < ARGS_SIZE_TWO) { + HILOG_ERROR("%{public}s, wrong number of arguments.", __func__); + errCode = ERR_ADD_INVALID_PARAM; + } + + std::string strFormId = + ::GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[0])); + std::string strDimensionId = + ::GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[1])); + // The promise form has only two parameters + decltype(info.argc) unwrapArgc = 2; + + int64_t formId = 0; + int64_t dimensionNum = 0; + if (!ConvertStringToInt64(strFormId, formId) || !ConvertStringToInt64(strDimensionId, dimensionNum)) { + HILOG_ERROR("Convert string formId to int64 failed."); + errCode = ERR_COMMON; + } + int32_t dimensionId = dimensionNum; + if (formId == 0 || dimensionId < 0) { + errCode = ERR_COMMON; + } + + AbilityRuntime::AsyncTask::CompleteCallback complete = + [formId, dimensionId, errCode](NativeEngine &engine, AbilityRuntime::AsyncTask &task, int32_t status) { + if (errCode != ERR_OK) { + task.Reject(engine, CreateJsError(engine, errCode, QueryRetMsg(errCode))); + return; + } + + auto ret = FormMgr::GetInstance().NotifyFormSizeChanged(formId, + dimensionId, FormHostClient::GetInstance()); + if (ret == ERR_OK) { + task.Resolve(engine, engine.CreateUndefined()); + } else { + auto retCode = QueryRetCode(ret); + task.Reject(engine, CreateJsError(engine, retCode, QueryRetMsg(retCode))); + } + }; + + NativeValue* lastParam = (info.argc <= unwrapArgc) ? nullptr : info.argv[unwrapArgc]; + NativeValue* result = nullptr; + + AsyncTask::Schedule("JsFormHost::OnResizeForm", + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; } \ No newline at end of file diff --git a/frameworks/js/napi/formHost/napi_form_host.h b/frameworks/js/napi/formHost/napi_form_host.h index 57682a8023..1d6b277cd1 100644 --- a/frameworks/js/napi/formHost/napi_form_host.h +++ b/frameworks/js/napi/formHost/napi_form_host.h @@ -156,16 +156,6 @@ struct AsyncGetFormsInfoCallbackInfo { int result; }; -struct AsyncFormResizeCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - napi_ref callback; - int64_t formId; - int32_t dimensionId; - int result; -}; - napi_value NAPI_DeleteForm(napi_env env, napi_callback_info info); napi_value NAPI_ReleaseForm(napi_env env, napi_callback_info info); napi_value NAPI_RequestForm(napi_env env, napi_callback_info info); @@ -183,7 +173,6 @@ napi_value NAPI_NotifyFormsVisible(napi_env env, napi_callback_info info); napi_value NAPI_NotifyFormsEnableUpdate(napi_env env, napi_callback_info info); napi_value NAPI_GetAllFormsInfo(napi_env env, napi_callback_info info); napi_value NAPI_GetFormsInfo(napi_env env, napi_callback_info info); -napi_value NAPI_NotifyFormSizeChanged(napi_env env, napi_callback_info info); using ShareFormTask = std::function; class JsFormHost { @@ -193,9 +182,11 @@ public: static void Finalizer(NativeEngine* engine, void* data, void* hint); static NativeValue* ShareForm(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* ResizeForm(NativeEngine* engine, NativeCallbackInfo* info); private: NativeValue* OnShareForm(NativeEngine &engine, NativeCallbackInfo &info); void InnerShareForm(NativeEngine &engine, const std::shared_ptr &asyncTask, ShareFormTask &&task, int64_t formId, const std::string &remoteDeviceId); + NativeValue* OnResizeForm(NativeEngine &engine, NativeCallbackInfo &info); }; #endif /* OHOS_FORM_FWK_NAPI_FORM_HOST_H_ */ diff --git a/frameworks/js/napi/formHost/native_module.cpp b/frameworks/js/napi/formHost/native_module.cpp index d2621b0d1c..aba70c3438 100644 --- a/frameworks/js/napi/formHost/native_module.cpp +++ b/frameworks/js/napi/formHost/native_module.cpp @@ -44,6 +44,7 @@ static NativeValue* JsFormHostInit(NativeEngine* engine, NativeValue* exports) object->SetNativePointer(jsFormHost.release(), JsFormHost::Finalizer, nullptr); OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "shareForm", JsFormHost::ShareForm); + OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "NotifyFormSizeChange", JsFormHost::ResizeForm); return exports; } @@ -77,7 +78,6 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("notifyFormsEnableUpdate", NAPI_NotifyFormsEnableUpdate), DECLARE_NAPI_FUNCTION("getAllFormsInfo", NAPI_GetAllFormsInfo), DECLARE_NAPI_FUNCTION("getFormsInfo", NAPI_GetFormsInfo), - DECLARE_NAPI_FUNCTION("NotifyFormSizeChange", NAPI_NotifyFormSizeChanged), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties)); HILOG_INFO("napi_moudule Init end..."); diff --git a/interfaces/inner_api/include/form_mgr_proxy.h b/interfaces/inner_api/include/form_mgr_proxy.h index e37459cb68..9967c24068 100644 --- a/interfaces/inner_api/include/form_mgr_proxy.h +++ b/interfaces/inner_api/include/form_mgr_proxy.h @@ -295,7 +295,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, - const sptr &callerToken) override; + const sptr &callerToken) override; /** * @brief Check if the request of publishing a form is supported by the host. diff --git a/interfaces/inner_api/include/form_provider_interface.h b/interfaces/inner_api/include/form_provider_interface.h index e762cdd69b..f940a40281 100644 --- a/interfaces/inner_api/include/form_provider_interface.h +++ b/interfaces/inner_api/include/form_provider_interface.h @@ -122,7 +122,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, - const sptr &callerToken) = 0; + const sptr &callerToken) = 0; /** * @brief Acquire to share form information data. This is sync API. diff --git a/interfaces/inner_api/include/form_provider_proxy.h b/interfaces/inner_api/include/form_provider_proxy.h index 086d5da059..5f659a46fd 100644 --- a/interfaces/inner_api/include/form_provider_proxy.h +++ b/interfaces/inner_api/include/form_provider_proxy.h @@ -124,7 +124,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode NotifyFormSizeChanged(const int64_t formId, const Want &want, - const sptr &callerToken) override; + const sptr &callerToken) override; /** * @brief Acquire to share form information data. This is sync API. diff --git a/interfaces/kits/native/include/form_host_client.h b/interfaces/kits/native/include/form_host_client.h index 95cc757657..3963e46ba4 100644 --- a/interfaces/kits/native/include/form_host_client.h +++ b/interfaces/kits/native/include/form_host_client.h @@ -144,7 +144,7 @@ public: * @param formJsInfo Form js info. * @return none. */ - virtual void OnSizeChanged(const FormJsInfo &formJsInfo); + void OnSizeChanged(const FormJsInfo &formJsInfo); private: static std::mutex instanceMutex_; diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index f87f235259..54d9d675f8 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -329,7 +329,7 @@ public: * @param formInfos Return the form' information of the specify bundle name and module name. * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetFormInfoByFormRecord(FormRecord &formrecord, FormInfo &formInfo); + ErrCode GetFormInfoByFormRecord(const FormRecord &formrecord, FormInfo &formInfo); /** * @brief Notify the form to change size. diff --git a/services/include/form_notify_size_changed_connection.h b/services/include/form_notify_size_changed_connection.h index 4a2bd3e7a7..4c9e26fac2 100644 --- a/services/include/form_notify_size_changed_connection.h +++ b/services/include/form_notify_size_changed_connection.h @@ -26,7 +26,7 @@ namespace AppExecFwk { */\ class FormNotifySizeChangedConnection : public FormAbilityConnection { public: - FormNotifySizeChangedConnection(const int64_t formId, const int32_t dimensionNum, + FormNotifySizeChangedConnection(int64_t formId, int32_t dimensionNum, const std::string &bundleName, const std::string &abilityName); virtual ~FormNotifySizeChangedConnection() = default; diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index d1cd44f7c9..922107169b 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2395,7 +2395,7 @@ bool FormMgrAdapter::IsRequestPublishFormSupported() return true; } -ErrCode FormMgrAdapter::GetFormInfoByFormRecord(FormRecord & formRecord, FormInfo & formInfo) +ErrCode FormMgrAdapter::GetFormInfoByFormRecord(const FormRecord &formRecord, FormInfo &formInfo) { std::vector formInfos {}; ErrCode errCode = FormInfoMgr::GetInstance().GetFormsInfoByModule(formRecord.bundleName, -- Gitee From a45215b8b35a7005ceead8a9747d4f9259d32c3d Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 31 Aug 2022 11:15:12 +0800 Subject: [PATCH 25/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I1abed59c58f5a3096aadec4f0f89af38781c7897 --- frameworks/js/napi/formHost/native_module.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/formHost/native_module.cpp b/frameworks/js/napi/formHost/native_module.cpp index aba70c3438..7382b363f8 100644 --- a/frameworks/js/napi/formHost/native_module.cpp +++ b/frameworks/js/napi/formHost/native_module.cpp @@ -43,8 +43,9 @@ static NativeValue* JsFormHostInit(NativeEngine* engine, NativeValue* exports) std::unique_ptr jsFormHost = std::make_unique(); object->SetNativePointer(jsFormHost.release(), JsFormHost::Finalizer, nullptr); - OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "shareForm", JsFormHost::ShareForm); - OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "NotifyFormSizeChange", JsFormHost::ResizeForm); + const char *moduleName = "JsFormHost"; + OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "shareForm", moduleName, JsFormHost::ShareForm); + OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "NotifyFormSizeChange", moduleName, JsFormHost::ResizeForm); return exports; } -- Gitee From f840caeef7b53d0cab329dc815bb0a1605703f87 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 31 Aug 2022 12:52:45 +0800 Subject: [PATCH 26/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I5720fc16a03199d0bde0962bed061bcd1183cab0 --- frameworks/js/napi/formHost/napi_form_host.cpp | 4 ++-- frameworks/js/napi/formHost/native_module.cpp | 3 ++- interfaces/inner_api/include/form_js_info.h | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/js/napi/formHost/napi_form_host.cpp b/frameworks/js/napi/formHost/napi_form_host.cpp index 01ee598ff3..b89669162d 100644 --- a/frameworks/js/napi/formHost/napi_form_host.cpp +++ b/frameworks/js/napi/formHost/napi_form_host.cpp @@ -3458,9 +3458,9 @@ NativeValue* JsFormHost::OnResizeForm(NativeEngine &engine, NativeCallbackInfo & } std::string strFormId = - ::GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[0])); + GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[0])); std::string strDimensionId = - ::GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[1])); + GetStringFromNAPI(reinterpret_cast(&engine), reinterpret_cast(info.argv[1])); // The promise form has only two parameters decltype(info.argc) unwrapArgc = 2; diff --git a/frameworks/js/napi/formHost/native_module.cpp b/frameworks/js/napi/formHost/native_module.cpp index 7382b363f8..a970551811 100644 --- a/frameworks/js/napi/formHost/native_module.cpp +++ b/frameworks/js/napi/formHost/native_module.cpp @@ -45,7 +45,8 @@ static NativeValue* JsFormHostInit(NativeEngine* engine, NativeValue* exports) const char *moduleName = "JsFormHost"; OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "shareForm", moduleName, JsFormHost::ShareForm); - OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "NotifyFormSizeChange", moduleName, JsFormHost::ResizeForm); + OHOS::AbilityRuntime::BindNativeFunction(*engine, *object, "NotifyFormSizeChange", + moduleName, JsFormHost::ResizeForm); return exports; } diff --git a/interfaces/inner_api/include/form_js_info.h b/interfaces/inner_api/include/form_js_info.h index 2a25b61bec..2e19e711e3 100644 --- a/interfaces/inner_api/include/form_js_info.h +++ b/interfaces/inner_api/include/form_js_info.h @@ -40,7 +40,6 @@ struct FormJsInfo : public Parcelable { std::map> imageDataMap; FormProviderData formProviderData; int32_t specification; - std::string formSrc; FormWindow formWindow; uint32_t versionCode = 0; -- Gitee From d553b7cf6dc32fa42cb58d64c02faa13d69b6705 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 31 Aug 2022 15:33:25 +0800 Subject: [PATCH 27/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I912d047928a6f8b7718558bee6d7624f6d7cc754 --- services/src/form_mgr_adapter.cpp | 14 +++--- .../form_notify_size_changed_connection.cpp | 4 +- services/src/form_provider_mgr.cpp | 49 +------------------ 3 files changed, 9 insertions(+), 58 deletions(-) diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 922107169b..5309ae6e94 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2438,6 +2438,12 @@ ErrCode FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_ FormRecord record; FormDataMgr::GetInstance().GetFormRecord(formId, record); + if(record.formUserUids.size() > 1) + { + HILOG_ERROR("Failed to resize when there are more than one user."); + return ERR_APPEXECFWK_FORM_INVALID_PARAM; + } + if (dimensionNum == record.specification) { HILOG_ERROR("This form want to change to the same size."); return ERR_APPEXECFWK_FORM_INVALID_PARAM; @@ -2448,14 +2454,6 @@ ErrCode FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_ if (errCode != ERR_OK) return errCode; - // isResizeable is the param of form record - bool isResizeable = true; - - if (!isResizeable) { - HILOG_ERROR("This form isn't resizeable, failed to changed form size."); - return ERR_APPEXECFWK_FORM_INVALID_PARAM; - } - bool isSupportFormDimension = false; for (auto iter : formInfo.supportDimensions) { if (dimensionNum == iter) { diff --git a/services/src/form_notify_size_changed_connection.cpp b/services/src/form_notify_size_changed_connection.cpp index 5b8de5a8a9..e7336fea25 100644 --- a/services/src/form_notify_size_changed_connection.cpp +++ b/services/src/form_notify_size_changed_connection.cpp @@ -51,5 +51,5 @@ void FormNotifySizeChangedConnection::OnAbilityConnectDone( newWant.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId()); FormTaskMgr::GetInstance().PostNotifyFormSizeChanged(formId_, dimensionNum, newWant, remoteObject); } -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index def55d4f0b..93624a95b0 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -99,13 +99,6 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons { HILOG_INFO("ResizeForm called, formId:%{public}" PRId64 ".", formId); - FormRecord formRecord; - bool isGetFormRecord = FormDataMgr::GetInstance().GetFormRecord(formId, formRecord); - if (!isGetFormRecord) { - HILOG_ERROR("Don't exist such form, formId:%{public}" PRId64 "", formId); - return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; - } - int32_t dimensionId = want.GetIntParam(Constants::PARAM_FORM_DIMENSION_KEY, 0); if (dimensionId == 0) { HILOG_ERROR("the dimensionId is wrong, formId:%{public}" PRId64 "", formId); @@ -115,47 +108,7 @@ ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, cons // update the specification of formRecord FormDataMgr::GetInstance().SetRecordSpecification(formId, dimensionId); - std::vector clientHosts; - FormDataMgr::GetInstance().GetFormHostRecord(formId, clientHosts); - if (clientHosts.empty()) { - HILOG_ERROR("clientHost is empty"); - return ERR_APPEXECFWK_FORM_COMMON_CODE; - } - - FormProviderData formProviderData = formProviderInfo.GetFormData(); - - if (!formRecord.versionUpgrade) { - nlohmann::json addJsonData = formProviderData.GetData(); - formRecord.formProviderInfo.MergeData(addJsonData); - // merge image - auto formData = formRecord.formProviderInfo.GetFormData(); - formData.SetImageDataState(formProviderData.GetImageDataState()); - formData.SetImageDataMap(formProviderData.GetImageDataMap()); - formRecord.formProviderInfo.SetFormData(formData); - } else { - formRecord.formProviderInfo.SetFormData(formProviderData); - formRecord.formProviderInfo.SetUpgradeFlg(true); - } - - formRecord.isInited = true; - formRecord.needRefresh = false; - FormDataMgr::GetInstance().SetFormCacheInited(formId, true); - - formRecord.formProviderInfo = formProviderInfo; - for (auto &iter : clientHosts) { - iter.OnAcquire(formId, formRecord); - } - - if (formRecord.formProviderInfo.NeedCache()) { - std::string jsonData = formRecord.formProviderInfo.GetFormDataString(); - HILOG_DEBUG("jsonData:%{public}s.", jsonData.c_str()); - FormCacheMgr::GetInstance().AddData(formId, jsonData); - } else { - FormCacheMgr::GetInstance().DeleteData(formId); - } - - // the resize form is successfully - return ERR_OK; + return AcquireForm(formId, formProviderInfo); } /** -- Gitee From ebb86845505ab6bea16648668f1d73d0cec0b829 Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 31 Aug 2022 16:11:22 +0800 Subject: [PATCH 28/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: I6d09024a64ad5dad31d30144b5d0cc3587bc9433 --- interfaces/inner_api/include/form_mgr_interface.h | 2 +- interfaces/inner_api/include/form_mgr_proxy.h | 2 +- interfaces/inner_api/include/form_provider_interface.h | 4 ++-- interfaces/inner_api/include/form_provider_proxy.h | 2 +- interfaces/inner_api/src/form_mgr_proxy.cpp | 2 +- interfaces/inner_api/src/form_provider_proxy.cpp | 2 +- interfaces/kits/native/include/form_mgr.h | 2 +- interfaces/kits/native/src/form_mgr.cpp | 2 +- services/include/form_host_callback.h | 2 +- services/include/form_mgr_adapter.h | 2 +- services/include/form_mgr_service.h | 2 +- services/include/form_provider_mgr.h | 2 +- services/include/form_task_mgr.h | 8 ++++---- services/src/form_host_callback.cpp | 2 +- services/src/form_mgr_adapter.cpp | 5 ++--- services/src/form_mgr_service.cpp | 2 +- services/src/form_notify_size_changed_connection.cpp | 2 +- services/src/form_provider_mgr.cpp | 2 +- services/src/form_task_mgr.cpp | 8 ++++---- test/mock/include/mock_form_mgr_proxy.h | 2 +- test/mock/include/mock_form_mgr_service.h | 2 +- test/mock/include/mock_form_provider_client.h | 2 +- 22 files changed, 30 insertions(+), 31 deletions(-) diff --git a/interfaces/inner_api/include/form_mgr_interface.h b/interfaces/inner_api/include/form_mgr_interface.h index 6e575a9c7d..9690f9d2f7 100644 --- a/interfaces/inner_api/include/form_mgr_interface.h +++ b/interfaces/inner_api/include/form_mgr_interface.h @@ -341,7 +341,7 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + virtual int NotifyFormSizeChanged(int64_t formId, int32_t dimensionNum, const sptr &callerToken) = 0; enum class Message { diff --git a/interfaces/inner_api/include/form_mgr_proxy.h b/interfaces/inner_api/include/form_mgr_proxy.h index 9967c24068..bcab6474a1 100644 --- a/interfaces/inner_api/include/form_mgr_proxy.h +++ b/interfaces/inner_api/include/form_mgr_proxy.h @@ -294,7 +294,7 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + ErrCode NotifyFormSizeChanged(int64_t formId, int32_t dimensionNum, const sptr &callerToken) override; /** diff --git a/interfaces/inner_api/include/form_provider_interface.h b/interfaces/inner_api/include/form_provider_interface.h index f940a40281..ef6b4809d1 100644 --- a/interfaces/inner_api/include/form_provider_interface.h +++ b/interfaces/inner_api/include/form_provider_interface.h @@ -121,8 +121,8 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, - const sptr &callerToken) = 0; + virtual int NotifyFormSizeChanged(int64_t formId, const Want &want, + const sptr &callerToken) = 0; /** * @brief Acquire to share form information data. This is sync API. diff --git a/interfaces/inner_api/include/form_provider_proxy.h b/interfaces/inner_api/include/form_provider_proxy.h index 5f659a46fd..100bd46319 100644 --- a/interfaces/inner_api/include/form_provider_proxy.h +++ b/interfaces/inner_api/include/form_provider_proxy.h @@ -123,7 +123,7 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - ErrCode NotifyFormSizeChanged(const int64_t formId, const Want &want, + ErrCode NotifyFormSizeChanged(int64_t formId, Want &want, const sptr &callerToken) override; /** diff --git a/interfaces/inner_api/src/form_mgr_proxy.cpp b/interfaces/inner_api/src/form_mgr_proxy.cpp index 99b0d34e26..b85e91ebcd 100644 --- a/interfaces/inner_api/src/form_mgr_proxy.cpp +++ b/interfaces/inner_api/src/form_mgr_proxy.cpp @@ -1133,7 +1133,7 @@ int32_t FormMgrProxy::GetFormsInfo(const std::string &moduleName, std::vector &callerToken) { MessageParcel data; diff --git a/interfaces/inner_api/src/form_provider_proxy.cpp b/interfaces/inner_api/src/form_provider_proxy.cpp index 2938ca6357..637fb724e0 100644 --- a/interfaces/inner_api/src/form_provider_proxy.cpp +++ b/interfaces/inner_api/src/form_provider_proxy.cpp @@ -398,7 +398,7 @@ int FormProviderProxy::AcquireState(const Want &wantArg, const std::string &prov return ERR_OK; } -ErrCode FormProviderProxy::NotifyFormSizeChanged(const int64_t formId, const Want &want, +ErrCode FormProviderProxy::NotifyFormSizeChanged(int64_t formId, Want &want, const sptr &callerToken) { MessageParcel data; diff --git a/interfaces/kits/native/include/form_mgr.h b/interfaces/kits/native/include/form_mgr.h index f12d84e2e4..813afc349e 100644 --- a/interfaces/kits/native/include/form_mgr.h +++ b/interfaces/kits/native/include/form_mgr.h @@ -400,7 +400,7 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - ErrCode NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, const sptr &callerToken); + ErrCode NotifyFormSizeChanged(int64_t formId, int32_t dimensionId, const sptr &callerToken); private: /** diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index 6199aa6a47..e891431ab4 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -982,7 +982,7 @@ bool FormMgr::CheckFMSReady() return true; } -ErrCode FormMgr::NotifyFormSizeChanged(const int64_t formId, int32_t dimensionId, +ErrCode FormMgr::NotifyFormSizeChanged(int64_t formId, int32_t dimensionId, const sptr &callerToken) { HILOG_DEBUG("NotifyFormSizeChanged called."); diff --git a/services/include/form_host_callback.h b/services/include/form_host_callback.h index e24ec8d1ff..9738fb0569 100644 --- a/services/include/form_host_callback.h +++ b/services/include/form_host_callback.h @@ -59,7 +59,7 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - void OnSizeChanged(const int64_t formId, const FormRecord &record, const sptr &callerToken); + void OnSizeChanged(int64_t formId, const FormRecord &record, const sptr &callerToken); /** * @brief Form provider is uninstalled. diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index 54d9d675f8..6c5ffa37d0 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -338,7 +338,7 @@ public: * @param callerToken Host client. * @return Returns ERR_OK on success, others on failure. */ - ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + ErrCode NotifyFormSizeChanged(int64_t formId, int32_t dimensionNum, const sptr &callerToken); private: /** diff --git a/services/include/form_mgr_service.h b/services/include/form_mgr_service.h index 9c30e0da8a..8265a6c736 100644 --- a/services/include/form_mgr_service.h +++ b/services/include/form_mgr_service.h @@ -366,7 +366,7 @@ public: * @param callerToken token of the ability that initially calls this function. * @return Returns ERR_OK on success, others on failure. */ - ErrCode NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + ErrCode NotifyFormSizeChanged(int64_t formId, int32_t dimensionNum, const sptr &callerToken) override; private: enum class DumpKey { diff --git a/services/include/form_provider_mgr.h b/services/include/form_provider_mgr.h index 83b627219e..dbfa7f085b 100644 --- a/services/include/form_provider_mgr.h +++ b/services/include/form_provider_mgr.h @@ -65,7 +65,7 @@ public: * @param providerFormInfo provider form info. * @return Returns ERR_OK on success, others on failure. */ - ErrCode ResizeForm(const int64_t formId, const Want &want, const FormProviderInfo &formProviderInfo); + ErrCode ResizeForm(int64_t formId, const Want &want, const FormProviderInfo &formProviderInfo); /** * @brief Refresh form. * @param formId The form id. diff --git a/services/include/form_task_mgr.h b/services/include/form_task_mgr.h index a229d6a841..55e64e68f0 100644 --- a/services/include/form_task_mgr.h +++ b/services/include/form_task_mgr.h @@ -125,7 +125,7 @@ public: * @param record form record. * @param remoteObject Form provider proxy object. */ - void PostSizeChangedTaskToHost(const int64_t formId, const FormRecord &record, + void PostSizeChangedTaskToHost(int64_t formId, const FormRecord &record, const sptr &remoteObject); /** @@ -195,7 +195,7 @@ public: * @param dimensionNum The dimension id of the new form. * @param remoteObject Form provider proxy object. */ - void PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + void PostNotifyFormSizeChanged(int64_t formId, int32_t dimensionNum, const Want &want, const sptr &remoteObject); private: /** @@ -274,7 +274,7 @@ private: * @param record form record. * @param remoteObject Form provider proxy object. */ - void SizeChangedTaskToHost(const int64_t formId, const FormRecord &record, const sptr &remoteObject); + void SizeChangedTaskToHost(int64_t formId, const FormRecord &record, const sptr &remoteObject); /** * @brief Handle form host died. @@ -332,7 +332,7 @@ private: * @param dimensionNum The dimension id of the new form. * @param remoteObject Form provider proxy object. */ - void NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, + void NotifyProviderFormSizeChanged(int64_t formId, int32_t dimensionNum, const Want &want, const sptr &remoteObject); /** * @brief Create form data for form host. diff --git a/services/src/form_host_callback.cpp b/services/src/form_host_callback.cpp index 821af47438..ec133d13c8 100644 --- a/services/src/form_host_callback.cpp +++ b/services/src/form_host_callback.cpp @@ -61,7 +61,7 @@ void FormHostCallback::OnUpdate(const int64_t formId, const FormRecord &record, FormTaskMgr::GetInstance().PostUpdateTaskToHost(formId, record, callerToken); } -void FormHostCallback::OnSizeChanged(const int64_t formId, const FormRecord &record, +void FormHostCallback::OnSizeChanged(int64_t formId, const FormRecord &record, const sptr &callerToken) { HILOG_DEBUG("OnSizeChanged start."); diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 5309ae6e94..c776525c96 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -2426,7 +2426,7 @@ ErrCode FormMgrAdapter::GetFormInfoByFormRecord(const FormRecord &formRecord, Fo return ERR_OK; } -ErrCode FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, +ErrCode FormMgrAdapter::NotifyFormSizeChanged(int64_t formId, int32_t dimensionNum, const sptr &callerToken) { HILOG_DEBUG("NotifyFormSizeChanged called."); @@ -2438,8 +2438,7 @@ ErrCode FormMgrAdapter::NotifyFormSizeChanged(const int64_t formId, const int32_ FormRecord record; FormDataMgr::GetInstance().GetFormRecord(formId, record); - if(record.formUserUids.size() > 1) - { + if (record.formUserUids.size() > 1) { HILOG_ERROR("Failed to resize when there are more than one user."); return ERR_APPEXECFWK_FORM_INVALID_PARAM; } diff --git a/services/src/form_mgr_service.cpp b/services/src/form_mgr_service.cpp index fb03da1241..2bb0295435 100644 --- a/services/src/form_mgr_service.cpp +++ b/services/src/form_mgr_service.cpp @@ -914,7 +914,7 @@ void FormMgrService::HiDumpFormInfoByFormId(const std::string &args, std::string DumpFormInfoByFormId(formId, result); } -ErrCode FormMgrService::NotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, +ErrCode FormMgrService::NotifyFormSizeChanged(int64_t formId, int32_t dimensionNum, const sptr &callerToken) { HILOG_DEBUG("NotifyFormSizeChanged called."); diff --git a/services/src/form_notify_size_changed_connection.cpp b/services/src/form_notify_size_changed_connection.cpp index e7336fea25..03e1eec26c 100644 --- a/services/src/form_notify_size_changed_connection.cpp +++ b/services/src/form_notify_size_changed_connection.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace AppExecFwk { -FormNotifySizeChangedConnection::FormNotifySizeChangedConnection(const int64_t formId, const int32_t dimensionNum, +FormNotifySizeChangedConnection::FormNotifySizeChangedConnection(int64_t formId, int32_t dimensionNum, const std::string &bundleName, const std::string &abilityName) : formId_(formId), dimensionNum_(dimensionNum) { diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index 93624a95b0..89310cfbf6 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -95,7 +95,7 @@ ErrCode FormProviderMgr::AcquireForm(const int64_t formId, const FormProviderInf return ERR_OK; } -ErrCode FormProviderMgr::ResizeForm(const int64_t formId, const Want &want, const FormProviderInfo &formProviderInfo) +ErrCode FormProviderMgr::ResizeForm(int64_t formId, const Want &want, const FormProviderInfo &formProviderInfo) { HILOG_INFO("ResizeForm called, formId:%{public}" PRId64 ".", formId); diff --git a/services/src/form_task_mgr.cpp b/services/src/form_task_mgr.cpp index 886570c5b2..056440741f 100644 --- a/services/src/form_task_mgr.cpp +++ b/services/src/form_task_mgr.cpp @@ -171,7 +171,7 @@ void FormTaskMgr::PostUpdateTaskToHost(const int64_t formId, const FormRecord &r eventHandler_->PostTask(updateTaskToHostFunc, FORM_TASK_DELAY_TIME); } -void FormTaskMgr::PostSizeChangedTaskToHost(const int64_t formId, const FormRecord &record, +void FormTaskMgr::PostSizeChangedTaskToHost(int64_t formId, const FormRecord &record, const sptr &remoteObject) { HILOG_DEBUG("PostSizeChangedTaskToHost called."); @@ -345,7 +345,7 @@ void FormTaskMgr::PostFormShareSendResponse(int64_t formShareRequestCode, int32_ HILOG_INFO("%{public}s end", __func__); } -void FormTaskMgr::PostNotifyFormSizeChanged(const int64_t formId, const int32_t dimensionNum, +void FormTaskMgr::PostNotifyFormSizeChanged(int64_t formId, int32_t dimensionNum, const Want &want, const sptr &remoteObject) { if (eventHandler_ == nullptr) { @@ -512,7 +512,7 @@ void FormTaskMgr::UpdateTaskToHost(const int64_t formId, const FormRecord &recor HILOG_INFO("%{public}s end.", __func__); } -void FormTaskMgr::SizeChangedTaskToHost(const int64_t formId, const FormRecord &record, +void FormTaskMgr::SizeChangedTaskToHost(int64_t formId, const FormRecord &record, const sptr &remoteObject) { HILOG_DEBUG("SizeChangedTaskToHost start."); @@ -662,7 +662,7 @@ void FormTaskMgr::AcquireStateBack(AppExecFwk::FormState state, const AAFwk::Wan HILOG_INFO("%{public}s end", __func__); } -void FormTaskMgr::NotifyProviderFormSizeChanged(const int64_t formId, const int32_t dimensionNum, +void FormTaskMgr::NotifyProviderFormSizeChanged(int64_t formId, int32_t dimensionNum, const Want &want, const sptr &remoteObject) { HILOG_DEBUG("NotifyProviderFormSizeChange called."); diff --git a/test/mock/include/mock_form_mgr_proxy.h b/test/mock/include/mock_form_mgr_proxy.h index b59775d85e..fbfcf2d341 100644 --- a/test/mock/include/mock_form_mgr_proxy.h +++ b/test/mock/include/mock_form_mgr_proxy.h @@ -27,7 +27,7 @@ public: MOCK_METHOD2(GetFormsInfo, int(const std::string &moduleName, std::vector &formInfos)); MOCK_METHOD0(IsRequestPublishFormSupported, bool()); MOCK_METHOD2(StartAbility, int32_t(const Want &want, const sptr &callerToken)); - MOCK_METHOD3(NotifyFormSizeChanged, int(const int64_t formId, const int32_t dimensionNum, + MOCK_METHOD3(NotifyFormSizeChanged, int(int64_t formId, int32_t dimensionNum, const sptr &callerToken)); }; } diff --git a/test/mock/include/mock_form_mgr_service.h b/test/mock/include/mock_form_mgr_service.h index f9ffe0af80..78877aa6e9 100644 --- a/test/mock/include/mock_form_mgr_service.h +++ b/test/mock/include/mock_form_mgr_service.h @@ -68,7 +68,7 @@ public: MOCK_METHOD2(UpdateRouterAction, int(const int64_t formId, std::string &action)); MOCK_METHOD4(ShareForm, int32_t(int64_t, const std::string&, const sptr&, int64_t)); MOCK_METHOD1(RecvFormShareInfoFromRemote, int32_t(const FormShareInfo&)); - MOCK_METHOD3(NotifyFormSizeChanged, int32_t(const int64_t formId, const int32_t dimensionNum, + MOCK_METHOD3(NotifyFormSizeChanged, int32_t(int64_t formId, int32_t dimensionNum, const sptr &callerToken)); }; } diff --git a/test/mock/include/mock_form_provider_client.h b/test/mock/include/mock_form_provider_client.h index f5a333787f..22782ba0f4 100644 --- a/test/mock/include/mock_form_provider_client.h +++ b/test/mock/include/mock_form_provider_client.h @@ -113,7 +113,7 @@ private: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyFormSizeChanged(const int64_t formId, const Want &want, + virtual int NotifyFormSizeChanged(int64_t formId, const Want &want, const sptr &callerToken) override; /** * @brief Acquire form state to form provider. -- Gitee From 03eb4e6a434be326a1f14926410f8f17cc9badeb Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 31 Aug 2022 16:28:17 +0800 Subject: [PATCH 29/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: Ib0222eee99b34bdf6908ff1e4faba0a511ab67e8 --- interfaces/inner_api/src/form_provider_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/src/form_provider_proxy.cpp b/interfaces/inner_api/src/form_provider_proxy.cpp index 637fb724e0..74a3b2b010 100644 --- a/interfaces/inner_api/src/form_provider_proxy.cpp +++ b/interfaces/inner_api/src/form_provider_proxy.cpp @@ -398,7 +398,7 @@ int FormProviderProxy::AcquireState(const Want &wantArg, const std::string &prov return ERR_OK; } -ErrCode FormProviderProxy::NotifyFormSizeChanged(int64_t formId, Want &want, +ErrCode FormProviderProxy::NotifyFormSizeChanged(int64_t formId, const Want &want, const sptr &callerToken) { MessageParcel data; -- Gitee From 03b8a536db81cf9b601a23c49c242d2a7010aa2a Mon Sep 17 00:00:00 2001 From: lin_xiangrong Date: Wed, 31 Aug 2022 16:45:31 +0800 Subject: [PATCH 30/31] resizeForm Signed-off-by: lin_xiangrong Change-Id: Ibd6ea57928e844bdc439a15057714c79c2f00935 --- interfaces/inner_api/include/form_provider_proxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/include/form_provider_proxy.h b/interfaces/inner_api/include/form_provider_proxy.h index 100bd46319..7eef713ba0 100644 --- a/interfaces/inner_api/include/form_provider_proxy.h +++ b/interfaces/inner_api/include/form_provider_proxy.h @@ -123,7 +123,7 @@ public: * @param callerToken Caller ability token. * @return Returns ERR_OK on success, others on failure. */ - ErrCode NotifyFormSizeChanged(int64_t formId, Want &want, + ErrCode NotifyFormSizeChanged(int64_t formId, const Want &want, const sptr &callerToken) override; /** -- Gitee From d0753bd8c5a70a4045ec52cd3aba01f176733ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=90=91=E8=8D=A3?= Date: Wed, 31 Aug 2022 08:46:35 +0000 Subject: [PATCH 31/31] resizeForm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 林向荣 --- .../unittest/fms_form_share_mgr_test/fms_form_share_mgr_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/fms_form_share_mgr_test/fms_form_share_mgr_test.cpp b/test/unittest/fms_form_share_mgr_test/fms_form_share_mgr_test.cpp index bc377cf80c..20d90276b6 100644 --- a/test/unittest/fms_form_share_mgr_test/fms_form_share_mgr_test.cpp +++ b/test/unittest/fms_form_share_mgr_test/fms_form_share_mgr_test.cpp @@ -105,6 +105,7 @@ public: MOCK_METHOD1(OnUninstall, void(const std::vector &formIds)); MOCK_METHOD2(OnAcquireState, void(AppExecFwk::FormState state, const AAFwk::Want &want)); MOCK_METHOD2(OnShareFormResponse, void(const int64_t requestCode, const int32_t result)); + MOCK_METHOD1(OnSizeChanged, void(const FormJsInfo &formInfo)); }; static sptr bundleMgr_ = nullptr; -- Gitee