Merge "CellularBatteryStats: Address API council feedback" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-03-02 17:40:09 +00:00
committed by Android (Google) Code Review
4 changed files with 157 additions and 161 deletions

View File

@@ -8857,9 +8857,9 @@ package android.os.connectivity {
method public long getNumPacketsTx(); method public long getNumPacketsTx();
method public long getRxTimeMillis(); method public long getRxTimeMillis();
method public long getSleepTimeMillis(); method public long getSleepTimeMillis();
method @NonNull public long[] getTimeInRatMicros(); method @NonNull public long getTimeInRatMicros(int);
method @NonNull public long[] getTimeInRxSignalStrengthLevelMicros(); method @NonNull public long getTimeInRxSignalStrengthLevelMicros(@IntRange(from=android.telephony.CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN, to=android.telephony.CellSignalStrength.SIGNAL_STRENGTH_GREAT) int);
method @NonNull public long[] getTxTimeMillis(); method @NonNull public long getTxTimeMillis(@IntRange(from=android.telephony.ModemActivityInfo.TX_POWER_LEVEL_0, to=android.telephony.ModemActivityInfo.TX_POWER_LEVEL_4) int);
method public void writeToParcel(@NonNull android.os.Parcel, int); method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.os.connectivity.CellularBatteryStats> CREATOR; field @NonNull public static final android.os.Parcelable.Creator<android.os.connectivity.CellularBatteryStats> CREATOR;
} }
@@ -11176,6 +11176,11 @@ package android.telephony {
method public void writeToParcel(android.os.Parcel, int); method public void writeToParcel(android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.telephony.ModemActivityInfo> CREATOR; field @NonNull public static final android.os.Parcelable.Creator<android.telephony.ModemActivityInfo> CREATOR;
field public static final int TX_POWER_LEVELS = 5; // 0x5 field public static final int TX_POWER_LEVELS = 5; // 0x5
field public static final int TX_POWER_LEVEL_0 = 0; // 0x0
field public static final int TX_POWER_LEVEL_1 = 1; // 0x1
field public static final int TX_POWER_LEVEL_2 = 2; // 0x2
field public static final int TX_POWER_LEVEL_3 = 3; // 0x3
field public static final int TX_POWER_LEVEL_4 = 4; // 0x4
} }
public class ModemActivityInfo.TransmitPower { public class ModemActivityInfo.TransmitPower {

View File

@@ -15,8 +15,10 @@
*/ */
package android.os.connectivity; package android.os.connectivity;
import android.annotation.IntRange;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.os.BatteryStats; import android.os.BatteryStats;
import android.os.Parcel; import android.os.Parcel;
@@ -36,26 +38,44 @@ import java.util.Objects;
@SystemApi @SystemApi
public final class CellularBatteryStats implements Parcelable { public final class CellularBatteryStats implements Parcelable {
private long mLoggingDurationMs = 0; private final long mLoggingDurationMs;
private long mKernelActiveTimeMs = 0; private final long mKernelActiveTimeMs;
private long mNumPacketsTx = 0; private final long mNumPacketsTx;
private long mNumBytesTx = 0; private final long mNumBytesTx;
private long mNumPacketsRx = 0; private final long mNumPacketsRx;
private long mNumBytesRx = 0; private final long mNumBytesRx;
private long mSleepTimeMs = 0; private final long mSleepTimeMs;
private long mIdleTimeMs = 0; private final long mIdleTimeMs;
private long mRxTimeMs = 0; private final long mRxTimeMs;
private long mEnergyConsumedMaMs = 0; private final long mEnergyConsumedMaMs;
private long[] mTimeInRatMs = new long[BatteryStats.NUM_DATA_CONNECTION_TYPES]; private final long[] mTimeInRatMs;
private long[] mTimeInRxSignalStrengthLevelMs = private final long[] mTimeInRxSignalStrengthLevelMs;
new long[CellSignalStrength.getNumSignalStrengthLevels()]; private final long[] mTxTimeMs;
private long[] mTxTimeMs = new long[ModemActivityInfo.TX_POWER_LEVELS]; private final long mMonitoredRailChargeConsumedMaMs;
private long mMonitoredRailChargeConsumedMaMs = 0;
public static final @NonNull Parcelable.Creator<CellularBatteryStats> CREATOR = public static final @NonNull Parcelable.Creator<CellularBatteryStats> CREATOR =
new Parcelable.Creator<CellularBatteryStats>() { new Parcelable.Creator<CellularBatteryStats>() {
public CellularBatteryStats createFromParcel(Parcel in) { public CellularBatteryStats createFromParcel(Parcel in) {
return new CellularBatteryStats(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) { public CellularBatteryStats[] newArray(int size) {
@@ -64,7 +84,34 @@ public final class CellularBatteryStats implements Parcelable {
}; };
/** @hide **/ /** @hide **/
public CellularBatteryStats() {} 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.TX_POWER_LEVELS));
mMonitoredRailChargeConsumedMaMs = monitoredRailChargeConsumedMaMs;
}
@Override @Override
public void writeToParcel(@NonNull Parcel out, int flags) { public void writeToParcel(@NonNull Parcel out, int flags) {
@@ -84,23 +131,6 @@ public final class CellularBatteryStats implements Parcelable {
out.writeLong(mMonitoredRailChargeConsumedMaMs); out.writeLong(mMonitoredRailChargeConsumedMaMs);
} }
private void readFromParcel(Parcel in) {
mLoggingDurationMs = in.readLong();
mKernelActiveTimeMs = in.readLong();
mNumPacketsTx = in.readLong();
mNumBytesTx = in.readLong();
mNumPacketsRx = in.readLong();
mNumBytesRx = in.readLong();
mSleepTimeMs = in.readLong();
mIdleTimeMs = in.readLong();
mRxTimeMs = in.readLong();
mEnergyConsumedMaMs = in.readLong();
in.readLongArray(mTimeInRatMs);
in.readLongArray(mTimeInRxSignalStrengthLevelMs);
in.readLongArray(mTxTimeMs);
mMonitoredRailChargeConsumedMaMs = in.readLong();
}
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
if (!(other instanceof CellularBatteryStats)) return false; if (!(other instanceof CellularBatteryStats)) return false;
@@ -236,32 +266,48 @@ public final class CellularBatteryStats implements Parcelable {
* Returns the time in microseconds that the phone has been running with * Returns the time in microseconds that the phone has been running with
* the given data connection. * the given data connection.
* *
* @return Amount of time phone spends in various Radio Access Technologies in microseconds. * @param networkType The network type to query.
* The index is {@link NetworkType}. * @return The amount of time the phone spends in the {@code networkType} network type. The
* unit is in microseconds.
*/ */
@NonNull @NonNull
public long[] getTimeInRatMicros() { @SuppressLint("MethodNameUnits")
return mTimeInRatMs; 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 * Returns the time in microseconds that the phone has been running with
* the given signal strength. * the given signal strength.
* *
* @return Amount of time phone spends in various cellular rx signal strength levels * @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. * in microseconds. The index is signal strength bin.
*/ */
@NonNull @NonNull
public long[] getTimeInRxSignalStrengthLevelMicros() { @SuppressLint("MethodNameUnits")
return mTimeInRxSignalStrengthLevelMs; 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 * Returns the duration for which the device was transmitting over cellular within
* {@link #getLoggingDurationMillis()}. * {@link #getLoggingDurationMillis()}.
* *
* @return Duration of cellular transmission time in milliseconds. * @param level a single integer from 0 to 4 representing the Tx(transmit) power level.
* Tx(transmit) power index below * @return Duration of cellular transmission time for specific power level in milliseconds.
*
* Tx(transmit) power level. see power index @ModemActivityInfo.TxPowerLevel below
* <ul> * <ul>
* <li> index 0 = tx_power < 0dBm. </li> * <li> index 0 = tx_power < 0dBm. </li>
* <li> index 1 = 0dBm < tx_power < 5dBm. </li> * <li> index 1 = 0dBm < tx_power < 5dBm. </li>
@@ -271,8 +317,14 @@ public final class CellularBatteryStats implements Parcelable {
* </ul> * </ul>
*/ */
@NonNull @NonNull
public long[] getTxTimeMillis() { public long getTxTimeMillis(
return mTxTimeMs; @IntRange(from = ModemActivityInfo.TX_POWER_LEVEL_0,
to = ModemActivityInfo.TX_POWER_LEVEL_4) int level) {
if (level >= mTxTimeMs.length) {
return -1;
}
return mTxTimeMs[level];
} }
/** /**
@@ -284,98 +336,8 @@ public final class CellularBatteryStats implements Parcelable {
return mMonitoredRailChargeConsumedMaMs; return mMonitoredRailChargeConsumedMaMs;
} }
/** @hide **/
public void setLoggingDurationMillis(long t) {
mLoggingDurationMs = t;
return;
}
/** @hide **/
public void setKernelActiveTimeMillis(long t) {
mKernelActiveTimeMs = t;
return;
}
/** @hide **/
public void setNumPacketsTx(long n) {
mNumPacketsTx = n;
return;
}
/** @hide **/
public void setNumBytesTx(long b) {
mNumBytesTx = b;
return;
}
/** @hide **/
public void setNumPacketsRx(long n) {
mNumPacketsRx = n;
return;
}
/** @hide **/
public void setNumBytesRx(long b) {
mNumBytesRx = b;
return;
}
/** @hide **/
public void setSleepTimeMillis(long t) {
mSleepTimeMs = t;
return;
}
/** @hide **/
public void setIdleTimeMillis(long t) {
mIdleTimeMs = t;
return;
}
/** @hide **/
public void setRxTimeMillis(long t) {
mRxTimeMs = t;
return;
}
/** @hide **/
public void setEnergyConsumedMaMillis(long e) {
mEnergyConsumedMaMs = e;
return;
}
/** @hide **/
public void setTimeInRatMicros(@NonNull long[] t) {
mTimeInRatMs = Arrays.copyOfRange(t, 0,
Math.min(t.length, BatteryStats.NUM_DATA_CONNECTION_TYPES));
return;
}
/** @hide **/
public void setTimeInRxSignalStrengthLevelMicros(@NonNull long[] t) {
mTimeInRxSignalStrengthLevelMs = Arrays.copyOfRange(t, 0,
Math.min(t.length, CellSignalStrength.getNumSignalStrengthLevels()));
return;
}
/** @hide **/
public void setTxTimeMillis(@NonNull long[] t) {
mTxTimeMs = Arrays.copyOfRange(t, 0, Math.min(t.length, ModemActivityInfo.TX_POWER_LEVELS));
return;
}
/** @hide **/
public void setMonitoredRailChargeConsumedMaMillis(long monitoredRailEnergyConsumedMaMs) {
mMonitoredRailChargeConsumedMaMs = monitoredRailEnergyConsumedMaMs;
return;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
private CellularBatteryStats(Parcel in) {
readFromParcel(in);
}
} }

View File

@@ -12598,7 +12598,6 @@ public class BatteryStatsImpl extends BatteryStats {
/*@hide */ /*@hide */
public CellularBatteryStats getCellularBatteryStats() { public CellularBatteryStats getCellularBatteryStats() {
CellularBatteryStats s = new CellularBatteryStats();
final int which = STATS_SINCE_CHARGED; final int which = STATS_SINCE_CHARGED;
final long rawRealTime = SystemClock.elapsedRealtime() * 1000; final long rawRealTime = SystemClock.elapsedRealtime() * 1000;
final ControllerActivityCounter counter = getModemControllerActivity(); final ControllerActivityCounter counter = getModemControllerActivity();
@@ -12625,21 +12624,16 @@ public class BatteryStatsImpl extends BatteryStats {
txTimeMs[i] = counter.getTxTimeCounters()[i].getCountLocked(which); txTimeMs[i] = counter.getTxTimeCounters()[i].getCountLocked(which);
totalTxTimeMs += txTimeMs[i]; totalTxTimeMs += txTimeMs[i];
} }
s.setLoggingDurationMillis(computeBatteryRealtime(rawRealTime, which) / 1000);
s.setKernelActiveTimeMillis(getMobileRadioActiveTime(rawRealTime, which) / 1000); return new CellularBatteryStats(computeBatteryRealtime(rawRealTime, which) / 1000,
s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); getMobileRadioActiveTime(rawRealTime, which) / 1000,
s.setNumBytesTx(getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which),
s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which),
s.setNumBytesRx(getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which),
s.setSleepTimeMillis(sleepTimeMs); getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which),
s.setIdleTimeMillis(idleTimeMs); sleepTimeMs, idleTimeMs, rxTimeMs, energyConsumedMaMs, timeInRatMs,
s.setRxTimeMillis(rxTimeMs); timeInRxSignalStrengthLevelMs, txTimeMs,
s.setEnergyConsumedMaMillis(energyConsumedMaMs); monitoredRailChargeConsumedMaMs);
s.setTimeInRatMicros(timeInRatMs);
s.setTimeInRxSignalStrengthLevelMicros(timeInRxSignalStrengthLevelMs);
s.setTxTimeMillis(txTimeMs);
s.setMonitoredRailChargeConsumedMaMillis(monitoredRailChargeConsumedMaMs);
return s;
} }
/*@hide */ /*@hide */

View File

@@ -16,6 +16,7 @@
package android.telephony; package android.telephony;
import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.os.Parcel; import android.os.Parcel;
@@ -23,6 +24,8 @@ import android.os.Parcelable;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Range; import android.util.Range;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -43,6 +46,38 @@ public final class ModemActivityInfo implements Parcelable {
* </ul> * </ul>
*/ */
public static final int TX_POWER_LEVELS = 5; public static final int TX_POWER_LEVELS = 5;
/**
* Tx(transmit) power level 0: tx_power < 0dBm
*/
public static final int TX_POWER_LEVEL_0 = 0;
/**
* Tx(transmit) power level 1: 0dBm < tx_power < 5dBm
*/
public static final int TX_POWER_LEVEL_1 = 1;
/**
* Tx(transmit) power level 2: 5dBm < tx_power < 15dBm
*/
public static final int TX_POWER_LEVEL_2 = 2;
/**
* Tx(transmit) power level 3: 15dBm < tx_power < 20dBm.
*/
public static final int TX_POWER_LEVEL_3 = 3;
/**
* Tx(transmit) power level 4: tx_power > 20dBm
*/
public static final int TX_POWER_LEVEL_4 = 4;
/** @hide */
@IntDef(prefix = {"TX_POWER_LEVEL_"}, value = {
TX_POWER_LEVEL_0,
TX_POWER_LEVEL_1,
TX_POWER_LEVEL_2,
TX_POWER_LEVEL_3,
TX_POWER_LEVEL_4,
})
@Retention(RetentionPolicy.SOURCE)
public @interface TxPowerLevel {}
private static final Range<Integer>[] TX_POWER_RANGES = new Range[] { private static final Range<Integer>[] TX_POWER_RANGES = new Range[] {
new Range<>(Integer.MIN_VALUE, 0), new Range<>(Integer.MIN_VALUE, 0),
new Range<>(0, 5), new Range<>(0, 5),