!7297 CFI整改register_manager

Merge pull request !7297 from 毛亮/master
This commit is contained in:
openharmony_ci 2024-07-10 08:32:27 +00:00 committed by Gitee
commit bea13c2b72
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 229 additions and 107 deletions

View File

@ -22,39 +22,46 @@ namespace Rosen {
using namespace AbilityRuntime;
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsRegisterManager"};
const std::map<std::string, RegisterListenerType> WINDOW_MANAGER_LISTENER_MAP {
// white register list for window manager
{SYSTEM_BAR_TINT_CHANGE_CB, RegisterListenerType::SYSTEM_BAR_TINT_CHANGE_CB},
{GESTURE_NAVIGATION_ENABLED_CHANGE_CB, RegisterListenerType::GESTURE_NAVIGATION_ENABLED_CHANGE_CB},
{WATER_MARK_FLAG_CHANGE_CB, RegisterListenerType::WATER_MARK_FLAG_CHANGE_CB},
};
const std::map<std::string, RegisterListenerType> WINDOW_LISTENER_MAP {
// white register list for window
{WINDOW_SIZE_CHANGE_CB, RegisterListenerType::WINDOW_SIZE_CHANGE_CB},
{SYSTEM_AVOID_AREA_CHANGE_CB, RegisterListenerType::SYSTEM_AVOID_AREA_CHANGE_CB},
{AVOID_AREA_CHANGE_CB, RegisterListenerType::AVOID_AREA_CHANGE_CB},
{LIFECYCLE_EVENT_CB, RegisterListenerType::LIFECYCLE_EVENT_CB},
{WINDOW_EVENT_CB, RegisterListenerType::WINDOW_EVENT_CB},
{KEYBOARD_HEIGHT_CHANGE_CB, RegisterListenerType::KEYBOARD_HEIGHT_CHANGE_CB},
{TOUCH_OUTSIDE_CB, RegisterListenerType::TOUCH_OUTSIDE_CB},
{SCREENSHOT_EVENT_CB, RegisterListenerType::SCREENSHOT_EVENT_CB},
{DIALOG_TARGET_TOUCH_CB, RegisterListenerType::DIALOG_TARGET_TOUCH_CB},
{DIALOG_DEATH_RECIPIENT_CB, RegisterListenerType::DIALOG_DEATH_RECIPIENT_CB},
{WINDOW_STATUS_CHANGE_CB, RegisterListenerType::WINDOW_STATUS_CHANGE_CB},
{WINDOW_TITLE_BUTTON_RECT_CHANGE_CB, RegisterListenerType::WINDOW_TITLE_BUTTON_RECT_CHANGE_CB},
{WINDOW_VISIBILITY_CHANGE_CB, RegisterListenerType::WINDOW_VISIBILITY_CHANGE_CB},
{WINDOW_NO_INTERACTION_DETECT_CB, RegisterListenerType::WINDOW_NO_INTERACTION_DETECT_CB},
{WINDOW_RECT_CHANGE_CB, RegisterListenerType::WINDOW_RECT_CHANGE_CB},
{SUB_WINDOW_CLOSE_CB, RegisterListenerType::SUB_WINDOW_CLOSE_CB},
};
const std::map<std::string, RegisterListenerType> WINDOW_STAGE_LISTENER_MAP {
// white register list for window stage
{WINDOW_STAGE_EVENT_CB, RegisterListenerType::WINDOW_STAGE_EVENT_CB},
};
const std::map<CaseType, std::map<std::string, RegisterListenerType>> LISTENER_CODE_MAP {
{CaseType::CASE_WINDOW_MANAGER, WINDOW_MANAGER_LISTENER_MAP},
{CaseType::CASE_WINDOW, WINDOW_LISTENER_MAP},
{CaseType::CASE_STAGE, WINDOW_STAGE_LISTENER_MAP},
};
}
JsWindowRegisterManager::JsWindowRegisterManager()
{
// white register list for window manager
listenerProcess_[CaseType::CASE_WINDOW_MANAGER] = {
{SYSTEM_BAR_TINT_CHANGE_CB, &JsWindowRegisterManager::ProcessSystemBarChangeRegister },
{GESTURE_NAVIGATION_ENABLED_CHANGE_CB, &JsWindowRegisterManager::ProcessGestureNavigationEnabledChangeRegister},
{WATER_MARK_FLAG_CHANGE_CB, &JsWindowRegisterManager::ProcessWaterMarkFlagChangeRegister },
};
// white register list for window
listenerProcess_[CaseType::CASE_WINDOW] = {
{ WINDOW_SIZE_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowChangeRegister },
{ SYSTEM_AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessSystemAvoidAreaChangeRegister },
{ AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessAvoidAreaChangeRegister },
{ LIFECYCLE_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister },
{ WINDOW_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister },
{ KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcessOccupiedAreaChangeRegister },
{ TOUCH_OUTSIDE_CB, &JsWindowRegisterManager::ProcessTouchOutsideRegister },
{ SCREENSHOT_EVENT_CB, &JsWindowRegisterManager::ProcessScreenshotRegister },
{ DIALOG_TARGET_TOUCH_CB, &JsWindowRegisterManager::ProcessDialogTargetTouchRegister },
{ DIALOG_DEATH_RECIPIENT_CB, &JsWindowRegisterManager::ProcessDialogDeathRecipientRegister },
{ WINDOW_STATUS_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowStatusChangeRegister },
{ WINDOW_TITLE_BUTTON_RECT_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowTitleButtonRectChangeRegister},
{ WINDOW_VISIBILITY_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowVisibilityChangeRegister },
{ WINDOW_NO_INTERACTION_DETECT_CB, &JsWindowRegisterManager::ProcessWindowNoInteractionRegister },
{ WINDOW_RECT_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowRectChangeRegister },
{ SUB_WINDOW_CLOSE_CB, &JsWindowRegisterManager::ProcessSubWindowCloseRegister },
};
// white register list for window stage
listenerProcess_[CaseType::CASE_STAGE] = {
{WINDOW_STAGE_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister }
};
}
JsWindowRegisterManager::~JsWindowRegisterManager()
@ -352,10 +359,17 @@ WmErrorCode JsWindowRegisterManager::RegisterListener(sptr<Window> window, std::
if (IsCallbackRegistered(env, type, callback)) {
return WmErrorCode::WM_OK;
}
if (listenerProcess_[caseType].count(type) == 0) {
auto iterCaseType = LISTENER_CODE_MAP.find(caseType);
if (iterCaseType == LISTENER_CODE_MAP.end()) {
WLOGFE("[NAPI]CaseType %{public}u is not supported", static_cast<uint32_t>(caseType));
return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
}
auto iterCallbackType = iterCaseType->second.find(type);
if (iterCallbackType == iterCaseType->second.end()) {
WLOGFE("[NAPI]Type %{public}s is not supported", type.c_str());
return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
}
RegisterListenerType listenerType = iterCallbackType->second;
napi_ref result = nullptr;
napi_create_reference(env, callback, 1, &result);
std::shared_ptr<NativeReference> callbackRef(reinterpret_cast<NativeReference*>(result));
@ -365,7 +379,8 @@ WmErrorCode JsWindowRegisterManager::RegisterListener(sptr<Window> window, std::
return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
}
windowManagerListener->SetMainEventHandler();
WmErrorCode ret = (this->*listenerProcess_[caseType][type])(windowManagerListener, window, true, env, parameter);
WmErrorCode ret = ProcessListener(listenerType, caseType, windowManagerListener, window, true,
env, parameter);
if (ret != WmErrorCode::WM_OK) {
WLOGFE("[NAPI]Register type %{public}s failed", type.c_str());
return ret;
@ -376,6 +391,72 @@ WmErrorCode JsWindowRegisterManager::RegisterListener(sptr<Window> window, std::
return WmErrorCode::WM_OK;
}
WmErrorCode JsWindowRegisterManager::ProcessListener(RegisterListenerType registerListenerType, CaseType caseType,
const sptr<JsWindowListener>& windowManagerListener, const sptr<Window>& window, bool isRegister,
napi_env env, napi_value parameter)
{
if (caseType == CaseType::CASE_WINDOW_MANAGER) {
switch (static_cast<uint32_t>(registerListenerType)) {
case static_cast<uint32_t>(RegisterListenerType::SYSTEM_BAR_TINT_CHANGE_CB):
return ProcessSystemBarChangeRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::GESTURE_NAVIGATION_ENABLED_CHANGE_CB):
return ProcessGestureNavigationEnabledChangeRegister(windowManagerListener, window, isRegister,
env, parameter);
case static_cast<uint32_t>(RegisterListenerType::WATER_MARK_FLAG_CHANGE_CB):
return ProcessWaterMarkFlagChangeRegister(windowManagerListener, window, isRegister, env, parameter);
default:
WLOGFE("[NAPI]RegisterListenerType %{public}u is not supported",
static_cast<uint32_t>(registerListenerType));
return WmErrorCode::WM_ERROR_INVALID_PARAM;
}
} else if (caseType == CaseType::CASE_WINDOW) {
switch (static_cast<uint32_t>(registerListenerType)) {
case static_cast<uint32_t>(RegisterListenerType::WINDOW_SIZE_CHANGE_CB):
return ProcessWindowChangeRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::SYSTEM_AVOID_AREA_CHANGE_CB):
return ProcessSystemAvoidAreaChangeRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::AVOID_AREA_CHANGE_CB):
return ProcessAvoidAreaChangeRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::LIFECYCLE_EVENT_CB):
return ProcessLifeCycleEventRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::WINDOW_EVENT_CB):
return ProcessLifeCycleEventRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::KEYBOARD_HEIGHT_CHANGE_CB):
return ProcessOccupiedAreaChangeRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::TOUCH_OUTSIDE_CB):
return ProcessTouchOutsideRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::SCREENSHOT_EVENT_CB):
return ProcessScreenshotRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::DIALOG_TARGET_TOUCH_CB):
return ProcessDialogTargetTouchRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::DIALOG_DEATH_RECIPIENT_CB):
return ProcessDialogDeathRecipientRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::WINDOW_STATUS_CHANGE_CB):
return ProcessWindowStatusChangeRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::WINDOW_TITLE_BUTTON_RECT_CHANGE_CB):
return ProcessWindowTitleButtonRectChangeRegister(windowManagerListener, window, isRegister, env,
parameter);
case static_cast<uint32_t>(RegisterListenerType::WINDOW_VISIBILITY_CHANGE_CB):
return ProcessWindowVisibilityChangeRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::WINDOW_NO_INTERACTION_DETECT_CB):
return ProcessWindowNoInteractionRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::WINDOW_RECT_CHANGE_CB):
return ProcessWindowRectChangeRegister(windowManagerListener, window, isRegister, env, parameter);
case static_cast<uint32_t>(RegisterListenerType::SUB_WINDOW_CLOSE_CB):
return ProcessSubWindowCloseRegister(windowManagerListener, window, isRegister, env, parameter);
default:
WLOGFE("[NAPI]RegisterListenerType %{public}u is not supported",
static_cast<uint32_t>(registerListenerType));
return WmErrorCode::WM_ERROR_INVALID_PARAM;
}
} else if (caseType == CaseType::CASE_STAGE) {
if (registerListenerType == RegisterListenerType::WINDOW_STAGE_EVENT_CB) {
return ProcessLifeCycleEventRegister(windowManagerListener, window, isRegister, env, parameter);
}
}
return WmErrorCode::WM_OK;
}
WmErrorCode JsWindowRegisterManager::UnregisterListener(sptr<Window> window, std::string type,
CaseType caseType, napi_env env, napi_value value)
{
@ -384,13 +465,21 @@ WmErrorCode JsWindowRegisterManager::UnregisterListener(sptr<Window> window, std
WLOGFW("[NAPI]Type %{public}s was not registerted", type.c_str());
return WmErrorCode::WM_OK;
}
if (listenerProcess_[caseType].count(type) == 0) {
auto iterCaseType = LISTENER_CODE_MAP.find(caseType);
if (iterCaseType == LISTENER_CODE_MAP.end()) {
WLOGFE("[NAPI]CaseType %{public}u is not supported", static_cast<uint32_t>(caseType));
return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
}
auto iterCallbackType = iterCaseType->second.find(type);
if (iterCallbackType == iterCaseType->second.end()) {
WLOGFE("[NAPI]Type %{public}s is not supported", type.c_str());
return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
}
RegisterListenerType listenerType = iterCallbackType->second;
if (value == nullptr) {
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
WmErrorCode ret = (this->*listenerProcess_[caseType][type])(it->second, window, false, env, nullptr);
WmErrorCode ret = ProcessListener(listenerType, caseType, it->second, window,
false, env, nullptr);
if (ret != WmErrorCode::WM_OK) {
WLOGFE("[NAPI]Unregister type %{public}s failed, no value", type.c_str());
return ret;
@ -406,7 +495,8 @@ WmErrorCode JsWindowRegisterManager::UnregisterListener(sptr<Window> window, std
continue;
}
findFlag = true;
WmErrorCode ret = (this->*listenerProcess_[caseType][type])(it->second, window, false, env, nullptr);
WmErrorCode ret = ProcessListener(listenerType, caseType, it->second, window,
false, env, nullptr);
if (ret != WmErrorCode::WM_OK) {
WLOGFE("[NAPI]Unregister type %{public}s failed", type.c_str());
return ret;

View File

@ -24,6 +24,29 @@
#include "window.h"
namespace OHOS {
namespace Rosen {
enum class RegisterListenerType : uint32_t {
SYSTEM_BAR_TINT_CHANGE_CB,
GESTURE_NAVIGATION_ENABLED_CHANGE_CB,
WATER_MARK_FLAG_CHANGE_CB,
WINDOW_SIZE_CHANGE_CB,
SYSTEM_AVOID_AREA_CHANGE_CB,
AVOID_AREA_CHANGE_CB,
LIFECYCLE_EVENT_CB,
WINDOW_EVENT_CB,
KEYBOARD_HEIGHT_CHANGE_CB,
TOUCH_OUTSIDE_CB,
SCREENSHOT_EVENT_CB,
DIALOG_TARGET_TOUCH_CB,
DIALOG_DEATH_RECIPIENT_CB,
WINDOW_STATUS_CHANGE_CB,
WINDOW_TITLE_BUTTON_RECT_CHANGE_CB,
WINDOW_VISIBILITY_CHANGE_CB,
WINDOW_NO_INTERACTION_DETECT_CB,
WINDOW_RECT_CHANGE_CB,
SUB_WINDOW_CLOSE_CB,
WINDOW_STAGE_EVENT_CB,
};
class JsWindowRegisterManager {
public:
JsWindowRegisterManager();
@ -70,11 +93,11 @@ private:
bool isRegister, napi_env env, napi_value parameter = nullptr);
WmErrorCode ProcessSubWindowCloseRegister(sptr<JsWindowListener> listener, sptr<Window> window,
bool isRegister, napi_env env, napi_value parameter = nullptr);
using Func = WmErrorCode(JsWindowRegisterManager::*)(sptr<JsWindowListener>, sptr<Window> window, bool,
WmErrorCode ProcessListener(RegisterListenerType registerListenerType, CaseType caseType,
const sptr<JsWindowListener>& windowManagerListener, const sptr<Window>& window, bool isRegister,
napi_env env, napi_value parameter);
std::map<std::string, std::map<std::shared_ptr<NativeReference>, sptr<JsWindowListener>>> jsCbMap_;
std::mutex mtx_;
std::map<CaseType, std::map<std::string, Func>> listenerProcess_;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -75,8 +75,6 @@ using CameraSessionChangeCallback = std::function<void(uint32_t accessTokenId, b
using NotifyLandscapeMultiWindowSessionFunc = std::function<void(bool isLandscapeMultiWindow)>;
using NotifyKeyboardGravityChangeFunc = std::function<void(SessionGravity gravity)>;
using NotifyKeyboardLayoutAdjustFunc = std::function<void(const KeyboardLayoutParams& params)>;
using HandleUpdatePropertyFunc = WMError (SceneSession::*)(const sptr<WindowSessionProperty>& property,
const sptr<SceneSession>& sceneSession, WSPropertyChangeAction action);
using SessionChangeByActionNotifyManagerFunc = std::function<void(const sptr<SceneSession>& sceneSession,
const sptr<WindowSessionProperty>& property, WSPropertyChangeAction action)>;
using SystemSessionBufferAvailableCallback = std::function<void()>;
@ -446,6 +444,8 @@ private:
const sptr<SceneSession>& sceneSession, WSPropertyChangeAction action);
WMError HandleActionUpdateModeSupportInfo(const sptr<WindowSessionProperty>& property,
const sptr<SceneSession>& sceneSession, WSPropertyChangeAction action);
WMError ProcessUpdatePropertyByAction(const sptr<WindowSessionProperty>& property,
const sptr<SceneSession>& sceneSession, WSPropertyChangeAction action);
void HandleSpecificSystemBarProperty(WindowType type, const sptr<WindowSessionProperty>& property,
const sptr<SceneSession>& sceneSession);
void SetWindowFlags(const sptr<SceneSession>& sceneSession,
@ -484,7 +484,6 @@ private:
mutable std::shared_mutex uiExtNodeIdToPersistentIdMapMutex_;
std::map<uint64_t, int32_t> uiExtNodeIdToPersistentIdMap_;
std::string clientIdentityToken_ = { "" };
static const std::map<uint32_t, HandleUpdatePropertyFunc> sessionFuncMap_;
SessionChangeByActionNotifyManagerFunc sessionChangeByActionNotifyManagerFunc_;
};
} // namespace OHOS::Rosen

View File

@ -66,62 +66,6 @@ std::mutex SceneSession::enterSessionMutex_;
std::shared_mutex SceneSession::windowDragHotAreaMutex_;
std::map<uint32_t, WSRect> SceneSession::windowDragHotAreaMap_;
static bool g_enableForceUIFirst = system::GetParameter("window.forceUIFirst.enabled", "1") == "1";
const std::map<uint32_t, HandleUpdatePropertyFunc> SceneSession::sessionFuncMap_ {
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON),
&SceneSession::HandleActionUpdateTurnScreenOn),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON),
&SceneSession::HandleActionUpdateKeepScreenOn),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_FOCUSABLE),
&SceneSession::HandleActionUpdateFocusable),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TOUCHABLE),
&SceneSession::HandleActionUpdateTouchable),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS),
&SceneSession::HandleActionUpdateSetBrightness),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_ORIENTATION),
&SceneSession::HandleActionUpdateOrientation),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE),
&SceneSession::HandleActionUpdatePrivacyMode),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE),
&SceneSession::HandleActionUpdatePrivacyMode),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP),
&SceneSession::HandleActionUpdateSnapshotSkip),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE),
&SceneSession::HandleActionUpdateMaximizeState),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_OTHER_PROPS),
&SceneSession::HandleActionUpdateOtherProps),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_STATUS_PROPS),
&SceneSession::HandleActionUpdateStatusProps),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_PROPS),
&SceneSession::HandleActionUpdateNavigationProps),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_INDICATOR_PROPS),
&SceneSession::HandleActionUpdateNavigationIndicatorProps),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_FLAGS),
&SceneSession::HandleActionUpdateFlags),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_MODE),
&SceneSession::HandleActionUpdateMode),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG),
&SceneSession::HandleActionUpdateAnimationFlag),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA),
&SceneSession::HandleActionUpdateTouchHotArea),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_DECOR_ENABLE),
&SceneSession::HandleActionUpdateDecorEnable),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS),
&SceneSession::HandleActionUpdateWindowLimits),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_DRAGENABLED),
&SceneSession::HandleActionUpdateDragenabled),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_RAISEENABLED),
&SceneSession::HandleActionUpdateRaiseenabled),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_HIDE_NON_SYSTEM_FLOATING_WINDOWS),
&SceneSession::HandleActionUpdateHideNonSystemFloatingWindows),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO),
&SceneSession::HandleActionUpdateTextfieldAvoidInfo),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_WINDOW_MASK),
&SceneSession::HandleActionUpdateWindowMask),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TOPMOST),
&SceneSession::HandleActionUpdateTopmost),
std::make_pair(static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO),
&SceneSession::HandleActionUpdateModeSupportInfo),
};
SceneSession::SceneSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback)
: Session(info)
@ -2810,12 +2754,72 @@ WMError SceneSession::HandleUpdatePropertyByAction(const sptr<WindowSessionPrope
TLOGE(WmsLogTag::DEFAULT, "property is nullptr");
return WMError::WM_ERROR_NULLPTR;
}
const auto funcIter = sessionFuncMap_.find(static_cast<uint32_t>(action));
if (funcIter == sessionFuncMap_.end()) {
TLOGE(WmsLogTag::DEFAULT, "Failed to find func handler!");
return WMError::WM_DO_NOTHING;
return ProcessUpdatePropertyByAction(property, sceneSession, action);
}
WMError SceneSession::ProcessUpdatePropertyByAction(const sptr<WindowSessionProperty>& property,
const sptr<SceneSession>& sceneSession, WSPropertyChangeAction action)
{
switch (static_cast<uint32_t>(action)) {
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON):
return HandleActionUpdateTurnScreenOn(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON):
return HandleActionUpdateKeepScreenOn(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_FOCUSABLE):
return HandleActionUpdateFocusable(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TOUCHABLE):
return HandleActionUpdateTouchable(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS):
return HandleActionUpdateSetBrightness(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_ORIENTATION):
return HandleActionUpdateOrientation(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE):
return HandleActionUpdatePrivacyMode(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE):
return HandleActionUpdatePrivacyMode(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP):
return HandleActionUpdateSnapshotSkip(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE):
return HandleActionUpdateMaximizeState(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_OTHER_PROPS):
return HandleActionUpdateOtherProps(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_STATUS_PROPS):
return HandleActionUpdateStatusProps(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_PROPS):
return HandleActionUpdateNavigationProps(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_INDICATOR_PROPS):
return HandleActionUpdateNavigationIndicatorProps(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_FLAGS):
return HandleActionUpdateFlags(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_MODE):
return HandleActionUpdateMode(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG):
return HandleActionUpdateAnimationFlag(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA):
return HandleActionUpdateTouchHotArea(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_DECOR_ENABLE):
return HandleActionUpdateDecorEnable(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS):
return HandleActionUpdateWindowLimits(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_DRAGENABLED):
return HandleActionUpdateDragenabled(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_RAISEENABLED):
return HandleActionUpdateRaiseenabled(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_HIDE_NON_SYSTEM_FLOATING_WINDOWS):
return HandleActionUpdateHideNonSystemFloatingWindows(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO):
return HandleActionUpdateTextfieldAvoidInfo(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_WINDOW_MASK):
return HandleActionUpdateWindowMask(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_TOPMOST):
return HandleActionUpdateTopmost(property, sceneSession, action);
case static_cast<uint32_t>(WSPropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO):
return HandleActionUpdateModeSupportInfo(property, sceneSession, action);
default:
TLOGE(WmsLogTag::DEFAULT, "Failed to find func handler!");
return WMError::WM_DO_NOTHING;
}
return (this->*(funcIter->second))(property, sceneSession, action);
}
WMError SceneSession::HandleActionUpdateTurnScreenOn(const sptr<WindowSessionProperty>& property,

View File

@ -49,9 +49,6 @@ private:
void SubscriberEventInner(int retry);
void HandleAccountSwitched(const EventFwk::CommonEventData& data) const;
typedef void (WindowCommonEvent::*HandleCommonEventFunc)(const EventFwk::CommonEventData& data) const;
std::map<std::string, HandleCommonEventFunc> handleCommonEventFuncs_;
std::shared_ptr<EventSubscriber> subscriber_;
std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
};

