1 /*
2  * Copyright (C) 2014 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.compat.annotation.UnsupportedAppUsage;
20 import android.os.Build;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * This class contains window animation frame statistics. For example, a window
26  * animation is usually performed when the application is transitioning from one
27  * activity to another. The frame statistics are a snapshot for the time interval
28  * from {@link #getStartTimeNano()} to {@link #getEndTimeNano()}.
29  * <p>
30  * The key idea is that in order to provide a smooth user experience the system should
31  * run window animations at a specific time interval obtained by calling {@link
32  * #getRefreshPeriodNano()}. If the system does not render a frame every refresh
33  * period the user will see irregular window transitions. The time when the frame was
34  * actually presented on the display by calling {@link #getFramePresentedTimeNano(int)}.
35  *
36  * @deprecated Use Shared
37  *             <a href="https://perfetto.dev/docs/data-sources/frametimeline">FrameTimeline</a>
38  *             jank metrics instead.
39  */
40 @Deprecated
41 public final class WindowAnimationFrameStats extends FrameStats implements Parcelable {
42     /**
43      * @hide
44      */
WindowAnimationFrameStats()45     public WindowAnimationFrameStats() {
46         /* do nothing */
47     }
48 
49     /**
50      * Initializes this isntance.
51      *
52      * @param refreshPeriodNano The display refresh period.
53      * @param framesPresentedTimeNano The presented frame times.
54      *
55      * @hide
56      */
57     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
init(long refreshPeriodNano, long[] framesPresentedTimeNano)58     public void init(long refreshPeriodNano, long[] framesPresentedTimeNano) {
59         mRefreshPeriodNano = refreshPeriodNano;
60         mFramesPresentedTimeNano = framesPresentedTimeNano;
61     }
62 
WindowAnimationFrameStats(Parcel parcel)63     private WindowAnimationFrameStats(Parcel parcel) {
64         mRefreshPeriodNano = parcel.readLong();
65         mFramesPresentedTimeNano = parcel.createLongArray();
66     }
67 
68     @Override
describeContents()69     public int describeContents() {
70         return 0;
71     }
72 
73     @Override
writeToParcel(Parcel parcel, int flags)74     public void writeToParcel(Parcel parcel, int flags) {
75         parcel.writeLong(mRefreshPeriodNano);
76         parcel.writeLongArray(mFramesPresentedTimeNano);
77     }
78 
79     @Override
toString()80     public String toString() {
81         StringBuilder builder = new StringBuilder();
82         builder.append("WindowAnimationFrameStats[");
83         builder.append("frameCount:" + getFrameCount());
84         builder.append(", fromTimeNano:" + getStartTimeNano());
85         builder.append(", toTimeNano:" + getEndTimeNano());
86         builder.append(']');
87         return builder.toString();
88     }
89 
90     public static final @android.annotation.NonNull Creator<WindowAnimationFrameStats> CREATOR =
91             new Creator<WindowAnimationFrameStats>() {
92                 @Override
93                 public WindowAnimationFrameStats createFromParcel(Parcel parcel) {
94                     return new WindowAnimationFrameStats(parcel);
95                 }
96 
97                 @Override
98                 public WindowAnimationFrameStats[] newArray(int size) {
99                     return new WindowAnimationFrameStats[size];
100                 }
101             };
102 }
103