Add interfaces to control screen auto rotation lock

Signed-off-by: xpeng <pengxin33@huawei.com>
Change-Id: Ia7dbf130ae113464ce439032ab9d9189c01973f4
This commit is contained in:
xpeng
2022-06-21 19:42:54 +08:00
parent 83195c894b
commit ea3b7d2a5d
13 changed files with 217 additions and 1 deletions
+2
View File
@@ -89,6 +89,8 @@ public:
virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId);
virtual bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio);
virtual DMError SetScreenRotationLocked(bool isLocked);
virtual bool IsScreenRotationLocked();
// colorspace, gamut
virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts);
+14
View File
@@ -125,6 +125,20 @@ DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr<Su
return displayManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface);
}
DMError ScreenManagerAdapter::SetScreenRotationLocked(bool isLocked)
{
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
WLOGFI("DisplayManagerAdapter::SetScreenRotationLocked");
return displayManagerServiceProxy_->SetScreenRotationLocked(isLocked);
}
bool ScreenManagerAdapter::IsScreenRotationLocked()
{
INIT_PROXY_CHECK_RETURN(false);
WLOGFI("DisplayManagerAdapter::IsScreenRotationLocked");
return displayManagerServiceProxy_->IsScreenRotationLocked();
}
bool ScreenManagerAdapter::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
{
INIT_PROXY_CHECK_RETURN(false);
+10
View File
@@ -435,6 +435,16 @@ ScreenPowerState ScreenManager::GetScreenPower(ScreenId dmsScreenId)
return SingletonContainer::Get<ScreenManagerAdapter>().GetScreenPower(dmsScreenId);
}
DMError ScreenManager::SetScreenRotationLocked(bool isLocked)
{
return SingletonContainer::Get<ScreenManagerAdapter>().SetScreenRotationLocked(isLocked);
}
bool ScreenManager::IsScreenRotationLocked()
{
return SingletonContainer::Get<ScreenManagerAdapter>().IsScreenRotationLocked();
}
void ScreenManager::Impl::NotifyScreenConnect(sptr<ScreenInfo> info)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
@@ -743,6 +743,20 @@ HWTEST_F(ScreenManagerTest, ScreenManager17, Function | MediumTest | Level2)
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
}
}
/**
* @tc.name: ScreenManager18
* @tc.desc: Set screen rotation lock, and check whether screen rotation lock is Locked.
* @tc.type: FUNC
*/
HWTEST_F(ScreenManagerTest, ScreenManager18, Function | SmallTest | Level1)
{
bool originalLockStatus = ScreenManager::GetInstance().IsScreenRotationLocked();
ScreenManager::GetInstance().SetScreenRotationLocked(!originalLockStatus);
bool modifiedLockedStatus = ScreenManager::GetInstance().IsScreenRotationLocked();
ScreenManager::GetInstance().SetScreenRotationLocked(originalLockStatus);
ASSERT_EQ(!originalLockStatus, modifiedLockedStatus);
}
}
} // namespace Rosen
} // namespace OHOS
@@ -71,6 +71,8 @@ public:
TRANS_ID_SCREEN_GET_GAMUT_MAP,
TRANS_ID_SCREEN_SET_GAMUT_MAP,
TRANS_ID_SCREEN_SET_COLOR_TRANSFORM,
TRANS_ID_IS_SCREEN_ROTATION_LOCKED,
TRANS_ID_SET_SCREEN_ROTATION_LOCKED,
};
virtual sptr<DisplayInfo> GetDefaultDisplayInfo() = 0;
@@ -83,6 +85,8 @@ public:
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) = 0;
virtual bool SetOrientation(ScreenId screenId, Orientation orientation) = 0;
virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) = 0;
virtual DMError SetScreenRotationLocked(bool isLocked) = 0;
virtual bool IsScreenRotationLocked() = 0;
// colorspace, gamut
virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts) = 0;
+2
View File
@@ -41,6 +41,8 @@ public:
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) override;
bool SetOrientation(ScreenId screenId, Orientation orientation) override;
std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) override;
bool IsScreenRotationLocked() override;
DMError SetScreenRotationLocked(bool isLocked) override;
// colorspace, gamut
DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts) override;
@@ -50,6 +50,8 @@ public:
const sptr<IRemoteObject>& displayManagerAgent) override;
DMError DestroyVirtualScreen(ScreenId screenId) override;
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) override;
bool IsScreenRotationLocked() override;
DMError SetScreenRotationLocked(bool isLocked) override;
sptr<DisplayInfo> GetDefaultDisplayInfo() override;
sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
+51
View File
@@ -1005,4 +1005,55 @@ bool DisplayManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualP
}
return reply.ReadBool();
}
bool DisplayManagerProxy::IsScreenRotationLocked()
{
bool isLocked;
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("IsScreenRotationLocked: remote is nullptr");
return false;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("IsScreenRotationLocked: WriteInterfaceToken failed");
return false;
}
if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED),
data, reply, option) != ERR_NONE) {
WLOGFW("IsScreenRotationLocked: SendRequest failed");
return false;
}
isLocked = reply.ReadBool();
return isLocked;
}
DMError DisplayManagerProxy::SetScreenRotationLocked(bool isLocked)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("SetScreenRotationLocked: remote is null");
return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("SetScreenRotationLocked: WriteInterfaceToken failed");
return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
}
if (!data.WriteBool(isLocked)) {
WLOGFE("SetScreenRotationLocked: write isLocked failed");
return DMError::DM_ERROR_IPC_FAILED;
}
if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED),
data, reply, option) != ERR_NONE) {
WLOGFE("SetScreenRotationLocked: SendRequest failed");
return DMError::DM_ERROR_IPC_FAILED;
}
return static_cast<DMError>(reply.ReadInt32());
}
} // namespace OHOS::Rosen
+11
View File
@@ -559,4 +559,15 @@ float DisplayManagerService::GetCustomVirtualPixelRatio()
{
return DisplayManagerService::customVirtualPixelRatio_;
}
bool DisplayManagerService::IsScreenRotationLocked()
{
return ScreenRotationController::IsScreenRotationLocked();
}
DMError DisplayManagerService::SetScreenRotationLocked(bool isLocked)
{
ScreenRotationController::SetScreenRotationLocked(isLocked);
return DMError::DM_OK;
}
} // namespace OHOS::Rosen
+11
View File
@@ -313,6 +313,17 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
reply.WriteInt32(static_cast<int32_t>(ret));
break;
}
case DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED: {
bool isLocked = IsScreenRotationLocked();
reply.WriteBool(isLocked);
break;
}
case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED: {
bool isLocked = static_cast<bool>(data.ReadBool());
DMError ret = SetScreenRotationLocked(isLocked);
reply.WriteInt32(static_cast<int32_t>(ret));
break;
}
default:
WLOGFW("unknown transaction code");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
+2 -1
View File
@@ -55,7 +55,8 @@ public:
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason);
ScreenPowerState GetScreenPower(ScreenId screenId);
DMError SetScreenRotationLocked(bool isLocked);
bool IsScreenRotationLocked();
private:
ScreenManager();
~ScreenManager();
@@ -82,6 +82,21 @@ declare namespace screen {
function setVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallback<void>): void;
function setVirtualScreenSurface(screenId:number, surfaceId: string): Promise<void>;
/**
* Get screen rotation lock status.
* @since 9
*/
function isScreenRotationLocked(callback: AsyncCallback<boolean>): void;
function isScreenRotationLocked(): Promise<boolean>;
/**
* Set screen rotation lock status.
* @param isLocked Indicates whether the screen rotation switch is locked.
* @since 9
*/
function setScreenRotationLocked(isLocked:boolean, callback: AsyncCallback<void>): void;
function setScreenRotationLocked(isLocked:boolean): Promise<void>;
/**
* the parameter of making expand screen
* @syscap SystemCapability.WindowManager.WindowManager.Core
@@ -98,6 +98,18 @@ static NativeValue* SetVirtualScreenSurface(NativeEngine* engine, NativeCallback
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(engine, info);
return (me != nullptr) ? me->OnSetVirtualScreenSurface(*engine, *info) : nullptr;
}
static NativeValue* IsScreenRotationLocked(NativeEngine* engine, NativeCallbackInfo* info)
{
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(engine, info);
return (me != nullptr) ? me->OnIsScreenRotationLocked(*engine, *info) : nullptr;
}
static NativeValue* SetScreenRotationLocked(NativeEngine* engine, NativeCallbackInfo* info)
{
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(engine, info);
return (me != nullptr) ? me->OnSetScreenRotationLocked(*engine, *info) : nullptr;
}
private:
std::map<std::string, std::map<std::unique_ptr<NativeReference>, sptr<JsScreenListener>>> jsCbMap_;
std::mutex mtx_;
@@ -607,6 +619,71 @@ NativeValue* OnSetVirtualScreenSurface(NativeEngine& engine, NativeCallbackInfo&
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* OnIsScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("OnIsScreenRotationLocked is called");
DMError errCode = DMError::DM_OK;
if (info.argc > 1) {
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
errCode = DMError::DM_ERROR_INVALID_PARAM;
}
AsyncTask::CompleteCallback complete =
[this](NativeEngine& engine, AsyncTask& task, int32_t status) {
bool isLocked = SingletonContainer::Get<ScreenManager>().IsScreenRotationLocked();
task.Resolve(engine, CreateJsValue(engine, isLocked));
};
NativeValue* lastParam = nullptr;
if (info.argc == ARGC_ONE && info.argv[ARGC_ONE - 1]->TypeOf() == NATIVE_FUNCTION) {
lastParam = info.argv[ARGC_ONE - 1];
}
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* OnSetScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsScreenManager::OnSetScreenRotationLocked is called");
DMError errCode = DMError::DM_OK;
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
errCode = DMError::DM_ERROR_INVALID_PARAM;
}
bool isLocked = false;
if (errCode == DMError::DM_OK) {
NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
if (nativeVal == nullptr) {
WLOGFE("[NAPI]Failed to convert parameter to isLocked");
errCode = DMError::DM_ERROR_INVALID_PARAM;
} else {
isLocked = static_cast<bool>(*nativeVal);
}
}
AsyncTask::CompleteCallback complete =
[isLocked, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (errCode != DMError::DM_OK) {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
return;
}
DMError ret = SingletonContainer::Get<ScreenManager>().SetScreenRotationLocked(isLocked);
if (ret == DMError::DM_OK) {
task.Resolve(engine, engine.CreateUndefined());
} else {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret),
"JsScreenManager:SetScreenRotationLocked failed."));
}
WLOGFI("JsScreenManager::OnSetScreenRotationLocked success, ret = %{public}d", ret);
};
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
};
NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj)
@@ -635,6 +712,8 @@ NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj)
BindNativeFunction(*engine, *object, "createVirtualScreen", JsScreenManager::CreateVirtualScreen);
BindNativeFunction(*engine, *object, "destroyVirtualScreen", JsScreenManager::DestroyVirtualScreen);
BindNativeFunction(*engine, *object, "setVirtualScreenSurface", JsScreenManager::SetVirtualScreenSurface);
BindNativeFunction(*engine, *object, "setScreenRotationLocked", JsScreenManager::SetScreenRotationLocked);
BindNativeFunction(*engine, *object, "isScreenRotationLocked", JsScreenManager::IsScreenRotationLocked);
return engine->CreateUndefined();
}
} // namespace Rosen