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      * Requests to start the animation.
46      *
47      * @param animationLeash The surface to run the animation on. See {@link SurfaceAnimator} for an
48      *                       overview of the mechanism. This surface needs to be released by the
49      *                       component running the animation after {@code finishCallback} has been
50      *                       invoked, or after the animation was cancelled.
51      * @param t The Transaction to apply the initial frame of the animation.
52      * @param type The type of the animation.
53      * @param finishCallback The callback to be invoked when the animation has finished.
54      */
startAnimation(SurfaceControl animationLeash, Transaction t, @AnimationType int type, @NonNull OnAnimationFinishedCallback finishCallback)55     void startAnimation(SurfaceControl animationLeash, Transaction t, @AnimationType int type,
56             @NonNull OnAnimationFinishedCallback finishCallback);
57 
58     /**
59      * Called when the animation that was started with {@link #startAnimation} was cancelled by the
60      * window manager.
61      *
62      * @param animationLeash The leash passed to {@link #startAnimation}.
63      */
onAnimationCancelled(SurfaceControl animationLeash)64     void onAnimationCancelled(SurfaceControl animationLeash);
65 
66     /**
67      * @return The approximate duration of the animation, in milliseconds.
68      */
getDurationHint()69     long getDurationHint();
70 
71     /**
72      * If this animation is run as an app opening animation, this calculates the start time for all
73      * status bar transitions that happen as part of the app opening animation, which will be
74      * forwarded to SystemUI.
75      *
76      * @return the desired start time of the status bar transition, in uptime millis
77      */
getStatusBarTransitionsStartTime()78     long getStatusBarTransitionsStartTime();
79 
dump(PrintWriter pw, String prefix)80     void dump(PrintWriter pw, String prefix);
81 
dumpDebug(ProtoOutputStream proto, long fieldId)82     default void dumpDebug(ProtoOutputStream proto, long fieldId) {
83         final long token = proto.start(fieldId);
84         dumpDebug(proto);
85         proto.end(token);
86     }
87 
dumpDebug(ProtoOutputStream proto)88     void dumpDebug(ProtoOutputStream proto);
89 
90     /**
91      * Gets called when the animation is about to finish and gives the client the opportunity to
92      * defer finishing the animation, i.e. it keeps the leash around until the client calls
93      * endDeferFinishCallback.
94      * <p>
95      * This has the same effect as
96      * {@link com.android.server.wm.SurfaceAnimator.Animatable#shouldDeferAnimationFinish(Runnable)}
97      * . The later will be evaluated first and has precedence over this method if it returns true,
98      * which means that if the {@link com.android.server.wm.SurfaceAnimator.Animatable} requests to
99      * defer its finish, this method won't be called so this adapter will never have access to the
100      * finish callback. On the other hand, if the
101      * {@link com.android.server.wm.SurfaceAnimator.Animatable}, doesn't request to defer, this
102      * {@link AnimationAdapter} is responsible for ending the animation.
103      *
104      * @param endDeferFinishCallback The callback to call when defer finishing should be ended.
105      * @return Whether the client would like to defer the animation finish.
106      */
shouldDeferAnimationFinish(Runnable endDeferFinishCallback)107     default boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
108         return false;
109     }
110 }
111