Home | History | Annotate | Download | only in app
      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.app;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 import android.os.ParcelFileDescriptor;
     22 
     23 /**
     24  * System private API for passing profiler settings.
     25  *
     26  * {@hide}
     27  */
     28 public class ProfilerInfo implements Parcelable {
     29 
     30     /* Name of profile output file. */
     31     public final String profileFile;
     32 
     33     /* File descriptor for profile output file, can be null. */
     34     public ParcelFileDescriptor profileFd;
     35 
     36     /* Indicates sample profiling when nonzero, interval in microseconds. */
     37     public final int samplingInterval;
     38 
     39     /* Automatically stop the profiler when the app goes idle. */
     40     public final boolean autoStopProfiler;
     41 
     42     public ProfilerInfo(String filename, ParcelFileDescriptor fd, int interval, boolean autoStop) {
     43         profileFile = filename;
     44         profileFd = fd;
     45         samplingInterval = interval;
     46         autoStopProfiler = autoStop;
     47     }
     48 
     49     public int describeContents() {
     50         if (profileFd != null) {
     51             return profileFd.describeContents();
     52         } else {
     53             return 0;
     54         }
     55     }
     56 
     57     public void writeToParcel(Parcel out, int flags) {
     58         out.writeString(profileFile);
     59         if (profileFd != null) {
     60             out.writeInt(1);
     61             profileFd.writeToParcel(out, flags);
     62         } else {
     63             out.writeInt(0);
     64         }
     65         out.writeInt(samplingInterval);
     66         out.writeInt(autoStopProfiler ? 1 : 0);
     67     }
     68 
     69     public static final Parcelable.Creator<ProfilerInfo> CREATOR =
     70             new Parcelable.Creator<ProfilerInfo>() {
     71         public ProfilerInfo createFromParcel(Parcel in) {
     72             return new ProfilerInfo(in);
     73         }
     74 
     75         public ProfilerInfo[] newArray(int size) {
     76             return new ProfilerInfo[size];
     77         }
     78     };
     79 
     80     private ProfilerInfo(Parcel in) {
     81         profileFile = in.readString();
     82         profileFd = in.readInt() != 0 ? ParcelFileDescriptor.CREATOR.createFromParcel(in) : null;
     83         samplingInterval = in.readInt();
     84         autoStopProfiler = in.readInt() != 0;
     85     }
     86 }
     87