Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 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 | */ |
Jeff Sharkey | 70168dd | 2016-03-30 21:47:16 -0600 | [diff] [blame] | 30 | public final class TimerStat implements Parcelable { |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 31 | private int mCount; |
| 32 | private long mTime; |
| 33 | |
| 34 | /** |
| 35 | * The CREATOR instance for use by aidl Binder interfaces. |
| 36 | */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 37 | public static final @android.annotation.NonNull Parcelable.Creator<TimerStat> CREATOR |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 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 | */ |
| 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 | */ |
| 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 | */ |
| 69 | public TimerStat(Parcel in) { |
| 70 | mCount = in.readInt(); |
| 71 | mTime = in.readLong(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @inheritDoc |
| 76 | */ |
| 77 | public int describeContents() { |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Write this TimerStat object to a parcel. |
| 83 | */ |
| 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 | */ |
| 92 | public void setCount(int count) { |
| 93 | mCount = count; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Get the count for this timer. |
| 98 | */ |
| 99 | public int getCount() { |
| 100 | return mCount; |
| 101 | } |
| 102 | |
| 103 | /** |
Joe Onorato | 181cada | 2016-05-09 10:31:41 -0700 | [diff] [blame] | 104 | * Set the time for this timer in milliseconds. |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 105 | */ |
| 106 | public void setTime(long time) { |
| 107 | mTime = time; |
| 108 | } |
| 109 | |
| 110 | /** |
Joe Onorato | 181cada | 2016-05-09 10:31:41 -0700 | [diff] [blame] | 111 | * Get the time for this timer in milliseconds. |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 112 | */ |
| 113 | public long getTime() { |
| 114 | return mTime; |
| 115 | } |
| 116 | } |