Signed-off-by: wangdongdong <wangdongdong14@huawei.com>

Change-Id: I356a719009cd153e03404a6e87f4cd91f2c94aaf
This commit is contained in:
wangdongdong 2022-01-07 16:28:39 +08:00
parent 6472328dd7
commit e67b722e3c
14 changed files with 405 additions and 94 deletions

View File

@ -26,7 +26,7 @@
namespace OHOS { namespace OHOS {
namespace DistributedSchedule { namespace DistributedSchedule {
using FuncContinuationCallback = std::function<void(const sptr<IRemoteObject>& abilityToken)>; using FuncContinuationCallback = std::function<void(int32_t missionId)>;
class DSchedContinuation : public std::enable_shared_from_this<DSchedContinuation> { class DSchedContinuation : public std::enable_shared_from_this<DSchedContinuation> {
public: public:
@ -34,6 +34,12 @@ public:
bool PushAbilityToken(int32_t sessionId, const sptr<IRemoteObject>& abilityToken); bool PushAbilityToken(int32_t sessionId, const sptr<IRemoteObject>& abilityToken);
sptr<IRemoteObject> PopAbilityToken(int32_t sessionId); sptr<IRemoteObject> PopAbilityToken(int32_t sessionId);
int32_t GenerateSessionId(); int32_t GenerateSessionId();
bool IsInContinuationProgress(int32_t missionId);
void SetTimeOut(int32_t missionId);
void RemoveTimeOut(int32_t missionId);
bool PushCallback(int32_t missionId, const sptr<IRemoteObject>& callback);
sptr<IRemoteObject> PopCallback(int32_t missionId);
int32_t NotifyMissionCenterResult(int32_t missionId, int32_t isSuccess);
private: private:
class ContinuationHandler : public AppExecFwk::EventHandler { class ContinuationHandler : public AppExecFwk::EventHandler {
@ -54,6 +60,7 @@ private:
std::mutex continuationLock_; std::mutex continuationLock_;
int32_t currSessionId_ = 1; int32_t currSessionId_ = 1;
std::map<int32_t, sptr<IRemoteObject>> continuationMap_; std::map<int32_t, sptr<IRemoteObject>> continuationMap_;
std::map<int32_t, sptr<IRemoteObject>> callbackMap_;
}; };
} // namespace DistributedSchedule } // namespace DistributedSchedule
} // namespace OHOS } // namespace OHOS

View File

@ -41,8 +41,10 @@ public:
virtual int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, virtual int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo,
const AccountInfo& accountInfo) = 0; const AccountInfo& accountInfo) = 0;
virtual int32_t StartContinuation(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& abilityToken, virtual int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t callerUid) = 0; int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams) = 0;
virtual int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
int32_t status) = 0;
virtual void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) = 0; virtual void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) = 0;
virtual int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) = 0; virtual int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) = 0;
virtual int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, virtual int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want,
@ -88,6 +90,8 @@ public:
CONTINUE_ABILITY = 16, CONTINUE_ABILITY = 16,
NOTIFY_PROCESS_DIED_FROM_REMOTE = 17, NOTIFY_PROCESS_DIED_FROM_REMOTE = 17,
GET_REMOTE_APPTHREAD = 35, GET_REMOTE_APPTHREAD = 35,
CONTINUE_MISSION = 36,
// request code for mission // request code for mission
GET_MISSION_INFOS = 80, GET_MISSION_INFOS = 80,
STORE_SNAPSHOT_INFO = 81, STORE_SNAPSHOT_INFO = 81,

6
services/dtbschedmgr/include/distributed_sched_proxy.h Normal file → Executable file
View File

@ -30,8 +30,10 @@ public:
int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo,
const AccountInfo& accountInfo) override; const AccountInfo& accountInfo) override;
int32_t StartContinuation(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& abilityToken, int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t callerUid) override; int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams) override;
int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
int32_t status) override;
void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override;
int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override;
int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want,

View File

