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

Commit dcbe421c authored by Evan Laird's avatar Evan Laird
Browse files

[Sb][Mobile] Listen for service states via broadcast for subId = -1

We already have tracking for service state for any valid subscription,
via the individual `MobileConnectionRepository` classes. However, there
are cases when there is a device-based state (in this case, emergency
calls only) that can be surfaced to SystemUI via the
ACTION_SERVICE_STATE intent. In these cases, the subscription id from
the intent is -1, and can be interpreted on our end as device state.

This change adds tracking specifically for the `ServiceState` for the
subId=-1 case, and exposes the emergency calls only state to the
MobileIconsInteractor.

Follow-up CLs will use this bit to better calculate the calling state of
the device for the sake of showing satellite iconography.

Flag: EXEMPT bugfix
Bug: 339023069
Test: MobileConnectionsRepositoryTest
Test: MobileIconsInteractorTest
Change-Id: I7cc0aee2d6f579d2027ea1f0ffdc64486126664d
parent 37a405ee
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -53,6 +53,27 @@ constructor(
        )
    }

    fun logTopLevelServiceStateBroadcastEmergencyOnly(subId: Int, serviceState: ServiceState) {
        buffer.log(
            TAG,
            LogLevel.INFO,
            {
                int1 = subId
                bool1 = serviceState.isEmergencyOnly
            },
            { "ACTION_SERVICE_STATE for subId=$int1. ServiceState.isEmergencyOnly=$bool1" }
        )
    }

    fun logTopLevelServiceStateBroadcastMissingExtras(subId: Int) {
        buffer.log(
            TAG,
            LogLevel.INFO,
            { int1 = subId },
            { "ACTION_SERVICE_STATE for subId=$int1. Intent is missing extras. Ignoring" }
        )
    }

    fun logOnSignalStrengthsChanged(signalStrength: SignalStrength, subId: Int) {
        buffer.log(
            TAG,
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.pipeline.mobile.data.model

import android.telephony.ServiceState

/**
 * Simplified representation of a [ServiceState] for use in SystemUI. Add any fields that we need to
 * extract from service state here for consumption downstream
 */
data class ServiceStateModel(val isEmergencyOnly: Boolean) {
    companion object {
        fun fromServiceState(serviceState: ServiceState): ServiceStateModel {
            return ServiceStateModel(isEmergencyOnly = serviceState.isEmergencyOnly)
        }
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.telephony.SubscriptionManager
import com.android.settingslib.SignalIcon.MobileIconGroup
import com.android.settingslib.mobile.MobileMappings
import com.android.settingslib.mobile.MobileMappings.Config
import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
@@ -91,6 +92,19 @@ interface MobileConnectionsRepository {
    /** Fallback [MobileIconGroup] in the case where there is no icon in the mapping */
    val defaultMobileIconGroup: Flow<MobileIconGroup>

    /**
     * [deviceServiceState] is equivalent to the last [Intent.ACTION_SERVICE_STATE] broadcast with a
     * subscriptionId of -1 (aka [SubscriptionManager.INVALID_SUBSCRIPTION_ID]).
     *
     * While each [MobileConnectionsRepository] listens for the service state of each subscription,
     * there is potentially a service state associated with the device itself. This value can be
     * used to calculate e.g., the emergency calling capability of the device (as opposed to the
     * emergency calling capability of an individual mobile connection)
     *
     * Note: this is a [StateFlow] using an eager sharing strategy.
     */
    val deviceServiceState: StateFlow<ServiceStateModel?>

    /**
     * If any active SIM on the device is in
     * [android.telephony.TelephonyManager.SIM_STATE_PIN_REQUIRED] or
+10 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.demomode.DemoMode
import com.android.systemui.demomode.DemoModeController
import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.DemoMobileConnectionsRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.prod.MobileConnectionsRepositoryImpl
@@ -151,6 +152,15 @@ constructor(
    override val defaultMobileIconGroup: Flow<SignalIcon.MobileIconGroup> =
        activeRepo.flatMapLatest { it.defaultMobileIconGroup }

    override val deviceServiceState: StateFlow<ServiceStateModel?> =
        activeRepo
            .flatMapLatest { it.deviceServiceState }
            .stateIn(
                scope,
                SharingStarted.WhileSubscribed(),
                realRepository.deviceServiceState.value
            )

    override val isAnySimSecure: Flow<Boolean> = activeRepo.flatMapLatest { it.isAnySimSecure }
    override fun getIsAnySimSecure(): Boolean = activeRepo.value.getIsAnySimSecure()

+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.table.TableLogBufferFactory
import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType
import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.DefaultNetworkType
import com.android.systemui.statusbar.pipeline.mobile.data.model.ServiceStateModel
import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
@@ -136,6 +137,9 @@ constructor(

    override val defaultMobileIconGroup = flowOf(TelephonyIcons.THREE_G)

    // TODO(b/339023069): demo command for device-based connectivity state
    override val deviceServiceState: StateFlow<ServiceStateModel?> = MutableStateFlow(null)

    override val isAnySimSecure: Flow<Boolean> = flowOf(getIsAnySimSecure())
    override fun getIsAnySimSecure(): Boolean = false

Loading