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
17package android.view;
18
19import android.app.ActivityOptions;
20import android.os.IBinder;
21import 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;
54
55    /** @see #getCallingPid */
56    private int mCallingPid;
57
58    /**
59     * @param runner The interface that gets notified when we actually need to start the animation.
60     * @param duration The duration of the animation.
61     * @param statusBarTransitionDelay The desired delay for all visual animations in the
62     *        status bar caused by this app animation in millis.
63     */
64    public RemoteAnimationAdapter(IRemoteAnimationRunner runner, long duration,
65            long statusBarTransitionDelay) {
66        mRunner = runner;
67        mDuration = duration;
68        mStatusBarTransitionDelay = statusBarTransitionDelay;
69    }
70
71    public RemoteAnimationAdapter(Parcel in) {
72        mRunner = IRemoteAnimationRunner.Stub.asInterface(in.readStrongBinder());
73        mDuration = in.readLong();
74        mStatusBarTransitionDelay = in.readLong();
75    }
76
77    public IRemoteAnimationRunner getRunner() {
78        return mRunner;
79    }
80
81    public long getDuration() {
82        return mDuration;
83    }
84
85    public long getStatusBarTransitionDelay() {
86        return mStatusBarTransitionDelay;
87    }
88
89    /**
90     * To be called by system_server to keep track which pid is running this animation.
91     */
92    public void setCallingPid(int pid) {
93        mCallingPid = pid;
94    }
95
96    /**
97     * @return The pid of the process running the animation.
98     */
99    public int getCallingPid() {
100        return mCallingPid;
101    }
102
103    @Override
104    public int describeContents() {
105        return 0;
106    }
107
108    @Override
109    public void writeToParcel(Parcel dest, int flags) {
110        dest.writeStrongInterface(mRunner);
111        dest.writeLong(mDuration);
112        dest.writeLong(mStatusBarTransitionDelay);
113    }
114
115    public static final Creator<RemoteAnimationAdapter> CREATOR
116            = new Creator<RemoteAnimationAdapter>() {
117        public RemoteAnimationAdapter createFromParcel(Parcel in) {
118            return new RemoteAnimationAdapter(in);
119        }
120
121        public RemoteAnimationAdapter[] newArray(int size) {
122            return new RemoteAnimationAdapter[size];
123        }
124    };
125}
126