• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 android.view;
18 
19 import android.app.ActivityOptions;
20 import android.app.IApplicationThread;
21 import android.compat.annotation.UnsupportedAppUsage;
22 import android.os.Build;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 /**
27  * Object that describes how to run a remote animation.
28  * <p>
29  * A remote animation lets another app control the entire app transition. It does so by
30  * <ul>
31  *     <li>using {@link ActivityOptions#makeRemoteAnimation}</li>
32  *     <li>using {@link IWindowManager#overridePendingAppTransitionRemote}</li>
33  * </ul>
34  * to register a {@link RemoteAnimationAdapter} that describes how the animation should be run:
35  * Along some meta-data, this object contains a callback that gets invoked from window manager when
36  * the transition is ready to be started.
37  * <p>
38  * Window manager supplies a list of {@link RemoteAnimationTarget}s into the callback. Each target
39  * contains information about the activity that is animating as well as
40  * {@link RemoteAnimationTarget#leash}. The controlling app can modify the leash like any other
41  * {@link SurfaceControl}, including the possibility to synchronize updating the leash's surface
42  * properties with a frame to be drawn using
43  * {@link SurfaceControl.Transaction#deferTransactionUntil}.
44  * <p>
45  * When the animation is done, the controlling app can invoke
46  * {@link IRemoteAnimationFinishedCallback} that gets supplied into
47  * {@link IRemoteAnimationRunner#onStartAnimation}
48  *
49  * @hide
50  */
51 public class RemoteAnimationAdapter implements Parcelable {
52 
53     private final IRemoteAnimationRunner mRunner;
54     private final long mDuration;
55     private final long mStatusBarTransitionDelay;
56     private final boolean mChangeNeedsSnapshot;
57 
58     /** @see #getCallingPid */
59     private int mCallingPid;
60     private int mCallingUid;
61 
62     /** @see #getCallingApplication */
63     private IApplicationThread mCallingApplication;
64 
65     /**
66      * @param runner The interface that gets notified when we actually need to start the animation.
67      * @param duration The duration of the animation.
68      * @param changeNeedsSnapshot For change transitions, whether this should create a snapshot by
69      *                            screenshotting the task.
70      * @param statusBarTransitionDelay The desired delay for all visual animations in the
71      *        status bar caused by this app animation in millis.
72      */
73     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration, long statusBarTransitionDelay, boolean changeNeedsSnapshot)74     public RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration,
75             long statusBarTransitionDelay, boolean changeNeedsSnapshot) {
76         mRunner = runner;
77         mDuration = duration;
78         mChangeNeedsSnapshot = changeNeedsSnapshot;
79         mStatusBarTransitionDelay = statusBarTransitionDelay;
80     }
81 
82     @UnsupportedAppUsage
RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration, long statusBarTransitionDelay)83     public RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration,
84             long statusBarTransitionDelay) {
85         this(runner, duration, statusBarTransitionDelay, false /* changeNeedsSnapshot */);
86     }
87 
88     @UnsupportedAppUsage
RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration, long statusBarTransitionDelay, IApplicationThread callingApplication)89     public RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration,
90             long statusBarTransitionDelay, IApplicationThread callingApplication) {
91         this(runner, duration, statusBarTransitionDelay, false /* changeNeedsSnapshot */);
92         mCallingApplication = callingApplication;
93     }
94 
RemoteAnimationAdapter(Parcel in)95     public RemoteAnimationAdapter(Parcel in) {
96         mRunner = IRemoteAnimationRunner.Stub.asInterface(in.readStrongBinder());
97         mDuration = in.readLong();
98         mStatusBarTransitionDelay = in.readLong();
99         mChangeNeedsSnapshot = in.readBoolean();
100         mCallingApplication = IApplicationThread.Stub.asInterface(in.readStrongBinder());
101     }
102 
getRunner()103     public IRemoteAnimationRunner getRunner() {
104         return mRunner;
105     }
106 
getDuration()107     public long getDuration() {
108         return mDuration;
109     }
110 
getStatusBarTransitionDelay()111     public long getStatusBarTransitionDelay() {
112         return mStatusBarTransitionDelay;
113     }
114 
getChangeNeedsSnapshot()115     public boolean getChangeNeedsSnapshot() {
116         return mChangeNeedsSnapshot;
117     }
118 
119     /**
120      * To be called by system_server to keep track which pid and uid is running this animation.
121      */
setCallingPidUid(int pid, int uid)122     public void setCallingPidUid(int pid, int uid) {
123         mCallingPid = pid;
124         mCallingUid = uid;
125     }
126 
127     /**
128      * @return The pid of the process running the animation.
129      */
getCallingPid()130     public int getCallingPid() {
131         return mCallingPid;
132     }
133 
134     /**
135      * @return The uid of the process running the animation.
136      */
getCallingUid()137     public int getCallingUid() {
138         return mCallingUid;
139     }
140 
141     /**
142      * Gets the ApplicationThread that will run the animation. Instead it is intended to pass the
143      * calling information among client processes (eg. shell + launcher) through one-way binder
144      * calls (where binder itself doesn't track calling information).
145      */
getCallingApplication()146     public IApplicationThread getCallingApplication() {
147         return mCallingApplication;
148     }
149 
150     @Override
describeContents()151     public int describeContents() {
152         return 0;
153     }
154 
155     @Override
writeToParcel(Parcel dest, int flags)156     public void writeToParcel(Parcel dest, int flags) {
157         dest.writeStrongInterface(mRunner);
158         dest.writeLong(mDuration);
159         dest.writeLong(mStatusBarTransitionDelay);
160         dest.writeBoolean(mChangeNeedsSnapshot);
161         dest.writeStrongInterface(mCallingApplication);
162     }
163 
164     public static final @android.annotation.NonNull Creator<RemoteAnimationAdapter> CREATOR
165             = new Creator<RemoteAnimationAdapter>() {
166         public RemoteAnimationAdapter createFromParcel(Parcel in) {
167             return new RemoteAnimationAdapter(in);
168         }
169 
170         public RemoteAnimationAdapter[] newArray(int size) {
171             return new RemoteAnimationAdapter[size];
172         }
173     };
174 }
175