1 /*
2  * Copyright (C) 2016 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.os.health;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 /**
23  * A TimerStat object stores a count and a time.
24  *
25  * @more
26  * When possible, the other APIs in this package avoid requiring a TimerStat
27  * object to be constructed, even internally, but the getTimers method on
28  * {@link android.os.health.HealthStats} does require TimerStat objects.
29  */
30 public final class TimerStat implements Parcelable {
31     private int mCount;
32     private long mTime;
33 
34     /**
35      * The CREATOR instance for use by aidl Binder interfaces.
36      */
37     public static final @android.annotation.NonNull Parcelable.Creator<TimerStat> CREATOR
38             = new Parcelable.Creator<TimerStat>() {
39         public TimerStat createFromParcel(Parcel in) {
40             return new TimerStat(in);
41         }
42 
43         public TimerStat[] newArray(int size) {
44             return new TimerStat[size];
45         }
46     };
47 
48     /**
49      * Construct an empty TimerStat object with the count and time set to 0.
50      */
TimerStat()51     public TimerStat() {
52     }
53 
54     /**
55      * Construct a TimerStat object with the supplied count and time fields.
56      *
57      * @param count The count
58      * @param time The time
59      */
TimerStat(int count, long time)60     public TimerStat(int count, long time) {
61         mCount = count;
62         mTime = time;
63     }
64 
65     /**
66      * Construct a TimerStat object reading the values from a {@link android.os.Parcel Parcel}
67      * object.
68      */
TimerStat(Parcel in)69     public TimerStat(Parcel in) {
70         mCount = in.readInt();
71         mTime = in.readLong();
72     }
73 
74     /**
75      * @inheritDoc
76      */
describeContents()77     public int describeContents() {
78         return 0;
79     }
80 
81     /**
82      * Write this TimerStat object to a parcel.
83      */
writeToParcel(Parcel out, int flags)84     public void writeToParcel(Parcel out, int flags) {
85         out.writeInt(mCount);
86         out.writeLong(mTime);
87     }
88 
89     /**
90      * Set the count for this timer.
91      */
setCount(int count)92     public void setCount(int count) {
93         mCount = count;
94     }
95 
96     /**
97      * Get the count for this timer.
98      */
getCount()99     public int getCount() {
100         return mCount;
101     }
102 
103     /**
104      * Set the time for this timer in milliseconds.
105      */
setTime(long time)106     public void setTime(long time) {
107         mTime = time;
108     }
109 
110     /**
111      * Get the time for this timer in milliseconds.
112      */
getTime()113     public long getTime() {
114         return mTime;
115     }
116 }
117