异常窗口模式处理

Signed-off-by: l00574490 <liuqi149@huawei.com>
Change-Id: I885b149cd2ee3423a194862ef18564ae2f0f521a
This commit is contained in:
l00574490
2022-06-29 18:27:13 +08:00
parent 56e1f6dcf0
commit 973e3c96d2
14 changed files with 128 additions and 50 deletions
+1
View File
@@ -59,6 +59,7 @@ public:
virtual void AfterFocused() = 0;
virtual void AfterUnfocused() = 0;
virtual void ForegroundFailed() {}
virtual void ForegroundInvalidMode() {}
virtual void AfterActive() {}
virtual void AfterInactive() {}
};
+1
View File
@@ -102,6 +102,7 @@ enum class WMError : int32_t {
WM_ERROR_DESTROYED_OBJECT,
WM_ERROR_DEATH_RECIPIENT,
WM_ERROR_INVALID_WINDOW,
WM_ERROR_INVALID_WINDOW_MODE,
WM_ERROR_INVALID_OPERATION,
WM_ERROR_INVALID_PERMISSION,
WM_ERROR_NO_REMOTE_ANIMATION,
+27 -2
View File
@@ -17,8 +17,9 @@
#define OHOS_WM_INCLUDE_WM_HELPER_H
#include <vector>
#include <wm_common.h>
#include <wm_common_inner.h>
#include "ability_info.h"
#include "wm_common.h"
#include "wm_common_inner.h"
namespace OHOS {
namespace Rosen {
@@ -181,6 +182,21 @@ public:
}
}
static void ConvertSupportModesToSupportInfo(uint32_t& modeSupportInfo,
const std::vector<AppExecFwk::SupportWindowMode>& supportModes)
{
for (auto& mode : supportModes) {
if (mode == AppExecFwk::SupportWindowMode::FULLSCREEN) {
modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN;
} else if (mode == AppExecFwk::SupportWindowMode::SPLIT) {
modeSupportInfo |= (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY);
} else if (mode == AppExecFwk::SupportWindowMode::FLOATING) {
modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING;
}
}
}
static Rect GetFixedWindowRectByLimitSize(const Rect& oriDstRect, const Rect& lastRect, bool isVertical,
float virtualPixelRatio)
{
@@ -358,6 +374,15 @@ public:
return false;
}
static bool IsInvalidWindowInTileLayoutMode(uint32_t supportModeInfo, WindowLayoutMode layoutMode)
{
if ((!IsWindowModeSupported(supportModeInfo, WindowMode::WINDOW_MODE_FLOATING)) &&
(layoutMode == WindowLayoutMode::TILE)) {
return true;
}
return false;
}
private:
WindowHelper() = default;
~WindowHelper() = default;
+5 -3
View File
@@ -17,6 +17,8 @@
#define OHOS_ROSEN_WINDOW_TRANSITION_INFO_H
#include <iremote_object.h>
#include <string>
#include "ability_info.h"
#include "window_info.h"
#include "wm_common.h"
@@ -52,8 +54,8 @@ public:
void SetWindowType(WindowType windowType);
WindowType GetWindowType();
void SetShowFlagWhenLocked(bool isShow);
void SetWindowSupportModes(const std::vector<uint32_t> supportModes);
std::vector<uint32_t> GetWindowSupportModes();
void SetWindowSupportModes(const std::vector<AppExecFwk::SupportWindowMode> supportModes);
std::vector<AppExecFwk::SupportWindowMode> GetWindowSupportModes();
bool GetShowFlagWhenLocked();
void SetTransitionReason(TransitionReason reason);
TransitionReason GetTransitionReason();
@@ -70,7 +72,7 @@ private:
bool isShowWhenLocked_ = false;
bool isRecent_ = false;
TransitionReason reason_ = TransitionReason::ABILITY_TRANSITION;
std::vector<uint32_t> supportWindowModes_;
std::vector<AppExecFwk::SupportWindowMode> supportWindowModes_;
};
} // Rosen
} // OHOS
+7 -6
View File
@@ -96,18 +96,19 @@ struct ModeChangeHotZonesConfig {
};
struct WindowSizeLimits {
bool isSizeLimitsUpdated_;
uint32_t maxWidth_;
uint32_t maxHeight_;
uint32_t minWidth_;
uint32_t minHeight_;
float maxRatio_;
float minRatio_;
WindowSizeLimits() : maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX), minWidth_(0),
minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {}
WindowSizeLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth,
uint32_t minHeight, float maxRatio, float minRatio)
: maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth),
minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {}
WindowSizeLimits() : isSizeLimitsUpdated_(false), maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX),
minWidth_(0), minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {}
WindowSizeLimits(bool isSizeLimitsUpdated, uint32_t maxWidth, uint32_t maxHeight,
uint32_t minWidth, uint32_t minHeight, float maxRatio, float minRatio)
: isSizeLimitsUpdated_(isSizeLimitsUpdated), maxWidth_(maxWidth), maxHeight_(maxHeight),
minWidth_(minWidth), minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {}
};
struct ModeChangeHotZones {
+6 -5
View File
@@ -502,9 +502,10 @@ void WindowProperty::UnmarshallingTransform(Parcel& parcel, WindowProperty* prop
bool WindowProperty::MarshallingWindowSizeLimits(Parcel& parcel) const
{
if (parcel.WriteUint32(sizeLimits_.maxWidth_) && parcel.WriteUint32(sizeLimits_.maxHeight_) &&
parcel.WriteUint32(sizeLimits_.minWidth_) && parcel.WriteUint32(sizeLimits_.minHeight_) &&
parcel.WriteFloat(sizeLimits_.maxRatio_) && parcel.WriteFloat(sizeLimits_.minRatio_)) {
if (parcel.WriteBool(sizeLimits_.isSizeLimitsUpdated_) && parcel.WriteUint32(sizeLimits_.maxWidth_) &&
parcel.WriteUint32(sizeLimits_.maxHeight_) && parcel.WriteUint32(sizeLimits_.minWidth_) &&
parcel.WriteUint32(sizeLimits_.minHeight_) && parcel.WriteFloat(sizeLimits_.maxRatio_) &&
parcel.WriteFloat(sizeLimits_.minRatio_)) {
return true;
}
return false;
@@ -512,8 +513,8 @@ bool WindowProperty::MarshallingWindowSizeLimits(Parcel& parcel) const
void WindowProperty::UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property)
{
WindowSizeLimits sizeLimits = { parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(),
parcel.ReadFloat(), parcel.ReadFloat() };
WindowSizeLimits sizeLimits = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(),
parcel.ReadUint32(), parcel.ReadFloat(), parcel.ReadFloat() };
property->SetSizeLimits(sizeLimits);
}
+3 -3
View File
@@ -26,7 +26,7 @@ WindowTransitionInfo::WindowTransitionInfo(sptr<AAFwk::AbilityTransitionInfo> in
displayId_ = info->displayId_;
isShowWhenLocked_ = info->isShowWhenLocked_;
isRecent_ = info->isRecent_;
supportWindowModes_ = { 0, 1, 2 }; // 0:fullScreen 1:split 2:floating
supportWindowModes_.assign(info->windowModes_.begin(), info->windowModes_.end());
}
void WindowTransitionInfo::SetBundleName(std::string name)
@@ -104,12 +104,12 @@ void WindowTransitionInfo::SetShowFlagWhenLocked(bool isShow)
isShowWhenLocked_ = isShow;
}
void WindowTransitionInfo::SetWindowSupportModes(const std::vector<uint32_t> supportModes)
void WindowTransitionInfo::SetWindowSupportModes(const std::vector<AppExecFwk::SupportWindowMode> supportModes)
{
supportWindowModes_.assign(supportModes.begin(), supportModes.end());
}
std::vector<uint32_t> WindowTransitionInfo::GetWindowSupportModes()
std::vector<AppExecFwk::SupportWindowMode> WindowTransitionInfo::GetWindowSupportModes()
{
return supportWindowModes_;
}
+6
View File
@@ -312,6 +312,12 @@ private:
CALL_LIFECYCLE_LISTENER(ForegroundFailed);
});
}
inline void NotifyForegroundInvalidWindowMode()
{
PostListenerTask([this]() {
CALL_LIFECYCLE_LISTENER(ForegroundInvalidMode);
});
}
void DestroyFloatingWindow();
void DestroySubWindow();
void SetDefaultOption(); // for api7
+22 -15
View File
@@ -689,21 +689,12 @@ void WindowImpl::GetConfigurationFromAbilityInfo()
// get support modes configuration
uint32_t modeSupportInfo = 0;
const auto& supportModes = abilityInfo->windowModes;
for (auto& mode : supportModes) {
if (static_cast<uint32_t>(mode) == static_cast<uint32_t>(0)) { // 0 : fullScreen
modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN;
} else if (static_cast<uint32_t>(mode) == static_cast<uint32_t>(1)) { // 1 : split
modeSupportInfo |= (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY);
} else if (static_cast<uint32_t>(mode) == static_cast<uint32_t>(2)) { // 2 : floating
modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING;
}
}
WindowHelper::ConvertSupportModesToSupportInfo(modeSupportInfo, abilityInfo->windowModes);
if (modeSupportInfo == 0) {
WLOGFI("mode config param is 0, set all modes");
WLOGFI("mode config param is 0, all modes is supported");
modeSupportInfo = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
}
WLOGFI("winId: %{public}u, modeSupportInfo: %{public}u", GetWindowId(), modeSupportInfo);
SetRequestModeSupportInfo(modeSupportInfo);
// get window size limits configuration
@@ -734,6 +725,18 @@ void WindowImpl::GetConfigurationFromAbilityInfo()
void WindowImpl::UpdateTitleButtonVisibility()
{
WLOGFI("[Client] UpdateTitleButtonVisibility");
if (uiContent_ == nullptr || !isAppDecorEnable_) {
return;
}
auto modeSupportInfo = GetModeSupportInfo();
bool hideSplitButton = !(modeSupportInfo & WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY);
// not support fullscreen in split and floating mode, or not support float in fullscreen mode
bool hideMaximizeButton = (!(modeSupportInfo & WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN) &&
(GetMode() == WindowMode::WINDOW_MODE_FLOATING || WindowHelper::IsSplitWindowMode(GetMode()))) ||
(!(modeSupportInfo & WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING) &&
GetMode() == WindowMode::WINDOW_MODE_FULLSCREEN);
WLOGFI("[Client] [hideSplit, hideMaximize]: [%{public}d, %{public}d]", hideSplitButton, hideMaximizeButton);
uiContent_->HideWindowTitleButton(hideSplitButton, hideMaximizeButton, false);
}
WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr<AbilityRuntime::Context>& context)
@@ -966,9 +969,10 @@ WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation)
bool isShowWhenLocked = GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
if (!WindowHelper::IsWindowModeSupported(GetModeSupportInfo(), GetMode()) ||
WindowHelper::IsOnlySupportSplitAndShowWhenLocked(isShowWhenLocked, GetModeSupportInfo())) {
WLOGFE("current mode is not be supported, windowId: %{public}u", property_->GetWindowId());
NotifyForegroundFailed();
return WMError::WM_ERROR_INVALID_WINDOW;
WLOGFE("current mode is not supported, windowId: %{public}u, modeSupportInfo: %{public}u, winMode: %{public}u",
property_->GetWindowId(), GetModeSupportInfo(), GetMode());
NotifyForegroundInvalidWindowMode();
return WMError::WM_ERROR_INVALID_WINDOW_MODE;
}
// update title button visibility when show
@@ -979,6 +983,8 @@ WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation)
if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) {
state_ = WindowState::STATE_SHOWN;
NotifyAfterForeground();
} else if (ret == WMError::WM_ERROR_INVALID_WINDOW_MODE) {
NotifyForegroundInvalidWindowMode();
} else {
NotifyForegroundFailed();
WLOGFE("show window id:%{public}u errCode:%{public}d", property_->GetWindowId(), static_cast<int32_t>(ret));
@@ -1678,6 +1684,7 @@ void WindowImpl::UpdateMode(WindowMode mode)
{
WLOGI("UpdateMode %{public}u", mode);
property_->SetWindowMode(mode);
UpdateTitleButtonVisibility();
NotifyModeChange(mode);
if (uiContent_ != nullptr) {
uiContent_->UpdateWindowMode(mode);
+5 -2
View File
@@ -30,7 +30,7 @@ public:
StartingWindow() = delete;
~StartingWindow() = default;
static sptr<WindowNode> CreateWindowNode(sptr<WindowTransitionInfo> info,
static sptr<WindowNode> CreateWindowNode(const sptr<WindowTransitionInfo>& info,
uint32_t winId, WindowLayoutMode layoutMode);
static void HandleClientWindowCreate(sptr<WindowNode>& node, sptr<IWindow>& window,
uint32_t& windowId, const std::shared_ptr<RSSurfaceNode>& surfaceNode, sptr<WindowProperty>& property,
@@ -39,9 +39,12 @@ public:
bool isColdStart);
static void UpdateRSTree(sptr<WindowNode>& node);
static void ReleaseStartWinSurfaceNode(sptr<WindowNode>& node);
private:
static SurfaceDraw surfaceDraw_;
static WMError CreateLeashAndStartingSurfaceNode(sptr<WindowNode>& node);
static bool NeedCancelStartingWindow(uint32_t modeSupportInfo,
WindowLayoutMode layoutMode, const sptr<WindowTransitionInfo>& info);
static SurfaceDraw surfaceDraw_;
static std::recursive_mutex mutex_;
};
} // Rosen
+16 -10
View File
@@ -32,7 +32,19 @@ SurfaceDraw StartingWindow::surfaceDraw_;
static bool g_hasInit = false;
std::recursive_mutex StartingWindow::mutex_;
sptr<WindowNode> StartingWindow::CreateWindowNode(sptr<WindowTransitionInfo> info,
bool StartingWindow::NeedCancelStartingWindow(uint32_t modeSupportInfo,
WindowLayoutMode layoutMode, const sptr<WindowTransitionInfo>& info)
{
if ((!WindowHelper::IsWindowModeSupported(modeSupportInfo, info->GetWindowMode())) ||
(WindowHelper::IsInvalidWindowInTileLayoutMode(modeSupportInfo, layoutMode)) ||
(WindowHelper::IsOnlySupportSplitAndShowWhenLocked(info->GetShowFlagWhenLocked(), modeSupportInfo))) {
WLOGFI("window mode is not be supported or not support floating mode in tile, cancel starting window");
return true;
}
return false;
}
sptr<WindowNode> StartingWindow::CreateWindowNode(const sptr<WindowTransitionInfo>& info,
uint32_t winId, WindowLayoutMode layoutMode)
{
sptr<WindowProperty> property = new(std::nothrow) WindowProperty();
@@ -40,16 +52,10 @@ sptr<WindowNode> StartingWindow::CreateWindowNode(sptr<WindowTransitionInfo> inf
return nullptr;
}
uint32_t modeSupportInfo = 0;
for (auto mode : info->GetWindowSupportModes()) {
modeSupportInfo |= mode;
}
// if mode isn't be supported or don't support floating mode in tile mode, create starting window failed
if ((!WindowHelper::IsWindowModeSupported(modeSupportInfo, info->GetWindowMode())) ||
((!WindowHelper::IsWindowModeSupported(modeSupportInfo, WindowMode::WINDOW_MODE_FLOATING)) &&
(layoutMode == WindowLayoutMode::TILE)) ||
(WindowHelper::IsOnlySupportSplitAndShowWhenLocked(info->GetShowFlagWhenLocked(), modeSupportInfo))) {
uint32_t modeSupportInfo = 0;
WindowHelper::ConvertSupportModesToSupportInfo(modeSupportInfo, info->GetWindowSupportModes());
if (NeedCancelStartingWindow(modeSupportInfo, layoutMode, info)) {
WLOGFI("window mode is not be supported or not support floating mode in tile, cancel starting window");
return nullptr;
}
+8
View File
@@ -197,10 +197,18 @@ WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
WLOGFE("could not find window");
return WMError::WM_ERROR_NULLPTR;
}
if (node->currentVisibility_ && !node->startingWindowShown_) {
WLOGFE("current window is visible, windowId: %{public}u", node->GetWindowId());
return WMError::WM_ERROR_INVALID_OPERATION;
}
auto layoutMode = windowRoot_->GetCurrentLayoutMode(property->GetDisplayId());
if (WindowHelper::IsInvalidWindowInTileLayoutMode(node->GetModeSupportInfo(), layoutMode)) {
WLOGFE("window doesn't support floating mode in tile, windowId: %{public}u", node->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW_MODE;
}
// using starting window rect if client rect is empty
if (WindowHelper::IsEmptyRect(property->GetRequestRect()) && node->startingWindowShown_) { // for tile and cascade
property->SetRequestRect(node->GetRequestRect());
+5
View File
@@ -536,6 +536,10 @@ void WindowLayoutPolicy::UpdateWindowSizeLimits(const sptr<WindowNode>& node)
const auto& virtualPixelRatio = GetVirtualPixelRatio(node->GetDisplayId());
const auto& systemLimits = GetSystemSizeLimits(displayRect, virtualPixelRatio);
const auto& customizedLimits = node->GetWindowSizeLimits();
if (customizedLimits.isSizeLimitsUpdated_) {
WLOGFI("size limits have been updated");
return;
}
WindowSizeLimits newLimits = systemLimits;
// configured limits of floating window
@@ -580,6 +584,7 @@ void WindowLayoutPolicy::UpdateWindowSizeLimits(const sptr<WindowNode>& node)
uint32_t newMinHeight = static_cast<uint32_t>(static_cast<float>(newLimits.minWidth_) / newLimits.maxRatio_);
newLimits.minHeight_ = std::max(newMinHeight, newLimits.minHeight_);
newLimits.isSizeLimitsUpdated_ = true;
WLOGFI("maxWidth: %{public}u, maxHeight: %{public}u, minWidth: %{public}u, minHeight: %{public}u, "
"maxRatio: %{public}f, minRatio: %{public}f", newLimits.maxWidth_, newLimits.maxHeight_,
newLimits.minWidth_, newLimits.minHeight_, newLimits.maxRatio_, newLimits.minRatio_);
+16 -4
View File
@@ -192,15 +192,27 @@ void WindowPair::Clear()
{
WLOGI("Clear window pair.");
DumpPairInfo();
auto splitModeInfo = (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY);
if (primary_ != nullptr && primary_->GetWindowProperty() != nullptr &&
primary_->GetWindowToken() != nullptr) {
primary_->GetWindowProperty()->ResumeLastWindowMode();
primary_->GetWindowToken()->UpdateWindowMode(primary_->GetWindowMode());
if (primary_->GetModeSupportInfo() == splitModeInfo) {
MinimizeApp::AddNeedMinimizeApp(primary_, MinimizeReason::SPLIT_QUIT);
MinimizeApp::ExecuteMinimizeTargetReason(MinimizeReason::SPLIT_QUIT);
} else {
primary_->GetWindowProperty()->ResumeLastWindowMode();
primary_->GetWindowToken()->UpdateWindowMode(primary_->GetWindowMode());
}
}
if (secondary_ != nullptr && secondary_->GetWindowProperty() != nullptr &&
secondary_->GetWindowToken() != nullptr) {
secondary_->GetWindowProperty()->ResumeLastWindowMode();
secondary_->GetWindowToken()->UpdateWindowMode(secondary_->GetWindowMode());
if (secondary_->GetModeSupportInfo() == splitModeInfo) {
MinimizeApp::AddNeedMinimizeApp(secondary_, MinimizeReason::SPLIT_QUIT);
MinimizeApp::ExecuteMinimizeTargetReason(MinimizeReason::SPLIT_QUIT);
} else {
secondary_->GetWindowProperty()->ResumeLastWindowMode();
secondary_->GetWindowToken()->UpdateWindowMode(secondary_->GetWindowMode());
}
}
primary_ = nullptr;
secondary_ = nullptr;