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     /* Indicates whether to stream the profiling info to the out file continuously. */
43     public final boolean streamingOutput;
44 
ProfilerInfo(String filename, ParcelFileDescriptor fd, int interval, boolean autoStop, boolean streaming)45     public ProfilerInfo(String filename, ParcelFileDescriptor fd, int interval, boolean autoStop,
46                         boolean streaming) {
47         profileFile = filename;
48         profileFd = fd;
49         samplingInterval = interval;
50         autoStopProfiler = autoStop;
51         streamingOutput = streaming;
52     }
53 
describeContents()54     public int describeContents() {
55         if (profileFd != null) {
56             return profileFd.describeContents();
57         } else {
58             return 0;
59         }
60     }
61 
writeToParcel(Parcel out, int flags)62     public void writeToParcel(Parcel out, int flags) {
63         out.writeString(profileFile);
64         if (profileFd != null) {
65             out.writeInt(1);
66             profileFd.writeToParcel(out, flags);
67         } else {
68             out.writeInt(0);
69         }
70         out.writeInt(samplingInterval);
71         out.writeInt(autoStopProfiler ? 1 : 0);
72         out.writeInt(streamingOutput ? 1 : 0);
73     }
74 
75     public static final Parcelable.Creator<ProfilerInfo> CREATOR =
76             new Parcelable.Creator<ProfilerInfo>() {
77         public ProfilerInfo createFromParcel(Parcel in) {
78             return new ProfilerInfo(in);
79         }
80 
81         public ProfilerInfo[] newArray(int size) {
82             return new ProfilerInfo[size];
83         }
84     };
85 
ProfilerInfo(Parcel in)86     private ProfilerInfo(Parcel in) {
87         profileFile = in.readString();
88         profileFd = in.readInt() != 0 ? ParcelFileDescriptor.CREATOR.createFromParcel(in) : null;
89         samplingInterval = in.readInt();
90         autoStopProfiler = in.readInt() != 0;
91         streamingOutput = in.readInt() != 0;
92     }
93 }
94