@ -61,8 +61,10 @@ public:
int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo,
const AccountInfo& accountInfo) override; const AccountInfo& accountInfo) override;
int32_t StartContinuation(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& abilityToken, int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t callerUid) override; int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams) override;
int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
int32_t status) override;
void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override;
int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override;
int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want,
@ -100,7 +102,7 @@ public:
private: private:
DistributedSchedService(); DistributedSchedService();
bool Init(); bool Init();
void NotifyContinuationCallbackResult(const sptr<IRemoteObject>& abilityToken, int32_t isSuccess); void NotifyContinuationCallbackResult(int32_t missionId, int32_t isSuccess);
void RemoteConnectAbilityMappingLocked(const sptr<IRemoteObject>& connect, const std::string& localDeviceId, void RemoteConnectAbilityMappingLocked(const sptr<IRemoteObject>& connect, const std::string& localDeviceId,
const std::string& remoteDeviceId, const AppExecFwk::ElementName& element, const CallerInfo& callerInfo, const std::string& remoteDeviceId, const AppExecFwk::ElementName& element, const CallerInfo& callerInfo,
TargetComponent targetComponent); TargetComponent targetComponent);
@ -120,6 +122,14 @@ private:
static int32_t GetUidLocked(const std::list<ConnectAbilitySession>& sessionList); static int32_t GetUidLocked(const std::list<ConnectAbilitySession>& sessionList);
int32_t TryConnectRemoteAbility(const OHOS::AAFwk::Want& want, int32_t TryConnectRemoteAbility(const OHOS::AAFwk::Want& want,
const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo); const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo);
int32_t ContinueToAbilityManager(const std::string& deviceId, int32_t missionId);
int32_t NotifyResultToAbilityManager(int32_t missionId, int32_t isSuccess);
int32_t CleanMission(int32_t missionId);
sptr<IRemoteObject> GetAbilityManagerProxy();
int32_t ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback);
int32_t ContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams);
std::shared_ptr<DSchedContinuation> dschedContinuation_; std::shared_ptr<DSchedContinuation> dschedContinuation_;
std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> distributedConnectAbilityMap_; std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> distributedConnectAbilityMap_;
@ -128,6 +138,7 @@ private:
std::mutex distributedLock_; std::mutex distributedLock_;
std::mutex connectLock_; std::mutex connectLock_;
sptr<IRemoteObject::DeathRecipient> connectDeathRecipient_; sptr<IRemoteObject::DeathRecipient> connectDeathRecipient_;
sptr<IRemoteObject> abilityManagerProxy_;
}; };
class ConnectAbilitySession { class ConnectAbilitySession {

View File

@ -37,6 +37,7 @@ protected:
private: private:
int32_t StartRemoteAbilityInner(MessageParcel& data, MessageParcel& reply); int32_t StartRemoteAbilityInner(MessageParcel& data, MessageParcel& reply);
int32_t StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply); int32_t StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply);
int32_t ContinueMissionInner(MessageParcel& data, MessageParcel& reply);
int32_t StartContinuationInner(MessageParcel& data, MessageParcel& reply); int32_t StartContinuationInner(MessageParcel& data, MessageParcel& reply);
int32_t NotifyCompleteContinuationInner(MessageParcel& data, MessageParcel& reply); int32_t NotifyCompleteContinuationInner(MessageParcel& data, MessageParcel& reply);
int32_t NotifyContinuationResultFromRemoteInner(MessageParcel& data, MessageParcel& reply); int32_t NotifyContinuationResultFromRemoteInner(MessageParcel& data, MessageParcel& reply);

View File

@ -324,6 +324,10 @@ enum {
* Result(29360196) for cloud switch is off. * Result(29360196) for cloud switch is off.
*/ */
MISSION_OSD_CLOUD_SWITCH_OFF = 29360196, MISSION_OSD_CLOUD_SWITCH_OFF = 29360196,
/*
* Result(29360197) for continue mission rejected.
*/
CONTINUE_MISSION_REJECTED = 29360197,
}; };
} // namespace DistributedSchedule } // namespace DistributedSchedule
} // namespace OHOS } // namespace OHOS

View File

