1713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato/*
2713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Copyright (C) 2016 The Android Open Source Project
3713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato *
4713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Licensed under the Apache License, Version 2.0 (the "License");
5713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * you may not use this file except in compliance with the License.
6713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * You may obtain a copy of the License at
7713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato *
8713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato *      http://www.apache.org/licenses/LICENSE-2.0
9713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato *
10713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * Unless required by applicable law or agreed to in writing, software
11713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * distributed under the License is distributed on an "AS IS" BASIS,
12713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * See the License for the specific language governing permissions and
14713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * limitations under the License.
15713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */
16713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
17713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratopackage android.os.health;
18713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
19713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.Parcel;
20713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onoratoimport android.os.Parcelable;
21713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
22713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato/**
23713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * A TimerStat object stores a count and a time.
24713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato *
25713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * @more
26713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * When possible, the other APIs in this package avoid requiring a TimerStat
27713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * object to be constructed, even internally, but the getTimers method on
28713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato * {@link android.os.health.HealthStats} does require TimerStat objects.
29713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato */
3070168dde6e1da06042818350fc6e258188d001aeJeff Sharkeypublic final class TimerStat implements Parcelable {
31713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    private int mCount;
32713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    private long mTime;
33713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
34713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
35713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * The CREATOR instance for use by aidl Binder interfaces.
36713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
37713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public static final Parcelable.Creator<TimerStat> CREATOR
38713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato            = new Parcelable.Creator<TimerStat>() {
39713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        public TimerStat createFromParcel(Parcel in) {
40713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato            return new TimerStat(in);
41713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        }
42713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
43713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        public TimerStat[] newArray(int size) {
44713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato            return new TimerStat[size];
45713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        }
46713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    };
47713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
48713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
49713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * Construct an empty TimerStat object with the count and time set to 0.
50713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
51713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public TimerStat() {
52713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
53713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
54713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
55713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * Construct a TimerStat object with the supplied count and time fields.
56713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     *
57713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * @param count The count
58713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * @param time The time
59713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
60713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public TimerStat(int count, long time) {
61713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        mCount = count;
62713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        mTime = time;
63713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
64713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
65713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
66713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * Construct a TimerStat object reading the values from a {@link android.os.Parcel Parcel}
67713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * object.
68713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
69713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public TimerStat(Parcel in) {
70713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        mCount = in.readInt();
71713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        mTime = in.readLong();
72713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
73713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
74713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
75713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * @inheritDoc
76713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
77713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public int describeContents() {
78713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        return 0;
79713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
80713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
81713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
82713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * Write this TimerStat object to a parcel.
83713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
84713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public void writeToParcel(Parcel out, int flags) {
85713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        out.writeInt(mCount);
86713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        out.writeLong(mTime);
87713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
88713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
89713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
90713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * Set the count for this timer.
91713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
92713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public void setCount(int count) {
93713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        mCount = count;
94713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
95713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
96713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
97713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     * Get the count for this timer.
98713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
99713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public int getCount() {
100713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        return mCount;
101713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
102713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
103713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
104181cada18a9feab90627ab27070bc00c29ec337aJoe Onorato     * Set the time for this timer in milliseconds.
105713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
106713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public void setTime(long time) {
107713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        mTime = time;
108713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
109713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato
110713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    /**
111181cada18a9feab90627ab27070bc00c29ec337aJoe Onorato     * Get the time for this timer in milliseconds.
112713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato     */
113713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    public long getTime() {
114713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato        return mTime;
115713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato    }
116713fec85b8612256211f09c62b8958a99fe5b9dbJoe Onorato}
117