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