Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be50af21 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents baed20e4 53515a0e
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -8857,9 +8857,9 @@ package android.os.connectivity {
    method public long getNumPacketsTx();
    method public long getRxTimeMillis();
    method public long getSleepTimeMillis();
    method @NonNull public long[] getTimeInRatMicros();
    method @NonNull public long[] getTimeInRxSignalStrengthLevelMicros();
    method @NonNull public long[] getTxTimeMillis();
    method @NonNull public long getTimeInRatMicros(int);
    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(@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);
    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);
    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_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 {
+104 −142
Original line number Diff line number Diff line
@@ -15,8 +15,10 @@
 */
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;
@@ -36,26 +38,44 @@ import java.util.Objects;
@SystemApi
public final class CellularBatteryStats implements Parcelable {

    private long mLoggingDurationMs = 0;
    private long mKernelActiveTimeMs = 0;
    private long mNumPacketsTx = 0;
    private long mNumBytesTx = 0;
    private long mNumPacketsRx = 0;
    private long mNumBytesRx = 0;
    private long mSleepTimeMs = 0;
    private long mIdleTimeMs = 0;
    private long mRxTimeMs = 0;
    private long mEnergyConsumedMaMs = 0;
    private long[] mTimeInRatMs = new long[BatteryStats.NUM_DATA_CONNECTION_TYPES];
    private long[] mTimeInRxSignalStrengthLevelMs =
            new long[CellSignalStrength.getNumSignalStrengthLevels()];
    private long[] mTxTimeMs = new long[ModemActivityInfo.TX_POWER_LEVELS];
    private long mMonitoredRailChargeConsumedMaMs = 0;
    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) {
                    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) {
@@ -64,7 +84,34 @@ public final class CellularBatteryStats implements Parcelable {
            };

    /** @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
    public void writeToParcel(@NonNull Parcel out, int flags) {
@@ -84,23 +131,6 @@ public final class CellularBatteryStats implements Parcelable {
        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
    public boolean equals(@Nullable Object other) {
        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
     * the given data connection.
     *
     * @return Amount of time phone spends in various Radio Access Technologies in microseconds.
     * The index is {@link NetworkType}.
     * @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
    public long[] getTimeInRatMicros() {
        return mTimeInRatMs;
    @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.
     *
     * @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.
     */
    @NonNull
    public long[] getTimeInRxSignalStrengthLevelMicros() {
        return mTimeInRxSignalStrengthLevelMs;
    @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()}.
     *
     * @return Duration of cellular transmission time in milliseconds.
     * Tx(transmit) power index below
     * @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>
@@ -271,8 +317,14 @@ public final class CellularBatteryStats implements Parcelable {
     * </ul>
     */
    @NonNull
    public long[] getTxTimeMillis() {
        return mTxTimeMs;
    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];
    }

    /**
@@ -284,98 +336,8 @@ public final class CellularBatteryStats implements Parcelable {
        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
    public int describeContents() {
        return 0;
    }

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

package android.telephony;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
@@ -23,6 +24,8 @@ import android.os.Parcelable;
import android.os.SystemClock;
import android.util.Range;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;

@@ -43,6 +46,38 @@ public final class ModemActivityInfo implements Parcelable {
     * </ul>
     */
    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[] {
        new Range<>(Integer.MIN_VALUE, 0),
        new Range<>(0, 5),