mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 06:50:40 +00:00
commit
f900d4e2c7
@ -145,6 +145,32 @@ public:
|
||||
* @return WM_OK means get success, others means get failed.
|
||||
*/
|
||||
WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo);
|
||||
|
||||
/**
|
||||
* @brief Get all main window info.
|
||||
*
|
||||
* @param infos the all main window info.
|
||||
* @return WM_OK means get success, others means get failed.
|
||||
*/
|
||||
WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) const;
|
||||
|
||||
/**
|
||||
* @brief Clear a specified set of sessions.
|
||||
*
|
||||
* @param persistentIds a vector of session persistentId.
|
||||
* @return WM_OK means clear session success, others means clear failed.
|
||||
*/
|
||||
WMError ClearMainSessions(const std::vector<int32_t>& persistentIds);
|
||||
|
||||
/**
|
||||
* @brief Clear a specified set of sessions.
|
||||
*
|
||||
* @param persistentIds a vector of session persistentId.
|
||||
* @param clearFailedIds a vector of session persistentId which is clear failed.
|
||||
* @return WM_OK means clear session success, others means clear failed.
|
||||
*/
|
||||
WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds);
|
||||
|
||||
private:
|
||||
WindowManagerLite();
|
||||
~WindowManagerLite();
|
||||
|
@ -433,6 +433,13 @@ struct MainWindowInfo : public Parcelable {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(persistentId_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(bundleType_)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -441,11 +448,15 @@ struct MainWindowInfo : public Parcelable {
|
||||
MainWindowInfo* mainWindowInfo = new MainWindowInfo;
|
||||
mainWindowInfo->pid_ = parcel.ReadInt32();
|
||||
mainWindowInfo->bundleName_ = parcel.ReadString();
|
||||
mainWindowInfo->persistentId_ = parcel.ReadInt32();
|
||||
mainWindowInfo->bundleType_ = parcel.ReadInt32();
|
||||
return mainWindowInfo;
|
||||
}
|
||||
|
||||
int32_t pid_ = 0;
|
||||
std::string bundleName_ = "";
|
||||
int32_t persistentId_ = 0;
|
||||
int32_t bundleType_ = 0;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
@ -32,6 +32,10 @@ public:
|
||||
MOCK_METHOD1(GetWindowModeType, WMError(WindowModeType& windowModeType));
|
||||
MOCK_METHOD2(GetMainWindowInfos, WMError(int32_t topNum,
|
||||
std::vector<MainWindowInfo>& topNInfo));
|
||||
MOCK_METHOD1(GetAllMainWindowInfos, WMError(std::vector<MainWindowInfo>& infos));
|
||||
MOCK_METHOD1(ClearMainSessions, WMError(const std::vector<int32_t>& persistentIds));
|
||||
MOCK_METHOD2(ClearMainSessions, WMError(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds));
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -329,6 +329,8 @@ public:
|
||||
int32_t GetCustomDecorHeight(int32_t persistentId);
|
||||
WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo);
|
||||
WSError NotifyEnterRecentTask(bool enterRecent);
|
||||
WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) const;
|
||||
WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds);
|
||||
|
||||
protected:
|
||||
SceneSessionManager();
|
||||
@ -489,7 +491,7 @@ private:
|
||||
|
||||
sptr<RootSceneSession> rootSceneSession_;
|
||||
std::weak_ptr<AbilityRuntime::Context> rootSceneContextWeak_;
|
||||
std::shared_mutex sceneSessionMapMutex_;
|
||||
mutable std::shared_mutex sceneSessionMapMutex_;
|
||||
std::map<int32_t, sptr<SceneSession>> sceneSessionMap_;
|
||||
std::map<int32_t, sptr<SceneSession>> systemTopSceneSessionMap_;
|
||||
std::map<int32_t, sptr<SceneSession>> nonSystemFloatSceneSessionMap_;
|
||||
|
@ -63,6 +63,8 @@ public:
|
||||
WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode);
|
||||
WMError GetWindowModeType(WindowModeType& windowModeType) override;
|
||||
WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo) override;
|
||||
WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) override;
|
||||
WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds) override;
|
||||
|
||||
protected:
|
||||
SceneSessionManagerLite() = default;
|
||||
|
@ -69,6 +69,8 @@ public:
|
||||
TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID,
|
||||
TRANS_ID_GET_WINDOW_MODE_TYPE,
|
||||
TRANS_ID_GET_TOPN_MAIN_WINDOW_INFO,
|
||||
TRANS_ID_GET_ALL_MAIN_WINDOW_INFO,
|
||||
TRANS_ID_CLEAR_MAIN_SESSIONS,
|
||||
};
|
||||
|
||||
virtual WSError SetSessionLabel(const sptr<IRemoteObject>& token, const std::string& label) = 0;
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) override;
|
||||
WMError GetWindowModeType(WindowModeType& windowModeType) override;
|
||||
WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo) override;
|
||||
WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) override;
|
||||
WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds) override;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
|
@ -64,6 +64,8 @@ private:
|
||||
int HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleGetWindowModeType(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleGetMainWinodowInfo(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleGetAllMainWindowInfos(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleClearMainSessions(MessageParcel& data, MessageParcel& reply);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_LITE_STUB_H
|
@ -8745,4 +8745,62 @@ WSError SceneSessionManager::NotifyEnterRecentTask(bool enterRecent)
|
||||
|
||||
return WSError::WS_OK;
|
||||
}
|
||||
|
||||
WMError SceneSessionManager::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) const
|
||||
{
|
||||
if (!infos.empty()) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "Input param invalid, infos must be empty.");
|
||||
return WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
if (!SessionPermission::IsSACalling() && !SessionPermission::IsShellCall()) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "Get all mainWindow infos failed, only support SA calling.");
|
||||
return WMError::WM_ERROR_INVALID_PERMISSION;
|
||||
}
|
||||
std::shared_lock<std::shared_mutex> lock(sceneSessionMapMutex_);
|
||||
for (const auto& iter : sceneSessionMap_) {
|
||||
auto& session = iter.second;
|
||||
if (session == nullptr || !WindowHelper::IsMainWindow(session->GetWindowType())) {
|
||||
continue;
|
||||
}
|
||||
MainWindowInfo info;
|
||||
auto abilityInfo = session->GetSessionInfo().abilityInfo;
|
||||
if (abilityInfo == nullptr) {
|
||||
TLOGW(WmsLogTag::WMS_MAIN, "Session id:%{public}d abilityInfo is null.", session->GetPersistentId());
|
||||
continue;
|
||||
}
|
||||
info.pid_ = session->GetCallingPid();
|
||||
info.bundleName_ = session->GetSessionInfo().bundleName_;
|
||||
info.persistentId_ = session->GetPersistentId();
|
||||
info.bundleType_ = static_cast<int32_t>(abilityInfo->applicationInfo.bundleType);
|
||||
TLOGD(WmsLogTag::WMS_MAIN, "Get mainWindow info, Session id:%{public}d, bundleName:%{public}s, "
|
||||
"bundleType:%{public}d", session->GetPersistentId(), info.bundleName_.c_str(), info.bundleType_);
|
||||
infos.push_back(info);
|
||||
}
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
|
||||
WMError SceneSessionManager::ClearMainSessions(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds)
|
||||
{
|
||||
if (!SessionPermission::IsSACalling() && !SessionPermission::IsShellCall()) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "Clear main sessions failed, only support SA calling.");
|
||||
return WMError::WM_ERROR_INVALID_PERMISSION;
|
||||
}
|
||||
clearFailedIds.clear();
|
||||
for (const auto persistentId : persistentIds) {
|
||||
auto sceneSession = GetSceneSession(persistentId);
|
||||
if (sceneSession == nullptr) {
|
||||
TLOGW(WmsLogTag::WMS_MAIN, "Session id:%{public}d is not found.", persistentId);
|
||||
clearFailedIds.push_back(persistentId);
|
||||
continue;
|
||||
}
|
||||
if (!WindowHelper::IsMainWindow(sceneSession->GetWindowType())) {
|
||||
TLOGW(WmsLogTag::WMS_MAIN, "Session id:%{public}d is not mainWindow.", persistentId);
|
||||
clearFailedIds.push_back(persistentId);
|
||||
continue;
|
||||
}
|
||||
sceneSession->Clear();
|
||||
}
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -209,4 +209,15 @@ WMError SceneSessionManagerLite::GetMainWindowInfos(int32_t topNum, std::vector<
|
||||
{
|
||||
return SceneSessionManager::GetInstance().GetMainWindowInfos(topNum, topNInfo);
|
||||
}
|
||||
|
||||
WMError SceneSessionManagerLite::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos)
|
||||
{
|
||||
return SceneSessionManager::GetInstance().GetAllMainWindowInfos(infos);
|
||||
}
|
||||
|
||||
WMError SceneSessionManagerLite::ClearMainSessions(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds)
|
||||
{
|
||||
return SceneSessionManager::GetInstance().ClearMainSessions(persistentIds, clearFailedIds);
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -828,4 +828,51 @@ WMError SceneSessionManagerLiteProxy::GetMainWindowInfos(int32_t topNum, std::ve
|
||||
|
||||
return static_cast<WMError>(reply.ReadInt32());
|
||||
}
|
||||
|
||||
WMError SceneSessionManagerLiteProxy::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (Remote()->SendRequest(static_cast<int32_t>(
|
||||
SceneSessionManagerLiteMessage::TRANS_ID_GET_ALL_MAIN_WINDOW_INFO), data, reply, option) != ERR_NONE) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
|
||||
WMError error = static_cast<WMError>(GetParcelableInfos(reply, infos));
|
||||
if (error != WMError::WM_OK) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "get info error");
|
||||
return error;
|
||||
}
|
||||
|
||||
return static_cast<WMError>(reply.ReadInt32());
|
||||
}
|
||||
|
||||
WMError SceneSessionManagerLiteProxy::ClearMainSessions(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (!data.WriteInt32Vector(persistentIds)) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "Write persistentIds failed");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (Remote()->SendRequest(static_cast<int32_t>(
|
||||
SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS), data, reply, option) != ERR_NONE) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
reply.ReadInt32Vector(&clearFailedIds);
|
||||
return static_cast<WMError>(reply.ReadInt32());
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -85,8 +85,10 @@ const std::map<uint32_t, SceneSessionManagerLiteStubFunc> SceneSessionManagerLit
|
||||
&SceneSessionManagerLiteStub::HandleGetVisibilityWindowInfo),
|
||||
std::make_pair(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_MODE_TYPE),
|
||||
&SceneSessionManagerLiteStub::HandleGetWindowModeType),
|
||||
std::make_pair(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_TOPN_MAIN_WINDOW_INFO),
|
||||
&SceneSessionManagerLiteStub::HandleGetMainWinodowInfo),
|
||||
std::make_pair(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_ALL_MAIN_WINDOW_INFO),
|
||||
&SceneSessionManagerLiteStub::HandleGetAllMainWindowInfos),
|
||||
std::make_pair(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS),
|
||||
&SceneSessionManagerLiteStub::HandleClearMainSessions),
|
||||
};
|
||||
|
||||
int SceneSessionManagerLiteStub::OnRemoteRequest(uint32_t code,
|
||||
@ -462,4 +464,40 @@ int SceneSessionManagerLiteStub::HandleGetMainWinodowInfo(MessageParcel &data, M
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
int SceneSessionManagerLiteStub::HandleGetAllMainWindowInfos(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
std::vector<MainWindowInfo> infos;
|
||||
WMError errCode = GetAllMainWindowInfos(infos);
|
||||
reply.WriteInt32(infos.size());
|
||||
for (auto& info : infos) {
|
||||
if (!reply.WriteParcelable(&info)) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "write main window info fail");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
int SceneSessionManagerLiteStub::HandleClearMainSessions(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
std::vector<int32_t> persistentIds;
|
||||
std::vector<int32_t> clearFailedIds;
|
||||
if (!data.ReadInt32Vector(&persistentIds)) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "failed to read persistentIds.");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
WMError errCode = ClearMainSessions(persistentIds, clearFailedIds);
|
||||
if (!reply.WriteInt32Vector(clearFailedIds)) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "write clearFailedIds fail.");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
return ERR_NONE;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -136,6 +136,18 @@ class MockSceneSessionManagerLiteStub : public SceneSessionManagerLiteStub {
|
||||
topNInfo.push_back(mainWindowInfo);
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) override
|
||||
{
|
||||
MainWindowInfo mainWindowInfo;
|
||||
infos.push_back(mainWindowInfo);
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
WMError ClearMainSessions(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds) override
|
||||
{
|
||||
clearFailedIds.push_back(1);
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
sptr<IRemoteObject> AsObject() override
|
||||
{
|
||||
return nullptr;
|
||||
@ -565,6 +577,36 @@ HWTEST_F(SceneSessionManagerLiteStubTest, HandleGetMainWinodowInfo, Function | S
|
||||
EXPECT_EQ(ERR_NONE, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleGetAllMainWindowInfos
|
||||
* @tc.desc: test function : HandleGetAllMainWindowInfos
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerLiteStubTest, HandleGetAllMainWindowInfos, Function | SmallTest | Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
auto res = sceneSessionManagerLiteStub_->
|
||||
SceneSessionManagerLiteStub::HandleGetAllMainWindowInfos(data, reply);
|
||||
EXPECT_EQ(ERR_NONE, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleClearMainSessions
|
||||
* @tc.desc: test function : HandleClearMainSessions
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerLiteStubTest, HandleClearMainSessions, Function | SmallTest | Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
std::vector<int32_t> persistentIds = {1, 2, 3};
|
||||
data.WriteInt32Vector(persistentIds);
|
||||
auto res = sceneSessionManagerLiteStub_->
|
||||
SceneSessionManagerLiteStub::HandleClearMainSessions(data, reply);
|
||||
EXPECT_EQ(ERR_NONE, res);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@
|
||||
#include "zidl/window_manager_agent_interface.h"
|
||||
#include "mock/mock_session_stage.h"
|
||||
#include "mock/mock_window_event_channel.h"
|
||||
#include "application_info.h"
|
||||
#include "context.h"
|
||||
|
||||
using namespace testing;
|
||||
@ -4390,6 +4391,74 @@ HWTEST_F(SceneSessionManagerTest, TestIsEnablePiPCreate, Function | SmallTest |
|
||||
ssm_->sceneSessionMap_.insert({100, sceneSession});
|
||||
ASSERT_TRUE(ssm_->isEnablePiPCreate(property));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllMainWindowInfos001
|
||||
* @tc.desc: SceneSessionManager get all main window infos.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerTest, GetAllMainWindowInfos001, Function | SmallTest | Level3)
|
||||
{
|
||||
SessionInfo info;
|
||||
info.abilityName_ = "test1";
|
||||
info.bundleName_ = "test1";
|
||||
info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
|
||||
info.persistentId_ = 1;
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
|
||||
AppExecFwk::ApplicationInfo applicationInfo;
|
||||
applicationInfo.bundleType = AppExecFwk::BundleType::ATOMIC_SERVICE;
|
||||
abilityInfo->applicationInfo = applicationInfo;
|
||||
info.abilityInfo = abilityInfo;
|
||||
sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
|
||||
if (sceneSession == nullptr) {
|
||||
return;
|
||||
}
|
||||
ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
|
||||
std::vector<MainWindowInfo> infos;
|
||||
WMError result = ssm_->GetAllMainWindowInfos(infos);
|
||||
EXPECT_EQ(result, WMError::WM_OK);
|
||||
ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllMainWindowInfos002
|
||||
* @tc.desc: SceneSessionManager get all main window infos, input params are not empty.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerTest, GetAllMainWindowInfos002, Function | SmallTest | Level3)
|
||||
{
|
||||
std::vector<MainWindowInfo> infos;
|
||||
MainWindowInfo info;
|
||||
info.pid_ = 1000;
|
||||
info.bundleName_ = "test";
|
||||
infos.push_back(info);
|
||||
WMError result = ssm_->GetAllMainWindowInfos(infos);
|
||||
EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearMainSessions
|
||||
* @tc.desc: SceneSessionManager get all main window infos, input params are not empty.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerTest, ClearMainSessions, Function | SmallTest | Level3)
|
||||
{
|
||||
SessionInfo info;
|
||||
info.abilityName_ = "test1";
|
||||
info.bundleName_ = "test1";
|
||||
info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
|
||||
sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
|
||||
if (sceneSession == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::vector<int32_t> clearFailedIds;
|
||||
ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
|
||||
std::vector<int32_t> persistentIds = {sceneSession->GetPersistentId()};
|
||||
auto result = ssm_->ClearMainSessions(persistentIds, clearFailedIds);
|
||||
EXPECT_EQ(result, WMError::WM_OK);
|
||||
EXPECT_EQ(clearFailedIds.size(), 0);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -353,6 +353,7 @@ ohos_shared_library("libwm_lite") {
|
||||
|
||||
deps = [
|
||||
"${window_base_path}/utils:libwmutil_base",
|
||||
"${window_base_path}/window_scene/common:window_scene_common",
|
||||
"${window_base_path}/window_scene/interfaces/innerkits:libwsutils",
|
||||
"${window_base_path}/window_scene/session_manager:session_manager_lite",
|
||||
]
|
||||
|
@ -45,6 +45,9 @@ public:
|
||||
virtual void ClearWindowAdapter();
|
||||
virtual WMError GetWindowModeType(WindowModeType& windowModeType);
|
||||
virtual WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo);
|
||||
virtual WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos);
|
||||
virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds);
|
||||
virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds);
|
||||
|
||||
private:
|
||||
static inline SingletonDelegator<WindowAdapterLite> delegator;
|
||||
|
@ -188,5 +188,28 @@ WMError WindowAdapterLite::GetMainWindowInfos(int32_t topNum, std::vector<MainWi
|
||||
TLOGD(WmsLogTag::WMS_MAIN, "get top main window info");
|
||||
return windowManagerServiceProxy_->GetMainWindowInfos(topNum, topNInfo);
|
||||
}
|
||||
|
||||
WMError WindowAdapterLite::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
TLOGD(WmsLogTag::WMS_MAIN, "get all main window info");
|
||||
return windowManagerServiceProxy_->GetAllMainWindowInfos(infos);
|
||||
}
|
||||
|
||||
WMError WindowAdapterLite::ClearMainSessions(const std::vector<int32_t>& persistentIds)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
TLOGD(WmsLogTag::WMS_MAIN, "clear main sessions.");
|
||||
std::vector<int32_t> clearFailedIds;
|
||||
return windowManagerServiceProxy_->ClearMainSessions(persistentIds, clearFailedIds);
|
||||
}
|
||||
|
||||
WMError WindowAdapterLite::ClearMainSessions(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
TLOGD(WmsLogTag::WMS_MAIN, "clear main sessions with failed ids.");
|
||||
return windowManagerServiceProxy_->ClearMainSessions(persistentIds, clearFailedIds);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -546,5 +546,33 @@ WMError WindowManagerLite::GetMainWindowInfos(int32_t topNum, std::vector<MainWi
|
||||
TLOGI(WmsLogTag::WMS_MAIN, "Get main window info lite");
|
||||
return SingletonContainer::Get<WindowAdapterLite>().GetMainWindowInfos(topNum, topNInfo);
|
||||
}
|
||||
|
||||
WMError WindowManagerLite::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) const
|
||||
{
|
||||
if (!infos.empty()) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "infos is not empty.");
|
||||
return WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
return SingletonContainer::Get<WindowAdapterLite>().GetAllMainWindowInfos(infos);
|
||||
}
|
||||
|
||||
WMError WindowManagerLite::ClearMainSessions(const std::vector<int32_t>& persistentIds)
|
||||
{
|
||||
if (persistentIds.empty()) {
|
||||
TLOGW(WmsLogTag::WMS_MAIN, "Clear main Session failed, persistentIds is empty.");
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
return SingletonContainer::Get<WindowAdapterLite>().ClearMainSessions(persistentIds);
|
||||
}
|
||||
|
||||
WMError WindowManagerLite::ClearMainSessions(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds)
|
||||
{
|
||||
if (persistentIds.empty()) {
|
||||
TLOGW(WmsLogTag::WMS_MAIN, "Clear main Session failed, persistentIds is empty.");
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
return SingletonContainer::Get<WindowAdapterLite>().ClearMainSessions(persistentIds, clearFailedIds);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -297,5 +297,130 @@ HWTEST_F(WindowManagerLiteTest, Test04, Function | SmallTest | Level2)
|
||||
auto ret = windowChecker.CheckWindowId(-1);
|
||||
ASSERT_EQ(-1, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllMainWindowInfos001
|
||||
* @tc.desc: GetAllMainWindowInfos001
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowManagerLiteTest, GetAllMainWindowInfos001, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
std::vector<MainWindowInfo> infos;
|
||||
std::vector<MainWindowInfo> infosResult;
|
||||
MainWindowInfo info1;
|
||||
info1.pid_ = 1900;
|
||||
info1.bundleName_ = "calendar";
|
||||
|
||||
MainWindowInfo info2;
|
||||
info1.pid_ = 1901;
|
||||
info1.bundleName_ = "settings";
|
||||
|
||||
MainWindowInfo info3;
|
||||
info1.pid_ = 1902;
|
||||
info1.bundleName_ = "photos";
|
||||
|
||||
infosResult.push_back(info1);
|
||||
infosResult.push_back(info2);
|
||||
infosResult.push_back(info3);
|
||||
|
||||
EXPECT_CALL(m->Mock(), GetAllMainWindowInfos(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(infosResult),
|
||||
Return(WMError::WM_OK)));
|
||||
|
||||
auto errorCode = WindowManagerLite::GetInstance().GetAllMainWindowInfos(infos);
|
||||
ASSERT_EQ(WMError::WM_OK, errorCode);
|
||||
auto it1 = infos.begin();
|
||||
auto it2 = infosResult.begin();
|
||||
for (; it1 != infos.end() && it2 != infosResult.end(); it1++, it2++) {
|
||||
ASSERT_EQ(it1->pid_, it2->pid_);
|
||||
ASSERT_EQ(it1->bundleName_, it2->bundleName_);
|
||||
ASSERT_EQ(it1->persistentId_, it2->persistentId_);
|
||||
ASSERT_EQ(it1->bundleType_, it2->bundleType_);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllMainWindowInfos002
|
||||
* @tc.desc: GetAllMainWindowInfos002
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowManagerLiteTest, GetAllMainWindowInfos002, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
std::vector<MainWindowInfo> infos;
|
||||
MainWindowInfo info1;
|
||||
info1.pid_ = 1900;
|
||||
info1.bundleName_ = "calendar";
|
||||
infos.push_back(info1);
|
||||
|
||||
EXPECT_CALL(m->Mock(), GetAllMainWindowInfos(_)).Times(0).WillOnce(DoAll(Return(WMError::WM_OK)));
|
||||
|
||||
auto errorCode = WindowManagerLite::GetInstance().GetAllMainWindowInfos(infos);
|
||||
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearMainSessions001
|
||||
* @tc.desc: ClearMainSessions001
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowManagerLiteTest, ClearMainSessions001, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
std::vector<int32_t> persistentIds;
|
||||
|
||||
EXPECT_CALL(m->Mock(), ClearMainSessions(_)).Times(0).WillOnce(Return(WMError::WM_OK));
|
||||
|
||||
auto errorCode = WindowManagerLite::GetInstance().ClearMainSessions(persistentIds);
|
||||
ASSERT_EQ(WMError::WM_OK, errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearMainSessions002
|
||||
* @tc.desc: ClearMainSessions002
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowManagerLiteTest, ClearMainSessions002, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
std::vector<int32_t> persistentIds = { 1, 2 };
|
||||
|
||||
EXPECT_CALL(m->Mock(), ClearMainSessions(_)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
|
||||
auto errorCode = WindowManagerLite::GetInstance().ClearMainSessions(persistentIds);
|
||||
ASSERT_EQ(WMError::WM_OK, errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearMainSessions003
|
||||
* @tc.desc: ClearMainSessions003
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowManagerLiteTest, ClearMainSessions003, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
std::vector<int32_t> persistentIds;
|
||||
std::vector<int32_t> clearFailedIds;
|
||||
EXPECT_CALL(m->Mock(), ClearMainSessions(_, _)).Times(0).WillOnce(Return(WMError::WM_OK));
|
||||
|
||||
auto errorCode = WindowManagerLite::GetInstance().ClearMainSessions(persistentIds, clearFailedIds);
|
||||
ASSERT_EQ(WMError::WM_OK, errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearMainSessions004
|
||||
* @tc.desc: ClearMainSessions004
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowManagerLiteTest, ClearMainSessions004, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
std::vector<int32_t> persistentIds = { 1, 2 };
|
||||
std::vector<int32_t> clearFailedIds;
|
||||
EXPECT_CALL(m->Mock(), ClearMainSessions(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
|
||||
auto errorCode = WindowManagerLite::GetInstance().ClearMainSessions(persistentIds, clearFailedIds);
|
||||
ASSERT_EQ(WMError::WM_OK, errorCode);
|
||||
}
|
||||
}
|
||||
}
|
@ -42,6 +42,9 @@ public:
|
||||
virtual WMError CheckWindowId(int32_t windowId, int32_t &pid) = 0;
|
||||
virtual WMError GetWindowModeType(WindowModeType& windowModeType) { return WMError::WM_OK; }
|
||||
virtual WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo) = 0;
|
||||
virtual WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) = 0;
|
||||
virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user