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