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 public final class WindowAnimationFrameStats extends FrameStats implements Parcelable { 37 /** 38 * @hide 39 */ WindowAnimationFrameStats()40 public WindowAnimationFrameStats() { 41 /* do nothing */ 42 } 43 44 /** 45 * Initializes this isntance. 46 * 47 * @param refreshPeriodNano The display refresh period. 48 * @param framesPresentedTimeNano The presented frame times. 49 * 50 * @hide 51 */ 52 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) init(long refreshPeriodNano, long[] framesPresentedTimeNano)53 public void init(long refreshPeriodNano, long[] framesPresentedTimeNano) { 54 mRefreshPeriodNano = refreshPeriodNano; 55 mFramesPresentedTimeNano = framesPresentedTimeNano; 56 } 57 WindowAnimationFrameStats(Parcel parcel)58 private WindowAnimationFrameStats(Parcel parcel) { 59 mRefreshPeriodNano = parcel.readLong(); 60 mFramesPresentedTimeNano = parcel.createLongArray(); 61 } 62 63 @Override describeContents()64 public int describeContents() { 65 return 0; 66 } 67 68 @Override writeToParcel(Parcel parcel, int flags)69 public void writeToParcel(Parcel parcel, int flags) { 70 parcel.writeLong(mRefreshPeriodNano); 71 parcel.writeLongArray(mFramesPresentedTimeNano); 72 } 73 74 @Override toString()75 public String toString() { 76 StringBuilder builder = new StringBuilder(); 77 builder.append("WindowAnimationFrameStats["); 78 builder.append("frameCount:" + getFrameCount()); 79 builder.append(", fromTimeNano:" + getStartTimeNano()); 80 builder.append(", toTimeNano:" + getEndTimeNano()); 81 builder.append(']'); 82 return builder.toString(); 83 } 84 85 public static final @android.annotation.NonNull Creator<WindowAnimationFrameStats> CREATOR = 86 new Creator<WindowAnimationFrameStats>() { 87 @Override 88 public WindowAnimationFrameStats createFromParcel(Parcel parcel) { 89 return new WindowAnimationFrameStats(parcel); 90 } 91 92 @Override 93 public WindowAnimationFrameStats[] newArray(int size) { 94 return new WindowAnimationFrameStats[size]; 95 } 96 }; 97 } 98