mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 06:50:40 +00:00
支持删除指定任务
Signed-off-by: hubijie <hubijie@huawei.com>
This commit is contained in:
parent
8516e118c1
commit
95bac5e121
@ -145,6 +145,31 @@ 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 get success, others means get 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 sessioni persistentId which is clear failed.
|
||||
* @return WM_OK means get success, others means get failed.
|
||||
*/
|
||||
WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds);
|
||||
private:
|
||||
WindowManagerLite();
|
||||
~WindowManagerLite();
|
||||
|
@ -432,7 +432,12 @@ struct MainWindowInfo : public Parcelable {
|
||||
if (!parcel.WriteString(bundleName_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(persistentId_)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(bundleType_)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -441,11 +446,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(std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds));
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -326,6 +326,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();
|
||||
@ -486,7 +488,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 HandleGetAllMainWinodowInfos(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleClearMainSessions(MessageParcel& data, MessageParcel& reply);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_LITE_STUB_H
|
@ -8640,4 +8640,65 @@ WSError SceneSessionManager::NotifyEnterRecentTask(bool enterRecent)
|
||||
|
||||
return WSError::WS_OK;
|
||||
}
|
||||
|
||||
WMError SceneSessionManager::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) const
|
||||
{
|
||||
if (!infos.empty()) {
|
||||
return WMError::WM_ERROR_INCALID_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_);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
WSError result;
|
||||
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(session->GetWindowType())) {
|
||||
TLOGW(WmsLogTag::WMS_MAIN, "Session id:%{public}d is not mainWindow.", persistentId);
|
||||
clearFailedIds.push_back(persistentId);
|
||||
continue;
|
||||
}
|
||||
result = sceneSession->Clear();
|
||||
if (result != WSError::WS_OK) {
|
||||
TLOGW(WmsLogTag::WMS_MAIN, "Clear session failed, session id:%{public}d.", persistentId);
|
||||
clearFailedIds.push_back(persistentId);
|
||||
}
|
||||
}
|
||||
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::HandleGetAllMainWinodowInfos),
|
||||
std::make_pair(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS),
|
||||
&SceneSessionManagerLiteStub::HandleClearMainSessions),
|
||||
};
|
||||
|
||||
int SceneSessionManagerLiteStub::OnRemoteRequest(uint32_t code,
|
||||
@ -462,4 +464,39 @@ int SceneSessionManagerLiteStub::HandleGetMainWinodowInfo(MessageParcel &data, M
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
int SceneSessionManagerLiteStub::HandleGetAllMainWinodowInfos(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
std::vector<MainWindowInfo> infos;
|
||||
WMError errCode = GetAllMainWinodowInfos(infos);
|
||||
reply.WriteInt32(info.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: HandleGetAllMainWinodowInfos
|
||||
* @tc.desc: test function : HandleGetAllMainWinodowInfos
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerLiteStubTest, HandleGetAllMainWinodowInfos, Function | SmallTest | Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
auto res = sceneSessionManagerLiteStub_->
|
||||
SceneSessionManagerLiteStub::HandleGetAllMainWinodowInfos(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;
|
||||
@ -4377,6 +4378,75 @@ 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
|
||||
|
@ -355,6 +355,7 @@ ohos_shared_library("libwm_lite") {
|
||||
"${window_base_path}/utils:libwmutil_base",
|
||||
"${window_base_path}/window_scene/interfaces/innerkits:libwsutils",
|
||||
"${window_base_path}/window_scene/session_manager:session_manager_lite",
|
||||
"${window_base_path}/window_scene/common:window_scene_common",
|
||||
]
|
||||
|
||||
public_configs = [ ":libwm_public_config" ]
|
||||
|
@ -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,37 @@ 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 (!info.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,35 @@ 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(), GetMainWindowInfos(_, _)).Times(1).WillOnce(DoAll(SetArgReferee<1>(topNInfoResult),
|
||||
Return(WMError::WM_OK)));
|
||||
}
|
||||
}
|
||||
}
|
@ -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