From db45dc8eed030d556a0addaa453b2788a5932ba4 Mon Sep 17 00:00:00 2001 From: zph Date: Mon, 17 Feb 2025 15:15:46 +0800 Subject: [PATCH] update Signed-off-by: zph --- .../include/dataobs_mgr_client.h | 11 ++++- .../include/dataobs_mgr_interface.h | 2 +- services/dataobsmgr/BUILD.gn | 2 - .../dataobsmgr/include/dataobs_mgr_proxy.h | 12 +++++- .../dataobsmgr/include/dataobs_mgr_service.h | 7 ++-- .../dataobsmgr/include/dataobs_mgr_stub.h | 2 +- .../dataobsmgr/src/dataobs_mgr_client.cpp | 5 ++- services/dataobsmgr/src/dataobs_mgr_proxy.cpp | 29 +++++--------- .../dataobsmgr/src/dataobs_mgr_service.cpp | 40 +++++++++---------- services/dataobsmgr/src/dataobs_mgr_stub.cpp | 15 ++----- .../mock_dataobs_mgr_service.h | 7 ++++ .../mock_data_obs_mgr_stub.h | 1 + .../mock_data_obs_mgr_stub.h | 1 + 13 files changed, 71 insertions(+), 63 deletions(-) diff --git a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_client.h b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_client.h index 3bde5a6317..71c95b5e9c 100644 --- a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_client.h +++ b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_client.h @@ -105,7 +105,16 @@ public: */ Status NotifyChangeExt(const ChangeInfo &changeInfo); - Status NotifyProcessDialog(const std::string &progressKey, const sptr &observer); + /** + * Notifies the process observer with the given progress key and cancel observer. + * + * @param progressKey Identifies the progress of a specific task. + + * @param observer bserver for monitoring the ongoing process. + * + * @return Returns SUCCESS on success, others on failure. + */ + Status NotifyProcessObserver(const std::string &progressKey, const sptr &cancelObserver); private: class SystemAbilityStatusChangeListener; diff --git a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_interface.h b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_interface.h index 0f539a93cf..5323a845d6 100644 --- a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_interface.h +++ b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_interface.h @@ -124,7 +124,7 @@ public: * * @return Returns SUCCESS on success, others on failure. */ - virtual Status NotifyProcessDialog(const std::string &progressKey, const sptr &observer) = 0; + virtual Status NotifyProcessObserver(const std::string &progressKey, const sptr &observer) = 0; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/dataobsmgr/BUILD.gn b/services/dataobsmgr/BUILD.gn index 08e584b48c..5832bfe11c 100644 --- a/services/dataobsmgr/BUILD.gn +++ b/services/dataobsmgr/BUILD.gn @@ -46,12 +46,10 @@ ohos_shared_library("dataobsms") { "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits" ] defines = [] external_deps = [ - "ability_base:want", "ability_base:zuri", "c_utils:utils", "ffrt:libffrt", diff --git a/services/dataobsmgr/include/dataobs_mgr_proxy.h b/services/dataobsmgr/include/dataobs_mgr_proxy.h index e7215679c1..9b31643e7b 100644 --- a/services/dataobsmgr/include/dataobs_mgr_proxy.h +++ b/services/dataobsmgr/include/dataobs_mgr_proxy.h @@ -104,7 +104,17 @@ public: */ virtual Status NotifyChangeExt(const ChangeInfo &changeInfo) override; - virtual Status NotifyProcessDialog(const std::string &progressKey, const sptr &observer) override; + /** + * Notifies the process observer with the given progress key and cancel observer. + * + * @param progressKey Identifies the progress of a specific task. + + * @param observer bserver for monitoring the ongoing process. + * + * @return Returns SUCCESS on success, others on failure. + */ + virtual Status NotifyProcessObserver(const std::string &progressKey, + const sptr &cancelObserver) override; private: bool WriteInterfaceToken(MessageParcel &data); diff --git a/services/dataobsmgr/include/dataobs_mgr_service.h b/services/dataobsmgr/include/dataobs_mgr_service.h index 2f3c770273..2ffcd097e3 100644 --- a/services/dataobsmgr/include/dataobs_mgr_service.h +++ b/services/dataobsmgr/include/dataobs_mgr_service.h @@ -22,6 +22,7 @@ #include #include "cpp/mutex.h" +#include "ability_manager_interface.h" #include "dataobs_mgr_inner.h" #include "dataobs_mgr_inner_ext.h" #include "dataobs_mgr_inner_pref.h" @@ -31,9 +32,6 @@ #include "task_handler_wrap.h" #include "uri.h" -#include "ability_manager_interface.h" -#include "refbase.h" - namespace OHOS { namespace AAFwk { enum class DataObsServiceRunningState { STATE_NOT_START, STATE_RUNNING }; @@ -60,7 +58,8 @@ public: virtual Status UnregisterObserverExt(const Uri &uri, sptr dataObserver) override; virtual Status UnregisterObserverExt(sptr dataObserver) override; virtual Status NotifyChangeExt(const ChangeInfo &changeInfo) override; - virtual Status NotifyProcessDialog(const std::string &progressKey, const sptr &observer) override; + virtual Status NotifyProcessObserver(const std::string &progressKey, + const sptr &cancelObserver) override; /** * @brief DataObs hidumper. diff --git a/services/dataobsmgr/include/dataobs_mgr_stub.h b/services/dataobsmgr/include/dataobs_mgr_stub.h index 07c7322dc7..53331f1c7b 100644 --- a/services/dataobsmgr/include/dataobs_mgr_stub.h +++ b/services/dataobsmgr/include/dataobs_mgr_stub.h @@ -45,7 +45,7 @@ private: int32_t UnregisterObserverExtInner(MessageParcel &data, MessageParcel &reply); int32_t UnregisterObserverExtALLInner(MessageParcel &data, MessageParcel &reply); int32_t NotifyChangeExtInner(MessageParcel &data, MessageParcel &reply); - int32_t NotifyProcessDialogInner(MessageParcel &data, MessageParcel &reply); + int32_t NotifyProcessObserverInner(MessageParcel &data, MessageParcel &reply); using RequestFuncType = int32_t (DataObsManagerStub::*)(MessageParcel &data, MessageParcel &reply); static const RequestFuncType HANDLES[TRANS_BUTT]; diff --git a/services/dataobsmgr/src/dataobs_mgr_client.cpp b/services/dataobsmgr/src/dataobs_mgr_client.cpp index 85652fe4a3..ddf0ff5bd6 100644 --- a/services/dataobsmgr/src/dataobs_mgr_client.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_client.cpp @@ -230,13 +230,14 @@ Status DataObsMgrClient::NotifyChangeExt(const ChangeInfo &changeInfo) return dataObsManger->NotifyChangeExt(changeInfo); } -Status DataObsMgrClient::NotifyProcessDialog(const std::string &progressKey, const sptr &observer) +Status DataObsMgrClient::NotifyProcessObserver(const std::string &progressKey, + const sptr &cancelObserver) { auto [errCode, dataObsManger] = GetObsMgr(); if (errCode != SUCCESS) { return DATAOBS_SERVICE_NOT_CONNECTED; } - return dataObsManger->NotifyProcessDialog(progressKey, observer); + return dataObsManger->NotifyProcessObserver(progressKey, cancelObserver); } void DataObsMgrClient::ResetService() diff --git a/services/dataobsmgr/src/dataobs_mgr_proxy.cpp b/services/dataobsmgr/src/dataobs_mgr_proxy.cpp index e58f3c9634..d6bd1d7d46 100644 --- a/services/dataobsmgr/src/dataobs_mgr_proxy.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_proxy.cpp @@ -239,45 +239,34 @@ Status DataObsManagerProxy::NotifyChangeExt(const ChangeInfo &changeInfo) return reply.ReadInt32(res) ? static_cast(res) : IPC_ERROR; } -Status DataObsManagerProxy::NotifyProcessDialog(const std::string &progressKey, const sptr &observer) +Status DataObsManagerProxy::NotifyProcessObserver(const std::string &progressKey, + const sptr &cancelObserver) { MessageParcel data; MessageParcel reply; MessageOption option; - if (!WriteInterfaceToken(data)) { return IPC_PARCEL_ERROR; } - // if (!ChangeInfo::Marshalling(progressKey, observer, data)) { - // TAG_LOGE(AAFwkTag::DBOBSMGR, - // "changeInfo marshalling error, changeType:%{public}ud, num:%{public}zu," - // "null data:%{public}d, size:%{public}ud", - // changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); - // return INVALID_PARAM; - // } - if (!data.WriteString(progressKey)) { - // TAG_LOGE(AAFwkTag::DBOBSMGR, "write uri error"); + TAG_LOGE(AAFwkTag::DBOBSMGR, "write progressKey error"); return INVALID_PARAM; } - if (observer == nullptr) { - // TAG_LOGE(AAFwkTag::DBOBSMGR, "null dataObserver"); + if (cancelObserver == nullptr) { + TAG_LOGE(AAFwkTag::DBOBSMGR, "null cancelObserver"); return INVALID_PARAM; } - - if (!data.WriteRemoteObject(observer)) { - // TAG_LOGE(AAFwkTag::DBOBSMGR, "write dataObserver error"); + if (!data.WriteRemoteObject(cancelObserver)) { + TAG_LOGE(AAFwkTag::DBOBSMGR, "write cancelObserver error"); return INVALID_PARAM; } auto error = SendTransactCmd(IDataObsMgr::NOTIFY_PROCESS, data, reply, option); if (error != NO_ERROR) { - // TAG_LOGE(AAFwkTag::DBOBSMGR, - // "sendRequest error: %{public}d, changeType:%{public}ud, num:%{public}zu," - // "null data:%{public}d, size:%{public}ud", - // error, changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); + TAG_LOGE(AAFwkTag::DBOBSMGR, + "sendRequest error: %{public}d, progressKey:%{public}s", error, progressKey.c_str()); return IPC_ERROR; } int32_t res = IPC_ERROR; diff --git a/services/dataobsmgr/src/dataobs_mgr_service.cpp b/services/dataobsmgr/src/dataobs_mgr_service.cpp index 6a250a8b94..8512a91b12 100644 --- a/services/dataobsmgr/src/dataobs_mgr_service.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_service.cpp @@ -21,18 +21,17 @@ #include #include "string_ex.h" +#include "ability_connect_callback_stub.h" +#include "ability_manager_proxy.h" #include "dataobs_mgr_errors.h" #include "hilog_tag_wrapper.h" #include "if_system_ability_manager.h" +#include "in_process_call_wrapper.h" #include "ipc_skeleton.h" +#include "iservice_registry.h" #include "system_ability_definition.h" #include "common_utils.h" #include "securec.h" - -#include "ability_connect_callback_stub.h" -#include "ability_manager_proxy.h" -#include "in_process_call_wrapper.h" -#include "iservice_registry.h" #ifdef SCENE_BOARD_ENABLE #include "window_manager_lite.h" #else @@ -41,9 +40,9 @@ namespace OHOS { namespace AAFwk { -static constexpr const char *DEFAULT_LABEL = "unknown"; -static constexpr const char *PASTEBOARD_DIALOG_APP = "com.ohos.pasteboarddialog"; -static constexpr const char *PASTEBOARD_PROGRESS_ABILITY = "PasteboardProgressAbility"; +static constexpr const char *DIALOG_APP = "com.ohos.pasteboarddialog"; +static constexpr const char *PROGRESS_ABILITY = "PasteboardProgressAbility"; +static constexpr const char *PROMPT_TEXT = "PromptText_PasteBoard_Local"; const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); @@ -330,23 +329,24 @@ sptr DataObsMgrService::GetAbilityManagerService() const { auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemAbilityManager == nullptr) { - // ZLOGE("Failed to get ability manager."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "Failed to get ability manager."); return nullptr; } sptr remoteObject = systemAbilityManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID); if (!remoteObject) { - // ZLOGE("Failed to get ability manager service."); + TAG_LOGE(AAFwkTag::DBOBSMGR, "Failed to get ability manager service."); return nullptr; } return iface_cast(remoteObject); } -Status DataObsMgrService::NotifyProcessDialog(const std::string &progressKey, const sptr &observer) +Status DataObsMgrService::NotifyProcessObserver(const std::string &progressKey, + const sptr &cancelObserver) { auto abilityManager = GetAbilityManagerService(); if (abilityManager == nullptr) { - // ZLOGE("Get ability manager failed."); - return SUCCESS; + TAG_LOGE(AAFwkTag::DBOBSMGR, "Get ability manager failed."); + return DATAOBS_PROXY_INNER_ERR; } int32_t windowId; @@ -354,24 +354,24 @@ Status DataObsMgrService::NotifyProcessDialog(const std::string &progressKey, co GetFocusedAppInfo(windowId, callerToken); Want want; - want.SetElementName(PASTEBOARD_DIALOG_APP, PASTEBOARD_PROGRESS_ABILITY); - want.SetAction(PASTEBOARD_PROGRESS_ABILITY); - want.SetParam("promptText", std::string("PromptText_PasteBoard_Local")); + want.SetElementName(DIALOG_APP, PROGRESS_ABILITY); + want.SetAction(PROGRESS_ABILITY); + want.SetParam("promptText", PROMPT_TEXT); want.SetParam("remoteDeviceName", std::string()); want.SetParam("progressKey", progressKey); want.SetParam("isRemote", false); want.SetParam("windowId", windowId); - want.SetParam("ipcCallback", observer); + want.SetParam("ipcCallback", cancelObserver); if (callerToken != nullptr) { want.SetParam("tokenKey", callerToken); } else { - // ZLOGW("CallerToken is nullptr."); + TAG_LOGW(AAFwkTag::DBOBSMGR, "CallerToken is nullptr."); } int32_t status = IN_PROCESS_CALL(abilityManager->StartAbility(want)); - if (status != SUCCESS) { - // ZLOGE("ShowProgress fail, status:%{public}d", status); + TAG_LOGE(AAFwkTag::DBOBSMGR, "ShowProgress fail, status:%{public}d", status); + return DATAOBS_PROXY_INNER_ERR; } return SUCCESS; } diff --git a/services/dataobsmgr/src/dataobs_mgr_stub.cpp b/services/dataobsmgr/src/dataobs_mgr_stub.cpp index 099bddc7cd..4146f33991 100644 --- a/services/dataobsmgr/src/dataobs_mgr_stub.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_stub.cpp @@ -37,7 +37,7 @@ const DataObsManagerStub::RequestFuncType DataObsManagerStub::HANDLES[TRANS_BUTT &DataObsManagerStub::UnregisterObserverExtInner, &DataObsManagerStub::UnregisterObserverExtALLInner, &DataObsManagerStub::NotifyChangeExtInner, - &DataObsManagerStub::NotifyProcessDialogInner + &DataObsManagerStub::NotifyProcessObserverInner }; DataObsManagerStub::DataObsManagerStub() {} @@ -156,18 +156,11 @@ int32_t DataObsManagerStub::NotifyChangeExtInner(MessageParcel &data, MessagePar return SUCCESS; } -int32_t DataObsManagerStub::NotifyProcessDialogInner(MessageParcel &data, MessageParcel &reply) +int32_t DataObsManagerStub::NotifyProcessObserverInner(MessageParcel &data, MessageParcel &reply) { - // ChangeInfo changeInfo; - // if (!ChangeInfo::Unmarshalling(changeInfo, data)) { - // LOG_ERROR("Failed to unmarshall changeInfo."); - // return IPC_STUB_INVALID_DATA_ERR; - // } - - std::string key = data.ReadString(); - auto remote = data.ReadRemoteObject(); - reply.WriteInt32(NotifyProcessDialog(key, remote)); + auto cancelObserver = data.ReadRemoteObject(); + reply.WriteInt32(NotifyProcessObserver(key, cancelObserver)); return SUCCESS; } } // namespace AAFwk diff --git a/test/unittest/dataobs_mgr_client_test/mock_dataobs_mgr_service.h b/test/unittest/dataobs_mgr_client_test/mock_dataobs_mgr_service.h index d696c1786a..df09df1c0a 100644 --- a/test/unittest/dataobs_mgr_client_test/mock_dataobs_mgr_service.h +++ b/test/unittest/dataobs_mgr_client_test/mock_dataobs_mgr_service.h @@ -69,6 +69,13 @@ public: return SUCCESS; } + Status NotifyProcessObserver(const std::string &progressKey, + const sptr &cancelObserver) override + { + onChangeCall_++; + return SUCCESS; + } + void OnStart() {} void OnStop() {} diff --git a/test/unittest/dataobs_mgr_proxy_test/mock_data_obs_mgr_stub.h b/test/unittest/dataobs_mgr_proxy_test/mock_data_obs_mgr_stub.h index 2270a02e84..4c605136b2 100644 --- a/test/unittest/dataobs_mgr_proxy_test/mock_data_obs_mgr_stub.h +++ b/test/unittest/dataobs_mgr_proxy_test/mock_data_obs_mgr_stub.h @@ -44,6 +44,7 @@ public: MOCK_METHOD2(UnregisterObserverExt, Status(const Uri&, sptr)); MOCK_METHOD1(UnregisterObserverExt, Status(sptr)); MOCK_METHOD1(NotifyChangeExt, Status(const ChangeInfo&)); + MOCK_METHOD2(NotifyProcessObserver, Status(const std::string&, const sptr&)); }; class MockDataAbilityObserverStub : public AAFwk::DataAbilityObserverStub { diff --git a/test/unittest/dataobs_mgr_stub_test/mock_data_obs_mgr_stub.h b/test/unittest/dataobs_mgr_stub_test/mock_data_obs_mgr_stub.h index 292b507326..dc226a6366 100644 --- a/test/unittest/dataobs_mgr_stub_test/mock_data_obs_mgr_stub.h +++ b/test/unittest/dataobs_mgr_stub_test/mock_data_obs_mgr_stub.h @@ -43,6 +43,7 @@ public: MOCK_METHOD2(UnregisterObserverExt, Status(const Uri&, sptr)); MOCK_METHOD1(UnregisterObserverExt, Status(sptr)); MOCK_METHOD1(NotifyChangeExt, Status(const ChangeInfo&)); + MOCK_METHOD2(NotifyProcessObserver, Status(const std::string&, const sptr&)); }; class MockDataAbilityObserverStub : public AAFwk::DataAbilityObserverStub {