mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-24 07:20:09 +00:00
新增状态通知接口
Signed-off-by: shulssins <yuanshusen@huawei.com>
This commit is contained in:
parent
4c518e6aac
commit
cc1dcedfc7
@ -39,6 +39,7 @@ const std::string ON_SCREEN_DENSITY_CHANGE = "screenDensityChange";
|
||||
const std::string ON_SCREEN_EXTEND_CHANGE = "screenExtendChange";
|
||||
const std::string ON_HOVER_STATUS_CHANGE_CALLBACK = "hoverStatusChange";
|
||||
const std::string ON_SCREEN_CAPTURE_NOTIFY = "screenCaptureNotify";
|
||||
const std::string ON_SUPER_FOLD_STATUS_CHANGE_CALLBACK = "superFoldStatusChange";
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
} // namespace
|
||||
|
||||
@ -725,4 +726,39 @@ void JsScreenSession::OnScreenCaptureNotify(ScreenId mainScreenId, int32_t uid,
|
||||
WLOGFE("OnScreenCaptureNotify: env is nullptr");
|
||||
}
|
||||
}
|
||||
|
||||
void JsScreenSession::OnSuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus)
|
||||
{
|
||||
const std::string callbackType = ON_SUPER_FOLD_STATUS_CHANGE_CALLBACK;
|
||||
WLOGD("Call js callback: %{public}s.", callbackType.c_str());
|
||||
if (mCallback_.count(callbackType) == 0) {
|
||||
WLOGFE("Callback %{public}s is unregistered!", callbackType.c_str());
|
||||
return;
|
||||
}
|
||||
auto jsCallbackRef = mCallback_[callbackType];
|
||||
auto asyncTask = [jsCallbackRef, callbackType, screenId, superFoldStatus, env = env_]() {
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "jsScreenSession::OnSuperFoldStatusChange");
|
||||
if (jsCallbackRef == nullptr) {
|
||||
WLOGFE("Call js callback failed, jsCallbackRef is null!");
|
||||
return;
|
||||
}
|
||||
auto method = jsCallbackRef->GetNapiValue();
|
||||
if (method == nullptr) {
|
||||
WLOGFE("Call js callback failed, method is null!");
|
||||
return;
|
||||
}
|
||||
napi_value id = CreateJsValue(env, static_cast<int64_t>(screenId));
|
||||
napi_value status = CreateJsValue(env, static_cast<int32_t>(superFoldStatus));
|
||||
napi_value argv[] = { id, status };
|
||||
napi_call_function(env, NapiGetUndefined(env), method, ArraySize(argv), argv, nullptr);
|
||||
};
|
||||
if (env_ != nullptr) {
|
||||
napi_status ret = napi_send_event(env_, asyncTask, napi_eprio_immediate);
|
||||
if (ret != napi_status::napi_ok) {
|
||||
WLOGFE("OnSuperFoldStatusChange: Failed to SendEvent.");
|
||||
}
|
||||
} else {
|
||||
WLOGFE("OnSuperFoldStatusChange: env is nullptr");
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -59,6 +59,7 @@ private:
|
||||
void OnScreenExtendChange(ScreenId mainScreenId, ScreenId extendScreenId) override;
|
||||
void OnHoverStatusChange(int32_t hoverStatus, ScreenId screenId) override;
|
||||
void OnScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override;
|
||||
void OnSuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus) override;
|
||||
|
||||
napi_env env_;
|
||||
sptr<ScreenSession> screenSession_;
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "screen_cutout_controller.h"
|
||||
#include "fold_screen_controller/fold_screen_controller.h"
|
||||
#include "fold_screen_controller/fold_screen_sensor_manager.h"
|
||||
#include "fold_screen_controller/super_fold_state_manager.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class RSInterfaces;
|
||||
@ -294,6 +295,7 @@ public:
|
||||
std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution() override;
|
||||
|
||||
void OnScreenExtendChange(ScreenId mainScreenId, ScreenId extendScreenId) override;
|
||||
void OnSuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus) override;
|
||||
void SetDefaultScreenId(ScreenId defaultId);
|
||||
sptr<IScreenSessionManagerClient> GetClientProxy();
|
||||
void NotifyCastWhenScreenConnectChange(bool isConnected);
|
||||
|
@ -151,6 +151,13 @@ void SuperFoldStateManager::HandleSuperFoldStatusChange(SuperFoldStatusChangeEve
|
||||
action();
|
||||
transferState(nextState);
|
||||
// notify
|
||||
auto screenSession = ScreenSessionManager::GetInstance().GetDefaultScreenSession();
|
||||
if (screenSession == nullptr) {
|
||||
TLOGE(WmsLogTag::DMS, "screen session is null!");
|
||||
return;
|
||||
}
|
||||
ScreenId screenId = screenSession->GetScreenId();
|
||||
ScreenSessionManager::GetInstance().OnSuperFoldStatusChange(screenId, curState_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6195,4 +6195,15 @@ sptr<DisplayInfo> ScreenSessionManager::GetPrimaryDisplayInfo()
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSessionManager::OnSuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus)
|
||||
{
|
||||
TLOGI(WmsLogTag::DMS, "screenId: %{public}" PRIu64 ", superFoldStatus: %{public}d", screenId,
|
||||
static_cast<uint32_t>(superFoldStatus));
|
||||
if (!clientProxy_) {
|
||||
TLOGI(WmsLogTag::DMS, "clientProxy_ is null");
|
||||
return;
|
||||
}
|
||||
clientProxy_->OnSuperFoldStatusChanged(screenId, superFoldStatus);
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -103,6 +103,7 @@ private:
|
||||
void OnScreenOrientationChanged(ScreenId screenId, float screenOrientation) override;
|
||||
void OnScreenRotationLockedChanged(ScreenId screenId, bool isLocked) override;
|
||||
void OnScreenExtendChanged(ScreenId mainScreenId, ScreenId extendScreenId) override;
|
||||
void OnSuperFoldStatusChanged(ScreenId screenId, SuperFoldStatus superFoldStatus) override;
|
||||
|
||||
void SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId) override;
|
||||
void ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override;
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
TRANS_ID_ON_SCREEN_EXTEND_CHANGED,
|
||||
TRANS_ID_ON_HOVER_STATUS_CHANGED,
|
||||
TRANS_ID_ON_SCREEN_CAPTURE_NOTIFY,
|
||||
TRANS_ID_ON_SUPER_FOLD_STATUS_CHANGED,
|
||||
};
|
||||
|
||||
virtual void SwitchUserCallback(std::vector<int32_t> oldScbPids, int32_t currentScbPid) = 0;
|
||||
@ -60,6 +61,7 @@ public:
|
||||
virtual void OnScreenOrientationChanged(ScreenId screenId, float screenOrientation) = 0;
|
||||
virtual void OnScreenRotationLockedChanged(ScreenId screenId, bool isLocked) = 0;
|
||||
virtual void OnScreenExtendChanged(ScreenId mainScreenId, ScreenId extendScreenId) = 0;
|
||||
virtual void OnSuperFoldStatusChanged(ScreenId screenId, SuperFoldStatus superFoldStatus) = 0;
|
||||
|
||||
virtual void OnDisplayStateChanged(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
|
||||
const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) = 0;
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
void SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio) override;
|
||||
void OnFoldStatusChangedReportUE(const std::vector<std::string>& screenFoldInfo) override;
|
||||
void ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override;
|
||||
void OnSuperFoldStatusChanged(ScreenId screenId, SuperFoldStatus superFoldStatus) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<ScreenSessionManagerClientProxy> delegator_;
|
||||
|
@ -52,6 +52,7 @@ private:
|
||||
int HandleOnScreenExtendChanged(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleOnHoverStatusChanged(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleScreenCaptureNotify(MessageParcel& data, MessageParcel& reply);
|
||||
int HandleOnSuperFoldStatusChanged(MessageParcel& data, MessageParcel& reply);
|
||||
|
||||
HandleScreenChangeMap HandleScreenChangeMap_ {};
|
||||
};
|
||||
|
@ -602,4 +602,16 @@ void ScreenSessionManagerClient::ScreenCaptureNotify(ScreenId mainScreenId, int3
|
||||
WLOGFI("capture screenId: %{public}" PRIu64", uid=%{public}d", mainScreenId, uid);
|
||||
screenSession->ScreenCaptureNotify(mainScreenId, uid, clientName);
|
||||
}
|
||||
|
||||
void ScreenSessionManagerClient::OnSuperFoldStatusChanged(ScreenId screenId, SuperFoldStatus superFoldStatus)
|
||||
{
|
||||
auto screenSession = GetScreenSession(screenId);
|
||||
if (!screenSession) {
|
||||
WLOGFE("screenSession is null");
|
||||
return;
|
||||
}
|
||||
WLOGI("screenId=%{public}" PRIu64 " superFoldStatus=%{public}d", screenId,
|
||||
static_cast<uint32_t>(superFoldStatus));
|
||||
screenSession->SuperFoldStatusChange(screenId, superFoldStatus);
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
@ -602,4 +602,34 @@ void ScreenSessionManagerClientProxy::ScreenCaptureNotify(ScreenId mainScreenId,
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSessionManagerClientProxy::OnSuperFoldStatusChanged(ScreenId screenId, SuperFoldStatus superFoldStatus)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGE("remote is nullptr");
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
|
||||
WLOGFE("Write screenId failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(superFoldStatus))) {
|
||||
WLOGFE("Write superFoldStatus failed");
|
||||
return;
|
||||
}
|
||||
if (remote->SendRequest(
|
||||
static_cast<uint32_t>(ScreenSessionManagerClientMessage::TRANS_ID_ON_SUPER_FOLD_STATUS_CHANGED),
|
||||
data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -100,6 +100,10 @@ void ScreenSessionManagerClientStub::InitScreenChangeMap()
|
||||
[this](MessageParcel& data, MessageParcel& reply) {
|
||||
return HandleScreenCaptureNotify(data, reply);
|
||||
};
|
||||
HandleScreenChangeMap_[ScreenSessionManagerClientMessage::TRANS_ID_ON_SUPER_FOLD_STATUS_CHANGED] =
|
||||
[this](MessageParcel& data, MessageParcel& reply) {
|
||||
return HandleOnSuperFoldStatusChanged(data, reply);
|
||||
};
|
||||
}
|
||||
|
||||
ScreenSessionManagerClientStub::ScreenSessionManagerClientStub()
|
||||
@ -315,4 +319,14 @@ int ScreenSessionManagerClientStub::HandleScreenCaptureNotify(MessageParcel& dat
|
||||
ScreenCaptureNotify(screenId, uid, clientName);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
int ScreenSessionManagerClientStub::HandleOnSuperFoldStatusChanged(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
auto screenId = static_cast<ScreenId>(data.ReadUint64());
|
||||
auto superFoldStatus = static_cast<SuperFoldStatus>(data.ReadUint32());
|
||||
WLOGI("super fold status screenId=%{public}" PRIu64", superFoldStatus=%{public}d.",
|
||||
screenId, static_cast<uint32_t>(superFoldStatus));
|
||||
OnSuperFoldStatusChanged(screenId, superFoldStatus);
|
||||
return ERR_NONE;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
virtual void OnScreenExtendChange(ScreenId mainScreenId, ScreenId extendScreenId) = 0;
|
||||
virtual void OnHoverStatusChange(int32_t hoverStatus, ScreenId extendScreenId) = 0;
|
||||
virtual void OnScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) = 0;
|
||||
virtual void OnSuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus) = 0;
|
||||
};
|
||||
|
||||
enum class MirrorScreenType : int32_t {
|
||||
@ -241,6 +242,7 @@ public:
|
||||
void SetPhysicalRotation(int rotation, FoldStatus foldStatus);
|
||||
void SetStartPosition(uint32_t startX, uint32_t startY);
|
||||
void ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName);
|
||||
void SuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus);
|
||||
|
||||
private:
|
||||
ScreenProperty property_;
|
||||
|
@ -1482,4 +1482,14 @@ void ScreenSession::ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, cons
|
||||
listener->OnScreenCaptureNotify(mainScreenId, uid, clientName);
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSession::SuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus)
|
||||
{
|
||||
for (auto& listener : screenChangeListenerList_) {
|
||||
if (!listener) {
|
||||
continue;
|
||||
}
|
||||
listener->OnSuperFoldStatusChange(screenId, superFoldStatus);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
void SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio) override {};
|
||||
void OnFoldStatusChangedReportUE(const std::vector<std::string>& screenFoldInfo) override {};
|
||||
void ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override {};
|
||||
void OnSuperFoldStatusChanged(ScreenId screenId, SuperFoldStatus superFoldStatus) override {};
|
||||
sptr<IRemoteObject> AsObject() override {return testPtr;};
|
||||
sptr<IRemoteObject> testPtr;
|
||||
};
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
void OnScreenExtendChange(ScreenId mainScreenId, ScreenId extendScreenId) override {}
|
||||
void OnHoverStatusChange(int32_t hoverStatus, ScreenId screenId) override {}
|
||||
void OnScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override {}
|
||||
void OnSuperFoldStatusChange(ScreenId screenId, SuperFoldStatus superFoldStatus) override {}
|
||||
};
|
||||
class ScreenSessionTest : public testing::Test {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user