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