1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "zidl/display_manager_agent_stub.h"
16
17 #include <vector>
18
19 #include "display_info.h"
20 #include "dm_common.h"
21 #include "marshalling_helper.h"
22 #include "screen_info.h"
23 #include "window_manager_hilog.h"
24
25 namespace OHOS::Rosen {
26 namespace {
27 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentStub"};
28 }
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
31 MessageParcel& reply, MessageOption& option)
32 {
33 WLOGFI("code:%{public}u", code);
34 if (data.ReadInterfaceToken() != GetDescriptor()) {
35 WLOGFE("InterfaceToken check failed");
36 return -1;
37 }
38 switch (code) {
39 case TRANS_ID_NOTIFY_DISPLAY_POWER_EVENT: {
40 DisplayPowerEvent event = static_cast<DisplayPowerEvent>(data.ReadUint32());
41 EventStatus status = static_cast<EventStatus>(data.ReadUint32());
42 NotifyDisplayPowerEvent(event, status);
43 break;
44 }
45 case TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED: {
46 DisplayState state = static_cast<DisplayState>(data.ReadUint32());
47 DisplayId id = static_cast<DisplayId>(data.ReadUint64());
48 NotifyDisplayStateChanged(id, state);
49 break;
50 }
51 case TRANS_ID_ON_SCREEN_CONNECT: {
52 sptr<ScreenInfo> screenInfo = data.ReadParcelable<ScreenInfo>();
53 OnScreenConnect(screenInfo);
54 break;
55 }
56 case TRANS_ID_ON_SCREEN_DISCONNECT: {
57 ScreenId screenId;
58 if (!data.ReadUint64(screenId)) {
59 WLOGFE("Read ScreenId failed");
60 return -1;
61 }
62 OnScreenDisconnect(screenId);
63 break;
64 }
65 case TRANS_ID_ON_SCREEN_CHANGED: {
66 sptr<ScreenInfo> screenInfo = data.ReadParcelable<ScreenInfo>();
67 uint32_t event;
68 if (!data.ReadUint32(event)) {
69 WLOGFE("Read ScreenChangeEvent failed");
70 return -1;
71 }
72 OnScreenChange(screenInfo, static_cast<ScreenChangeEvent>(event));
73 break;
74 }
75 case TRANS_ID_ON_SCREENGROUP_CHANGED: {
76 std::string trigger;
77 if (!data.ReadString(trigger)) {
78 WLOGFE("Read trigger failed");
79 return -1;
80 }
81 std::vector<sptr<ScreenInfo>> screenInfos;
82 if (!MarshallingHelper::UnmarshallingVectorParcelableObj<ScreenInfo>(data, screenInfos)) {
83 WLOGFE("Read ScreenInfo failed");
84 return -1;
85 }
86 uint32_t event;
87 if (!data.ReadUint32(event)) {
88 WLOGFE("Read ScreenChangeEvent failed");
89 return -1;
90 }
91 OnScreenGroupChange(trigger, screenInfos, static_cast<ScreenGroupChangeEvent>(event));
92 break;
93 }
94 case TRANS_ID_ON_DISPLAY_CONNECT: {
95 sptr<DisplayInfo> displayInfo = data.ReadParcelable<DisplayInfo>();
96 OnDisplayCreate(displayInfo);
97 break;
98 }
99 case TRANS_ID_ON_DISPLAY_DISCONNECT: {
100 DisplayId displayId;
101 if (!data.ReadUint64(displayId)) {
102 WLOGFE("Read DisplayId failed");
103 return -1;
104 }
105 OnDisplayDestroy(displayId);
106 break;
107 }
108 case TRANS_ID_ON_DISPLAY_CHANGED: {
109 sptr<DisplayInfo> displayInfo = data.ReadParcelable<DisplayInfo>();
110 uint32_t event;
111 if (!data.ReadUint32(event)) {
112 WLOGFE("Read DisplayChangeEvent failed");
113 return -1;
114 }
115 OnDisplayChange(displayInfo, static_cast<DisplayChangeEvent>(event));
116 break;
117 }
118 case TRANS_ID_ON_SCREEN_SHOT: {
119 sptr<ScreenshotInfo> snapshotInfo = data.ReadParcelable<ScreenshotInfo>();
120 OnScreenshot(snapshotInfo);
121 break;
122 }
123 default:
124 break;
125 }
126 return 0;
127 }
128 } // namespace OHOS::Rosen
129