• 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 #include "rs_window_animation_stub.h"
17 
18 #include "rs_iwindow_animation_finished_callback.h"
19 #include "rs_window_animation_log.h"
20 #include "rs_window_animation_target.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 static constexpr int MAX_FLOATING_WINDOW_NUMBER = 100;
26 static constexpr int MAX_WINDOW_NUMBER = 100;
27 }
28 const std::map<uint32_t, WindowAnimationStubFunc> RSWindowAnimationStub::stubFuncMap_{
29     std::make_pair(RSIWindowAnimationController::ON_START_APP, &RSWindowAnimationStub::StartApp),
30     std::make_pair(RSIWindowAnimationController::ON_APP_TRANSITION, &RSWindowAnimationStub::AppTransition),
31     std::make_pair(RSIWindowAnimationController::ON_APP_BACK_TRANSITION, &RSWindowAnimationStub::AppBackTransition),
32     std::make_pair(RSIWindowAnimationController::ON_MINIMIZE_WINDOW, &RSWindowAnimationStub::MinimizeWindow),
33     std::make_pair(RSIWindowAnimationController::ON_MINIMIZE_ALLWINDOW, &RSWindowAnimationStub::MinimizeAllWindow),
34     std::make_pair(RSIWindowAnimationController::ON_CLOSE_WINDOW, &RSWindowAnimationStub::CloseWindow),
35     std::make_pair(RSIWindowAnimationController::ON_SCREEN_UNLOCK, &RSWindowAnimationStub::ScreenUnlock),
36     std::make_pair(RSIWindowAnimationController::ON_WINDOW_ANIMATION_TARGETS_UPDATE,
37         &RSWindowAnimationStub::WindowAnimationTargetsUpdate),
38     std::make_pair(RSIWindowAnimationController::ON_WALLPAPER_UPDATE, &RSWindowAnimationStub::WallpaperUpdate)
39 };
40 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41 int RSWindowAnimationStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
42     MessageParcel& reply, MessageOption &option)
43 {
44     WALOGD("Window animation on remote request!");
45     if (data.ReadInterfaceToken() != GetDescriptor()) {
46         WALOGE("Failed to check interface token!");
47         return ERR_INVALID_STATE;
48     }
49 
50     const auto func = stubFuncMap_.find(code);
51     if (func == stubFuncMap_.end()) {
52         WALOGE("Failed to find function handler!");
53         return ERR_UNKNOWN_TRANSACTION;
54     }
55 
56     return (this->*(func->second))(data, reply);
57 }
58 
StartApp(MessageParcel & data,MessageParcel & reply)59 int RSWindowAnimationStub::StartApp(MessageParcel& data, MessageParcel& reply)
60 {
61     WALOGD("Window animation start app!");
62     StartingAppType type = static_cast<StartingAppType>(data.ReadInt32());
63     sptr<RSWindowAnimationTarget> startingWindowTarget(data.ReadParcelable<RSWindowAnimationTarget>());
64     if (startingWindowTarget == nullptr) {
65         WALOGE("Failed to read starting window target!");
66         return ERR_INVALID_DATA;
67     }
68 
69     sptr<IRemoteObject> finishcallbackObject = data.ReadRemoteObject();
70     sptr<RSIWindowAnimationFinishedCallback> finishedCallback =
71         iface_cast<RSIWindowAnimationFinishedCallback>(finishcallbackObject);
72     if (finishedCallback == nullptr) {
73         WALOGE("Failed to read animation finished callback!");
74         return ERR_INVALID_DATA;
75     }
76 
77     OnStartApp(type, startingWindowTarget, finishedCallback);
78     return ERR_NONE;
79 }
80 
AppTransition(MessageParcel & data,MessageParcel & reply)81 int RSWindowAnimationStub::AppTransition(MessageParcel& data, MessageParcel& reply)
82 {
83     WALOGD("Window animation transition!");
84     sptr<RSWindowAnimationTarget> fromWindowTarget(data.ReadParcelable<RSWindowAnimationTarget>());
85     if (fromWindowTarget == nullptr) {
86         WALOGE("Failed to read animation target from!");
87         return ERR_INVALID_DATA;
88     }
89 
90     sptr<RSWindowAnimationTarget> toWindowTarget(data.ReadParcelable<RSWindowAnimationTarget>());
91     if (toWindowTarget == nullptr) {
92         WALOGE("Failed to read animation target to!");
93         return ERR_INVALID_DATA;
94     }
95 
96     sptr<IRemoteObject> finishcallbackObject = data.ReadRemoteObject();
97     sptr<RSIWindowAnimationFinishedCallback> finishedCallback =
98         iface_cast<RSIWindowAnimationFinishedCallback>(finishcallbackObject);
99     if (finishedCallback == nullptr) {
100         WALOGE("Failed to read animation finished callback!");
101         return ERR_INVALID_DATA;
102     }
103 
104     OnAppTransition(fromWindowTarget, toWindowTarget, finishedCallback);
105     return ERR_NONE;
106 }
107 
AppBackTransition(MessageParcel & data,MessageParcel & reply)108 int RSWindowAnimationStub::AppBackTransition(MessageParcel& data, MessageParcel& reply)
109 {
110     WALOGD("Window animation back transition!");
111     sptr<RSWindowAnimationTarget> fromWindowTarget(data.ReadParcelable<RSWindowAnimationTarget>());
112     if (fromWindowTarget == nullptr) {
113         WALOGE("Failed to read animation target from!");
114         return ERR_INVALID_DATA;
115     }
116 
117     sptr<RSWindowAnimationTarget> toWindowTarget(data.ReadParcelable<RSWindowAnimationTarget>());
118     if (toWindowTarget == nullptr) {
119         WALOGE("Failed to read animation target to!");
120         return ERR_INVALID_DATA;
121     }
122 
123     sptr<IRemoteObject> finishcallbackObject = data.ReadRemoteObject();
124     sptr<RSIWindowAnimationFinishedCallback> finishedCallback =
125         iface_cast<RSIWindowAnimationFinishedCallback>(finishcallbackObject);
126     if (finishedCallback == nullptr) {
127         WALOGE("Failed to read animation finished callback!");
128         return ERR_INVALID_DATA;
129     }
130 
131     OnAppBackTransition(fromWindowTarget, toWindowTarget, finishedCallback);
132     return ERR_NONE;
133 }
134 
MinimizeWindow(MessageParcel & data,MessageParcel & reply)135 int RSWindowAnimationStub::MinimizeWindow(MessageParcel& data, MessageParcel& reply)
136 {
137     WALOGD("Window animation minimize window!");
138     sptr<RSWindowAnimationTarget> minimizingWindow(data.ReadParcelable<RSWindowAnimationTarget>());
139     if (minimizingWindow == nullptr) {
140         WALOGE("Failed to read minimizing window!");
141         return ERR_INVALID_DATA;
142     }
143 
144     sptr<IRemoteObject> finishcallbackObject = data.ReadRemoteObject();
145     sptr<RSIWindowAnimationFinishedCallback> finishedCallback =
146         iface_cast<RSIWindowAnimationFinishedCallback>(finishcallbackObject);
147     if (finishedCallback == nullptr) {
148         WALOGE("Failed to read animation finished callback!");
149         return ERR_INVALID_DATA;
150     }
151 
152     OnMinimizeWindow(minimizingWindow, finishedCallback);
153     return ERR_NONE;
154 }
155 
MinimizeAllWindow(MessageParcel & data,MessageParcel & reply)156 int RSWindowAnimationStub::MinimizeAllWindow(MessageParcel& data, MessageParcel& reply)
157 {
158     WALOGD("Window animation minimize all window!");
159     size_t dataCount = data.ReadUint32();
160     if (dataCount > MAX_WINDOW_NUMBER) {
161         WALOGE("Windows are too much!");
162         return ERR_INVALID_DATA;
163     }
164     std::vector<sptr<RSWindowAnimationTarget>> minimizingWindows;
165     for (size_t i = 0; i < dataCount; i++) {
166         sptr<RSWindowAnimationTarget> minimizingWindow(data.ReadParcelable<RSWindowAnimationTarget>());
167         if (minimizingWindow == nullptr) {
168             WALOGE("Failed to read minimizing window!");
169             return ERR_INVALID_DATA;
170         }
171         minimizingWindows.push_back(minimizingWindow);
172     }
173 
174     sptr<IRemoteObject> finishcallbackObject = data.ReadRemoteObject();
175     sptr<RSIWindowAnimationFinishedCallback> finishedCallback =
176         iface_cast<RSIWindowAnimationFinishedCallback>(finishcallbackObject);
177     if (finishedCallback == nullptr) {
178         WALOGE("Failed to read animation finished callback!");
179         return ERR_INVALID_DATA;
180     }
181 
182     OnMinimizeAllWindow(minimizingWindows, finishedCallback);
183     return ERR_NONE;
184 }
185 
CloseWindow(MessageParcel & data,MessageParcel & reply)186 int RSWindowAnimationStub::CloseWindow(MessageParcel& data, MessageParcel& reply)
187 {
188     WALOGD("Window animation close window!");
189     sptr<RSWindowAnimationTarget> closingWindow(data.ReadParcelable<RSWindowAnimationTarget>());
190     if (closingWindow == nullptr) {
191         WALOGE("Failed to read closing window!");
192         return ERR_INVALID_DATA;
193     }
194 
195     sptr<IRemoteObject> finishcallbackObject = data.ReadRemoteObject();
196     sptr<RSIWindowAnimationFinishedCallback> finishedCallback =
197         iface_cast<RSIWindowAnimationFinishedCallback>(finishcallbackObject);
198     if (finishedCallback == nullptr) {
199         WALOGE("Failed to read animation finished callback!");
200         return ERR_INVALID_DATA;
201     }
202 
203     OnCloseWindow(closingWindow, finishedCallback);
204     return ERR_NONE;
205 }
206 
ScreenUnlock(MessageParcel & data,MessageParcel & reply)207 int RSWindowAnimationStub::ScreenUnlock(MessageParcel& data, MessageParcel& reply)
208 {
209     WALOGD("Window animation screen unlock!");
210     sptr<IRemoteObject> finishcallbackObject = data.ReadRemoteObject();
211     sptr<RSIWindowAnimationFinishedCallback> finishedCallback =
212         iface_cast<RSIWindowAnimationFinishedCallback>(finishcallbackObject);
213     if (finishedCallback == nullptr) {
214         WALOGE("Failed to read animation finished callback!");
215         return ERR_INVALID_DATA;
216     }
217 
218     OnScreenUnlock(finishedCallback);
219     return ERR_NONE;
220 }
221 
WindowAnimationTargetsUpdate(MessageParcel & data,MessageParcel & reply)222 int RSWindowAnimationStub::WindowAnimationTargetsUpdate(MessageParcel& data, MessageParcel& reply)
223 {
224     WALOGD("Window animation targets update!");
225     sptr<RSWindowAnimationTarget> fullScreenWindowTarget = nullptr;
226     if (data.ReadBool()) {
227         fullScreenWindowTarget = data.ReadParcelable<RSWindowAnimationTarget>();
228     }
229 
230     size_t floatWindowSize = data.ReadUint32();
231     if (floatWindowSize > MAX_FLOATING_WINDOW_NUMBER) {
232         WALOGE("Floating windows are too much!");
233         return ERR_INVALID_DATA;
234     }
235     std::vector<sptr<RSWindowAnimationTarget>> floatingWindowTargets;
236     for (size_t i = 0; i < floatWindowSize; i++) {
237         sptr<RSWindowAnimationTarget> floatingWindowTarget(data.ReadParcelable<RSWindowAnimationTarget>());
238         if (floatingWindowTarget == nullptr) {
239             WALOGE("Failed to read floating window animation window!");
240             return ERR_INVALID_DATA;
241         }
242         floatingWindowTargets.push_back(floatingWindowTarget);
243     }
244 
245     OnWindowAnimationTargetsUpdate(fullScreenWindowTarget, floatingWindowTargets);
246     return ERR_NONE;
247 }
248 
WallpaperUpdate(MessageParcel & data,MessageParcel & reply)249 int RSWindowAnimationStub::WallpaperUpdate(MessageParcel& data, MessageParcel& reply)
250 {
251     WALOGD("Window animation wallpaper update!");
252     sptr<RSWindowAnimationTarget> wallpaperTarget(data.ReadParcelable<RSWindowAnimationTarget>());
253     OnWallpaperUpdate(wallpaperTarget);
254     return ERR_NONE;
255 }
256 } // namespace Rosen
257 } // namespace OHOS
258