1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.server.wm;
18 
19 import android.annotation.NonNull;
20 import android.util.proto.ProtoOutputStream;
21 import android.view.SurfaceControl;
22 import android.view.SurfaceControl.Transaction;
23 import android.view.animation.Animation;
24 
25 import com.android.server.wm.SurfaceAnimator.AnimationType;
26 import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
27 
28 import java.io.PrintWriter;
29 
30 /**
31  * Interface that describes an animation and bridges the animation start to the component
32  * responsible for running the animation.
33  */
34 interface AnimationAdapter {
35 
36     long STATUS_BAR_TRANSITION_DURATION = 120L;
37 
38     /**
39      * @return Whether we should show the wallpaper during the animation.
40      * @see Animation#getShowWallpaper()
41      */
getShowWallpaper()42     boolean getShowWallpaper();
43 
44     /**
45      * @return Whether we should show a background behind the animating windows.
46      * @see Animation#getShowBackdrop()
47      */
getShowBackground()48     default boolean getShowBackground() {
49         return false;
50     }
51 
52     /**
53      * @return The background color to use during an animation if getShowBackground returns true.
54      * @see Animation#getBackdropColor()
55      */
getBackgroundColor()56     default int getBackgroundColor() {
57         return 0;
58     }
59 
60     /**
61      * Requests to start the animation.
62      *
63      * @param animationLeash The surface to run the animation on. See {@link SurfaceAnimator} for an
64      *                       overview of the mechanism. This surface needs to be released by the
65      *                       component running the animation after {@code finishCallback} has been
66      *                       invoked, or after the animation was cancelled.
67      * @param t The Transaction to apply the initial frame of the animation.
68      * @param type The type of the animation.
69      * @param finishCallback The callback to be invoked when the animation has finished.
70      */
startAnimation(SurfaceControl animationLeash, Transaction t, @AnimationType int type, @NonNull OnAnimationFinishedCallback finishCallback)71     void startAnimation(SurfaceControl animationLeash, Transaction t, @AnimationType int type,
72             @NonNull OnAnimationFinishedCallback finishCallback);
73 
74     /**
75      * Called when the animation that was started with {@link #startAnimation} was cancelled by the
76      * window manager.
77      *
78      * @param animationLeash The leash passed to {@link #startAnimation}.
79      */
onAnimationCancelled(SurfaceControl animationLeash)80     void onAnimationCancelled(SurfaceControl animationLeash);
81 
82     /**
83      * @return The approximate duration of the animation, in milliseconds.
84      */
getDurationHint()85     long getDurationHint();
86 
87     /**
88      * If this animation is run as an app opening animation, this calculates the start time for all
89      * status bar transitions that happen as part of the app opening animation, which will be
90      * forwarded to SystemUI.
91      *
92      * @return the desired start time of the status bar transition, in uptime millis
93      */
getStatusBarTransitionsStartTime()94     long getStatusBarTransitionsStartTime();
95 
dump(PrintWriter pw, String prefix)96     void dump(PrintWriter pw, String prefix);
97 
dumpDebug(ProtoOutputStream proto, long fieldId)98     default void dumpDebug(ProtoOutputStream proto, long fieldId) {
99         final long token = proto.start(fieldId);
100         dumpDebug(proto);
101         proto.end(token);
102     }
103 
dumpDebug(ProtoOutputStream proto)104     void dumpDebug(ProtoOutputStream proto);
105 
106     /**
107      * Gets called when the animation is about to finish and gives the client the opportunity to
108      * defer finishing the animation, i.e. it keeps the leash around until the client calls
109      * endDeferFinishCallback.
110      * <p>
111      * This has the same effect as
112      * {@link com.android.server.wm.SurfaceAnimator.Animatable#shouldDeferAnimationFinish(Runnable)}
113      * . The later will be evaluated first and has precedence over this method if it returns true,
114      * which means that if the {@link com.android.server.wm.SurfaceAnimator.Animatable} requests to
115      * defer its finish, this method won't be called so this adapter will never have access to the
116      * finish callback. On the other hand, if the
117      * {@link com.android.server.wm.SurfaceAnimator.Animatable}, doesn't request to defer, this
118      * {@link AnimationAdapter} is responsible for ending the animation.
119      *
120      * @param endDeferFinishCallback The callback to call when defer finishing should be ended.
121      * @return Whether the client would like to defer the animation finish.
122      */
shouldDeferAnimationFinish(Runnable endDeferFinishCallback)123     default boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
124         return false;
125     }
126 }
127