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