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

Commit 39333536 authored by Michael Wachenschwanz's avatar Michael Wachenschwanz Committed by Android (Google) Code Review
Browse files

Merge "Record NR State changes in BatteryHistory and track NR NSA time." into main

parents cf01441d 149bcd69
Loading
Loading
Loading
Loading
+35 −4
Original line number Diff line number Diff line
@@ -1968,6 +1968,9 @@ public abstract class BatteryStats {
        public static final int STATE2_GPS_SIGNAL_QUALITY_SHIFT = 7;
        public static final int STATE2_GPS_SIGNAL_QUALITY_MASK =
                0x3 << STATE2_GPS_SIGNAL_QUALITY_SHIFT;
        // Values for NR_STATE_*
        public static final int STATE2_NR_STATE_SHIFT = 9;
        public static final int STATE2_NR_STATE_MASK = 0x3 << STATE2_NR_STATE_SHIFT;

        public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
        public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
@@ -2763,6 +2766,14 @@ public abstract class BatteryStats {
     */
    public abstract Timer getPhoneDataConnectionTimer(int dataType);

    /**
     * Returns the time in microseconds that the phone's data connection was in NR NSA mode while
     * on battery.
     *
     * {@hide}
     */
    public abstract long getNrNsaTime(long elapsedRealtimeUs);

    /** @hide */
    public static final int RADIO_ACCESS_TECHNOLOGY_OTHER = 0;
    /** @hide */
@@ -3029,7 +3040,11 @@ public abstract class BatteryStats {
                "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", "none"}, new String[] { "poor", "good", "none"})
            new String[] { "poor", "good", "none"}, new String[] { "poor", "good", "none"}),
        new BitDescription(HistoryItem.STATE2_NR_STATE_MASK,
            HistoryItem.STATE2_NR_STATE_SHIFT, "nr_state", "nrs",
            new String[]{"none", "restricted", "not_restricted", "connected"},
            new String[]{"0", "1", "2", "3"}),
    };

    public static final String[] HISTORY_EVENT_NAMES = new String[] {
@@ -5612,20 +5627,36 @@ public abstract class BatteryStats {
        sb.append(prefix);
        sb.append("     Cellular Radio Access Technology:");
        didOne = false;
        for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
            final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
        for (int connType = 0; connType < NUM_DATA_CONNECTION_TYPES; connType++) {
            final long time = getPhoneDataConnectionTime(connType, rawRealtime, which);
            if (time == 0) {
                continue;
            }
            sb.append("\n       ");
            sb.append(prefix);
            didOne = true;
            sb.append(i < DATA_CONNECTION_NAMES.length ? DATA_CONNECTION_NAMES[i] : "ERROR");
            sb.append(connType < DATA_CONNECTION_NAMES.length ?
                DATA_CONNECTION_NAMES[connType] : "ERROR");
            sb.append(" ");
            formatTimeMs(sb, time/1000);
            sb.append("(");
            sb.append(formatRatioLocked(time, whichBatteryRealtime));
            sb.append(") ");

            if (connType == TelephonyManager.NETWORK_TYPE_LTE) {
                // Report any of the LTE time was spent in NR NSA mode.
                final long nrNsaTime = getNrNsaTime(rawRealtime);
                if (nrNsaTime != 0) {
                    sb.append("\n         ");
                    sb.append(prefix);
                    sb.append("nr_nsa");
                    sb.append(" ");
                    formatTimeMs(sb, nrNsaTime / 1000);
                    sb.append("(");
                    sb.append(formatRatioLocked(nrNsaTime, whichBatteryRealtime));
                    sb.append(") ");
                }
            }
        }
        if (!didOne) sb.append(" (no activity)");
        pw.println(sb.toString());
+2 −1
Original line number Diff line number Diff line
@@ -158,7 +158,8 @@ interface IBatteryStats {
    @EnforcePermission("UPDATE_DEVICE_STATS")
    void notePhoneSignalStrength(in SignalStrength signalStrength);
    @EnforcePermission("UPDATE_DEVICE_STATS")
    void notePhoneDataConnectionState(int dataType, boolean hasData, int serviceType, int nrFrequency);
    void notePhoneDataConnectionState(int dataType, boolean hasData, int serviceType, int nrState,
            int nrFrequency);
    @EnforcePermission("UPDATE_DEVICE_STATS")
    void notePhoneState(int phoneState);
    @EnforcePermission("UPDATE_DEVICE_STATS")
+13 −1
Original line number Diff line number Diff line
@@ -1225,6 +1225,17 @@ public class BatteryStatsHistory {
        writeHistoryItem(elapsedRealtimeMs, uptimeMs);
    }

    /**
     * Records a data connection type change event.
     */
    public void recordNrStateChangeEvent(long elapsedRealtimeMs, long uptimeMs,
            int nrState) {
        mHistoryCur.states2 = setBitField(mHistoryCur.states2, nrState,
                HistoryItem.STATE2_NR_STATE_SHIFT,
                HistoryItem.STATE2_NR_STATE_MASK);
        writeHistoryItem(elapsedRealtimeMs, uptimeMs);
    }

    /**
     * Records a WiFi supplicant state change event.
     */
@@ -1556,7 +1567,7 @@ public class BatteryStatsHistory {

        State2 change int: if C in the first token is set,
        31              23              15               7             0
        █M|L|K|J|I|H|H|G█F|E|D|C| | | | █ | | | | | | |N█N|B|B|B|A|A|A|A█
        █M|L|K|J|I|H|H|G█F|E|D|C| | | | █ | | | | |O|O|N█N|B|B|B|A|A|A|A█

        A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}.
        B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4.
@@ -1572,6 +1583,7 @@ public class BatteryStatsHistory {
        L: video was playing.
        M: power save mode was on.
        N: 2 bits indicating the gps signal strength: poor, good, none.
        O: 2 bits indicating nr state: none, restricted, not restricted, connected.

        Wakelock/wakereason struct: if D in the first token is set,
        Event struct: if E in the first token is set,
+4 −2
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import android.power.PowerStatsInternal;
import android.provider.Settings;
import android.telephony.DataConnectionRealTimeInfo;
import android.telephony.ModemActivityInfo;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.IndentingPrintWriter;
@@ -1587,7 +1588,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    @Override
    @EnforcePermission(UPDATE_DEVICE_STATS)
    public void notePhoneDataConnectionState(final int dataType, final boolean hasData,
            final int serviceType, final int nrFrequency) {
            final int serviceType, @NetworkRegistrationInfo.NRState final int nrState,
            final int nrFrequency) {
        super.notePhoneDataConnectionState_enforcePermission();

        synchronized (mLock) {
@@ -1596,7 +1598,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
            mHandler.post(() -> {
                synchronized (mStats) {
                    mStats.notePhoneDataConnectionStateLocked(dataType, hasData, serviceType,
                            nrFrequency, elapsedRealtime, uptime);
                            nrState, nrFrequency, elapsedRealtime, uptime);
                }
            });
        }
+1 −6
Original line number Diff line number Diff line
@@ -98,18 +98,13 @@ public class DataConnectionStats extends BroadcastReceiver {
                mServiceState.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN);
        int networkType = regInfo == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN
                : regInfo.getAccessNetworkTechnology();
        // If the device is in NSA NR connection the networkType will report as LTE.
        // For cell dwell rate metrics, this should report NR instead.
        if (mNrState == NetworkRegistrationInfo.NR_STATE_CONNECTED) {
            networkType = TelephonyManager.NETWORK_TYPE_NR;
        }
        if (DEBUG) {
            Log.d(TAG, String.format("Noting data connection for network type %s: %svisible",
                    networkType, visible ? "" : "not "));
        }
        try {
            mBatteryStats.notePhoneDataConnectionState(networkType, visible,
                    mServiceState.getState(), mServiceState.getNrFrequencyRange());
                    mServiceState.getState(), mNrState, mServiceState.getNrFrequencyRange());
        } catch (RemoteException e) {
            Log.w(TAG, "Error noting data connection state", e);
        }
Loading