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

Commit 149bcd69 authored by Michael Wachenschwanz's avatar Michael Wachenschwanz
Browse files

Record NR State changes in BatteryHistory and track NR NSA time.

Add NR state awareness to BatteryStats. This allows the ability to
distinguish an NR NSA mode connection (which is the combine state
of Network type == LTE and NR state == connected).

Fixes: 282770637
Test: atest BatteryStatsHistoryTest
Test: atest BatteryStatsNoteTest
Change-Id: I335c9a0c22e662ae8c86f77cc5b3debd71b76bb6
parent 4a12d7bd
Loading
Loading
Loading
Loading
+35 −4
Original line number Original line 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_SHIFT = 7;
        public static final int STATE2_GPS_SIGNAL_QUALITY_MASK =
        public static final int STATE2_GPS_SIGNAL_QUALITY_MASK =
                0x3 << STATE2_GPS_SIGNAL_QUALITY_SHIFT;
                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_POWER_SAVE_FLAG = 1<<31;
        public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
        public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
@@ -2763,6 +2766,14 @@ public abstract class BatteryStats {
     */
     */
    public abstract Timer getPhoneDataConnectionTimer(int dataType);
    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 */
    /** @hide */
    public static final int RADIO_ACCESS_TECHNOLOGY_OTHER = 0;
    public static final int RADIO_ACCESS_TECHNOLOGY_OTHER = 0;
    /** @hide */
    /** @hide */
@@ -3029,7 +3040,11 @@ public abstract class BatteryStats {
                "cellular_high_tx_power", "Chtp"),
                "cellular_high_tx_power", "Chtp"),
        new BitDescription(HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK,
        new BitDescription(HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK,
            HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT, "gps_signal_quality", "Gss",
            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[] {
    public static final String[] HISTORY_EVENT_NAMES = new String[] {
@@ -5612,20 +5627,36 @@ public abstract class BatteryStats {
        sb.append(prefix);
        sb.append(prefix);
        sb.append("     Cellular Radio Access Technology:");
        sb.append("     Cellular Radio Access Technology:");
        didOne = false;
        didOne = false;
        for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
        for (int connType = 0; connType < NUM_DATA_CONNECTION_TYPES; connType++) {
            final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
            final long time = getPhoneDataConnectionTime(connType, rawRealtime, which);
            if (time == 0) {
            if (time == 0) {
                continue;
                continue;
            }
            }
            sb.append("\n       ");
            sb.append("\n       ");
            sb.append(prefix);
            sb.append(prefix);
            didOne = true;
            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(" ");
            sb.append(" ");
            formatTimeMs(sb, time/1000);
            formatTimeMs(sb, time/1000);
            sb.append("(");
            sb.append("(");
            sb.append(formatRatioLocked(time, whichBatteryRealtime));
            sb.append(formatRatioLocked(time, whichBatteryRealtime));
            sb.append(") ");
            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)");
        if (!didOne) sb.append(" (no activity)");
        pw.println(sb.toString());
        pw.println(sb.toString());
+2 −1
Original line number Original line Diff line number Diff line
@@ -158,7 +158,8 @@ interface IBatteryStats {
    @EnforcePermission("UPDATE_DEVICE_STATS")
    @EnforcePermission("UPDATE_DEVICE_STATS")
    void notePhoneSignalStrength(in SignalStrength signalStrength);
    void notePhoneSignalStrength(in SignalStrength signalStrength);
    @EnforcePermission("UPDATE_DEVICE_STATS")
    @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")
    @EnforcePermission("UPDATE_DEVICE_STATS")
    void notePhoneState(int phoneState);
    void notePhoneState(int phoneState);
    @EnforcePermission("UPDATE_DEVICE_STATS")
    @EnforcePermission("UPDATE_DEVICE_STATS")
+13 −1
Original line number Original line Diff line number Diff line
@@ -1221,6 +1221,17 @@ public class BatteryStatsHistory {
        writeHistoryItem(elapsedRealtimeMs, uptimeMs);
        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.
     * Records a WiFi supplicant state change event.
     */
     */
@@ -1552,7 +1563,7 @@ public class BatteryStatsHistory {


        State2 change int: if C in the first token is set,
        State2 change int: if C in the first token is set,
        31              23              15               7             0
        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}.
        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.
        B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4.
@@ -1568,6 +1579,7 @@ public class BatteryStatsHistory {
        L: video was playing.
        L: video was playing.
        M: power save mode was on.
        M: power save mode was on.
        N: 2 bits indicating the gps signal strength: poor, good, none.
        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,
        Wakelock/wakereason struct: if D in the first token is set,
        Event struct: if E in the first token is set,
        Event struct: if E in the first token is set,
+4 −2
Original line number Original line Diff line number Diff line
@@ -84,6 +84,7 @@ import android.power.PowerStatsInternal;
import android.provider.Settings;
import android.provider.Settings;
import android.telephony.DataConnectionRealTimeInfo;
import android.telephony.DataConnectionRealTimeInfo;
import android.telephony.ModemActivityInfo;
import android.telephony.ModemActivityInfo;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.SignalStrength;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.util.IndentingPrintWriter;
import android.util.IndentingPrintWriter;
@@ -1586,7 +1587,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    @Override
    @Override
    @EnforcePermission(UPDATE_DEVICE_STATS)
    @EnforcePermission(UPDATE_DEVICE_STATS)
    public void notePhoneDataConnectionState(final int dataType, final boolean hasData,
    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();
        super.notePhoneDataConnectionState_enforcePermission();


        synchronized (mLock) {
        synchronized (mLock) {
@@ -1595,7 +1597,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
            mHandler.post(() -> {
            mHandler.post(() -> {
                synchronized (mStats) {
                synchronized (mStats) {
                    mStats.notePhoneDataConnectionStateLocked(dataType, hasData, serviceType,
                    mStats.notePhoneDataConnectionStateLocked(dataType, hasData, serviceType,
                            nrFrequency, elapsedRealtime, uptime);
                            nrState, nrFrequency, elapsedRealtime, uptime);
                }
                }
            });
            });
        }
        }
+1 −6
Original line number Original line Diff line number Diff line
@@ -98,18 +98,13 @@ public class DataConnectionStats extends BroadcastReceiver {
                mServiceState.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN);
                mServiceState.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN);
        int networkType = regInfo == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN
        int networkType = regInfo == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN
                : regInfo.getAccessNetworkTechnology();
                : 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) {
        if (DEBUG) {
            Log.d(TAG, String.format("Noting data connection for network type %s: %svisible",
            Log.d(TAG, String.format("Noting data connection for network type %s: %svisible",
                    networkType, visible ? "" : "not "));
                    networkType, visible ? "" : "not "));
        }
        }
        try {
        try {
            mBatteryStats.notePhoneDataConnectionState(networkType, visible,
            mBatteryStats.notePhoneDataConnectionState(networkType, visible,
                    mServiceState.getState(), mServiceState.getNrFrequencyRange());
                    mServiceState.getState(), mNrState, mServiceState.getNrFrequencyRange());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.w(TAG, "Error noting data connection state", e);
            Log.w(TAG, "Error noting data connection state", e);
        }
        }
Loading