mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-27 00:51:35 +00:00
commit
5cb59fd641
@ -198,6 +198,14 @@ public:
|
||||
*/
|
||||
WMError UnregisterWMSConnectionChangedListener();
|
||||
|
||||
/**
|
||||
* @brief Terminate session by persistentId and start caller.
|
||||
* @persistentId persistentId to be terminated.
|
||||
*
|
||||
* @return WM_OK means Terminate success, others means Terminate failed.
|
||||
*/
|
||||
WMError TerminateSessionByPersistentId(int32_t persistentId);
|
||||
|
||||
private:
|
||||
WindowManagerLite();
|
||||
~WindowManagerLite();
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
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));
|
||||
MOCK_METHOD1(TerminateSessionByPersistentId, WMError(int32_t persistentId));
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -22,6 +22,7 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace PermissionConstants {
|
||||
constexpr const char* PERMISSION_MANAGE_MISSION = "ohos.permission.MANAGE_MISSIONS";
|
||||
constexpr const char* PERMISSION_KILL_APP_PROCESS = "ohos.permission.KILL_APP_PROCESSES";
|
||||
}
|
||||
class SessionPermission {
|
||||
public:
|
||||
@ -39,6 +40,7 @@ public:
|
||||
static bool IsStartedByUIExtension();
|
||||
static bool CheckCallingIsUserTestMode(pid_t pid);
|
||||
static bool IsBetaVersion();
|
||||
static bool IsSystemAppCall();
|
||||
};
|
||||
} // Rosen
|
||||
} // OHOS
|
||||
|
@ -103,6 +103,12 @@ bool SessionPermission::IsSystemCalling()
|
||||
return isSystemApp;
|
||||
}
|
||||
|
||||
bool SessionPermission::IsSystemAppCall()
|
||||
{
|
||||
uint64_t callingTokenId = IPCSkeleton::GetCallingFullTokenID();
|
||||
return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(callingTokenId);
|
||||
}
|
||||
|
||||
bool SessionPermission::IsSACalling()
|
||||
{
|
||||
const auto tokenId = IPCSkeleton::GetCallingTokenID();
|
||||
|
@ -232,7 +232,7 @@ public:
|
||||
void SetSessionSnapshotListener(const NotifySessionSnapshotFunc& func);
|
||||
WSError TerminateSessionTotal(const sptr<AAFwk::SessionInfo> info, TerminateType terminateType);
|
||||
void SetTerminateSessionListenerTotal(const NotifyTerminateSessionFuncTotal& func);
|
||||
WSError Clear();
|
||||
WSError Clear(bool needStartCaller = false);
|
||||
WSError SetSessionLabel(const std::string &label);
|
||||
void SetUpdateSessionLabelListener(const NofitySessionLabelUpdatedFunc& func);
|
||||
WSError SetSessionIcon(const std::shared_ptr<Media::PixelMap> &icon);
|
||||
|
@ -1394,14 +1394,14 @@ void Session::SetUpdateSessionIconListener(const NofitySessionIconUpdatedFunc &f
|
||||
updateSessionIconFunc_ = func;
|
||||
}
|
||||
|
||||
WSError Session::Clear()
|
||||
WSError Session::Clear(bool needStartCaller)
|
||||
{
|
||||
TLOGI(WmsLogTag::WMS_LIFE, "id: %{public}d", GetPersistentId());
|
||||
auto task = [this]() {
|
||||
TLOGI(WmsLogTag::WMS_LIFE, "id:%{public}d, needStartCaller:%{public}u", GetPersistentId(), needStartCaller);
|
||||
auto task = [this, needStartCaller]() {
|
||||
isTerminating = true;
|
||||
SessionInfo info = GetSessionInfo();
|
||||
if (terminateSessionFuncNew_) {
|
||||
terminateSessionFuncNew_(info, false, false);
|
||||
terminateSessionFuncNew_(info, needStartCaller, false);
|
||||
}
|
||||
};
|
||||
PostLifeCycleTask(task, "Clear", LifeCycleTaskType::STOP);
|
||||
|
@ -353,6 +353,7 @@ public:
|
||||
void UpdateSecSurfaceInfo(std::shared_ptr<RSUIExtensionData> secExtensionData, uint64_t userid);
|
||||
WSError SetAppForceLandscapeMode(const std::string& bundleName, int32_t mode);
|
||||
int32_t GetAppForceLandscapeMode(const std::string& bundleName);
|
||||
WMError TerminateSessionByPersistentId(int32_t persistentId);
|
||||
|
||||
protected:
|
||||
SceneSessionManager();
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
WSError RegisterIAbilityManagerCollaborator(int32_t type,
|
||||
const sptr<AAFwk::IAbilityManagerCollaborator>& impl) override;
|
||||
WSError UnregisterIAbilityManagerCollaborator(int32_t type) override;
|
||||
WMError TerminateSessionByPersistentId(int32_t persistentId) override;
|
||||
|
||||
protected:
|
||||
SceneSessionManagerLite() = default;
|
||||
|
@ -74,6 +74,7 @@ public:
|
||||
TRANS_ID_RAISE_WINDOW_TO_TOP,
|
||||
TRANS_ID_REGISTER_COLLABORATOR,
|
||||
TRANS_ID_UNREGISTER_COLLABORATOR,
|
||||
TRANS_ID_TERMINATE_SESSION_BY_PERSISTENT_ID,
|
||||
};
|
||||
|
||||
virtual WSError SetSessionLabel(const sptr<IRemoteObject>& token, const std::string& label) = 0;
|
||||
|
@ -68,6 +68,7 @@ public:
|
||||
WSError RegisterIAbilityManagerCollaborator(int32_t type,
|
||||
const sptr<AAFwk::IAbilityManagerCollaborator>& impl) override;
|
||||
WSError UnregisterIAbilityManagerCollaborator(int32_t type) override;
|
||||
WMError TerminateSessionByPersistentId(int32_t persistentId) override;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
|
@ -66,6 +66,7 @@ private:
|
||||
int HandleRaiseWindowToTop(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleRegisterCollaborator(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleUnregisterCollaborator(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleTerminateSessionByPersistentId(MessageParcel& data, MessageParcel& reply);
|
||||
|
||||
int ProcessRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option);
|
||||
};
|
||||
|
@ -9812,4 +9812,25 @@ int32_t SceneSessionManager::GetAppForceLandscapeMode(const std::string& bundleN
|
||||
}
|
||||
return appForceLandscapeMap_[bundleName];
|
||||
}
|
||||
|
||||
WMError SceneSessionManager::TerminateSessionByPersistentId(int32_t persistentId)
|
||||
{
|
||||
if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_KILL_APP_PROCESS) ||
|
||||
!SessionPermission::IsSystemAppCall()) {
|
||||
TLOGE(WmsLogTag::WMS_LIFE, "The caller has no permission granted.");
|
||||
return WMError::WM_ERROR_INVALID_PERMISSION;
|
||||
}
|
||||
auto sceneSession = GetSceneSession(persistentId);
|
||||
if (sceneSession == nullptr) {
|
||||
TLOGE(WmsLogTag::WMS_LIFE, "Session id:%{public}d is not found.", persistentId);
|
||||
return WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
if (!WindowHelper::IsMainWindow(sceneSession->GetWindowType())) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "Session id:%{public}d is not mainWindow.", persistentId);
|
||||
return WMError::WM_ERROR_INVALID_PERMISSION;
|
||||
}
|
||||
sceneSession->Clear(true);
|
||||
TLOGI(WmsLogTag::WMS_LIFE, "Terminate success, id:%{public}d.", persistentId);
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -236,4 +236,9 @@ WSError SceneSessionManagerLite::UnregisterIAbilityManagerCollaborator(int32_t t
|
||||
{
|
||||
return SceneSessionManager::GetInstance().UnregisterIAbilityManagerCollaborator(type);
|
||||
}
|
||||
|
||||
WMError SceneSessionManagerLite::TerminateSessionByPersistentId(int32_t persistentId)
|
||||
{
|
||||
return SceneSessionManager::GetInstance().TerminateSessionByPersistentId(persistentId);
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -958,4 +958,26 @@ WSError SceneSessionManagerLiteProxy::UnregisterIAbilityManagerCollaborator(int3
|
||||
}
|
||||
return static_cast<WSError>(reply.ReadInt32());
|
||||
}
|
||||
|
||||
WMError SceneSessionManagerLiteProxy::TerminateSessionByPersistentId(int32_t persistentId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (!data.WriteInt32(persistentId)) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (Remote()->SendRequest(static_cast<int32_t>(
|
||||
SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_BY_PERSISTENT_ID),
|
||||
data, reply, option) != ERR_NONE) {
|
||||
TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
return static_cast<WMError>(reply.ReadInt32());
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -542,4 +542,14 @@ int SceneSessionManagerLiteStub::HandleUnregisterCollaborator(MessageParcel& dat
|
||||
reply.WriteInt32(static_cast<int32_t>(ret));
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
int SceneSessionManagerLiteStub::HandleTerminateSessionByPersistentId(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
int32_t persistentId = data.ReadInt32();
|
||||
WMError errCode = TerminateSessionByPersistentId(persistentId);
|
||||
if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
return ERR_NONE;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -161,6 +161,10 @@ class MockSceneSessionManagerLiteStub : public SceneSessionManagerLiteStub {
|
||||
{
|
||||
return WSError::WS_OK;
|
||||
}
|
||||
WMError TerminateSessionByPersistentId(int32_t persistentId) override
|
||||
{
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
sptr<IRemoteObject> AsObject() override
|
||||
{
|
||||
return nullptr;
|
||||
@ -636,6 +640,22 @@ HWTEST_F(SceneSessionManagerLiteStubTest, HandleRaiseWindowToTop, Function | Sma
|
||||
EXPECT_EQ(ERR_NONE, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleTerminateSessionByPersistentId
|
||||
* @tc.desc: test function : HandleTerminateSessionByPersistentId
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerLiteStubTest, HandleTerminateSessionByPersistentId, Function | SmallTest | Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
int32_t persistentId = 1;
|
||||
data.WriteInt32(persistentId);
|
||||
auto res = sceneSessionManagerLiteStub_->
|
||||
SceneSessionManagerLiteStub::HandleTerminateSessionByPersistentId(data, reply);
|
||||
EXPECT_EQ(ERR_NONE, res);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1214,6 +1214,44 @@ HWTEST_F(SceneSessionManagerTest6, DeleteStateDetectTask, Function | SmallTest |
|
||||
ASSERT_NE(nullptr, ssm_);
|
||||
ssm_->DeleteStateDetectTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TerminateSessionByPersistentId
|
||||
* @tc.desc: Success to terminate session by persistentId.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerTest6, TerminateSessionByPersistentId001, Function | SmallTest | Level3)
|
||||
{
|
||||
SessionInfo info;
|
||||
info.abilityName_ = "test1";
|
||||
info.bundleName_ = "test1";
|
||||
info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
|
||||
sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
|
||||
ASSERT_NE(nullptr, sceneSession);
|
||||
ASSERT_NE(nullptr, ssm_);
|
||||
ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
|
||||
auto result = ssm_->TerminateSessionByPersistentId(sceneSession->GetPersistentId());
|
||||
EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TerminateSessionByPersistentId
|
||||
* @tc.desc: Fail to terminate session by persistentId, invalid persistentId.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SceneSessionManagerTest6, TerminateSessionByPersistentId002, Function | SmallTest | Level3)
|
||||
{
|
||||
SessionInfo info;
|
||||
info.abilityName_ = "test1";
|
||||
info.bundleName_ = "test1";
|
||||
info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
|
||||
sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
|
||||
ASSERT_NE(nullptr, sceneSession);
|
||||
ASSERT_NE(nullptr, ssm_);
|
||||
ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
|
||||
auto result = ssm_->TerminateSessionByPersistentId(INVALID_SESSION_ID);
|
||||
EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -50,6 +50,7 @@ public:
|
||||
virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds);
|
||||
virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds);
|
||||
virtual WMError RaiseWindowToTop(int32_t persistentId);
|
||||
virtual WMError TerminateSessionByPersistentId(int32_t persistentId);
|
||||
WMError RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc);
|
||||
|
||||
private:
|
||||
|
@ -278,5 +278,14 @@ sptr<IWindowManagerLite> WindowAdapterLite::GetWindowManagerServiceProxy() const
|
||||
return windowManagerServiceProxy_;
|
||||
}
|
||||
|
||||
WMError WindowAdapterLite::TerminateSessionByPersistentId(int32_t persistentId)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
|
||||
auto wmsProxy = GetWindowManagerServiceProxy();
|
||||
CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
|
||||
return wmsProxy->TerminateSessionByPersistentId(persistentId);
|
||||
}
|
||||
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -638,5 +638,14 @@ void WindowManagerLite::OnWMSConnectionChanged(int32_t userId, int32_t screenId,
|
||||
pImpl_->NotifyWMSDisconnected(userId, screenId);
|
||||
}
|
||||
}
|
||||
|
||||
WMError WindowManagerLite::TerminateSessionByPersistentId(int32_t persistentId)
|
||||
{
|
||||
if (persistentId == INVALID_SESSION_ID) {
|
||||
TLOGE(WmsLogTag::WMS_LIFE, "persistentId is invalid.");
|
||||
return WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
return SingletonContainer::Get<WindowAdapterLite>().TerminateSessionByPersistentId(persistentId);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -464,5 +464,35 @@ HWTEST_F(WindowManagerLiteTest, NotifyWMSConnected, Function | SmallTest | Level
|
||||
auto ret = WindowManagerLite::GetInstance().GetWindowModeType(windowModeType);
|
||||
EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TerminateSessionByPersistentId001
|
||||
* @tc.desc: TerminateSessionByPersistentId001
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowManagerLiteTest, TerminateSessionByPersistentId001, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
int32_t persistentId = 1;
|
||||
EXPECT_CALL(m->Mock(), TerminateSessionByPersistentId(_)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
|
||||
auto errorCode = WindowManagerLite::GetInstance().TerminateSessionByPersistentId(persistentId);
|
||||
ASSERT_EQ(WMError::WM_OK, errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TerminateSessionByPersistentId002
|
||||
* @tc.desc: TerminateSessionByPersistentId002
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowManagerLiteTest, TerminateSessionByPersistentId002, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
int32_t persistentId = 0;
|
||||
EXPECT_CALL(m->Mock(), TerminateSessionByPersistentId(_)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
|
||||
auto errorCode = WindowManagerLite::GetInstance().TerminateSessionByPersistentId(persistentId);
|
||||
ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, errorCode);
|
||||
}
|
||||
}
|
||||
}
|
@ -46,6 +46,7 @@ public:
|
||||
virtual WMError ClearMainSessions(const std::vector<int32_t>& persistentIds,
|
||||
std::vector<int32_t>& clearFailedIds) = 0;
|
||||
virtual WSError RaiseWindowToTop(int32_t persistentId) { return WSError::WS_OK; }
|
||||
virtual WMError TerminateSessionByPersistentId(int32_t persistentId) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user