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