Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -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 | package android.os.connectivity; |
| 17 | |
| 18 | import android.os.Parcel; |
| 19 | import android.os.Parcelable; |
| 20 | |
| 21 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
| 22 | |
| 23 | import java.util.Arrays; |
| 24 | |
| 25 | /** |
| 26 | * API for GPS power stats |
| 27 | * |
| 28 | * @hide |
| 29 | */ |
| 30 | public final class GpsBatteryStats implements Parcelable { |
| 31 | |
| 32 | private long mLoggingDurationMs; |
| 33 | private long mEnergyConsumedMaMs; |
| 34 | private long[] mTimeInGpsSignalQualityLevel; |
| 35 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 36 | public static final @android.annotation.NonNull Parcelable.Creator<GpsBatteryStats> CREATOR = new |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 37 | Parcelable.Creator<GpsBatteryStats>() { |
| 38 | public GpsBatteryStats createFromParcel(Parcel in) { |
| 39 | return new GpsBatteryStats(in); |
| 40 | } |
| 41 | |
| 42 | public GpsBatteryStats[] newArray(int size) { |
| 43 | return new GpsBatteryStats[size]; |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | public GpsBatteryStats() { |
| 48 | initialize(); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void writeToParcel(Parcel out, int flags) { |
| 53 | out.writeLong(mLoggingDurationMs); |
| 54 | out.writeLong(mEnergyConsumedMaMs); |
| 55 | out.writeLongArray(mTimeInGpsSignalQualityLevel); |
| 56 | } |
| 57 | |
| 58 | public void readFromParcel(Parcel in) { |
| 59 | mLoggingDurationMs = in.readLong(); |
| 60 | mEnergyConsumedMaMs = in.readLong(); |
| 61 | in.readLongArray(mTimeInGpsSignalQualityLevel); |
| 62 | } |
| 63 | |
| 64 | public long getLoggingDurationMs() { |
| 65 | return mLoggingDurationMs; |
| 66 | } |
| 67 | |
| 68 | public long getEnergyConsumedMaMs() { |
| 69 | return mEnergyConsumedMaMs; |
| 70 | } |
| 71 | |
| 72 | public long[] getTimeInGpsSignalQualityLevel() { |
| 73 | return mTimeInGpsSignalQualityLevel; |
| 74 | } |
| 75 | |
| 76 | public void setLoggingDurationMs(long t) { |
| 77 | mLoggingDurationMs = t; |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | public void setEnergyConsumedMaMs(long e) { |
| 82 | mEnergyConsumedMaMs = e; |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | public void setTimeInGpsSignalQualityLevel(long[] t) { |
| 87 | mTimeInGpsSignalQualityLevel = Arrays.copyOfRange(t, 0, |
| 88 | Math.min(t.length, GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS)); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public int describeContents() { |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | private GpsBatteryStats(Parcel in) { |
| 98 | initialize(); |
| 99 | readFromParcel(in); |
| 100 | } |
| 101 | |
| 102 | private void initialize() { |
| 103 | mLoggingDurationMs = 0; |
| 104 | mEnergyConsumedMaMs = 0; |
| 105 | mTimeInGpsSignalQualityLevel = new long[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 106 | return; |
| 107 | } |
| 108 | } |