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