1 /*
2 * Copyright (c) 2022-2025 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
16 #ifdef SUPPORT_SCREEN
17 #include "window_manager_service_handler_stub.h"
18
19 #include "ability_manager_errors.h"
20 #include "hilog_tag_wrapper.h"
21 #include "pixel_map.h"
22
23 namespace OHOS {
24 namespace AAFwk {
WindowManagerServiceHandlerStub()25 WindowManagerServiceHandlerStub::WindowManagerServiceHandlerStub()
26 {
27 Init();
28 }
29
~WindowManagerServiceHandlerStub()30 WindowManagerServiceHandlerStub::~WindowManagerServiceHandlerStub() {}
31
Init()32 void WindowManagerServiceHandlerStub::Init() {}
33
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int WindowManagerServiceHandlerStub::OnRemoteRequest(
35 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
36 {
37 if (data.ReadInterfaceToken() != IWindowManagerServiceHandler::GetDescriptor()) {
38 TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid descriptor");
39 return ERR_AAFWK_PARCEL_FAIL;
40 }
41
42 switch (code) {
43 case ON_NOTIFY_WINDOW_TRANSITION:
44 return NotifyWindowTransitionInner(data, reply);
45 case ON_GET_FOCUS_ABILITY:
46 return GetFocusWindowInner(data, reply);
47 case ON_COLD_STARTING_WINDOW:
48 return StartingWindowCold(data, reply);
49 case ON_HOT_STARTING_WINDOW:
50 return StartingWindowHot(data, reply);
51 case ON_CANCEL_STARTING_WINDOW:
52 return CancelStartingWindowInner(data, reply);
53 case ON_NOTIFY_ANIMATION_ABILITY_DIED:
54 return NotifyAnimationAbilityDiedInner(data, reply);
55 case ON_MOVE_MISSINONS_TO_FOREGROUND:
56 return MoveMissionsToForegroundInner(data, reply);
57 case ON_MOVE_MISSIONS_TO_BACKGROUND:
58 return MoveMissionsToBackgroundInner(data, reply);
59 }
60
61 TAG_LOGW(AAFwkTag::ABILITYMGR, "default case to be checked");
62 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
63 }
64
NotifyWindowTransitionInner(MessageParcel & data,MessageParcel & reply)65 int WindowManagerServiceHandlerStub::NotifyWindowTransitionInner(MessageParcel &data, MessageParcel &reply)
66 {
67 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
68 sptr<AbilityTransitionInfo> fromInfo(data.ReadParcelable<AbilityTransitionInfo>());
69 if (!fromInfo) {
70 TAG_LOGE(AAFwkTag::ABILITYMGR, "read fromInfo failed");
71 return ERR_AAFWK_PARCEL_FAIL;
72 }
73 sptr<AbilityTransitionInfo> toInfo(data.ReadParcelable<AbilityTransitionInfo>());
74 if (!toInfo) {
75 TAG_LOGE(AAFwkTag::ABILITYMGR, "read toInfo failed");
76 return ERR_AAFWK_PARCEL_FAIL;
77 }
78 bool animaEnabled = data.ReadBool();
79 NotifyWindowTransition(fromInfo, toInfo, animaEnabled);
80 reply.WriteBool(animaEnabled);
81 return ERR_OK;
82 }
83
GetFocusWindowInner(MessageParcel & data,MessageParcel & reply)84 int WindowManagerServiceHandlerStub::GetFocusWindowInner(MessageParcel &data, MessageParcel &reply)
85 {
86 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
87 sptr<IRemoteObject> abilityToken = nullptr;
88 int32_t ret = GetFocusWindow(abilityToken);
89 if (!reply.WriteInt32(ret)) {
90 TAG_LOGE(AAFwkTag::ABILITYMGR, "write result failed");
91 return ERR_AAFWK_PARCEL_FAIL;
92 }
93 if (abilityToken) {
94 if (!reply.WriteBool(true)) {
95 TAG_LOGE(AAFwkTag::ABILITYMGR, "write true failed");
96 return ERR_AAFWK_PARCEL_FAIL;
97 }
98 if (!reply.WriteRemoteObject(abilityToken)) {
99 TAG_LOGE(AAFwkTag::ABILITYMGR, "write abilityToken failed");
100 return ERR_AAFWK_PARCEL_FAIL;
101 }
102 } else {
103 if (!reply.WriteBool(false)) {
104 TAG_LOGE(AAFwkTag::ABILITYMGR, "write false failed");
105 return ERR_AAFWK_PARCEL_FAIL;
106 }
107 }
108 return ERR_OK;
109 }
110
StartingWindowCold(MessageParcel & data,MessageParcel & reply)111 int WindowManagerServiceHandlerStub::StartingWindowCold(MessageParcel &data, MessageParcel &reply)
112 {
113 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
114 sptr<AbilityTransitionInfo> info(data.ReadParcelable<AbilityTransitionInfo>());
115 if (!info) {
116 TAG_LOGE(AAFwkTag::ABILITYMGR, "read info failed");
117 return ERR_AAFWK_PARCEL_FAIL;
118 }
119 std::shared_ptr<Media::PixelMap> pixelMap
120 = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
121 if (pixelMap == nullptr) {
122 TAG_LOGE(AAFwkTag::ABILITYMGR, "read pixelMap failed");
123 return ERR_AAFWK_PARCEL_FAIL;
124 }
125 auto bgColor = data.ReadUint32();
126 StartingWindow(info, pixelMap, bgColor);
127 return ERR_OK;
128 }
129
StartingWindowHot(MessageParcel & data,MessageParcel & reply)130 int WindowManagerServiceHandlerStub::StartingWindowHot(MessageParcel &data, MessageParcel &reply)
131 {
132 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
133 sptr<AbilityTransitionInfo> info(data.ReadParcelable<AbilityTransitionInfo>());
134 if (!info) {
135 TAG_LOGE(AAFwkTag::ABILITYMGR, "read info failed");
136 return ERR_AAFWK_PARCEL_FAIL;
137 }
138 std::shared_ptr<Media::PixelMap> pixelMap
139 = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
140 if (pixelMap == nullptr) {
141 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to read pixelMap");
142 return ERR_AAFWK_PARCEL_FAIL;
143 }
144 StartingWindow(info, pixelMap);
145 return ERR_OK;
146 }
147
CancelStartingWindowInner(MessageParcel & data,MessageParcel & reply)148 int WindowManagerServiceHandlerStub::CancelStartingWindowInner(MessageParcel &data, MessageParcel &reply)
149 {
150 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
151 sptr<IRemoteObject> abilityToken = nullptr;
152 if (data.ReadBool()) {
153 TAG_LOGD(AAFwkTag::ABILITYMGR, "valid abilityToken");
154 abilityToken = data.ReadRemoteObject();
155 }
156 CancelStartingWindow(abilityToken);
157 return ERR_OK;
158 }
159
NotifyAnimationAbilityDiedInner(MessageParcel & data,MessageParcel & reply)160 int WindowManagerServiceHandlerStub::NotifyAnimationAbilityDiedInner(MessageParcel &data, MessageParcel &reply)
161 {
162 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
163 sptr<AbilityTransitionInfo> info(data.ReadParcelable<AbilityTransitionInfo>());
164 if (!info) {
165 TAG_LOGE(AAFwkTag::ABILITYMGR, "read info failed");
166 return ERR_AAFWK_PARCEL_FAIL;
167 }
168 NotifyAnimationAbilityDied(info);
169 return ERR_OK;
170 }
171
MoveMissionsToForegroundInner(MessageParcel & data,MessageParcel & reply)172 int WindowManagerServiceHandlerStub::MoveMissionsToForegroundInner(MessageParcel &data, MessageParcel &reply)
173 {
174 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
175 std::vector<int32_t> missionIds;
176 data.ReadInt32Vector(&missionIds);
177 int32_t topMissionId = data.ReadInt32();
178 auto errCode = MoveMissionsToForeground(missionIds, topMissionId);
179 reply.WriteInt32(errCode);
180 return errCode;
181 }
182
MoveMissionsToBackgroundInner(MessageParcel & data,MessageParcel & reply)183 int WindowManagerServiceHandlerStub::MoveMissionsToBackgroundInner(MessageParcel &data, MessageParcel &reply)
184 {
185 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
186 std::vector<int32_t> missionIds;
187 std::vector<int32_t> result;
188 data.ReadInt32Vector(&missionIds);
189 auto errCode = MoveMissionsToBackground(missionIds, result);
190 reply.WriteInt32Vector(result);
191 return errCode;
192 }
193
194 } // namespace AAFwk
195 } // namespace OHOS
196 #endif
197