diff --git a/adapter/ohos/entrance/ace_container.cpp b/adapter/ohos/entrance/ace_container.cpp index ec220167..3e6b384c 100644 --- a/adapter/ohos/entrance/ace_container.cpp +++ b/adapter/ohos/entrance/ace_container.cpp @@ -480,6 +480,20 @@ void AceContainer::OnNewRequest(int32_t instanceId, const std::string& data) } } +void AceContainer::OnDialogUpdated(int32_t instanceId, const std::string& data) +{ + auto container = AceEngine::Get().GetContainer(instanceId); + if (!container) { + return; + } + + ContainerScope scope(instanceId); + auto front = container->GetFrontend(); + if (front) { + front->OnDialogUpdated(data); + } +} + void AceContainer::InitializeCallback() { ACE_FUNCTION_TRACE(); diff --git a/adapter/ohos/entrance/ace_container.h b/adapter/ohos/entrance/ace_container.h index f14ee6a9..eeb22f6a 100644 --- a/adapter/ohos/entrance/ace_container.h +++ b/adapter/ohos/entrance/ace_container.h @@ -233,6 +233,7 @@ public: static void OnRemoteTerminated(int32_t instanceId); static void OnConfigurationUpdated(int32_t instanceId, const std::string& configuration); static void OnNewRequest(int32_t instanceId, const std::string& data); + static void OnDialogUpdated(int32_t instanceId, const std::string& data); static void AddAssetPath(int32_t instanceId, const std::string& packagePath, const std::vector& paths); static void AddLibPath(int32_t instanceId, const std::string& libPath); static void SetView(AceView* view, double density, int32_t width, int32_t height, int32_t windowId, diff --git a/adapter/ohos/services/uiservice/include/ui_mgr_service.h b/adapter/ohos/services/uiservice/include/ui_mgr_service.h index e11010a1..f6733f18 100644 --- a/adapter/ohos/services/uiservice/include/ui_mgr_service.h +++ b/adapter/ohos/services/uiservice/include/ui_mgr_service.h @@ -70,6 +70,8 @@ public: int CancelDialog(int id) override; + int UpdateDialog(int id, const std::string& data) override; + /** * GetEventHandler, get the ui_service manager service's handler. * diff --git a/adapter/ohos/services/uiservice/include/ui_service_mgr_proxy.h b/adapter/ohos/services/uiservice/include/ui_service_mgr_proxy.h index 83ee3154..4ceb5f5e 100644 --- a/adapter/ohos/services/uiservice/include/ui_service_mgr_proxy.h +++ b/adapter/ohos/services/uiservice/include/ui_service_mgr_proxy.h @@ -56,6 +56,8 @@ public: virtual int CancelDialog(int id); + virtual int UpdateDialog(int id, const std::string& data); + private: bool WriteInterfaceToken(MessageParcel& data); diff --git a/adapter/ohos/services/uiservice/include/ui_service_mgr_stub.h b/adapter/ohos/services/uiservice/include/ui_service_mgr_stub.h index 1e7d79e2..55b65a99 100644 --- a/adapter/ohos/services/uiservice/include/ui_service_mgr_stub.h +++ b/adapter/ohos/services/uiservice/include/ui_service_mgr_stub.h @@ -45,6 +45,7 @@ private: using RequestFuncType = int (UIServiceMgrStub ::*)(MessageParcel& data, MessageParcel& reply); int ShowDialogInner(MessageParcel& data, MessageParcel& reply); int CancelDialogInner(MessageParcel& data, MessageParcel& reply); + int UpdateDialogInner(MessageParcel &data, MessageParcel &reply); std::map requestFuncMap_; }; } // namespace Ace diff --git a/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp b/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp index 0547bb98..bb8e7b79 100644 --- a/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp +++ b/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp @@ -382,6 +382,24 @@ int UIMgrService::CancelDialog(int id) return NO_ERROR; } +int UIMgrService::UpdateDialog(int id, const std::string& data) +{ + auto updateDialogCallback = [id, data]() { + HILOG_INFO("Update dialog id: %{public}d", id); + auto container = Platform::AceContainer::GetContainer(id); + if (!container) { + HILOG_INFO("Container(%{public}d) not found.", id); + return; + } + Platform::AceContainer::OnDialogUpdated(id, data); + }; + if (!handler_->PostTask(updateDialogCallback)) { + return UI_SERVICE_POST_TASK_FAILED; + } + + return NO_ERROR; +} + void UIMgrService::OnStart() { if (state_ == UIServiceRunningState::STATE_RUNNING) { diff --git a/adapter/ohos/services/uiservice/src/ui_service_mgr_client.cpp b/adapter/ohos/services/uiservice/src/ui_service_mgr_client.cpp index f636afc6..d459b6d2 100644 --- a/adapter/ohos/services/uiservice/src/ui_service_mgr_client.cpp +++ b/adapter/ohos/services/uiservice/src/ui_service_mgr_client.cpp @@ -175,6 +175,29 @@ ErrCode UIServiceMgrClient::CancelDialog(int32_t id) return doms->CancelDialog(id); } +ErrCode UIServiceMgrClient::UpdateDialog(int32_t id, const std::string& data) +{ + if (id < 0) { + HILOG_INFO("invalid parameter"); + return UI_SERVICE_INVALID_PARAMETER; + } + + if (remoteObject_ == nullptr) { + ErrCode err = Connect(); + if (err != ERR_OK) { + HILOG_ERROR("%{private}s:fail to connect UIMgrService", __func__); + return UI_SERVICE_NOT_CONNECTED; + } + } + + sptr doms = iface_cast(remoteObject_); + if (doms == nullptr) { + HILOG_ERROR("doms is nullptr"); + return UI_SERVICE_GET_PROXY_FAILED; + } + return doms->UpdateDialog(id, data); +} + ErrCode UIServiceMgrClient::ShowAppPickerDialog( const AAFwk::Want& want, const std::vector& abilityInfos, int32_t userId) { diff --git a/adapter/ohos/services/uiservice/src/ui_service_mgr_proxy.cpp b/adapter/ohos/services/uiservice/src/ui_service_mgr_proxy.cpp index e3420d94..d75a3e82 100644 --- a/adapter/ohos/services/uiservice/src/ui_service_mgr_proxy.cpp +++ b/adapter/ohos/services/uiservice/src/ui_service_mgr_proxy.cpp @@ -268,5 +268,33 @@ int UIServiceMgrProxy::CancelDialog(int id) } return reply.ReadInt32(); } + +int UIServiceMgrProxy::UpdateDialog(int id, const std::string& data) +{ + MessageParcel dataParcel; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(dataParcel)) { + return UI_SERVICE_PROXY_INNER_ERR; + } + + if (!dataParcel.WriteInt32(id)) { + HILOG_ERROR("fail to WriteString id"); + return INVALID_DATA; + } + + if (!dataParcel.WriteString(data)) { + HILOG_ERROR("fail to WriteString data"); + return INVALID_DATA; + } + + int error = Remote()->SendRequest(IUIServiceMgr::UPDATE_DIALOG, dataParcel, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Request fail, error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} } // namespace Ace } // namespace OHOS diff --git a/adapter/ohos/services/uiservice/src/ui_service_mgr_stub.cpp b/adapter/ohos/services/uiservice/src/ui_service_mgr_stub.cpp index b5eefe97..47b26474 100644 --- a/adapter/ohos/services/uiservice/src/ui_service_mgr_stub.cpp +++ b/adapter/ohos/services/uiservice/src/ui_service_mgr_stub.cpp @@ -32,6 +32,7 @@ UIServiceMgrStub::UIServiceMgrStub() requestFuncMap_[RETURN_REQUEST] = &UIServiceMgrStub::ReturnRequestInner; requestFuncMap_[SHOW_DIALOG] = &UIServiceMgrStub::ShowDialogInner; requestFuncMap_[CANCEL_DIALOG] = &UIServiceMgrStub::CancelDialogInner; + requestFuncMap_[UPDATE_DIALOG] = &UIServiceMgrStub::UpdateDialogInner; } UIServiceMgrStub::~UIServiceMgrStub() @@ -167,5 +168,14 @@ int UIServiceMgrStub::CancelDialogInner(MessageParcel &data, MessageParcel &repl reply.WriteInt32(result); return NO_ERROR; } + +int UIServiceMgrStub::UpdateDialogInner(MessageParcel &data, MessageParcel &reply) +{ + int32_t id = data.ReadInt32(); + std::string updateData = data.ReadString(); + int32_t result = UpdateDialog(id, updateData); + reply.WriteInt32(result); + return NO_ERROR; +} } // namespace Ace } // namespace OHOS diff --git a/frameworks/bridge/card_frontend/card_frontend.h b/frameworks/bridge/card_frontend/card_frontend.h index 28e58d27..81725751 100644 --- a/frameworks/bridge/card_frontend/card_frontend.h +++ b/frameworks/bridge/card_frontend/card_frontend.h @@ -100,6 +100,7 @@ public: } void OnRemoteTerminated() override {} void OnNewRequest(const std::string& data) override {} + void OnDialogUpdated(const std::string& data) override {} void OnNewWant(const std::string& data) override {} void CallRouterBack() override {} void OnSurfaceChanged(int32_t width, int32_t height) override; diff --git a/frameworks/bridge/declarative_frontend/declarative_frontend.h b/frameworks/bridge/declarative_frontend/declarative_frontend.h index 8ca47478..f3186d85 100644 --- a/frameworks/bridge/declarative_frontend/declarative_frontend.h +++ b/frameworks/bridge/declarative_frontend/declarative_frontend.h @@ -113,6 +113,7 @@ public: bool OnRestoreData(const std::string& data) override; void OnRemoteTerminated() override; void OnNewRequest(const std::string& data) override; + void OnDialogUpdated(const std::string& data) override {} void OnMemoryLevel(const int32_t level) override; void CallRouterBack() override; void OnSurfaceChanged(int32_t width, int32_t height) override; diff --git a/frameworks/bridge/js_frontend/frontend_delegate_impl.cpp b/frameworks/bridge/js_frontend/frontend_delegate_impl.cpp index 023b419b..fc6470c9 100644 --- a/frameworks/bridge/js_frontend/frontend_delegate_impl.cpp +++ b/frameworks/bridge/js_frontend/frontend_delegate_impl.cpp @@ -442,6 +442,11 @@ void FrontendDelegateImpl::OnNewRequest(const std::string& data) FireSyncEvent("_root", std::string("\"onNewRequest\","), data); } +void FrontendDelegateImpl::OnDialogUpdated(const std::string& data) +{ + FireSyncEvent("_root", std::string("\"onDialogUpdated\","), data); +} + void FrontendDelegateImpl::CallPopPage() { std::lock_guard lock(mutex_); diff --git a/frameworks/bridge/js_frontend/frontend_delegate_impl.h b/frameworks/bridge/js_frontend/frontend_delegate_impl.h index 4b161b4b..a8252272 100644 --- a/frameworks/bridge/js_frontend/frontend_delegate_impl.h +++ b/frameworks/bridge/js_frontend/frontend_delegate_impl.h @@ -234,6 +234,7 @@ public: void OnSaveData(std::string& data); bool OnRestoreData(const std::string& data); void OnNewRequest(const std::string& data); + void OnDialogUpdated(const std::string& data); void OnMemoryLevel(const int32_t level); void OnNewWant(const std::string& data); void CallPopPage(); diff --git a/frameworks/bridge/js_frontend/js_frontend.cpp b/frameworks/bridge/js_frontend/js_frontend.cpp index ff75762e..a7630183 100644 --- a/frameworks/bridge/js_frontend/js_frontend.cpp +++ b/frameworks/bridge/js_frontend/js_frontend.cpp @@ -701,6 +701,13 @@ void JsFrontend::OnNewRequest(const std::string& data) } } +void JsFrontend::OnDialogUpdated(const std::string& data) +{ + if (delegate_) { + delegate_->OnDialogUpdated(data); + } +} + void JsFrontend::CallRouterBack() { if (delegate_) { diff --git a/frameworks/bridge/js_frontend/js_frontend.h b/frameworks/bridge/js_frontend/js_frontend.h index 13a758b6..a67ba05a 100644 --- a/frameworks/bridge/js_frontend/js_frontend.h +++ b/frameworks/bridge/js_frontend/js_frontend.h @@ -114,6 +114,7 @@ public: void OnMemoryLevel(const int32_t level) override {} void OnNewRequest(const std::string& data) override; + void OnDialogUpdated(const std::string& data) override; void OnNewWant(const std::string& data) override {} void CallRouterBack() override; void SetColorMode(ColorMode colorMode) override; diff --git a/frameworks/bridge/plugin_frontend/plugin_frontend.h b/frameworks/bridge/plugin_frontend/plugin_frontend.h index 1e31b7bd..983b7e69 100644 --- a/frameworks/bridge/plugin_frontend/plugin_frontend.h +++ b/frameworks/bridge/plugin_frontend/plugin_frontend.h @@ -101,6 +101,7 @@ public: bool OnRestoreData(const std::string& data) override; void OnRemoteTerminated() override; void OnNewRequest(const std::string& data) override; + void OnDialogUpdated(const std::string& data) override {} void OnMemoryLevel(const int32_t level) override; void SetColorMode(ColorMode colorMode) override; void CallRouterBack() override; diff --git a/frameworks/bridge/test/unittest/jsfrontend/dom_mock.h b/frameworks/bridge/test/unittest/jsfrontend/dom_mock.h index 233f669a..d4ae0894 100644 --- a/frameworks/bridge/test/unittest/jsfrontend/dom_mock.h +++ b/frameworks/bridge/test/unittest/jsfrontend/dom_mock.h @@ -131,6 +131,7 @@ public: void OnRestoreAbilityState (const std::string& data) override {} void OnRemoteTerminated() override {} void OnNewRequest(const std::string& data) override {} + void OnDialogUpdated(const std::string& data) override {} void OnNewWant(const std::string& data) override {} void CallRouterBack() override {} void OnSurfaceChanged(int32_t width, int32_t height) override {} diff --git a/frameworks/core/common/frontend.h b/frameworks/core/common/frontend.h index 1c32f0ac..5f121d37 100644 --- a/frameworks/core/common/frontend.h +++ b/frameworks/core/common/frontend.h @@ -166,6 +166,8 @@ public: virtual void OnNewWant(const std::string& data) = 0; + virtual void OnDialogUpdated(const std::string& data) = 0; + // call router back virtual void CallRouterBack() = 0; diff --git a/frameworks/core/components/test/json/json_frontend.h b/frameworks/core/components/test/json/json_frontend.h index 99b97bef..6b130ff5 100644 --- a/frameworks/core/components/test/json/json_frontend.h +++ b/frameworks/core/components/test/json/json_frontend.h @@ -88,6 +88,8 @@ public: void OnNewRequest(const std::string& data) override; + void OnDialogUpdated(const std::string& data) override {} + void OnNewWant(const std::string& data) override {} void CallRouterBack() override; diff --git a/frameworks/core/pipeline/test/unittest/context/pipeline_context_test.cpp b/frameworks/core/pipeline/test/unittest/context/pipeline_context_test.cpp index ad22dcba..bc6c4f4d 100644 --- a/frameworks/core/pipeline/test/unittest/context/pipeline_context_test.cpp +++ b/frameworks/core/pipeline/test/unittest/context/pipeline_context_test.cpp @@ -192,6 +192,7 @@ public: } void OnRemoteTerminated() override {} void OnNewRequest(const std::string& data) override {} + void OnDialogUpdated(const std::string& data) override {} void OnNewWant(const std::string& data) override {} void CallRouterBack() override {} void OnSurfaceChanged(int32_t width, int32_t height) override {} diff --git a/interfaces/innerkits/ui_service_manager/include/ui_service_mgr_client.h b/interfaces/innerkits/ui_service_manager/include/ui_service_mgr_client.h index eb5d8556..51041c97 100644 --- a/interfaces/innerkits/ui_service_manager/include/ui_service_mgr_client.h +++ b/interfaces/innerkits/ui_service_manager/include/ui_service_mgr_client.h @@ -62,6 +62,8 @@ public: ErrCode CancelDialog(int32_t id); + ErrCode UpdateDialog(int32_t id, const std::string& data); + ErrCode ShowAppPickerDialog( const AAFwk::Want& want, const std::vector& abilityInfos, int32_t userId); diff --git a/interfaces/innerkits/ui_service_manager/include/ui_service_mgr_interface.h b/interfaces/innerkits/ui_service_manager/include/ui_service_mgr_interface.h index 00dcab80..84c506b5 100644 --- a/interfaces/innerkits/ui_service_manager/include/ui_service_mgr_interface.h +++ b/interfaces/innerkits/ui_service_manager/include/ui_service_mgr_interface.h @@ -65,6 +65,8 @@ public: virtual int CancelDialog(int id) = 0; + virtual int UpdateDialog(int id, const std::string& data) = 0; + enum { // ipc id 1-1000 for kit // ipc id for RegisterCallBack (1) @@ -76,6 +78,7 @@ public: RETURN_REQUEST, SHOW_DIALOG, CANCEL_DIALOG, + UPDATE_DIALOG, }; }; } // namespace Ace