• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 package com.android.server.wm;
17 
18 import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_REMOTE_ANIMATIONS;
19 import static com.android.server.wm.AnimationAdapterProto.REMOTE;
20 import static com.android.server.wm.RemoteAnimationAdapterWrapperProto.TARGET;
21 import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_WINDOW_ANIMATION;
22 
23 import android.graphics.Point;
24 import android.os.SystemClock;
25 import android.util.proto.ProtoOutputStream;
26 import android.view.RemoteAnimationTarget;
27 import android.view.SurfaceControl;
28 
29 import com.android.internal.protolog.common.ProtoLog;
30 import com.android.server.wm.SurfaceAnimator.AnimationType;
31 
32 import java.io.PrintWriter;
33 import java.util.ArrayList;
34 import java.util.function.Consumer;
35 
36 /**
37  * An animation adapter for wallpaper windows.
38  */
39 class WallpaperAnimationAdapter implements AnimationAdapter {
40     private static final String TAG = "WallpaperAnimationAdapter";
41 
42     private final WallpaperWindowToken mWallpaperToken;
43     private SurfaceControl mCapturedLeash;
44     private SurfaceAnimator.OnAnimationFinishedCallback mCapturedLeashFinishCallback;
45     private @AnimationType int mLastAnimationType;
46 
47     private long mDurationHint;
48     private long mStatusBarTransitionDelay;
49 
50     private Consumer<WallpaperAnimationAdapter> mAnimationCanceledRunnable;
51     private RemoteAnimationTarget mTarget;
52 
WallpaperAnimationAdapter(WallpaperWindowToken wallpaperToken, long durationHint, long statusBarTransitionDelay, Consumer<WallpaperAnimationAdapter> animationCanceledRunnable)53     WallpaperAnimationAdapter(WallpaperWindowToken wallpaperToken,
54             long durationHint, long statusBarTransitionDelay,
55             Consumer<WallpaperAnimationAdapter> animationCanceledRunnable) {
56         mWallpaperToken = wallpaperToken;
57         mDurationHint = durationHint;
58         mStatusBarTransitionDelay = statusBarTransitionDelay;
59         mAnimationCanceledRunnable = animationCanceledRunnable;
60     }
61 
62     /**
63      * Creates and starts remote animations for all the visible wallpaper windows.
64      *
65      * @return RemoteAnimationTarget[] targets for all the visible wallpaper windows
66      */
startWallpaperAnimations(WindowManagerService service, long durationHint, long statusBarTransitionDelay, Consumer<WallpaperAnimationAdapter> animationCanceledRunnable, ArrayList<WallpaperAnimationAdapter> adaptersOut)67     public static RemoteAnimationTarget[] startWallpaperAnimations(WindowManagerService service,
68             long durationHint, long statusBarTransitionDelay,
69             Consumer<WallpaperAnimationAdapter> animationCanceledRunnable,
70             ArrayList<WallpaperAnimationAdapter> adaptersOut) {
71         final ArrayList<RemoteAnimationTarget> targets = new ArrayList<>();
72         service.mRoot.forAllWallpaperWindows(wallpaperWindow -> {
73             if (!wallpaperWindow.getDisplayContent().mWallpaperController.isWallpaperVisible()) {
74                 ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "\tNot visible=%s", wallpaperWindow);
75                 return;
76             }
77 
78             ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "\tvisible=%s", wallpaperWindow);
79             final WallpaperAnimationAdapter wallpaperAdapter = new WallpaperAnimationAdapter(
80                     wallpaperWindow, durationHint, statusBarTransitionDelay,
81                     animationCanceledRunnable);
82             wallpaperWindow.startAnimation(wallpaperWindow.getPendingTransaction(),
83                     wallpaperAdapter, false /* hidden */, ANIMATION_TYPE_WINDOW_ANIMATION);
84             targets.add(wallpaperAdapter.createRemoteAnimationTarget());
85             adaptersOut.add(wallpaperAdapter);
86         });
87         return targets.toArray(new RemoteAnimationTarget[targets.size()]);
88     }
89 
90     /**
91      * Create a remote animation target for this animation adapter.
92      */
createRemoteAnimationTarget()93     RemoteAnimationTarget createRemoteAnimationTarget() {
94         mTarget = new RemoteAnimationTarget(-1, -1, getLeash(), false, null, null,
95                 mWallpaperToken.getPrefixOrderIndex(), new Point(), null, null,
96                 mWallpaperToken.getWindowConfiguration(), true, null, null, null);
97         return mTarget;
98     }
99 
100     /**
101      * @return the leash for this animation (only valid after the wallpaper window surface animation
102      * has started).
103      */
getLeash()104     SurfaceControl getLeash() {
105         return mCapturedLeash;
106     }
107 
108     /**
109      * @return the callback to call to clean up when the animation has finished.
110      */
getLeashFinishedCallback()111     SurfaceAnimator.OnAnimationFinishedCallback getLeashFinishedCallback() {
112         return mCapturedLeashFinishCallback;
113     }
114 
115     /**
116      * @return the type of animation.
117      */
getLastAnimationType()118     @AnimationType int getLastAnimationType() {
119         return mLastAnimationType;
120     }
121 
122     /**
123      * @return the wallpaper window
124      */
getToken()125     WallpaperWindowToken getToken() {
126         return mWallpaperToken;
127     }
128 
129     @Override
getShowWallpaper()130     public boolean getShowWallpaper() {
131         // Not used
132         return false;
133     }
134 
135     @Override
startAnimation(SurfaceControl animationLeash, SurfaceControl.Transaction t, @AnimationType int type, SurfaceAnimator.OnAnimationFinishedCallback finishCallback)136     public void startAnimation(SurfaceControl animationLeash, SurfaceControl.Transaction t,
137             @AnimationType int type, SurfaceAnimator.OnAnimationFinishedCallback finishCallback) {
138         ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "startAnimation");
139 
140         // Restore z-layering until client has a chance to modify it.
141         t.setLayer(animationLeash, mWallpaperToken.getPrefixOrderIndex());
142         mCapturedLeash = animationLeash;
143         mCapturedLeashFinishCallback = finishCallback;
144         mLastAnimationType = type;
145     }
146 
147     @Override
onAnimationCancelled(SurfaceControl animationLeash)148     public void onAnimationCancelled(SurfaceControl animationLeash) {
149         ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "onAnimationCancelled");
150         mAnimationCanceledRunnable.accept(this);
151     }
152 
153     @Override
getDurationHint()154     public long getDurationHint() {
155         return mDurationHint;
156     }
157 
158     @Override
getStatusBarTransitionsStartTime()159     public long getStatusBarTransitionsStartTime() {
160         return SystemClock.uptimeMillis() + mStatusBarTransitionDelay;
161     }
162 
163     @Override
dump(PrintWriter pw, String prefix)164     public void dump(PrintWriter pw, String prefix) {
165         pw.print(prefix);
166         pw.print("token=");
167         pw.println(mWallpaperToken);
168         if (mTarget != null) {
169             pw.print(prefix);
170             pw.println("Target:");
171             mTarget.dump(pw, prefix + "  ");
172         } else {
173             pw.print(prefix);
174             pw.println("Target: null");
175         }
176     }
177 
178     @Override
dumpDebug(ProtoOutputStream proto)179     public void dumpDebug(ProtoOutputStream proto) {
180         final long token = proto.start(REMOTE);
181         if (mTarget != null) {
182             mTarget.dumpDebug(proto, TARGET);
183         }
184         proto.end(token);
185     }
186 }
187