优化LockSessionByAbilityInfo

Signed-off-by: nzy <niezhiyuan@huawei.com>
This commit is contained in:
nzy 2025-01-21 22:33:37 +08:00
parent 5a8d01867e
commit 63fdf32186
12 changed files with 139 additions and 235 deletions

View File

@ -300,6 +300,61 @@ struct AppUseControlInfo : public Parcelable {
bool isNeedControl_ = false;
};
/**
* @struct AbilityInfoBase
*
* @brief ability info.
*/
struct AbilityInfoBase : public Parcelable {
/**
* @brief Marshalling AbilityInfoBase.
*
* @param parcel Package of AbilityInfoBase.
* @return True means marshall success, false means marshall failed.
*/
bool Marshalling(Parcel& parcel) const override
{
return parcel.WriteString(bundleName) &&
parcel.WriteString(moduleName) &&
parcel.WriteString(abilityName) &&
parcel.WriteInt32(appIndex);
}
/**
* @brief Unmarshalling AbilityInfoBase.
*
* @param parcel Package of AbilityInfoBase.
* @return AbilityInfoBase object.
*/
static AbilityInfoBase* Unmarshalling(Parcel& parcel)
{
auto info = new AbilityInfoBase();
if (!parcel.ReadString(info->bundleName) ||
!parcel.ReadString(info->moduleName) ||
!parcel.ReadString(info->abilityName) ||
!parcel.ReadInt32(info->appIndex)) {
delete info;
return nullptr;
}
return info;
}
bool IsValid() const
{
return !bundleName.empty() && !moduleName.empty() && !abilityName.empty() && appIndex >= 0;
}
std::string ToKeyString() const
{
return bundleName + "_" + moduleName + "_" + abilityName + "_" + std::to_string(appIndex);
}
std::string bundleName;
std::string moduleName;
std::string abilityName;
int32_t appIndex = 0;
};
/**
* @class UnreliableWindowInfo
*

View File

@ -596,12 +596,9 @@ public:
WMError TerminateSessionByPersistentId(int32_t persistentId);
void SetUserAuthPassed(bool isUserAuthPassed);
bool IsUserAuthPassed() const;
void GetMainSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex, std::vector<sptr<SceneSession>>& mainSessions) const;
WMError LockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex);
WMError UnlockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex);
void GetMainSessionByAbilityInfo(const AbilityInfoBase& abilityInfo,
std::vector<sptr<SceneSession>>& mainSessions) const;
WMError LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock);
protected:
SceneSessionManager();

View File

@ -80,10 +80,7 @@ public:
WSError NotifyAppUseControlList(ControlAppType type, int32_t userId,
const std::vector<AppUseControlInfo>& controlList) override;
WMError MinimizeMainSession(const std::string& bundleName, int32_t appIndex, int32_t userId) override;
WMError LockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex) override;
WMError UnlockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex) override;
WMError LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock) override;
WMError HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken,
bool& hasOrNot) override;
};

View File

@ -85,7 +85,6 @@ public:
TRANS_ID_NOTIFY_APP_USE_CONTROL_LIST,
TRANS_ID_MINIMIZE_MAIN_SESSION,
TRANS_ID_LOCK_SESSION_BY_ABILITY_INFO,
TRANS_ID_UNLOCK_SESSION_BY_ABILITY_INFO,
TRANS_ID_HAS_FLOAT_FOREGROUND,
};
@ -167,36 +166,18 @@ public:
virtual WMError MinimizeMainSession(const std::string& bundleName, int32_t appIndex, int32_t userId) = 0;
/**
* @brief Lock a session in recent tasks.
* @brief Lock or unlock a session in recent tasks.
*
* This function locks the session in recent tasks.
* The invoker must be an SA or SystemApp and have the related permission.
* This function lock or unlock the session in recent tasks.
* The invoker must be an SA or SystemApp and have the ohos.permission.MANAGE_MISSIONS permission.
*
* @param bundleName bundle name of the session that needed to be locked.
* @param moduleName moduel name of the session that needed to be locked.
* @param abilityName ability name of the session that needed to be locked.
* @param appIndex appIndex of the session that needed to be locked.
* @param AbilityInfoBase abilityInfo of the session that needed to be locked or locked.
* @param isLock isLock of the session that needed to be locked or unlocked.
* @return Successful call returns WMError: WS-OK, otherwise it indicates failure
* @permission application requires SA permission or SystemApp permission
* @permission application requires ohos.permission.MANAGE_MISSIONS permission and
* SA permission or SystemApp permission
*/
virtual WMError LockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex) = 0;
/**
* @brief Unlock the session in recent tasks.
*
* This function unlocks the session in recent tasks.
* The invoker must be an SA or SystemApp and have the related permission.
*
* @param bundleName bundle name of the session that needed to be unlocked.
* @param moduleName moduel name of the session that needed to be unlocked.
* @param abilityName ability name of the session that needed to be unlocked.
* @param appIndex appIndex of the session that needed to be unlocked.
* @return Successful call returns WMError: WS-OK, otherwise it indicates failure
* @permission application requires SA permission or SystemApp permission
*/
virtual WMError UnlockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex) = 0;
virtual WMError LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock) = 0;
/**
* @brief Query if there is float type window foreground of an abilityToken

View File

@ -90,10 +90,7 @@ public:
WSError NotifyAppUseControlList(ControlAppType type, int32_t userId,
const std::vector<AppUseControlInfo>& controlList) override;
WMError MinimizeMainSession(const std::string& bundleName, int32_t appIndex, int32_t userId) override;
WMError LockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex) override;
WMError UnlockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex) override;
WMError LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock) override;
WMError HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken,
bool& hasOrNot) override;

View File

@ -78,7 +78,6 @@ private:
int HandleNotifyAppUseControlList(MessageParcel& data, MessageParcel& reply);
int HandleMinimizeMainSession(MessageParcel& data, MessageParcel& reply);
int HandleLockSessionByAbilityInfo(MessageParcel& data, MessageParcel& reply);
int HandleUnlockSessionByAbilityInfo(MessageParcel& data, MessageParcel& reply);
int HandleHasFloatingWindowForeground(MessageParcel& data, MessageParcel& reply);
int ProcessRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option);

View File

@ -130,6 +130,7 @@ constexpr uint32_t MAX_SUB_WINDOW_LEVEL = 10;
constexpr uint64_t DEFAULT_DISPLAY_ID = 0;
constexpr uint64_t VIRTUAL_DISPLAY_ID = 999;
constexpr uint32_t DEFAULT_LOCK_SCREEN_ZORDER = 2000;
constexpr int32_t MAX_LOCK_STATUS_CACHE_SIZE = 1000;
const std::map<std::string, OHOS::AppExecFwk::DisplayOrientation> STRING_TO_DISPLAY_ORIENTATION_MAP = {
{"unspecified", OHOS::AppExecFwk::DisplayOrientation::UNSPECIFIED},
@ -1340,21 +1341,18 @@ void SceneSessionManager::GetMainSessionByBundleNameAndAppIndex(
}
}
void SceneSessionManager::GetMainSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex, std::vector<sptr<SceneSession>>& mainSessions) const
void SceneSessionManager::GetMainSessionByAbilityInfo(const AbilityInfoBase& abilityInfo,
std::vector<sptr<SceneSession>>& mainSessions) const
{
if (bundleName.empty() || moduleName.empty() || abilityName.empty()) {
return;
}
std::shared_lock<std::shared_mutex> lock(sceneSessionMapMutex_);
for (const auto& [_, sceneSession] : sceneSessionMap_) {
if (!sceneSession || !SessionHelper::IsMainWindow(sceneSession->GetWindowType())) {
continue;
}
if (sceneSession->GetSessionInfo().bundleName_ == bundleName &&
sceneSession->GetSessionInfo().moduleName_ == moduleName &&
sceneSession->GetSessionInfo().abilityName_ == abilityName &&
sceneSession->GetSessionInfo().appIndex_ == appIndex) {
if (sceneSession->GetSessionInfo().bundleName_ == abilityInfo.bundleName &&
sceneSession->GetSessionInfo().moduleName_ == abilityInfo.moduleName &&
sceneSession->GetSessionInfo().abilityName_ == abilityInfo.abilityName &&
sceneSession->GetSessionInfo().appIndex_ == abilityInfo.appIndex) {
mainSessions.push_back(sceneSession);
}
}
@ -2722,8 +2720,7 @@ void SceneSessionManager::ResetSceneSessionInfoWant(const sptr<AAFwk::SessionInf
std::string keySessionId = sceneSessionInfo->want.GetStringParam(ATOMIC_SERVICE_SESSION_ID);
want.SetParam(ATOMIC_SERVICE_SESSION_ID, keySessionId);
sceneSessionInfo->want = std::move(want);
TLOGI(WmsLogTag::WMS_MAIN, "sceneSessionInfo.resultCode: %{public}d, keySessionId: %{public}s",
sceneSessionInfo->resultCode, keySessionId.c_str());
TLOGI(WmsLogTag::WMS_MAIN, "keySessionId: %{public}s", keySessionId.c_str());
}
}
@ -12538,52 +12535,52 @@ WMError SceneSessionManager::ShiftAppWindowPointerEvent(int32_t sourcePersistent
}, __func__);
}
WMError SceneSessionManager::LockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex)
WMError SceneSessionManager::LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock)
{
if (!SessionPermission::IsSystemAppCall() && !SessionPermission::IsSACalling()) {
TLOGE(WmsLogTag::WMS_LIFE, "The caller is neither a system app nor an SA.");
return WMError::WM_ERROR_INVALID_PERMISSION;
}
taskScheduler_->PostAsyncTask([this, bundleName, moduleName, abilityName, appIndex, where = __func__] {
if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) {
TLOGE(WmsLogTag::WMS_LIFE, "The caller has not permission granted");
return WMError::WM_ERROR_INVALID_PERMISSION;
}
TLOGI(WmsLogTag::WMS_LIFE,
"bundleName:%{public}s moduleName:%{public}s abilityName:%{public}s appIndex:%{public}d isLock:%{public}d",
abilityInfo.bundleName.c_str(), abilityInfo.moduleName.c_str(), abilityInfo.abilityName.c_str(),
abilityInfo.appIndex, isLock);
if (!abilityInfo.IsValid()) {
TLOGE(WmsLogTag::WMS_LIFE, "abilityInfo not valid");
return WMError::WM_ERROR_INVALID_PARAM;
}
taskScheduler_->PostAsyncTask([this, abilityInfo, isLock, where = __func__] {
std::vector<sptr<SceneSession>> mainSessions;
GetMainSessionByAbilityInfo(bundleName, moduleName, abilityName, appIndex, mainSessions);
GetMainSessionByAbilityInfo(abilityInfo, mainSessions);
if (!mainSessions.empty()) {
for (const auto& mainSession : mainSessions) {
TLOGNI(WmsLogTag::WMS_LIFE, "%{public}s, set isLockedState true, persistentId:%{public}d",
where, mainSession->GetPersistentId());
mainSession->NotifySessionLockStateChange(true);
mainSession->NotifySessionLockStateChange(isLock);
}
if (isLock) {
return;
}
}
if (isLock) {
if (sessionLockedStateCacheSet_.size() > MAX_LOCK_STATUS_CACHE_SIZE) {
auto iter = sessionLockedStateCacheSet_.begin();
TLOGNW(WmsLogTag::WMS_LIFE, "%{public}s, reach max erase begin:%{public}s", where, (*iter).c_str());
sessionLockedStateCacheSet_.erase(iter);
}
} else {
TLOGNI(WmsLogTag::WMS_LIFE, "%{public}s, update isLockedState into cache set", where);
sessionLockedStateCacheSet_.insert(
bundleName + "_" + moduleName + "_" + abilityName + "_" + std::to_string(appIndex));
sessionLockedStateCacheSet_.insert(abilityInfo.ToKeyString());
} else {
sessionLockedStateCacheSet_.erase(abilityInfo.ToKeyString());
}
}, __func__);
return WMError::WM_OK;
}
WMError SceneSessionManager::UnlockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex)
{
if (!SessionPermission::IsSystemAppCall() && !SessionPermission::IsSACalling()) {
TLOGE(WmsLogTag::WMS_LIFE, "The caller is neither a system app nor an SA.");
return WMError::WM_ERROR_INVALID_PERMISSION;
}
taskScheduler_->PostAsyncTask([this, bundleName, moduleName, abilityName, appIndex, where = __func__] {
std::vector<sptr<SceneSession>> mainSessions;
GetMainSessionByAbilityInfo(bundleName, moduleName, abilityName, appIndex, mainSessions);
for (const auto& mainSession : mainSessions) {
TLOGNI(WmsLogTag::WMS_LIFE, "%{public}s, set isLockedState false, persistentId:%{public}d",
where, mainSession->GetPersistentId());
mainSession->NotifySessionLockStateChange(false);
}
sessionLockedStateCacheSet_.erase(
bundleName + "_" + moduleName + "_" + abilityName + "_" + std::to_string(appIndex));
}, __func__);
return WMError::WM_OK;
}
WMError SceneSessionManager::HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken, bool& hasOrNot)
{
if (!abilityToken) {

View File

@ -290,18 +290,9 @@ WMError SceneSessionManagerLite::MinimizeMainSession(const std::string& bundleNa
return SceneSessionManager::GetInstance().MinimizeMainSession(bundleName, appIndex, userId);
}
WMError SceneSessionManagerLite::LockSessionByAbilityInfo(
const std::string& bundleName, const std::string& moduleName, const std::string& abilityName, int32_t appIndex)
WMError SceneSessionManagerLite::LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock)
{
return SceneSessionManager::GetInstance().LockSessionByAbilityInfo(
bundleName, moduleName, abilityName, appIndex);
}
WMError SceneSessionManagerLite::UnlockSessionByAbilityInfo(
const std::string& bundleName, const std::string& moduleName, const std::string& abilityName, int32_t appIndex)
{
return SceneSessionManager::GetInstance().UnlockSessionByAbilityInfo(
bundleName, moduleName, abilityName, appIndex);
return SceneSessionManager::GetInstance().LockSessionByAbilityInfo(abilityInfo, isLock);
}
WMError SceneSessionManagerLite::HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken,

View File

@ -1472,8 +1472,7 @@ WMError SceneSessionManagerLiteProxy::MinimizeMainSession(
return static_cast<WMError>(ret);
}
WMError SceneSessionManagerLiteProxy::LockSessionByAbilityInfo(
const std::string& bundleName, const std::string& moduleName, const std::string& abilityName, int32_t appIndex)
WMError SceneSessionManagerLiteProxy::LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock)
{
TLOGD(WmsLogTag::WMS_LIFE, "in");
MessageParcel data;
@ -1483,22 +1482,26 @@ WMError SceneSessionManagerLiteProxy::LockSessionByAbilityInfo(
TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteString(bundleName)) {
if (!data.WriteString(abilityInfo.bundleName)) {
TLOGE(WmsLogTag::WMS_LIFE, "write bundleName failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteString(moduleName)) {
if (!data.WriteString(abilityInfo.moduleName)) {
TLOGE(WmsLogTag::WMS_LIFE, "write moduleName failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteString(abilityName)) {
if (!data.WriteString(abilityInfo.abilityName)) {
TLOGE(WmsLogTag::WMS_LIFE, "write abilityName failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteInt32(appIndex)) {
if (!data.WriteInt32(abilityInfo.appIndex)) {
TLOGE(WmsLogTag::WMS_LIFE, "write appIndex failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteBool(isLock)) {
TLOGE(WmsLogTag::WMS_LIFE, "write isLock failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
@ -1518,52 +1521,6 @@ WMError SceneSessionManagerLiteProxy::LockSessionByAbilityInfo(
return static_cast<WMError>(ret);
}
WMError SceneSessionManagerLiteProxy::UnlockSessionByAbilityInfo(
const std::string& bundleName, const std::string& moduleName, const std::string& abilityName, int32_t appIndex)
{
TLOGD(WmsLogTag::WMS_LIFE, "in");
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteString(bundleName)) {
TLOGE(WmsLogTag::WMS_LIFE, "write bundleName failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteString(moduleName)) {
TLOGE(WmsLogTag::WMS_LIFE, "write moduleName failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteString(abilityName)) {
TLOGE(WmsLogTag::WMS_LIFE, "write abilityName failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteInt32(appIndex)) {
TLOGE(WmsLogTag::WMS_LIFE, "write appIndex failed.");
return WMError::WM_ERROR_IPC_FAILED;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
return WMError::WM_ERROR_IPC_FAILED;
}
if (remote->SendRequest(
static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNLOCK_SESSION_BY_ABILITY_INFO),
data, reply, option) != ERR_NONE) {
TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = 0;
if (!reply.ReadInt32(ret)) {
TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed");
return WMError::WM_ERROR_IPC_FAILED;
}
return static_cast<WMError>(ret);
}
WMError SceneSessionManagerLiteProxy::HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken,
bool& hasOrNot)
{

View File

@ -135,8 +135,6 @@ int SceneSessionManagerLiteStub::ProcessRemoteRequest(uint32_t code, MessageParc
return HandleHasFloatingWindowForeground(data, reply);
case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION_BY_ABILITY_INFO):
return HandleLockSessionByAbilityInfo(data, reply);
case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNLOCK_SESSION_BY_ABILITY_INFO):
return HandleUnlockSessionByAbilityInfo(data, reply);
default:
WLOGFE("Failed to find function handler!");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
@ -913,64 +911,39 @@ int SceneSessionManagerLiteStub::HandleMinimizeMainSession(MessageParcel& data,
return ERR_INVALID_DATA;
}
WMError ret = MinimizeMainSession(bundleName, appIndex, userId);
reply.WriteInt32(static_cast<int32_t>(ret));
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
TLOGE(WmsLogTag::WMS_LIFE, "Write ret failed.");
return ERR_INVALID_DATA;
}
return ERR_NONE;
}
int SceneSessionManagerLiteStub::HandleLockSessionByAbilityInfo(MessageParcel& data, MessageParcel& reply)
{
TLOGD(WmsLogTag::WMS_LIFE, "in");
std::string bundleName;
if (!data.ReadString(bundleName)) {
AbilityInfoBase abilityInfo;
if (!data.ReadString(abilityInfo.bundleName)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read bundleName");
return ERR_INVALID_DATA;
}
std::string moduleName;
if (!data.ReadString(moduleName)) {
if (!data.ReadString(abilityInfo.moduleName)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read moduleName");
return ERR_INVALID_DATA;
}
std::string abilityName;
if (!data.ReadString(abilityName)) {
if (!data.ReadString(abilityInfo.abilityName)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read abilityName");
return ERR_INVALID_DATA;
}
int32_t appIndex = 0;
if (!data.ReadInt32(appIndex)) {
if (!data.ReadInt32(abilityInfo.appIndex)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read appIndex");
return ERR_INVALID_DATA;
}
WMError ret = LockSessionByAbilityInfo(bundleName, moduleName, abilityName, appIndex);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
bool isLock = false;
if (!data.ReadBool(isLock)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read isLock");
return ERR_INVALID_DATA;
}
return ERR_NONE;
}
int SceneSessionManagerLiteStub::HandleUnlockSessionByAbilityInfo(MessageParcel& data, MessageParcel& reply)
{
TLOGD(WmsLogTag::WMS_LIFE, "in");
std::string bundleName;
if (!data.ReadString(bundleName)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read bundleName");
return ERR_INVALID_DATA;
}
std::string moduleName;
if (!data.ReadString(moduleName)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read moduleName");
return ERR_INVALID_DATA;
}
std::string abilityName;
if (!data.ReadString(abilityName)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read abilityName");
return ERR_INVALID_DATA;
}
int32_t appIndex = 0;
if (!data.ReadInt32(appIndex)) {
TLOGE(WmsLogTag::WMS_LIFE, "Failed to read appIndex");
return ERR_INVALID_DATA;
}
WMError ret = UnlockSessionByAbilityInfo(bundleName, moduleName, abilityName, appIndex);
WMError ret = LockSessionByAbilityInfo(abilityInfo, isLock);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
return ERR_INVALID_DATA;
}

View File

@ -209,10 +209,8 @@ class MockSceneSessionManagerLiteStub : public SceneSessionManagerLiteStub {
int32_t appIndex, int32_t userId) override { return WMError::WM_OK; }
WMError HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken,
bool& hasFloatingShowing) override { return WMError::WM_OK; }
WMError LockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex) override { return WMError::WM_OK; }
WMError UnlockSessionByAbilityInfo(const std::string& bundleName, const std::string& moduleName,
const std::string& abilityName, int32_t appIndex) override { return WMError::WM_OK; }
WMError LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo,
bool isLock) override { return WMError::WM_OK; }
};
class SceneSessionManagerLiteStubTest : public testing::Test {
@ -1005,40 +1003,18 @@ HWTEST_F(SceneSessionManagerLiteStubTest, HandleLockSessionByAbilityInfo, Functi
std::string moduleName = "moduleName";
std::string abilityName = "abilityName";
int32_t appIndex = 0;
bool isLock = true;
data.WriteString(bundleName);
data.WriteString(moduleName);
data.WriteString(abilityName);
data.WriteInt32(appIndex);
data.WriteBool(isLock);
auto res =
sceneSessionManagerLiteStub_->SceneSessionManagerLiteStub::HandleLockSessionByAbilityInfo(data, reply);
EXPECT_EQ(ERR_NONE, res);
}
/**
* @tc.name: HandleUnlockSessionByAbilityInfo
* @tc.desc: test function : HandleUnlockSessionByAbilityInfo
* @tc.type: FUNC
*/
HWTEST_F(SceneSessionManagerLiteStubTest, HandleUnlockSessionByAbilityInfo, Function | SmallTest | Level1)
{
MessageParcel data;
MessageParcel reply;
std::string bundleName = "appbundleName";
std::string moduleName = "moduleName";
std::string abilityName = "abilityName";
int32_t appIndex = 0;
data.WriteString(bundleName);
data.WriteString(moduleName);
data.WriteString(abilityName);
data.WriteInt32(appIndex);
auto res =
sceneSessionManagerLiteStub_->SceneSessionManagerLiteStub::HandleUnlockSessionByAbilityInfo(data, reply);
EXPECT_EQ(ERR_NONE, res);
}
}
}
}

