add switch for startingWindow

Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
Change-Id: Iaa8cc10a2cb6ac53116b10a6c49237e392d30237
Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
This commit is contained in:
chyyy0213
2022-05-17 17:12:03 +08:00
parent c33f0202cc
commit 738ed374f9
9 changed files with 144 additions and 72 deletions
+2 -1
View File
@@ -23,7 +23,8 @@ namespace OHOS {
namespace Rosen {
enum DumpType : uint32_t {
DUMP_ALL = 0,
OPEN_STARTING,
CLOSE_STARTING,
DUMP_NONE = 100,
};
class WindowDumper : public RefBase {
@@ -95,6 +95,8 @@ public:
void StartingWindow(sptr<WindowTransitionInfo> info, sptr<Media::PixelMap> pixelMap,
bool isColdStart, uint32_t bkgColor = 0xffffffff);
void CancelStartingWindow(sptr<IRemoteObject> abilityToken);
void OpenStartingWindow();
void CloseStartingWindow();
protected:
WindowManagerService();
virtual ~WindowManagerService() = default;
@@ -120,6 +122,7 @@ private:
sptr<WindowDumper> windowDumper_;
SystemConfig systemConfig_;
ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 };
bool startingOpen_ = true;
};
}
}
+4 -2
View File
@@ -80,7 +80,7 @@ public:
WMError GetModeChangeHotZones(DisplayId displayId,
ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config);
std::vector<DisplayId> GetAllDisplayIds() const;
std::map<uint32_t, sptr<WindowNode>> GetWindowNodeMap();
uint32_t GetTotalWindowNum();
private:
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
WMError DestroyWindowInner(sptr<WindowNode>& node);
@@ -97,7 +97,9 @@ private:
void ProcessExpandDisplayCreate(DisplayId displayId, ScreenId screenGroupId);
std::map<DisplayId, sptr<DisplayInfo>> GetAllDisplayInfos(const std::vector<DisplayId>& displayIdVec);
void MoveNotShowingWindowToDefaultDisplay(DisplayId displayId);
void DestroyLeakStartingWindow();
WMError PostProcessAddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode,
sptr<WindowNodeContainer>& container);
std::recursive_mutex& mutex_;
std::map<uint32_t, sptr<WindowNode>> windowNodeMap_;
std::map<sptr<IRemoteObject>, uint32_t> windowIdMap_;
+6 -9
View File
@@ -31,6 +31,10 @@ std::recursive_mutex MinimizeApp::mutex_;
void MinimizeApp::AddNeedMinimizeApp(const sptr<WindowNode>& node, MinimizeReason reason)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
bool isFromUser = IsFromUser(reason);
if (!isMinimizedByOtherWindow_ && !isFromUser) {
return;
}
WLOGFI("[Minimize] Add Window %{public}u to minimize list, reason %{public}u", node->GetWindowId(), reason);
needMinimizeAppNodes_[reason].emplace_back(node);
}
@@ -40,12 +44,8 @@ void MinimizeApp::ExecuteMinimizeAll()
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto& appNodes: needMinimizeAppNodes_) {
bool isFromUser = IsFromUser(appNodes.first);
if (!isMinimizedByOtherWindow_ && !isFromUser) {
continue;
}
for (auto& node : appNodes.second) {
if (node->abilityToken_ != nullptr) {
if (node->abilityToken_ != nullptr && !node->startingWindowShown_) {
WLOGFI("[Minimize] Minimize Window %{public}u, reason %{public}u", node->GetWindowId(), appNodes.first);
AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(node->abilityToken_, isFromUser);
}
@@ -83,11 +83,8 @@ void MinimizeApp::ExecuteMinimizeTargetReason(MinimizeReason reason)
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (needMinimizeAppNodes_.find(reason) != needMinimizeAppNodes_.end()) {
bool isFromUser = IsFromUser(reason);
if (!isMinimizedByOtherWindow_ && !isFromUser) {
return;
}
for (auto& node : needMinimizeAppNodes_.at(reason)) {
if (node->abilityToken_ != nullptr) {
if (node->abilityToken_ != nullptr && !node->startingWindowShown_) {
WLOGFI("[Minimize] Minimize Window %{public}u, reason %{public}u", node->GetWindowId(), reason);
AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(node->abilityToken_, isFromUser);
}
+18 -21
View File
@@ -30,8 +30,6 @@ namespace {
SurfaceDraw StartingWindow::surfaceDraw_;
static bool g_hasInit = false;
std::recursive_mutex StartingWindow::mutex_;
static bool g_initStart = false;
static std::shared_ptr<RSSurfaceNode> g_startingWinSurfaceNode = nullptr;
sptr<WindowNode> StartingWindow::CreateWindowNode(sptr<WindowTransitionInfo> info, uint32_t winId)
{
@@ -69,18 +67,15 @@ WMError StartingWindow::CreateLeashAndStartingSurfaceNode(sptr<WindowNode>& node
WLOGFE("create leashWinSurfaceNode failed");
return WMError::WM_ERROR_NULLPTR;
}
if (!g_initStart) {
rsSurfaceNodeConfig.SurfaceNodeName = "startingWindow";
g_startingWinSurfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
if (g_startingWinSurfaceNode == nullptr) {
WLOGFE("create startingWinSurfaceNode failed");
node->leashWinSurfaceNode_ = nullptr;
return WMError::WM_ERROR_NULLPTR;
}
g_initStart = true;
rsSurfaceNodeConfig.SurfaceNodeName = "startingWindow" + std::to_string(node->GetWindowId());
node->startingWinSurfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig);
if (node->startingWinSurfaceNode_ == nullptr) {
WLOGFE("create startingWinSurfaceNode failed");
node->leashWinSurfaceNode_ = nullptr;
return WMError::WM_ERROR_NULLPTR;
}
node->startingWinSurfaceNode_ = g_startingWinSurfaceNode;
WLOGFI("Create leashWinSurfaceNode and startingWinSurfaceNode success!");
WLOGFI("Create leashWinSurfaceNode and startingWinSurfaceNode success with id:%{public}u!", node->GetWindowId());
return WMError::WM_OK;
}
@@ -120,17 +115,19 @@ void StartingWindow::HandleClientWindowCreate(sptr<WindowNode>& node, sptr<IWind
node->GetRequestRect().width_, node->GetRequestRect().height_);
// Register FirstFrame Callback to rs, replace startwin
auto firstFrameCompleteCallback = [node]() {
wptr<WindowNode> weak = node;
auto firstFrameCompleteCallback = [weak]() {
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (node->leashWinSurfaceNode_ == nullptr) {
WLOGFE("leashWinSurfaceNode_ is nullptr");
auto weakNode = weak.promote();
if (weakNode == nullptr || weakNode->leashWinSurfaceNode_ == nullptr) {
WLOGFE("windowNode or leashWinSurfaceNode_ is nullptr");
return;
}
WLOGFI("StartingWindow::Replace surfaceNode, id: %{public}u", node->GetWindowId());
node->leashWinSurfaceNode_->RemoveChild(node->startingWinSurfaceNode_);
node->leashWinSurfaceNode_->AddChild(node->surfaceNode_, -1);
node->startingWinSurfaceNode_ = nullptr;
AAFwk::AbilityManagerClient::GetInstance()->CompleteFirstFrameDrawing(node->abilityToken_);
WLOGFI("StartingWindow::Replace surfaceNode, id: %{public}u", weakNode->GetWindowId());
weakNode->leashWinSurfaceNode_->RemoveChild(weakNode->startingWinSurfaceNode_);
weakNode->leashWinSurfaceNode_->AddChild(weakNode->surfaceNode_, -1);
weakNode->startingWinSurfaceNode_ = nullptr;
AAFwk::AbilityManagerClient::GetInstance()->CompleteFirstFrameDrawing(weakNode->abilityToken_);
RSTransaction::FlushImplicitTransaction();
};
node->surfaceNode_->SetBufferAvailableCallback(firstFrameCompleteCallback);
+9 -2
View File
@@ -78,18 +78,23 @@ void WindowController::StartingWindow(sptr<WindowTransitionInfo> info, sptr<Medi
void WindowController::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
{
WLOGFI("begin CancelStartingWindow!");
auto node = windowRoot_->FindWindowNodeWithToken(abilityToken);
if (node == nullptr) {
WLOGFI("cannot find windowNode!");
return;
}
WM_SCOPED_TRACE("wms:CancelStartingWindow(%u)", node->GetWindowId());
DestroyWindow(node->GetWindowId(), true);
WLOGFI("CancelStartingWindow with id:%{public}u!", node->GetWindowId());
WMError res = windowRoot_->DestroyWindow(node->GetWindowId(), false);
if (res != WMError::WM_OK) {
WLOGFE("DestroyWindow failed!");
}
}
WMError WindowController::NotifyWindowTransition(sptr<WindowTransitionInfo>& srcInfo,
sptr<WindowTransitionInfo>& dstInfo)
{
WLOGFI("NotifyWindowTransition begin!");
if (!srcInfo || !dstInfo) {
WLOGFE("srcInfo or dstInfo is nullptr!");
return WMError::WM_ERROR_NULLPTR;
@@ -157,6 +162,8 @@ WMError WindowController::CreateWindow(sptr<IWindow>& window, sptr<WindowPropert
node = new WindowNode(windowProperty, window, surfaceNode);
node->abilityToken_ = token;
UpdateWindowAnimation(node);
WLOGFI("createWindow name:%{public}u, windowName:%{public}s",
windowId, node->GetWindowName().c_str());
return windowRoot_->SaveWindow(node);
}
+19 -2
View File
@@ -25,6 +25,7 @@
#include "string_ex.h"
#include "unique_fd.h"
#include "window_manager_hilog.h"
#include "window_manager_service.h"
#include "wm_common.h"
namespace OHOS {
@@ -35,6 +36,8 @@ namespace {
constexpr int WINDOW_NAME_MAX_LENGTH = 20;
const std::string ARG_DUMP_HELP = "-h";
const std::string ARG_DUMP_ALL = "-a";
const std::string ARG_OPEN_STARTINGWIN = "-os";
const std::string ARG_CLOSE_STARTINGWIN = "-cs";
}
WMError WindowDumper::Dump(int fd, const std::vector<std::u16string>& args) const
@@ -112,7 +115,7 @@ WMError WindowDumper::DumpDisplayWindowInfo(DisplayId displayId, std::string& du
<< std::endl;
}
oss << "Focus window: " << windowNodeContainer->GetFocusWindow() << std::endl;
oss << "total window num: " << windowRoot_->GetWindowNodeMap().size() << std::endl;
oss << "total window num: " << windowRoot_->GetTotalWindowNum()<< std::endl;
dumpInfo.append(oss.str());
return WMError::WM_OK;
}
@@ -145,12 +148,22 @@ WMError WindowDumper::DumpWindowInfo(const std::vector<std::string>& args, std::
DumpType dumpType = DumpType::DUMP_NONE;
if (args[0] == ARG_DUMP_ALL) {
dumpType = DumpType::DUMP_ALL;
} else if (args[0] == ARG_OPEN_STARTINGWIN) {
dumpType = DumpType::OPEN_STARTING;
} else if (args[0] == ARG_CLOSE_STARTINGWIN) {
dumpType = DumpType::CLOSE_STARTING;
}
WMError ret = WMError::WM_OK;
switch (dumpType) {
case DumpType::DUMP_ALL:
ret = DumpAllWindowInfo(dumpInfo);
break;
case DumpType::OPEN_STARTING:
WindowManagerService::GetInstance().OpenStartingWindow();
break;
case DumpType::CLOSE_STARTING:
WindowManagerService::GetInstance().CloseStartingWindow();
break;
default:
ret = WMError::WM_ERROR_INVALID_PARAM;
break;
@@ -169,7 +182,11 @@ void WindowDumper::ShowHelpInfo(std::string& dumpInfo) const
.append(" -h ")
.append("|help text for the tool\n")
.append(" -a ")
.append("|dump all window infomation in the system\n");
.append("|dump all window infomation in the system\n")
.append(" -o ")
.append("|open starting window\n")
.append(" -c ")
.append("|close starting window\n");
}
}
}
+18
View File
@@ -242,15 +242,33 @@ void WindowManagerService::StartingWindow(sptr<WindowTransitionInfo> info, sptr<
bool isColdStart, uint32_t bkgColor)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (!startingOpen_) {
WLOGFI("startingWindow not open!");
return;
}
return windowController_->StartingWindow(info, pixelMap, bkgColor, isColdStart);
}
void WindowManagerService::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (!startingOpen_) {
WLOGFI("startingWindow not open!");
return;
}
return windowController_->CancelStartingWindow(abilityToken);
}
void WindowManagerService::OpenStartingWindow()
{
startingOpen_ = true;
}
void WindowManagerService::CloseStartingWindow()
{
startingOpen_ = false;
}
WMError WindowManagerService::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId, sptr<IRemoteObject> token)
{
+65 -35
View File
@@ -30,9 +30,9 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowRoot"};
}
std::map<uint32_t, sptr<WindowNode>> WindowRoot::GetWindowNodeMap()
uint32_t WindowRoot::GetTotalWindowNum()
{
return windowNodeMap_;
return static_cast<uint32_t>(windowNodeMap_.size());
}
ScreenId WindowRoot::GetScreenGroupId(DisplayId displayId, bool& isRecordedDisplay)
@@ -192,8 +192,14 @@ WMError WindowRoot::SaveWindow(const sptr<WindowNode>& node)
AddDeathRecipient(node);
}
// Register FirstFrame Callback to rs, inform ability to get snapshot
auto firstFrameCompleteCallback = [node]() {
AAFwk::AbilityManagerClient::GetInstance()->CompleteFirstFrameDrawing(node->abilityToken_);
wptr<WindowNode> weak = node;
auto firstFrameCompleteCallback = [weak]() {
auto weakNode = weak.promote();
if (weakNode == nullptr) {
WLOGFE("windowNode is nullptr");
return;
}
AAFwk::AbilityManagerClient::GetInstance()->CompleteFirstFrameDrawing(weakNode->abilityToken_);
};
if (node->surfaceNode_ && WindowHelper::IsMainWindow(node->GetWindowType())) {
node->surfaceNode_->SetBufferAvailableCallback(firstFrameCompleteCallback);
@@ -297,6 +303,55 @@ WMError WindowRoot::MaxmizeWindow(uint32_t windowId)
return WMError::WM_OK;
}
void WindowRoot::DestroyLeakStartingWindow()
{
std::vector<uint32_t> destroyIds;
for (auto& iter : windowNodeMap_) {
if (iter.second->startingWindowShown_ && !iter.second->GetWindowToken()) {
destroyIds.push_back(iter.second->GetWindowId());
}
}
for (auto& id : destroyIds) {
WLOGFI("Destroy Window id:%{public}u", id);
DestroyWindow(id, false);
}
}
WMError WindowRoot::PostProcessAddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode,
sptr<WindowNodeContainer>& container)
{
if (WindowHelper::IsSubWindow(node->GetWindowType())) {
if (parentNode == nullptr) {
WLOGFE("window type is invalid");
return WMError::WM_ERROR_INVALID_TYPE;
}
sptr<WindowNode> parent = nullptr;
container->RaiseZOrderForAppWindow(parentNode, parent);
}
if (node->GetWindowProperty()->GetFocusable()) {
container->SetFocusWindow(node->GetWindowId());
needCheckFocusWindow = true;
}
container->SetActiveWindow(node->GetWindowId(), false);
NotifyKeyboardSizeChangeInfo(node, container, node->GetWindowRect());
for (auto& child : node->children_) {
if (child == nullptr || !child->currentVisibility_) {
break;
}
HandleKeepScreenOn(child->GetWindowId(), child->IsKeepScreenOn());
}
HandleKeepScreenOn(node->GetWindowId(), node->IsKeepScreenOn());
WLOGFI("windowId:%{public}u, name:%{public}s, orientation:%{public}u, type:%{public}u, isMainWindow:%{public}d",
node->GetWindowId(), node->GetWindowName().c_str(), static_cast<uint32_t>(node->GetRequestedOrientation()),
node->GetWindowType(), WindowHelper::IsMainWindow(node->GetWindowType()));
if (WindowHelper::IsMainWindow(node->GetWindowType()) &&
node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) {
DisplayManagerServiceInner::GetInstance().
SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation());
}
return WMError::WM_OK;
}
WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr<WindowNode>& node, bool fromStartingWin)
{
if (node == nullptr) {
@@ -320,38 +375,13 @@ WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr<WindowNode>& node, boo
auto parentNode = GetWindowNode(parentId);
WMError res = container->AddWindowNode(node, parentNode);
if (res == WMError::WM_OK && WindowHelper::IsSubWindow(node->GetWindowType())) {
if (parentNode == nullptr) {
WLOGFE("window type is invalid");
return WMError::WM_ERROR_INVALID_TYPE;
}
sptr<WindowNode> parent = nullptr;
container->RaiseZOrderForAppWindow(parentNode, parent);
DestroyLeakStartingWindow();
if (res != WMError::WM_OK) {
WLOGFE("AddWindowNode failed with ret: %{public}u", static_cast<uint32_t>(res));
return res;
}
if (res == WMError::WM_OK && node->GetWindowProperty()->GetFocusable()) {
container->SetFocusWindow(node->GetWindowId());
needCheckFocusWindow = true;
}
if (res == WMError::WM_OK) {
container->SetActiveWindow(node->GetWindowId(), false);
NotifyKeyboardSizeChangeInfo(node, container, node->GetWindowRect());
for (auto& child : node->children_) {
if (child == nullptr || !child->currentVisibility_) {
break;
}
HandleKeepScreenOn(child->GetWindowId(), child->IsKeepScreenOn());
}
HandleKeepScreenOn(node->GetWindowId(), node->IsKeepScreenOn());
}
WLOGFI("windowId:%{public}u, name:%{public}s, orientation:%{public}u, type:%{public}u, isMainWindow:%{public}d",
node->GetWindowId(), node->GetWindowName().c_str(), static_cast<uint32_t>(node->GetRequestedOrientation()),
node->GetWindowType(), WindowHelper::IsMainWindow(node->GetWindowType()));
if (res == WMError::WM_OK && WindowHelper::IsMainWindow(node->GetWindowType()) &&
node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) {
DisplayManagerServiceInner::GetInstance().
SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation());
}
return res;
return PostProcessAddWindowNode(node, parentNode, container);
}
WMError WindowRoot::RemoveWindowNode(uint32_t windowId)