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 36 public static final @android.annotation.NonNull Parcelable.Creator<GpsBatteryStats> CREATOR = new 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 GpsBatteryStats()47 public GpsBatteryStats() { 48 initialize(); 49 } 50 51 @Override writeToParcel(Parcel out, int flags)52 public void writeToParcel(Parcel out, int flags) { 53 out.writeLong(mLoggingDurationMs); 54 out.writeLong(mEnergyConsumedMaMs); 55 out.writeLongArray(mTimeInGpsSignalQualityLevel); 56 } 57 readFromParcel(Parcel in)58 public void readFromParcel(Parcel in) { 59 mLoggingDurationMs = in.readLong(); 60 mEnergyConsumedMaMs = in.readLong(); 61 in.readLongArray(mTimeInGpsSignalQualityLevel); 62 } 63 getLoggingDurationMs()64 public long getLoggingDurationMs() { 65 return mLoggingDurationMs; 66 } 67 getEnergyConsumedMaMs()68 public long getEnergyConsumedMaMs() { 69 return mEnergyConsumedMaMs; 70 } 71 getTimeInGpsSignalQualityLevel()72 public long[] getTimeInGpsSignalQualityLevel() { 73 return mTimeInGpsSignalQualityLevel; 74 } 75 setLoggingDurationMs(long t)76 public void setLoggingDurationMs(long t) { 77 mLoggingDurationMs = t; 78 return; 79 } 80 setEnergyConsumedMaMs(long e)81 public void setEnergyConsumedMaMs(long e) { 82 mEnergyConsumedMaMs = e; 83 return; 84 } 85 setTimeInGpsSignalQualityLevel(long[] t)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 describeContents()93 public int describeContents() { 94 return 0; 95 } 96 GpsBatteryStats(Parcel in)97 private GpsBatteryStats(Parcel in) { 98 initialize(); 99 readFromParcel(in); 100 } 101 initialize()102 private void initialize() { 103 mLoggingDurationMs = 0; 104 mEnergyConsumedMaMs = 0; 105 mTimeInGpsSignalQualityLevel = new long[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; 106 return; 107 } 108 }