* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <ipc_types.h>
#include <message_option.h>
#include <message_parcel.h>
#include "display_manager_lite_proxy.h"
namespace OHOS::Rosen {
ErrCode DisplayManagerLiteProxy::RegisterDisplayManagerAgent(
const sptr<IDisplayManagerAgent>& displayManagerAgent,
uint32_t type,
int32_t& dmError)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (displayManagerAgent == nullptr) {
TLOGE(WmsLogTag::DMS, "displayManagerAgent is nullptr!");
return ERR_INVALID_DATA;
}
if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
TLOGE(WmsLogTag::DMS, "Write [displayManagerAgent] failed!");
return ERR_INVALID_DATA;
}
if (!data.WriteUint32(type)) {
TLOGE(WmsLogTag::DMS, "Write [type] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_REGISTER_DISPLAY_MANAGER_AGENT), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_REGISTER_DISPLAY_MANAGER_AGENT));
return errCode;
}
if (!reply.ReadInt32(dmError)) {
TLOGE(WmsLogTag::DMS, "Read dmError failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::UnregisterDisplayManagerAgent(
const sptr<IDisplayManagerAgent>& displayManagerAgent,
uint32_t type,
int32_t& dmError)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (displayManagerAgent == nullptr) {
TLOGE(WmsLogTag::DMS, "displayManagerAgent is nullptr!");
return ERR_INVALID_DATA;
}
if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
TLOGE(WmsLogTag::DMS, "Write [displayManagerAgent] failed!");
return ERR_INVALID_DATA;
}
if (!data.WriteUint32(type)) {
TLOGE(WmsLogTag::DMS, "Write [type] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_UNREGISTER_DISPLAY_MANAGER_AGENT), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_UNREGISTER_DISPLAY_MANAGER_AGENT));
return errCode;
}
if (!reply.ReadInt32(dmError)) {
TLOGE(WmsLogTag::DMS, "Read dmError failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetDefaultDisplayInfo(
sptr<DisplayInfo>& displayInfo)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DEFAULT_DISPLAY_INFO), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DEFAULT_DISPLAY_INFO));
return errCode;
}
displayInfo = sptr<DisplayInfo>(reply.ReadParcelable<DisplayInfo>());
if (!displayInfo) {
TLOGE(WmsLogTag::DMS, "Read [DisplayInfo] failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetDisplayInfoById(
uint64_t displayId,
sptr<DisplayInfo>& displayInfo)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint64(displayId)) {
TLOGE(WmsLogTag::DMS, "Write [displayId] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DISPLAY_INFO_BY_ID), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DISPLAY_INFO_BY_ID));
return errCode;
}
displayInfo = sptr<DisplayInfo>(reply.ReadParcelable<DisplayInfo>());
if (!displayInfo) {
TLOGE(WmsLogTag::DMS, "Read [DisplayInfo] failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetCutoutInfo(
uint64_t displayId,
sptr<CutoutInfo>& cutoutInfo)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint64(displayId)) {
TLOGE(WmsLogTag::DMS, "Write [displayId] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_CUTOUT_INFO), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_CUTOUT_INFO));
return errCode;
}
cutoutInfo = sptr<CutoutInfo>(reply.ReadParcelable<CutoutInfo>());
if (!cutoutInfo) {
TLOGE(WmsLogTag::DMS, "Read [CutoutInfo] failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::WakeUpBegin(
uint32_t reason,
bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint32(reason)) {
TLOGE(WmsLogTag::DMS, "Write [reason] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_WAKE_UP_BEGIN), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_WAKE_UP_BEGIN));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::WakeUpEnd(
bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_WAKE_UP_END), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_WAKE_UP_END));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::SuspendBegin(
uint32_t reason,
bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint32(reason)) {
TLOGE(WmsLogTag::DMS, "Write [reason] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SUSPEND_BEGIN), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SUSPEND_BEGIN));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::SuspendEnd(
bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SUSPEND_END), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SUSPEND_END));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::SetSpecifiedScreenPower(
uint64_t screenId,
uint32_t screenPowerState,
uint32_t reason,
bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint64(screenId)) {
TLOGE(WmsLogTag::DMS, "Write [screenId] failed!");
return ERR_INVALID_DATA;
}
if (!data.WriteUint32(screenPowerState)) {
TLOGE(WmsLogTag::DMS, "Write [screenPowerState] failed!");
return ERR_INVALID_DATA;
}
if (!data.WriteUint32(reason)) {
TLOGE(WmsLogTag::DMS, "Write [reason] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SPECIFIED_SCREEN_POWER), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SPECIFIED_SCREEN_POWER));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::SetScreenPowerForAll(
uint32_t screenPowerState,
uint32_t reason,
bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint32(screenPowerState)) {
TLOGE(WmsLogTag::DMS, "Write [screenPowerState] failed!");
return ERR_INVALID_DATA;
}
if (!data.WriteUint32(reason)) {
TLOGE(WmsLogTag::DMS, "Write [reason] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SCREEN_POWER_FOR_ALL), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SCREEN_POWER_FOR_ALL));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetScreenPower(
uint64_t dmsScreenId,
uint32_t& screenPowerState)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint64(dmsScreenId)) {
TLOGE(WmsLogTag::DMS, "Write [dmsScreenId] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_POWER), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_POWER));
return errCode;
}
if (!reply.ReadUint32(screenPowerState)) {
TLOGE(WmsLogTag::DMS, "Read [screenPowerState] failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::SetDisplayState(
uint32_t displayState,
bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint32(displayState)) {
TLOGE(WmsLogTag::DMS, "Write [displayState] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_DISPLAY_STATE), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_DISPLAY_STATE));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetDisplayState(
uint64_t displayId,
uint32_t& displayState)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint64(displayId)) {
TLOGE(WmsLogTag::DMS, "Write [displayId] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DISPLAY_STATE), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_DISPLAY_STATE));
return errCode;
}
if (!reply.ReadUint32(displayState)) {
TLOGE(WmsLogTag::DMS, "Read [displayState] failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::TryToCancelScreenOff(
bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_TRY_TO_CANCEL_SCREEN_OFF), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_TRY_TO_CANCEL_SCREEN_OFF));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetAllDisplayIds(
std::vector<uint64_t>& displayIds)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_ALL_DISPLAY_IDS), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_ALL_DISPLAY_IDS));
return errCode;
}
int32_t displayIdsSize = 0;
if (!reply.ReadInt32(displayIdsSize)) {
TLOGE(WmsLogTag::DMS, "Read displayIdsSize failed!");
return ERR_INVALID_DATA;
}
if (displayIdsSize > static_cast<int32_t>(VECTOR_MAX_SIZE)) {
TLOGE(WmsLogTag::DMS, "The vector/array size exceeds the security limit!");
return ERR_INVALID_DATA;
}
for (int32_t i1 = 0; i1 < displayIdsSize; ++i1) {
uint64_t value1 = reply.ReadUint64();
displayIds.push_back(value1);
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetAllScreenInfos(
std::vector<sptr<ScreenInfo>>& screenInfos,
int32_t& dmError)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
if (auto result = remote->SendRequest(static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_ALL_SCREEN_INFOS),
data, reply, option); FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d", errCode);
return errCode;
}
int32_t screenInfosSize = 0;
if (!reply.ReadInt32(screenInfosSize)) {
TLOGE(WmsLogTag::DMS, "Read screenInfosSize failed!");
return ERR_INVALID_DATA;
}
if (screenInfosSize > static_cast<int32_t>(VECTOR_MAX_SIZE)) {
TLOGE(WmsLogTag::DMS, "The vector/array size exceeds the security limit!");
return ERR_INVALID_DATA;
}
for (int32_t i2 = 0; i2 < screenInfosSize; ++i2) {
sptr<ScreenInfo> value2 = sptr<ScreenInfo>(reply.ReadParcelable<ScreenInfo>());
if (!value2) {
TLOGE(WmsLogTag::DMS, "Read [ScreenInfo] failed!");
return ERR_INVALID_DATA;
}
screenInfos.push_back(value2);
}
if (!reply.ReadInt32(dmError)) {
TLOGE(WmsLogTag::DMS, "Read dmError failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetScreenInfoById(
uint64_t screenId,
sptr<ScreenInfo>& screenInfo)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint64(screenId)) {
TLOGE(WmsLogTag::DMS, "Write [screenId] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_INFO_BY_ID), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_INFO_BY_ID));
return errCode;
}
screenInfo = sptr<ScreenInfo>(reply.ReadParcelable<ScreenInfo>());
if (!screenInfo) {
TLOGE(WmsLogTag::DMS, "Read [ScreenInfo] failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::SetScreenBrightness(const DmsScreenBrightnessData& brightnessData, bool& isSucc)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteParcelable(&brightnessData)) {
TLOGE(WmsLogTag::DMS, "Write [brightnessData] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SCREEN_BRIGHTNESS), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_SET_SCREEN_BRIGHTNESS));
return errCode;
}
int32_t isSuccInt = 0;
if (!reply.ReadInt32(isSuccInt)) {
TLOGE(WmsLogTag::DMS, "Read [isSucc] failed!");
return ERR_INVALID_DATA;
}
isSucc = isSuccInt == 1;
return ERR_OK;
}
ErrCode DisplayManagerLiteProxy::GetScreenBrightness(
uint64_t screenId,
uint32_t& level)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
if (!data.WriteUint64(screenId)) {
TLOGE(WmsLogTag::DMS, "Write [screenId] failed!");
return ERR_INVALID_DATA;
}
sptr<IRemoteObject> remote = Remote();
if (!remote) {
TLOGE(WmsLogTag::DMS, "Remote is nullptr!");
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_BRIGHTNESS), data, reply, option);
if (FAILED(result)) {
TLOGE(WmsLogTag::DMS, "Send request failed!");
return result;
}
ErrCode errCode = ERR_OK;
if (!reply.ReadInt32(errCode)) {
TLOGE(WmsLogTag::DMS, "Read result failed!");
return ERR_INVALID_DATA;
}
if (FAILED(errCode)) {
TLOGE(WmsLogTag::DMS, "Result is: %{public}d, code is: %{public}d.", errCode,
static_cast<uint32_t>(IDisplayManagerIpcCode::COMMAND_GET_SCREEN_BRIGHTNESS));
return errCode;
}
if (!reply.ReadUint32(level)) {
TLOGE(WmsLogTag::DMS, "Read [level] failed!");
return ERR_INVALID_DATA;
}
return ERR_OK;
}
}