router强制分栏需求开发

Signed-off-by: 陈前 <chenqian73@huawei.com>
This commit is contained in:
陈前 2024-07-09 17:06:59 +08:00
parent 8183288c1b
commit ccd4987f2a
15 changed files with 164 additions and 0 deletions

View File

@ -106,6 +106,7 @@ public:
MOCK_METHOD0(IsUIExtensionAbilityProcess, bool());
MOCK_METHOD4(NotifyExecuteAction, bool(int64_t elementId, const std::map<std::string, std::string>& actionAguments,
int32_t action, int64_t baseParent));
MOCK_METHOD1(SetForceSplitEnable, void(bool isForceSplit));
};
} // namespace Ace
} // namespace OHOS

View File

@ -160,6 +160,8 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj)
JsSceneSessionManager::UpdateDisplayHookInfo);
BindNativeFunction(env, exportObj, "initScheduleUtils", moduleName,
JsSceneSessionManager::InitScheduleUtils);
BindNativeFunction(env, exportObj, "SetAppForceLandscapeMode", moduleName,
JsSceneSessionManager::SetAppForceLandscapeMode);
return NapiGetUndefined(env);
}
@ -2664,4 +2666,41 @@ napi_value JsSceneSessionManager::OnUpdateDisplayHookInfo(napi_env env, napi_cal
SceneSessionManager::GetInstance().UpdateDisplayHookInfo(uid, width, height, static_cast<float_t>(density), enable);
return NapiGetUndefined(env);
}
napi_value JsSceneSessionManager::SetAppForceLandscapeMode(napi_env env, napi_callback_info info)
{
WLOGFI("[NAPI] SetAppForceLandscapeMode");
JsSceneSessionManager *me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
return (me != nullptr) ? me->OnSetAppForceLandscapeMode(env, info) : nullptr;
}
napi_value JsSceneSessionManager::OnSetAppForceLandscapeMode(napi_env env, napi_callback_info info)
{
size_t argc = 4;
napi_value argv[4] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < ARGC_TWO) {
WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
return NapiGetUndefined(env);
}
std::string bundleName;
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
WLOGFE("[NAPI]Failed to convert parameter to bundleName");
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
return NapiGetUndefined(env);
}
int32_t mode;
if (!ConvertFromJsValue(env, argv[1], mode)) {
WLOGFE("[NAPI]Failed to convert parameter to forceLandscapeMode");
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
return NapiGetUndefined(env);
}
SceneSessionManager::GetInstance().SetAppForceLandscapeMode(bundleName, mode);
return NapiGetUndefined(env);
}
} // namespace OHOS::Rosen

View File

@ -86,6 +86,7 @@ public:
static napi_value NotifyEnterRecentTask(napi_env env, napi_callback_info info);
static napi_value UpdateDisplayHookInfo(napi_env env, napi_callback_info info);
static napi_value InitScheduleUtils(napi_env env, napi_callback_info info);
static napi_value SetAppForceLandscapeMode(napi_env env, napi_callback_info info);
private:
enum class ListenerFunctionType : uint32_t {
@ -155,6 +156,7 @@ private:
napi_value OnNotifyEnterRecentTask(napi_env env, napi_callback_info info);
napi_value OnUpdateDisplayHookInfo(napi_env env, napi_callback_info info);
napi_value OnInitScheduleUtils(napi_env env, napi_callback_info info);
napi_value OnSetAppForceLandscapeMode(napi_env env, napi_callback_info info);
void OnStatusBarEnabledUpdate(bool enable);
void OnGestureNavigationEnabledUpdate(bool enable);

View File

@ -82,6 +82,7 @@ using SessionChangeByActionNotifyManagerFunc = std::function<void(const sptr<Sce
using SystemSessionBufferAvailableCallback = std::function<void()>;
using NotifyLayoutFullScreenChangeFunc = std::function<void(bool isLayoutFullScreen)>;
using SetSkipSelfWhenShowOnVirtualScreenCallback = std::function<void(uint64_t surfaceNodeId, bool isSkip)>;
using NotifyForceSplitFunc = std::function<int32_t(const std::string& bundleName)>;
class SceneSession : public Session {
public:
// callback for notify SceneSessionManager
@ -278,6 +279,7 @@ public:
void NotifySessionForeground(uint32_t reason, bool withAnimation);
void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits);
void RegisterSessionChangeCallback(const sptr<SceneSession::SessionChangeCallback>& sessionChangeCallback);
void RegisterForceSplitListener(const NotifyForceSplitFunc& func);
void ClearSpecificSessionCbMap();
void SendPointerEventToUI(std::shared_ptr<MMI::PointerEvent> pointerEvent);
bool SendKeyEventToUI(std::shared_ptr<MMI::KeyEvent> keyEvent, bool isPreImeEvent = false);
@ -336,6 +338,7 @@ public:
void AddUIExtSurfaceNodeId(uint64_t surfaceNodeId, int32_t persistentId);
void RemoveUIExtSurfaceNodeId(int32_t persistentId);
int32_t GetUIExtPersistentIdBySurfaceNodeId(uint64_t surfaceNodeId) const;
int32_t GetAppForceLandscapeMode(const std::string& bundleName) override;
protected:
void NotifyIsCustomAnimationPlaying(bool isPlaying);
@ -455,6 +458,7 @@ private:
NotifySessionRectChangeFunc sessionRectChangeFunc_;
NotifySessionPiPControlStatusChangeFunc sessionPiPControlStatusChangeFunc_;
NotifyForceSplitFunc forceSplitFunc_;
static wptr<SceneSession> enterSession_;
static std::mutex enterSessionMutex_;
mutable std::mutex sessionChangeCbMutex_;

View File

@ -111,6 +111,7 @@ public:
virtual WSError AdjustKeyboardLayout(const KeyboardLayoutParams& params) { return WSError::WS_OK; }
virtual WMError UpdateSessionPropertyByAction(const sptr<WindowSessionProperty>& property,
WSPropertyChangeAction action) { return WMError::WM_OK; }
virtual int32_t GetAppForceLandscapeMode(const std::string& bundleName) { return 0; }
};
} // namespace OHOS::Rosen