@ -15,6 +15,7 @@
#include "distributed_sched_continuation.h" #include "distributed_sched_continuation.h"
#include "dtbschedmgr_log.h" #include "dtbschedmgr_log.h"
#include "parcel_helper.h"
using namespace std; using namespace std;
using namespace OHOS::AppExecFwk; using namespace OHOS::AppExecFwk;
@ -24,6 +25,8 @@ namespace DistributedSchedule {
namespace { namespace {
constexpr int64_t CONTINUATION_DELAY_TIME = 20000; constexpr int64_t CONTINUATION_DELAY_TIME = 20000;
const std::string TAG = "DSchedContinuation"; const std::string TAG = "DSchedContinuation";
const std::u16string NAPI_MISSION_CENTER_INTERFACE_TOKEN = u"ohos.DistributedSchedule.IMissionCallback";
constexpr int32_t NOTIFY_MISSION_CENTER_RESULT = 4;
} }
void DSchedContinuation::Init(const FuncContinuationCallback& contCallback) void DSchedContinuation::Init(const FuncContinuationCallback& contCallback)
@ -97,6 +100,101 @@ int32_t DSchedContinuation::GenerateSessionId()
return currValue; return currValue;
} }
void DSchedContinuation::SetTimeOut(int32_t missionId)
{
if (continuationHandler_ == nullptr) {
HILOGE("continuationHandler not initialized!");
return;
}
continuationHandler_->SendEvent(missionId, 0, CONTINUATION_DELAY_TIME);
}
void DSchedContinuation::RemoveTimeOut(int32_t missionId)
{
if (continuationHandler_ == nullptr) {
HILOGE("continuationHandler not initialized!");
return;
}
continuationHandler_->RemoveEvent(missionId);
}
bool DSchedContinuation::IsInContinuationProgress(int32_t missionId)
{
lock_guard<mutex> autoLock(continuationLock_);
auto iterSession = callbackMap_.find(missionId);
if (iterSession != callbackMap_.end()) {
HILOGE("Continuation in progress, missionId:%{public}d exist!", missionId);
return true;
}
return false;
}
bool DSchedContinuation::PushCallback(int32_t missionId, const sptr<IRemoteObject>& callback)
{
if (callback == nullptr) {
HILOGE("PushCallback callback null!");
return false;
}
if (continuationHandler_ == nullptr) {
HILOGE("PushCallback not initialized!");
return false;
}
bool ret = true;
ret = continuationHandler_->SendEvent(missionId, 0, CONTINUATION_DELAY_TIME);
if (!ret) {
HILOGE("PushCallback SendEvent failed!");
return false;
}
lock_guard<mutex> autoLock(continuationLock_);
auto iterSession = callbackMap_.find(missionId);
if (iterSession != callbackMap_.end()) {
HILOGE("PushCallback missionId:%{public}d exist!", missionId);
return false;
}
(void)callbackMap_.emplace(missionId, callback);
return true;
}
sptr<IRemoteObject> DSchedContinuation::PopCallback(int32_t missionId)
{
lock_guard<mutex> autoLock(continuationLock_);
auto iter = callbackMap_.find(missionId);
if (iter == callbackMap_.end()) {
HILOGW("PopCallback not found missionId:%{public}d", missionId);
return nullptr;
}
sptr<IRemoteObject> callback = iter->second;
(void)callbackMap_.erase(iter);
if (continuationHandler_ != nullptr) {
continuationHandler_->RemoveEvent(missionId);
}
return callback;
}
int32_t DSchedContinuation::NotifyMissionCenterResult(int32_t missionId, int32_t isSuccess)
{
sptr<IRemoteObject> callback = PopCallback(missionId);
if (callback == nullptr) {
HILOGE("NotifyMissionCenterResult callback is null");
return INVALID_PARAMETERS_ERR;
}
MessageParcel data;
if (!data.WriteInterfaceToken(NAPI_MISSION_CENTER_INTERFACE_TOKEN)) {
HILOGE("NotifyMissionCenterResult write token failed");
return INVALID_PARAMETERS_ERR;
}
PARCEL_WRITE_HELPER_RET(data, Int32, isSuccess, INVALID_PARAMETERS_ERR);
MessageParcel reply;
MessageOption option;
int32_t error = callback->SendRequest(NOTIFY_MISSION_CENTER_RESULT, data, reply, option);
HILOGI("NotifyMissionCenterResult transact result: %{public}d", error);
return error;
}
void DSchedContinuation::ContinuationHandler::ProcessEvent(const InnerEvent::Pointer& event) void DSchedContinuation::ContinuationHandler::ProcessEvent(const InnerEvent::Pointer& event)
{ {
if (event == nullptr) { if (event == nullptr) {
@ -104,12 +202,6 @@ void DSchedContinuation::ContinuationHandler::ProcessEvent(const InnerEvent::Poi
return; return;
} }
auto dSchedContinuation = continuationObj_.lock();
if (dSchedContinuation == nullptr) {
HILOGE("ProcessEvent continuation object failed!");
return;
}
auto eventId = event->GetInnerEventId(); auto eventId = event->GetInnerEventId();
int32_t sessionId = static_cast<int32_t>(eventId); int32_t sessionId = static_cast<int32_t>(eventId);
if (sessionId <= 0) { if (sessionId <= 0) {
@ -117,14 +209,8 @@ void DSchedContinuation::ContinuationHandler::ProcessEvent(const InnerEvent::Poi
return; return;
} }
auto abilityToken = dSchedContinuation->PopAbilityToken(sessionId);
if (abilityToken == nullptr) {
HILOGW("ProcessEvent abilityToken nullptr!");
return;
}
if (contCallback_ != nullptr) { if (contCallback_ != nullptr) {
contCallback_(abilityToken); contCallback_(sessionId);
} }
} }
} // namespace DistributedSchedule } // namespace DistributedSchedule

32
services/dtbschedmgr/src/distributed_sched_proxy.cpp Normal file → Executable file
View File

@ -76,13 +76,34 @@ int32_t DistributedSchedProxy::StartAbilityFromRemote(const OHOS::AAFwk::Want& w
PARCEL_TRANSACT_SYNC_RET_INT(remote, START_ABILITY_FROM_REMOTE, data, reply); PARCEL_TRANSACT_SYNC_RET_INT(remote, START_ABILITY_FROM_REMOTE, data, reply);
} }
int32_t DistributedSchedProxy::StartContinuation(const OHOS::AAFwk::Want& want, int32_t DistributedSchedProxy::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
const sptr<IRemoteObject>& abilityToken, int32_t callerUid) int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
{ {
if (abilityToken == nullptr) { if (callback == nullptr) {
HILOGE("StartContinuation abilityToken null!"); HILOGE("ContinueMission callback null");
return ERR_NULL_OBJECT; return ERR_NULL_OBJECT;
} }
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
HILOGE("ContinueMission remote service null");
return ERR_NULL_OBJECT;
}
MessageParcel data;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, String, srcDeviceId);
PARCEL_WRITE_HELPER(data, String, dstDeviceId);
PARCEL_WRITE_HELPER(data, Int32, missionId);
PARCEL_WRITE_HELPER(data, RemoteObject, callback);
PARCEL_WRITE_HELPER(data, Parcelable, &wantParams);
MessageParcel reply;
PARCEL_TRANSACT_SYNC_RET_INT(remote, CONTINUE_MISSION, data, reply);
}
int32_t DistributedSchedProxy::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
int32_t status)
{
sptr<IRemoteObject> remote = Remote(); sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) { if (remote == nullptr) {
HILOGE("StartContinuation remote service null"); HILOGE("StartContinuation remote service null");
@ -93,8 +114,9 @@ int32_t DistributedSchedProxy::StartContinuation(const OHOS::AAFwk::Want& want,
return ERR_FLATTEN_OBJECT; return ERR_FLATTEN_OBJECT;
} }
PARCEL_WRITE_HELPER(data, Parcelable, &want); PARCEL_WRITE_HELPER(data, Parcelable, &want);
PARCEL_WRITE_HELPER(data, RemoteObject, abilityToken); PARCEL_WRITE_HELPER(data, Int32, missionId);
PARCEL_WRITE_HELPER(data, Int32, callerUid); PARCEL_WRITE_HELPER(data, Int32, callerUid);
PARCEL_WRITE_HELPER(data, Int32, status);
MessageParcel reply; MessageParcel reply;
PARCEL_TRANSACT_SYNC_RET_INT(remote, START_CONTINUATION, data, reply); PARCEL_TRANSACT_SYNC_RET_INT(remote, START_CONTINUATION, data, reply);
} }

