• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_proxy.h"
18 
19 #include "ability_manager_errors.h"
20 #include "hilog_tag_wrapper.h"
21 #include "parcel.h"
22 #include "pixel_map.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
WindowManagerServiceHandlerProxy(const sptr<IRemoteObject> & impl)26 WindowManagerServiceHandlerProxy::WindowManagerServiceHandlerProxy(const sptr<IRemoteObject> &impl)
27     : IRemoteProxy<IWindowManagerServiceHandler>(impl) {}
28 
NotifyWindowTransition(sptr<AbilityTransitionInfo> fromInfo,sptr<AbilityTransitionInfo> toInfo,bool & animaEnabled)29 void WindowManagerServiceHandlerProxy::NotifyWindowTransition(sptr<AbilityTransitionInfo> fromInfo,
30     sptr<AbilityTransitionInfo> toInfo, bool& animaEnabled)
31 {
32     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
33     MessageParcel data;
34     if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
35         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
36         return;
37     }
38     if (!data.WriteParcelable(fromInfo.GetRefPtr())) {
39         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write fromInfo failed");
40         return;
41     }
42     if (!data.WriteParcelable(toInfo.GetRefPtr())) {
43         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write toInfo failed");
44         return;
45     }
46     if (!data.WriteBool(animaEnabled)) {
47         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write animaEnabled failed");
48         return;
49     }
50     MessageParcel reply;
51     MessageOption option(MessageOption::TF_ASYNC);
52     int error = SendTransactCmd(WMSCmd::ON_NOTIFY_WINDOW_TRANSITION, data, reply, option);
53     if (error != ERR_OK) {
54         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
55     }
56     animaEnabled = reply.ReadBool();
57 }
58 
GetFocusWindow(sptr<IRemoteObject> & abilityToken)59 int32_t WindowManagerServiceHandlerProxy::GetFocusWindow(sptr<IRemoteObject>& abilityToken)
60 {
61     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
62     MessageParcel data;
63     if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
64         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
65         return ERR_AAFWK_PARCEL_FAIL;
66     }
67 
68     MessageParcel reply;
69     MessageOption option;
70     int error = SendTransactCmd(WMSCmd::ON_GET_FOCUS_ABILITY, data, reply, option);
71     if (error != ERR_OK) {
72         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
73         return ERR_AAFWK_PARCEL_FAIL;
74     }
75     auto ret = reply.ReadInt32();
76     if (ret == 0 && reply.ReadBool()) {
77         abilityToken = reply.ReadRemoteObject();
78     }
79     TAG_LOGD(AAFwkTag::ABILITYMGR, "ending");
80     return ret;
81 }
82 
StartingWindow(sptr<AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,uint32_t bgColor)83 void WindowManagerServiceHandlerProxy::StartingWindow(sptr<AbilityTransitionInfo> info,
84     std::shared_ptr<Media::PixelMap> pixelMap, uint32_t bgColor)
85 {
86     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
87     MessageParcel data;
88     if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
89         TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write token");
90         return;
91     }
92     if (!data.WriteParcelable(info.GetRefPtr())) {
93         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write info failed");
94         return;
95     }
96     if (!data.WriteParcelable(pixelMap.get())) {
97         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write pixelMap failed");
98         return;
99     }
100     if (!data.WriteUint32(bgColor)) {
101         TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write bgColor");
102         return;
103     }
104     MessageParcel reply;
105     MessageOption option(MessageOption::TF_ASYNC);
106     int error = SendTransactCmd(WMSCmd::ON_COLD_STARTING_WINDOW, data, reply, option);
107     if (error != ERR_OK) {
108         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
109     }
110 }
111 
StartingWindow(sptr<AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap)112 void WindowManagerServiceHandlerProxy::StartingWindow(sptr<AbilityTransitionInfo> info,
113     std::shared_ptr<Media::PixelMap> pixelMap)
114 {
115     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
116     MessageParcel data;
117     if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
118         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
119         return;
120     }
121     if (!data.WriteParcelable(info.GetRefPtr())) {
122         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write info failed");
123         return;
124     }
125     if (!data.WriteParcelable(pixelMap.get())) {
126         TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write pixelMap");
127         return;
128     }
129     MessageParcel reply;
130     MessageOption option(MessageOption::TF_ASYNC);
131     int error = SendTransactCmd(WMSCmd::ON_HOT_STARTING_WINDOW, data, reply, option);
132     if (error != ERR_OK) {
133         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
134     }
135 }
136 
CancelStartingWindow(sptr<IRemoteObject> abilityToken)137 void WindowManagerServiceHandlerProxy::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
138 {
139     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
140     MessageParcel data;
141     if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
142         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
143         return;
144     }
145     if (!abilityToken) {
146         if (!data.WriteBool(false)) {
147             TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write false");
148             return;
149         }
150     } else {
151         if (!data.WriteBool(true)) {
152             TAG_LOGE(AAFwkTag::ABILITYMGR, "Write true failed");
153             return;
154         }
155         if (!data.WriteRemoteObject(abilityToken)) {
156             TAG_LOGE(AAFwkTag::ABILITYMGR, "Write abilityToken failed");
157             return;
158         }
159     }
160     MessageParcel reply;
161     MessageOption option(MessageOption::TF_ASYNC);
162     int error = SendTransactCmd(WMSCmd::ON_CANCEL_STARTING_WINDOW, data, reply, option);
163     if (error != ERR_OK) {
164         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
165     }
166 }
167 
NotifyAnimationAbilityDied(sptr<AbilityTransitionInfo> info)168 void WindowManagerServiceHandlerProxy::NotifyAnimationAbilityDied(sptr<AbilityTransitionInfo> info)
169 {
170     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
171     MessageParcel data;
172     if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
173         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
174         return;
175     }
176     if (!data.WriteParcelable(info.GetRefPtr())) {
177         TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write info");
178         return;
179     }
180     MessageParcel reply;
181     MessageOption option(MessageOption::TF_ASYNC);
182     int error = SendTransactCmd(WMSCmd::ON_NOTIFY_ANIMATION_ABILITY_DIED, data, reply, option);
183     if (error != ERR_OK) {
184         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
185     }
186 }
187 
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)188 int32_t WindowManagerServiceHandlerProxy::MoveMissionsToForeground(const std::vector<int32_t>& missionIds,
189     int32_t topMissionId)
190 {
191     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
192     MessageParcel data;
193     MessageParcel reply;
194     MessageOption option;
195 
196     if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
197         TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed");
198         return ERR_AAFWK_PARCEL_FAIL;
199     }
200 
201     if (!data.WriteInt32Vector(missionIds)) {
202         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write missionIds failed");
203         return ERR_AAFWK_PARCEL_FAIL;
204     }
205 
206     if (!data.WriteInt32(topMissionId)) {
207         TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write TopMissionId");
208         return ERR_AAFWK_PARCEL_FAIL;
209     }
210 
211     int error = SendTransactCmd(WMSCmd::ON_MOVE_MISSINONS_TO_FOREGROUND, data, reply, option);
212     if (error != ERR_NONE) {
213         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendoRequest error: %{public}d", error);
214         return ERR_AAFWK_PARCEL_FAIL;
215     }
216     return reply.ReadInt32();
217 }
218 
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)219 int32_t WindowManagerServiceHandlerProxy::MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
220     std::vector<int32_t>& result)
221 {
222     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
223     MessageParcel data;
224     MessageParcel reply;
225     MessageOption option;
226 
227     if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
228         TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed");
229         return ERR_AAFWK_PARCEL_FAIL;
230     }
231 
232     if (!data.WriteInt32Vector(missionIds)) {
233         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write missionIds failed");
234         return ERR_AAFWK_PARCEL_FAIL;
235     }
236 
237     int error = SendTransactCmd(WMSCmd::ON_MOVE_MISSIONS_TO_BACKGROUND, data, reply, option);
238     if (error != ERR_NONE) {
239         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendoRequest error: %{public}d", error);
240         return ERR_AAFWK_PARCEL_FAIL;
241     }
242     if (!reply.ReadInt32Vector(&result)) {
243         TAG_LOGE(AAFwkTag::ABILITYMGR, "Read hide result failed");
244         return ERR_AAFWK_PARCEL_FAIL;
245     };
246     return reply.ReadInt32();
247 }
248 
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)249 int32_t WindowManagerServiceHandlerProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
250     MessageParcel &reply, MessageOption &option)
251 {
252     sptr<IRemoteObject> remote = Remote();
253     if (remote == nullptr) {
254         TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
255         return ERR_NULL_OBJECT;
256     }
257 
258     int32_t ret = remote->SendRequest(code, data, reply, option);
259     if (ret != ERR_OK) {
260         TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest failed. code: %{public}d, ret: %{public}d", code, ret);
261         return ret;
262     }
263     return ERR_OK;
264 }
265 }  // namespace AAFwk
266 }  // namespace OHOS
267 #endif
268