!918 get dms opt Info and notify collaborate state

Merge pull request !918 from 仝月姣/master
This commit is contained in:
openharmony_ci 2024-05-30 16:31:56 +00:00 committed by Gitee
commit ff19bced46
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
29 changed files with 950 additions and 275 deletions

View File

@ -117,14 +117,15 @@
},
{
"header": {
"header_base": "//foundation/ability/dmsfwk/interfaces/innerkits/distributed_event/include",
"header_base": "//foundation/ability/dmsfwk/interfaces/innerkits",
"header_files": [
"distributed_event_listener.h",
"distributed_parcel_helper.h",
"dms_client.h",
"dms_handler.h",
"dms_listener_stub.h",
"dms_sa_client.h"
"./common/include/distributed_sched_types.h",
"./distributed_event/include/distributed_event_listener.h",
"./distributed_event/include/distributed_parcel_helper.h",
"./distributed_event/include/dms_client.h",
"./distributed_event/include/dms_handler.h",
"./distributed_event/include/dms_listener_stub.h",
"./distributed_event/include/dms_sa_client.h"
]
},
"name": "//foundation/ability/dmsfwk/interfaces/innerkits/distributed_event:distributed_sdk"

View File

@ -153,14 +153,14 @@ int32_t LoadContinueConfig()
return DMS_PERMISSION_DENIED;
}
std::string CfgFileContent;
std::string cfgFileContent;
in.seekg(0, std::ios::end);
CfgFileContent.resize(in.tellg());
cfgFileContent.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.rdbuf()->sgetn(&CfgFileContent[0], CfgFileContent.size());
in.rdbuf()->sgetn(&cfgFileContent[0], cfgFileContent.size());
in.close();
if (!UpdateAllowAppList(CfgFileContent)) {
if (!UpdateAllowAppList(cfgFileContent)) {
HILOGE("Update allow app list fail, cfgFullPath %{public}s.", g_continueCfgFullPath.c_str());
return DMS_PERMISSION_DENIED;
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 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_DISTRIBUTED_SCHED_TYPES_H
#define OHOS_DISTRIBUTED_SCHED_TYPES_H
#include <string>
namespace OHOS {
namespace DistributedSchedule {
class ContinueInfo {
public:
std::string srcNetworkId_;
std::string dstNetworkId_;
};
enum DSchedEventType {
DMS_UNKNOW = -1,
DMS_CONTINUE = 0,
DMS_COLLABORATION = 1,
DMS_ALL = 2,
};
enum DSchedEventState {
DMS_DSCHED_EVENT_INIT = 0,
DMS_DSCHED_EVENT_START = 1,
DMS_DSCHED_EVENT_PROCESSING = 2,
DMS_DSCHED_EVENT_STOP = 3,
DMS_DSCHED_EVENT_FINISH = 4,
};
class EventNotify {
public:
int32_t eventResult_ = -1;
std::string srcNetworkId_ = "";
std::string dstNetworkId_ = "";
std::string srcBundleName_ = "";
std::string srcModuleName_ = "";
std::string srcAbilityName_ = "";
std::string destBundleName_ = "";
std::string destModuleName_ = "";
std::string destAbilityName_ = "";
DSchedEventType dSchedEventType_ = DMS_UNKNOW;
DSchedEventState state_ = DMS_DSCHED_EVENT_INIT;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_SCHED_TYPES_H

View File

@ -18,6 +18,7 @@ config("dms_sdk_public_config") {
visibility = [ ":*" ]
include_dirs = [
"${dms_path}/common/include",
"${dms_path}/interfaces/innerkits/common/include/",
"${dms_path}/interfaces/innerkits/distributed_event/include/",
"${dms_path}/services/dtbabilitymgr/include/",
"${dms_path}/services/dtbschedmgr/include/",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -20,36 +20,10 @@
#include "iremote_broker.h"
#include "distributed_sched_types.h"
namespace OHOS {
namespace DistributedSchedule {
enum DSchedEventType {
DMS_CONTINUE = 0,
DMS_COLLABRATION = 1,
DMS_ALL = 2,
};
enum DSchedEventState {
DMS_DSCHED_EVENT_START = 0,
DMS_DSCHED_EVENT_PROCESSING = 1,
DMS_DSCHED_EVENT_STOP = 2,
DMS_DSCHED_EVENT_FINISH = 3,
};
class EventNotify {
public:
int32_t eventResult_ = -1;
std::string srcNetworkId_;
std::string dstNetworkId_;
std::string srcBundleName_;
std::string srcModuleName_;
std::string srcAbilityName_;
std::string destBundleName_;
std::string destModuleName_;
std::string destAbilityName_;
DSchedEventType dSchedEventType_;
DSchedEventState state_;
};
class IDSchedEventListener : public OHOS::IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedSchedule.dschedeventlistener");
@ -63,4 +37,4 @@ public:
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_EVENT_LISTENER_H
#endif // OHOS_DISTRIBUTED_EVENT_LISTENER_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -18,30 +18,24 @@
#include <string>
#include "iremote_broker.h"
#include "ability_manager_errors.h"
#include "distributed_event_listener.h"
#include "iremote_broker.h"
#include "distributed_sched_types.h"
namespace OHOS {
namespace DistributedSchedule {
class ContinueInfo {
public:
std::string srcNetworkId_;
std::string dstNetworkId_;
};
class DistributedClient {
public:
int32_t RegisterDSchedEventListener(const uint8_t& type, const sptr<IDSchedEventListener>& obj);
int32_t UnRegisterDSchedEventListener(const uint8_t& type, const sptr<IDSchedEventListener>& obj);
int32_t RegisterDSchedEventListener(const DSchedEventType& type, const sptr<IDSchedEventListener>& obj);
int32_t UnRegisterDSchedEventListener(const DSchedEventType& type, const sptr<IDSchedEventListener>& obj);
int32_t GetContinueInfo(ContinueInfo &continueInfo);
enum {
REGISTER_DSCHED_EVENT_LISTENER = 262,
UNREGISTER_DSCHED_EVENT_LISTENER = 263,
GET_CONTINUE_INFO = 264,
};
int32_t GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events);
private:
sptr<IRemoteObject> GetDmsProxy();
int32_t GetDecodeDSchedEventNotify(MessageParcel &reply, EventNotify &event);
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -22,9 +22,11 @@
#include <string>
#include <vector>
#include "distributed_event_listener.h"
#include "dms_sa_client.h"
#include "refbase.h"
#include "distributed_event_listener.h"
#include "distributed_sched_types.h"
#include "dms_sa_client.h"
#include "single_instance.h"
namespace OHOS {
@ -33,9 +35,10 @@ class DmsHandler {
DECLARE_SINGLE_INSTANCE(DmsHandler);
public:
int32_t RegisterDSchedEventListener(const uint8_t& type, sptr<IDSchedEventListener> &listener);
int32_t UnRegisterDSchedEventListener(const uint8_t& type, sptr<IDSchedEventListener> &listener);
int32_t RegisterDSchedEventListener(const DSchedEventType& type, sptr<IDSchedEventListener> &listener);
int32_t UnRegisterDSchedEventListener(const DSchedEventType& type, sptr<IDSchedEventListener> &listener);
int32_t GetContinueInfo(ContinueInfo &continueInfo);
int32_t GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events);
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -18,32 +18,36 @@
#include <mutex>
#include "distributed_event_listener.h"
#include "dms_client.h"
#include "dms_handler.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "sam_log.h"
#include "system_ability_status_change_stub.h"
#include "system_ability_definition.h"
#include "distributed_event_listener.h"
#include "distributed_sched_types.h"
#include "dms_client.h"
#include "dms_handler.h"
namespace OHOS {
namespace DistributedSchedule {
class DmsSaClient : public SystemAbilityStatusChangeStub {
public:
static DmsSaClient &GetInstance();
bool SubscribeDmsSA();
int32_t AddDSchedEventListener(const uint8_t& type, const sptr<IDSchedEventListener>& listener);
int32_t DelDSchedEventListener(const uint8_t& type, const sptr<IDSchedEventListener>& listener);
int32_t AddDSchedEventListener(const DSchedEventType& type, const sptr<IDSchedEventListener>& listener);
int32_t DelDSchedEventListener(const DSchedEventType& type, const sptr<IDSchedEventListener>& listener);
int32_t GetContinueInfo(ContinueInfo &continueInfo);
int32_t GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events);
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
private:
DmsSaClient() {};
~DmsSaClient() {};
bool hasSubscribeDmsSA_ = false;
OHOS::sptr<ISystemAbilityManager> saMgrProxy_;
std::map<uint8_t, sptr<IDSchedEventListener>> listeners_;
std::map<DSchedEventType, sptr<IDSchedEventListener>> listeners_;
std::mutex eventMutex_;
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -16,18 +16,21 @@
#include "dms_client.h"
#include "ability_manager_errors.h"
#include "distributed_parcel_helper.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "string_ex.h"
#include "system_ability_definition.h"
#include "distributed_parcel_helper.h"
#include "distributedsched_ipc_interface_code.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
}
sptr<IRemoteObject> DistributedClient::GetDmsProxy()
{
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
@ -38,7 +41,7 @@ sptr<IRemoteObject> DistributedClient::GetDmsProxy()
return samgrProxy->CheckSystemAbility(DISTRIBUTED_SCHED_SA_ID);
}
int32_t DistributedClient::RegisterDSchedEventListener(const uint8_t& type,
int32_t DistributedClient::RegisterDSchedEventListener(const DSchedEventType& type,
const sptr<IDSchedEventListener>& obj)
{
HILOG_INFO("RegisterDSchedEventListener called");
@ -54,10 +57,11 @@ int32_t DistributedClient::RegisterDSchedEventListener(const uint8_t& type,
}
PARCEL_WRITE_HELPER(data, Uint8, type);
PARCEL_WRITE_HELPER(data, RemoteObject, obj->AsObject());
PARCEL_TRANSACT_SYNC_RET_INT(remote, REGISTER_DSCHED_EVENT_LISTENER, data, reply);
PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_DSCHED_EVENT_LISTENER),
data, reply);
}
int32_t DistributedClient::UnRegisterDSchedEventListener(const uint8_t& type,
int32_t DistributedClient::UnRegisterDSchedEventListener(const DSchedEventType& type,
const sptr<IDSchedEventListener>& obj)
{
HILOG_INFO("UnRegisterDSchedEventListener called");
@ -74,7 +78,8 @@ int32_t DistributedClient::UnRegisterDSchedEventListener(const uint8_t& type,
}
PARCEL_WRITE_HELPER(data, Uint8, type);
PARCEL_WRITE_HELPER(data, RemoteObject, obj->AsObject());
PARCEL_TRANSACT_SYNC_RET_INT(remote, UNREGISTER_DSCHED_EVENT_LISTENER, data, reply);
PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_DSCHED_EVENT_LISTENER),
data, reply);
}
int32_t DistributedClient::GetContinueInfo(ContinueInfo &continueInfo)
@ -93,7 +98,8 @@ int32_t DistributedClient::GetContinueInfo(ContinueInfo &continueInfo)
}
MessageOption option;
int32_t ret = remote->SendRequest(GET_CONTINUE_INFO, data, reply, option);
int32_t ret = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_CONTINUE_INFO),
data, reply, option);
if (ret != ERR_NONE) {
HILOG_ERROR("sendRequest fail, error: %{public}d", ret);
return ret;
@ -106,5 +112,64 @@ int32_t DistributedClient::GetContinueInfo(ContinueInfo &continueInfo)
}
return ret;
}
int32_t DistributedClient::GetDecodeDSchedEventNotify(MessageParcel &reply, EventNotify &event)
{
event.eventResult_ = reply.ReadInt32();
event.srcNetworkId_ = reply.ReadString();
event.dstNetworkId_ = reply.ReadString();
event.srcBundleName_ = reply.ReadString();
event.srcModuleName_ = reply.ReadString();
event.srcAbilityName_ = reply.ReadString();
event.destBundleName_ = reply.ReadString();
event.destModuleName_ = reply.ReadString();
event.destAbilityName_ = reply.ReadString();
event.dSchedEventType_ = static_cast<DSchedEventType>(reply.ReadInt32());
event.state_ = static_cast<DSchedEventState>(reply.ReadInt32());
return ERR_OK;
}
int32_t DistributedClient::GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events)
{
HILOG_INFO("%{public}s called", __func__);
sptr<IRemoteObject> remote = GetDmsProxy();
if (remote == nullptr) {
HILOG_ERROR("remote system ablity is null");
return ERR_FLATTEN_OBJECT;
}
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
HILOG_DEBUG("write interface token failed.");
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, Uint32, type);
MessageOption option;
int32_t ret = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_DSCHED_EVENT_INFO),
data, reply, option);
if (ret != ERR_OK) {
HILOG_ERROR("sendRequest fail, ret: %{public}d", ret);
return ret;
}
ret = reply.ReadInt32();
if (ret != ERR_OK) {
HILOG_ERROR("Proxy get dms eventInfos from dms service fail, ret: %{public}d", ret);
return ret;
}
uint32_t eventNum = reply.ReadUint32();
if (eventNum > UINT32_MAX) {
HILOG_ERROR("Proxy get dms eventInfos num %{public}u is invalid.", eventNum);
return AAFwk::INVALID_PARAMETERS_ERR;
}
for (uint32_t i = 0; i < eventNum; i++) {
EventNotify event;
GetDecodeDSchedEventNotify(reply, event);
events.emplace_back(event);
}
return ret;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -26,7 +26,7 @@ namespace {
const std::string TAG = "DmsHandle";
}
int32_t DmsHandler::RegisterDSchedEventListener(const uint8_t& type, sptr<IDSchedEventListener>& listener)
int32_t DmsHandler::RegisterDSchedEventListener(const DSchedEventType& type, sptr<IDSchedEventListener>& listener)
{
HILOGI("RegisterListener type:%d", type);
if (listener == nullptr) {
@ -41,7 +41,7 @@ int32_t DmsHandler::RegisterDSchedEventListener(const uint8_t& type, sptr<IDSche
return 0;
}
int32_t DmsHandler::UnRegisterDSchedEventListener(const uint8_t& type, sptr<IDSchedEventListener> &listener)
int32_t DmsHandler::UnRegisterDSchedEventListener(const DSchedEventType& type, sptr<IDSchedEventListener> &listener)
{
HILOGI("RegisterListener type:%d", type);
if (listener == nullptr) {
@ -66,5 +66,16 @@ int32_t DmsHandler::GetContinueInfo(ContinueInfo &continueInfo)
}
return 0;
}
int32_t DmsHandler::GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events)
{
HILOGI("%{public}s called", __func__);
int32_t ret = DmsSaClient::GetInstance().GetDSchedEventInfo(type, events);
if (ret != ERR_OK) {
HILOGE("DmsSaClient GetDSchedEventInfo fail, ret %{public}d.", ret);
return GET_REMOTE_DMS_FAIL;
}
return ERR_OK;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -35,7 +35,7 @@ bool DmsSaClient::SubscribeDmsSA()
return true;
}
int32_t DmsSaClient::AddDSchedEventListener(const uint8_t& type, const sptr<IDSchedEventListener>& listener)
int32_t DmsSaClient::AddDSchedEventListener(const DSchedEventType& type, const sptr<IDSchedEventListener>& listener)
{
HILOGI("%{public}s called, the type is %{public}d", __func__, type);
saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
@ -59,7 +59,7 @@ int32_t DmsSaClient::AddDSchedEventListener(const uint8_t& type, const sptr<IDSc
return NO_ERROR;
}
int32_t DmsSaClient::DelDSchedEventListener(const uint8_t& type, const sptr<IDSchedEventListener>& listener)
int32_t DmsSaClient::DelDSchedEventListener(const DSchedEventType& type, const sptr<IDSchedEventListener>& listener)
{
HILOGI("%{public}s called, the type is %{public}d", __func__, type);
saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
@ -91,6 +91,27 @@ int32_t DmsSaClient::GetContinueInfo(ContinueInfo &continueInfo)
return NO_ERROR;
}
int32_t DmsSaClient::GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events)
{
HILOGI("%{public}s called", __func__);
saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (saMgrProxy_ == nullptr) {
HILOGE("Get SA manager proxy fail.");
return AAFwk::INNER_ERR;
}
if (!saMgrProxy_->CheckSystemAbility(DISTRIBUTED_SCHED_SA_ID)) {
HILOGE("Get SA manager proxy fail.");
return AAFwk::INNER_ERR;
}
DistributedClient distributedClient;
int32_t ret = distributedClient.GetDSchedEventInfo(type, events);
if (ret != ERR_OK) {
HILOGE("Get dms event Info proxy call fail, ret %{public}d.", ret);
}
return ret;
}
void DmsSaClient::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
{
HILOGI("%{public}s called, the systemAbilityId is %{public}d", __func__, systemAbilityId);

View File

@ -26,11 +26,11 @@ using namespace std;
Business g_business;
namespace {
DmsHandler &dmsSourceHandlerdemo = DmsHandler::GetInstance();
uint8_t g_type = DMS_CONTINUE;
DSchedEventType g_type = DMS_CONTINUE;
sptr<IDSchedEventListener> listener = sptr<IDSchedEventListener>(new Business());
ContinueInfo g_continueInfo;
}
void Business::Register()
{
int32_t result = 0;
@ -41,7 +41,7 @@ void Business::Register()
cout << "RegisterDSchedEventListener succeed.CODE = " << result << endl;
}
}
void Business::UnRegister()
{
int32_t result = 0;

View File

@ -28,6 +28,7 @@ config("distributed_sched_config") {
"${dms_path}/common/include",
"${dms_path}/interfaces/kits/napi/include",
"${dms_path}/interfaces/innerkits/common/include",
"include/collaborate",
"include/continue",
"include/continue/state",
"include/continue/state/source_state",
@ -83,6 +84,7 @@ ohos_shared_library("distributedschedsvr") {
"src/app_state_observer.cpp",
"src/bundle/bundle_manager_callback_stub.cpp",
"src/bundle/bundle_manager_internal.cpp",
"src/collaborate/dsched_collaborate_callback_mgr.cpp",
"src/connect_death_recipient.cpp",
"src/continue/dsched_continue.cpp",
"src/continue/dsched_continue_event.cpp",

View File

@ -34,6 +34,7 @@ class BundleManagerInternal {
public:
static bool GetCallerAppIdFromBms(int32_t callingUid, std::string& appId);
static bool GetCallerAppIdFromBms(const std::string& bundleName, std::string& appId);
static bool GetSpecifyBundleNameFromBms(int32_t callingUid, std::string& bundleName);
static bool GetBundleNameListFromBms(int32_t callingUid, std::vector<std::string>& bundleNameList);
static bool GetBundleNameListFromBms(int32_t callingUid, std::vector<std::u16string>& u16BundleNameList);
static bool QueryAbilityInfo(const AAFwk::Want& want, AppExecFwk::AbilityInfo& abilityInfo);

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2024 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_DSCHED_COLLABORATION_H
#define OHOS_DSCHED_COLLABORATION_H
#include <cstdint>
#include <map>
#include <mutex>
#include "event_handler.h"
#include "iremote_object.h"
#include "refbase.h"
#include "distributed_event_died_listener.h"
#include "distributed_sched_types.h"
namespace OHOS {
namespace DistributedSchedule {
class DSchedCollaborationCallbackMgr : public std::enable_shared_from_this<DSchedCollaborationCallbackMgr> {
public:
void Init();
bool PushCallback(const sptr<IRemoteObject>& callback);
std::vector<sptr<IRemoteObject>> GetCallback();
bool CleanupCallback(const sptr<IRemoteObject>& callback);
int32_t NotifyDSchedEventResult(int32_t resultCode, const EventNotify& event);
private:
int32_t NotifyDSchedEventForOneCB(const sptr<IRemoteObject> &cb, const EventNotify& event);
private:
std::mutex collaborateCbLock_;
std::vector<sptr<IRemoteObject>> collaborateCbArr_;
sptr<DistributedEventDiedListener> diedListener_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DSCHED_COLLABORATION_H

View File

@ -20,46 +20,17 @@
#include <map>
#include <mutex>
#include "distributed_event_died_listener.h"
#include "event_handler.h"
#include "iremote_object.h"
#include "refbase.h"
#include "distributed_event_died_listener.h"
#include "distributed_sched_types.h"
namespace OHOS {
namespace DistributedSchedule {
using FuncContinuationCallback = std::function<void(int32_t missionId)>;
struct ContinueInfo {
std::string srcNetworkId;
std::string dstNetworkId;
};
enum DSchedEventType {
DMS_CONTINUE = 0,
DMS_COLLABRATION = 1,
DMS_ALL = 2,
};
enum DSchedEventState {
DMS_DSCHED_EVENT_START = 0,
DMS_DSCHED_EVENT_PROCESSING = 1,
DMS_DSCHED_EVENT_STOP = 2,
DMS_DSCHED_EVENT_FINISH = 3,
};
struct EventNotify {
int32_t eventResult = -1;
std::string srcNetworkId;
std::string dstNetworkId;
std::string srcBundleName;
std::string srcModuleName;
std::string srcAbilityName;
std::string destBundleName;
std::string destModuleName;
std::string destAbilityName;
DSchedEventType dSchedEventType;
DSchedEventState state;
};
class DSchedContinuation : public std::enable_shared_from_this<DSchedContinuation> {
public:
void Init(const FuncContinuationCallback& contCallback);
@ -84,6 +55,9 @@ public:
EventNotify continueEvent_;
ContinueInfo continueInfo_;
private:
int32_t NotifyDSchedEventForOneCB(const sptr<IRemoteObject> &cb, int32_t resultCode);
private:
class ContinuationHandler : public AppExecFwk::EventHandler {
public:
@ -112,5 +86,4 @@ private:
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_SCHED_CONTINUATION_H
#endif // OHOS_DISTRIBUTED_SCHED_CONTINUATION_H

View File

@ -20,6 +20,7 @@
#include "ability_info.h"
#include "ability_manager_interface.h"
#include "caller_info.h"
#include "distributed_sched_types.h"
#include "distributedsched_ipc_interface_code.h"
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
#include "form_share_info.h"
@ -100,11 +101,11 @@ public:
virtual int32_t StopSyncRemoteMissions(const std::string& devId) = 0;
virtual int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) = 0;
virtual int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) = 0;
virtual int32_t RegisterDSchedEventListener(const uint8_t& type, const sptr<IRemoteObject>& obj)
virtual int32_t RegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj)
{
return 0;
}
virtual int32_t UnRegisterDSchedEventListener(const uint8_t& type, const sptr<IRemoteObject>& obj)
virtual int32_t UnRegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj)
{
return 0;
}
@ -112,6 +113,10 @@ public:
{
return 0;
}
virtual int32_t GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events)
{
return 0;
}
virtual int32_t RegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj)
{
return 0;

View File

@ -60,8 +60,8 @@ public:
int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override;
int32_t StopSyncRemoteMissions(const std::string& devId) override;
int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
int32_t RegisterDSchedEventListener(const uint8_t& type, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterDSchedEventListener(const uint8_t& type, const sptr<IRemoteObject>& obj) override;
int32_t RegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj) override;
int32_t RegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj) override;
int32_t RegisterOffListener(const std::string& type, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
@ -101,6 +101,7 @@ public:
const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType) override;
virtual int32_t StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType) override;
private:
bool CallerInfoMarshalling(const CallerInfo& callerInfo, MessageParcel& data);
static inline BrokerDelegator<DistributedSchedProxy> delegator_;

View File

@ -27,6 +27,7 @@
#include "distributed_sched_stub.h"
#include "distributed_sched_continuation.h"
#include "dms_callback_task.h"
#include "dsched_collaborate_callback_mgr.h"
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
#include "form_mgr_interface.h"
#endif
@ -142,14 +143,15 @@ public:
int32_t StopSyncRemoteMissions(const std::string& devId) override;
int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) override;
int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
int32_t RegisterDSchedEventListener(const uint8_t& type, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterDSchedEventListener(const uint8_t& type, const sptr<IRemoteObject>& obj) override;
int32_t GetContinueInfo(std::string& dstNetworkId, std::string& srcNetworkId) override;
int32_t RegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj) override;
int32_t RegisterOffListener(const std::string& type, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
int32_t SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState &state) override;
#endif
int32_t RegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj) override;
int32_t GetContinueInfo(std::string& dstNetworkId, std::string& srcNetworkId) override;
int32_t GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events) override;
void ProcessConnectDied(const sptr<IRemoteObject>& connect);
void ProcessDeviceOffline(const std::string& deviceId);
void DumpConnectInfo(std::string& info);
@ -193,6 +195,7 @@ public:
int32_t CheckTargetPermission(const OHOS::AAFwk::Want& want, const CallerInfo& callerInfo,
const AccountInfo& accountInfo, int32_t flag, bool needQueryExtension);
ErrCode QueryOsAccount(int32_t& activeAccountId);
private:
DistributedSchedService();
bool Init();
@ -258,8 +261,25 @@ private:
void SetCleanMissionFlag(const OHOS::AAFwk::Want& want, int32_t missionId);
void RemoveConnectAbilityInfo(const std::string& deviceId);
void InitWifiStateListener();
void NotifyContinuateEventResult(int32_t resultCode, const EventNotify& event);
void NotifyCollaborateEventResult(int32_t resultCode, const EventNotify& event);
void GetContinueEventInfo(int32_t callingUid, std::vector<EventNotify> &events);
void GetCollaborateEventInfo(int32_t callingUid, std::vector<EventNotify> &events);
void GetCollaborateEventsByCallers(int32_t callingUid, const std::string &callingBundleName,
std::vector<EventNotify> &events);
void GetCollaborateEventsByCallees(int32_t callingUid, const std::string &callingBundleName,
std::vector<EventNotify> &events);
void GetCurSrcCollaborateEvent(const CallerInfo &callerInfo, const AppExecFwk::ElementName &element,
DSchedEventState state, int32_t ret, EventNotify &event);
void GetCurDestCollaborateEvent(const CallerInfo &callerInfo, const AppExecFwk::ElementName &element,
DSchedEventState state, int32_t ret, EventNotify &event);
void NotifyCollaborateEventWithSessions(const std::list<ConnectAbilitySession> &sessionsList,
DSchedEventState state, int32_t ret);
bool CheckCallingUid();
private:
std::shared_ptr<DSchedContinuation> dschedContinuation_;
std::shared_ptr<DSchedCollaborationCallbackMgr> collaborateCbMgr_;
std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> distributedConnectAbilityMap_;
std::map<sptr<IRemoteObject>, ConnectInfo> connectAbilityMap_;
std::unordered_map<int32_t, uint32_t> trackingUidMap_;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -54,6 +54,7 @@ private:
int32_t RegisterDSchedEventListenerInner(MessageParcel& data, MessageParcel& reply);
int32_t UnRegisterDSchedEventListenerInner(MessageParcel& data, MessageParcel& reply);
int32_t GetContinueInfoInner(MessageParcel& data, MessageParcel& reply);
int32_t GetDSchedEventInfoInner(MessageParcel& data, MessageParcel& reply);
int32_t RegisterOnListenerInner(MessageParcel& data, MessageParcel& reply);
int32_t RegisterOffListenerInner(MessageParcel& data, MessageParcel& reply);
int32_t UnRegisterMissionListenerInner(MessageParcel& data, MessageParcel& reply);
@ -92,6 +93,7 @@ private:
void InitLocalMissionManagerInner();
void InitRemoteFuncsInner();
std::shared_ptr<AAFwk::Want> ReadDistributedWant(MessageParcel& data);
int32_t GetEncodeDSchedEventNotify(const EventNotify& event, MessageParcel& reply);
int32_t StopRemoteExtensionAbilityInner(MessageParcel& data, MessageParcel& reply);
int32_t StopExtensionAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2024 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
@ -87,6 +87,7 @@ enum class IDSchedInterfaceCode : uint32_t {
REGISTER_DSCHED_EVENT_LISTENER = 262,
UNREGISTER_DSCHED_EVENT_LISTENER = 263,
GET_CONTINUE_INFO = 264,
GET_DSCHED_EVENT_INFO = 265,
// request code for set continue state
SET_MISSION_CONTINUE_STATE = 300,

View File

@ -61,6 +61,21 @@ bool BundleManagerInternal::GetCallerAppIdFromBms(const std::string& bundleName,
return true;
}
bool BundleManagerInternal::GetSpecifyBundleNameFromBms(int32_t callingUid, std::string& bundleName)
{
auto bundleMgr = GetBundleManager();
if (bundleMgr == nullptr) {
HILOGE("failed to get bms");
return false;
}
bool result = bundleMgr->GetBundleNameForUid(callingUid, bundleName);
if (!result) {
HILOGE("Get specify bundle name for uid failed, result: %{public}d", result);
return false;
}
return result;
}
bool BundleManagerInternal::GetBundleNameListFromBms(int32_t callingUid, std::vector<std::string>& bundleNameList)
{
auto bundleMgr = GetBundleManager();
@ -70,7 +85,7 @@ bool BundleManagerInternal::GetBundleNameListFromBms(int32_t callingUid, std::ve
}
bool result = bundleMgr->GetBundlesForUid(callingUid, bundleNameList);
if (!result) {
HILOGE("GetBundlesForUid failed, result: %{public}d", result);
HILOGE("Get bundle name list for userId which the uid belongs failed, result: %{public}d", result);
return false;
}
return result;
@ -81,7 +96,7 @@ bool BundleManagerInternal::GetBundleNameListFromBms(int32_t callingUid,
{
std::vector<std::string> bundleNameList;
if (!GetBundleNameListFromBms(callingUid, bundleNameList)) {
HILOGE("GetBundleNameListFromBms failed");
HILOGE("Get bundle name list for userId which the uid belongs failed.");
return false;
}
for (const std::string& bundleName : bundleNameList) {

View File

@ -0,0 +1,153 @@
/*
* Copyright (c) 2024 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 "dsched_collaborate_callback_mgr.h"
#include "distributed_sched_service.h"
#include "dtbschedmgr_log.h"
#include "parcel_helper.h"
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DSchedCollaborationCallbackMgr";
const std::u16string DSCHED_EVENT_TOKEN = u"ohos.distributedSchedule.dschedeventlistener";
constexpr int32_t DSCHED_EVENT_CALLBACK = 0;
}
void DSchedCollaborationCallbackMgr::Init()
{
diedListener_ = new DistributedEventDiedListener();
}
bool DSchedCollaborationCallbackMgr::PushCallback(const sptr<IRemoteObject>& callback)
{
HILOGI("DSchedCollaborationCallbackMgr PushCallback start!");
if (diedListener_ == nullptr) {
HILOGE("DSchedCollaborationCallbackMgr is not init!");
return false;
}
if (callback == nullptr) {
HILOGE("callback null!");
return false;
}
std::lock_guard<std::mutex> autoLock(collaborateCbLock_);
std::vector<sptr<IRemoteObject>> vecCallback = collaborateCbArr_;
for (auto ele = collaborateCbArr_.begin(); ele != collaborateCbArr_.end(); ++ele) {
if ((*ele) == callback) {
HILOGW("callback already exists!");
return false;
}
}
collaborateCbArr_.push_back(callback);
callback->AddDeathRecipient(diedListener_);
std::vector<EventNotify> events;
if (DistributedSchedService::GetInstance().GetDSchedEventInfo(DMS_COLLABORATION, events) != ERR_OK) {
HILOGE("GetDSchedEventInfo fail, events size %{public}zu", events.size());
}
for (const auto &event : events) {
int32_t dSchedEventresult = NotifyDSchedEventForOneCB(callback, event);
if (dSchedEventresult != ERR_OK) {
HILOGE("Push continuation success, notify dms event result: %{public}d", dSchedEventresult);
}
}
return true;
}
std::vector<sptr<IRemoteObject>> DSchedCollaborationCallbackMgr::GetCallback()
{
std::lock_guard<std::mutex> autoLock(collaborateCbLock_);
return collaborateCbArr_;
}
bool DSchedCollaborationCallbackMgr::CleanupCallback(const sptr<IRemoteObject>& callback)
{
std::lock_guard<std::mutex> autoLock(collaborateCbLock_);
if (collaborateCbArr_.empty()) {
HILOGE("No need for cleaning!");
return false;
}
for (auto ele = collaborateCbArr_.begin(); ele != collaborateCbArr_.end(); ++ele) {
if ((*ele) == callback) {
collaborateCbArr_.erase(ele);
HILOGI("callback is exists, cleared successfully.");
return true;
}
}
HILOGI("callback is not exists!");
return false;
}
int32_t DSchedCollaborationCallbackMgr::NotifyDSchedEventForOneCB(const sptr<IRemoteObject> &cb,
const EventNotify& event)
{
if (cb == nullptr) {
HILOGE("NotifyDSchedEventForOneCB input callback is null.");
return INVALID_PARAMETERS_ERR;
}
MessageParcel data;
if (!data.WriteInterfaceToken(DSCHED_EVENT_TOKEN)) {
HILOGE("NotifyDSchedEventForOneCB write token failed");
return SEND_REQUEST_DEF_FAIL;
}
PARCEL_WRITE_HELPER_RET(data, Int32, event.eventResult_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, event.srcNetworkId_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, event.dstNetworkId_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, event.srcBundleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, event.srcModuleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, event.srcAbilityName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, event.destBundleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, event.destModuleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, event.destAbilityName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, Int32, event.dSchedEventType_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, Int32, event.state_, SEND_REQUEST_DEF_FAIL);
MessageParcel reply;
MessageOption option;
int32_t ret = cb->SendRequest(DSCHED_EVENT_CALLBACK, data, reply, option);
HILOGI("NotifyDSchedEventListenerResult transact end, ret: %{public}d.", ret);
return ret;
}
int32_t DSchedCollaborationCallbackMgr::NotifyDSchedEventResult(int32_t resultCode, const EventNotify& event)
{
HILOGI("GetCallback IDSchedEventListener");
std::vector<sptr<IRemoteObject>> vecCallback = GetCallback();
if (vecCallback.empty()) {
HILOGD("No listening has been registered, no need to report events");
return INVALID_PARAMETERS_ERR;
}
bool isAllSuc = true;
for (auto callback = vecCallback.begin(); callback != vecCallback.end(); ++callback) {
int32_t ret = NotifyDSchedEventForOneCB(*callback, event);
if (ret != ERR_OK) {
HILOGE("NotifyDSchedEventForOneCB transact fail, ret: %{public}d", ret);
isAllSuc = isAllSuc && false;
}
}
if (!isAllSuc) {
HILOGE("NotifyDSchedEventListenerResult transact fail, isAllSuc: %{public}d", isAllSuc);
return SEND_REQUEST_DEF_FAIL;
}
HILOGI("NotifyDSchedEventResult transact ok.");
return ERR_OK;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -137,17 +137,17 @@ void DSchedContinue::SetEventData()
ContinueEventInfo dstContinueInfo;
DmsBmStorage::GetInstance()->GetContinueEventInfo(continueInfo_.sinkDeviceId_, continueInfo_.sinkBundleName_,
continueInfo_.continueType_, dstContinueInfo);
eventData_.eventResult = 0;
eventData_.srcNetworkId = srcContinueInfo.networkId;
eventData_.srcBundleName = srcContinueInfo.bundleName;
eventData_.srcModuleName = srcContinueInfo.moduleName;
eventData_.srcAbilityName = srcContinueInfo.abilityName;
eventData_.dstNetworkId = dstContinueInfo.networkId;
eventData_.destBundleName = dstContinueInfo.bundleName;
eventData_.destModuleName = dstContinueInfo.moduleName;
eventData_.destAbilityName = dstContinueInfo.abilityName;
eventData_.dSchedEventType = DMS_CONTINUE;
eventData_.state = DMS_DSCHED_EVENT_START;
eventData_.eventResult_ = 0;
eventData_.srcNetworkId_ = srcContinueInfo.networkId;
eventData_.srcBundleName_ = srcContinueInfo.bundleName;
eventData_.srcModuleName_ = srcContinueInfo.moduleName;
eventData_.srcAbilityName_ = srcContinueInfo.abilityName;
eventData_.dstNetworkId_ = dstContinueInfo.networkId;
eventData_.destBundleName_ = dstContinueInfo.bundleName;
eventData_.destModuleName_ = dstContinueInfo.moduleName;
eventData_.destAbilityName_ = dstContinueInfo.abilityName;
eventData_.dSchedEventType_ = DMS_CONTINUE;
eventData_.state_ = DMS_DSCHED_EVENT_START;
}
int32_t DSchedContinue::Init()
@ -865,19 +865,6 @@ int32_t DSchedContinue::ExecuteContinueData(std::shared_ptr<DSchedContinueDataCm
return ret;
}
void DSchedContinue::DurationDumperBeforeStartAbility(std::shared_ptr<DSchedContinueDataCmd> cmd)
{
if (subServiceType_ == CONTINUE_PULL) {
std::string timeInfo = cmd->want_.GetStringParam(DMSDURATION_SAVETIME);
DmsContinueTime::GetInstance().ReadDurationInfo(timeInfo.c_str());
DmsContinueTime::GetInstance().SetSrcBundleName(cmd->want_.GetElement().GetBundleName());
DmsContinueTime::GetInstance().SetSrcAbilityName(cmd->want_.GetElement().GetAbilityName());
DmsContinueTime::GetInstance().SetDstBundleName(cmd->want_.GetElement().GetBundleName());
DmsContinueTime::GetInstance().SetDstAbilityName(cmd->want_.GetElement().GetAbilityName());
}
DmsContinueTime::GetInstance().SetDurationBegin(CONTINUE_START_ABILITY_TIME, GetTickCount());
}
int32_t DSchedContinue::UpdateWantForContinueType(OHOS::AAFwk::Want& want)
{
std::string srcAbilityName = want.GetElement().GetAbilityName();
@ -893,6 +880,19 @@ int32_t DSchedContinue::UpdateWantForContinueType(OHOS::AAFwk::Want& want)
return ERR_OK;
}
void DSchedContinue::DurationDumperBeforeStartAbility(std::shared_ptr<DSchedContinueDataCmd> cmd)
{
if (subServiceType_ == CONTINUE_PULL) {
std::string timeInfo = cmd->want_.GetStringParam(DMSDURATION_SAVETIME);
DmsContinueTime::GetInstance().ReadDurationInfo(timeInfo.c_str());
DmsContinueTime::GetInstance().SetSrcBundleName(cmd->want_.GetElement().GetBundleName());
DmsContinueTime::GetInstance().SetSrcAbilityName(cmd->want_.GetElement().GetAbilityName());
DmsContinueTime::GetInstance().SetDstBundleName(cmd->want_.GetElement().GetBundleName());
DmsContinueTime::GetInstance().SetDstAbilityName(cmd->want_.GetElement().GetAbilityName());
}
DmsContinueTime::GetInstance().SetDurationBegin(CONTINUE_START_ABILITY_TIME, GetTickCount());
}
bool DSchedContinue::WaitAbilityStateInitial(int32_t persistentId)
{
int32_t retryTimeout = GET_ABILITY_STATE_RETRY_TIMES;
@ -1011,9 +1011,9 @@ int32_t DSchedContinue::ExecuteContinueEnd(int32_t result)
}
if (result != ERR_OK) {
eventData_.state = DMS_DSCHED_EVENT_STOP;
eventData_.state_ = DMS_DSCHED_EVENT_STOP;
} else {
eventData_.state = DMS_DSCHED_EVENT_FINISH;
eventData_.state_ = DMS_DSCHED_EVENT_FINISH;
}
if (result == ERR_OK && direction_ == CONTINUE_SOURCE && isSourceExit_) {
int32_t ret = AbilityManagerClient::GetInstance()->CleanMission(continueInfo_.missionId_);

View File

@ -174,6 +174,11 @@ bool DSchedContinuation::PushCallback(const sptr<IRemoteObject>& callback)
}
continuationCallbackArr_.push_back(callback);
callback->AddDeathRecipient(diedListener_);
int dSchedEventresult = NotifyDSchedEventForOneCB(callback, ERR_OK);
if (dSchedEventresult != ERR_OK) {
HILOGE("Push continuation success, notify dms event result: %{public}d.", dSchedEventresult);
}
return true;
}
@ -255,6 +260,37 @@ sptr<IRemoteObject> DSchedContinuation::PopCallback(int32_t missionId)
return callback;
}
int32_t DSchedContinuation::NotifyDSchedEventForOneCB(const sptr<IRemoteObject> &cb, int32_t resultCode)
{
if (cb == nullptr) {
HILOGE("NotifyDSchedEventForOneCB input callback is null.");
return INVALID_PARAMETERS_ERR;
}
MessageParcel data;
if (!data.WriteInterfaceToken(DSCHED_EVENT_TOKEN)) {
HILOGE("NotifyDSchedEventForOneCB write token failed");
return SEND_REQUEST_DEF_FAIL;
}
PARCEL_WRITE_HELPER_RET(data, Int32, resultCode, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcNetworkId_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.dstNetworkId_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcBundleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcModuleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcAbilityName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destBundleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destModuleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destAbilityName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, Int32, continueEvent_.dSchedEventType_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, Int32, continueEvent_.state_, SEND_REQUEST_DEF_FAIL);
MessageParcel reply;
MessageOption option;
int32_t ret = cb->SendRequest(DSCHED_EVENT_CALLBACK, data, reply, option);
HILOGI("NotifyDSchedEventListenerResult transact end, ret: %{public}d.", ret);
return ret;
}
int32_t DSchedContinuation::NotifyDSchedEventResult(int32_t resultCode)
{
HILOGI("GetCallback IDSchedEventListener");
@ -263,31 +299,20 @@ int32_t DSchedContinuation::NotifyDSchedEventResult(int32_t resultCode)
HILOGD("No listening has been registered, no need to report events");
return INVALID_PARAMETERS_ERR;
}
int32_t error = -1;
bool isAllSuc = true;
for (auto callback = vecCallback.begin(); callback != vecCallback.end(); ++callback) {
MessageParcel data;
if (!data.WriteInterfaceToken(DSCHED_EVENT_TOKEN)) {
HILOGE("NotifyMissionCenterResult write token failed");
return INVALID_PARAMETERS_ERR;
int32_t ret = NotifyDSchedEventForOneCB(*callback, resultCode);
if (ret != ERR_OK) {
HILOGE("NotifyDSchedEventForOneCB transact fail, ret: %{public}d", ret);
isAllSuc = isAllSuc && false;
}
PARCEL_WRITE_HELPER_RET(data, Int32, resultCode, false);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcNetworkId, false);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.dstNetworkId, false);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcBundleName, false);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcModuleName, false);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.srcAbilityName, false);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destBundleName, false);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destModuleName, false);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destAbilityName, false);
PARCEL_WRITE_HELPER_RET(data, Int32, continueEvent_.dSchedEventType, false);
PARCEL_WRITE_HELPER_RET(data, Int32, continueEvent_.state, false);
MessageParcel reply;
MessageOption option;
error = (*callback)->SendRequest(DSCHED_EVENT_CALLBACK, data, reply, option);
HILOGI("NotifyDSchedEventListenerResult transact result: %{public}d", error);
}
return error;
if (!isAllSuc) {
HILOGE("NotifyDSchedEventListenerResult transact fail, isAllSuc: %{public}d", isAllSuc);
return SEND_REQUEST_DEF_FAIL;
}
HILOGI("NotifyDSchedEventResult transact ok.");
return ERR_OK;
}
int32_t DSchedContinuation::NotifyMissionCenterResult(int32_t missionId, int32_t resultCode)

View File

@ -203,7 +203,6 @@ bool DistributedSchedPermission::GetRelatedGroups(const std::string& udid,
}
}
}
if (accountInfo.groupIdList.empty()) {
HILOGE("groupIdList is empty");
return false;

View File

@ -37,6 +37,7 @@ const std::string EXTRO_INFO_JSON_KEY_ACCESS_TOKEN = "accessTokenID";
const std::string EXTRO_INFO_JSON_KEY_REQUEST_CODE = "requestCode";
const std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles";
const std::string DMS_VERSION_ID = "dmsVersion";
const std::string DMS_UID_SPEC_BUNDLE_NAME = "dmsCallerUidBundleName";
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
constexpr int32_t WAIT_TIME = 15;
#endif
@ -511,7 +512,7 @@ int32_t DistributedSchedProxy::RegisterMissionListener(const std::u16string& dev
data, reply);
}
int32_t DistributedSchedProxy::RegisterDSchedEventListener(const uint8_t& type,
int32_t DistributedSchedProxy::RegisterDSchedEventListener(const DSchedEventType& type,
const sptr<IRemoteObject>& obj)
{
HILOGI("RegisterDSchedEventListener called");
@ -531,7 +532,7 @@ int32_t DistributedSchedProxy::RegisterDSchedEventListener(const uint8_t& type,
data, reply);
}
int32_t DistributedSchedProxy::UnRegisterDSchedEventListener(const uint8_t& type,
int32_t DistributedSchedProxy::UnRegisterDSchedEventListener(const DSchedEventType& type,
const sptr<IRemoteObject>& obj)
{
HILOGI("UnRegisterDSchedEventListener called");
@ -822,6 +823,10 @@ int32_t DistributedSchedProxy::StartAbilityByCallFromRemote(const OHOS::AAFwk::W
if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
}
if (callerInfo.extraInfoJson.find(DMS_UID_SPEC_BUNDLE_NAME) != callerInfo.extraInfoJson.end()) {
extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME] = callerInfo.extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME];
}
std::string extraInfo = extraInfoJson.dump();
PARCEL_WRITE_HELPER(data, String, extraInfo);
DistributedWant dstbWant(want);

View File

@ -15,6 +15,7 @@
#include "distributed_sched_service.h"
#include <algorithm>
#include <cinttypes>
#include <unistd.h>
@ -98,6 +99,7 @@ const std::string DEVICE_TYPE_KEY = "deviceType";
const std::string CHANGE_TYPE_KEY = "changeType";
const std::string DMS_HIPLAY_ACTION = "ohos.ability.action.deviceSelect";
const std::string DMS_VERSION_ID = "dmsVersion";
const std::string DMS_UID_SPEC_BUNDLE_NAME = "dmsCallerUidBundleName";
const std::string DMS_CONNECT_TOKEN = "connectToken";
const std::string DMS_MISSION_ID = "dmsMissionId";
const std::string SUPPORT_CONTINUE_PAGE_STACK_KEY = "ohos.extra.param.key.supportContinuePageStack";
@ -130,6 +132,7 @@ constexpr int32_t DMSDURATION_TOTALTIME = 2;
constexpr int32_t DMSDURATION_DSTTOSRCRPCTIME = 3;
constexpr int32_t DMSDURATION_SRCTODSTRPCTIME = 5;
constexpr int32_t DMSDURATION_STARTABILITY = 6;
constexpr int32_t HID_HAP = 10000; /* first hap user */
static const std::string CONTINUE_SWITCH_STATUS_KEY = "Continue_Switch_Status";
}
@ -160,8 +163,10 @@ void DistributedSchedService::OnStart()
NotifyCompleteFreeInstallFromRemote(taskId, AAFwk::FREE_INSTALL_TIMEOUT);
};
dschedContinuation_ = std::make_shared<DSchedContinuation>();
collaborateCbMgr_ = std::make_shared<DSchedCollaborationCallbackMgr>();
dmsCallbackTask_ = std::make_shared<DmsCallbackTask>();
dschedContinuation_->Init(continuationCallback);
collaborateCbMgr_->Init();
dmsCallbackTask_->Init(freeCallback);
HILOGI("OnStart start service success.");
Publish(this);
@ -672,8 +677,8 @@ int32_t DistributedSchedService::ProcessContinueLocalMission(const std::string&
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
dschedContinuation_->continueEvent_.srcNetworkId = srcDeviceId;
dschedContinuation_->continueEvent_.dstNetworkId = dstDeviceId;
dschedContinuation_->continueEvent_.srcNetworkId_ = srcDeviceId;
dschedContinuation_->continueEvent_.dstNetworkId_ = dstDeviceId;
return ContinueLocalMission(dstDeviceId, missionId, callback, wantParams);
}
@ -690,8 +695,8 @@ int32_t DistributedSchedService::ProcessContinueRemoteMission(const std::string&
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
dschedContinuation_->continueEvent_.srcNetworkId = dstDeviceId;
dschedContinuation_->continueEvent_.dstNetworkId = srcDeviceId;
dschedContinuation_->continueEvent_.srcNetworkId_ = dstDeviceId;
dschedContinuation_->continueEvent_.dstNetworkId_ = srcDeviceId;
HILOGI("ProcessContinueRemoteMission end.");
return ContinueRemoteMission(srcDeviceId, dstDeviceId, bundleName, callback, wantParams);
}
@ -761,7 +766,7 @@ int32_t DistributedSchedService::DealDSchedEventResult(const OHOS::AAFwk::Want&
return INVALID_PARAMETERS_ERR;
}
DmsContinueTime::GetInstance().SetSrcBundleName(want.GetElement().GetBundleName());
DmsContinueTime::GetInstance().SetSrcAbilityName(dschedContinuation_->continueEvent_.srcAbilityName);
DmsContinueTime::GetInstance().SetSrcAbilityName(dschedContinuation_->continueEvent_.srcAbilityName_);
if (status != ERR_OK) {
HILOGD("want.GetElement().GetDeviceId result:%{public}s", want.GetElement().GetDeviceID().c_str());
std::string deviceId = want.GetElement().GetDeviceID();
@ -862,8 +867,8 @@ void DistributedSchedService::NotifyCompleteContinuation(const std::u16string& d
int dSchedEventresult = dschedContinuation_->NotifyDSchedEventResult(ERR_OK);
HILOGD("NotifyDSchedEventResult result:%{public}d", dSchedEventresult);
remoteDms->NotifyContinuationResultFromRemote(sessionId, isSuccess, dstInfo);
dschedContinuation_->continueInfo_.srcNetworkId = "";
dschedContinuation_->continueInfo_.dstNetworkId = "";
dschedContinuation_->continueInfo_.srcNetworkId_ = "";
dschedContinuation_->continueInfo_.dstNetworkId_ = "";
}
int32_t DistributedSchedService::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess,
@ -884,8 +889,8 @@ int32_t DistributedSchedService::NotifyContinuationResultFromRemote(int32_t sess
int32_t missionId = sessionId;
NotifyContinuationCallbackResult(missionId, isSuccess ? 0 : NOTIFYCOMPLETECONTINUATION_FAILED);
dschedContinuation_->continueInfo_.srcNetworkId = "";
dschedContinuation_->continueInfo_.dstNetworkId = "";
dschedContinuation_->continueInfo_.srcNetworkId_ = "";
dschedContinuation_->continueInfo_.dstNetworkId_ = "";
return ERR_OK;
}
@ -984,6 +989,21 @@ void DistributedSchedService::NotifyDSchedEventCallbackResult(int32_t resultCode
void DistributedSchedService::NotifyDSchedEventCallbackResult(int32_t resultCode, const EventNotify& event)
{
HILOGD("Continuation result is: %{public}d", resultCode);
switch (event.dSchedEventType_) {
case DMS_CONTINUE:
NotifyContinuateEventResult(resultCode, event);
break;
case DMS_COLLABORATION:
NotifyCollaborateEventResult(resultCode, event);
break;
default:
HILOGE("Event does not carry specific operation type, eventType %{public}d.", event.dSchedEventType_);
return;
}
}
void DistributedSchedService::NotifyContinuateEventResult(int32_t resultCode, const EventNotify& event)
{
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return;
@ -991,7 +1011,74 @@ void DistributedSchedService::NotifyDSchedEventCallbackResult(int32_t resultCode
dschedContinuation_->continueEvent_ = event;
int dSchedEventresult = dschedContinuation_->NotifyDSchedEventResult(resultCode);
HILOGD("NotifyDSchedEventResult result:%{public}d", dSchedEventresult);
dschedContinuation_->continueEvent_ = EventNotify();
if (event.state_ == DMS_DSCHED_EVENT_FINISH || resultCode != ERR_OK) {
dschedContinuation_->continueEvent_ = EventNotify();
}
}
void DistributedSchedService::NotifyCollaborateEventResult(int32_t resultCode, const EventNotify& event)
{
if (collaborateCbMgr_ == nullptr) {
HILOGE("collaborate callback manager is null.");
return;
}
int32_t collaborateEventRet = collaborateCbMgr_->NotifyDSchedEventResult(resultCode, event);
HILOGD("NotifyDSchedEventResult result: %{public}d", collaborateEventRet);
}
void DistributedSchedService::NotifyCollaborateEventWithSessions(
const std::list<ConnectAbilitySession> &sessionsList, DSchedEventState state, int32_t ret)
{
for (const auto &session : sessionsList) {
for (const auto &element : session.GetElementsList()) {
EventNotify tempEvent;
GetCurSrcCollaborateEvent(session.GetCallerInfo(), element, state, ret, tempEvent);
NotifyDSchedEventCallbackResult(ret, tempEvent);
}
}
}
void DistributedSchedService::GetCurSrcCollaborateEvent(const CallerInfo &callerInfo,
const AppExecFwk::ElementName &element, DSchedEventState state, int32_t ret, EventNotify &event)
{
std::string callingBundleName;
if (!BundleManagerInternal::GetSpecifyBundleNameFromBms(callerInfo.uid, callingBundleName)) {
HILOGE("Get specify bundle name for from Bms fail, connect session caller uid %{public}d.", callerInfo.uid);
}
event.eventResult_ = ret;
event.srcNetworkId_ = callerInfo.sourceDeviceId;
event.dstNetworkId_ = element.GetDeviceID();
event.srcBundleName_ = callingBundleName;
event.srcModuleName_ = "";
event.srcAbilityName_ = "";
event.destBundleName_ = element.GetBundleName();
event.destModuleName_ = element.GetModuleName();
event.destAbilityName_ = element.GetAbilityName();
event.dSchedEventType_ = DMS_COLLABORATION;
event.state_ = state;
}
void DistributedSchedService::GetCurDestCollaborateEvent(const CallerInfo &callerInfo,
const AppExecFwk::ElementName &element, DSchedEventState state, int32_t ret, EventNotify &event)
{
std::string callerBundleName;
if (callerInfo.extraInfoJson.find(DMS_UID_SPEC_BUNDLE_NAME) != callerInfo.extraInfoJson.end() &&
callerInfo.extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME].is_string()) {
callerBundleName = callerInfo.extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME];
}
event.eventResult_ = ret;
event.srcNetworkId_ = callerInfo.sourceDeviceId;
event.dstNetworkId_ = element.GetDeviceID();
event.srcBundleName_ = callerBundleName;
event.srcModuleName_ = "";
event.srcAbilityName_ = "";
event.destBundleName_ = element.GetBundleName();
event.destModuleName_ = element.GetModuleName();
event.destAbilityName_ = element.GetAbilityName();
event.dSchedEventType_ = DMS_COLLABORATION;
event.state_ = state;
}
void DistributedSchedService::RemoteConnectAbilityMappingLocked(const sptr<IRemoteObject>& connect,
@ -1156,15 +1243,21 @@ void DistributedSchedService::ProcessCallerDied(const sptr<IRemoteObject>& conne
return;
}
sptr<IRemoteObject> callbackWrapper = connect;
CallerInfo callerInfo;
AppExecFwk::ElementName element;
EventNotify tempEvent;
{
std::lock_guard<std::mutex> autoLock(calleeLock_);
auto itConnect = calleeMap_.find(connect);
if (itConnect != calleeMap_.end()) {
callbackWrapper = itConnect->second.callbackWrapper;
element = itConnect->second.element;
callerInfo = itConnect->second.callerInfo;
ReportDistributedComponentChange(itConnect->second, DISTRIBUTED_COMPONENT_REMOVE,
IDistributedSched::CALL, IDistributedSched::CALLEE);
GetCurDestCollaborateEvent(callerInfo, element, DMS_DSCHED_EVENT_STOP, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
calleeMap_.erase(itConnect);
} else {
HILOGW("ProcessCallerDied connect not found");
@ -1175,6 +1268,8 @@ void DistributedSchedService::ProcessCallerDied(const sptr<IRemoteObject>& conne
if (result != ERR_OK) {
HILOGW("ProcessCallerDied failed, error: %{public}d", result);
}
GetCurDestCollaborateEvent(callerInfo, element, DMS_DSCHED_EVENT_FINISH, result, tempEvent);
NotifyDSchedEventCallbackResult(result, tempEvent);
}
void DistributedSchedService::HandleLocalCallerDied(const sptr<IRemoteObject>& connect)
@ -1188,6 +1283,7 @@ void DistributedSchedService::HandleLocalCallerDied(const sptr<IRemoteObject>& c
ReportDistributedComponentChange(sessionsList.front().GetCallerInfo(), DISTRIBUTED_COMPONENT_REMOVE,
IDistributedSched::CALL, IDistributedSched::CALLER);
}
NotifyCollaborateEventWithSessions(sessionsList, DMS_DSCHED_EVENT_FINISH, ERR_OK);
callerMap_.erase(it);
HILOGI("remove connection success");
} else {
@ -1213,6 +1309,9 @@ void DistributedSchedService::ProcessCalleeDied(const sptr<IRemoteObject>& conne
return;
}
sptr<IRemoteObject> callbackWrapper;
CallerInfo callerInfo;
AppExecFwk::ElementName element;
EventNotify tempEvent;
{
std::lock_guard<std::mutex> autoLock(calleeLock_);
auto itConnect = calleeMap_.find(connect);
@ -1220,13 +1319,20 @@ void DistributedSchedService::ProcessCalleeDied(const sptr<IRemoteObject>& conne
ReportDistributedComponentChange(itConnect->second, DISTRIBUTED_COMPONENT_REMOVE,
IDistributedSched::CALL, IDistributedSched::CALLEE);
callbackWrapper = itConnect->second.callbackWrapper;
callerInfo = itConnect->second.callerInfo;
element = itConnect->second.element;
calleeMap_.erase(itConnect);
} else {
HILOGW("ProcessCalleeDied connect not found");
return;
}
}
GetCurDestCollaborateEvent(callerInfo, element, DMS_DSCHED_EVENT_STOP, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
UnregisterAppStateObserver(callbackWrapper);
GetCurDestCollaborateEvent(callerInfo, element, DMS_DSCHED_EVENT_FINISH, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
}
void DistributedSchedService::ProcessCallResult(const sptr<IRemoteObject>& calleeConnect,
@ -1301,7 +1407,11 @@ void DistributedSchedService::SaveCallerComponent(const OHOS::AAFwk::Want& want,
// connect to another remote device, add a new session to list
auto& session = sessionsList.emplace_back(callerInfo.sourceDeviceId, remoteDeviceId, callerInfo);
session.AddElement(want.GetElement());
HILOGD("add connection success");
EventNotify tempEvent;
GetCurSrcCollaborateEvent(callerInfo, want.GetElement(), DMS_DSCHED_EVENT_PROCESSING, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
}
void DistributedSchedService::RemoveCallerComponent(const sptr<IRemoteObject>& connect)
@ -1316,6 +1426,7 @@ void DistributedSchedService::RemoveCallerComponent(const sptr<IRemoteObject>& c
ReportDistributedComponentChange(sessionsList.front().GetCallerInfo(), DISTRIBUTED_COMPONENT_REMOVE,
IDistributedSched::CALL, IDistributedSched::CALLER);
}
NotifyCollaborateEventWithSessions(sessionsList, DMS_DSCHED_EVENT_FINISH, ERR_OK);
callerMap_.erase(it);
HILOGI("remove connection success");
} else {
@ -1346,6 +1457,11 @@ void DistributedSchedService::ProcessCalleeOffline(const std::string& deviceId)
CallerInfo callerInfo;
if (itSession != sessionsList.end()) {
callerInfo = itSession->GetCallerInfo();
for (const auto &element : itSession->GetElementsList()) {
EventNotify tempEvent;
GetCurSrcCollaborateEvent(callerInfo, element, DMS_DSCHED_EVENT_FINISH, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
}
sessionsList.erase(itSession);
}
@ -1418,6 +1534,16 @@ int32_t DistributedSchedService::StartRemoteAbilityByCall(const OHOS::AAFwk::Wan
return INVALID_PARAMETERS_ERR;
}
callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
std::string uidSpecBundleName;
if (!BundleManagerInternal::GetSpecifyBundleNameFromBms(callerInfo.uid, uidSpecBundleName)) {
HILOGE("Get specify bundle name for from Bms fail, connect session caller uid %{public}d.", callerInfo.uid);
}
callerInfo.extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME] = uidSpecBundleName;
EventNotify tempEvent;
GetCurSrcCollaborateEvent(callerInfo, want.GetElement(), DMS_DSCHED_EVENT_START, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
int32_t ret = TryStartRemoteAbilityByCall(want, connect, callerInfo);
if (ret != ERR_OK) {
{
@ -1468,6 +1594,11 @@ int32_t DistributedSchedService::StartAbilityByCallFromRemote(const OHOS::AAFwk:
HILOGE("StartAbilityByCallFromRemote connect is null");
return INVALID_REMOTE_PARAMETERS_ERR;
}
EventNotify tempEvent;
GetCurDestCollaborateEvent(callerInfo, want.GetElement(), DMS_DSCHED_EVENT_START, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
std::string localDeviceId;
std::string destinationDeviceId = want.GetElement().GetDeviceID();
if (!GetLocalDeviceId(localDeviceId) ||
@ -1506,6 +1637,9 @@ int32_t DistributedSchedService::StartAbilityByCallFromRemote(const OHOS::AAFwk:
HILOGE("RegisterAppStateObserver failed");
}
}
GetCurDestCollaborateEvent(callerInfo, want.GetElement(), DMS_DSCHED_EVENT_PROCESSING, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
return errCode;
}
@ -1516,6 +1650,9 @@ int32_t DistributedSchedService::ReleaseAbilityFromRemote(const sptr<IRemoteObje
HILOGE("ReleaseAbilityFromRemote connect is null");
return INVALID_REMOTE_PARAMETERS_ERR;
}
EventNotify tempEvent;
GetCurDestCollaborateEvent(callerInfo, element, DMS_DSCHED_EVENT_STOP, ERR_OK, tempEvent);
NotifyDSchedEventCallbackResult(ERR_OK, tempEvent);
HILOGD("[PerformanceTest] ReleaseAbilityFromRemote begin");
std::string localDeviceId;
@ -1545,6 +1682,8 @@ int32_t DistributedSchedService::ReleaseAbilityFromRemote(const sptr<IRemoteObje
if (result != ERR_OK) {
HILOGE("ReleaseAbilityFromRemote failed, error: %{public}d", result);
}
GetCurDestCollaborateEvent(callerInfo, element, DMS_DSCHED_EVENT_FINISH, result, tempEvent);
NotifyDSchedEventCallbackResult(result, tempEvent);
return result;
}
@ -2273,80 +2412,6 @@ int32_t DistributedSchedService::RegisterMissionListener(const std::u16string& d
return DistributedSchedMissionManager::GetInstance().RegisterMissionListener(devId, obj);
}
int32_t DistributedSchedService::RegisterDSchedEventListener(const uint8_t& type,
const sptr<IRemoteObject>& callback)
{
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
int32_t result = 0;
switch (type) {
case DMS_CONTINUE:
result = dschedContinuation_->PushCallback(callback);
break;
case DMS_COLLABRATION:
break;
case DMS_ALL:
result = dschedContinuation_->PushCallback(callback);
break;
default:
break;
}
if (!result) {
HILOGI("The callback does not exist,type: %{public}d", type);
} else {
HILOGI("Pushing the callback succeeded.");
}
NotifyDSchedEventCallbackResult(dschedContinuation_->continueEvent_.eventResult,
dschedContinuation_->continueEvent_);
return result;
}
int32_t DistributedSchedService::UnRegisterDSchedEventListener(const uint8_t& type,
const sptr<IRemoteObject>& callback)
{
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
bool result = 0;
switch (type) {
case DMS_CONTINUE:
result = dschedContinuation_->CleanupCallback(callback);
break;
case DMS_COLLABRATION:
break;
case DMS_ALL:
result = dschedContinuation_->CleanupCallback(callback);
break;
default:
break;
}
if (!result) {
HILOGI("The callback does not exist,type: %{public}d", type);
} else {
HILOGI("Clearing the callback succeeded.");
}
return 0;
}
int32_t DistributedSchedService::GetContinueInfo(std::string& dstNetworkId, std::string& srcNetworkId)
{
HILOGI("GetContinueInfo called");
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
dstNetworkId = dschedContinuation_->continueInfo_.dstNetworkId;
srcNetworkId = dschedContinuation_->continueInfo_.srcNetworkId;
HILOGI("GetContinueInfo dstNetworkId: %{public}s, srcNetworkId: %{public}s",
GetAnonymStr(dstNetworkId).c_str(), GetAnonymStr(srcNetworkId).c_str());
return 0;
}
int32_t DistributedSchedService::RegisterOnListener(const std::string& type,
const sptr<IRemoteObject>& obj)
{
@ -2393,6 +2458,192 @@ int32_t DistributedSchedService::SetMissionContinueState(int32_t missionId, cons
}
#endif
int32_t DistributedSchedService::RegisterDSchedEventListener(const DSchedEventType& type,
const sptr<IRemoteObject>& callback)
{
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
bool ret = false;
switch (type) {
case DMS_CONTINUE:
ret = dschedContinuation_->PushCallback(callback);
break;
case DMS_COLLABORATION:
ret = collaborateCbMgr_->PushCallback(callback);
break;
case DMS_ALL:
ret = dschedContinuation_->PushCallback(callback) && collaborateCbMgr_->PushCallback(callback);
break;
default:
HILOGE("Not support register Dms event listener with event type: %{public}d.", type);
return INVALID_PARAMETERS_ERR;
}
if (!ret) {
HILOGE("The callback does not exist, type: %{public}d", type);
return CALLBACK_HAS_NOT_REGISTERED;
}
HILOGD("Push %{public}d callback success.", type);
return ERR_OK;
}
int32_t DistributedSchedService::UnRegisterDSchedEventListener(const DSchedEventType& type,
const sptr<IRemoteObject>& callback)
{
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
bool result = 0;
switch (type) {
case DMS_CONTINUE:
result = dschedContinuation_->CleanupCallback(callback);
break;
case DMS_COLLABORATION:
break;
case DMS_ALL:
result = dschedContinuation_->CleanupCallback(callback);
break;
default:
break;
}
if (!result) {
HILOGI("The callback does not exist,type: %{public}d", type);
} else {
HILOGI("Clearing the callback succeeded.");
}
return 0;
}
int32_t DistributedSchedService::GetContinueInfo(std::string& dstNetworkId, std::string& srcNetworkId)
{
HILOGI("GetContinueInfo called");
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
dstNetworkId = dschedContinuation_->continueInfo_.dstNetworkId_;
srcNetworkId = dschedContinuation_->continueInfo_.srcNetworkId_;
HILOGI("GetContinueInfo dstNetworkId: %{public}s, srcNetworkId: %{public}s",
GetAnonymStr(dstNetworkId).c_str(), GetAnonymStr(srcNetworkId).c_str());
return 0;
}
int32_t DistributedSchedService::GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events)
{
int32_t callingUid = CheckCallingUid() ? DEFAULT_REQUEST_CODE : IPCSkeleton::GetCallingUid();
HILOGI("GetDSchedEventInfo called, uid %{public}d, dms eventType %{public}d.", callingUid, type);
switch (type) {
case DMS_CONTINUE:
GetContinueEventInfo(callingUid, events);
break;
case DMS_COLLABORATION:
GetCollaborateEventInfo(callingUid, events);
break;
case DMS_ALL:
GetContinueEventInfo(callingUid, events);
GetCollaborateEventInfo(callingUid, events);
break;
default:
HILOGI("Get dms event info not support eventType %{public}d.", type);
return INVALID_PARAMETERS_ERR;
}
HILOGI("GetDSchedEventInfo end, uid %{public}d, eventType %{public}d, events size %{public}zu.",
callingUid, type, events.size());
return ERR_OK;
}
bool DistributedSchedService::CheckCallingUid()
{
// never allow non-system uid for distributed request
auto callingUid = IPCSkeleton::GetCallingUid();
return callingUid < HID_HAP;
}
void DistributedSchedService::GetContinueEventInfo(int32_t callingUid, std::vector<EventNotify> &events)
{
if (callingUid == DEFAULT_REQUEST_CODE) {
events.emplace_back(dschedContinuation_->continueEvent_);
return;
}
std::vector<std::string> bundleNames;
if (!BundleManagerInternal::GetBundleNameListFromBms(callingUid, bundleNames)) {
HILOGE("Get bundle name from Bms failed");
return;
}
for (const auto &bundleName : bundleNames) {
HILOGD("Get bundle name %{public}s from Bms.", bundleName.c_str());
if (bundleName == dschedContinuation_->continueEvent_.srcBundleName_ ||
bundleName == dschedContinuation_->continueEvent_.destBundleName_) {
events.emplace_back(dschedContinuation_->continueEvent_);
}
}
}
void DistributedSchedService::GetCollaborateEventInfo(int32_t callingUid, std::vector<EventNotify> &events)
{
if (callingUid == DEFAULT_REQUEST_CODE) {
GetCollaborateEventsByCallers(callingUid, "", events);
GetCollaborateEventsByCallees(callingUid, "", events);
return;
}
std::string callingBundleName;
if (!BundleManagerInternal::GetSpecifyBundleNameFromBms(callingUid, callingBundleName)) {
HILOGE("Get specify bundle name for from Bms fail, uid %{public}d.", callingUid);
return;
}
GetCollaborateEventsByCallers(callingUid, callingBundleName, events);
GetCollaborateEventsByCallees(callingUid, callingBundleName, events);
}
void DistributedSchedService::GetCollaborateEventsByCallers(int32_t callingUid, const std::string &callingBundleName,
std::vector<EventNotify> &events)
{
std::lock_guard<std::mutex> autoLock(callerLock_);
for (const auto &iter : callerMap_) {
for (const auto &connectSession : iter.second) {
auto bundleNames = connectSession.GetCallerInfo().bundleNames;
if (callingUid != DEFAULT_REQUEST_CODE && callingUid != connectSession.GetCallerInfo().uid &&
std::count(bundleNames.begin(), bundleNames.end(), callingBundleName) == 0) {
HILOGE("Connect session callerInfo uid %{public}d is different from callingUid %{public}d, "
"callingbundle %{public}s.", connectSession.GetCallerInfo().uid,
callingUid, callingBundleName.c_str());
continue;
}
for (const auto &element : connectSession.GetElementsList()) {
EventNotify tempEvent;
GetCurSrcCollaborateEvent(connectSession.GetCallerInfo(), element,
DMS_DSCHED_EVENT_PROCESSING, ERR_OK, tempEvent);
events.emplace_back(tempEvent);
}
}
}
}
void DistributedSchedService::GetCollaborateEventsByCallees(int32_t callingUid, const std::string &callingBundleName,
std::vector<EventNotify> &events)
{
std::lock_guard<std::mutex> autoLock(calleeLock_);
for (const auto &iter : calleeMap_) {
if (callingUid != DEFAULT_REQUEST_CODE && callingBundleName != iter.second.element.GetBundleName()) {
HILOGE("Connect session calleeInfo destBundleName %{public}s is different from "
"callingBundleName %{public}s, callingUid %{public}d.", iter.second.element.GetBundleName().c_str(),
callingBundleName.c_str(), callingUid);
continue;
}
EventNotify tempEvent;
GetCurDestCollaborateEvent(iter.second.callerInfo, iter.second.element,
DMS_DSCHED_EVENT_PROCESSING, ERR_OK, tempEvent);
events.emplace_back(tempEvent);
}
}
void CallerDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOGI("CallerDeathRecipient OnRemoteDied called");

View File

@ -29,6 +29,7 @@
#include "dfx/dms_hitrace_constants.h"
#include "distributed_want.h"
#include "distributed_sched_permission.h"
#include "distributed_sched_types.h"
#include "distributed_sched_utils.h"
#include "dms_version_manager.h"
#include "dsched_continue_manager.h"
@ -65,6 +66,7 @@ const std::string PARAM_FREEINSTALL_BUNDLENAMES = "ohos.freeinstall.params.calli
const std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles";
const std::string FEATURE_ABILITY_FLAG_KEY = "ohos.dms.faFlag";
const std::string DMS_VERSION_ID = "dmsVersion";
const std::string DMS_UID_SPEC_BUNDLE_NAME = "dmsCallerUidBundleName";
constexpr int32_t QOS_THRESHOLD_VERSION = 5;
const int DEFAULT_REQUEST_CODE = -1;
}
@ -92,6 +94,8 @@ void DistributedSchedStub::InitExtendedLocalFuncsInner()
&DistributedSchedStub::UnRegisterDSchedEventListenerInner;
localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::GET_CONTINUE_INFO)] =
&DistributedSchedStub::GetContinueInfoInner;
localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::GET_DSCHED_EVENT_INFO)] =
&DistributedSchedStub::GetDSchedEventInfoInner;
#endif
}
@ -348,11 +352,18 @@ void DistributedSchedStub::SaveExtraInfo(const nlohmann::json& extraInfoJson, Ca
callerInfo.accessToken = accessToken;
HILOGD("parse extra info, accessTokenID = %u", accessToken);
}
if (extraInfoJson.find(DMS_VERSION_ID) != extraInfoJson.end() && extraInfoJson[DMS_VERSION_ID].is_string()) {
std::string dmsVersion = extraInfoJson[DMS_VERSION_ID];
callerInfo.extraInfoJson[DMS_VERSION_ID] = dmsVersion;
HILOGD("save dms version");
}
if (extraInfoJson.find(DMS_UID_SPEC_BUNDLE_NAME) != extraInfoJson.end() &&
extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME].is_string()) {
std::string uidBundleName = extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME];
callerInfo.extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME] = uidBundleName;
}
HILOGD("save dms version");
}
int32_t DistributedSchedStub::SendResultFromRemoteInner(MessageParcel& data, MessageParcel& reply)
@ -856,11 +867,7 @@ int32_t DistributedSchedStub::RegisterDSchedEventListenerInner(MessageParcel& da
HILOGW("request DENIED!");
return DMS_PERMISSION_DENIED;
}
uint8_t type = data.ReadUint8();
if (type != DMS_CONTINUE && type != DMS_COLLABRATION && type != DMS_ALL) {
HILOGW("read type failed!");
return ERR_FLATTEN_OBJECT;
}
DSchedEventType type = static_cast<DSchedEventType>(data.ReadUint8());
sptr<IRemoteObject> dSchedEventListener = data.ReadRemoteObject();
if (dSchedEventListener == nullptr) {
HILOGW("read IRemoteObject failed!");
@ -877,11 +884,7 @@ int32_t DistributedSchedStub::UnRegisterDSchedEventListenerInner(MessageParcel&
HILOGW("request DENIED!");
return DMS_PERMISSION_DENIED;
}
uint8_t type = data.ReadUint8();
if (type != DMS_CONTINUE && type != DMS_COLLABRATION && type != DMS_ALL) {
HILOGW("read type failed!");
return ERR_FLATTEN_OBJECT;
}
DSchedEventType type = static_cast<DSchedEventType>(data.ReadUint8());
sptr<IRemoteObject> dSchedEventListener = data.ReadRemoteObject();
if (dSchedEventListener == nullptr) {
HILOGW("read IRemoteObject failed!");
@ -902,6 +905,41 @@ int32_t DistributedSchedStub::GetContinueInfoInner(MessageParcel& data, MessageP
return result;
}
int32_t DistributedSchedStub::GetEncodeDSchedEventNotify(const EventNotify& event, MessageParcel& reply)
{
PARCEL_WRITE_HELPER(reply, Int32, event.eventResult_);
PARCEL_WRITE_HELPER(reply, String, event.srcNetworkId_);
PARCEL_WRITE_HELPER(reply, String, event.dstNetworkId_);
PARCEL_WRITE_HELPER(reply, String, event.srcBundleName_);
PARCEL_WRITE_HELPER(reply, String, event.srcModuleName_);
PARCEL_WRITE_HELPER(reply, String, event.srcAbilityName_);
PARCEL_WRITE_HELPER(reply, String, event.destBundleName_);
PARCEL_WRITE_HELPER(reply, String, event.destModuleName_);
PARCEL_WRITE_HELPER(reply, String, event.destAbilityName_);
PARCEL_WRITE_HELPER(reply, Int32, event.dSchedEventType_);
PARCEL_WRITE_HELPER(reply, Int32, event.state_);
return ERR_OK;
}
int32_t DistributedSchedStub::GetDSchedEventInfoInner(MessageParcel& data, MessageParcel& reply)
{
HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
DSchedEventType type = static_cast<DSchedEventType>(data.ReadInt32());
std::vector<EventNotify> eventInfos;
int32_t result = GetDSchedEventInfo(type, eventInfos);
PARCEL_WRITE_HELPER(reply, Int32, result);
PARCEL_WRITE_HELPER(reply, Uint32, eventInfos.size());
for (const auto &event : eventInfos) {
result = GetEncodeDSchedEventNotify(event, reply);
if (result != ERR_OK) {
HILOGE("Get encode Dms event notify failed!");
return DMS_WRITE_FILE_FAILED_ERR;
}
}
return result;
}
int32_t DistributedSchedStub::RegisterOnListenerInner(MessageParcel& data, MessageParcel& reply)
{
if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
@ -1392,7 +1430,7 @@ int32_t DistributedSchedStub::StartFreeInstallFromRemoteInner(MessageParcel& dat
}
int32_t requestCode = CreateJsonObject(extraInfo, callerInfo);
FreeInstallInfo info = {
.want = *want, .callerInfo = callerInfo, .requestCode = requestCode, .accountInfo = accountInfo};
.want = *want, .requestCode = requestCode, .callerInfo = callerInfo, .accountInfo = accountInfo};
info.want.RemoveParam(PARAM_FREEINSTALL_APPID);
info.want.SetParam(PARAM_FREEINSTALL_APPID, callerInfo.callerAppId);
info.want.RemoveParam(PARAM_FREEINSTALL_BUNDLENAMES);