mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 06:20:07 +00:00
commit
c01f4d089d
@ -513,6 +513,14 @@ enum {
|
||||
* Result(29360234) for mission is not focused.
|
||||
*/
|
||||
MISSION_NOT_FOCUSED = 29360234,
|
||||
/**
|
||||
* Result(29360235) for user is not foreground.
|
||||
*/
|
||||
DMS_NOT_FOREGROUND_USER = 29360235,
|
||||
/**
|
||||
* Result(29360236) for not get mgr.
|
||||
*/
|
||||
DMS_NOT_GET_MANAGER = 29360236,
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -136,6 +136,7 @@ ohos_shared_library("distributedschedsvr") {
|
||||
"src/dms_token_callback.cpp",
|
||||
"src/dms_version_manager.cpp",
|
||||
"src/dtbschedmgr_device_info_storage.cpp",
|
||||
"src/multi_user_manager.cpp",
|
||||
"src/softbus_adapter/allconnectmgr/dsched_all_connect_manager.cpp",
|
||||
"src/softbus_adapter/transport/dsched_data_buffer.cpp",
|
||||
"src/softbus_adapter/transport/dsched_softbus_session.cpp",
|
||||
|
@ -32,8 +32,16 @@ public:
|
||||
|
||||
void OnReceiveEvent(const EventFwk::CommonEventData &eventData);
|
||||
int32_t GetForegroundOsAccountLocalId();
|
||||
AccountSA::OsAccountType GetOsAccountType(int32_t &accountId);
|
||||
void OnUserSwitched();
|
||||
private:
|
||||
void HandleScreenLocked();
|
||||
void HandleScreenOff();
|
||||
void HandleScreenUnLocked();
|
||||
void HandleScreenOn();
|
||||
void HandleUserSwitched(int32_t accountId);
|
||||
void HandlePackageAdded(const std::string& bundleName);
|
||||
void HandlePackageChange(const std::string& bundleName);
|
||||
void HandlePackageRemoved(const std::string& bundleName);
|
||||
void HandleUserRemoved(int32_t accountId);
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -61,8 +61,6 @@ struct currentIconInfo {
|
||||
};
|
||||
|
||||
class DMSContinueRecvMgr {
|
||||
DECLARE_SINGLE_INSTANCE(DMSContinueRecvMgr);
|
||||
|
||||
public:
|
||||
constexpr static uint8_t DMS_DATA_LEN = 3; // Dms data Length
|
||||
constexpr static int32_t DMS_SEND_LEN = 4; // Maximum Broadcast Length
|
||||
|
@ -87,9 +87,7 @@ enum class UnfocusedReason {
|
||||
MAX
|
||||
};
|
||||
|
||||
class DMSContinueSendMgr {
|
||||
DECLARE_SINGLE_INSTANCE(DMSContinueSendMgr);
|
||||
|
||||
class DMSContinueSendMgr : public std::enable_shared_from_this<DMSContinueSendMgr> {
|
||||
public:
|
||||
constexpr static uint8_t DMS_DATA_LEN = 3; // Dms data Length
|
||||
constexpr static int32_t DMS_SEND_LEN = 4; // Maximum broadcast length
|
||||
@ -107,6 +105,7 @@ public:
|
||||
class ScreenOffHandler {
|
||||
public:
|
||||
ScreenOffHandler() = default;
|
||||
explicit ScreenOffHandler(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr);
|
||||
virtual ~ScreenOffHandler() = default;
|
||||
|
||||
int32_t GetMissionId();
|
||||
@ -123,6 +122,7 @@ public:
|
||||
private:
|
||||
bool isScreenOn_ = true;
|
||||
lastUnfoInfo unfoInfo_ = { INVALID_MISSION_ID, 0, "", 0 };
|
||||
std::weak_ptr<DMSContinueSendMgr> dmsContinueSendMgr_;
|
||||
};
|
||||
|
||||
void Init();
|
||||
@ -138,6 +138,7 @@ public:
|
||||
int32_t SendScreenOffEvent(uint8_t type);
|
||||
void DeleteContinueLaunchMissionInfo(const int32_t missionId);
|
||||
int32_t GetContinueLaunchMissionInfo(const int32_t missionId, ContinueLaunchMissionInfo& missionInfo);
|
||||
void UserSwitchedRemoveMMIListener();
|
||||
|
||||
private:
|
||||
int32_t GetCurrentMissionId();
|
||||
|
63
services/dtbschedmgr/include/multi_user_manager.h
Normal file
63
services/dtbschedmgr/include/multi_user_manager.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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_MULTI_USER_MANAGER_H
|
||||
#define OHOS_MULTI_USER_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "mission/dms_continue_send_manager.h"
|
||||
#include "switch_status_dependency.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class MultiUserManager {
|
||||
DECLARE_SINGLE_INSTANCE(MultiUserManager);
|
||||
|
||||
public:
|
||||
void Init();
|
||||
void UnInit();
|
||||
void OnUserSwitched(int32_t userId);
|
||||
void OnUserRemoved(int32_t userId);
|
||||
AccountSA::OsAccountType GetOsAccountType(int32_t &accountId);
|
||||
int32_t CreateNewSendMgr();
|
||||
int32_t CreateNewRecvMgr();
|
||||
std::shared_ptr<DMSContinueSendMgr> GetCurrentSendMgr();
|
||||
std::shared_ptr<DMSContinueRecvMgr> GetCurrentRecvMgr();
|
||||
std::shared_ptr<DMSContinueSendMgr> GetSendMgrByCallingUid(int32_t callingUid);
|
||||
std::shared_ptr<DMSContinueRecvMgr> GetRecvMgrByCallingUid(int32_t callingUid);
|
||||
int32_t OnRegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj, int32_t callingUid);
|
||||
int32_t OnRegisterOffListener(const std::string& type, const sptr<IRemoteObject>& obj, int32_t callingUid);
|
||||
int32_t GetForegroundUser();
|
||||
bool IsUserForeground(int32_t userId);
|
||||
bool IsCallerForeground(int32_t callingUid);
|
||||
|
||||
private:
|
||||
void UserSwitchedOnRegisterListenerCache();
|
||||
|
||||
private:
|
||||
int32_t currentUserId_;
|
||||
std::map<int32_t, std::shared_ptr<DMSContinueSendMgr>> sendMgrMap_;
|
||||
std::map<int32_t, std::shared_ptr<DMSContinueRecvMgr>> recvMgrMap_;
|
||||
std::map<int32_t, std::map<std::string, sptr<IRemoteObject>>> listenerCache_;
|
||||
std::mutex sendMutex_;
|
||||
std::mutex recvMutex_;
|
||||
std::mutex listenerMutex_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_MULTI_USER_MANAGER_H
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/dms_continue_send_manager.h"
|
||||
#include "multi_user_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -126,7 +127,12 @@ void MMIAdapter::HandleRawMMIEvent()
|
||||
return;
|
||||
}
|
||||
isMMIFreezed_ = true;
|
||||
DMSContinueSendMgr::GetInstance().OnMMIEvent();
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->OnMMIEvent();
|
||||
PostUnfreezeMMIEvent();
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "mission/distributed_bm_storage.h"
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "mission/dms_continue_send_manager.h"
|
||||
#include "multi_user_manager.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "switch_status_dependency.h"
|
||||
|
||||
@ -35,6 +36,7 @@ const uint8_t USER_SWITCHED = 4;
|
||||
const uint8_t PACKAGE_ADDED = 5;
|
||||
const uint8_t PACKAGE_CHANGED = 6;
|
||||
const uint8_t PACKAGE_REMOVED = 7;
|
||||
const uint8_t USER_REMOVED = 8;
|
||||
constexpr static int32_t INVALID_ID = 0;
|
||||
std::map<std::string, uint8_t> receiveEvent = {
|
||||
{EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED, SCREEN_LOCKED},
|
||||
@ -45,51 +47,123 @@ std::map<std::string, uint8_t> receiveEvent = {
|
||||
{EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED, PACKAGE_ADDED},
|
||||
{EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED, PACKAGE_CHANGED},
|
||||
{EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED, PACKAGE_REMOVED},
|
||||
{EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED, USER_REMOVED},
|
||||
};
|
||||
}
|
||||
|
||||
void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData &eventData)
|
||||
{
|
||||
auto want = eventData.GetWant();
|
||||
std::string action = want.GetAction();
|
||||
int32_t accountId = GetForegroundOsAccountLocalId();
|
||||
HILOGI("OnReceiveEvent called, action = %{public}s", action.c_str());
|
||||
switch (receiveEvent[action]) {
|
||||
case SCREEN_LOCKED :
|
||||
HILOGI("SCREEN_LOCKED");
|
||||
DMSContinueSendMgr::GetInstance().OnDeviceScreenOff();
|
||||
HandleScreenLocked();
|
||||
break;
|
||||
case SCREEN_OFF :
|
||||
HILOGI("SCREEN_OFF");
|
||||
DMSContinueRecvMgr::GetInstance().OnDeviceScreenOff();
|
||||
HandleScreenOff();
|
||||
break;
|
||||
case SCREEN_UNLOCKED :
|
||||
HILOGI("SCREEN_UNLOCKED");
|
||||
DMSContinueSendMgr::GetInstance().OnDeviceScreenOn();
|
||||
HandleScreenUnLocked();
|
||||
break;
|
||||
case SCREEN_ON :
|
||||
HILOGI("SCREEN_ON");
|
||||
HandleScreenOn();
|
||||
break;
|
||||
case USER_SWITCHED :
|
||||
HILOGI("USER_SWITCHED");
|
||||
OnUserSwitched();
|
||||
HandleUserSwitched(accountId);
|
||||
break;
|
||||
case PACKAGE_ADDED :
|
||||
HILOGI("PACKAGE_ADDED: %{public}s", want.GetElement().GetBundleName().c_str());
|
||||
DmsBmStorage::GetInstance()->SaveStorageDistributeInfo(want.GetElement().GetBundleName());
|
||||
HandlePackageAdded(want.GetElement().GetBundleName());
|
||||
break;
|
||||
case PACKAGE_CHANGED :
|
||||
HILOGI("PACKAGE_CHANGED: %{public}s", want.GetElement().GetBundleName().c_str());
|
||||
DmsBmStorage::GetInstance()->SaveStorageDistributeInfo(want.GetElement().GetBundleName(), true);
|
||||
HandlePackageChange(want.GetElement().GetBundleName());
|
||||
break;
|
||||
case PACKAGE_REMOVED :
|
||||
HILOGI("PACKAGE_REMOVED: %{public}s", want.GetElement().GetBundleName().c_str());
|
||||
DmsBmStorage::GetInstance()->DeleteStorageDistributeInfo(want.GetElement().GetBundleName());
|
||||
DMSContinueRecvMgr::GetInstance().NotifyPackageRemoved(want.GetElement().GetBundleName());
|
||||
HandlePackageRemoved(want.GetElement().GetBundleName());
|
||||
break;
|
||||
case USER_REMOVED :
|
||||
HandleUserRemoved(accountId);
|
||||
break;
|
||||
default:
|
||||
HILOGW("OnReceiveEvent undefined action");
|
||||
}
|
||||
}
|
||||
|
||||
void CommonEventListener::HandleScreenLocked()
|
||||
{
|
||||
HILOGI("SCREEN_LOCKED");
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGE("SendMgr is nullptr.");
|
||||
return;
|
||||
}
|
||||
sendMgr->OnDeviceScreenOff();
|
||||
}
|
||||
|
||||
void CommonEventListener::HandleScreenOff()
|
||||
{
|
||||
HILOGI("SCREEN_OFF");
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGE("RecvMgr is nullptr.");
|
||||
return;
|
||||
}
|
||||
recvMgr->OnDeviceScreenOff();
|
||||
}
|
||||
|
||||
void CommonEventListener::HandleScreenUnLocked()
|
||||
{
|
||||
HILOGI("SCREEN_UNLOCKED");
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGE("SendMgr is nullptr.");
|
||||
return;
|
||||
}
|
||||
sendMgr->OnDeviceScreenOn();
|
||||
}
|
||||
|
||||
void CommonEventListener::HandleScreenOn()
|
||||
{
|
||||
HILOGI("SCREEN_ON");
|
||||
}
|
||||
|
||||
void CommonEventListener::HandleUserSwitched(int32_t accountId)
|
||||
{
|
||||
HILOGI("USER_SWITCHED");
|
||||
MultiUserManager::GetInstance().OnUserSwitched(accountId);
|
||||
}
|
||||
|
||||
void CommonEventListener::HandlePackageAdded(const std::string& bundleName)
|
||||
{
|
||||
HILOGI("PACKAGE_ADDED: %{public}s", bundleName.c_str());
|
||||
DmsBmStorage::GetInstance()->SaveStorageDistributeInfo(bundleName);
|
||||
}
|
||||
|
||||
void CommonEventListener::HandlePackageChange(const std::string& bundleName)
|
||||
{
|
||||
HILOGI("PACKAGE_CHANGED: %{public}s", bundleName.c_str());
|
||||
DmsBmStorage::GetInstance()->SaveStorageDistributeInfo(bundleName, true);
|
||||
}
|
||||
|
||||
void CommonEventListener::HandlePackageRemoved(const std::string& bundleName)
|
||||
{
|
||||
HILOGI("PACKAGE_REMOVED: %{public}s", bundleName.c_str());
|
||||
DmsBmStorage::GetInstance()->DeleteStorageDistributeInfo(bundleName);
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGE("RecvMgr is nullptr.");
|
||||
return;
|
||||
}
|
||||
recvMgr->NotifyPackageRemoved(bundleName);
|
||||
}
|
||||
|
||||
void CommonEventListener::HandleUserRemoved(int32_t accountId)
|
||||
{
|
||||
HILOGI("USER_REMOVED");
|
||||
MultiUserManager::GetInstance().OnUserRemoved(accountId);
|
||||
}
|
||||
|
||||
int32_t CommonEventListener::GetForegroundOsAccountLocalId()
|
||||
{
|
||||
int32_t accountId = INVALID_ID;
|
||||
@ -101,35 +175,5 @@ int32_t CommonEventListener::GetForegroundOsAccountLocalId()
|
||||
HILOGD("GetForegroundOsAccountLocalId accountId is: %{public}d", accountId);
|
||||
return accountId;
|
||||
}
|
||||
|
||||
AccountSA::OsAccountType CommonEventListener::GetOsAccountType(int32_t& accountId)
|
||||
{
|
||||
AccountSA::OsAccountType type;
|
||||
ErrCode err = AccountSA::OsAccountManager::GetOsAccountType(accountId, type);
|
||||
if (err != ERR_OK) {
|
||||
HILOGE("GetOsAccountType passing param invalid or return error!, err : %{public}d", err);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
void CommonEventListener::OnUserSwitched()
|
||||
{
|
||||
int32_t accountId = GetForegroundOsAccountLocalId();
|
||||
AccountSA::OsAccountType type = GetOsAccountType(accountId);
|
||||
HILOGI("OnUserSwitched called, accountId = %{public}d, type = %{public}d", accountId, type);
|
||||
if (type == AccountSA::OsAccountType::PRIVATE) {
|
||||
HILOGI("GetOsAccountType : OsAccountType is PRIVATE, type : %{public}d", type);
|
||||
DataShareManager::GetInstance().UpdateSwitchStatus(SwitchStatusDependency::GetInstance()
|
||||
.CONTINUE_SWITCH_STATUS_KEY, SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_OFF);
|
||||
}
|
||||
|
||||
DataShareManager::GetInstance().SetCurrentContinueSwitch(SwitchStatusDependency::GetInstance()
|
||||
.IsContinueSwitchOn());
|
||||
if (!DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) {
|
||||
DMSContinueRecvMgr::GetInstance().OnContinueSwitchOff();
|
||||
HILOGI("ICurrentContinueSwitch is off, %{public}d", DataShareManager::GetInstance()
|
||||
.IsCurrentContinueSwitchOn());
|
||||
};
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -37,6 +37,7 @@
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/distributed_bm_storage.h"
|
||||
#include "mission/dsched_sync_e2e.h"
|
||||
#include "multi_user_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "parcel_helper.h"
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
@ -697,8 +698,12 @@ int32_t DSchedContinue::GetMissionIdByBundleName()
|
||||
{
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
if (continueInfo_.missionId_ == 0) {
|
||||
return DMSContinueSendMgr::GetInstance().GetMissionIdByBundleName(continueInfo_.sourceBundleName_,
|
||||
continueInfo_.missionId_);
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return DMS_NOT_GET_MANAGER;
|
||||
}
|
||||
return sendMgr->GetMissionIdByBundleName(continueInfo_.sourceBundleName_, continueInfo_.missionId_);
|
||||
}
|
||||
#endif
|
||||
return ERR_OK;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "mission/distributed_bm_storage.h"
|
||||
#include "mission/dms_continue_send_manager.h"
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "multi_user_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -208,8 +209,12 @@ int32_t DSchedContinueManager::ContinueMission(const DSchedContinueInfo& continu
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
if (localDevId == srcDeviceId) {
|
||||
int32_t missionId = -1;
|
||||
int32_t ret = DMSContinueSendMgr::GetInstance().GetMissionIdByBundleName(
|
||||
continueInfo.sinkBundleName_, missionId);
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return DMS_NOT_GET_MANAGER;
|
||||
}
|
||||
int32_t ret = sendMgr->GetMissionIdByBundleName(continueInfo.sinkBundleName_, missionId);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("get missionId fail, ret %{public}d.", ret);
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
@ -515,7 +520,12 @@ void DSchedContinueManager::NotifyTerminateContinuation(const int32_t missionId)
|
||||
}
|
||||
|
||||
ContinueLaunchMissionInfo missionInfo;
|
||||
int32_t ret = DMSContinueSendMgr::GetInstance().GetContinueLaunchMissionInfo(missionId, missionInfo);
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
int32_t ret = sendMgr->GetContinueLaunchMissionInfo(missionId, missionInfo);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("get continueLaunchMissionInfo failed, missionId %{public}d", missionId);
|
||||
return;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/dms_continue_send_manager.h"
|
||||
#include "multi_user_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -44,7 +45,12 @@ void DistributedDeviceNodeListener::OnDeviceOnline(const DistributedHardware::Dm
|
||||
#ifdef DMSFWK_INTERACTIVE_ADAPTER
|
||||
DistributedSchedService::GetInstance().OnDeviceOnlineEx(deviceInfo);
|
||||
#endif
|
||||
DMSContinueSendMgr::GetInstance().NotifyDeviceOnline();
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->NotifyDeviceOnline();
|
||||
}
|
||||
|
||||
void DistributedDeviceNodeListener::OnDeviceOffline(const DistributedHardware::DmDeviceInfo& deviceInfo)
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "file_ex.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "multi_user_manager.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "parameters.h"
|
||||
#include "string_ex.h"
|
||||
@ -167,8 +168,7 @@ void DistributedSchedService::OnStop(const SystemAbilityOnDemandReason &stopReas
|
||||
{
|
||||
HILOGI("OnStart reason %{public}s, reasonId_:%{public}d", stopReason.GetName().c_str(), stopReason.GetId());
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
DMSContinueSendMgr::GetInstance().UnInit();
|
||||
DMSContinueRecvMgr::GetInstance().UnInit();
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
RemoveSystemAbilityListener(WINDOW_MANAGER_SERVICE_ID);
|
||||
DistributedSchedAdapter::GetInstance().UnRegisterMissionListener(missionFocusedListener_);
|
||||
#endif
|
||||
@ -269,10 +269,15 @@ void DistributedSchedService::DeviceOnlineNotify(const std::string& networkId)
|
||||
DistributedSchedAdapter::GetInstance().DeviceOnline(networkId);
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(networkId);
|
||||
if (!DMSContinueRecvMgr::GetInstance().CheckRegSoftbusListener() &&
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
if (!recvMgr->CheckRegSoftbusListener() &&
|
||||
DistributedHardware::DeviceManager::GetInstance().IsSameAccount(networkId)) {
|
||||
HILOGI("DMSContinueRecvMgr need init");
|
||||
DMSContinueRecvMgr::GetInstance().Init();
|
||||
recvMgr->Init();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -281,7 +286,12 @@ void DistributedSchedService::DeviceOfflineNotify(const std::string& networkId)
|
||||
{
|
||||
DistributedSchedAdapter::GetInstance().DeviceOffline(networkId);
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
DMSContinueRecvMgr::GetInstance().NotifyDeviceOffline(networkId);
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->NotifyDeviceOffline(networkId);
|
||||
DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify(networkId);
|
||||
#endif
|
||||
}
|
||||
@ -324,15 +334,17 @@ void DistributedSchedService::InitMissionManager()
|
||||
InitCommonEventListener();
|
||||
InitWifiStateListener();
|
||||
InitWifiSemiStateListener();
|
||||
DMSContinueSendMgr::GetInstance().Init();
|
||||
DMSContinueRecvMgr::GetInstance().Init();
|
||||
MultiUserManager::GetInstance().Init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void DistributedSchedService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
|
||||
{
|
||||
HILOGI("OnAddSystemAbility systemAbilityId:%{public}d added!", systemAbilityId);
|
||||
missionFocusedListener_ = sptr<DistributedMissionFocusedListener>(new DistributedMissionFocusedListener());
|
||||
if (missionFocusedListener_ == nullptr) {
|
||||
HILOGI("missionFocusedListener_ is nullptr.");
|
||||
missionFocusedListener_ = sptr<DistributedMissionFocusedListener>(new DistributedMissionFocusedListener());
|
||||
}
|
||||
int32_t ret = DistributedSchedAdapter::GetInstance().RegisterMissionListener(missionFocusedListener_);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("get RegisterMissionListener failed, ret: %{public}d", ret);
|
||||
@ -351,11 +363,26 @@ void DistributedSchedService::InitDataShareManager()
|
||||
}
|
||||
DmsUE::GetInstance().ChangedSwitchState(dataShareManager.IsCurrentContinueSwitchOn(), ERR_OK);
|
||||
if (dataShareManager.IsCurrentContinueSwitchOn()) {
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionFocused(missionId, FocusedReason::INIT);
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->NotifyMissionFocused(missionId, FocusedReason::INIT);
|
||||
DSchedContinueManager::GetInstance().Init();
|
||||
} else {
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(missionId, UnfocusedReason::NORMAL);
|
||||
DMSContinueRecvMgr::GetInstance().OnContinueSwitchOff();
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->NotifyMissionUnfocused(missionId, UnfocusedReason::NORMAL);
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->OnContinueSwitchOff();
|
||||
DSchedContinueManager::GetInstance().UnInit();
|
||||
};
|
||||
};
|
||||
@ -1084,7 +1111,12 @@ int32_t DistributedSchedService::ProcessContinueLocalMission(const std::string&
|
||||
|
||||
int32_t missionId = 1;
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
int32_t ret = DMSContinueSendMgr::GetInstance().GetMissionIdByBundleName(bundleName, missionId);
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return DMS_NOT_GET_MANAGER;
|
||||
}
|
||||
int32_t ret = sendMgr->GetMissionIdByBundleName(bundleName, missionId);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("get missionId failed");
|
||||
return ret;
|
||||
@ -2875,13 +2907,13 @@ int32_t DistributedSchedService::RegisterMissionListener(const std::u16string& d
|
||||
int32_t DistributedSchedService::RegisterOnListener(const std::string& type,
|
||||
const sptr<IRemoteObject>& obj, int32_t callingUid)
|
||||
{
|
||||
return DMSContinueRecvMgr::GetInstance().RegisterOnListener(type, obj);
|
||||
return MultiUserManager::GetInstance().OnRegisterOnListener(type, obj, callingUid);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedService::RegisterOffListener(const std::string& type,
|
||||
const sptr<IRemoteObject>& obj, int32_t callingUid)
|
||||
{
|
||||
return DMSContinueRecvMgr::GetInstance().RegisterOffListener(type, obj);
|
||||
return MultiUserManager::GetInstance().OnRegisterOffListener(type, obj, callingUid);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedService::UnRegisterMissionListener(const std::u16string& devId,
|
||||
@ -2914,7 +2946,17 @@ int32_t DistributedSchedService::StopSyncMissionsFromRemote(const CallerInfo& ca
|
||||
|
||||
int32_t DistributedSchedService::SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState &state)
|
||||
{
|
||||
return DMSContinueSendMgr::GetInstance().SetMissionContinueState(missionId, state);
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
if (!MultiUserManager::GetInstance().IsCallerForeground(callingUid)) {
|
||||
HILOGW("The current user is not foreground.");
|
||||
return DMS_NOT_FOREGROUND_USER;
|
||||
}
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return DMS_NOT_GET_MANAGER;
|
||||
}
|
||||
return sendMgr->SetMissionContinueState(missionId, state);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "dsched_transport_softbus_adapter.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
#include "multi_user_manager.h"
|
||||
#include "parcel_helper.h"
|
||||
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
@ -568,6 +569,16 @@ int32_t DistributedSchedStub::ContinueMissionInner(MessageParcel& data, MessageP
|
||||
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
|
||||
}
|
||||
|
||||
void SetContinueType(std::string& continueType, std::string& bundleName)
|
||||
{
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
continueType = recvMgr->GetContinueType(bundleName);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedStub::ContinueMissionOfBundleNameInner(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
bool isLocalCalling = IPCSkeleton::IsLocalCalling();
|
||||
@ -599,7 +610,7 @@ int32_t DistributedSchedStub::ContinueMissionOfBundleNameInner(MessageParcel& da
|
||||
PARCEL_READ_HELPER_NORET(data, String, srcBundleName);
|
||||
PARCEL_READ_HELPER_NORET(data, String, continueType);
|
||||
if (continueType == "") {
|
||||
continueType = DMSContinueRecvMgr::GetInstance().GetContinueType(bundleName);
|
||||
SetContinueType(continueType, bundleName);
|
||||
}
|
||||
|
||||
int32_t result = ERR_OK;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "distributed_sched_utils.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "multi_user_manager.h"
|
||||
|
||||
using namespace std;
|
||||
namespace OHOS {
|
||||
@ -402,10 +403,15 @@ void DtbschedmgrDeviceInfoStorage::DeviceOfflineNotify(const std::string& networ
|
||||
void DtbschedmgrDeviceInfoStorage::OnDeviceInfoChanged(const std::string& deviceId)
|
||||
{
|
||||
HILOGI("OnDeviceInfoChanged called");
|
||||
if (!DMSContinueRecvMgr::GetInstance().CheckRegSoftbusListener() &&
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
if (!recvMgr->CheckRegSoftbusListener() &&
|
||||
DistributedHardware::DeviceManager::GetInstance().IsSameAccount(deviceId)) {
|
||||
HILOGI("DMSContinueRecvMgr need init");
|
||||
DMSContinueRecvMgr::GetInstance().Init();
|
||||
recvMgr->Init();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "multi_user_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -27,7 +28,12 @@ const std::string TAG = "DistributedMissionBroadcastListener";
|
||||
void DistributedMissionBroadcastListener::OnDataRecv(std::string& senderNetworkId, uint8_t* payload, uint32_t dataLen)
|
||||
{
|
||||
HILOGI("OnDataRecv, dataLen = %{public}u", dataLen);
|
||||
DMSContinueRecvMgr::GetInstance().NotifyDataRecv(senderNetworkId, payload, dataLen);
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->NotifyDataRecv(senderNetworkId, payload, dataLen);
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "multi_user_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -26,7 +27,12 @@ const std::string TAG = "DistributedMissionDiedListener";
|
||||
void DistributedMissionDiedListener::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
HILOGD("called");
|
||||
DMSContinueRecvMgr::GetInstance().NotifyDied(remote.promote());
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->NotifyDied(remote.promote());
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -18,7 +18,9 @@
|
||||
#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 "multi_user_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -33,9 +35,20 @@ void DistributedMissionFocusedListener::OnMissionCreated(int32_t missionId)
|
||||
void DistributedMissionFocusedListener::OnMissionDestroyed(int32_t missionId)
|
||||
{
|
||||
HILOGD("OnMissionDestroyed, missionId = %{public}d", missionId);
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(missionId, UnfocusedReason::DESTORY);
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
if (!MultiUserManager::GetInstance().IsCallerForeground(callingUid)) {
|
||||
HILOGW("Current process is not foreground. callingUid = %{public}d", callingUid);
|
||||
return;
|
||||
}
|
||||
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->NotifyMissionUnfocused(missionId, UnfocusedReason::DESTORY);
|
||||
DSchedContinueManager::GetInstance().NotifyTerminateContinuation(missionId);
|
||||
DMSContinueSendMgr::GetInstance().DeleteContinueLaunchMissionInfo(missionId);
|
||||
sendMgr->DeleteContinueLaunchMissionInfo(missionId);
|
||||
}
|
||||
|
||||
void DistributedMissionFocusedListener::OnMissionSnapshotChanged(int32_t missionId)
|
||||
@ -51,13 +64,35 @@ void DistributedMissionFocusedListener::OnMissionMovedToFront(int32_t missionId)
|
||||
void DistributedMissionFocusedListener::OnMissionFocused(int32_t missionId)
|
||||
{
|
||||
HILOGD("OnMissionFocused, missionId = %{public}d", missionId);
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionFocused(missionId, FocusedReason::NORMAL);
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
if (!MultiUserManager::GetInstance().IsCallerForeground(callingUid)) {
|
||||
HILOGW("Current process is not foreground. callingUid = %{public}d", callingUid);
|
||||
return;
|
||||
}
|
||||
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->NotifyMissionFocused(missionId, FocusedReason::NORMAL);
|
||||
}
|
||||
|
||||
void DistributedMissionFocusedListener::OnMissionUnfocused(int32_t missionId)
|
||||
{
|
||||
HILOGD("OnMissionUnFocused, missionId = %{public}d", missionId);
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(missionId, UnfocusedReason::NORMAL);
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
if (!MultiUserManager::GetInstance().IsCallerForeground(callingUid)) {
|
||||
HILOGW("Current process is not foreground. callingUid = %{public}d", callingUid);
|
||||
return;
|
||||
}
|
||||
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetSendMgrByCallingUid(callingUid);
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->NotifyMissionUnfocused(missionId, UnfocusedReason::NORMAL);
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
@ -70,7 +105,18 @@ void DistributedMissionFocusedListener::OnMissionIconUpdated([[maybe_unused]]int
|
||||
void DistributedMissionFocusedListener::OnMissionClosed(int32_t missionId)
|
||||
{
|
||||
HILOGD("OnMissionClosed, missionId = %{public}d", missionId);
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(missionId, UnfocusedReason::CLOSE);
|
||||
int32_t callingUid = IPCSkeleton::GetCallingUid();
|
||||
if (!MultiUserManager::GetInstance().IsCallerForeground(callingUid)) {
|
||||
HILOGW("Current process is not foreground. callingUid = %{public}d", callingUid);
|
||||
return;
|
||||
}
|
||||
|
||||
auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->NotifyMissionUnfocused(missionId, UnfocusedReason::CLOSE);
|
||||
}
|
||||
|
||||
void DistributedMissionFocusedListener::OnMissionLabelUpdated([[maybe_unused]]int32_t missionId)
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/dsched_sync_e2e.h"
|
||||
#include "mission/wifi_state_adapter.h"
|
||||
#include "multi_user_manager.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "softbus_adapter/softbus_adapter.h"
|
||||
#include "switch_status_dependency.h"
|
||||
@ -49,8 +50,6 @@ const std::u16string DESCRIPTOR = u"ohos.aafwk.RemoteOnListener";
|
||||
const std::string QUICK_START_CONFIGURATION = "_ContinueQuickStart";
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(DMSContinueRecvMgr);
|
||||
|
||||
void DMSContinueRecvMgr::Init()
|
||||
{
|
||||
HILOGI("Init start");
|
||||
@ -59,13 +58,6 @@ void DMSContinueRecvMgr::Init()
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::shared_ptr<SoftbusAdapterListener> missionBroadcastListener =
|
||||
std::make_shared<DistributedMissionBroadcastListener>();
|
||||
int32_t ret = SoftbusAdapter::GetInstance().RegisterSoftbusEventListener(missionBroadcastListener);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("get RegisterSoftbusEventListener failed, ret: %{public}d", ret);
|
||||
return;
|
||||
}
|
||||
hasRegSoftbusEventListener_ = true;
|
||||
missionDiedListener_ = new DistributedMissionDiedListener();
|
||||
eventThread_ = std::thread(&DMSContinueRecvMgr::StartEvent, this);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "mission/dsched_sync_e2e.h"
|
||||
#include "mission/wifi_state_adapter.h"
|
||||
#include "multi_user_manager.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "softbus_adapter/softbus_adapter.h"
|
||||
#include "switch_status_dependency.h"
|
||||
@ -47,8 +48,6 @@ const std::string TIMEOUT_UNFOCUSED_TASK = "timeout_unfocused_task";
|
||||
const std::string SCREEN_OFF_UNFOCUSED_TASK = "screen_off_unfocused_task";
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(DMSContinueSendMgr);
|
||||
|
||||
void DMSContinueSendMgr::Init()
|
||||
{
|
||||
HILOGI("Init start");
|
||||
@ -57,9 +56,7 @@ void DMSContinueSendMgr::Init()
|
||||
return;
|
||||
}
|
||||
{
|
||||
MMIAdapter::GetInstance().Init();
|
||||
SoftbusAdapter::GetInstance().Init();
|
||||
screenOffHandler_ = std::make_shared<ScreenOffHandler>();
|
||||
screenOffHandler_ = std::make_shared<ScreenOffHandler>(shared_from_this());
|
||||
|
||||
eventThread_ = std::thread(&DMSContinueSendMgr::StartEvent, this);
|
||||
std::unique_lock<std::mutex> lock(eventMutex_);
|
||||
@ -80,8 +77,6 @@ void DMSContinueSendMgr::Init()
|
||||
void DMSContinueSendMgr::UnInit()
|
||||
{
|
||||
HILOGI("UnInit start");
|
||||
MMIAdapter::GetInstance().UnInit();
|
||||
SoftbusAdapter::GetInstance().UnInit();
|
||||
if (eventHandler_ != nullptr && eventHandler_->GetEventRunner() != nullptr) {
|
||||
eventHandler_->GetEventRunner()->Stop();
|
||||
eventThread_.join();
|
||||
@ -281,6 +276,13 @@ void DMSContinueSendMgr::RemoveMMIListener()
|
||||
return;
|
||||
}
|
||||
|
||||
void DMSContinueSendMgr::UserSwitchedRemoveMMIListener()
|
||||
{
|
||||
HILOGD("UserSwitched MMI listener remove start.");
|
||||
RemoveMMIListener();
|
||||
HILOGD("UserSwitched MMI listener remove end.");
|
||||
}
|
||||
|
||||
int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId, FocusedReason reason)
|
||||
{
|
||||
HILOGI("DealFocusedBusiness start, missionId: %{public}d", missionId);
|
||||
@ -633,7 +635,7 @@ int32_t DMSContinueSendMgr::GetBundleNameIdAndContinueTypeId(const int32_t missi
|
||||
|
||||
void DMSContinueSendMgr::OnMMIEvent()
|
||||
{
|
||||
DMSContinueSendMgr::GetInstance().NotifyMissionFocused(INVALID_MISSION_ID, FocusedReason::MMI);
|
||||
NotifyMissionFocused(INVALID_MISSION_ID, FocusedReason::MMI);
|
||||
}
|
||||
|
||||
int32_t DMSContinueSendMgr::NotifyDeviceOnline()
|
||||
@ -681,6 +683,11 @@ void DMSContinueSendMgr::OnDeviceScreenOn()
|
||||
eventHandler_->PostTask(feedfunc);
|
||||
}
|
||||
|
||||
DMSContinueSendMgr::ScreenOffHandler::ScreenOffHandler(const std::shared_ptr<DMSContinueSendMgr>& dmsContinueSendMgr)
|
||||
: dmsContinueSendMgr_(dmsContinueSendMgr)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t DMSContinueSendMgr::ScreenOffHandler::GetMissionId()
|
||||
{
|
||||
return unfoInfo_.missionId;
|
||||
@ -711,11 +718,16 @@ void DMSContinueSendMgr::ScreenOffHandler::OnDeviceScreenOff(int32_t missionId)
|
||||
{
|
||||
HILOGI("ScreenOffHandler::OnDeviceScreenOff called");
|
||||
isScreenOn_ = false;
|
||||
std::shared_ptr<DMSContinueSendMgr> sendMgr = dmsContinueSendMgr_.lock();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGW("sendMgr is nullptr.");
|
||||
return;
|
||||
}
|
||||
if (unfoInfo_.missionId != INVALID_MISSION_ID && (GetTickCount()- unfoInfo_.unfoTime) < TIME_DELAYED) {
|
||||
// handle unfocus before screen off
|
||||
DMSContinueSendMgr::GetInstance().SendScreenOffEvent(DMS_FOCUSED_TYPE);
|
||||
sendMgr->SendScreenOffEvent(DMS_FOCUSED_TYPE);
|
||||
}
|
||||
DMSContinueSendMgr::GetInstance().PostUnfocusedTaskWithDelay(missionId, UnfocusedReason::SCREENOFF);
|
||||
sendMgr->PostUnfocusedTaskWithDelay(missionId, UnfocusedReason::SCREENOFF);
|
||||
}
|
||||
|
||||
void DMSContinueSendMgr::ScreenOffHandler::OnDeviceScreenOn()
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/dms_continue_recv_manager.h"
|
||||
#include "mission/wifi_state_adapter.h"
|
||||
#include "multi_user_manager.h"
|
||||
#include "wifi_device.h"
|
||||
#include "wifi_msg.h"
|
||||
|
||||
@ -35,7 +36,12 @@ void WifiStateListener::OnReceiveEvent(const EventFwk::CommonEventData &data)
|
||||
case int32_t(OHOS::Wifi::WifiState::DISABLED): {
|
||||
HILOGI("on wifi disabled");
|
||||
WifiStateAdapter::GetInstance().UpdateWifiState(false);
|
||||
DMSContinueRecvMgr::GetInstance().OnContinueSwitchOff();
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->OnContinueSwitchOff();
|
||||
break;
|
||||
}
|
||||
|
||||
|
357
services/dtbschedmgr/src/multi_user_manager.cpp
Normal file
357
services/dtbschedmgr/src/multi_user_manager.cpp
Normal file
@ -0,0 +1,357 @@
|
||||
/*
|
||||
* 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 "multi_user_manager.h"
|
||||
|
||||
#include "adapter/mmi_adapter.h"
|
||||
#include "datashare_manager.h"
|
||||
#include "distributed_sched_utils.h"
|
||||
#include "dtbschedmgr_log.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";
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(MultiUserManager);
|
||||
|
||||
void MultiUserManager::Init()
|
||||
{
|
||||
HILOGI("Init start.");
|
||||
currentUserId_ = GetForegroundUser();
|
||||
MMIAdapter::GetInstance().Init();
|
||||
SoftbusAdapter::GetInstance().Init();
|
||||
auto sendMgr = GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->Init();
|
||||
auto recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->Init();
|
||||
std::shared_ptr<SoftbusAdapterListener> missionBroadcastListener =
|
||||
std::make_shared<DistributedMissionBroadcastListener>();
|
||||
int32_t ret = SoftbusAdapter::GetInstance().RegisterSoftbusEventListener(missionBroadcastListener);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("get RegisterSoftbusEventListener failed, ret: %{public}d", ret);
|
||||
}
|
||||
HILOGI("Init end.");
|
||||
}
|
||||
|
||||
void MultiUserManager::UnInit()
|
||||
{
|
||||
HILOGI("UnInit start");
|
||||
MMIAdapter::GetInstance().UnInit();
|
||||
SoftbusAdapter::GetInstance().UnInit();
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(sendMutex_);
|
||||
if (!sendMgrMap_.empty()) {
|
||||
auto it = sendMgrMap_.begin();
|
||||
while (it != sendMgrMap_.end()) {
|
||||
if (it->second == nullptr) {
|
||||
sendMgrMap_.erase(it++);
|
||||
continue;
|
||||
}
|
||||
it->second->UnInit();
|
||||
sendMgrMap_.erase(it++);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(recvMutex_);
|
||||
if (!recvMgrMap_.empty()) {
|
||||
auto it = recvMgrMap_.begin();
|
||||
while (it != recvMgrMap_.end()) {
|
||||
if (it->second == nullptr) {
|
||||
recvMgrMap_.erase(it++);
|
||||
continue;
|
||||
}
|
||||
it->second->UnInit();
|
||||
recvMgrMap_.erase(it++);
|
||||
}
|
||||
}
|
||||
}
|
||||
HILOGI("UnInit end");
|
||||
}
|
||||
|
||||
void MultiUserManager::OnUserSwitched(int32_t accountId)
|
||||
{
|
||||
HILOGI("UserSwitched start");
|
||||
auto sendMgr = GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->SendScreenOffEvent(DMS_UNFOCUSED_TYPE);
|
||||
sendMgr->UserSwitchedRemoveMMIListener();
|
||||
currentUserId_ = accountId;
|
||||
|
||||
AccountSA::OsAccountType type = GetOsAccountType(currentUserId_);
|
||||
HILOGI("OnUserSwitched called, currentUserId = %{public}d, type = %{public}d", currentUserId_, type);
|
||||
if (type == AccountSA::OsAccountType::PRIVATE) {
|
||||
HILOGI("GetOsAccountType : OsAccountType is PRIVATE, type : %{public}d", type);
|
||||
DataShareManager::GetInstance().UpdateSwitchStatus(SwitchStatusDependency::GetInstance()
|
||||
.CONTINUE_SWITCH_STATUS_KEY, SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_OFF);
|
||||
}
|
||||
|
||||
DataShareManager::GetInstance().SetCurrentContinueSwitch(SwitchStatusDependency::GetInstance()
|
||||
.IsContinueSwitchOn());
|
||||
sendMgr = GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->Init();
|
||||
auto recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->Init();
|
||||
|
||||
if (!DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) {
|
||||
recvMgr->OnContinueSwitchOff();
|
||||
HILOGI("ICurrentContinueSwitch is off, %{public}d", DataShareManager::GetInstance()
|
||||
.IsCurrentContinueSwitchOn());
|
||||
};
|
||||
UserSwitchedOnRegisterListenerCache();
|
||||
HILOGI("UserSwitched end");
|
||||
}
|
||||
|
||||
void MultiUserManager::UserSwitchedOnRegisterListenerCache()
|
||||
{
|
||||
HILOGI("UserSwitchedOnRegisterListenerCache start");
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(listenerMutex_);
|
||||
if (!listenerCache_.empty()) {
|
||||
HILOGI("Cache invoke register listener. userId: %{public}d.", currentUserId_);
|
||||
auto recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
auto it = listenerCache_.find(currentUserId_);
|
||||
if (it != listenerCache_.end() && !it->second.empty()) {
|
||||
for (auto param = it->second.begin(); param != it->second.end(); param ++) {
|
||||
std::string type = param->first;
|
||||
sptr<IRemoteObject> obj = param->second;
|
||||
recvMgr->RegisterOnListener(type, obj);
|
||||
}
|
||||
listenerCache_.erase(it);
|
||||
HILOGI("Cache remove. userId: %{public}d.", currentUserId_);
|
||||
}
|
||||
}
|
||||
}
|
||||
HILOGI("UserSwitchedOnRegisterListenerCache end");
|
||||
}
|
||||
|
||||
void MultiUserManager::OnUserRemoved(int32_t accountId)
|
||||
{
|
||||
HILOGI("UserRemoved start");
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(sendMutex_);
|
||||
if (!sendMgrMap_.empty()) {
|
||||
auto it = sendMgrMap_.find(accountId);
|
||||
if (it != sendMgrMap_.end()) {
|
||||
if (it->second != nullptr) {
|
||||
it->second->UnInit();
|
||||
}
|
||||
sendMgrMap_.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(recvMutex_);
|
||||
if (!recvMgrMap_.empty()) {
|
||||
auto it = recvMgrMap_.find(accountId);
|
||||
if (it != recvMgrMap_.end()) {
|
||||
if (it->second != nullptr) {
|
||||
it->second->UnInit();
|
||||
}
|
||||
recvMgrMap_.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
HILOGI("UserRemoved end");
|
||||
}
|
||||
|
||||
AccountSA::OsAccountType MultiUserManager::GetOsAccountType(int32_t &accountId)
|
||||
{
|
||||
AccountSA::OsAccountType type;
|
||||
ErrCode err = AccountSA::OsAccountManager::GetOsAccountType(accountId, type);
|
||||
if (err != ERR_OK) {
|
||||
HILOGE("GetOsAccountType passing param invalid or return error!, err : %{public}d", err);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
int32_t MultiUserManager::CreateNewSendMgr()
|
||||
{
|
||||
HILOGI("CreateNewSendMgr begin. accountId: %{public}d.", currentUserId_);
|
||||
auto sendMgr = std::make_shared<DMSContinueSendMgr>();
|
||||
sendMgrMap_.emplace(currentUserId_, sendMgr);
|
||||
HILOGI("CreateNewSendMgr end.");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t MultiUserManager::CreateNewRecvMgr()
|
||||
{
|
||||
HILOGI("CreateNewRecvMgr begin. accountId: %{public}d.", currentUserId_);
|
||||
auto recvMgr = std::make_shared<DMSContinueRecvMgr>();
|
||||
recvMgrMap_.emplace(currentUserId_, recvMgr);
|
||||
HILOGI("CreateNewRecvMgr end.");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::shared_ptr<DMSContinueSendMgr> MultiUserManager::GetCurrentSendMgr()
|
||||
{
|
||||
HILOGI("GetCurrentSendMgr. accountId: %{public}d.", currentUserId_);
|
||||
std::lock_guard<std::mutex> lock(sendMutex_);
|
||||
if (sendMgrMap_.empty() || sendMgrMap_.find(currentUserId_) == sendMgrMap_.end()) {
|
||||
HILOGI("sendMgr need to create.");
|
||||
CreateNewSendMgr();
|
||||
}
|
||||
auto cur = sendMgrMap_.find(currentUserId_);
|
||||
return cur->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<DMSContinueRecvMgr> MultiUserManager::GetCurrentRecvMgr()
|
||||
{
|
||||
HILOGI("GetCurrentRecvMgr. accountId: %{public}d.", currentUserId_);
|
||||
std::lock_guard<std::mutex> lock(recvMutex_);
|
||||
if (recvMgrMap_.empty() || recvMgrMap_.find(currentUserId_) == recvMgrMap_.end()) {
|
||||
HILOGI("recvMgr need to create.");
|
||||
CreateNewRecvMgr();
|
||||
}
|
||||
auto cur = recvMgrMap_.find(currentUserId_);
|
||||
return cur->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<DMSContinueSendMgr> MultiUserManager::GetSendMgrByCallingUid(int32_t callingUid)
|
||||
{
|
||||
int32_t accountId = -1;
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId);
|
||||
HILOGI("GetRecvMgrByCallingUid. accountId: %{public}d , callingUid: %{public}d.", accountId, callingUid);
|
||||
std::lock_guard<std::mutex> lock(sendMutex_);
|
||||
if (sendMgrMap_.empty() || sendMgrMap_.find(accountId) == sendMgrMap_.end()) {
|
||||
HILOGI("sendMgr need to create.");
|
||||
CreateNewSendMgr();
|
||||
}
|
||||
auto cur = sendMgrMap_.find(accountId);
|
||||
return cur->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<DMSContinueRecvMgr> MultiUserManager::GetRecvMgrByCallingUid(int32_t callingUid)
|
||||
{
|
||||
int32_t accountId = -1;
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId);
|
||||
HILOGI("GetRecvMgrByCallingUid. userId: %{public}d , callingUid: %{public}d.", accountId, callingUid);
|
||||
std::lock_guard<std::mutex> lock(recvMutex_);
|
||||
if (recvMgrMap_.empty() || recvMgrMap_.find(accountId) == recvMgrMap_.end()) {
|
||||
HILOGI("recvMgr need to create.");
|
||||
CreateNewRecvMgr();
|
||||
}
|
||||
auto cur = recvMgrMap_.find(accountId);
|
||||
return cur->second;
|
||||
}
|
||||
|
||||
int32_t MultiUserManager::OnRegisterOnListener(const std::string& type,
|
||||
const sptr<IRemoteObject>& obj, int32_t callingUid)
|
||||
{
|
||||
int32_t accountId = -1;
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId);
|
||||
HILOGI("OnRegisterOnListener. accountId: %{public}d , callingUid: %{public}d.", accountId, callingUid);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(listenerMutex_);
|
||||
if (!IsUserForeground(accountId) || accountId != currentUserId_) {
|
||||
HILOGW("The current user is not foreground. accountId: %{public}d , currentUserId_: %{public}d.",
|
||||
accountId, currentUserId_);
|
||||
std::map<std::string, sptr<IRemoteObject>> param;
|
||||
param.emplace(type, obj);
|
||||
listenerCache_.emplace(accountId, param);
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
auto recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return DMS_NOT_GET_MANAGER;
|
||||
}
|
||||
return recvMgr->RegisterOnListener(type, obj);
|
||||
}
|
||||
|
||||
int32_t MultiUserManager::OnRegisterOffListener(const std::string& type,
|
||||
const sptr<IRemoteObject>& obj, int32_t callingUid)
|
||||
{
|
||||
int32_t accountId = -1;
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId);
|
||||
HILOGI("OnRegisterOffListener. accountId: %{public}d , callingUid: %{public}d.", accountId, callingUid);
|
||||
if (!IsUserForeground(accountId) || accountId != currentUserId_) {
|
||||
HILOGW("The current user is not foreground. accountId: %{public}d , currentUserId_: %{public}d.",
|
||||
accountId, currentUserId_);
|
||||
return DMS_NOT_FOREGROUND_USER;
|
||||
}
|
||||
auto recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return DMS_NOT_GET_MANAGER;
|
||||
}
|
||||
return recvMgr->RegisterOffListener(type, obj);
|
||||
}
|
||||
|
||||
int32_t MultiUserManager::GetForegroundUser()
|
||||
{
|
||||
int32_t accountId = INVALID_ID;
|
||||
ErrCode err = AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(accountId);
|
||||
if (err != ERR_OK || accountId == INVALID_ID) {
|
||||
HILOGE("GetForegroundOsAccountLocalId passing param invalid or return error!, err : %{public}d", err);
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
HILOGD("GetForegroundOsAccountLocalId accountId is: %{public}d", accountId);
|
||||
return accountId;
|
||||
}
|
||||
|
||||
bool MultiUserManager::IsUserForeground(int32_t accountId)
|
||||
{
|
||||
bool isForeground = false;
|
||||
std::vector<AccountSA::ForegroundOsAccount> accounts;
|
||||
ErrCode err = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccounts(accounts);
|
||||
if (err != ERR_OK) {
|
||||
HILOGE("GetForegroundOsAccounts passing param inval id or return error!, err : %{public}d", err);
|
||||
}
|
||||
if (!accounts.empty() && accounts[0].localId == accountId) {
|
||||
isForeground = true;
|
||||
}
|
||||
HILOGD("Current account. accounts[0].localId: %{public}d, accountId: %{public}d.", accounts[0].localId, accountId);
|
||||
return isForeground;
|
||||
}
|
||||
|
||||
bool MultiUserManager::IsCallerForeground(int32_t callingUid)
|
||||
{
|
||||
int32_t accountId = -1;
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId);
|
||||
return IsUserForeground(accountId);
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -211,6 +211,30 @@ ohos_unittest("distributedschedstubtest") {
|
||||
subsystem_name = "ability"
|
||||
}
|
||||
|
||||
ohos_unittest("multiusermanagertest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [ "unittest/multi_user_manager_test.cpp" ]
|
||||
sources += dtbschedmgr_sources
|
||||
|
||||
configs = [
|
||||
":test_config",
|
||||
"${distributed_service}/dtbschedmgr/test/resource:coverage_flags",
|
||||
]
|
||||
configs += dsched_configs
|
||||
if (is_standard_system) {
|
||||
external_deps = dsched_external_deps
|
||||
public_deps = dsched_public_deps
|
||||
}
|
||||
|
||||
if (dmsfwk_report_memmgr || dmsfwk_report_memmgr_plugins) {
|
||||
defines = [ "SUPPORT_DISTRIBUTEDCOMPONENT_TO_MEMMGR" ]
|
||||
}
|
||||
|
||||
part_name = "dmsfwk"
|
||||
subsystem_name = "ability"
|
||||
}
|
||||
|
||||
ohos_unittest("distributedschedadaptertest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
@ -782,6 +806,7 @@ group("unittest") {
|
||||
":dschedcontinuetest",
|
||||
":dschedswitchstatustest",
|
||||
":hisyseventreporttest",
|
||||
":multiusermanagertest",
|
||||
":softbusadaptertest",
|
||||
"${dms_path}/common/test/unittest:distributed_sched_utils_test",
|
||||
]
|
||||
|
File diff suppressed because it is too large
Load Diff
347
services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp
Normal file
347
services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp
Normal file
@ -0,0 +1,347 @@
|
||||
/*
|
||||
* 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 "multi_user_manager_test.h"
|
||||
|
||||
#define private public
|
||||
#include "multi_user_manager.h"
|
||||
#undef private
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TYPE = "type";
|
||||
}
|
||||
|
||||
void MultiUserManagerTest::SetUpTestCase()
|
||||
{
|
||||
DTEST_LOG << "MultiUserManagerTest::SetUpTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void MultiUserManagerTest::TearDownTestCase()
|
||||
{
|
||||
DTEST_LOG << "MultiUserManagerTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void MultiUserManagerTest::TearDown()
|
||||
{
|
||||
DTEST_LOG << "MultiUserManagerTest::TearDown" << std::endl;
|
||||
}
|
||||
|
||||
void MultiUserManagerTest::SetUp()
|
||||
{
|
||||
DTEST_LOG << "MultiUserManagerTest::SetUp" << std::endl;
|
||||
}
|
||||
|
||||
void RemoteOnListenerStubTest::OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId,
|
||||
const std::string &bundleName, const std::string &continueType, const std::string &srcBundleName)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_Init_001
|
||||
* @tc.desc: test Init
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_Init_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_Init_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test Init with set currentUserId_ sendMgr recvMgr;
|
||||
*/
|
||||
int32_t accountId = 100;
|
||||
MultiUserManager::GetInstance().Init();
|
||||
EXPECT_EQ(MultiUserManager::GetInstance().currentUserId_, accountId);
|
||||
auto sendMgr = MultiUserManager::GetInstance().sendMgrMap_.find(accountId);
|
||||
EXPECT_NE(sendMgr->second, nullptr);
|
||||
auto recvMgr = MultiUserManager::GetInstance().recvMgrMap_.find(accountId);
|
||||
EXPECT_NE(recvMgr->second, nullptr);
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_Init_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_UnInit_001
|
||||
* @tc.desc: test UnInit
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_UnInit_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_UnInit_001 start" << std::endl;
|
||||
/**
|
||||
* @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());
|
||||
|
||||
DTEST_LOG << "MultiUserManager_UnInit_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_OnUserSwitched_001
|
||||
* @tc.desc: test OnUserSwitched
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_OnUserSwitched_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_OnUserSwitched_001 start" << std::endl;
|
||||
/**
|
||||
* @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);
|
||||
EXPECT_EQ(MultiUserManager::GetInstance().currentUserId_, switchedAccountId);
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_OnUserSwitched_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_OnUserSwitched_002
|
||||
* @tc.desc: test OnUserSwitched
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_OnUserSwitched_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_OnUserSwitched_002 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserSwitched with cache switched user;
|
||||
*/
|
||||
int32_t accountId = 100;
|
||||
int32_t switchedAccountId = 101;
|
||||
MultiUserManager::GetInstance().Init();
|
||||
|
||||
std::map<std::string, sptr<IRemoteObject>> param;
|
||||
sptr<IRemoteObject> obj(new RemoteOnListenerStubTest());
|
||||
param.emplace(TYPE, obj);
|
||||
MultiUserManager::GetInstance().listenerCache_.emplace(switchedAccountId, param);
|
||||
|
||||
MultiUserManager::GetInstance().OnUserSwitched(switchedAccountId);
|
||||
EXPECT_EQ(MultiUserManager::GetInstance().currentUserId_, switchedAccountId);
|
||||
EXPECT_TRUE(MultiUserManager::GetInstance().listenerCache_.empty());
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_OnUserSwitched_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_OnUserRemoved_001
|
||||
* @tc.desc: test OnUserRemoved
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_OnUserRemoved_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_OnUserRemoved_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with remove by accountId sendMgr recvMgr;
|
||||
*/
|
||||
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);
|
||||
EXPECT_TRUE(recvMgr == MultiUserManager::GetInstance().recvMgrMap_.end());
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_OnUserRemoved_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_CreateNewSendMgr_001
|
||||
* @tc.desc: test CreateNewSendMgr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_CreateNewSendMgr_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_CreateNewSendMgr_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with create current user sendMgr;
|
||||
*/
|
||||
MultiUserManager::GetInstance().Init();
|
||||
int32_t ret = MultiUserManager::GetInstance().CreateNewSendMgr();
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_CreateNewSendMgr_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_CreateNewRecvMgr_001
|
||||
* @tc.desc: test CreateNewRecvMgr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_CreateNewRecvMgr_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_CreateNewRecvMgr_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with create current user recvMgr;
|
||||
*/
|
||||
MultiUserManager::GetInstance().Init();
|
||||
int32_t ret = MultiUserManager::GetInstance().CreateNewRecvMgr();
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_CreateNewRecvMgr_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_GetCurrentSendMgr_001
|
||||
* @tc.desc: test GetCurrentSendMgr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentSendMgr_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_GetCurrentSendMgr_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with create current user sendMgr;
|
||||
*/
|
||||
int32_t accountId = 100;
|
||||
MultiUserManager::GetInstance().Init();
|
||||
auto sendMgr = MultiUserManager::GetInstance().sendMgrMap_.find(accountId)->second;
|
||||
|
||||
auto ret = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
EXPECT_EQ(ret, sendMgr);
|
||||
|
||||
MultiUserManager::GetInstance().sendMgrMap_.insert({accountId, nullptr});
|
||||
ret = MultiUserManager::GetInstance().GetCurrentSendMgr();
|
||||
EXPECT_NE(ret, nullptr);
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_GetCurrentSendMgr_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_GetCurrentRecvMgr_001
|
||||
* @tc.desc: test GetCurrentRecvMgr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with create current user recvMgr;
|
||||
*/
|
||||
int32_t accountId = 100;
|
||||
MultiUserManager::GetInstance().Init();
|
||||
auto recvMgr = MultiUserManager::GetInstance().recvMgrMap_.find(accountId)->second;
|
||||
|
||||
auto ret = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
EXPECT_EQ(ret, recvMgr);
|
||||
|
||||
MultiUserManager::GetInstance().recvMgrMap_.insert({accountId, nullptr});
|
||||
ret = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
EXPECT_NE(ret, nullptr);
|
||||
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_OnRegisterOnListener_001
|
||||
* @tc.desc: test OnRegisterOnListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_OnRegisterOnListener_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_OnRegisterOnListener_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with register listener
|
||||
*/
|
||||
MultiUserManager::GetInstance().Init();
|
||||
|
||||
int32_t callingUid = 0;
|
||||
sptr<IRemoteObject> obj(new RemoteOnListenerStubTest());
|
||||
auto ret = MultiUserManager::GetInstance().OnRegisterOnListener(TYPE, obj, callingUid);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_OnRegisterOnListener_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_OnRegisterOffListener_001
|
||||
* @tc.desc: test OnRegisterOffListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_OnRegisterOffListener_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_OnRegisterOffListener_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with unregister listener
|
||||
*/
|
||||
MultiUserManager::GetInstance().Init();
|
||||
|
||||
int32_t callingUid = 0;
|
||||
sptr<IRemoteObject> obj(new RemoteOnListenerStubTest());
|
||||
auto ret = MultiUserManager::GetInstance().OnRegisterOffListener(TYPE, obj, callingUid);
|
||||
EXPECT_EQ(ret, DMS_NOT_FOREGROUND_USER);
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_OnRegisterOffListener_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_GetForegroundUser_001
|
||||
* @tc.desc: test GetForegroundUser
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_GetForegroundUser_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_GetForegroundUser_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with get currrent accountid
|
||||
*/
|
||||
int32_t accountId = 100;
|
||||
int32_t ret = MultiUserManager::GetInstance().GetForegroundUser();
|
||||
EXPECT_EQ(ret, accountId);
|
||||
|
||||
DTEST_LOG << "MultiUserManager_GetForegroundUser_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_IsUserForeground_001
|
||||
* @tc.desc: test IsUserForeground
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_IsUserForeground_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_IsUserForeground_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with is foreground user
|
||||
*/
|
||||
int32_t accountId = 100;
|
||||
int32_t otherAccountId = 101;
|
||||
|
||||
bool ret = MultiUserManager::GetInstance().IsUserForeground(accountId);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
ret = MultiUserManager::GetInstance().IsUserForeground(otherAccountId);
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
DTEST_LOG << "MultiUserManager_IsCallerForeground_001 end" << std::endl;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
40
services/dtbschedmgr/test/unittest/multi_user_manager_test.h
Normal file
40
services/dtbschedmgr/test/unittest/multi_user_manager_test.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 MULTI_USER_MANAGER_TEST_H
|
||||
#define MULTI_USER_MANAGER_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "remote_on_listener_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class MultiUserManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
|
||||
class RemoteOnListenerStubTest : public AAFwk::RemoteOnListenerStub {
|
||||
public:
|
||||
void OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId,
|
||||
const std::string &bundleName, const std::string &continueType, const std::string &srcBundleName) override;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // MULTI_USER_MANAGER_TEST_H
|
Loading…
Reference in New Issue
Block a user