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.internal.annotations.VisibleForTesting;
26 import com.android.server.wm.SurfaceAnimator.AnimationType;
27 import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
28 
29 import java.io.PrintWriter;
30 
31 /**
32  * Interface that describes an animation and bridges the animation start to the component
33  * responsible for running the animation.
34  */
35 @VisibleForTesting
36 public interface AnimationAdapter {
37 
38     long STATUS_BAR_TRANSITION_DURATION = 120L;
39 
40     /**
41      * @return Whether we should show the wallpaper during the animation.
42      * @see Animation#getShowWallpaper()
43      */
getShowWallpaper()44     boolean getShowWallpaper();
45 
46     /**
47      * @return Whether we should show a background behind the animating windows.
48      * @see Animation#getShowBackdrop()
49      */
getShowBackground()50     default boolean getShowBackground() {
51         return false;
52     }
53 
54     /**
55      * @return The background color to use during an animation if getShowBackground returns true.
56      * @see Animation#getBackdropColor()
57      */
getBackgroundColor()58     default int getBackgroundColor() {
59         return 0;
60     }
61 
62     /**
63      * Requests to start the animation.
64      *
65      * @param animationLeash The surface to run the animation on. See {@link SurfaceAnimator} for an
66      *                       overview of the mechanism. This surface needs to be released by the
67      *                       component running the animation after {@code finishCallback} has been
68      *                       invoked, or after the animation was cancelled.
69      * @param t The Transaction to apply the initial frame of the animation.
70      * @param type The type of the animation.
71      * @param finishCallback The callback to be invoked when the animation has finished.
72      */
startAnimation(SurfaceControl animationLeash, Transaction t, @AnimationType int type, @NonNull OnAnimationFinishedCallback finishCallback)73     void startAnimation(SurfaceControl animationLeash, Transaction t, @AnimationType int type,
74             @NonNull OnAnimationFinishedCallback finishCallback);
75 
76     /**
77      * Called when the animation that was started with {@link #startAnimation} was cancelled by the
78      * window manager.
79      *
80      * @param animationLeash The leash passed to {@link #startAnimation}.
81      */
onAnimationCancelled(SurfaceControl animationLeash)82     void onAnimationCancelled(SurfaceControl animationLeash);
83 
84     /**
85      * @return The approximate duration of the animation, in milliseconds.
86      */
getDurationHint()87     long getDurationHint();
88 
89     /**
90      * If this animation is run as an app opening animation, this calculates the start time for all
91      * status bar transitions that happen as part of the app opening animation, which will be
92      * forwarded to SystemUI.
93      *
94      * @return the desired start time of the status bar transition, in uptime millis
95      */
getStatusBarTransitionsStartTime()96     long getStatusBarTransitionsStartTime();
97 
dump(PrintWriter pw, String prefix)98     void dump(PrintWriter pw, String prefix);
99 
dumpDebug(ProtoOutputStream proto, long fieldId)100     default void dumpDebug(ProtoOutputStream proto, long fieldId) {
101         final long token = proto.start(fieldId);
102         dumpDebug(proto);
103         proto.end(token);
104     }
105 
dumpDebug(ProtoOutputStream proto)106     void dumpDebug(ProtoOutputStream proto);
107 
108     /**
109      * Gets called when the animation is about to finish and gives the client the opportunity to
110      * defer finishing the animation, i.e. it keeps the leash around until the client calls
111      * endDeferFinishCallback.
112      * <p>
113      * This has the same effect as
114      * {@link com.android.server.wm.SurfaceAnimator.Animatable#shouldDeferAnimationFinish(Runnable)}
115      * . The later will be evaluated first and has precedence over this method if it returns true,
116      * which means that if the {@link com.android.server.wm.SurfaceAnimator.Animatable} requests to
117      * defer its finish, this method won't be called so this adapter will never have access to the
118      * finish callback. On the other hand, if the
119      * {@link com.android.server.wm.SurfaceAnimator.Animatable}, doesn't request to defer, this
120      * {@link AnimationAdapter} is responsible for ending the animation.
121      *
122      * @param endDeferFinishCallback The callback to call when defer finishing should be ended.
123      * @return Whether the client would like to defer the animation finish.
124      */
shouldDeferAnimationFinish(Runnable endDeferFinishCallback)125     default boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
126         return false;
127     }
128 }
129