226
services/dtbschedmgr/src/distributed_sched_service.cpp Normal file → Executable file
View File

@ -47,6 +47,10 @@ using namespace AppExecFwk;
namespace { namespace {
const std::string TAG = "DistributedSchedService"; const std::string TAG = "DistributedSchedService";
const std::u16string CONNECTION_CALLBACK_INTERFACE_TOKEN = u"ohos.abilityshell.DistributedConnection"; const std::u16string CONNECTION_CALLBACK_INTERFACE_TOKEN = u"ohos.abilityshell.DistributedConnection";
const std::u16string ABILITY_MANAGER_SERVICE_TOKEN = u"ohos.aafwk.AbilityManager";
constexpr int32_t IAbilityManager_CONTINUE_ABILITY = 1104;
constexpr int32_t IAbilityManager_NOTIFY_CONTINUATION_RESULT = 1102;
constexpr int32_t IAbilityManager_CLEAN_MISSION = 45;
constexpr int32_t BIND_CONNECT_RETRY_TIMES = 3; constexpr int32_t BIND_CONNECT_RETRY_TIMES = 3;
constexpr int32_t BIND_CONNECT_TIMEOUT = 500; // 500ms constexpr int32_t BIND_CONNECT_TIMEOUT = 500; // 500ms
constexpr int32_t MAX_DISTRIBUTED_CONNECT_NUM = 600; constexpr int32_t MAX_DISTRIBUTED_CONNECT_NUM = 600;
@ -68,9 +72,9 @@ void DistributedSchedService::OnStart()
HILOGE("failed to init DistributedSchedService"); HILOGE("failed to init DistributedSchedService");
return; return;
} }
FuncContinuationCallback continuationCallback = [this] (const sptr<IRemoteObject>& abilityToken) { FuncContinuationCallback continuationCallback = [this] (int32_t missionId) {
HILOGW("continuationCallback timeout."); HILOGW("continuationCallback timeout.");
NotifyContinuationCallbackResult(abilityToken, CONTINUE_ABILITY_TIMEOUT_ERR); NotifyContinuationCallbackResult(missionId, CONTINUE_ABILITY_TIMEOUT_ERR);
}; };
dschedContinuation_ = std::make_shared<DSchedContinuation>(); dschedContinuation_ = std::make_shared<DSchedContinuation>();
dschedContinuation_->Init(continuationCallback); dschedContinuation_->Init(continuationCallback);
@ -161,12 +165,96 @@ int32_t DistributedSchedService::StartAbilityFromRemote(const OHOS::AAFwk::Want&
return err; return err;
} }
int32_t DistributedSchedService::StartContinuation(const OHOS::AAFwk::Want& want, int32_t DistributedSchedService::ContinueToAbilityManager(const std::string& deviceId, int32_t missionId)
const sptr<IRemoteObject>& abilityToken, int32_t callerUid) {
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(ABILITY_MANAGER_SERVICE_TOKEN)) {
return INVALID_PARAMETERS_ERR;
}
if (!data.WriteString(deviceId)) {
HILOGE("deviceId write failed.");
return INVALID_PARAMETERS_ERR;
}
if (!data.WriteInt32(missionId)) {
HILOGE("missionId write failed.");
return INVALID_PARAMETERS_ERR;
}
sptr<IRemoteObject> ability_manager = GetAbilityManagerProxy();
if (ability_manager == nullptr) {
HILOGE("get ability manager failed");
return INVALID_PARAMETERS_ERR;
}
auto error = ability_manager->SendRequest(IAbilityManager_CONTINUE_ABILITY, data, reply, option);
if (error != NO_ERROR) {
HILOGE("Send request error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback)
{
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return INVALID_PARAMETERS_ERR;
}
if (dschedContinuation_->IsInContinuationProgress(missionId)) {
HILOGE("ContinueLocalMission already in progress!");
return INVALID_PARAMETERS_ERR;
}
dschedContinuation_->PushCallback(missionId, callback);
int32_t result = ContinueToAbilityManager(dstDeviceId, missionId);
HILOGI("ContinueLocalMission result: %{public}d!", result);
return result;
}
int32_t DistributedSchedService::ContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
{
sptr<IDistributedSched> remoteDms = GetRemoteDms(srcDeviceId);
if (remoteDms == nullptr) {
HILOGE("get remote dms null!");
return INVALID_REMOTE_PARAMETERS_ERR;
}
int32_t result = remoteDms->ContinueMission(srcDeviceId, dstDeviceId, missionId, callback, wantParams);
HILOGI("ContinueRemoteMission result: %{public}d!", result);
return result;
}
int32_t DistributedSchedService::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
{
if (srcDeviceId.empty() || dstDeviceId.empty() || callback == nullptr) {
HILOGE("srcDeviceId or dstDeviceId or callback is null!");
return INVALID_PARAMETERS_ERR;
}
std::string localDevId;
if (!GetLocalDeviceId(localDevId)) {
HILOGE("get local deviceId failed!");
return INVALID_PARAMETERS_ERR;
}
if (srcDeviceId == localDevId) {
return ContinueLocalMission(dstDeviceId, missionId, callback);
} else if (dstDeviceId == localDevId) {
return ContinueRemoteMission(srcDeviceId, dstDeviceId, missionId, callback, wantParams);
} else {
HILOGE("source or target device must be local!");
return INVALID_PARAMETERS_ERR;
}
}
int32_t DistributedSchedService::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId,
int32_t callerUid, int32_t status)
{ {
HILOGD("[PerformanceTest] StartContinuation begin"); HILOGD("[PerformanceTest] StartContinuation begin");
if (abilityToken == nullptr) { if (status != ERR_OK) {
HILOGE("StartContinuation abilityToken is null!"); HILOGE("continuation has been rejected, status: %{public}d", status);
NotifyContinuationCallbackResult(missionId, CONTINUE_MISSION_REJECTED);
return INVALID_REMOTE_PARAMETERS_ERR; return INVALID_REMOTE_PARAMETERS_ERR;
} }
auto flags = want.GetFlags(); auto flags = want.GetFlags();
@ -192,10 +280,13 @@ int32_t DistributedSchedService::StartContinuation(const OHOS::AAFwk::Want& want
if (dschedContinuation_ == nullptr) { if (dschedContinuation_ == nullptr) {
HILOGE("StartContinuation continuation object null!"); HILOGE("StartContinuation continuation object null!");
return INVALID_PARAMETERS_ERR; return INVALID_REMOTE_PARAMETERS_ERR;
}
if (!dschedContinuation_->IsInContinuationProgress(missionId)) {
dschedContinuation_->SetTimeOut(missionId);
} }
int32_t sessionId = dschedContinuation_->GenerateSessionId(); int32_t sessionId = missionId;
AAFwk::Want newWant = want; AAFwk::Want newWant = want;
newWant.SetParam("sessionId", sessionId); newWant.SetParam("sessionId", sessionId);
newWant.SetParam("deviceId", devId); newWant.SetParam("deviceId", devId);
@ -206,16 +297,12 @@ int32_t DistributedSchedService::StartContinuation(const OHOS::AAFwk::Want& want
return result; return result;
} }
bool ret = dschedContinuation_->PushAbilityToken(sessionId, abilityToken);
if (!ret) {
HILOGW("StartContinuation PushAbilityToken failed!");
return INVALID_REMOTE_PARAMETERS_ERR;
}
HILOGD("[PerformanceTest] StartContinuation end"); HILOGD("[PerformanceTest] StartContinuation end");
return result; return result;
} }
void DistributedSchedService::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) void DistributedSchedService::NotifyCompleteContinuation(const std::u16string& devId,
int32_t sessionId, bool isSuccess)
{ {
if (!isSuccess) { if (!isSuccess) {
HILOGE("NotifyCompleteContinuation failed!"); HILOGE("NotifyCompleteContinuation failed!");
@ -239,34 +326,107 @@ int32_t DistributedSchedService::NotifyContinuationResultFromRemote(int32_t sess
HILOGE("NotifyContinuationResultFromRemote sessionId:%{public}d invalid!", sessionId); HILOGE("NotifyContinuationResultFromRemote sessionId:%{public}d invalid!", sessionId);
return INVALID_REMOTE_PARAMETERS_ERR; return INVALID_REMOTE_PARAMETERS_ERR;
} }
if (dschedContinuation_ == nullptr) {
HILOGE("NotifyContinuationResultFromRemote continuation object null!");
return INVALID_REMOTE_PARAMETERS_ERR;
}
auto abilityToken = dschedContinuation_->PopAbilityToken(sessionId); int32_t missionId = sessionId;
if (abilityToken == nullptr) { NotifyContinuationCallbackResult(missionId, isSuccess ? 0 : NOTIFYCOMPLETECONTINUATION_FAILED);
HILOGE("DSchedContinuationCallback NotifyContinuationResultFromRemote abilityToken null!");
return INVALID_REMOTE_PARAMETERS_ERR;
}
NotifyContinuationCallbackResult(abilityToken, isSuccess ? 0 : NOTIFYCOMPLETECONTINUATION_FAILED);
return ERR_OK; return ERR_OK;
} }
void DistributedSchedService::NotifyContinuationCallbackResult(const sptr<IRemoteObject>& abilityToken, sptr<IRemoteObject> DistributedSchedService::GetAbilityManagerProxy()
int32_t isSuccess)
{ {
if (isSuccess != ERR_OK) { HILOGI("%{public}s begin.", __func__);
HILOGE("NotifyContinuationCallbackResult failed!"); auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sm == nullptr) {
HILOGE("GetAbilityManagerProxy sm is nullptr");
return nullptr;
} }
HILOGD("NotifyContinuationCallbackResult ContinuationRet result:%{public}d", isSuccess);
if (abilityToken == nullptr) { abilityManagerProxy_ = sm->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
HILOGE("NotifyContinuationCallbackResult abilityToken null!"); if (abilityManagerProxy_ == nullptr) {
HILOGE("failed to get ability manager service");
return nullptr;
}
return abilityManagerProxy_;
}
int32_t DistributedSchedService::NotifyResultToAbilityManager(int32_t missionId, int32_t isSuccess)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(ABILITY_MANAGER_SERVICE_TOKEN)) {
return INVALID_PARAMETERS_ERR;
}
if (!data.WriteInt32(missionId)) {
HILOGE("NotifyResultToAbilityManager missionId write failed.");
return INVALID_PARAMETERS_ERR;
}
if (!data.WriteInt32(isSuccess)) {
HILOGE("NotifyResultToAbilityManager result write failed.");
return INVALID_PARAMETERS_ERR;
}
sptr<IRemoteObject> ability_manager = GetAbilityManagerProxy();
if (ability_manager == nullptr) {
HILOGE("get ability manager failed");
return INVALID_PARAMETERS_ERR;
}
auto error = ability_manager->SendRequest(IAbilityManager_NOTIFY_CONTINUATION_RESULT,
data, reply, option);
if (error != NO_ERROR) {
HILOGE("NotifyResultToAbilityManager Send request error: %{public}d", error);
return INVALID_PARAMETERS_ERR;
}
return reply.ReadInt32();
}
int32_t DistributedSchedService::CleanMission(int32_t missionId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(ABILITY_MANAGER_SERVICE_TOKEN)) {
return INVALID_PARAMETERS_ERR;
}
if (!data.WriteInt32(missionId)) {
HILOGE("CleanMission WriteInt32 fail.");
return INVALID_PARAMETERS_ERR;
}
sptr<IRemoteObject> ability_manager = GetAbilityManagerProxy();
if (ability_manager == nullptr) {
HILOGE("get ability manager failed");
return INVALID_PARAMETERS_ERR;
}
auto error = ability_manager->SendRequest(IAbilityManager_CLEAN_MISSION, data, reply, option);
if (error != NO_ERROR) {
HILOGE("CleanMission error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId, int32_t isSuccess)
{
HILOGD("Continuation result is: %{public}d", isSuccess);
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
return; return;
} }
int32_t result = AAFwk::AbilityManagerClient::GetInstance()->NotifyContinuationResult(abilityToken, isSuccess); int32_t result = 0;
HILOGD("NotifyContinuationCallbackResult ScheduleCompleteContinuation result:%{public}d", result); if (dschedContinuation_->IsInContinuationProgress(missionId)) {
if (isSuccess) {
result = CleanMission(missionId);
}
result = dschedContinuation_->NotifyMissionCenterResult(missionId, isSuccess);
} else {
result = NotifyResultToAbilityManager(missionId, isSuccess);
dschedContinuation_->RemoveTimeOut(missionId);
}
HILOGD("NotifyContinuationCallbackResult result:%{public}d", result);
} }
void DistributedSchedService::RemoteConnectAbilityMappingLocked(const sptr<IRemoteObject>& connect, void DistributedSchedService::RemoteConnectAbilityMappingLocked(const sptr<IRemoteObject>& connect,

30
services/dtbschedmgr/src/distributed_sched_stub.cpp Normal file → Executable file
View File

@ -42,6 +42,7 @@ const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.acces
DistributedSchedStub::DistributedSchedStub() DistributedSchedStub::DistributedSchedStub()
{ {
localFuncsMap_[START_REMOTE_ABILITY] = &DistributedSchedStub::StartRemoteAbilityInner; localFuncsMap_[START_REMOTE_ABILITY] = &DistributedSchedStub::StartRemoteAbilityInner;
localFuncsMap_[CONTINUE_MISSION] = &DistributedSchedStub::ContinueMissionInner;
localFuncsMap_[START_CONTINUATION] = &DistributedSchedStub::StartContinuationInner; localFuncsMap_[START_CONTINUATION] = &DistributedSchedStub::StartContinuationInner;
localFuncsMap_[NOTIFY_COMPLETE_CONTINUATION] = &DistributedSchedStub::NotifyCompleteContinuationInner; localFuncsMap_[NOTIFY_COMPLETE_CONTINUATION] = &DistributedSchedStub::NotifyCompleteContinuationInner;
localFuncsMap_[CONNECT_REMOTE_ABILITY] = &DistributedSchedStub::ConnectRemoteAbilityInner; localFuncsMap_[CONNECT_REMOTE_ABILITY] = &DistributedSchedStub::ConnectRemoteAbilityInner;
@ -73,6 +74,7 @@ DistributedSchedStub::DistributedSchedStub()
&DistributedSchedStub::UnRegisterMissionListenerFromRemoteInner; &DistributedSchedStub::UnRegisterMissionListenerFromRemoteInner;
remoteFuncsMap_[NOTIFY_MISSIONS_CHANGED_FROM_REMOTE] = &DistributedSchedStub::NotifyMissionsChangedFromRemoteInner; remoteFuncsMap_[NOTIFY_MISSIONS_CHANGED_FROM_REMOTE] = &DistributedSchedStub::NotifyMissionsChangedFromRemoteInner;
remoteFuncsMap_[NOTIFY_SWITCH_CHANGED_FROM_REMOTE] = &DistributedSchedStub::UpdateOsdSwitchValueFromRemoteInner; remoteFuncsMap_[NOTIFY_SWITCH_CHANGED_FROM_REMOTE] = &DistributedSchedStub::UpdateOsdSwitchValueFromRemoteInner;
remoteFuncsMap_[CONTINUE_MISSION] = &DistributedSchedStub::ContinueMissionInner;
} }
DistributedSchedStub::~DistributedSchedStub() DistributedSchedStub::~DistributedSchedStub()
@ -159,6 +161,29 @@ int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, M
return ERR_NONE; return ERR_NONE;
} }
int32_t DistributedSchedStub::ContinueMissionInner(MessageParcel& data, MessageParcel& reply)
{
std::string srcDevId;
std::string dstDevId;
PARCEL_READ_HELPER(data, String, srcDevId);
PARCEL_READ_HELPER(data, String, dstDevId);
int32_t missionId = 0;
PARCEL_READ_HELPER(data, Int32, missionId);
sptr<IRemoteObject> callback = data.ReadRemoteObject();
if (callback == nullptr) {
HILOGW("read callback failed!");
return ERR_NULL_OBJECT;
}
shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
if (wantParams == nullptr) {
HILOGW("wantParams readParcelable failed!");
return ERR_NULL_OBJECT;
}
int32_t result = ContinueMission(srcDevId, dstDevId, missionId, callback, *wantParams);
HILOGI("result = %{public}d", result);
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
}
int32_t DistributedSchedStub::StartContinuationInner(MessageParcel& data, MessageParcel& reply) int32_t DistributedSchedStub::StartContinuationInner(MessageParcel& data, MessageParcel& reply)
{ {
shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>()); shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
@ -166,9 +191,10 @@ int32_t DistributedSchedStub::StartContinuationInner(MessageParcel& data, Messag
HILOGW("want readParcelable failed!"); HILOGW("want readParcelable failed!");
return ERR_NULL_OBJECT; return ERR_NULL_OBJECT;
} }
sptr<IRemoteObject> abilityToken = data.ReadRemoteObject(); int32_t missionId = data.ReadInt32();
int32_t callerUid = data.ReadInt32(); int32_t callerUid = data.ReadInt32();
int32_t result = StartContinuation(*want, abilityToken, callerUid); int32_t status = data.ReadInt32();
int32_t result = StartContinuation(*want, missionId, callerUid, status);
HILOGI("result = %{public}d", result); HILOGI("result = %{public}d", result);
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result); PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
} }