View File

@ -29,12 +29,18 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "CommonEvent"};
constexpr int RETRY_MAX_COUNT = 3;
const std::string THREAD_ID = "WindowCommonEventHandler";
enum class CommonEventCode : uint32_t {
COMMON_EVENT_USER_SWITCHED,
};
const std::map<std::string, CommonEventCode> COMMON_EVENT_CODE_MAP {
{EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED, CommonEventCode::COMMON_EVENT_USER_SWITCHED},
};
}
WindowCommonEvent::WindowCommonEvent()
{
handleCommonEventFuncs_.insert(make_pair(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED,
&WindowCommonEvent::HandleAccountSwitched));
auto runner = AppExecFwk::EventRunner::Create(THREAD_ID);
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
@ -82,8 +88,11 @@ void WindowCommonEvent::OnReceiveEvent(const EventFwk::CommonEventData& data)
auto task = [this, data] {
std::string action = data.GetWant().GetAction();
WLOGI("called action = %{public}s", action.c_str());
if (handleCommonEventFuncs_.count(action)) {
(this->*handleCommonEventFuncs_[action])(data);
if (auto iter = COMMON_EVENT_CODE_MAP.find(action); iter != COMMON_EVENT_CODE_MAP.end()) {
CommonEventCode commonEventCode = iter->second;
if (commonEventCode == CommonEventCode::COMMON_EVENT_USER_SWITCHED) {
HandleAccountSwitched(data);
}
}
};
eventHandler_->PostTask(task, "wms:OnReceiveEvent", 0, AppExecFwk::EventQueue::Priority::HIGH);