Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 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; |
Artur Satayev | ad9254c | 2019-12-10 17:47:54 +0000 | [diff] [blame] | 20 | import android.compat.annotation.UnsupportedAppUsage; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import 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 | */ |
| 49 | public class RemoteAnimationAdapter implements Parcelable { |
| 50 | |
| 51 | private final IRemoteAnimationRunner mRunner; |
| 52 | private final long mDuration; |
| 53 | private final long mStatusBarTransitionDelay; |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 54 | private final boolean mChangeNeedsSnapshot; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 55 | |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 56 | /** @see #getCallingPid */ |
| 57 | private int mCallingPid; |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 58 | private int mCallingUid; |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 59 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 60 | /** |
| 61 | * @param runner The interface that gets notified when we actually need to start the animation. |
| 62 | * @param duration The duration of the animation. |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 63 | * @param changeNeedsSnapshot For change transitions, whether this should create a snapshot by |
| 64 | * screenshotting the task. |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 65 | * @param statusBarTransitionDelay The desired delay for all visual animations in the |
| 66 | * status bar caused by this app animation in millis. |
| 67 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 68 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 69 | public RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration, |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 70 | long statusBarTransitionDelay, boolean changeNeedsSnapshot) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 71 | mRunner = runner; |
| 72 | mDuration = duration; |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 73 | mChangeNeedsSnapshot = changeNeedsSnapshot; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 74 | mStatusBarTransitionDelay = statusBarTransitionDelay; |
| 75 | } |
| 76 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 77 | @UnsupportedAppUsage |
| 78 | public RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration, |
| 79 | long statusBarTransitionDelay) { |
| 80 | this(runner, duration, statusBarTransitionDelay, false /* changeNeedsSnapshot */); |
| 81 | } |
| 82 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 83 | public RemoteAnimationAdapter(Parcel in) { |
| 84 | mRunner = IRemoteAnimationRunner.Stub.asInterface(in.readStrongBinder()); |
| 85 | mDuration = in.readLong(); |
| 86 | mStatusBarTransitionDelay = in.readLong(); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 87 | mChangeNeedsSnapshot = in.readBoolean(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | public IRemoteAnimationRunner getRunner() { |
| 91 | return mRunner; |
| 92 | } |
| 93 | |
| 94 | public long getDuration() { |
| 95 | return mDuration; |
| 96 | } |
| 97 | |
| 98 | public long getStatusBarTransitionDelay() { |
| 99 | return mStatusBarTransitionDelay; |
| 100 | } |
| 101 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 102 | public boolean getChangeNeedsSnapshot() { |
| 103 | return mChangeNeedsSnapshot; |
| 104 | } |
| 105 | |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 106 | /** |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 107 | * To be called by system_server to keep track which pid and uid is running this animation. |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 108 | */ |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 109 | public void setCallingPidUid(int pid, int uid) { |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 110 | mCallingPid = pid; |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 111 | mCallingUid = uid; |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @return The pid of the process running the animation. |
| 116 | */ |
| 117 | public int getCallingPid() { |
| 118 | return mCallingPid; |
| 119 | } |
| 120 | |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 121 | /** |
| 122 | * @return The uid of the process running the animation. |
| 123 | */ |
| 124 | public int getCallingUid() { |
| 125 | return mCallingUid; |
| 126 | } |
| 127 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 128 | @Override |
| 129 | public int describeContents() { |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void writeToParcel(Parcel dest, int flags) { |
| 135 | dest.writeStrongInterface(mRunner); |
| 136 | dest.writeLong(mDuration); |
| 137 | dest.writeLong(mStatusBarTransitionDelay); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 138 | dest.writeBoolean(mChangeNeedsSnapshot); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 141 | public static final @android.annotation.NonNull Creator<RemoteAnimationAdapter> CREATOR |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 142 | = new Creator<RemoteAnimationAdapter>() { |
| 143 | public RemoteAnimationAdapter createFromParcel(Parcel in) { |
| 144 | return new RemoteAnimationAdapter(in); |
| 145 | } |
| 146 | |
| 147 | public RemoteAnimationAdapter[] newArray(int size) { |
| 148 | return new RemoteAnimationAdapter[size]; |
| 149 | } |
| 150 | }; |
| 151 | } |