Merge "Expose ModemActivitiyInfo to system API"
This commit is contained in:
@@ -7727,6 +7727,24 @@ package android.telephony {
|
||||
field public static final String MBMS_STREAMING_SERVICE_ACTION = "android.telephony.action.EmbmsStreaming";
|
||||
}
|
||||
|
||||
public final class ModemActivityInfo implements android.os.Parcelable {
|
||||
ctor public ModemActivityInfo(long, int, int, @NonNull int[], int);
|
||||
method public int describeContents();
|
||||
method public int getIdleTimeMillis();
|
||||
method public int getReceiveTimeMillis();
|
||||
method public int getSleepTimeMillis();
|
||||
method public long getTimestamp();
|
||||
method @NonNull public java.util.List<android.telephony.ModemActivityInfo.TransmitPower> getTransmitPowerInfo();
|
||||
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
|
||||
}
|
||||
|
||||
public class ModemActivityInfo.TransmitPower {
|
||||
method @NonNull public android.util.Range<java.lang.Integer> getPowerRangeInDbm();
|
||||
method public int getTimeInMillis();
|
||||
}
|
||||
|
||||
public final class NetworkRegistrationInfo implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method public int getAccessNetworkTechnology();
|
||||
|
||||
@@ -3968,7 +3968,7 @@ message ModemActivityInfo {
|
||||
// rx time in ms at power level 5
|
||||
optional uint64 controller_rx_time_millis = 9;
|
||||
// product of current(mA), voltage(V) and time(ms)
|
||||
optional uint64 energy_used = 10;
|
||||
optional uint64 energy_used = 10 [deprecated=true];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,6 +60,7 @@ import android.os.connectivity.WifiBatteryStats;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.DataConnectionRealTimeInfo;
|
||||
import android.telephony.ModemActivityInfo;
|
||||
import android.telephony.ModemActivityInfo.TransmitPower;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SignalStrength;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -10975,7 +10976,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
}
|
||||
|
||||
private ModemActivityInfo mLastModemActivityInfo =
|
||||
new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
|
||||
new ModemActivityInfo(0, 0, 0, new int[0], 0);
|
||||
|
||||
private ModemActivityInfo getDeltaModemActivityInfo(ModemActivityInfo activityInfo) {
|
||||
if (activityInfo == null) {
|
||||
@@ -10983,15 +10984,14 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
}
|
||||
int[] txTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
|
||||
for (int i = 0; i < ModemActivityInfo.TX_POWER_LEVELS; i++) {
|
||||
txTimeMs[i] = activityInfo.getTxTimeMillis()[i]
|
||||
- mLastModemActivityInfo.getTxTimeMillis()[i];
|
||||
txTimeMs[i] = activityInfo.getTransmitPowerInfo().get(i).getTimeInMillis()
|
||||
- mLastModemActivityInfo.getTransmitPowerInfo().get(i).getTimeInMillis();
|
||||
}
|
||||
ModemActivityInfo deltaInfo = new ModemActivityInfo(activityInfo.getTimestamp(),
|
||||
activityInfo.getSleepTimeMillis() - mLastModemActivityInfo.getSleepTimeMillis(),
|
||||
activityInfo.getIdleTimeMillis() - mLastModemActivityInfo.getIdleTimeMillis(),
|
||||
txTimeMs,
|
||||
activityInfo.getRxTimeMillis() - mLastModemActivityInfo.getRxTimeMillis(),
|
||||
activityInfo.getEnergyUsed() - mLastModemActivityInfo.getEnergyUsed());
|
||||
activityInfo.getReceiveTimeMillis() - mLastModemActivityInfo.getReceiveTimeMillis());
|
||||
mLastModemActivityInfo = activityInfo;
|
||||
return deltaInfo;
|
||||
}
|
||||
@@ -11034,10 +11034,11 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
deltaInfo.getIdleTimeMillis());
|
||||
mModemActivity.getSleepTimeCounter().addCountLocked(
|
||||
deltaInfo.getSleepTimeMillis());
|
||||
mModemActivity.getRxTimeCounter().addCountLocked(deltaInfo.getRxTimeMillis());
|
||||
mModemActivity.getRxTimeCounter().addCountLocked(deltaInfo.getReceiveTimeMillis());
|
||||
for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) {
|
||||
mModemActivity.getTxTimeCounters()[lvl]
|
||||
.addCountLocked(deltaInfo.getTxTimeMillis()[lvl]);
|
||||
.addCountLocked(deltaInfo.getTransmitPowerInfo()
|
||||
.get(lvl).getTimeInMillis());
|
||||
}
|
||||
|
||||
// POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V.
|
||||
@@ -11049,13 +11050,13 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_SLEEP)
|
||||
+ deltaInfo.getIdleTimeMillis() *
|
||||
mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_IDLE)
|
||||
+ deltaInfo.getRxTimeMillis() *
|
||||
+ deltaInfo.getReceiveTimeMillis() *
|
||||
mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_RX);
|
||||
int[] txTimeMs = deltaInfo.getTxTimeMillis();
|
||||
for (int i = 0; i < Math.min(txTimeMs.length,
|
||||
List<TransmitPower> txPowerInfo = deltaInfo.getTransmitPowerInfo();
|
||||
for (int i = 0; i < Math.min(txPowerInfo.size(),
|
||||
SignalStrength.NUM_SIGNAL_STRENGTH_BINS); i++) {
|
||||
energyUsed += txTimeMs[i] * mPowerProfile.getAveragePower(
|
||||
PowerProfile.POWER_MODEM_CONTROLLER_TX, i);
|
||||
energyUsed += txPowerInfo.get(i).getTimeInMillis() * mPowerProfile
|
||||
.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_TX, i);
|
||||
}
|
||||
|
||||
// We store the power drain as mAms.
|
||||
@@ -11144,15 +11145,16 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
ControllerActivityCounterImpl activityCounter =
|
||||
u.getOrCreateModemControllerActivityLocked();
|
||||
if (totalRxPackets > 0 && entry.rxPackets > 0) {
|
||||
final long rxMs = (entry.rxPackets * deltaInfo.getRxTimeMillis())
|
||||
/ totalRxPackets;
|
||||
final long rxMs = (entry.rxPackets
|
||||
* deltaInfo.getReceiveTimeMillis()) / totalRxPackets;
|
||||
activityCounter.getRxTimeCounter().addCountLocked(rxMs);
|
||||
}
|
||||
|
||||
if (totalTxPackets > 0 && entry.txPackets > 0) {
|
||||
for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) {
|
||||
long txMs =
|
||||
entry.txPackets * deltaInfo.getTxTimeMillis()[lvl];
|
||||
entry.txPackets * deltaInfo.getTransmitPowerInfo()
|
||||
.get(lvl).getTimeInMillis();
|
||||
txMs /= totalTxPackets;
|
||||
activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs);
|
||||
}
|
||||
@@ -11183,15 +11185,16 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
if (activityInfo == null) {
|
||||
return;
|
||||
}
|
||||
int[] txTimeMs = activityInfo.getTxTimeMillis();
|
||||
if (txTimeMs == null || txTimeMs.length != ModemActivityInfo.TX_POWER_LEVELS) {
|
||||
List<TransmitPower> txPowerInfo = activityInfo.getTransmitPowerInfo();
|
||||
if (txPowerInfo == null || txPowerInfo.size() != ModemActivityInfo.TX_POWER_LEVELS) {
|
||||
return;
|
||||
}
|
||||
final long elapsedRealtime = mClocks.elapsedRealtime();
|
||||
final long uptime = mClocks.uptimeMillis();
|
||||
int levelMaxTimeSpent = 0;
|
||||
for (int i = 1; i < txTimeMs.length; i++) {
|
||||
if (txTimeMs[i] > txTimeMs[levelMaxTimeSpent]) {
|
||||
for (int i = 1; i < txPowerInfo.size(); i++) {
|
||||
if (txPowerInfo.get(i).getTimeInMillis() > txPowerInfo.get(levelMaxTimeSpent)
|
||||
.getTimeInMillis()) {
|
||||
levelMaxTimeSpent = i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1112,13 +1112,12 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
||||
e.writeLong(modemInfo.getTimestamp());
|
||||
e.writeLong(modemInfo.getSleepTimeMillis());
|
||||
e.writeLong(modemInfo.getIdleTimeMillis());
|
||||
e.writeLong(modemInfo.getTxTimeMillis()[0]);
|
||||
e.writeLong(modemInfo.getTxTimeMillis()[1]);
|
||||
e.writeLong(modemInfo.getTxTimeMillis()[2]);
|
||||
e.writeLong(modemInfo.getTxTimeMillis()[3]);
|
||||
e.writeLong(modemInfo.getTxTimeMillis()[4]);
|
||||
e.writeLong(modemInfo.getRxTimeMillis());
|
||||
e.writeLong(modemInfo.getEnergyUsed());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(0).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(1).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(2).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(3).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getTransmitPowerInfo().get(4).getTimeInMillis());
|
||||
e.writeLong(modemInfo.getReceiveTimeMillis());
|
||||
pulledData.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,43 +16,65 @@
|
||||
|
||||
package android.telephony;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import android.util.Range;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Reports modem activity information
|
||||
* Reports modem activity information.
|
||||
* @hide
|
||||
*/
|
||||
public class ModemActivityInfo implements Parcelable {
|
||||
@SystemApi
|
||||
public final class ModemActivityInfo implements Parcelable {
|
||||
/**
|
||||
* Tx power index
|
||||
* index 0 = tx_power < 0dBm
|
||||
* index 1 = 0dBm < tx_power < 5dBm
|
||||
* index 2 = 5dBm < tx_power < 15dBm
|
||||
* index 3 = 15dBm < tx_power < 20dBm
|
||||
* index 4 = tx_power > 20dBm
|
||||
* Tx(transmit) power level. see power index 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>
|
||||
*/
|
||||
public static final int TX_POWER_LEVELS = 5;
|
||||
private static final Range<Integer>[] TX_POWER_RANGES = new Range[] {
|
||||
new Range<>(Integer.MIN_VALUE, 0),
|
||||
new Range<>(0, 5),
|
||||
new Range<>(5, 15),
|
||||
new Range<>(15, 20),
|
||||
new Range<>(20, Integer.MAX_VALUE)
|
||||
|
||||
};
|
||||
|
||||
private long mTimestamp;
|
||||
private int mSleepTimeMs;
|
||||
private int mIdleTimeMs;
|
||||
private int [] mTxTimeMs = new int[TX_POWER_LEVELS];
|
||||
private List<TransmitPower> mTransmitPowerInfo = new ArrayList<>(TX_POWER_LEVELS);
|
||||
private int mRxTimeMs;
|
||||
private int mEnergyUsed;
|
||||
|
||||
public ModemActivityInfo(long timestamp, int sleepTimeMs, int idleTimeMs,
|
||||
int[] txTimeMs, int rxTimeMs, int energyUsed) {
|
||||
@NonNull int[] txTimeMs, int rxTimeMs) {
|
||||
mTimestamp = timestamp;
|
||||
mSleepTimeMs = sleepTimeMs;
|
||||
mIdleTimeMs = idleTimeMs;
|
||||
if (txTimeMs != null) {
|
||||
System.arraycopy(txTimeMs, 0, mTxTimeMs, 0, Math.min(txTimeMs.length, TX_POWER_LEVELS));
|
||||
populateTransmitPowerRange(txTimeMs);
|
||||
}
|
||||
mRxTimeMs = rxTimeMs;
|
||||
mEnergyUsed = energyUsed;
|
||||
}
|
||||
|
||||
/** helper API to populate tx power range for each bucket **/
|
||||
private void populateTransmitPowerRange(@NonNull int[] transmitPowerMs) {
|
||||
for (int i = 0; i < Math.min(transmitPowerMs.length, TX_POWER_LEVELS); i++) {
|
||||
mTransmitPowerInfo.add(i, new TransmitPower(TX_POWER_RANGES[i], transmitPowerMs[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,9 +83,8 @@ public class ModemActivityInfo implements Parcelable {
|
||||
+ " mTimestamp=" + mTimestamp
|
||||
+ " mSleepTimeMs=" + mSleepTimeMs
|
||||
+ " mIdleTimeMs=" + mIdleTimeMs
|
||||
+ " mTxTimeMs[]=" + Arrays.toString(mTxTimeMs)
|
||||
+ " mTransmitPowerInfo[]=" + mTransmitPowerInfo.toString()
|
||||
+ " mRxTimeMs=" + mRxTimeMs
|
||||
+ " mEnergyUsed=" + mEnergyUsed
|
||||
+ "}";
|
||||
}
|
||||
|
||||
@@ -82,9 +103,8 @@ public class ModemActivityInfo implements Parcelable {
|
||||
txTimeMs[i] = in.readInt();
|
||||
}
|
||||
int rxTimeMs = in.readInt();
|
||||
int energyUsed = in.readInt();
|
||||
return new ModemActivityInfo(timestamp, sleepTimeMs, idleTimeMs,
|
||||
txTimeMs, rxTimeMs, energyUsed);
|
||||
txTimeMs, rxTimeMs);
|
||||
}
|
||||
|
||||
public ModemActivityInfo[] newArray(int size) {
|
||||
@@ -97,102 +117,153 @@ public class ModemActivityInfo implements Parcelable {
|
||||
dest.writeInt(mSleepTimeMs);
|
||||
dest.writeInt(mIdleTimeMs);
|
||||
for (int i = 0; i < TX_POWER_LEVELS; i++) {
|
||||
dest.writeInt(mTxTimeMs[i]);
|
||||
dest.writeInt(mTransmitPowerInfo.get(i).getTimeInMillis());
|
||||
}
|
||||
dest.writeInt(mRxTimeMs);
|
||||
dest.writeInt(mEnergyUsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return timestamp of record creation
|
||||
* @return milliseconds since boot, including mTimeInMillis spent in sleep.
|
||||
* @see SystemClock#elapsedRealtime()
|
||||
*/
|
||||
public long getTimestamp() {
|
||||
return mTimestamp;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void setTimestamp(long timestamp) {
|
||||
mTimestamp = timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return tx time in ms. It's an array of tx times
|
||||
* with each index...
|
||||
* @return an arrayList of {@link TransmitPower} with each element representing the total time where
|
||||
* transmitter is awake time (in ms) for a given power range (in dbm).
|
||||
*
|
||||
* @see #TX_POWER_LEVELS
|
||||
*/
|
||||
public int [] getTxTimeMillis() {
|
||||
return mTxTimeMs;
|
||||
@NonNull
|
||||
public List<TransmitPower> getTransmitPowerInfo() {
|
||||
return mTransmitPowerInfo;
|
||||
}
|
||||
|
||||
public void setTxTimeMillis(int[] txTimeMs) {
|
||||
mTxTimeMs = txTimeMs;
|
||||
/** @hide */
|
||||
public void setTransmitTimeMillis(int[] txTimeMs) {
|
||||
populateTransmitPowerRange(txTimeMs);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@NonNull
|
||||
public int[] getTransmitTimeMillis() {
|
||||
int[] transmitTimeMillis = new int[TX_POWER_LEVELS];
|
||||
for (int i = 0; i < transmitTimeMillis.length; i++) {
|
||||
transmitTimeMillis[i] = mTransmitPowerInfo.get(i).getTimeInMillis();
|
||||
}
|
||||
return transmitTimeMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sleep time in ms.
|
||||
* @return total mTimeInMillis (in ms) when modem is in a low power or sleep state.
|
||||
*/
|
||||
public int getSleepTimeMillis() {
|
||||
return mSleepTimeMs;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void setSleepTimeMillis(int sleepTimeMillis) {
|
||||
mSleepTimeMs = sleepTimeMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return idle time in ms.
|
||||
* @return total mTimeInMillis (in ms) when modem is awake but neither the transmitter nor receiver are
|
||||
* active.
|
||||
*/
|
||||
public int getIdleTimeMillis() {
|
||||
return mIdleTimeMs;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void setIdleTimeMillis(int idleTimeMillis) {
|
||||
mIdleTimeMs = idleTimeMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return rx time in ms.
|
||||
* @return rx(receive) mTimeInMillis in ms.
|
||||
*/
|
||||
public int getRxTimeMillis() {
|
||||
public int getReceiveTimeMillis() {
|
||||
return mRxTimeMs;
|
||||
}
|
||||
|
||||
public void setRxTimeMillis(int rxTimeMillis) {
|
||||
/** @hide */
|
||||
public void setReceiveTimeMillis(int rxTimeMillis) {
|
||||
mRxTimeMs = rxTimeMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* product of current(mA), voltage(V) and time(ms)
|
||||
* @return energy used
|
||||
*/
|
||||
public int getEnergyUsed () {
|
||||
return mEnergyUsed;
|
||||
}
|
||||
|
||||
public void setEnergyUsed(int energyUsed) {
|
||||
mEnergyUsed = energyUsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the record is valid
|
||||
* @return {@code true} if this {@link ModemActivityInfo} record is valid,
|
||||
* {@code false} otherwise.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public boolean isValid() {
|
||||
for (int txVal : getTxTimeMillis()) {
|
||||
if(txVal < 0) {
|
||||
for (TransmitPower powerInfo : getTransmitPowerInfo()) {
|
||||
if(powerInfo.getTimeInMillis() < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return ((getIdleTimeMillis() >= 0) && (getSleepTimeMillis() >= 0)
|
||||
&& (getRxTimeMillis() >= 0) && (getEnergyUsed() >= 0) && !isEmpty());
|
||||
&& (getReceiveTimeMillis() >= 0) && !isEmpty());
|
||||
}
|
||||
|
||||
private boolean isEmpty() {
|
||||
for (int txVal : getTxTimeMillis()) {
|
||||
if(txVal != 0) {
|
||||
for (TransmitPower txVal : getTransmitPowerInfo()) {
|
||||
if(txVal.getTimeInMillis() != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return ((getIdleTimeMillis() == 0) && (getSleepTimeMillis() == 0)
|
||||
&& (getRxTimeMillis() == 0) && (getEnergyUsed() == 0));
|
||||
&& (getReceiveTimeMillis() == 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Transmit power Information, including the power range in dbm and the total time (in ms) where
|
||||
* the transmitter is active/awake for this power range.
|
||||
* e.g, range: 0dbm(lower) ~ 5dbm(upper)
|
||||
* time: 5ms
|
||||
*/
|
||||
public class TransmitPower {
|
||||
private int mTimeInMillis;
|
||||
private Range<Integer> mPowerRangeInDbm;
|
||||
/** @hide */
|
||||
public TransmitPower(@NonNull Range<Integer> range, int time) {
|
||||
this.mTimeInMillis = time;
|
||||
this.mPowerRangeInDbm = range;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the total time in ms where the transmitter is active/wake for this power range
|
||||
* {@link #getPowerRangeInDbm()}.
|
||||
*/
|
||||
public int getTimeInMillis() {
|
||||
return mTimeInMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the power range in dbm. e.g, range: 0dbm(lower) ~ 5dbm(upper)
|
||||
*/
|
||||
@NonNull
|
||||
public Range<Integer> getPowerRangeInDbm() {
|
||||
return mPowerRangeInDbm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TransmitPower{"
|
||||
+ " mTimeInMillis=" + mTimeInMillis
|
||||
+ " mPowerRangeInDbm={" + mPowerRangeInDbm.getLower()
|
||||
+ "," + mPowerRangeInDbm.getUpper()
|
||||
+ "}}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user