Feature: add continue condition manager

Signed-off-by: z00838083 <zhuhuixuan@huawei.com>
This commit is contained in:
z00838083 2024-11-30 16:22:35 +08:00
parent ea37dc0646
commit 3d7ad28d28
28 changed files with 1788 additions and 834 deletions

View File

@ -54,6 +54,23 @@ namespace DistributedSchedule {
#define HILOGI(fmt, ...) HILOG_INFO(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__)
#define HILOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__)
#define CHECK_POINTER_RETURN(object, log) \
do { \
if ((object) == nullptr) { \
HILOGE("%{public}s nullptr", (log)); \
return; \
} \
} while (0)
#define CHECK_POINTER_RETURN_VALUE(object, value, log) \
do { \
if ((object) == nullptr) { \
HILOGE("%{public}s nullptr", (log)); \
return (value); \
} \
} while (0)
enum {
/**
* Module type: Distributed schedule Service side

View File

@ -220,12 +220,14 @@ ohos_shared_library("distributedschedsvr") {
"src/mission/distributed_mission_focused_listener.cpp",
"src/mission/distributed_mission_info.cpp",
"src/mission/distributed_sched_mission_manager.cpp",
"src/mission/dms_continue_condition_manager.cpp",
"src/mission/dms_continue_recv_manager.cpp",
"src/mission/dms_continue_send_manager.cpp",
"src/mission/dsched_sync_e2e.cpp",
"src/mission/kvstore_death_recipient.cpp",
"src/mission/mission_changed_notify.cpp",
"src/mission/mission_info_converter.cpp",
"src/mission/notification/dms_continue_send_manager.cpp",
"src/mission/notification/dms_continue_send_strategy.cpp",
"src/mission/snapshot.cpp",
"src/mission/snapshot_converter.cpp",
"src/mission/wifi_state_adapter.cpp",

View File

@ -131,8 +131,9 @@ class DSchedContinue : public std::enable_shared_from_this<DSchedContinue> {
public:
DSchedContinue(int32_t subServiceType, int32_t direction, const sptr<IRemoteObject>& callback,
const DSchedContinueInfo& continueInfo);
DSchedContinue(std::shared_ptr<DSchedContinueStartCmd> startCmd, int32_t sessionId);
const DSchedContinueInfo& continueInfo, int32_t accountId = INVALID_ACCOUNT_ID);
DSchedContinue(std::shared_ptr<DSchedContinueStartCmd> startCmd, int32_t sessionId,
int32_t accountId = INVALID_ACCOUNT_ID);
~DSchedContinue();
private:
@ -212,6 +213,7 @@ private:
private:
static constexpr int32_t INVALID_SESSION_ID = -1;
static constexpr int32_t INVALID_ACCOUNT_ID = -1;
static constexpr int32_t ERROR_BASE_DSOFTBUS_WIFI = -200000;
static constexpr int32_t ERROR_PEER_THREE_VAP_CONFLICT = ERROR_BASE_DSOFTBUS_WIFI - 6604;
static const std::map<int32_t, int32_t> DMS_CONVERT_TO_SDK_ERR_MAP;
@ -231,6 +233,7 @@ private:
int32_t softbusSessionId_ = INVALID_SESSION_ID;
sptr<IRemoteObject> callback_ = nullptr;
EventNotify eventData_;
int32_t accountId_ = INVALID_ACCOUNT_ID;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -52,7 +52,7 @@ public:
std::atomic<bool> isCurrentContinueSwitchOn_ = true;
bool IsCurrentContinueSwitchOn();
void SetCurrentContinueSwitch(bool status);
private:
std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
sptr<SettingObserver> GetSettingObserver(const std::string &key);
@ -65,4 +65,4 @@ private:
} // namespace DistributedSchedule
} // namespace OHOS
#endif // DMS_DATASHARE_MANAGER_H
#endif // DMS_DATASHARE_MANAGER_H

View File

@ -215,6 +215,7 @@ public:
int32_t CheckTargetPermission4DiffBundle(const OHOS::AAFwk::Want& want, const CallerInfo& callerInfo,
const AccountInfo& accountInfo, int32_t flag, bool needQueryExtension);
ErrCode QueryOsAccount(int32_t& activeAccountId);
void RegisterDataShareObserver(const std::string& key);
#ifdef DMSFWK_INTERACTIVE_ADAPTER
bool CheckRemoteOsType(const std::string& netwokId) override;

View File

@ -16,6 +16,12 @@
#ifndef OHOS_DISTRIBUTED_MISSION_FOCUSED_LISTENER_H
#define OHOS_DISTRIBUTED_MISSION_FOCUSED_LISTENER_H
#include <mutex>
#include <queue>
#include <thread>
#include <cstdint>
#include "event_handler.h"
#include "mission_listener_stub.h"
namespace OHOS {
@ -90,6 +96,16 @@ public:
* @param missionId, mission Id.
*/
virtual void OnMissionLabelUpdated(int32_t missionId) override;
void Init();
void UnInit();
private:
void StartEvent();
std::thread eventThread_;
std::condition_variable eventCon_;
std::mutex eventMutex_;
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -0,0 +1,142 @@
/*
* 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_DMS_CONTINUE_CONDITION_MANAGER_H
#define OHOS_DMS_CONTINUE_CONDITION_MANAGER_H
#include <atomic>
#include <map>
#include <mutex>
#include <string>
#include "ability_manager_client.h"
#include "single_instance.h"
namespace OHOS {
namespace DistributedSchedule {
struct MissionStatus {
int32_t missionId;
std::string bundleName;
std::string moduleName;
std::string abilityName;
bool isContinuable;
unsigned int launchFlag;
bool isFocused;
AAFwk::ContinueState continueState;
std::string ToString() const
{
return "[ missionId: " + std::to_string(this->missionId) + " " +
"bundleName: " + this->bundleName + " " +
"moduleName: " + this->moduleName + " " +
"abilityName: " + this->abilityName + " " +
"isContinuable: "+ std::to_string(this->isContinuable) + " " +
"launchFlag: " + std::to_string(this->launchFlag) + " " +
"isFocused: " + std::to_string(this->isFocused) + " " +
"continueState: " + std::to_string(this->continueState) + " ]";
}
};
typedef enum {
MISSION_EVENT_INVALID = -1,
MISSION_EVENT_FOCUSED = 0,
MISSION_EVENT_UNFOCUSED = 1,
MISSION_EVENT_DESTORYED = 2,
MISSION_EVENT_ACTIVE = 4,
MISSION_EVENT_INACTIVE = 5,
MISSION_EVENT_TIMEOUT = 6,
MISSION_EVENT_MMI = 7,
MISSION_EVENT_MAX,
} MissionEventType;
typedef enum {
SYS_EVENT_INVALID = -1,
SYS_EVENT_CONTINUE_SWITCH = 0,
SYS_EVENT_WIFI = 1,
SYS_EVENT_SCREEN = 2,
SYS_EVENT_MAX,
} SysEventType;
class DmsContinueConditionMgr {
DECLARE_SINGLE_INSTANCE_BASE(DmsContinueConditionMgr);
public:
DmsContinueConditionMgr() = default;
virtual ~DmsContinueConditionMgr() = default;
void Init();
void UnInit();
int32_t UpdateSystemStatus(SysEventType type, bool value);
int32_t UpdateMissionStatus(int32_t accountId, int32_t missionId, MissionEventType type);
void OnUserSwitched(int32_t accountId);
void OnUserRemoved(int32_t accountId);
bool CheckSystemSendCondition();
bool CheckMissionSendCondition(const MissionStatus& status, MissionEventType type);
bool IsScreenLocked();
int32_t GetCurrentFocusedMission(int32_t accountId);
int32_t GetMissionStatus(int32_t accountId, int32_t missionId, MissionStatus& status);
int32_t GetMissionIdByBundleName(int32_t accountId, const std::string& bundleName, int32_t& missionId);
std::string TypeEnumToString(MissionEventType type);
private:
void InitConditionFuncs();
void InitSystemCondition();
int32_t SetIsContinueSwitchOn(bool isSwitchOn);
int32_t SetIsWifiActive(bool isWifiActive);
int32_t SetIsScreenLocked(bool isScreenLocked);
void InitMissionCondition();
void InitMissionStatus(int32_t accountId);
int32_t OnMissionFocused(int32_t accountId, int32_t missionId);
int32_t OnMissionUnfocused(int32_t accountId, int32_t missionId);
int32_t OnMissionDestory(int32_t accountId, int32_t missionId);
int32_t OnMissionActive(int32_t accountId, int32_t missionId);
int32_t OnMissionInactive(int32_t accountId, int32_t missionId);
bool CheckSendFocusedCondition(const MissionStatus& status);
bool CheckSendUnfocusedCondition(const MissionStatus& status);
bool CheckSendActiveCondition(const MissionStatus& status);
bool CheckSendInactiveCondition(const MissionStatus& status);
int32_t GetMissionInfo(int32_t missionId, AAFwk::MissionInfo& info);
int32_t GetMissionInfos(std::vector<AAFwk::MissionInfo>& missions);
void ConvertToMissionStatus(const AAFwk::MissionInfo& missionInfo, MissionStatus& status);
void CleanLastFocusedFlagLocked(int32_t accountId, int32_t missionId);
bool IsMissionStatusExistLocked(int32_t accountId, int32_t missionId);
std::atomic<bool> isCfgDevice_ = false;
std::atomic<bool> isSwitchOn_ = false;
std::atomic<bool> isWifiActive_ = false;
std::atomic<bool> isScreenLocked_ = false;
using DSchedSysEventFunc = int32_t (DmsContinueConditionMgr::*)(bool value);
std::map<SysEventType, DSchedSysEventFunc> sysFuncMap_;
using DSchedMissionEventFunc = int32_t (DmsContinueConditionMgr::*)(int32_t accountId, int32_t missionId);
std::map<MissionEventType, DSchedMissionEventFunc> missionFuncMap_;
using DSchedSendConditionFunc = bool (DmsContinueConditionMgr::*)(const MissionStatus& status);
std::map<MissionEventType, DSchedSendConditionFunc> conditionFuncMap_;
std::mutex missionMutex_;
std::map<int32_t, std::map<int32_t, MissionStatus>> missionMap_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DMS_CONTINUE_CONDITION_MANAGER_H

View File

@ -75,7 +75,8 @@ public:
constexpr static uint8_t CONTINUE_SHIFT_04 = 0x04;
constexpr static int32_t INVALID_MISSION_ID = -1;
void Init();
~DMSContinueRecvMgr();
void Init(int32_t accountId);
void UnInit();
void NotifyDataRecv(std::string& senderNetworkId, uint8_t* payload, uint32_t dataLen);
int32_t RegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj);
@ -118,6 +119,7 @@ private:
std::mutex eventMutex_;
std::mutex iconMutex_;
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
int32_t accountId_ = -1;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -0,0 +1,122 @@
/*
* 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 DMS_CONTINUE_SEND_MANAGER_H
#define DMS_CONTINUE_SEND_MANAGER_H
#include <mutex>
#include <queue>
#include <string>
#include <thread>
#include <cstdint>
#include "event_handler.h"
#include "single_instance.h"
#include "mission/dms_continue_condition_manager.h"
#include "mission/notification/dms_continue_send_strategy.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
constexpr uint8_t BROADCAST_TYPE_APPEAR = 0;
constexpr uint8_t BROADCAST_TYPE_DISAPPEAR = 1;
constexpr int32_t DEFAULT_USER = 100;
}
class DMSContinueSendMgr : public std::enable_shared_from_this<DMSContinueSendMgr> {
friend class SendStrategyFocused;
friend class SendStrategyUnfocused;
friend class SendStrategyDestoryed;
friend class SendStrategyActive;
friend class SendStrategyInactive;
friend class SendStrategyTimeout;
friend class SendStrategyMMI;
public:
constexpr static uint8_t DMS_DATA_LEN = 3; // Dms data Length
constexpr static int32_t DMS_SEND_LEN = 4; // Maximum broadcast length
constexpr static uint8_t DMS_0XF0 = 0xf0;
constexpr static uint8_t DMS_0X0F = 0x0f;
constexpr static uint8_t DMS_0XFF = 0xff;
constexpr static uint8_t DMS_FOCUSED_TYPE = 0x00;
constexpr static uint8_t DMS_UNFOCUSED_TYPE = 0x01;
constexpr static uint8_t CONTINUE_SHIFT_24 = 0x18;
constexpr static uint8_t CONTINUE_SHIFT_16 = 0x10;
constexpr static uint8_t CONTINUE_SHIFT_08 = 0x08;
constexpr static uint8_t CONTINUE_SHIFT_04 = 0x04;
constexpr static int32_t INVALID_ID = -1;
~DMSContinueSendMgr();
void Init(int32_t currentUserId);
void UnInit();
void OnMissionStatusChanged(int32_t missionId, MissionEventType type);
void OnMMIEvent();
int32_t OnDeviceOnline();
void OnDeviceScreenLocked();
void OnDeviceScreenOn();
void OnUserSwitched();
private:
void StartEvent();
void SendContinueBroadcast(int32_t missionId, MissionEventType type);
void SendContinueBroadcast(const MissionStatus& status, MissionEventType type);
void SendContinueBroadcastAfterDelay(int32_t missionId);
int32_t ExecuteSendStrategy(MissionEventType type, const MissionStatus& status, uint8_t &sendType);
int32_t QueryBroadcastInfo(const MissionStatus& status, uint16_t& bundleNameId, uint8_t& continueTypeId);
void SendSoftbusEvent(uint16_t& bundleNameId, uint8_t& continueTypeId, uint8_t type);
void AddMMIListener();
void RemoveMMIListener();
private:
class ScreenLockedHandler {
public:
struct LastUnfoInfo {
int32_t missionId;
int32_t unfoTime;
MissionStatus status;
};
ScreenLockedHandler() = default;
explicit ScreenLockedHandler(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr);
virtual ~ScreenLockedHandler() = default;
int32_t GetMissionId();
MissionStatus GetMissionStatus();
void OnDeviceScreenLocked();
void ResetScreenLockedInfo();
void SetScreenLockedInfo(LastUnfoInfo info);
private:
LastUnfoInfo unfoInfo_;
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
};
int32_t SendScreenLockedEvent(uint8_t type);
void PostScreenLockedEventAfterDelay(int32_t missionId, uint8_t type, int32_t timeout);
private:
int32_t accountId_ = DEFAULT_USER;
int32_t mmiMonitorId_ = INVALID_ID;
std::thread eventThread_;
std::condition_variable eventCon_;
std::mutex eventMutex_;
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
std::shared_ptr<ScreenLockedHandler> screenLockedHandler_;
std::map<MissionEventType, std::shared_ptr<ContinueSendStrategy>> strategyMap_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // DMS_CONTINUE_SEND_MANAGER_H

View File

@ -0,0 +1,109 @@
/*
* 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_DMS_CONTINUE_SEND_STRATEGY_H
#define OHOS_DMS_CONTINUE_SEND_STRATEGY_H
#include <string>
#include "mission/dms_continue_condition_manager.h"
namespace OHOS {
namespace DistributedSchedule {
class DMSContinueSendMgr;
class ContinueSendStrategy {
public:
ContinueSendStrategy() = default;
virtual ~ContinueSendStrategy() = default;
virtual int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const = 0;
};
class ContinueSendContext {
public:
ContinueSendContext() = default;
void SetStrategy(std::shared_ptr<ContinueSendStrategy> strategy);
int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const;
private:
std::shared_ptr<ContinueSendStrategy> strategy_;
};
class SendStrategyFocused : public ContinueSendStrategy {
public:
explicit SendStrategyFocused(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr)
: dmsContinueSendMgr_(dmsContinueSendMgr) {};
int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const override;
private:
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
};
class SendStrategyUnfocused : public ContinueSendStrategy {
public:
explicit SendStrategyUnfocused(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr)
: dmsContinueSendMgr_(dmsContinueSendMgr) {};
int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const override;
private:
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
};
class SendStrategyDestoryed : public ContinueSendStrategy {
public:
explicit SendStrategyDestoryed(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr)
: dmsContinueSendMgr_(dmsContinueSendMgr) {};
int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const override;
private:
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
};
class SendStrategyActive : public ContinueSendStrategy {
public:
explicit SendStrategyActive(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr)
: dmsContinueSendMgr_(dmsContinueSendMgr) {};
int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const override;
private:
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
};
class SendStrategyInactive : public ContinueSendStrategy {
public:
explicit SendStrategyInactive(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr)
: dmsContinueSendMgr_(dmsContinueSendMgr) {};
int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const override;
private:
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
};
class SendStrategyTimeout : public ContinueSendStrategy {
public:
explicit SendStrategyTimeout(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr)
: dmsContinueSendMgr_(dmsContinueSendMgr) {};
int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const override;
private:
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
};
class SendStrategyMMI : public ContinueSendStrategy {
public:
explicit SendStrategyMMI(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr)
: dmsContinueSendMgr_(dmsContinueSendMgr) {};
int32_t ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const override;
private:
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DMS_CONTINUE_SEND_STRATEGY_H

View File

@ -19,7 +19,7 @@
#include <map>
#include "mission/dms_continue_recv_manager.h"
#include "mission/dms_continue_send_manager.h"
#include "mission/notification/dms_continue_send_manager.h"
#include "switch_status_dependency.h"
#include "single_instance.h"
@ -44,6 +44,8 @@ public:
AccountSA::OsAccountType GetOsAccountType(int32_t &accountId);
int32_t CreateNewSendMgrLocked();
int32_t CreateNewRecvMgrLocked();
int32_t CreateNewSendMgrLocked(int32_t accountId);
int32_t CreateNewRecvMgrLocked(int32_t accountId);
std::shared_ptr<DMSContinueSendMgr> GetCurrentSendMgr();
std::shared_ptr<DMSContinueRecvMgr> GetCurrentRecvMgr();
std::shared_ptr<DMSContinueSendMgr> GetSendMgrByCallingUid(int32_t callingUid);

View File

@ -20,7 +20,6 @@
#include <sys/prctl.h>
#include "dtbschedmgr_log.h"
#include "mission/dms_continue_send_manager.h"
#include "multi_user_manager.h"
namespace OHOS {

View File

@ -19,7 +19,7 @@
#include "dtbschedmgr_log.h"
#include "mission/distributed_bm_storage.h"
#include "mission/dms_continue_recv_manager.h"
#include "mission/dms_continue_send_manager.h"
#include "mission/notification/dms_continue_send_manager.h"
#include "multi_user_manager.h"
#include "os_account_manager.h"
#include "switch_status_dependency.h"
@ -93,12 +93,13 @@ void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData &eventD
void CommonEventListener::HandleScreenLocked()
{
HILOGI("SCREEN_LOCKED");
DmsContinueConditionMgr::GetInstance().UpdateSystemStatus(SYS_EVENT_SCREEN, true);
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
if (sendMgr == nullptr) {
HILOGE("SendMgr is nullptr.");
return;
}
sendMgr->OnDeviceScreenOff();
sendMgr->OnDeviceScreenLocked();
}
void CommonEventListener::HandleScreenOff()
@ -115,12 +116,7 @@ void CommonEventListener::HandleScreenOff()
void CommonEventListener::HandleScreenUnLocked()
{
HILOGI("SCREEN_UNLOCKED");
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
if (sendMgr == nullptr) {
HILOGE("SendMgr is nullptr.");
return;
}
sendMgr->OnDeviceScreenOn();
DmsContinueConditionMgr::GetInstance().UpdateSystemStatus(SYS_EVENT_SCREEN, false);
}
void CommonEventListener::HandleScreenOn()
@ -176,4 +172,4 @@ int32_t CommonEventListener::GetForegroundOsAccountLocalId()
return accountId;
}
} // namespace DistributedSchedule
} // namespace OHOS
} // namespace OHOS

View File

@ -41,7 +41,7 @@
#include "ipc_skeleton.h"
#include "parcel_helper.h"
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
#include "mission/dms_continue_send_manager.h"
#include "mission/dms_continue_condition_manager.h"
#endif
#include "scene_board_judgement.h"
#include "softbus_adapter/transport/dsched_transport_softbus_adapter.h"
@ -121,8 +121,8 @@ const std::map<int32_t, int32_t> DSchedContinue::DMS_CONVERT_TO_SDK_ERR_MAP = {
};
DSchedContinue::DSchedContinue(int32_t subServiceType, int32_t direction, const sptr<IRemoteObject>& callback,
const DSchedContinueInfo& continueInfo) : subServiceType_(subServiceType), direction_(direction),
continueInfo_(continueInfo), callback_(callback)
const DSchedContinueInfo& continueInfo, int32_t accountId) : subServiceType_(subServiceType), direction_(direction),
continueInfo_(continueInfo), callback_(callback), accountId_(accountId)
{
HILOGI("DSchedContinue create");
version_ = DSCHED_CONTINUE_PROTOCOL_VERSION;
@ -132,7 +132,7 @@ DSchedContinue::DSchedContinue(int32_t subServiceType, int32_t direction, const
NotifyDSchedEventResult(ERR_OK);
}
DSchedContinue::DSchedContinue(std::shared_ptr<DSchedContinueStartCmd> startCmd, int32_t sessionId)
DSchedContinue::DSchedContinue(std::shared_ptr<DSchedContinueStartCmd> startCmd, int32_t sessionId, int32_t accountId)
{
HILOGI("DSchedContinue create by start command");
if (startCmd == nullptr) {
@ -162,6 +162,7 @@ DSchedContinue::DSchedContinue(std::shared_ptr<DSchedContinueStartCmd> startCmd,
continueInfo_.sourceBundleName_ = missionInfo.want.GetBundle();
continueInfo_.sinkBundleName_ = missionInfo.want.GetBundle();
}
accountId_ = accountId;
}
DSchedContinue::~DSchedContinue()
@ -698,12 +699,8 @@ int32_t DSchedContinue::GetMissionIdByBundleName()
{
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
if (continueInfo_.missionId_ == 0) {
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
if (sendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return DMS_NOT_GET_MANAGER;
}
return sendMgr->GetMissionIdByBundleName(continueInfo_.sourceBundleName_, continueInfo_.missionId_);
return DmsContinueConditionMgr::GetInstance().GetMissionIdByBundleName(
accountId_, continueInfo_.sourceBundleName_, continueInfo_.missionId_);
}
#endif
return ERR_OK;
@ -1021,18 +1018,11 @@ int32_t DSchedContinue::StartAbility(const OHOS::AAFwk::Want& want, int32_t requ
return ret;
}
int32_t activeAccountId = 0;
ret = DistributedSchedService::GetInstance().QueryOsAccount(activeAccountId);
if (ret != ERR_OK) {
HILOGE("QueryOsAccount failed %{public}d", ret);
return ret;
}
continueInfo_.sinkAbilityName_ = want.GetElement().GetAbilityName();
DmsRadar::GetInstance().ClickIconDmsStartAbility("StartAbility", ret);
HILOGI("call StartAbility start, flag is %{public}d", want.GetFlags());
ret = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, DEFAULT_REQUEST_CODE, activeAccountId);
ret = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, DEFAULT_REQUEST_CODE, accountId_);
if (ret != ERR_OK) {
HILOGE("failed %{public}d", ret);
return ret;

View File

@ -27,8 +27,7 @@
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "mission/distributed_bm_storage.h"
#include "mission/dms_continue_send_manager.h"
#include "mission/dms_continue_recv_manager.h"
#include "mission/dms_continue_condition_manager.h"
#include "multi_user_manager.h"
namespace OHOS {
@ -209,15 +208,12 @@ int32_t DSchedContinueManager::ContinueMission(const DSchedContinueInfo& continu
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
if (localDevId == srcDeviceId) {
int32_t missionId = -1;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
if (sendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return DMS_NOT_GET_MANAGER;
}
int32_t ret = sendMgr->GetMissionIdByBundleName(continueInfo.sinkBundleName_, missionId);
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
int32_t ret = DmsContinueConditionMgr::GetInstance().GetMissionIdByBundleName(
currentAccountId, continueInfo.sinkBundleName_, missionId);
if (ret != ERR_OK) {
HILOGE("get missionId fail, ret %{public}d.", ret);
return INVALID_PARAMETERS_ERR;
return ret;
}
}
#endif
@ -313,7 +309,8 @@ void DSchedContinueManager::HandleContinueMissionWithBundleName(DSchedContinueIn
HILOGE("a same continue task is already in progress.");
return;
}
auto newContinue = std::make_shared<DSchedContinue>(subType, direction, callback, info);
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
auto newContinue = std::make_shared<DSchedContinue>(subType, direction, callback, info, currentAccountId);
newContinue->Init();
continues_.insert(std::make_pair(info, newContinue));
#ifdef DMSFWK_ALL_CONNECT_MGR
@ -519,19 +516,21 @@ void DSchedContinueManager::NotifyTerminateContinuation(const int32_t missionId)
return;
}
ContinueLaunchMissionInfo missionInfo;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
if (sendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return;
}
int32_t ret = sendMgr->GetContinueLaunchMissionInfo(missionId, missionInfo);
MissionStatus status;
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
int32_t ret = DmsContinueConditionMgr::GetInstance().GetMissionStatus(currentAccountId, missionId, status);
if (ret != ERR_OK) {
HILOGE("get continueLaunchMissionInfo failed, missionId %{public}d", missionId);
return;
}
auto flag = status.launchFlag;
if ((flag & AAFwk::Want::FLAG_ABILITY_CONTINUATION) != AAFwk::Want::FLAG_ABILITY_CONTINUATION &&
(flag & AAFwk::Want::FLAG_ABILITY_PREPARE_CONTINUATION) != AAFwk::Want::FLAG_ABILITY_PREPARE_CONTINUATION) {
HILOGI("missionId %{public}d not start by continue, ignore", missionId);
return;
}
HILOGI("alive missionInfo bundleName is %{public}s, abilityName is %{public}s",
missionInfo.bundleName.c_str(), missionInfo.abilityName.c_str());
status.bundleName.c_str(), status.abilityName.c_str());
for (auto iter = continues_.begin(); iter != continues_.end(); iter++) {
if (iter->second == nullptr) {
break;
@ -540,9 +539,9 @@ void DSchedContinueManager::NotifyTerminateContinuation(const int32_t missionId)
auto continueInfo = iter->second->GetContinueInfo();
HILOGI("continueInfo bundleName is %{public}s, abilityName is %{public}s",
continueInfo.sinkBundleName_.c_str(), continueInfo.sinkAbilityName_.c_str());
if (missionInfo.bundleName == continueInfo.sinkBundleName_
&& missionInfo.abilityName == continueInfo.sinkAbilityName_) {
HILOGE("Excute onContinueEnd");
if (status.bundleName == continueInfo.sinkBundleName_
&& status.abilityName == continueInfo.sinkAbilityName_) {
HILOGE("Execute onContinueEnd");
iter->second->OnContinueEnd(CONTINUE_SINK_ABILITY_TERMINATED);
return;
}
@ -682,7 +681,8 @@ void DSchedContinueManager::NotifyContinueDataRecv(int32_t sessionId, int32_t co
return;
}
auto newContinue = std::make_shared<DSchedContinue>(startCmd, sessionId);
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
auto newContinue = std::make_shared<DSchedContinue>(startCmd, sessionId, currentAccountId);
newContinue->Init();
continues_.insert(std::make_pair(newContinue->GetContinueInfo(), newContinue));

View File

@ -18,8 +18,8 @@
#include "distributed_sched_utils.h"
#include "dsched_continue_manager.h"
#include "dtbschedmgr_log.h"
#include "mission/dms_continue_recv_manager.h"
#include "mission/dms_continue_send_manager.h"
#include "mission/dms_continue_condition_manager.h"
#include "mission/notification/dms_continue_send_manager.h"
#include "os_account_manager.h"
#include "switch_status_dependency.h"
@ -173,6 +173,7 @@ void DataShareManager::SetCurrentContinueSwitch(bool status)
{
HILOGD("SetCurrentContinueSwitch start, status : %{public}d", status);
isCurrentContinueSwitchOn_.store(status);
DmsContinueConditionMgr::GetInstance().UpdateSystemStatus(SYS_EVENT_CONTINUE_SWITCH, status);
}
} // namespace DistributedSchedule
} // namespace OHOS
} // namespace OHOS

View File

@ -23,7 +23,7 @@
#include "distributed_sched_utils.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "mission/dms_continue_send_manager.h"
#include "mission/notification/dms_continue_send_manager.h"
#include "multi_user_manager.h"
namespace OHOS {
@ -50,7 +50,7 @@ void DistributedDeviceNodeListener::OnDeviceOnline(const DistributedHardware::Dm
HILOGI("GetSendMgr failed.");
return;
}
sendMgr->NotifyDeviceOnline();
sendMgr->OnDeviceOnline();
}
void DistributedDeviceNodeListener::OnDeviceOffline(const DistributedHardware::DmDeviceInfo& deviceInfo)

View File

@ -72,7 +72,8 @@
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
#include "mission/distributed_bm_storage.h"
#include "mission/distributed_mission_info.h"
#include "mission/dms_continue_send_manager.h"
#include "mission/dms_continue_condition_manager.h"
#include "mission/notification/dms_continue_send_manager.h"
#include "mission/dms_continue_recv_manager.h"
#include "mission/distributed_sched_mission_manager.h"
#include "mission/dsched_sync_e2e.h"
@ -171,7 +172,9 @@ void DistributedSchedService::OnStop(const SystemAbilityOnDemandReason &stopReas
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
MultiUserManager::GetInstance().UnInit();
RemoveSystemAbilityListener(WINDOW_MANAGER_SERVICE_ID);
missionFocusedListener_->UnInit();
DistributedSchedAdapter::GetInstance().UnRegisterMissionListener(missionFocusedListener_);
DmsContinueConditionMgr::GetInstance().UnInit();
#endif
#ifdef DMSFWK_INTERACTIVE_ADAPTER
@ -322,6 +325,7 @@ bool DistributedSchedService::Init()
void DistributedSchedService::InitMissionManager()
{
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DmsContinueConditionMgr::GetInstance().Init();
if (!AddSystemAbilityListener(WINDOW_MANAGER_SERVICE_ID)) {
HILOGE("Add System Ability Listener failed!");
}
@ -340,6 +344,7 @@ void DistributedSchedService::OnAddSystemAbility(int32_t systemAbilityId, const
if (missionFocusedListener_ == nullptr) {
HILOGI("missionFocusedListener_ is nullptr.");
missionFocusedListener_ = sptr<DistributedMissionFocusedListener>(new DistributedMissionFocusedListener());
missionFocusedListener_->Init();
}
int32_t ret = DistributedSchedAdapter::GetInstance().RegisterMissionListener(missionFocusedListener_);
if (ret != ERR_OK) {
@ -347,15 +352,15 @@ void DistributedSchedService::OnAddSystemAbility(int32_t systemAbilityId, const
}
}
void DistributedSchedService::InitDataShareManager()
void DistributedSchedService::RegisterDataShareObserver(const std::string& key)
{
HILOGI("RegisterObserver start.");
DataShareManager::ObserverCallback observerCallback = [this]() {
dataShareManager.SetCurrentContinueSwitch(SwitchStatusDependency::GetInstance().IsContinueSwitchOn());
HILOGD("dsMgr IsCurrentContinueSwitchOn : %{public}d", dataShareManager.IsCurrentContinueSwitchOn());
int32_t missionId = GetCurrentMissionId();
if (missionId <= 0) {
HILOGW("GetCurrentMissionId failed, init end. ret: %{public}d", missionId);
return;
}
DmsUE::GetInstance().ChangedSwitchState(dataShareManager.IsCurrentContinueSwitchOn(), ERR_OK);
if (dataShareManager.IsCurrentContinueSwitchOn()) {
@ -364,7 +369,7 @@ void DistributedSchedService::InitDataShareManager()
HILOGI("GetSendMgr failed.");
return;
}
sendMgr->NotifyMissionFocused(missionId, FocusedReason::INIT);
sendMgr->OnMissionStatusChanged(missionId, MISSION_EVENT_FOCUSED);
DSchedContinueManager::GetInstance().Init();
} else {
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
@ -372,7 +377,7 @@ void DistributedSchedService::InitDataShareManager()
HILOGI("GetSendMgr failed.");
return;
}
sendMgr->NotifyMissionUnfocused(missionId, UnfocusedReason::NORMAL);
sendMgr->OnMissionStatusChanged(missionId, MISSION_EVENT_UNFOCUSED);
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
if (recvMgr == nullptr) {
HILOGI("GetRecvMgr failed.");
@ -382,10 +387,15 @@ void DistributedSchedService::InitDataShareManager()
DSchedContinueManager::GetInstance().UnInit();
};
};
dataShareManager.RegisterObserver(key, observerCallback);
HILOGI("RegisterObserver end.");
}
void DistributedSchedService::InitDataShareManager()
{
dataShareManager.SetCurrentContinueSwitch(SwitchStatusDependency::GetInstance().IsContinueSwitchOn());
HILOGD("dsMgr IsCurrentContinueSwitchOn : %{public}d", dataShareManager.IsCurrentContinueSwitchOn());
dataShareManager.RegisterObserver(SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_STATUS_KEY,
observerCallback);
RegisterDataShareObserver(SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_STATUS_KEY);
DmsUE::GetInstance().OriginalSwitchState(SwitchStatusDependency::GetInstance().IsContinueSwitchOn(), ERR_OK);
HILOGI("Init data share manager, register observer end.");
}
@ -1119,7 +1129,9 @@ int32_t DistributedSchedService::ProcessContinueLocalMission(const std::string&
HILOGI("GetSendMgr failed.");
return DMS_NOT_GET_MANAGER;
}
int32_t ret = sendMgr->GetMissionIdByBundleName(bundleName, missionId);
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
int32_t ret =
DmsContinueConditionMgr::GetInstance().GetMissionIdByBundleName(currentAccountId, bundleName, missionId);
if (ret != ERR_OK) {
HILOGE("get missionId failed");
return ret;
@ -2980,12 +2992,19 @@ int32_t DistributedSchedService::SetMissionContinueState(int32_t missionId, cons
HILOGW("The current user is not foreground. callingUid: %{public}d.", callingUid);
return DMS_NOT_FOREGROUND_USER;
}
auto event = (state == AAFwk::ContinueState::CONTINUESTATE_ACTIVE) ?
MISSION_EVENT_ACTIVE: MISSION_EVENT_INACTIVE;
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
DmsContinueConditionMgr::GetInstance().UpdateMissionStatus(currentAccountId, missionId, event);
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
if (sendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return DMS_NOT_GET_MANAGER;
}
return sendMgr->SetMissionContinueState(missionId, state);
sendMgr->OnMissionStatusChanged(missionId, event);
return ERR_OK;
}
#endif

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
@ -15,11 +15,13 @@
#include "mission/distributed_mission_focused_listener.h"
#include <sys/prctl.h>
#include "continue/dsched_continue_manager.h"
#include "dfx/distributed_radar.h"
#include "dtbschedmgr_log.h"
#include "ipc_skeleton.h"
#include "mission/dms_continue_send_manager.h"
#include "mission/notification/dms_continue_send_manager.h"
#include "multi_user_manager.h"
namespace OHOS {
@ -27,6 +29,55 @@ namespace DistributedSchedule {
namespace {
const std::string TAG = "DistributedMissionFocusedListener";
}
void DistributedMissionFocusedListener::Init()
{
HILOGI("Init start");
if (eventHandler_ != nullptr) {
HILOGI("Already inited, end.");
return;
}
{
eventThread_ = std::thread(&DistributedMissionFocusedListener::StartEvent, this);
std::unique_lock<std::mutex> lock(eventMutex_);
eventCon_.wait(lock, [this] {
return eventHandler_ != nullptr;
});
}
HILOGI("Init end");
}
void DistributedMissionFocusedListener::StartEvent()
{
HILOGI("StartEvent start");
prctl(PR_SET_NAME, TAG.c_str());
auto runner = AppExecFwk::EventRunner::Create(false);
{
std::lock_guard<std::mutex> lock(eventMutex_);
eventHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner);
}
eventCon_.notify_one();
CHECK_POINTER_RETURN(runner, "runner");
runner->Run();
HILOGI("StartEvent end");
}
void DistributedMissionFocusedListener::UnInit()
{
HILOGI("UnInit start");
if (eventHandler_ != nullptr && eventHandler_->GetEventRunner() != nullptr) {
eventHandler_->GetEventRunner()->Stop();
if (eventThread_.joinable()) {
eventThread_.join();
}
eventHandler_ = nullptr;
} else {
HILOGE("eventHandler_ is nullptr");
}
HILOGI("UnInit end");
}
void DistributedMissionFocusedListener::OnMissionCreated(int32_t missionId)
{
HILOGD("OnMissionCreated, missionId = %{public}d", missionId);
@ -40,15 +91,18 @@ void DistributedMissionFocusedListener::OnMissionDestroyed(int32_t missionId)
HILOGW("Current process is not foreground. callingUid = %{public}d", callingUid);
return;
}
auto feedfunc = [this, missionId, callingUid]() {
DSchedContinueManager::GetInstance().NotifyTerminateContinuation(missionId);
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
CHECK_POINTER_RETURN(sendMgr, "sendMgr");
sendMgr->OnMissionStatusChanged(missionId, MISSION_EVENT_DESTORYED);
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
if (sendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return;
}
sendMgr->NotifyMissionUnfocused(missionId, UnfocusedReason::DESTORY);
DSchedContinueManager::GetInstance().NotifyTerminateContinuation(missionId);
sendMgr->DeleteContinueLaunchMissionInfo(missionId);
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
DmsContinueConditionMgr::GetInstance().UpdateMissionStatus(
currentAccountId, missionId, MISSION_EVENT_DESTORYED);
};
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->PostTask(feedfunc);
}
void DistributedMissionFocusedListener::OnMissionSnapshotChanged(int32_t missionId)
@ -70,12 +124,16 @@ void DistributedMissionFocusedListener::OnMissionFocused(int32_t missionId)
return;
}
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
if (sendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return;
}
sendMgr->NotifyMissionFocused(missionId, FocusedReason::NORMAL);
auto feedfunc = [this, missionId, callingUid]() {
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
DmsContinueConditionMgr::GetInstance().UpdateMissionStatus(currentAccountId, missionId, MISSION_EVENT_FOCUSED);
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
CHECK_POINTER_RETURN(sendMgr, "sendMgr");
sendMgr->OnMissionStatusChanged(missionId, MISSION_EVENT_FOCUSED);
};
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->PostTask(feedfunc);
}
void DistributedMissionFocusedListener::OnMissionUnfocused(int32_t missionId)
@ -87,12 +145,17 @@ void DistributedMissionFocusedListener::OnMissionUnfocused(int32_t missionId)
return;
}
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
if (sendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return;
}
sendMgr->NotifyMissionUnfocused(missionId, UnfocusedReason::NORMAL);
auto feedfunc = [this, missionId, callingUid]() {
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
CHECK_POINTER_RETURN(sendMgr, "sendMgr");
sendMgr->OnMissionStatusChanged(missionId, MISSION_EVENT_UNFOCUSED);
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
DmsContinueConditionMgr::GetInstance().UpdateMissionStatus(
currentAccountId, missionId, MISSION_EVENT_UNFOCUSED);
};
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->PostTask(feedfunc);
}
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
@ -111,12 +174,17 @@ void DistributedMissionFocusedListener::OnMissionClosed(int32_t missionId)
return;
}
auto feedfunc = [this, missionId, callingUid]() {
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
if (sendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return;
}
sendMgr->NotifyMissionUnfocused(missionId, UnfocusedReason::CLOSE);
CHECK_POINTER_RETURN(sendMgr, "sendMgr");
sendMgr->OnMissionStatusChanged(missionId, MISSION_EVENT_DESTORYED);
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
DmsContinueConditionMgr::GetInstance().UpdateMissionStatus(
currentAccountId, missionId, MISSION_EVENT_DESTORYED);
};
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->PostTask(feedfunc);
}
void DistributedMissionFocusedListener::OnMissionLabelUpdated([[maybe_unused]]int32_t missionId)

View File

@ -0,0 +1,584 @@
/*
* 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 "mission/dms_continue_condition_manager.h"
#include "ability_manager_client.h"
#include "datashare_manager.h"
#include "dtbschedmgr_log.h"
#include "mission_info.h"
#include "mission/dsched_sync_e2e.h"
#include "mission/wifi_state_adapter.h"
#include "multi_user_manager.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DmsContinueConditionMgr";
constexpr int32_t GET_MAX_MISSIONS = 50;
constexpr int32_t CONDITION_INVALID_MISSION_ID = -1;
}
IMPLEMENT_SINGLE_INSTANCE(DmsContinueConditionMgr);
void DmsContinueConditionMgr::Init()
{
InitConditionFuncs();
InitSystemCondition();
InitMissionCondition();
}
void DmsContinueConditionMgr::UnInit()
{
std::lock_guard<std::mutex> missionlock(missionMutex_);
missionMap_.clear();
}
void DmsContinueConditionMgr::InitConditionFuncs()
{
sysFuncMap_[SYS_EVENT_CONTINUE_SWITCH] = &DmsContinueConditionMgr::SetIsContinueSwitchOn;
sysFuncMap_[SYS_EVENT_WIFI] = &DmsContinueConditionMgr::SetIsWifiActive;
sysFuncMap_[SYS_EVENT_SCREEN] = &DmsContinueConditionMgr::SetIsScreenLocked;
missionFuncMap_[MISSION_EVENT_FOCUSED] = &DmsContinueConditionMgr::OnMissionFocused;
missionFuncMap_[MISSION_EVENT_UNFOCUSED] = &DmsContinueConditionMgr::OnMissionUnfocused;
missionFuncMap_[MISSION_EVENT_DESTORYED] = &DmsContinueConditionMgr::OnMissionDestory;
missionFuncMap_[MISSION_EVENT_ACTIVE] = &DmsContinueConditionMgr::OnMissionActive;
missionFuncMap_[MISSION_EVENT_INACTIVE] = &DmsContinueConditionMgr::OnMissionInactive;
conditionFuncMap_[MISSION_EVENT_FOCUSED] = &DmsContinueConditionMgr::CheckSendFocusedCondition;
conditionFuncMap_[MISSION_EVENT_UNFOCUSED] = &DmsContinueConditionMgr::CheckSendUnfocusedCondition;
conditionFuncMap_[MISSION_EVENT_DESTORYED] = &DmsContinueConditionMgr::CheckSendUnfocusedCondition;
conditionFuncMap_[MISSION_EVENT_ACTIVE] = &DmsContinueConditionMgr::CheckSendActiveCondition;
conditionFuncMap_[MISSION_EVENT_INACTIVE] = &DmsContinueConditionMgr::CheckSendInactiveCondition;
conditionFuncMap_[MISSION_EVENT_TIMEOUT] = &DmsContinueConditionMgr::CheckSendUnfocusedCondition;
conditionFuncMap_[MISSION_EVENT_MMI] = &DmsContinueConditionMgr::CheckSendFocusedCondition;
}
void DmsContinueConditionMgr::InitSystemCondition()
{
isCfgDevice_ = !DmsKvSyncE2E::GetInstance()->CheckCtrlRule();
isSwitchOn_ = DataShareManager::GetInstance().IsCurrentContinueSwitchOn();
isWifiActive_ = WifiStateAdapter::GetInstance().IsWifiActive();
HILOGI("end. cfg %{public}d, switch: %{public}d, wifi: %{public}d",
isCfgDevice_.load(), isSwitchOn_.load(), isWifiActive_.load());
}
void DmsContinueConditionMgr::InitMissionCondition()
{
int32_t currentAccountId = MultiUserManager::GetInstance().GetForegroundUser();
InitMissionStatus(currentAccountId);
}
int32_t DmsContinueConditionMgr::UpdateSystemStatus(SysEventType type, bool value)
{
auto iterFunc = sysFuncMap_.find(type);
if (iterFunc == sysFuncMap_.end()) {
HILOGE("invalid system status %{public}d", type);
return INVALID_PARAMETERS_ERR;
}
auto memberFunc = iterFunc->second;
int32_t ret = (this->*memberFunc)(value);
if (ret != ERR_OK) {
HILOGE("update system status %{public}d failed, ret: %{public}d", type, ret);
}
return ret;
}
int32_t DmsContinueConditionMgr::SetIsContinueSwitchOn(bool isSwitchOn)
{
HILOGI("isSwitchOn changed, before: %{public}d, after: %{public}d", isSwitchOn_.load(), isSwitchOn);
isSwitchOn_.store(isSwitchOn);
return ERR_OK;
}
int32_t DmsContinueConditionMgr::SetIsWifiActive(bool isWifiActive)
{
HILOGI("isWifiActive changed, before: %{public}d, after: %{public}d", isWifiActive_.load(), isWifiActive);
isWifiActive_.store(isWifiActive);
return ERR_OK;
}
int32_t DmsContinueConditionMgr::SetIsScreenLocked(bool isScreenLocked)
{
HILOGI("isScreenLocked changed, before: %{public}d, after: %{public}d", isScreenLocked_.load(), isScreenLocked);
isScreenLocked_.store(isScreenLocked);
return ERR_OK;
}
void DmsContinueConditionMgr::OnUserSwitched(int32_t accountId)
{
HILOGI("OnUserSwitched init mission status for new user: %{public}d", accountId);
InitMissionStatus(accountId);
return;
}
void DmsContinueConditionMgr::OnUserRemoved(int32_t accountId)
{
HILOGI("OnUserRemoved delete mission status for user: %{public}d", accountId);
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (missionMap_.empty()) {
return;
}
auto it = missionMap_.find(accountId);
if (it != missionMap_.end()) {
missionMap_.erase(it);
}
return;
}
int32_t DmsContinueConditionMgr::UpdateMissionStatus(int32_t accountId, int32_t missionId, MissionEventType type)
{
HILOGI("user %{public}d, missionId %{public}d, type %{public}s", accountId, missionId,
TypeEnumToString(type).c_str());
{
std::lock_guard<std::mutex> missionlock(missionMutex_);
auto missionList = missionMap_.find(accountId);
if (missionList == missionMap_.end()) {
HILOGW("no mission status records for user %{public}d", accountId);
return INVALID_PARAMETERS_ERR;
}
}
auto iterFunc = missionFuncMap_.find(type);
if (iterFunc == missionFuncMap_.end()) {
HILOGE("invalid mission status %{public}d", type);
return INVALID_PARAMETERS_ERR;
}
auto memberFunc = iterFunc->second;
int32_t ret = (this->*memberFunc)(accountId, missionId);
if (ret != ERR_OK) {
HILOGE("update mission status %{public}s failed, accountId %{public}d, missionId %{public}d, ret: %{public}d",
TypeEnumToString(type).c_str(), accountId, missionId, ret);
}
return ret;
}
void DmsContinueConditionMgr::InitMissionStatus(int32_t accountId)
{
HILOGI("InitMissionStatus for user %{public}d start", accountId);
std::vector<AAFwk::MissionInfo> missions;
int32_t ret = GetMissionInfos(missions);
if (ret != ERR_OK) {
HILOGE("GetMissionInfos failed, ret %{public}d", ret);
}
if (missions.empty()) {
HILOGW("no running mission under current user");
}
HILOGI("GetMissionInfos ret size %{public}zu", missions.size());
int32_t focusedMissionId = GetCurrentMissionId();
{
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (!missionMap_.empty() && missionMap_.find(accountId) != missionMap_.end()) {
HILOGI("mission list for user %{public}d has already been inited", accountId);
return;
}
std::map<int32_t, MissionStatus> missionList;
for (auto mission : missions) {
MissionStatus status;
ConvertToMissionStatus(mission, status);
HILOGD("mission %{public}d status: %{public}s", mission.id, status.ToString().c_str());
missionList[mission.id] = status;
}
if (focusedMissionId > 0 && missionList.count(focusedMissionId) != 0) {
missionList[focusedMissionId].isFocused = true;
}
missionMap_[accountId] = missionList;
}
HILOGI("InitMissionStatus for user %{public}d end", accountId);
return;
}
int32_t DmsContinueConditionMgr::GetMissionInfos(std::vector<AAFwk::MissionInfo>& missions)
{
auto abilityMgr = AAFwk::AbilityManagerClient::GetInstance();
if (abilityMgr == nullptr) {
HILOGE("abilityMgr is null");
return INVALID_PARAMETERS_ERR;
}
int32_t ret = abilityMgr->Connect();
if (ret != ERR_OK) {
HILOGE("get ability server failed, ret = %{public}d", ret);
return ret;
}
return abilityMgr->GetMissionInfos("", GET_MAX_MISSIONS, missions);
}
int32_t DmsContinueConditionMgr::OnMissionFocused(int32_t accountId, int32_t missionId)
{
HILOGI("accountId %{public}d, missionId %{public}d", accountId, missionId);
AAFwk::MissionInfo info;
int32_t ret = GetMissionInfo(missionId, info);
{
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (IsMissionStatusExistLocked(accountId, missionId)) {
HILOGI("found mission %{public}d, update status: isFocused", missionId);
CleanLastFocusedFlagLocked(accountId, missionId);
missionMap_[accountId][missionId].isFocused = true;
return ERR_OK;
}
if (ret != ERR_OK) {
HILOGE("GetMissionInfo failed, missionId %{public}d, ret %{public}d", missionId, ret);
return ret;
}
HILOGI("new mission %{public}d focused, add record", missionId);
MissionStatus status;
ConvertToMissionStatus(info, status);
CleanLastFocusedFlagLocked(accountId, missionId);
status.isFocused = true;
HILOGD("mission %{public}d status: %{public}s", missionId, status.ToString().c_str());
missionMap_[accountId][missionId] = status;
}
return ERR_OK;
}
int32_t DmsContinueConditionMgr::GetMissionInfo(int32_t missionId, AAFwk::MissionInfo& info)
{
auto abilityMgr = AAFwk::AbilityManagerClient::GetInstance();
if (abilityMgr == nullptr) {
HILOGE("abilityMgr is null");
return INVALID_PARAMETERS_ERR;
}
int32_t ret = abilityMgr->Connect();
if (ret != ERR_OK) {
HILOGE("get ability server failed, ret = %{public}d", ret);
return ret;
}
return abilityMgr->GetMissionInfo("", missionId, info);
}
void DmsContinueConditionMgr::ConvertToMissionStatus(const AAFwk::MissionInfo& missionInfo,
MissionStatus& status)
{
status.missionId = missionInfo.id;
status.bundleName = missionInfo.want.GetElement().GetBundleName();
status.moduleName = missionInfo.want.GetElement().GetModuleName();
status.abilityName = missionInfo.want.GetElement().GetAbilityName();
status.isContinuable = missionInfo.continuable;
status.launchFlag = missionInfo.want.GetFlags();
status.continueState = missionInfo.continueState;
return;
}
void DmsContinueConditionMgr::CleanLastFocusedFlagLocked(int32_t accountId, int32_t missionId)
{
for (auto& record : missionMap_[accountId]) {
if (record.first != missionId && record.second.isFocused) {
HILOGI("new mission %{public}d focused, mission %{public}d lose focus", missionId, record.first);
record.second.isFocused = false;
}
}
return;
}
int32_t DmsContinueConditionMgr::OnMissionUnfocused(int32_t accountId, int32_t missionId)
{
HILOGI("accountId %{public}d, missionId %{public}d", accountId, missionId);
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (!IsMissionStatusExistLocked(accountId, missionId)) {
HILOGW("mission %{public}d under user %{public}d not exist", missionId, accountId);
return CONDITION_INVALID_MISSION_ID;
}
missionMap_[accountId][missionId].isFocused = false;
HILOGI("missionMap update finished! status: %{public}s", missionMap_[accountId][missionId].ToString().c_str());
return ERR_OK;
}
int32_t DmsContinueConditionMgr::OnMissionDestory(int32_t accountId, int32_t missionId)
{
HILOGI("accountId %{public}d, missionId %{public}d", accountId, missionId);
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (!IsMissionStatusExistLocked(accountId, missionId)) {
HILOGW("mission %{public}d under user %{public}d not exist", missionId, accountId);
return ERR_OK;
}
missionMap_[accountId].erase(missionId);
HILOGI("missionMap update finished!");
return ERR_OK;
}
int32_t DmsContinueConditionMgr::OnMissionActive(int32_t accountId, int32_t missionId)
{
HILOGI("accountId %{public}d, missionId %{public}d", accountId, missionId);
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (!IsMissionStatusExistLocked(accountId, missionId)) {
HILOGW("mission %{public}d under user %{public}d not exist", missionId, accountId);
return ERR_OK;
}
missionMap_[accountId][missionId].continueState = AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
HILOGI("missionMap update finished! status: %{public}s", missionMap_[accountId][missionId].ToString().c_str());
return ERR_OK;
}
int32_t DmsContinueConditionMgr::OnMissionInactive(int32_t accountId, int32_t missionId)
{
HILOGI("accountId %{public}d, missionId %{public}d", accountId, missionId);
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (!IsMissionStatusExistLocked(accountId, missionId)) {
HILOGW("mission %{public}d under user %{public}d not exist", missionId, accountId);
return ERR_OK;
}
missionMap_[accountId][missionId].continueState = AAFwk::ContinueState::CONTINUESTATE_INACTIVE;
HILOGI("missionMap update finished! status: %{public}s", missionMap_[accountId][missionId].ToString().c_str());
return ERR_OK;
}
bool DmsContinueConditionMgr::CheckSystemSendCondition()
{
HILOGI("CheckSystemSendCondition start. cfg %{public}d, switch: %{public}d, wifi: %{public}d",
isCfgDevice_.load(), isSwitchOn_.load(), isWifiActive_.load());
std::string reason = "";
do {
if (isCfgDevice_) {
reason = "CFG_DEVICE";
break;
}
if (!isSwitchOn_) {
reason = "CONTINUE_SWITCH_OFF";
break;
}
if (!isWifiActive_) {
reason = "WIFI_INACTIVE";
break;
}
HILOGI("PASS");
return true;
} while (0);
HILOGE("FAILED, Reason: %{public}s", reason.c_str());
return false;
}
bool DmsContinueConditionMgr::CheckMissionSendCondition(const MissionStatus& status, MissionEventType type)
{
HILOGI("missionId %{public}d, type %{public}s", status.missionId, TypeEnumToString(type).c_str());
auto iterFunc = conditionFuncMap_.find(type);
if (iterFunc == conditionFuncMap_.end()) {
HILOGE("invalid system status %{public}d", type);
return false;
}
auto memberFunc = iterFunc->second;
return (this->*memberFunc)(status);
}
bool DmsContinueConditionMgr::CheckSendFocusedCondition(const MissionStatus& status)
{
HILOGI("missionId %{public}d", status.missionId);
std::string reason = "";
do {
if (!status.isContinuable) {
reason = "NOT_CONTINUABLE";
break;
}
if (status.continueState != AAFwk::ContinueState::CONTINUESTATE_ACTIVE) {
reason = "CONTINUE_STATE_INACTIVE";
break;
}
if (!DmsKvSyncE2E::GetInstance()->CheckBundleContinueConfig(status.bundleName)) {
reason = "BUNDLE_NOT_ALLOWED_IN_CFG";
break;
}
HILOGI("PASS");
return true;
} while (0);
HILOGE("FAILED, Reason: %{public}s", reason.c_str());
return false;
}
bool DmsContinueConditionMgr::CheckSendUnfocusedCondition(const MissionStatus& status)
{
HILOGI("missionId %{public}d", status.missionId);
std::string reason = "";
do {
if (!status.isFocused) {
reason = "NOT_FOCUSED";
break;
}
if (!status.isContinuable) {
reason = "NOT_CONTINUABLE";
break;
}
if (status.continueState != AAFwk::ContinueState::CONTINUESTATE_ACTIVE) {
reason = "CONTINUE_STATE_INACTIVE";
break;
}
if (!DmsKvSyncE2E::GetInstance()->CheckBundleContinueConfig(status.bundleName)) {
reason = "BUNDLE_NOT_ALLOWED_IN_CFG";
break;
}
HILOGI("PASS");
return true;
} while (0);
HILOGE("FAILED, Reason: %{public}s", reason.c_str());
return false;
}
bool DmsContinueConditionMgr::CheckSendActiveCondition(const MissionStatus& status)
{
HILOGI("missionId %{public}d", status.missionId);
std::string reason = "";
do {
if (!status.isFocused) {
reason = "NOT_FOCUSED";
break;
}
if (!status.isContinuable) {
reason = "NOT_CONTINUABLE";
break;
}
if (!DmsKvSyncE2E::GetInstance()->CheckBundleContinueConfig(status.bundleName)) {
reason = "BUNDLE_NOT_ALLOWED_IN_CFG";
break;
}
HILOGI("PASS");
return true;
} while (0);
HILOGE("FAILED, Reason: %{public}s", reason.c_str());
return false;
}
bool DmsContinueConditionMgr::CheckSendInactiveCondition(const MissionStatus& status)
{
HILOGI("missionId %{public}d", status.missionId);
std::string reason = "";
do {
if (!status.isContinuable) {
reason = "NOT_CONTINUABLE";
break;
}
if (!DmsKvSyncE2E::GetInstance()->CheckBundleContinueConfig(status.bundleName)) {
reason = "BUNDLE_NOT_ALLOWED_IN_CFG";
break;
}
HILOGI("PASS");
return true;
} while (0);
HILOGE("FAILED, Reason: %{public}s", reason.c_str());
return false;
}
int32_t DmsContinueConditionMgr::GetMissionStatus(int32_t accountId, int32_t missionId, MissionStatus& status)
{
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (!IsMissionStatusExistLocked(accountId, missionId)) {
HILOGE("mission %{public}d under user %{public}d not exist", missionId, accountId);
return INVALID_PARAMETERS_ERR;
}
status = missionMap_[accountId][missionId];
return ERR_OK;
}
bool DmsContinueConditionMgr::IsMissionStatusExistLocked(int32_t accountId, int32_t missionId)
{
if (missionMap_.count(accountId) == 0 || missionMap_[accountId].count(missionId) == 0) {
return false;
}
return true;
}
bool DmsContinueConditionMgr::IsScreenLocked()
{
return isScreenLocked_.load();
}
int32_t DmsContinueConditionMgr::GetMissionIdByBundleName(
int32_t accountId, const std::string& bundleName, int32_t& missionId)
{
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (missionMap_.count(accountId) == 0) {
HILOGE("user %{public}d not exist!", accountId);
return MISSION_NOT_FOCUSED;
}
for (const auto& record : missionMap_[accountId]) {
if (record.second.bundleName == bundleName) {
missionId = record.first;
return ERR_OK;
}
}
return MISSION_NOT_FOCUSED;
}
int32_t DmsContinueConditionMgr::GetCurrentFocusedMission(int32_t accountId)
{
int32_t missionId = CONDITION_INVALID_MISSION_ID;
{
std::lock_guard<std::mutex> missionlock(missionMutex_);
if (missionMap_.count(accountId) == 0) {
HILOGE("user %{public}d not exist!", accountId);
return missionId;
}
for (const auto& record : missionMap_[accountId]) {
if (record.second.isFocused) {
missionId = record.first;
break;
}
}
}
return missionId;
}
std::string DmsContinueConditionMgr::TypeEnumToString(MissionEventType type)
{
switch (type) {
case MISSION_EVENT_FOCUSED:
return "FOCUSED";
case MISSION_EVENT_UNFOCUSED:
return "UNFOCUSED";
case MISSION_EVENT_DESTORYED:
return "DESTORYED";
case MISSION_EVENT_ACTIVE:
return "ACTIVE";
case MISSION_EVENT_INACTIVE:
return "INACTIVE";
case MISSION_EVENT_TIMEOUT:
return "TIMEOUT";
case MISSION_EVENT_MMI:
return "MMI";
default:
return "UNDEFINED";
}
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -44,15 +44,23 @@ constexpr int32_t INDEX_2 = 2;
constexpr int32_t INDEX_3 = 3;
constexpr int32_t DBMS_RETRY_MAX_TIME = 5;
constexpr int32_t DBMS_RETRY_DELAY = 2000;
constexpr int32_t REGIST_MAX_SIZE = 1000;
const std::string TAG = "DMSContinueRecvMgr";
const std::string DBMS_RETRY_TASK = "retry_on_boradcast_task";
const std::u16string DESCRIPTOR = u"ohos.aafwk.RemoteOnListener";
const std::string QUICK_START_CONFIGURATION = "_ContinueQuickStart";
}
void DMSContinueRecvMgr::Init()
DMSContinueRecvMgr::~DMSContinueRecvMgr()
{
HILOGI("Init start");
HILOGI("~DMSContinueRecvMgr. accountId: %{public}d.", accountId_);
UnInit();
}
void DMSContinueRecvMgr::Init(int32_t accountId)
{
HILOGI("Init start. accountId: %{public}d.", accountId);
accountId_ = accountId;
if (eventHandler_ != nullptr) {
HILOGI("Already inited, end.");
return;
@ -70,10 +78,12 @@ void DMSContinueRecvMgr::Init()
void DMSContinueRecvMgr::UnInit()
{
HILOGI("UnInit start");
HILOGI("UnInit start. accountId: %{public}d.", accountId_);
if (eventHandler_ != nullptr && eventHandler_->GetEventRunner() != nullptr) {
eventHandler_->GetEventRunner()->Stop();
eventThread_.join();
if (eventThread_.joinable()) {
eventThread_.join();
}
eventHandler_ = nullptr;
} else {
HILOGE("eventHandler_ is nullptr");
@ -84,8 +94,8 @@ void DMSContinueRecvMgr::UnInit()
void DMSContinueRecvMgr::NotifyDataRecv(std::string& senderNetworkId,
uint8_t* payload, uint32_t dataLen)
{
HILOGI("NotifyDataRecv start, senderNetworkId: %{public}s, dataLen: %{public}u.",
GetAnonymStr(senderNetworkId).c_str(), dataLen);
HILOGI("NotifyDataRecv start, senderNetworkId: %{public}s, dataLen: %{public}u. accountId: %{public}d.",
GetAnonymStr(senderNetworkId).c_str(), dataLen, accountId_);
if (!DmsKvSyncE2E::GetInstance()->CheckCtrlRule()) {
HILOGE("Forbid sending and receiving");
return;
@ -121,7 +131,7 @@ void DMSContinueRecvMgr::NotifyDataRecv(std::string& senderNetworkId,
int32_t DMSContinueRecvMgr::RegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj)
{
HILOGI("RegisterOnListener start, type: %{public}s", type.c_str());
HILOGI("RegisterOnListener start, type: %{public}s. accountId: %{public}d.", type.c_str(), accountId_);
if (obj == nullptr) {
HILOGE("obj is null, type: %{public}s", type.c_str());
return INVALID_PARAMETERS_ERR;
@ -129,7 +139,7 @@ int32_t DMSContinueRecvMgr::RegisterOnListener(const std::string& type, const sp
onType_ = type;
std::lock_guard<std::mutex> registerOnListenerMapLock(eventMutex_);
auto iterItem = registerOnListener_.find(type);
if (iterItem == registerOnListener_.end()) {
if (iterItem == registerOnListener_.end() && registerOnListener_.size() < REGIST_MAX_SIZE) {
HILOGD("The itemItem does not exist in the registerOnListener_, adding, type: %{public}s", type.c_str());
std::vector<sptr<IRemoteObject>> objs;
obj->AddDeathRecipient(missionDiedListener_);
@ -153,7 +163,7 @@ int32_t DMSContinueRecvMgr::RegisterOnListener(const std::string& type, const sp
int32_t DMSContinueRecvMgr::RegisterOffListener(const std::string& type,
const sptr<IRemoteObject>& obj)
{
HILOGI("RegisterOffListener start, type: %{public}s", type.c_str());
HILOGI("RegisterOffListener start, type: %{public}s. accountId: %{public}d.", type.c_str(), accountId_);
if (obj == nullptr) {
HILOGE("obj is null, type: %{public}s", type.c_str());
return INVALID_PARAMETERS_ERR;
@ -201,6 +211,7 @@ void DMSContinueRecvMgr::StartEvent()
int32_t DMSContinueRecvMgr::VerifyBroadcastSource(const std::string& senderNetworkId, const std::string& srcBundleName,
const std::string& sinkBundleName, const std::string& continueType, const int32_t state)
{
HILOGI("accountId: %{public}d.", accountId_);
std::lock_guard<std::mutex> currentIconLock(iconMutex_);
if (state == ACTIVE) {
iconInfo_.senderNetworkId = senderNetworkId;
@ -230,6 +241,7 @@ int32_t DMSContinueRecvMgr::VerifyBroadcastSource(const std::string& senderNetwo
void DMSContinueRecvMgr::PostOnBroadcastBusiness(const std::string& senderNetworkId,
uint16_t bundleNameId, uint8_t continueTypeId, const int32_t state, const int32_t delay, const int32_t retry)
{
HILOGI("accountId: %{public}d.", accountId_);
auto feedfunc = [this, senderNetworkId, bundleNameId, continueTypeId, state, retry]() mutable {
DealOnBroadcastBusiness(senderNetworkId, bundleNameId, continueTypeId, state, retry);
};
@ -244,7 +256,7 @@ void DMSContinueRecvMgr::PostOnBroadcastBusiness(const std::string& senderNetwor
int32_t DMSContinueRecvMgr::RetryPostBroadcast(const std::string& senderNetworkId,
uint16_t bundleNameId, uint8_t continueTypeId, const int32_t state, const int32_t retry)
{
HILOGI("Retry post broadcast, current retry times %{public}d", retry);
HILOGI("Retry post broadcast, current retry times %{public}d. accountId: %{public}d.", retry, accountId_);
if (retry == DBMS_RETRY_MAX_TIME) {
HILOGE("meet max retry time!");
return INVALID_PARAMETERS_ERR;
@ -256,6 +268,7 @@ int32_t DMSContinueRecvMgr::RetryPostBroadcast(const std::string& senderNetworkI
bool DMSContinueRecvMgr::GetFinalBundleName(DmsBundleInfo &distributedBundleInfo, std::string &finalBundleName,
AppExecFwk::BundleInfo &localBundleInfo, std::string &continueType)
{
HILOGI("accountId: %{public}d", accountId_);
std::string bundleName = distributedBundleInfo.bundleName;
if (BundleManagerInternal::GetLocalBundleInfo(bundleName, localBundleInfo) == ERR_OK) {
finalBundleName = bundleName;
@ -287,6 +300,7 @@ bool DMSContinueRecvMgr::GetFinalBundleName(DmsBundleInfo &distributedBundleInfo
void DMSContinueRecvMgr::FindContinueType(const DmsBundleInfo &distributedBundleInfo,
uint8_t &continueTypeId, std::string &continueType, DmsAbilityInfo &abilityInfo)
{
HILOGI("accountId: %{public}d.", accountId_);
uint32_t pos = 0;
for (auto dmsAbilityInfo: distributedBundleInfo.dmsAbilityInfos) {
for (auto continueTypeElement: dmsAbilityInfo.continueType) {
@ -304,8 +318,8 @@ void DMSContinueRecvMgr::FindContinueType(const DmsBundleInfo &distributedBundle
int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNetworkId,
uint16_t bundleNameId, uint8_t continueTypeId, const int32_t state, const int32_t retry)
{
HILOGI("DealOnBroadcastBusiness start, senderNetworkId: %{public}s, bundleNameId: %{public}u, state: %{public}d.",
GetAnonymStr(senderNetworkId).c_str(), bundleNameId, state);
HILOGI("start, senderNetworkId: %{public}s, bundleNameId: %{public}u, state: %{public}d. accountId: %{public}d.",
GetAnonymStr(senderNetworkId).c_str(), bundleNameId, state, accountId_);
DmsBundleInfo distributedBundleInfo;
if (!DmsBmStorage::GetInstance()->GetDistributedBundleInfo(senderNetworkId, bundleNameId,
distributedBundleInfo)) {
@ -361,6 +375,7 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNet
bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo,
const std::string &srcAbilityName, const std::string &srcContinueType, bool isSameBundle)
{
HILOGI("accountId: %{public}d.", accountId_);
std::string formatSrcContinueType = ContinueTypeFormat(srcContinueType);
for (auto &abilityInfo: bundleInfo.abilityInfos) {
if (!abilityInfo.continuable) {
@ -368,7 +383,7 @@ bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundl
}
for (const auto &continueTypeItem: abilityInfo.continueType) {
HILOGI("IsBundleContinuable check: srcAbilityName:%{public}s; srcContinueType:%{public}s;"
" sinkAbilityName:%{public}s; sinkContinueType:%{public}s; isSameBundle: %{public}d",
" sinkAbilityName:%{public}s; sinkContinueType:%{public}s; isSameBundle: %{public}d ",
srcAbilityName.c_str(), srcContinueType.c_str(), abilityInfo.name.c_str(),
continueTypeItem.c_str(), isSameBundle);
if (continueTypeItem == srcContinueType || continueTypeItem == formatSrcContinueType) {
@ -385,6 +400,7 @@ bool DMSContinueRecvMgr::IsBundleContinuable(const AppExecFwk::BundleInfo& bundl
std::string DMSContinueRecvMgr::ContinueTypeFormat(const std::string &continueType)
{
HILOGI("accountId: %{public}d.", accountId_);
std::string suffix = QUICK_START_CONFIGURATION;
if (suffix.length() <= continueType.length() &&
continueType.rfind(suffix) == (continueType.length() - suffix.length())) {
@ -397,6 +413,7 @@ std::string DMSContinueRecvMgr::ContinueTypeFormat(const std::string &continueTy
void DMSContinueRecvMgr::NotifyRecvBroadcast(const sptr<IRemoteObject>& obj,
const currentIconInfo& continueInfo, const int32_t state)
{
HILOGI("accountId: %{public}d.", accountId_);
std::string networkId = continueInfo.senderNetworkId;
std::string srcBundleName = continueInfo.sourceBundleName;
std::string sinkBundleName = continueInfo.bundleName;
@ -437,7 +454,7 @@ void DMSContinueRecvMgr::NotifyRecvBroadcast(const sptr<IRemoteObject>& obj,
void DMSContinueRecvMgr::NotifyDied(const sptr<IRemoteObject>& obj)
{
HILOGI("NotifyDied start");
HILOGI("NotifyDied start. accountId: %{public}d.", accountId_);
if (obj == nullptr) {
HILOGE("obj is null");
return;
@ -464,7 +481,7 @@ void DMSContinueRecvMgr::NotifyDied(const sptr<IRemoteObject>& obj)
#ifdef SUPPORT_COMMON_EVENT_SERVICE
void DMSContinueRecvMgr::OnDeviceScreenOff()
{
HILOGI("OnDeviceScreenOff called");
HILOGI("OnDeviceScreenOff called. accountId: %{public}d.", accountId_);
auto func = [this]() {
std::string senderNetworkId;
std::string bundleName;
@ -510,6 +527,7 @@ void DMSContinueRecvMgr::OnDeviceScreenOff()
void DMSContinueRecvMgr::FindToNotifyRecvBroadcast(const std::string& senderNetworkId, const std::string& bundleName,
const std::string& continueType)
{
HILOGI("accountId: %{public}d.", accountId_);
std::lock_guard<std::mutex> registerOnListenerMapLock(eventMutex_);
auto iterItem = registerOnListener_.find(onType_);
if (iterItem == registerOnListener_.end()) {
@ -526,6 +544,7 @@ void DMSContinueRecvMgr::FindToNotifyRecvBroadcast(const std::string& senderNetw
void DMSContinueRecvMgr::OnContinueSwitchOff()
{
HILOGI("accountId: %{public}d.", accountId_);
auto func = [this]() {
std::string senderNetworkId;
std::string bundleName;
@ -556,7 +575,7 @@ void DMSContinueRecvMgr::OnContinueSwitchOff()
void DMSContinueRecvMgr::OnUserSwitch()
{
HILOGI("OnUserSwitch start.");
HILOGI("OnUserSwitch start. accountId: %{public}d.", accountId_);
std::string senderNetworkId;
std::string bundleName;
std::string continueType;
@ -581,6 +600,7 @@ void DMSContinueRecvMgr::OnUserSwitch()
void DMSContinueRecvMgr::NotifyDeviceOffline(const std::string& networkId)
{
HILOGI("accountId: %{public}d.", accountId_);
if (networkId.empty()) {
HILOGE("NotifyDeviceOffline networkId empty");
return;
@ -615,6 +635,7 @@ void DMSContinueRecvMgr::NotifyDeviceOffline(const std::string& networkId)
void DMSContinueRecvMgr::NotifyPackageRemoved(const std::string& sinkBundleName)
{
HILOGI("accountId: %{public}d.", accountId_);
if (sinkBundleName.empty()) {
HILOGE("NotifyPackageRemoved sinkBundleName empty");
return;
@ -644,6 +665,7 @@ void DMSContinueRecvMgr::NotifyPackageRemoved(const std::string& sinkBundleName)
std::string DMSContinueRecvMgr::GetContinueType(const std::string& bundleName)
{
HILOGI("accountId: %{public}d.", accountId_);
std::lock_guard<std::mutex> currentIconLock(iconMutex_);
if (iconInfo_.isEmpty()) {
HILOGW("get continueType failed, Saved iconInfo has already been cleared.");

View File

@ -0,0 +1,406 @@
/*
* 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 "mission/notification/dms_continue_send_manager.h"
#include <sys/prctl.h>
#include "adapter/mmi_adapter.h"
#include "bundle/bundle_manager_internal.h"
#include "datetime_ex.h"
#include "distributed_sched_utils.h"
#include "dsched_data_buffer.h"
#include "dtbschedmgr_log.h"
#include "mission/dms_continue_condition_manager.h"
#include "softbus_adapter/softbus_adapter.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DMSContinueSendMgr";
constexpr int32_t INDEX_0 = 0;
constexpr int32_t INDEX_1 = 1;
constexpr int32_t INDEX_2 = 2;
constexpr int32_t INDEX_3 = 3;
constexpr int32_t FOCUS_TIMEOUT_DELAY_TIME = 60000;
constexpr int32_t SCREEN_LOCK_DELAY_TIME = 10000;
constexpr int64_t SCREEN_LOCK_EVENT_INTERVAL = 500; // determines whether normal unfocused or locked
const std::string TIMEOUT_UNFOCUSED_TASK = "timeout_unfocused_task";
}
void DMSContinueSendMgr::Init(int32_t currentUserId)
{
HILOGI("Init start");
if (eventHandler_ != nullptr) {
HILOGI("Already inited, end.");
return;
}
{
screenLockedHandler_ = std::make_shared<ScreenLockedHandler>(shared_from_this());
screenLockedHandler_->ResetScreenLockedInfo();
accountId_ = currentUserId;
strategyMap_[MISSION_EVENT_FOCUSED] = std::make_shared<SendStrategyFocused>(shared_from_this());
strategyMap_[MISSION_EVENT_UNFOCUSED] = std::make_shared<SendStrategyUnfocused>(shared_from_this());
strategyMap_[MISSION_EVENT_DESTORYED] = std::make_shared<SendStrategyDestoryed>(shared_from_this());
strategyMap_[MISSION_EVENT_ACTIVE] = std::make_shared<SendStrategyActive>(shared_from_this());
strategyMap_[MISSION_EVENT_INACTIVE] = std::make_shared<SendStrategyInactive>(shared_from_this());
strategyMap_[MISSION_EVENT_TIMEOUT] = std::make_shared<SendStrategyTimeout>(shared_from_this());
strategyMap_[MISSION_EVENT_MMI] = std::make_shared<SendStrategyMMI>(shared_from_this());
eventThread_ = std::thread(&DMSContinueSendMgr::StartEvent, this);
std::unique_lock<std::mutex> lock(eventMutex_);
eventCon_.wait(lock, [this] {
return eventHandler_ != nullptr;
});
}
HILOGI("Init end");
}
void DMSContinueSendMgr::StartEvent()
{
HILOGI("StartEvent start");
prctl(PR_SET_NAME, TAG.c_str());
auto runner = AppExecFwk::EventRunner::Create(false);
{
std::lock_guard<std::mutex> lock(eventMutex_);
eventHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner);
}
eventCon_.notify_one();
CHECK_POINTER_RETURN(runner, "runner");
runner->Run();
HILOGI("StartEvent end");
}
DMSContinueSendMgr::~DMSContinueSendMgr()
{
HILOGI("~DMSContinueSendMgr, accountId: %{public}d.", accountId_);
UnInit();
}
void DMSContinueSendMgr::UnInit()
{
HILOGI("UnInit start");
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
if (eventHandler_->GetEventRunner() != nullptr) {
eventHandler_->GetEventRunner()->Stop();
if (eventThread_.joinable()) {
eventThread_.join();
}
eventHandler_ = nullptr;
}
HILOGI("UnInit end");
}
void DMSContinueSendMgr::OnMissionStatusChanged(int32_t missionId, MissionEventType type)
{
MissionStatus status;
int32_t ret = DmsContinueConditionMgr::GetInstance().GetMissionStatus(accountId_, missionId, status);
if (ret != ERR_OK) {
HILOGE("GetMissionStatus failed, ret: %{public}d, missionId %{public}d, type: %{public}s",
ret, missionId, DmsContinueConditionMgr::GetInstance().TypeEnumToString(type).c_str());
return;
}
auto feedfunc = [this, status, type]() {
SendContinueBroadcast(status, type);
};
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->RemoveTask(TIMEOUT_UNFOCUSED_TASK + std::to_string(missionId));
eventHandler_->PostTask(feedfunc);
}
void DMSContinueSendMgr::OnMMIEvent()
{
auto feedfunc = [this]() {
int32_t missionId = DmsContinueConditionMgr::GetInstance().GetCurrentFocusedMission(accountId_);
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->RemoveTask(TIMEOUT_UNFOCUSED_TASK + std::to_string(missionId));
SendContinueBroadcast(missionId, MISSION_EVENT_MMI);
};
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->PostTask(feedfunc);
}
int32_t DMSContinueSendMgr::OnDeviceOnline()
{
HILOGD("OnDeviceOnline called");
int32_t missionId = GetCurrentMissionId();
if (missionId <= 0) {
return INVALID_MISSION_ID;
}
OnMissionStatusChanged(missionId, MISSION_EVENT_FOCUSED);
return ERR_OK;
}
void DMSContinueSendMgr::OnDeviceScreenLocked()
{
HILOGI("OnDeviceScreenLocked called");
auto feedfunc = [this]() {
CHECK_POINTER_RETURN(screenLockedHandler_, "screenLockedHandler_");
screenLockedHandler_->OnDeviceScreenLocked();
};
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->PostTask(feedfunc);
}
void DMSContinueSendMgr::OnUserSwitched()
{
HILOGI("OnUserSwitched called");
auto feedfunc = [this]() {
RemoveMMIListener();
SendScreenLockedEvent(DMS_UNFOCUSED_TYPE);
};
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
eventHandler_->PostTask(feedfunc);
CHECK_POINTER_RETURN(screenLockedHandler_, "screenLockedHandler_");
std::string timeoutTaskName = TIMEOUT_UNFOCUSED_TASK + std::to_string(screenLockedHandler_->GetMissionId());
eventHandler_->RemoveTask(timeoutTaskName);
}
void DMSContinueSendMgr::SendContinueBroadcast(int32_t missionId, MissionEventType type)
{
MissionStatus status;
int32_t ret = DmsContinueConditionMgr::GetInstance().GetMissionStatus(accountId_, missionId, status);
if (ret != ERR_OK) {
HILOGE("GetMissionStatus failed, ret: %{public}d, missionId %{public}d, type: %{public}s",
ret, missionId, DmsContinueConditionMgr::GetInstance().TypeEnumToString(type).c_str());
return;
}
SendContinueBroadcast(status, type);
return;
}
void DMSContinueSendMgr::SendContinueBroadcast(const MissionStatus& status, MissionEventType type)
{
auto typeStr = DmsContinueConditionMgr::GetInstance().TypeEnumToString(type);
HILOGI("start, missionId: %{public}d, type: %{public}s", status.missionId, typeStr.c_str());
if (!DmsContinueConditionMgr::GetInstance().CheckSystemSendCondition() ||
!DmsContinueConditionMgr::GetInstance().CheckMissionSendCondition(status, type)) {
HILOGE("CheckBroadcastCondition %{public}s failed! status: %{public}s",
typeStr.c_str(), status.ToString().c_str());
return;
}
uint8_t sendType = 0;
int32_t ret = ExecuteSendStrategy(type, status, sendType);
if (ret != ERR_OK) {
HILOGE("ExecuteSendStrategy %{public}s failed, ret: %{public}d. status: %{public}s",
typeStr.c_str(), ret, status.ToString().c_str());
return;
}
uint16_t bundleNameId = 0;
uint8_t continueTypeId = 0;
ret = QueryBroadcastInfo(status, bundleNameId, continueTypeId);
if (ret != ERR_OK) {
HILOGE("QueryBroadcastInfo %{public}s failed! status: %{public}s",
typeStr.c_str(), status.ToString().c_str());
return;
}
SendSoftbusEvent(bundleNameId, continueTypeId, sendType);
HILOGI("end");
return;
}
int32_t DMSContinueSendMgr::ExecuteSendStrategy(MissionEventType type, const MissionStatus& status, uint8_t &sendType)
{
HILOGI("start, missionId: %{public}d, type: %{public}s", status.missionId,
DmsContinueConditionMgr::GetInstance().TypeEnumToString(type).c_str());
if (strategyMap_.count(type) == 0) {
HILOGE("Invalid type %{public}d!", type);
return INVALID_PARAMETERS_ERR;
}
ContinueSendContext context;
context.SetStrategy(strategyMap_[type]);
int32_t ret = context.ExecuteSendStrategy(status, sendType);
HILOGI("end, ExecuteSendStrategy ret: %{public}d", ret);
return ret;
}
int32_t DMSContinueSendMgr::QueryBroadcastInfo(
const MissionStatus& status, uint16_t& bundleNameId, uint8_t& continueTypeId)
{
if (status.bundleName.empty() || status.abilityName.empty()) {
HILOGE("bundleName or ability name is null!");
return INVALID_PARAMETERS_ERR;
}
HILOGI("start, bundleName: %{public}s, abilityName: %{public}s", status.bundleName.c_str(),
status.abilityName.c_str());
int32_t ret = BundleManagerInternal::GetBundleNameId(status.bundleName, bundleNameId);
if (ret != ERR_OK) {
HILOGE("GetBundleNameId failed, bundleName: %{public}s, ret: %{public}d", status.bundleName.c_str(), ret);
return ret;
}
ret = BundleManagerInternal::GetContinueTypeId(status.bundleName, status.abilityName, continueTypeId);
if (ret != ERR_OK) {
HILOGE("GetContinueTypeId failed, abilityName: %{public}s, ret: %{public}d", status.abilityName.c_str(), ret);
return ret;
}
HILOGI("success, bundleNameId: %{public}d, continueTypeId: %{public}d", bundleNameId, continueTypeId);
return ERR_OK;
}
void DMSContinueSendMgr::SendSoftbusEvent(uint16_t& bundleNameId, uint8_t& continueTypeId, uint8_t type)
{
HILOGI("bundleNameId: %{public}u, continueTypeId: %{public}u, sendType %{public}u",
bundleNameId, continueTypeId, type);
std::shared_ptr<DSchedDataBuffer> buffer = std::make_shared<DSchedDataBuffer>(DMS_SEND_LEN);
buffer->Data()[INDEX_0] = (type << CONTINUE_SHIFT_04) | DMS_DATA_LEN;
buffer->Data()[INDEX_1] = (bundleNameId >> CONTINUE_SHIFT_08) & DMS_0XFF;
buffer->Data()[INDEX_2] = bundleNameId & DMS_0XFF;
buffer->Data()[INDEX_3] = continueTypeId & DMS_0XFF;
SoftbusAdapter::GetInstance().SendSoftbusEvent(buffer);
}
void DMSContinueSendMgr::SendContinueBroadcastAfterDelay(int32_t missionId)
{
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
HILOGI("send continue broadcast for missionId: %{public}d after %{public}d delay",
missionId, FOCUS_TIMEOUT_DELAY_TIME);
auto func = [this, missionId]() {
SendContinueBroadcast(missionId, MISSION_EVENT_TIMEOUT);
};
std::string timeoutTaskName = TIMEOUT_UNFOCUSED_TASK + std::to_string(missionId);
eventHandler_->RemoveTask(timeoutTaskName);
eventHandler_->PostTask(func, timeoutTaskName, FOCUS_TIMEOUT_DELAY_TIME);
}
void DMSContinueSendMgr::AddMMIListener()
{
if (mmiMonitorId_ >= 0) {
HILOGD("MMI listener already exist, monitor id: %{public}d", mmiMonitorId_);
return;
}
mmiMonitorId_ = MMIAdapter::GetInstance().AddMMIListener();
if (mmiMonitorId_ < 0) {
HILOGW("Add MMI listener failed, ret: %{public}d", mmiMonitorId_);
return;
}
HILOGI("MMI listener has been added, monitor id: %{public}d", mmiMonitorId_);
}
void DMSContinueSendMgr::RemoveMMIListener()
{
if (mmiMonitorId_ < 0) {
HILOGI("No MMI listener to be removed, monitor id: %{public}d", mmiMonitorId_);
return;
}
MMIAdapter::GetInstance().RemoveMMIListener(mmiMonitorId_);
HILOGI("MMI listener has been removed, monitor id: %{public}d", mmiMonitorId_);
mmiMonitorId_ = INVALID_MISSION_ID;
return;
}
void DMSContinueSendMgr::PostScreenLockedEventAfterDelay(int32_t missionId, uint8_t type, int32_t timeout)
{
CHECK_POINTER_RETURN(eventHandler_, "eventHandler_");
auto func = [this, type]() {
SendScreenLockedEvent(type);
};
std::string timeoutTaskName = TIMEOUT_UNFOCUSED_TASK + std::to_string(missionId);
eventHandler_->RemoveTask(timeoutTaskName);
if (timeout == 0) {
eventHandler_->PostTask(func);
return;
}
eventHandler_->PostTask(func, timeoutTaskName, timeout);
}
int32_t DMSContinueSendMgr::SendScreenLockedEvent(uint8_t type)
{
HILOGI("start, type: %{public}u", type);
CHECK_POINTER_RETURN_VALUE(screenLockedHandler_, ERR_NULL_OBJECT, "screenLockedHandler_");
uint16_t bundleNameId = 0;
uint8_t continueTypeId = 0;
MissionStatus status = screenLockedHandler_->GetMissionStatus();
int32_t ret = QueryBroadcastInfo(status, bundleNameId, continueTypeId);
if (ret != ERR_OK) {
HILOGE("QueryBroadcastInfo failed, ret: %{public}d, status: %{public}s", ret, status.ToString().c_str());
return ret;
}
if (!DmsContinueConditionMgr::GetInstance().CheckSystemSendCondition()) {
HILOGE("check system send condition failed!");
return DMS_PERMISSION_DENIED;
}
SendSoftbusEvent(bundleNameId, continueTypeId, type);
HILOGI("end");
return ERR_OK;
}
DMSContinueSendMgr::ScreenLockedHandler::ScreenLockedHandler
(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr) : dmsContinueSendMgr_(dmsContinueSendMgr)
{
}
int32_t DMSContinueSendMgr::ScreenLockedHandler::GetMissionId()
{
return unfoInfo_.missionId;
}
MissionStatus DMSContinueSendMgr::ScreenLockedHandler::GetMissionStatus()
{
return unfoInfo_.status;
}
void DMSContinueSendMgr::ScreenLockedHandler::OnDeviceScreenLocked()
{
HILOGI("ScreenLockedHandler::OnDeviceScreenLocked called");
std::shared_ptr<DMSContinueSendMgr> sendMgr = dmsContinueSendMgr_.lock();
if (sendMgr == nullptr) {
HILOGW("sendMgr is nullptr.");
return;
}
if (unfoInfo_.missionId != INVALID_MISSION_ID
&& (GetTickCount()- unfoInfo_.unfoTime) < SCREEN_LOCK_EVENT_INTERVAL) {
// handle unfocus before screen locked
sendMgr->PostScreenLockedEventAfterDelay(unfoInfo_.missionId, DMS_FOCUSED_TYPE, 0);
}
sendMgr->PostScreenLockedEventAfterDelay(
unfoInfo_.missionId, DMS_UNFOCUSED_TYPE, SCREEN_LOCK_DELAY_TIME);
}
void DMSContinueSendMgr::ScreenLockedHandler::ResetScreenLockedInfo()
{
HILOGI("clear last unfocused info");
unfoInfo_.missionId = INVALID_MISSION_ID;
unfoInfo_.unfoTime = 0;
unfoInfo_.status = {};
}
void DMSContinueSendMgr::ScreenLockedHandler::SetScreenLockedInfo(LastUnfoInfo info)
{
HILOGI("set last unfocused info, missionId: %{public}d, bundleName: %{public}s, abilityName: %{public}s",
info.missionId, info.status.bundleName.c_str(), info.status.abilityName.c_str());
unfoInfo_.missionId = info.missionId;
unfoInfo_.unfoTime = GetTickCount();
unfoInfo_.status = info.status;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -0,0 +1,113 @@
/*
* 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 "mission/notification/dms_continue_send_strategy.h"
#include "dtbschedmgr_log.h"
#include "mission/notification/dms_continue_send_manager.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DmsContinueSendStrategy";
}
void ContinueSendContext::SetStrategy(std::shared_ptr<ContinueSendStrategy> strategy)
{
strategy_ = strategy;
}
int32_t ContinueSendContext::ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const
{
CHECK_POINTER_RETURN_VALUE(strategy_, ERR_NULL_OBJECT, "strategy_");
return strategy_->ExecuteSendStrategy(status, sendType);
}
int32_t SendStrategyFocused::ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const
{
std::shared_ptr<DMSContinueSendMgr> sendMgr = dmsContinueSendMgr_.lock();
CHECK_POINTER_RETURN_VALUE(sendMgr, ERR_NULL_OBJECT, "dmsContinueSendMgr_");
sendMgr->AddMMIListener();
sendMgr->SendContinueBroadcastAfterDelay(status.missionId);
CHECK_POINTER_RETURN_VALUE(sendMgr->screenLockedHandler_, ERR_OK, "screenLockedHandler_");
sendMgr->screenLockedHandler_->ResetScreenLockedInfo();
sendType = BROADCAST_TYPE_APPEAR;
return ERR_OK;
}
int32_t SendStrategyUnfocused::ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const
{
std::shared_ptr<DMSContinueSendMgr> sendMgr = dmsContinueSendMgr_.lock();
CHECK_POINTER_RETURN_VALUE(sendMgr, ERR_NULL_OBJECT, "dmsContinueSendMgr_");
sendMgr->RemoveMMIListener();
sendType = BROADCAST_TYPE_DISAPPEAR;
DMSContinueSendMgr::ScreenLockedHandler::LastUnfoInfo info = { status.missionId, 0, status };
CHECK_POINTER_RETURN_VALUE(sendMgr->screenLockedHandler_, ERR_OK, "screenLockedHandler_");
sendMgr->screenLockedHandler_->SetScreenLockedInfo(info);
if (DmsContinueConditionMgr::GetInstance().IsScreenLocked()) {
HILOGW("already screenLocked, task abort");
return DMS_PERMISSION_DENIED;
}
return ERR_OK;
}
int32_t SendStrategyDestoryed::ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const
{
std::shared_ptr<DMSContinueSendMgr> sendMgr = dmsContinueSendMgr_.lock();
CHECK_POINTER_RETURN_VALUE(sendMgr, ERR_NULL_OBJECT, "dmsContinueSendMgr_");
sendMgr->RemoveMMIListener();
sendType = BROADCAST_TYPE_DISAPPEAR;
return ERR_OK;
}
int32_t SendStrategyActive::ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const
{
std::shared_ptr<DMSContinueSendMgr> sendMgr = dmsContinueSendMgr_.lock();
CHECK_POINTER_RETURN_VALUE(sendMgr, ERR_NULL_OBJECT, "dmsContinueSendMgr_");
sendMgr->AddMMIListener();
sendMgr->SendContinueBroadcastAfterDelay(status.missionId);
sendType = BROADCAST_TYPE_APPEAR;
return ERR_OK;
}
int32_t SendStrategyInactive::ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const
{
std::shared_ptr<DMSContinueSendMgr> sendMgr = dmsContinueSendMgr_.lock();
CHECK_POINTER_RETURN_VALUE(sendMgr, ERR_NULL_OBJECT, "dmsContinueSendMgr_");
sendMgr->RemoveMMIListener();
sendType = BROADCAST_TYPE_DISAPPEAR;
return ERR_OK;
}
int32_t SendStrategyTimeout::ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const
{
sendType = BROADCAST_TYPE_DISAPPEAR;
return ERR_OK;
}
int32_t SendStrategyMMI::ExecuteSendStrategy(const MissionStatus& status, uint8_t &sendType) const
{
sendType = BROADCAST_TYPE_APPEAR;
return ERR_OK;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "mission/dms_continue_condition_manager.h"
#include "mission/wifi_state_adapter.h"
#include "dtbschedmgr_log.h"
@ -32,6 +33,7 @@ bool WifiStateAdapter::IsWifiActive()
void WifiStateAdapter::UpdateWifiState(bool isWifiActive)
{
isWifiActive_ = isWifiActive;
DmsContinueConditionMgr::GetInstance().UpdateSystemStatus(SYS_EVENT_WIFI, isWifiActive_);
}
} // namespace DistributedSchedule
} // namespace OHOS
} // namespace OHOS

View File

@ -16,39 +16,37 @@
#include "adapter/mmi_adapter.h"
#include "datashare_manager.h"
#include "dsched_continue_manager.h"
#include "distributed_sched_service.h"
#include "distributed_sched_utils.h"
#include "dtbschedmgr_log.h"
#include "mission/distributed_sched_mission_manager.h"
#include "mission/dms_continue_condition_manager.h"
#include "softbus_adapter/softbus_adapter.h"
#include "os_account_manager.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
constexpr static uint8_t DMS_UNFOCUSED_TYPE = 0x01;
constexpr static int32_t INVALID_ID = 0;
const std::string TAG = "MultiUserManager";
}
MultiUserManager& MultiUserManager::GetInstance()
{
static auto instance = new MultiUserManager();
return *instance;
static MultiUserManager instance;
return instance;
}
MultiUserManager::MultiUserManager()
{
HILOGI("Start.");
if (currentUserId_ <= 0) {
Init();
}
currentUserId_ = GetForegroundUser();
}
void MultiUserManager::Init()
{
HILOGI("Init start.");
currentUserId_ = GetForegroundUser();
MMIAdapter::GetInstance().Init();
SoftbusAdapter::GetInstance().Init();
auto sendMgr = GetCurrentSendMgr();
@ -64,6 +62,7 @@ void MultiUserManager::Init()
if (!CheckRegSoftbusListener()) {
RegisterSoftbusListener();
}
sendMgr->OnDeviceOnline();
HILOGI("Init end.");
}
@ -82,7 +81,6 @@ void MultiUserManager::UnInit()
sendMgrMap_.erase(it++);
continue;
}
it->second->UnInit();
sendMgrMap_.erase(it++);
}
}
@ -96,7 +94,6 @@ void MultiUserManager::UnInit()
recvMgrMap_.erase(it++);
continue;
}
it->second->UnInit();
recvMgrMap_.erase(it++);
}
}
@ -107,19 +104,18 @@ void MultiUserManager::UnInit()
void MultiUserManager::OnUserSwitched(int32_t accountId)
{
HILOGI("UserSwitched start");
auto recvMgr = GetCurrentRecvMgr();
if (recvMgr == nullptr) {
auto oldRecvMgr = GetCurrentRecvMgr();
if (oldRecvMgr == nullptr) {
HILOGI("GetRecvMgr failed.");
return;
}
recvMgr->OnUserSwitch();
auto sendMgr = GetCurrentSendMgr();
if (sendMgr == nullptr) {
oldRecvMgr->OnUserSwitch();
auto oldSendMgr = GetCurrentSendMgr();
if (oldSendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return;
}
sendMgr->SendScreenOffEvent(DMS_UNFOCUSED_TYPE);
sendMgr->UserSwitchedRemoveMMIListener();
oldSendMgr->OnUserSwitched();
currentUserId_ = accountId;
AccountSA::OsAccountType type = GetOsAccountType(currentUserId_);
@ -132,22 +128,29 @@ void MultiUserManager::OnUserSwitched(int32_t accountId)
DataShareManager::GetInstance().SetCurrentContinueSwitch(SwitchStatusDependency::GetInstance()
.IsContinueSwitchOn());
sendMgr = GetCurrentSendMgr();
if (sendMgr == nullptr) {
DistributedSchedService::GetInstance()
.RegisterDataShareObserver(SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_STATUS_KEY);
auto newSendMgr = GetCurrentSendMgr();
if (newSendMgr == nullptr) {
HILOGI("GetSendMgr failed.");
return;
}
recvMgr = GetCurrentRecvMgr();
if (recvMgr == nullptr) {
auto newRecvMgr = GetCurrentRecvMgr();
if (newRecvMgr == nullptr) {
HILOGI("GetRecvMgr failed.");
return;
}
if (!DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) {
recvMgr->OnContinueSwitchOff();
if (DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) {
newSendMgr->OnDeviceOnline();
DSchedContinueManager::GetInstance().Init();
} else {
newRecvMgr->OnContinueSwitchOff();
HILOGI("ICurrentContinueSwitch is off, %{public}d", DataShareManager::GetInstance()
.IsCurrentContinueSwitchOn());
DSchedContinueManager::GetInstance().UnInit();
};
UserSwitchedOnRegisterListenerCache();
DmsContinueConditionMgr::GetInstance().OnUserSwitched(accountId);
HILOGI("UserSwitched end");
}
@ -186,9 +189,6 @@ void MultiUserManager::OnUserRemoved(int32_t accountId)
if (!sendMgrMap_.empty()) {
auto it = sendMgrMap_.find(accountId);
if (it != sendMgrMap_.end()) {
if (it->second != nullptr) {
it->second->UnInit();
}
sendMgrMap_.erase(it);
}
}
@ -198,13 +198,11 @@ void MultiUserManager::OnUserRemoved(int32_t accountId)
if (!recvMgrMap_.empty()) {
auto it = recvMgrMap_.find(accountId);
if (it != recvMgrMap_.end()) {
if (it->second != nullptr) {
it->second->UnInit();
}
recvMgrMap_.erase(it);
}
}
}
DmsContinueConditionMgr::GetInstance().OnUserRemoved(accountId);
HILOGI("UserRemoved end");
}
@ -222,7 +220,7 @@ int32_t MultiUserManager::CreateNewSendMgrLocked()
{
HILOGI("CreateNewSendMgr begin. accountId: %{public}d.", currentUserId_);
auto sendMgr = std::make_shared<DMSContinueSendMgr>();
sendMgr->Init();
sendMgr->Init(currentUserId_);
sendMgrMap_.emplace(currentUserId_, sendMgr);
HILOGI("CreateNewSendMgr end.");
return ERR_OK;
@ -232,12 +230,32 @@ int32_t MultiUserManager::CreateNewRecvMgrLocked()
{
HILOGI("CreateNewRecvMgr begin. accountId: %{public}d.", currentUserId_);
auto recvMgr = std::make_shared<DMSContinueRecvMgr>();
recvMgr->Init();
recvMgr->Init(currentUserId_);
recvMgrMap_.emplace(currentUserId_, recvMgr);
HILOGI("CreateNewRecvMgr end.");
return ERR_OK;
}
int32_t MultiUserManager::CreateNewSendMgrLocked(int32_t accountId)
{
HILOGI("CreateNewSendMgr by accountid begin. accountId: %{public}d.", accountId);
auto sendMgr = std::make_shared<DMSContinueSendMgr>();
sendMgr->Init(accountId);
sendMgrMap_.emplace(accountId, sendMgr);
HILOGI("CreateNewSendMgr by accountid end.");
return ERR_OK;
}
int32_t MultiUserManager::CreateNewRecvMgrLocked(int32_t accountId)
{
HILOGI("CreateNewRecvMgr by accountid begin. accountId: %{public}d.", accountId);
auto recvMgr = std::make_shared<DMSContinueRecvMgr>();
recvMgr->Init(accountId);
recvMgrMap_.emplace(accountId, recvMgr);
HILOGI("CreateNewRecvMgr by accountid end.");
return ERR_OK;
}
std::shared_ptr<DMSContinueSendMgr> MultiUserManager::GetCurrentSendMgr()
{
HILOGI("GetCurrentSendMgr. accountId: %{public}d.", currentUserId_);
@ -270,7 +288,7 @@ std::shared_ptr<DMSContinueSendMgr> MultiUserManager::GetSendMgrByCallingUid(int
std::lock_guard<std::mutex> lock(sendMutex_);
if (sendMgrMap_.empty() || sendMgrMap_.find(accountId) == sendMgrMap_.end()) {
HILOGI("sendMgr need to create.");
CreateNewSendMgrLocked();
CreateNewSendMgrLocked(accountId);
}
auto cur = sendMgrMap_.find(accountId);
return cur->second;
@ -284,7 +302,7 @@ std::shared_ptr<DMSContinueRecvMgr> MultiUserManager::GetRecvMgrByCallingUid(int
std::lock_guard<std::mutex> lock(recvMutex_);
if (recvMgrMap_.empty() || recvMgrMap_.find(accountId) == recvMgrMap_.end()) {
HILOGI("recvMgr need to create.");
CreateNewRecvMgrLocked();
CreateNewRecvMgrLocked(accountId);
}
auto cur = recvMgrMap_.find(accountId);
return cur->second;

View File

@ -138,7 +138,7 @@ HWTEST_F(DSchedContinueManagerTest, ContinueMission_002, TestSize.Level3)
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, "", MISSION_ID, callback, wantParams);
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
nullptr, wantParams);
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true)).WillOnce(Return(true));
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
callback, wantParams);
@ -550,7 +550,7 @@ HWTEST_F(DSchedContinueManagerTest, GetDSchedContinueByWant_002, TestSize.Level3
usleep(WAITTIME);
DSchedContinueManager::GetInstance().continues_[info] = nullptr;
DSchedContinueManager::GetInstance().continues_[info] = dContinue;
DSchedContinueManager::GetInstance().NotifyTerminateContinuation(missionId);
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
ret = DSchedContinueManager::GetInstance().GetDSchedContinueByWant(want, missionId);

View File

@ -77,148 +77,6 @@ void RemoteOnListenerStubTest::OnCallback(const uint32_t ContinueState, const st
{
}
/**
* @tc.name: testUnInit001
* @tc.desc: test UnInit
* @tc.type: FUNC
* @tc.require: I7F8KH
*/
HWTEST_F(DMSContinueManagerTest, testUnInit001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testUnInit001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->Init();
EXPECT_NE(sendMgr->eventHandler_, nullptr);
/**
* @tc.steps: step1. test UnInit when eventHandler is not nullptr;
*/
sendMgr->UnInit();
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
/**
* @tc.steps: step2. test UnInit when eventHandler is nullptr;
*/
sendMgr->UnInit();
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testUnInit001 end" << std::endl;
}
/**
* @tc.name: testUnInit002
* @tc.desc: test UnInit
* @tc.type: FUNC
* @tc.require: I7F8KH
*/
HWTEST_F(DMSContinueManagerTest, testUnInit002, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testUnInit002 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->Init();
EXPECT_NE(sendMgr->eventHandler_, nullptr);
sendMgr->UnInit();
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testUnInit002 end" << std::endl;
}
/**
* @tc.name: testPostUnfocusedTaskWithDelay001
* @tc.desc: test PostUnfocusedTaskWithDelay
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testPostUnfocusedTaskWithDelay001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testPostUnfocusedTaskWithDelay001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->Init();
/**
* @tc.steps: step1. test PostUnfocusedTaskWithDelay when eventHandler is not nullptr;
*/
sendMgr->PostUnfocusedTaskWithDelay(0, UnfocusedReason::TIMEOUT);
sendMgr->PostUnfocusedTaskWithDelay(0, UnfocusedReason::SCREENOFF);
EXPECT_NE(sendMgr->eventHandler_, nullptr);
/**
* @tc.steps: step2. test PostUnfocusedTaskWithDelay when eventHandler is nullptr;
*/
sendMgr->UnInit();
sendMgr->PostUnfocusedTaskWithDelay(0, UnfocusedReason::TIMEOUT);
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testPostUnfocusedTaskWithDelay001 end" << std::endl;
}
/**
* @tc.name: testNotifyMissionFocused001
* @tc.desc: test NotifyMissionFocused
* @tc.type: FUNC
* @tc.require: I7F8KH
*/
HWTEST_F(DMSContinueManagerTest, testNotifyMissionFocused001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testNotifyMissionFocused001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->Init();
/**
* @tc.steps: step1. test NotifyMissionFocused when eventHandler is not nullptr;
*/
sendMgr->NotifyMissionFocused(0, FocusedReason::NORMAL);
sendMgr->NotifyMissionFocused(0, FocusedReason::SCREENOFF);
EXPECT_NE(sendMgr->eventHandler_, nullptr);
/**
* @tc.steps: step2. test NotifyMissionFocused when eventHandler is nullptr;
*/
sendMgr->UnInit();
sendMgr->NotifyMissionFocused(0, FocusedReason::NORMAL);
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testNotifyMissionFocused001 end" << std::endl;
}
/**
* @tc.name: testNotifyMissionUnfocused001
* @tc.desc: test NotifyMissionUnfocused
* @tc.type: FUNC
* @tc.require: I7F8KH
*/
HWTEST_F(DMSContinueManagerTest, testNotifyMissionUnfocused001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testNotifyMissionUnfocused001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->Init();
/**
* @tc.steps: step1. test NotifyMissionUnfocused when eventHandler is not nullptr;
*/
sendMgr->NotifyMissionUnfocused(0, UnfocusedReason::NORMAL);
EXPECT_NE(sendMgr->eventHandler_, nullptr);
/**
* @tc.steps: step2. test NotifyMissionUnfocused when eventHandler is nullptr;
*/
sendMgr->UnInit();
sendMgr->NotifyMissionUnfocused(0, UnfocusedReason::NORMAL);
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testNotifyMissionUnfocused001 end" << std::endl;
}
/**
* @tc.name: testRegisterOnListener001
* @tc.desc: test RegisterOnListener
@ -229,7 +87,8 @@ HWTEST_F(DMSContinueManagerTest, testRegisterOnListener001, TestSize.Level1)
DTEST_LOG << "DMSContinueManagerTest testRegisterOnListener001 start" << std::endl;
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
ASSERT_NE(nullptr, recvMgr);
recvMgr->Init();
int32_t accountId = 100;
recvMgr->Init(accountId);
sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01);
EXPECT_EQ(ret, ERR_OK);
@ -288,96 +147,6 @@ HWTEST_F(DMSContinueManagerTest, testRegisterOffListener002, TestSize.Level3)
DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener002 end" << std::endl;
}
/**
* @tc.name: testGetMissionId001
* @tc.desc: test GetMissionId
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testGetMissionId001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testGetMissionId001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->focusedMission_[BUNDLENAME_01] = MISSIONID_01;
int32_t missionId;
int32_t ret = sendMgr->GetMissionIdByBundleName(BUNDLENAME_01, missionId);
EXPECT_EQ(missionId, MISSIONID_01);
EXPECT_EQ(ret, ERR_OK);
ret = sendMgr->GetMissionIdByBundleName(BUNDLENAME_02, missionId);
EXPECT_EQ(ret, MISSION_NOT_FOCUSED);
DTEST_LOG << "DMSContinueManagerTest testGetMissionId001 end" << std::endl;
}
/**
* @tc.name: testDealFocusedBusiness001
* @tc.desc: test DealFocusedBusiness.
* @tc.type: FUNC
* @tc.require: I7F8KH
*/
HWTEST_F(DMSContinueManagerTest, testDealFocusedBusiness001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testDealFocusedBusiness001 start" << std::endl;
/**
* @tc.steps: step1. test DealFocusedBusiness when missionId is invalid;
*/
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
int32_t ret = sendMgr->DealFocusedBusiness(-1, FocusedReason::MIN);
EXPECT_NE(ret, ERR_OK);
DTEST_LOG << "DMSContinueManagerTest testDealFocusedBusiness001 end" << std::endl;
}
/**
* @tc.name: testDealUnfocusedBusiness001
* @tc.desc: test DealUnfocusedBusiness.
* @tc.type: FUNC
* @tc.require: I7F8KH
*/
HWTEST_F(DMSContinueManagerTest, testDealUnfocusedBusiness001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testDealUnfocusedBusiness001 start" << std::endl;
/**
* @tc.steps: step1. test DealUnfocusedBusiness when missionId is invalid;
*/
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
int32_t ret = sendMgr->DealUnfocusedBusiness(-1, UnfocusedReason::NORMAL);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
/**
* @tc.steps: step2. test DealUnfocusedBusiness when missionId is not invalid;
*/
sendMgr->focusedMission_[BUNDLENAME_01] = MISSIONID_01;
sendMgr->focusedMissionAbility_[MISSIONID_01] = ABILITY_NAME_01;
ret = sendMgr->DealUnfocusedBusiness(MISSIONID_01, UnfocusedReason::NORMAL);
EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
/**
* @tc.steps: step3. test NotifyDied when obj is nullptr;
*/
sptr<IRemoteObject> obj01 = nullptr;
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
ASSERT_NE(nullptr, recvMgr);
recvMgr->NotifyDied(obj01);
/**
* @tc.steps: step4. test NotifyDied when iterItem->second is empty;
*/
std::vector<sptr<IRemoteObject>> objs;
{
std::lock_guard<std::mutex> registerOnListenerMapLock(recvMgr->eventMutex_);
recvMgr->registerOnListener_[TYPE] = objs;
}
obj01 = new RemoteOnListenerStubTest();
recvMgr->NotifyDied(obj01);
DTEST_LOG << "DMSContinueManagerTest testDealUnfocusedBusiness001 end" << std::endl;
}
/**
* @tc.name: testVerifyBroadcastSource001
* @tc.desc: test testVerifyBroadcastSource001.
@ -503,52 +272,6 @@ HWTEST_F(DMSContinueManagerTest, testDealOnBroadcastBusiness001, TestSize.Level3
DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 end" << std::endl;
}
/**
* @tc.name: testGetBundleName001
* @tc.desc: test GetBundleName
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testGetBundleName001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testGetBundleName001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->focusedMission_[BUNDLENAME_01] = MISSIONID_01;
std::string bundleName;
int32_t ret = sendMgr->GetBundleNameByMissionId(MISSIONID_01, bundleName);
EXPECT_EQ(bundleName, BUNDLENAME_01);
EXPECT_EQ(ret, ERR_OK);
ret = sendMgr->GetBundleNameByMissionId(MISSIONID_02, bundleName);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DMSContinueManagerTest testGetBundleName001 end" << std::endl;
}
/**
* @tc.name: testIsContinue001
* @tc.desc: test IsContinue
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testIsContinue001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testIsContinue001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->focusedMission_[BUNDLENAME_02] = MISSIONID_02;
sendMgr->info_.currentMissionId = MISSIONID_01;
sendMgr->info_.currentIsContinuable = true;
bool ret = sendMgr->IsContinue(MISSIONID_02, BUNDLENAME_02);
EXPECT_EQ(ret, false);
ret = sendMgr->IsContinue(MISSIONID_01, BUNDLENAME_01);
EXPECT_EQ(ret, true);
sendMgr->info_.currentIsContinuable = false;
sendMgr->IsContinue(MISSIONID_01, BUNDLENAME_01);
EXPECT_EQ(ret, true);
DTEST_LOG << "DMSContinueManagerTest testIsContinue001 end" << std::endl;
}
/**
* @tc.name: testNotifyDied001
* @tc.desc: test NotifyDied
@ -566,140 +289,6 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDied001, TestSize.Level1)
DTEST_LOG << "DMSContinueManagerTest testNotifyDied001 end" << std::endl;
}
/**
* @tc.name: testSetMissionContinueState001
* @tc.desc: test SetMissionContinueState
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 start" << std::endl;
DistributedSchedUtil::MockManageMissions();
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->Init();
OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
/**
* @tc.steps: step1. test SetMissionContinueState when eventHandler is not nullptr;
*/
sendMgr->SetMissionContinueState(0, state);
EXPECT_NE(sendMgr->eventHandler_, nullptr);
/**
* @tc.steps: step2. test SetMissionContinueState when eventHandler is nullptr;
*/
sendMgr->UnInit();
sendMgr->SetMissionContinueState(0, state);
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 end" << std::endl;
}
/**
* @tc.name: testSetMissionContinueState002
* @tc.desc: test SetMissionContinueState
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState002, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState002 start" << std::endl;
DistributedSchedUtil::MockManageMissions();
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->Init();
OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_INACTIVE;
/**
* @tc.steps: step1. test SetMissionContinueState when eventHandler is not nullptr;
*/
sendMgr->SetMissionContinueState(0, state);
EXPECT_NE(sendMgr->eventHandler_, nullptr);
/**
* @tc.steps: step2. test SetMissionContinueState when eventHandler is nullptr;
*/
sendMgr->UnInit();
sendMgr->SetMissionContinueState(0, state);
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState002 end" << std::endl;
}
/**
* @tc.name: testDealSetMissionContinueStateBusiness001
* @tc.desc: test DealSetMissionContinueStateBusiness.
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness001 start" << std::endl;
OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->info_.currentMissionId = MISSIONID_01;
/**
* @tc.steps: step1. test DealSetMissionContinueStateBusiness when missionId is invalid;
*/
int32_t ret = sendMgr->DealSetMissionContinueStateBusiness(MISSIONID_02, state);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
/**
* @tc.steps: step2. test DealUnfocusedBusiness when mission is not continueable;
*/
sendMgr->info_.currentIsContinuable = false;
ret = sendMgr->DealSetMissionContinueStateBusiness(MISSIONID_01, state);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness001 end" << std::endl;
}
/**
* @tc.name: testDealSetMissionContinueStateBusiness002
* @tc.desc: test DealSetMissionContinueStateBusiness.
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness002, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness002 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->info_.currentIsContinuable = true;
OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
int32_t ret = sendMgr->DealSetMissionContinueStateBusiness(MISSIONID_01, state);
EXPECT_NE(ret, ERR_OK);
DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness002 end" << std::endl;
}
#ifdef SUPPORT_COMMON_EVENT_SERVICE
/**
* @tc.name: testOnDeviceScreenOff001
* @tc.desc: test OnDeviceScreenOff normal
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testOnDeviceScreenOff001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testOnDeviceScreenOff001 start" << std::endl;
DistributedSchedUtil::MockManageMissions();
/**
* @tc.steps: step1. test OnDeviceScreenOff when eventHandler is not nullptr;
*/
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->Init();
sendMgr->OnDeviceScreenOff();
EXPECT_NE(sendMgr->eventHandler_, nullptr);
/**
* @tc.steps: step2. test OnDeviceScreenOff when eventHandler is nullptr;
*/
sendMgr->UnInit();
sendMgr->OnDeviceScreenOff();
EXPECT_EQ(sendMgr->eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testOnDeviceScreenOff001 end" << std::endl;
}
#endif
/**
* @tc.name: testNotifyDeviceOffline001
* @tc.desc: test NotifyDeviceOffline normal
@ -829,94 +418,6 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDataRecv001, TestSize.Level1)
DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 end" << std::endl;
}
/**
* @tc.name: testSendSoftbusEvent001
* @tc.desc: SendSoftbusEvent
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testSendSoftbusEvent001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testSendSoftbusEvent001 start" << std::endl;
uint16_t bundleNameId = 0;
uint8_t continueType = 1;
uint8_t type = 0;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
bool ret = sendMgr->SendSoftbusEvent(bundleNameId, continueType, type);
EXPECT_NE(ret, CAN_NOT_FOUND_ABILITY_ERR);
DTEST_LOG << "DMSContinueManagerTest testSendSoftbusEvent001 end" << std::endl;
}
/**
* @tc.name: testNotifyDeviceOnline001
* @tc.desc: NotifyDeviceOnline
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOnline001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOnline001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
int32_t ret = sendMgr->NotifyDeviceOnline();
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOnline001 end" << std::endl;
}
/**
* @tc.name: testGetAbilityNameByMissionId_001
* @tc.desc: test GetAbilityNameByMissionId
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testGetAbilityNameByMissionId_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testGetAbilityNameByMissionId_001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->focusedMissionAbility_[MISSIONID_01] = ABILITY_NAME_01;
std::string abilityName;
int32_t ret = sendMgr->GetAbilityNameByMissionId(MISSIONID_01, abilityName);
EXPECT_EQ(abilityName, ABILITY_NAME_01);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DMSContinueManagerTest testGetAbilityNameByMissionId_001 end" << std::endl;
}
/**
* @tc.name: testFocusedBusinessSendEvent_001
* @tc.desc: test FocusedBusinessSendEvent
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testFocusedBusinessSendEvent_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testFocusedBusinessSendEvent_001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
int32_t ret = sendMgr->FocusedBusinessSendEvent(BUNDLENAME_01, ABILITY_NAME_01);
EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
DTEST_LOG << "DMSContinueManagerTest testFocusedBusinessSendEvent_001 end" << std::endl;
}
/**
* @tc.name: testGetBundleNameIdAndContinueTypeId_001
* @tc.desc: test GetBundleNameIdAndContinueTypeId
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testGetBundleNameIdAndContinueTypeId_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testGetBundleNameIdAndContinueTypeId_001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->focusedMission_[BUNDLENAME_01] = MISSIONID_01;
sendMgr->focusedMissionAbility_[MISSIONID_01] = ABILITY_NAME_01;
uint16_t bundleNameId = 0;
uint8_t continueTypeId = 0;
OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
int32_t ret = sendMgr->GetBundleNameIdAndContinueTypeId(MISSIONID_01, state, bundleNameId, continueTypeId);
EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
DTEST_LOG << "DMSContinueManagerTest testGetBundleNameIdAndContinueTypeId_001 end" << std::endl;
}
/**
* @tc.name: testGetContinueType_001
* @tc.desc: test GetContinueType
@ -939,97 +440,6 @@ HWTEST_F(DMSContinueManagerTest, testGetContinueType_001, TestSize.Level1)
DTEST_LOG << "DMSContinueManagerTest testGetContinueType_001 end" << std::endl;
}
/**
* @tc.name: testSetScreenOffInfo_001
* @tc.desc: test SetScreenOffInfo
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testSetScreenOffInfo_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testSetScreenOffInfo_001 start" << std::endl;
int32_t missionId = 0;
std::string bundleName = "bundleName";
uint16_t bundleNameId = 0;
std::string abilityName = "abilityName";
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->screenOffHandler_ =
std::make_shared<DMSContinueSendMgr::ScreenOffHandler>();
sendMgr->screenOffHandler_->SetScreenOffInfo(missionId, bundleName,
bundleNameId, abilityName);
EXPECT_EQ(sendMgr->screenOffHandler_->unfoInfo_.abilityName.empty(), false);
sendMgr->screenOffHandler_->ClearScreenOffInfo();
EXPECT_EQ(sendMgr->screenOffHandler_->unfoInfo_.abilityName.empty(), true);
DTEST_LOG << "DMSContinueManagerTest testSetScreenOffInfo_001 end" << std::endl;
}
/**
* @tc.name: testSetStateSendEvent_001
* @tc.desc: test SetStateSendEvent
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testSetStateSendEvent_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testSetStateSendEvent_001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
int32_t ret = sendMgr->SetStateSendEvent(0, 0, AAFwk::ContinueState::CONTINUESTATE_INACTIVE);
EXPECT_NE(ret, DMS_PERMISSION_DENIED);
ret = sendMgr->SetStateSendEvent(0, 0, AAFwk::ContinueState::CONTINUESTATE_ACTIVE);
EXPECT_NE(ret, DMS_PERMISSION_DENIED);
DTEST_LOG << "DMSContinueManagerTest testSetStateSendEvent_001 end" << std::endl;
}
/**
* @tc.name: testGetContinueLaunchMissionInfo_001
* @tc.desc: test GetContinueLaunchMissionInfo
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testGetContinueLaunchMissionInfo_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testGetContinueLaunchMissionInfo_001 start" << std::endl;
ContinueLaunchMissionInfo missionInfo = {"com.test.missionInfo", "MainAbility"};
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->continueLaunchMission_.clear();
int32_t ret = sendMgr->GetContinueLaunchMissionInfo(MISSIONID_01, missionInfo);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
sendMgr->continueLaunchMission_[missionInfo] = MISSIONID_01;
ret = sendMgr->GetContinueLaunchMissionInfo(MISSIONID_01, missionInfo);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DMSContinueManagerTest testGetContinueLaunchMissionInfo_001 end" << std::endl;
}
/**
* @tc.name: testUpdateContinueLaunchMission_001
* @tc.desc: test UpdateContinueLaunchMission
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testUpdateContinueLaunchMission_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testUpdateContinueLaunchMission_001 start" << std::endl;
AAFwk::Want want;
AppExecFwk::ElementName element("", "com.test.demo", "MainAbility", "");
want.SetElement(element);
AAFwk::MissionInfo info;
info.id = MISSIONID_01;
info.want = want;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
EXPECT_FALSE(sendMgr->UpdateContinueLaunchMission(info));
info.want.SetFlags(AAFwk::Want::FLAG_ABILITY_CONTINUATION);
EXPECT_TRUE(sendMgr->UpdateContinueLaunchMission(info));
info.id = MISSIONID_02;
EXPECT_TRUE(sendMgr->UpdateContinueLaunchMission(info));
DTEST_LOG << "DMSContinueManagerTest testUpdateContinueLaunchMission_001 end" << std::endl;
}
/**
* @tc.name: testGetFinalBundleName_001
* @tc.desc: test GetFinalBundleName
@ -1220,93 +630,6 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_005, TestSize.Level1)
DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 end" << std::endl;
}
/**
* @tc.name: GetBundleNameByScreenOffInfo_001
* @tc.desc: test GetBundleNameByScreenOffInfo
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, GetBundleNameByScreenOffInfo_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest GetBundleNameByScreenOffInfo_001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->screenOffHandler_ = nullptr;
int32_t missionId = 0;
std::string bundleName;
int32_t ret = sendMgr->GetBundleNameByScreenOffInfo(missionId, bundleName);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
sendMgr->screenOffHandler_ = std::make_shared<DMSContinueSendMgr::ScreenOffHandler>();
ret = sendMgr->GetBundleNameByScreenOffInfo(missionId, bundleName);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
sendMgr->screenOffHandler_->SetScreenOffInfo(0, "", 0, "");
ret = sendMgr->GetBundleNameByScreenOffInfo(missionId, bundleName);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
sendMgr->screenOffHandler_->SetScreenOffInfo(0, "bundleName", 0, "");
ret = sendMgr->GetBundleNameByScreenOffInfo(missionId, bundleName);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DMSContinueManagerTest GetBundleNameByScreenOffInfo_001 end" << std::endl;
}
/**
* @tc.name: SendScreenOffEvent_001
* @tc.desc: test SendScreenOffEvent
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, SendScreenOffEvent_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest SendScreenOffEvent_001 start" << std::endl;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->screenOffHandler_ = nullptr;
int32_t ret = sendMgr->SendScreenOffEvent(DMS_FOCUSED_TYPE);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
sendMgr->screenOffHandler_ = std::make_shared<DMSContinueSendMgr::ScreenOffHandler>();
ret = sendMgr->SendScreenOffEvent(DMS_FOCUSED_TYPE);
EXPECT_NE(ret, ERR_OK);
DTEST_LOG << "DMSContinueManagerTest SendScreenOffEvent_001 end" << std::endl;
}
/**
* @tc.name: DeleteContinueLaunchMissionInfo_001
* @tc.desc: test DeleteContinueLaunchMissionInfo
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, DeleteContinueLaunchMissionInfo_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest DeleteContinueLaunchMissionInfo_001 start" << std::endl;
int32_t missionId = 0;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
sendMgr->continueLaunchMission_.clear();
sendMgr->DeleteContinueLaunchMissionInfo(missionId);
ContinueLaunchMissionInfo info { "bundleName", "abilityName" };
sendMgr->continueLaunchMission_[info] = 0;
sendMgr->DeleteContinueLaunchMissionInfo(missionId);
EXPECT_EQ(sendMgr->continueLaunchMission_.empty(), true);
DTEST_LOG << "DMSContinueManagerTest DeleteContinueLaunchMissionInfo_001 end" << std::endl;
}
/**
* @tc.name: CheckContinueState_001
* @tc.desc: test CheckContinueState
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, CheckContinueState_001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest CheckContinueState_001 start" << std::endl;
int32_t missionId = 0;
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
ASSERT_NE(nullptr, sendMgr);
int32_t ret = sendMgr->CheckContinueState(missionId);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DMSContinueManagerTest CheckContinueState_001 end" << std::endl;
}
/**
* @tc.name: OnContinueSwitchOff_001
* @tc.desc: test OnContinueSwitchOff

View File

@ -87,10 +87,9 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_UnInit_001, TestSize.Level3)
/**
* @tc.steps: step1. test UnInit with delete sendMgr recvMgr;
*/
int32_t accountId = 100;
MultiUserManager::GetInstance().Init();
MultiUserManager::GetInstance().UnInit();
EXPECT_TRUE(MultiUserManager::GetInstance().sendMgrMap_.empty());
EXPECT_TRUE(MultiUserManager::GetInstance().recvMgrMap_.empty());
@ -108,7 +107,6 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_OnUserSwitched_001, TestSize.Lev
/**
* @tc.steps: step1. test OnUserSwitched with no cache switched user;
*/
int32_t accountId = 100;
int32_t switchedAccountId = 101;
MultiUserManager::GetInstance().Init();
MultiUserManager::GetInstance().OnUserSwitched(switchedAccountId);
@ -128,8 +126,7 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_OnUserSwitched_002, TestSize.Lev
/**
* @tc.steps: step1. test OnUserSwitched with cache switched user;
*/
int32_t accountId = 100;
int32_t switchedAccountId = 101;
int32_t switchedAccountId = 100;
MultiUserManager::GetInstance().Init();
std::map<std::string, sptr<IRemoteObject>> param;
@ -158,7 +155,7 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_OnUserRemoved_001, TestSize.Leve
int32_t accountId = 100;
MultiUserManager::GetInstance().Init();
MultiUserManager::GetInstance().OnUserRemoved(accountId);
auto sendMgr = MultiUserManager::GetInstance().sendMgrMap_.find(accountId);
EXPECT_TRUE(sendMgr == MultiUserManager::GetInstance().sendMgrMap_.end());
auto recvMgr = MultiUserManager::GetInstance().recvMgrMap_.find(accountId);