blob: 6f5a85d210af67b1e5514d9d2dd72f7512694deb [file] [log] [blame]
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001/*
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
17package android.view;
18
Mathew Inwooda570dee2018-08-17 14:56:00 +010019import android.annotation.UnsupportedAppUsage;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010020import android.app.ActivityOptions;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010021import android.os.Parcel;
22import android.os.Parcelable;
23
24/**
25 * Object that describes how to run a remote animation.
26 * <p>
27 * A remote animation lets another app control the entire app transition. It does so by
28 * <ul>
29 * <li>using {@link ActivityOptions#makeRemoteAnimation}</li>
30 * <li>using {@link IWindowManager#overridePendingAppTransitionRemote}</li>
31 * </ul>
32 * to register a {@link RemoteAnimationAdapter} that describes how the animation should be run:
33 * Along some meta-data, this object contains a callback that gets invoked from window manager when
34 * the transition is ready to be started.
35 * <p>
36 * Window manager supplies a list of {@link RemoteAnimationTarget}s into the callback. Each target
37 * contains information about the activity that is animating as well as
38 * {@link RemoteAnimationTarget#leash}. The controlling app can modify the leash like any other
39 * {@link SurfaceControl}, including the possibility to synchronize updating the leash's surface
40 * properties with a frame to be drawn using
41 * {@link SurfaceControl.Transaction#deferTransactionUntil}.
42 * <p>
43 * When the animation is done, the controlling app can invoke
44 * {@link IRemoteAnimationFinishedCallback} that gets supplied into
45 * {@link IRemoteAnimationRunner#onStartAnimation}
46 *
47 * @hide
48 */
49public class RemoteAnimationAdapter implements Parcelable {
50
51 private final IRemoteAnimationRunner mRunner;
52 private final long mDuration;
53 private final long mStatusBarTransitionDelay;
Evan Rosky966759f2019-01-15 10:33:58 -080054 private final boolean mChangeNeedsSnapshot;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010055
Jorim Jaggibc2aabe2018-03-08 17:27:43 +010056 /** @see #getCallingPid */
57 private int mCallingPid;
58
Jorim Jaggi33a701a2017-12-01 14:58:18 +010059 /**
60 * @param runner The interface that gets notified when we actually need to start the animation.
61 * @param duration The duration of the animation.
Evan Rosky966759f2019-01-15 10:33:58 -080062 * @param changeNeedsSnapshot For change transitions, whether this should create a snapshot by
63 * screenshotting the task.
Jorim Jaggi33a701a2017-12-01 14:58:18 +010064 * @param statusBarTransitionDelay The desired delay for all visual animations in the
65 * status bar caused by this app animation in millis.
66 */
Mathew Inwooda570dee2018-08-17 14:56:00 +010067 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +010068 public RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration,
Evan Rosky966759f2019-01-15 10:33:58 -080069 long statusBarTransitionDelay, boolean changeNeedsSnapshot) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +010070 mRunner = runner;
71 mDuration = duration;
Evan Rosky966759f2019-01-15 10:33:58 -080072 mChangeNeedsSnapshot = changeNeedsSnapshot;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010073 mStatusBarTransitionDelay = statusBarTransitionDelay;
74 }
75
Evan Rosky966759f2019-01-15 10:33:58 -080076 @UnsupportedAppUsage
77 public RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration,
78 long statusBarTransitionDelay) {
79 this(runner, duration, statusBarTransitionDelay, false /* changeNeedsSnapshot */);
80 }
81
Jorim Jaggi33a701a2017-12-01 14:58:18 +010082 public RemoteAnimationAdapter(Parcel in) {
83 mRunner = IRemoteAnimationRunner.Stub.asInterface(in.readStrongBinder());
84 mDuration = in.readLong();
85 mStatusBarTransitionDelay = in.readLong();
Evan Rosky966759f2019-01-15 10:33:58 -080086 mChangeNeedsSnapshot = in.readBoolean();
Jorim Jaggi33a701a2017-12-01 14:58:18 +010087 }
88
89 public IRemoteAnimationRunner getRunner() {
90 return mRunner;
91 }
92
93 public long getDuration() {
94 return mDuration;
95 }
96
97 public long getStatusBarTransitionDelay() {
98 return mStatusBarTransitionDelay;
99 }
100
Evan Rosky966759f2019-01-15 10:33:58 -0800101 public boolean getChangeNeedsSnapshot() {
102 return mChangeNeedsSnapshot;
103 }
104
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100105 /**
106 * To be called by system_server to keep track which pid is running this animation.
107 */
108 public void setCallingPid(int pid) {
109 mCallingPid = pid;
110 }
111
112 /**
113 * @return The pid of the process running the animation.
114 */
115 public int getCallingPid() {
116 return mCallingPid;
117 }
118
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100119 @Override
120 public int describeContents() {
121 return 0;
122 }
123
124 @Override
125 public void writeToParcel(Parcel dest, int flags) {
126 dest.writeStrongInterface(mRunner);
127 dest.writeLong(mDuration);
128 dest.writeLong(mStatusBarTransitionDelay);
Evan Rosky966759f2019-01-15 10:33:58 -0800129 dest.writeBoolean(mChangeNeedsSnapshot);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100130 }
131
132 public static final Creator<RemoteAnimationAdapter> CREATOR
133 = new Creator<RemoteAnimationAdapter>() {
134 public RemoteAnimationAdapter createFromParcel(Parcel in) {
135 return new RemoteAnimationAdapter(in);
136 }
137
138 public RemoteAnimationAdapter[] newArray(int size) {
139 return new RemoteAnimationAdapter[size];
140 }
141 };
142}