View File

@ -58,6 +58,7 @@ enum class SessionInterfaceCode {
TRANS_ID_ADJUST_KEYBOARD_LAYOUT,
TRANS_ID_UPDATE_SESSION_PROPERTY,
TRANS_ID_LAYOUT_FULL_SCREEN_CHANGE,
TRANS_ID_GET_FORCE_LANDSCAPE_MODE,
// Extension
TRANS_ID_TRANSFER_ABILITY_RESULT = 500,

View File

@ -84,6 +84,8 @@ public:
WSError AdjustKeyboardLayout(const KeyboardLayoutParams& params) override;
WMError UpdateSessionPropertyByAction(const sptr<WindowSessionProperty>& property,
WSPropertyChangeAction action) override;
int32_t GetAppForceLandscapeMode(const std::string& bundleName) override;
private:
static inline BrokerDelegator<SessionProxy> delegator_;
};

View File

@ -71,6 +71,7 @@ private:
int HandleAdjustKeyboardLayout(MessageParcel& data, MessageParcel& reply);
int HandleUpdatePropertyByAction(MessageParcel& data, MessageParcel& reply);
int HandleLayoutFullScreenChange(MessageParcel& data, MessageParcel& reply);
int HandleGetAppForceLandscapeMode(MessageParcel& data, MessageParcel& reply);
// extension extension
int HandleTransferAbilityResult(MessageParcel& data, MessageParcel& reply);

View File

@ -3787,4 +3787,17 @@ WMError SceneSession::HandleActionUpdateModeSupportInfo(const sptr<WindowSession
}
return WMError::WM_OK;
}
void SceneSession::RegisterForceSplitListener(const NotifyForceSplitFunc& func)
{
forceSplitFunc_ = func;
}
int32_t SceneSession::GetAppForceLandscapeMode(const std::string& bundleName)
{
if (forceSplitFunc_ == nullptr) {
return 0;
}
return forceSplitFunc_(bundleName);
}
} // namespace OHOS::Rosen

View File

@ -1284,4 +1284,26 @@ WMError SessionProxy::UpdateSessionPropertyByAction(const sptr<WindowSessionProp
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
int32_t SessionProxy::GetAppForceLandscapeMode(const std::string& bundleName)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
return 0;
}
if (!data.WriteString(bundleName)) {
TLOGE(WmsLogTag::DEFAULT, "bundle name write failed");
return 0;
}
if (Remote()->SendRequest(static_cast<uint32_t>(
SessionInterfaceCode::TRANS_ID_GET_FORCE_LANDSCAPE_MODE),
data, reply, option) != ERR_NONE) {
TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
return 0;
}
return reply.ReadInt32();
}
} // namespace OHOS::Rosen

View File

@ -145,6 +145,8 @@ int SessionStub::ProcessRemoteRequest(uint32_t code, MessageParcel& data, Messag
return HandleUpdatePiPControlStatus(data, reply);
case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_LAYOUT_FULL_SCREEN_CHANGE):
return HandleLayoutFullScreenChange(data, reply);
case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_FORCE_LANDSCAPE_MODE):
return HandleGetAppForceLandscapeMode(data, reply);
default:
WLOGFE("Failed to find function handler!");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
@ -753,4 +755,17 @@ int SessionStub::HandleUpdatePropertyByAction(MessageParcel& data, MessageParcel
reply.WriteInt32(static_cast<int32_t>(ret));
return ERR_NONE;
}
int SessionStub::HandleGetAppForceLandscapeMode(MessageParcel& data, MessageParcel& reply)
{
TLOGD(WmsLogTag::DEFAULT, "called");
std::string bundleName = data.ReadString();
if (bundleName.empty()) {
TLOGE(WmsLogTag::DEFAULT, "read bundle name filed");
return ERR_INVALID_DATA;
}
int32_t ret = GetAppForceLandscapeMode(bundleName);
reply.WriteInt32(ret);
return ERR_NONE;
}
} // namespace OHOS::Rosen

