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