View File

@ -56,10 +56,7 @@ sptr<IRemoteObject> DSchedContinuationTest::GetDSchedService() const
int32_t DSchedContinuationTest::PushAbilityToken() int32_t DSchedContinuationTest::PushAbilityToken()
{ {
FuncContinuationCallback continuationCallback = [this] (const sptr<IRemoteObject>& abilityToken) { FuncContinuationCallback continuationCallback = [this] (int32_t missionId) {
if (abilityToken == nullptr) {
return;
}
timeoutFlag_ = true; timeoutFlag_ = true;
}; };
dschedContinuation_->Init(continuationCallback); dschedContinuation_->Init(continuationCallback);
@ -77,14 +74,14 @@ std::shared_ptr<Want> DSchedContinuationTest::MockWant(const string& bundleName,
return spWant; return spWant;
} }
int32_t DSchedContinuationTest::StartContinuation(const sptr<IRemoteObject>& abilityToken, int32_t flags) int32_t DSchedContinuationTest::StartContinuation(int32_t missionId, int32_t flags)
{ {
string bundleName = "bundleName"; string bundleName = "bundleName";
string abilityName = "abilityName"; string abilityName = "abilityName";
string devId = "devId"; string devId = "devId";
shared_ptr<Want> spWant = MockWant(bundleName, abilityName, flags); shared_ptr<Want> spWant = MockWant(bundleName, abilityName, flags);
int callerUid = 0; int callerUid = 0;
return DistributedSchedService::GetInstance().StartContinuation(*spWant, abilityToken, callerUid); return DistributedSchedService::GetInstance().StartContinuation(*spWant, missionId, callerUid, 0);
} }
/** /**
@ -96,44 +93,27 @@ HWTEST_F(DSchedContinuationTest, StartContinuation_001, TestSize.Level1)
{ {
DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl; DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl;
/** /**
* @tc.steps: step1. input invalid abilityToken * @tc.steps: step1. want not set continuation flags.
* @tc.expected: step1. return false. * @tc.expected: step1. return false.
*/ */
int32_t ret = StartContinuation(nullptr, Want::FLAG_ABILITY_CONTINUATION); int32_t ret = StartContinuation(0, 0);
EXPECT_TRUE(ret != ERR_OK); EXPECT_TRUE(ret != ERR_OK);
DTEST_LOG << "DSchedContinuationTest StartContinuation001 end" << std::endl; DTEST_LOG << "DSchedContinuationTest StartContinuation002 end" << std::endl;
} }
/** /**
* @tc.name: StartContinuation_002 * @tc.name: StartContinuation_002
* @tc.desc: input invalid params. * @tc.desc: get remote dms failed.
* @tc.type: FUNC * @tc.type: FUNC
*/ */
HWTEST_F(DSchedContinuationTest, StartContinuation_002, TestSize.Level1) HWTEST_F(DSchedContinuationTest, StartContinuation_002, TestSize.Level1)
{ {
DTEST_LOG << "DSchedContinuationTest StartContinuation_002 start" << std::endl; DTEST_LOG << "DSchedContinuationTest StartContinuation_002 start" << std::endl;
/**
* @tc.steps: step1. want not set continuation flags.
* @tc.expected: step1. return false.
*/
int32_t ret = StartContinuation(GetDSchedService(), 0);
EXPECT_TRUE(ret != ERR_OK);
DTEST_LOG << "DSchedContinuationTest StartContinuation002 end" << std::endl;
}
/**
* @tc.name: StartContinuation_003
* @tc.desc: get remote dms failed.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, StartContinuation_003, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest StartContinuation_003 start" << std::endl;
/** /**
* @tc.steps: step1. get remote dms failed. * @tc.steps: step1. get remote dms failed.
* @tc.expected: step1. return false. * @tc.expected: step1. return false.
*/ */
int32_t ret = StartContinuation(GetDSchedService(), Want::FLAG_ABILITY_CONTINUATION); int32_t ret = StartContinuation(0, Want::FLAG_ABILITY_CONTINUATION);
EXPECT_TRUE(ret != ERR_OK); EXPECT_TRUE(ret != ERR_OK);
DTEST_LOG << "DSchedContinuationTest StartContinuation003 end" << std::endl; DTEST_LOG << "DSchedContinuationTest StartContinuation003 end" << std::endl;
} }