View File

@ -343,6 +343,9 @@ public:
void InitScheduleUtils();
WMError ReportScreenFoldStatusChange(const std::vector<std::string>& screenFoldInfo);
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);
protected:
SceneSessionManager();
virtual ~SceneSessionManager();
@ -570,6 +573,8 @@ private:
std::shared_mutex startingWindowMapMutex_;
const size_t MAX_CACHE_COUNT = 100;
std::map<std::string, std::map<std::string, StartingWindowInfo>> startingWindowMap_;
std::map<std::string, int32_t> appForceLandscapeMap_;
std::shared_mutex appForceLandscapeMutex_;
std::mutex privacyBundleMapMutex_;
std::unordered_map<DisplayId, std::unordered_set<std::string>> privacyBundleMap_;

View File

@ -1402,6 +1402,8 @@ sptr<SceneSession> SceneSessionManager::CreateSceneSession(const SessionInfo& se
if (sceneSession != nullptr) {
sceneSession->SetSessionInfoPersistentId(sceneSession->GetPersistentId());
sceneSession->isKeyboardPanelEnabled_ = isKeyboardPanelEnabled_;
sceneSession->RegisterForceSplitListener(std::bind(&SceneSessionManager::GetAppForceLandscapeMode,
this, std::placeholders::_1));
}
return sceneSession;
}
@ -9274,4 +9276,30 @@ void SceneSessionManager::RegisterSecSurfaceInfoListener()
TLOGE(WmsLogTag::WMS_EVENT, "RegisterSecSurfaceInfoListener failed");
}
}
WSError SceneSessionManager::SetAppForceLandscapeMode(const std::string& bundleName, int32_t mode)
{
if (bundleName.empty()) {
WLOGFE("bundle name is empty");
return WSError::WS_ERROR_NULLPTR;
}
WLOGFD("set app force landscape mode, app: %{public}s, mode: %{public}d", bundleName.c_str(), mode);
std::unique_lock<std::shared_mutex> lock(appForceLandscapeMutex_);
appForceLandscapeMap_.emplace(bundleName, mode);
return WSError::WS_OK;
}
int32_t SceneSessionManager::GetAppForceLandscapeMode(const std::string& bundleName)
{
if (bundleName.empty()) {
WLOGFE("bundle name is empty");
return 0;
}
std::shared_lock<std::shared_mutex> lock(appForceLandscapeMutex_);
if (appForceLandscapeMap_.empty()
|| appForceLandscapeMap_.find(bundleName) == appForceLandscapeMap_.end()) {
return 0;
}
return appForceLandscapeMap_[bundleName];
}
} // namespace OHOS::Rosen

View File

@ -373,6 +373,8 @@ private:
{
return windowSystemConfig_.freeMultiWindowSupport_ && windowSystemConfig_.freeMultiWindowEnable_;
}
bool IsAppSupportForceSplit(const std::string& bundleName);
void SetForceSplitEnable(bool isForceSplit);
static std::recursive_mutex lifeCycleListenerMutex_;
static std::recursive_mutex windowChangeListenerMutex_;

View File

@ -59,6 +59,7 @@ constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowS
constexpr int32_t ANIMATION_TIME = 400;
constexpr int32_t FULL_CIRCLE_DEGREE = 360;
constexpr int32_t ONE_FOURTH_FULL_CIRCLE_DEGREE = 90;
constexpr int32_t FORCE_SPLIT_MODE = 5;
Ace::ContentInfoType GetAceContentInfoType(BackupAndRestoreType type)
{
@ -972,6 +973,11 @@ WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, nap
}
}
if (context_ != nullptr && WindowHelper::IsMainWindow(GetType())
&& IsAppSupportForceSplit(context_->GetBundleName())) {
SetForceSplitEnable(true);
}
uint32_t version = 0;
if ((context_ != nullptr) && (context_->GetApplicationInfo() != nullptr)) {
version = context_->GetApplicationInfo()->apiCompatibleVersion;
@ -3334,5 +3340,27 @@ void WindowSessionImpl::SetUiDvsyncSwitch(bool dvsyncSwitch)
vsyncStation_->SetUiDvsyncSwitch(dvsyncSwitch);
}
bool WindowSessionImpl::IsAppSupportForceSplit(const std::string& bundleName)
{
if (bundleName.empty()) {
return false;
}
if (IsWindowSessionInvalid()) {
TLOGE(WmsLogTag::DEFAULT, "HostSession is invalid");
return false;
}
return hostSession_->GetAppForceLandscapeMode(bundleName) == FORCE_SPLIT_MODE;
}
void WindowSessionImpl::SetForceSplitEnable(bool isForceSplit)
{
std::shared_ptr<Ace::UIContent> uiContent = GetUIContentSharedPtr();
if (uiContent == nullptr) {
WLOGFW("uiContent is null!");
return;
}
uiContent->SetForceSplitEnable(isForceSplit);
WLOGFI("set app force split success");
}
} // namespace Rosen
} // namespace OHOS