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