Signed-off-by: zph <zhaopenghui8@huawei.com>
This commit is contained in:
zph
2025-02-17 15:15:46 +08:00
parent ee4825429f
commit db45dc8eed
13 changed files with 71 additions and 63 deletions
@@ -105,7 +105,16 @@ public:
*/
Status NotifyChangeExt(const ChangeInfo &changeInfo);
Status NotifyProcessDialog(const std::string &progressKey, const sptr<IRemoteObject> &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<IRemoteObject> &cancelObserver);
private:
class SystemAbilityStatusChangeListener;
@@ -124,7 +124,7 @@ public:
*
* @return Returns SUCCESS on success, others on failure.
*/
virtual Status NotifyProcessDialog(const std::string &progressKey, const sptr<IRemoteObject> &observer) = 0;
virtual Status NotifyProcessObserver(const std::string &progressKey, const sptr<IRemoteObject> &observer) = 0;
};
} // namespace AAFwk
} // namespace OHOS
-2
View File
@@ -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",
@@ -104,7 +104,17 @@ public:
*/
virtual Status NotifyChangeExt(const ChangeInfo &changeInfo) override;
virtual Status NotifyProcessDialog(const std::string &progressKey, const sptr<IRemoteObject> &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<IRemoteObject> &cancelObserver) override;
private:
bool WriteInterfaceToken(MessageParcel &data);
@@ -22,6 +22,7 @@
#include <unordered_map>
#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<IDataAbilityObserver> dataObserver) override;
virtual Status UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver) override;
virtual Status NotifyChangeExt(const ChangeInfo &changeInfo) override;
virtual Status NotifyProcessDialog(const std::string &progressKey, const sptr<IRemoteObject> &observer) override;
virtual Status NotifyProcessObserver(const std::string &progressKey,
const sptr<IRemoteObject> &cancelObserver) override;
/**
* @brief DataObs hidumper.
@@ -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];
@@ -230,13 +230,14 @@ Status DataObsMgrClient::NotifyChangeExt(const ChangeInfo &changeInfo)
return dataObsManger->NotifyChangeExt(changeInfo);
}
Status DataObsMgrClient::NotifyProcessDialog(const std::string &progressKey, const sptr<IRemoteObject> &observer)
Status DataObsMgrClient::NotifyProcessObserver(const std::string &progressKey,
const sptr<IRemoteObject> &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()
+9 -20
View File
@@ -239,45 +239,34 @@ Status DataObsManagerProxy::NotifyChangeExt(const ChangeInfo &changeInfo)
return reply.ReadInt32(res) ? static_cast<Status>(res) : IPC_ERROR;
}
Status DataObsManagerProxy::NotifyProcessDialog(const std::string &progressKey, const sptr<IRemoteObject> &observer)
Status DataObsManagerProxy::NotifyProcessObserver(const std::string &progressKey,
const sptr<IRemoteObject> &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;
+20 -20
View File
@@ -21,18 +21,17 @@
#include <unistd.h>
#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<DataObsMgrService>::GetInstance().get());
@@ -330,23 +329,24 @@ sptr<IAbilityManager> 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<IRemoteObject> 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<IAbilityManager>(remoteObject);
}
Status DataObsMgrService::NotifyProcessDialog(const std::string &progressKey, const sptr<IRemoteObject> &observer)
Status DataObsMgrService::NotifyProcessObserver(const std::string &progressKey,
const sptr<IRemoteObject> &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;
}
+4 -11
View File
@@ -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
@@ -69,6 +69,13 @@ public:
return SUCCESS;
}
Status NotifyProcessObserver(const std::string &progressKey,
const sptr<IRemoteObject> &cancelObserver) override
{
onChangeCall_++;
return SUCCESS;
}
void OnStart() {}
void OnStop() {}
@@ -44,6 +44,7 @@ public:
MOCK_METHOD2(UnregisterObserverExt, Status(const Uri&, sptr<IDataAbilityObserver>));
MOCK_METHOD1(UnregisterObserverExt, Status(sptr<IDataAbilityObserver>));
MOCK_METHOD1(NotifyChangeExt, Status(const ChangeInfo&));
MOCK_METHOD2(NotifyProcessObserver, Status(const std::string&, const sptr<IRemoteObject>&));
};
class MockDataAbilityObserverStub : public AAFwk::DataAbilityObserverStub {
@@ -43,6 +43,7 @@ public:
MOCK_METHOD2(UnregisterObserverExt, Status(const Uri&, sptr<IDataAbilityObserver>));
MOCK_METHOD1(UnregisterObserverExt, Status(sptr<IDataAbilityObserver>));
MOCK_METHOD1(NotifyChangeExt, Status(const ChangeInfo&));
MOCK_METHOD2(NotifyProcessObserver, Status(const std::string&, const sptr<IRemoteObject>&));
};
class MockDataAbilityObserverStub : public AAFwk::DataAbilityObserverStub {