1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.os.connectivity;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.os.BatteryStats;
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.Annotation.NetworkType;
import android.telephony.CellSignalStrength;
import android.telephony.ModemActivityInfo;
import java.util.Arrays;
import java.util.Objects;
/**
* API for Cellular power stats
*
* @hide
*/
@SystemApi
public final class CellularBatteryStats implements Parcelable {
private final long mLoggingDurationMs;
private final long mKernelActiveTimeMs;
private final long mNumPacketsTx;
private final long mNumBytesTx;
private final long mNumPacketsRx;
private final long mNumBytesRx;
private final long mSleepTimeMs;
private final long mIdleTimeMs;
private final long mRxTimeMs;
private final long mEnergyConsumedMaMs;
private final long[] mTimeInRatMs;
private final long[] mTimeInRxSignalStrengthLevelMs;
private final long[] mTxTimeMs;
private final long mMonitoredRailChargeConsumedMaMs;
public static final @NonNull Parcelable.Creator<CellularBatteryStats> CREATOR =
new Parcelable.Creator<CellularBatteryStats>() {
public CellularBatteryStats createFromParcel(Parcel in) {
long loggingDurationMs = in.readLong();
long kernelActiveTimeMs = in.readLong();
long numPacketsTx = in.readLong();
long numBytesTx = in.readLong();
long numPacketsRx = in.readLong();
long numBytesRx = in.readLong();
long sleepTimeMs = in.readLong();
long idleTimeMs = in.readLong();
long rxTimeMs = in.readLong();
long energyConsumedMaMs = in.readLong();
long[] timeInRatMs = in.createLongArray();
long[] timeInRxSignalStrengthLevelMs = in.createLongArray();
long[] txTimeMs = in.createLongArray();
long monitoredRailChargeConsumedMaMs = in.readLong();
return new CellularBatteryStats(loggingDurationMs, kernelActiveTimeMs,
numPacketsTx, numBytesTx, numPacketsRx, numBytesRx, sleepTimeMs,
idleTimeMs, rxTimeMs, energyConsumedMaMs, timeInRatMs,
timeInRxSignalStrengthLevelMs, txTimeMs,
monitoredRailChargeConsumedMaMs);
}
public CellularBatteryStats[] newArray(int size) {
return new CellularBatteryStats[size];
}
};
/** @hide **/
public CellularBatteryStats(long loggingDurationMs, long kernelActiveTimeMs, long numPacketsTx,
long numBytesTx, long numPacketsRx, long numBytesRx, long sleepTimeMs, long idleTimeMs,
long rxTimeMs, Long energyConsumedMaMs, long[] timeInRatMs,
long[] timeInRxSignalStrengthLevelMs, long[] txTimeMs,
long monitoredRailChargeConsumedMaMs) {
mLoggingDurationMs = loggingDurationMs;
mKernelActiveTimeMs = kernelActiveTimeMs;
mNumPacketsTx = numPacketsTx;
mNumBytesTx = numBytesTx;
mNumPacketsRx = numPacketsRx;
mNumBytesRx = numBytesRx;
mSleepTimeMs = sleepTimeMs;
mIdleTimeMs = idleTimeMs;
mRxTimeMs = rxTimeMs;
mEnergyConsumedMaMs = energyConsumedMaMs;
mTimeInRatMs = Arrays.copyOfRange(
timeInRatMs, 0,
Math.min(timeInRatMs.length, BatteryStats.NUM_DATA_CONNECTION_TYPES));
mTimeInRxSignalStrengthLevelMs = Arrays.copyOfRange(
timeInRxSignalStrengthLevelMs, 0,
Math.min(timeInRxSignalStrengthLevelMs.length,
CellSignalStrength.getNumSignalStrengthLevels()));
mTxTimeMs = Arrays.copyOfRange(
txTimeMs, 0,
Math.min(txTimeMs.length, ModemActivityInfo.getNumTxPowerLevels()));
mMonitoredRailChargeConsumedMaMs = monitoredRailChargeConsumedMaMs;
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
out.writeLong(mLoggingDurationMs);
out.writeLong(mKernelActiveTimeMs);
out.writeLong(mNumPacketsTx);
out.writeLong(mNumBytesTx);
out.writeLong(mNumPacketsRx);
out.writeLong(mNumBytesRx);
out.writeLong(mSleepTimeMs);
out.writeLong(mIdleTimeMs);
out.writeLong(mRxTimeMs);
out.writeLong(mEnergyConsumedMaMs);
out.writeLongArray(mTimeInRatMs);
out.writeLongArray(mTimeInRxSignalStrengthLevelMs);
out.writeLongArray(mTxTimeMs);
out.writeLong(mMonitoredRailChargeConsumedMaMs);
}
@Override
public boolean equals(@Nullable Object other) {
if (!(other instanceof CellularBatteryStats)) return false;
if (other == this) return true;
CellularBatteryStats otherStats = (CellularBatteryStats) other;
return this.mLoggingDurationMs == otherStats.mLoggingDurationMs
&& this.mKernelActiveTimeMs == otherStats.mKernelActiveTimeMs
&& this.mNumPacketsTx == otherStats.mNumPacketsTx
&& this.mNumBytesTx == otherStats.mNumBytesTx
&& this.mNumPacketsRx == otherStats.mNumPacketsRx
&& this.mNumBytesRx == otherStats.mNumBytesRx
&& this.mSleepTimeMs == otherStats.mSleepTimeMs
&& this.mIdleTimeMs == otherStats.mIdleTimeMs
&& this.mRxTimeMs == otherStats.mRxTimeMs
&& this.mEnergyConsumedMaMs == otherStats.mEnergyConsumedMaMs
&& Arrays.equals(this.mTimeInRatMs, otherStats.mTimeInRatMs)
&& Arrays.equals(this.mTimeInRxSignalStrengthLevelMs,
otherStats.mTimeInRxSignalStrengthLevelMs)
&& Arrays.equals(this.mTxTimeMs, otherStats.mTxTimeMs)
&& this.mMonitoredRailChargeConsumedMaMs
== otherStats.mMonitoredRailChargeConsumedMaMs;
}
@Override
public int hashCode() {
return Objects.hash(mLoggingDurationMs, mKernelActiveTimeMs, mNumPacketsTx,
mNumBytesTx, mNumPacketsRx, mNumBytesRx, mSleepTimeMs, mIdleTimeMs,
mRxTimeMs, mEnergyConsumedMaMs, Arrays.hashCode(mTimeInRatMs),
Arrays.hashCode(mTimeInRxSignalStrengthLevelMs), Arrays.hashCode(mTxTimeMs),
mMonitoredRailChargeConsumedMaMs);
}
/**
* Returns the duration for which these cellular stats were collected.
*
* @return Duration of stats collection in milliseconds.
*/
public long getLoggingDurationMillis() {
return mLoggingDurationMs;
}
/**
* Returns the duration for which the kernel was active within
* {@link #getLoggingDurationMillis()}.
*
* @return Duration of kernel active time in milliseconds.
*/
public long getKernelActiveTimeMillis() {
return mKernelActiveTimeMs;
}
/**
* Returns the number of packets transmitted over cellular within
* {@link #getLoggingDurationMillis()}.
*
* @return Number of packets transmitted.
*/
public long getNumPacketsTx() {
return mNumPacketsTx;
}
/**
* Returns the number of packets received over cellular within
* {@link #getLoggingDurationMillis()}.
*
* @return Number of packets received.
*/
public long getNumBytesTx() {
return mNumBytesTx;
}
/**
* Returns the number of bytes transmitted over cellular within
* {@link #getLoggingDurationMillis()}.
*
* @return Number of bytes transmitted.
*/
public long getNumPacketsRx() {
return mNumPacketsRx;
}
/**
* Returns the number of bytes received over cellular within
* {@link #getLoggingDurationMillis()}.
*
* @return Number of bytes received.
*/
public long getNumBytesRx() {
return mNumBytesRx;
}
/**
* Returns the duration for which the device was sleeping within
* {@link #getLoggingDurationMillis()}.
*
* @return Duration of sleep time in milliseconds.
*/
public long getSleepTimeMillis() {
return mSleepTimeMs;
}
/**
* Returns the duration for which the device was idle within
* {@link #getLoggingDurationMillis()}.
*
* @return Duration of idle time in milliseconds.
*/
public long getIdleTimeMillis() {
return mIdleTimeMs;
}
/**
* Returns the duration for which the device was receiving over cellular within
* {@link #getLoggingDurationMillis()}.
*
* @return Duration of cellular reception time in milliseconds.
*/
public long getRxTimeMillis() {
return mRxTimeMs;
}
/**
* Returns an estimation of energy consumed by cellular chip within
* {@link #getLoggingDurationMillis()}.
*
* @return Energy consumed in milli-ampere milliseconds (mAmS).
*/
public long getEnergyConsumedMaMillis() {
return mEnergyConsumedMaMs;
}
/**
* Returns the time in microseconds that the phone has been running with
* the given data connection.
*
* @param networkType The network type to query.
* @return The amount of time the phone spends in the {@code networkType} network type. The
* unit is in microseconds.
*/
@NonNull
@SuppressLint("MethodNameUnits")
public long getTimeInRatMicros(@NetworkType int networkType) {
if (networkType >= mTimeInRatMs.length) {
return -1;
}
return mTimeInRatMs[networkType];
}
/**
* Returns the time in microseconds that the phone has been running with
* the given signal strength.
*
* @param signalStrengthBin a single integer from 0 to 4 representing the general signal
* quality.
* @return Amount of time phone spends in specific cellular rx signal strength levels
* in microseconds. The index is signal strength bin.
*/
@NonNull
@SuppressLint("MethodNameUnits")
public long getTimeInRxSignalStrengthLevelMicros(
@IntRange(from = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN,
to = CellSignalStrength.SIGNAL_STRENGTH_GREAT) int signalStrengthBin) {
if (signalStrengthBin >= mTimeInRxSignalStrengthLevelMs.length) {
return -1;
}
return mTimeInRxSignalStrengthLevelMs[signalStrengthBin];
}
/**
* Returns the duration for which the device was transmitting over cellular within
* {@link #getLoggingDurationMillis()}.
*
* @param level a single integer from 0 to 4 representing the Tx(transmit) power level.
* @return Duration of cellular transmission time for specific power level in milliseconds.
*
* Tx(transmit) power level. see power index @ModemActivityInfo.TxPowerLevel below
* <ul>
* <li> index 0 = tx_power < 0dBm. </li>
* <li> index 1 = 0dBm < tx_power < 5dBm. </li>
* <li> index 2 = 5dBm < tx_power < 15dBm. </li>
* <li> index 3 = 15dBm < tx_power < 20dBm. </li>
* <li> index 4 = tx_power > 20dBm. </li>
* </ul>
*
* @hide
*/
@NonNull
public long getTxTimeMillis(
@IntRange(from = ModemActivityInfo.TX_POWER_LEVEL_0,
to = ModemActivityInfo.TX_POWER_LEVEL_4) int level) {
if (level >= mTxTimeMs.length) {
return -1;
}
return mTxTimeMs[level];
}
/**
* Returns the energy consumed by cellular chip within {@link #getLoggingDurationMillis()}.
*
* @return Energy consumed in milli-ampere milli-seconds (mAmS).
*/
public long getMonitoredRailChargeConsumedMaMillis() {
return mMonitoredRailChargeConsumedMaMs;
}
@Override
public int describeContents() {
return 0;
}
}
|