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.BatteryStats;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.telephony.CellSignalStrength;
22 import android.telephony.ModemActivityInfo;
23 
24 import java.util.Arrays;
25 
26 /**
27  * API for Cellular power stats
28  *
29  * @hide
30  */
31 public final class CellularBatteryStats implements Parcelable {
32 
33   private long mLoggingDurationMs;
34   private long mKernelActiveTimeMs;
35   private long mNumPacketsTx;
36   private long mNumBytesTx;
37   private long mNumPacketsRx;
38   private long mNumBytesRx;
39   private long mSleepTimeMs;
40   private long mIdleTimeMs;
41   private long mRxTimeMs;
42   private long mEnergyConsumedMaMs;
43   private long[] mTimeInRatMs;
44   private long[] mTimeInRxSignalStrengthLevelMs;
45   private long[] mTxTimeMs;
46   private long mMonitoredRailChargeConsumedMaMs;
47 
48   public static final @android.annotation.NonNull Parcelable.Creator<CellularBatteryStats> CREATOR = new
49       Parcelable.Creator<CellularBatteryStats>() {
50         public CellularBatteryStats createFromParcel(Parcel in) {
51           return new CellularBatteryStats(in);
52         }
53 
54         public CellularBatteryStats[] newArray(int size) {
55           return new CellularBatteryStats[size];
56         }
57       };
58 
CellularBatteryStats()59   public CellularBatteryStats() {
60     initialize();
61   }
62 
writeToParcel(Parcel out, int flags)63   public void writeToParcel(Parcel out, int flags) {
64     out.writeLong(mLoggingDurationMs);
65     out.writeLong(mKernelActiveTimeMs);
66     out.writeLong(mNumPacketsTx);
67     out.writeLong(mNumBytesTx);
68     out.writeLong(mNumPacketsRx);
69     out.writeLong(mNumBytesRx);
70     out.writeLong(mSleepTimeMs);
71     out.writeLong(mIdleTimeMs);
72     out.writeLong(mRxTimeMs);
73     out.writeLong(mEnergyConsumedMaMs);
74     out.writeLongArray(mTimeInRatMs);
75     out.writeLongArray(mTimeInRxSignalStrengthLevelMs);
76     out.writeLongArray(mTxTimeMs);
77     out.writeLong(mMonitoredRailChargeConsumedMaMs);
78   }
79 
readFromParcel(Parcel in)80   public void readFromParcel(Parcel in) {
81     mLoggingDurationMs = in.readLong();
82     mKernelActiveTimeMs = in.readLong();
83     mNumPacketsTx = in.readLong();
84     mNumBytesTx = in.readLong();
85     mNumPacketsRx = in.readLong();
86     mNumBytesRx = in.readLong();
87     mSleepTimeMs = in.readLong();
88     mIdleTimeMs = in.readLong();
89     mRxTimeMs = in.readLong();
90     mEnergyConsumedMaMs = in.readLong();
91     in.readLongArray(mTimeInRatMs);
92     in.readLongArray(mTimeInRxSignalStrengthLevelMs);
93     in.readLongArray(mTxTimeMs);
94     mMonitoredRailChargeConsumedMaMs = in.readLong();
95   }
96 
getLoggingDurationMs()97   public long getLoggingDurationMs() {
98     return mLoggingDurationMs;
99   }
100 
getKernelActiveTimeMs()101   public long getKernelActiveTimeMs() {
102     return mKernelActiveTimeMs;
103   }
104 
getNumPacketsTx()105   public long getNumPacketsTx() {
106     return mNumPacketsTx;
107   }
108 
getNumBytesTx()109   public long getNumBytesTx() {
110     return mNumBytesTx;
111   }
112 
getNumPacketsRx()113   public long getNumPacketsRx() {
114     return mNumPacketsRx;
115   }
116 
getNumBytesRx()117   public long getNumBytesRx() {
118     return mNumBytesRx;
119   }
120 
getSleepTimeMs()121   public long getSleepTimeMs() {
122     return mSleepTimeMs;
123   }
124 
getIdleTimeMs()125   public long getIdleTimeMs() {
126     return mIdleTimeMs;
127   }
128 
getRxTimeMs()129   public long getRxTimeMs() {
130     return mRxTimeMs;
131   }
132 
getEnergyConsumedMaMs()133   public long getEnergyConsumedMaMs() {
134     return mEnergyConsumedMaMs;
135   }
136 
getTimeInRatMs()137   public long[] getTimeInRatMs() {
138     return mTimeInRatMs;
139   }
140 
getTimeInRxSignalStrengthLevelMs()141   public long[] getTimeInRxSignalStrengthLevelMs() {
142     return mTimeInRxSignalStrengthLevelMs;
143   }
144 
getTxTimeMs()145   public long[] getTxTimeMs() {
146     return mTxTimeMs;
147   }
148 
getMonitoredRailChargeConsumedMaMs()149   public long getMonitoredRailChargeConsumedMaMs() {
150     return mMonitoredRailChargeConsumedMaMs;
151   }
152 
setLoggingDurationMs(long t)153   public void setLoggingDurationMs(long t) {
154     mLoggingDurationMs = t;
155     return;
156   }
157 
setKernelActiveTimeMs(long t)158   public void setKernelActiveTimeMs(long t) {
159     mKernelActiveTimeMs = t;
160     return;
161   }
162 
setNumPacketsTx(long n)163   public void setNumPacketsTx(long n) {
164     mNumPacketsTx = n;
165     return;
166   }
167 
setNumBytesTx(long b)168   public void setNumBytesTx(long b) {
169     mNumBytesTx = b;
170     return;
171   }
172 
setNumPacketsRx(long n)173   public void setNumPacketsRx(long n) {
174     mNumPacketsRx = n;
175     return;
176   }
177 
setNumBytesRx(long b)178   public void setNumBytesRx(long b) {
179     mNumBytesRx = b;
180     return;
181   }
182 
setSleepTimeMs(long t)183   public void setSleepTimeMs(long t) {
184     mSleepTimeMs = t;
185     return;
186   }
187 
setIdleTimeMs(long t)188   public void setIdleTimeMs(long t) {
189     mIdleTimeMs = t;
190     return;
191   }
192 
setRxTimeMs(long t)193   public void setRxTimeMs(long t) {
194     mRxTimeMs = t;
195     return;
196   }
197 
setEnergyConsumedMaMs(long e)198   public void setEnergyConsumedMaMs(long e) {
199     mEnergyConsumedMaMs = e;
200     return;
201   }
202 
setTimeInRatMs(long[] t)203   public void setTimeInRatMs(long[] t) {
204     mTimeInRatMs = Arrays.copyOfRange(t, 0,
205         Math.min(t.length, BatteryStats.NUM_DATA_CONNECTION_TYPES));
206     return;
207   }
208 
setTimeInRxSignalStrengthLevelMs(long[] t)209   public void setTimeInRxSignalStrengthLevelMs(long[] t) {
210     mTimeInRxSignalStrengthLevelMs = Arrays.copyOfRange(t, 0,
211         Math.min(t.length, CellSignalStrength.getNumSignalStrengthLevels()));
212     return;
213   }
214 
setTxTimeMs(long[] t)215   public void setTxTimeMs(long[] t) {
216     mTxTimeMs = Arrays.copyOfRange(t, 0, Math.min(t.length, ModemActivityInfo.TX_POWER_LEVELS));
217     return;
218   }
219 
setMonitoredRailChargeConsumedMaMs(long monitoredRailEnergyConsumedMaMs)220   public void setMonitoredRailChargeConsumedMaMs(long monitoredRailEnergyConsumedMaMs) {
221     mMonitoredRailChargeConsumedMaMs = monitoredRailEnergyConsumedMaMs;
222     return;
223   }
224 
describeContents()225   public int describeContents() {
226     return 0;
227   }
228 
CellularBatteryStats(Parcel in)229   private CellularBatteryStats(Parcel in) {
230     initialize();
231     readFromParcel(in);
232   }
233 
initialize()234   private void initialize() {
235     mLoggingDurationMs = 0;
236     mKernelActiveTimeMs = 0;
237     mNumPacketsTx = 0;
238     mNumBytesTx = 0;
239     mNumPacketsRx = 0;
240     mNumBytesRx = 0;
241     mSleepTimeMs = 0;
242     mIdleTimeMs = 0;
243     mRxTimeMs = 0;
244     mEnergyConsumedMaMs = 0;
245     mTimeInRatMs = new long[BatteryStats.NUM_DATA_CONNECTION_TYPES];
246     Arrays.fill(mTimeInRatMs, 0);
247     mTimeInRxSignalStrengthLevelMs = new long[CellSignalStrength.getNumSignalStrengthLevels()];
248     Arrays.fill(mTimeInRxSignalStrengthLevelMs, 0);
249     mTxTimeMs = new long[ModemActivityInfo.TX_POWER_LEVELS];
250     Arrays.fill(mTxTimeMs, 0);
251     mMonitoredRailChargeConsumedMaMs = 0;
252     return;
253   }
254 }
255