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

Commit 502ec035 authored by Evan Laird's avatar Evan Laird
Browse files

[Sb] Add prioritize_latency tracking in mobile connections

This CL adds a network callback -- registered via ConnectivityManager --
for every mobile subscription that we know about. This amounts to one
listeners per subId (more on that below). The network callback is
registered only to receive information about _that_ subId's network
pertaining to the NET_CAPABILITY_PRIORITIZE_LATENCY. We'll use this flag
downstream to determine whether or not to show a network slice
attribution.

On ConnectivityManager's callback list:
  The docs on ConnectivityManagerService claims that we should be careful
about too many callbacks registered with the system. If we need to get
rid of the 1:1 mapping from subscription to registrant, then we would
have to do some work to register a _single_ callback that maintained a
map of <netId, networkCapabilities>. It would also presumably have to be
eagerly listening, and make sure to update the map whenever a network
disappears
  Note that this doesn't actually give us a huge performance benefit
from what I can tell. This is because our single registrant would still
get a callback-per-network in which the capabilities changed. Therefore,
we still get the penalty of N incoming IPCs when there are N networks
that meet the criteria. So we only should worry about that in the case
where we run close to the limit of 100 subscribers per process.

Test: tests in statusbar/pipeline
Bug: 270385675
Change-Id: If42b52ad6e14bdc258c90761e3e6dd629bbe9d3d
parent 171f2e42
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -190,6 +190,24 @@ constructor(
    fun logOnSimStateChanged() {
        buffer.log(TAG, LogLevel.INFO, "onSimStateChanged")
    }

    fun logPrioritizedNetworkAvailable(netId: Int) {
        buffer.log(
            TAG,
            LogLevel.INFO,
            { int1 = netId },
            { "Found prioritized network (nedId=$int1)" },
        )
    }

    fun logPrioritizedNetworkLost(netId: Int) {
        buffer.log(
            TAG,
            LogLevel.INFO,
            { int1 = netId },
            { "Lost prioritized network (nedId=$int1)" },
        )
    }
}

private const val TAG = "MobileInputLog"
+6 −0
Original line number Diff line number Diff line
@@ -131,6 +131,12 @@ interface MobileConnectionRepository {
     */
    val isAllowedDuringAirplaneMode: StateFlow<Boolean>

    /**
     * True if this network has NET_CAPABILITIY_PRIORITIZE_LATENCY, and can be considered to be a
     * network slice
     */
    val hasPrioritizedNetworkCapabilities: StateFlow<Boolean>

    companion object {
        /** The default number of levels to use for [numberOfLevels]. */
        const val DEFAULT_NUM_LEVELS = 4
+4 −0
Original line number Diff line number Diff line
@@ -191,6 +191,8 @@ class DemoMobileConnectionRepository(

    override val isAllowedDuringAirplaneMode = MutableStateFlow(false)

    override val hasPrioritizedNetworkCapabilities = MutableStateFlow(false)

    /**
     * Process a new demo mobile event. Note that [resolvedNetworkType] must be passed in separately
     * from the event, due to the requirement to reverse the mobile mappings lookup in the top-level
@@ -225,6 +227,7 @@ class DemoMobileConnectionRepository(
        _resolvedNetworkType.value = resolvedNetworkType

        isAllowedDuringAirplaneMode.value = false
        hasPrioritizedNetworkCapabilities.value = event.slice
    }

    fun processCarrierMergedEvent(event: FakeWifiEventModel.CarrierMerged) {
@@ -250,6 +253,7 @@ class DemoMobileConnectionRepository(
        _isGsm.value = false
        _carrierNetworkChangeActive.value = false
        isAllowedDuringAirplaneMode.value = true
        hasPrioritizedNetworkCapabilities.value = false
    }

    companion object {
+2 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ constructor(
        val carrierNetworkChange = getString("carriernetworkchange") == "show"
        val roaming = getString("roam") == "show"
        val name = getString("networkname") ?: "demo mode"
        val slice = getString("slice").toBoolean()

        return Mobile(
            level = level,
@@ -87,6 +88,7 @@ constructor(
            carrierNetworkChange = carrierNetworkChange,
            roaming = roaming,
            name = name,
            slice = slice,
        )
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ sealed interface FakeNetworkEventModel {
        val carrierNetworkChange: Boolean,
        val roaming: Boolean,
        val name: String,
        val slice: Boolean = false,
    ) : FakeNetworkEventModel

    data class MobileDisabled(
Loading