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

Commit f5e796a0 authored by Siddharth Ray's avatar Siddharth Ray
Browse files

Cellular Tx power added to Volta historian

A flag in historian is added to identify time periods where the
cellular radio is transmitting at the highest power level.

BUG:38354995
Change-Id: Ib89a505636c1d5aa66f8c19690742dde9d40fe61
parent 451832a5
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1537,6 +1537,7 @@ public abstract class BatteryStats implements Parcelable {
        public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
        public static final int STATE2_CAMERA_FLAG = 1<<21;
        public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
        public static final int STATE2_CELLULAR_HIGH_TX_POWER_FLAG = 1 << 19;

        public static final int MOST_INTERESTING_STATES2 =
                STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
@@ -2353,9 +2354,11 @@ public abstract class BatteryStats implements Parcelable {
                WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
        new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
        new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
        new BitDescription(HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG,
                "cellular_high_tx_power", "Chtp"),
        new BitDescription(HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK,
            HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT, "gps_signal_quality", "Gss",
            new String[] { "poor", "good"}, new String[] { "poor", "good"}),
            new String[] { "poor", "good"}, new String[] { "poor", "good"})
    };

    public static final String[] HISTORY_EVENT_NAMES = new String[] {
+45 −0
Original line number Diff line number Diff line
@@ -760,6 +760,8 @@ public class BatteryStatsImpl extends BatteryStats {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    protected StopwatchTimer mBluetoothScanTimer;
    boolean mIsCellularTxPowerHigh = false;
    int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
    long mMobileRadioActiveStartTime;
    StopwatchTimer mMobileRadioActiveTimer;
@@ -11214,6 +11216,9 @@ public class BatteryStatsImpl extends BatteryStats {
            Slog.d(TAG, "Updating mobile radio stats with " + activityInfo);
        }
        // Add modem tx power to history.
        addModemTxPowerToHistory(activityInfo);
        // Grab a separate lock to acquire the network stats, which may do I/O.
        NetworkStats delta = null;
        synchronized (mModemNetworkLock) {
@@ -11387,6 +11392,44 @@ public class BatteryStatsImpl extends BatteryStats {
    private BluetoothActivityEnergyInfo mLastBluetoothActivityEnergyInfo =
            new BluetoothActivityEnergyInfo(0, 0, 0, 0, 0, 0);
    /**
     * Add modem tx power to history
     * Device is said to be in high cellular transmit power when it has spent most of the transmit
     * time at the highest power level.
     * @param activityInfo
     */
    private void addModemTxPowerToHistory(final ModemActivityInfo activityInfo) {
        if (activityInfo == null) {
            return;
        }
        int[] txTimeMs = activityInfo.getTxTimeMillis();
        if (txTimeMs == null || txTimeMs.length != 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]) {
                levelMaxTimeSpent = i;
            }
        }
        if (levelMaxTimeSpent == ModemActivityInfo.TX_POWER_LEVELS - 1) {
            if (!mIsCellularTxPowerHigh) {
                mHistoryCur.states2 |= HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG;
                addHistoryRecordLocked(elapsedRealtime, uptime);
                mIsCellularTxPowerHigh = true;
            }
            return;
        }
        if (mIsCellularTxPowerHigh) {
            mHistoryCur.states2 &= ~HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG;
            addHistoryRecordLocked(elapsedRealtime, uptime);
            mIsCellularTxPowerHigh = false;
        }
        return;
    }
    /**
     * Distribute Bluetooth energy info and network traffic to apps.
     * @param info The energy information from the bluetooth controller.
@@ -13542,6 +13585,7 @@ public class BatteryStatsImpl extends BatteryStats {
        mCameraOnTimer.readSummaryFromParcelLocked(in);
        mBluetoothScanNesting = 0;
        mBluetoothScanTimer.readSummaryFromParcelLocked(in);
        mIsCellularTxPowerHigh = false;
        int NRPMS = in.readInt();
        if (NRPMS > 10000) {
@@ -14478,6 +14522,7 @@ public class BatteryStatsImpl extends BatteryStats {
        mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in);
        mBluetoothScanNesting = 0;
        mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in);
        mIsCellularTxPowerHigh = false;
        mDischargeUnplugLevel = in.readInt();
        mDischargePlugLevel = in.readInt();
        mDischargeCurrentLevel = in.readInt();