View File

@ -408,29 +408,13 @@ HWTEST_F(SceneSessionManagerTest11, GetAbilityInfo05, Function | SmallTest | Lev
HWTEST_F(SceneSessionManagerTest11, LockSessionByAbilityInfo, Function | SmallTest | Level1)
{
ASSERT_NE(ssm_, nullptr);
std::string bundleName = "LockSessionByAbilityInfoBundle";
std::string moduleName = "LockSessionByAbilityInfoModule";
std::string abilityName = "LockSessionByAbilityInfoAbility";
int32_t appIndex = 0;
AbilityInfoBase abilityInfo;
abilityInfo.bundleName = "LockSessionByAbilityInfoBundle";
abilityInfo.moduleName = "LockSessionByAbilityInfoModule";
abilityInfo.abilityName = "LockSessionByAbilityInfoAbility";
abilityInfo.appIndex = 0;
auto result = ssm_->LockSessionByAbilityInfo(bundleName, moduleName, abilityName, appIndex);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, result);
}
/**
* @tc.name: UnlockSessionByAbilityInfo
* @tc.desc: SceneSesionManager test UnlockSessionByAbilityInfo
* @tc.type: FUNC
*/
HWTEST_F(SceneSessionManagerTest11, UnlockSessionByAbilityInfo, Function | SmallTest | Level1)
{
ASSERT_NE(ssm_, nullptr);
std::string bundleName = "UnlockSessionByAbilityInfoBundle";
std::string moduleName = "UnlockSessionByAbilityInfoModule";
std::string abilityName = "UnlockSessionByAbilityInfoAbility";
int32_t appIndex = 0;
auto result = ssm_->UnlockSessionByAbilityInfo(bundleName, moduleName, abilityName, appIndex);
auto result = ssm_->LockSessionByAbilityInfo(abilityInfo, true);
ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, result);
}
} // namespace