View File

@ -42,7 +42,7 @@ protected:
int32_t flags); int32_t flags);
std::shared_ptr<AppExecFwk::AbilityInfo> MockAbilityInfo(const std::string& bundleName, std::shared_ptr<AppExecFwk::AbilityInfo> MockAbilityInfo(const std::string& bundleName,
const std::string& ability, const std::string& devId); const std::string& ability, const std::string& devId);
int32_t StartContinuation(const sptr<IRemoteObject>& abilityToken, int32_t flags); int32_t StartContinuation(int32_t missionId, int32_t flags);
std::shared_ptr<DSchedContinuation> dschedContinuation_; std::shared_ptr<DSchedContinuation> dschedContinuation_;
bool timeoutFlag_ = false; bool timeoutFlag_ = false;

View File

@ -36,8 +36,14 @@ int32_t MockDistributedSched::StartAbilityFromRemote(const OHOS::AAFwk::Want& wa
return 0; return 0;
} }
int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& abilityToken, int32_t MockDistributedSched::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t callerUid) int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
{
return 0;
}
int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId,
int32_t callerUid, int32_t status)
{ {
return 0; return 0;
} }

View File

@ -32,8 +32,10 @@ public:
int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo,
const AccountInfo& accountInfo) override; const AccountInfo& accountInfo) override;
int32_t StartContinuation(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& abilityToken, int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
int32_t callerUid) override; int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams) override;
int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
int32_t status) override;
void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override;
int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override;
int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want,