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

Commit d0cc7051 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Check for telephony features before using their APIs

Bug: 398045526
Bug: 396801499
Test: atest CtsCarTestCases
Test: atest AndroidAutomotiveNavigationBarTests:android.platform.tests.NavigationBarTest#testNotificationButton
Flag: EXEMPT bugfix
Change-Id: Ia402e0f56548d12e7d4ab50b911f0f5387b33a95
parent b5681d5d
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -203,7 +203,9 @@ public class CarrierTextManager {
            CarrierTextManagerLogger logger) {

        mContext = context;
        mIsEmergencyCallCapable = telephonyManager.isVoiceCapable();
        boolean hasTelephony = mContext.getPackageManager()
                .hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
        mIsEmergencyCallCapable = telephonyManager.isVoiceCapable() && hasTelephony;

        mShowAirplaneMode = showAirplaneMode;
        mShowMissingSim = showMissingSim;
@@ -221,9 +223,7 @@ public class CarrierTextManager {
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mLogger = logger;
        mBgExecutor.execute(() -> {
            boolean supported = mContext.getPackageManager()
                    .hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
            if (supported && mNetworkSupported.compareAndSet(false, supported)) {
            if (hasTelephony && mNetworkSupported.compareAndSet(false, hasTelephony)) {
                // This will set/remove the listeners appropriately. Note that it will never double
                // add the listeners.
                handleSetListening(mCarrierTextCallback);
+10 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.telephony.CarrierConfigManager
import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
@@ -191,6 +192,15 @@ constructor(
    override val isDeviceEmergencyCallCapable: StateFlow<Boolean> =
        serviceStateChangedEvent
            .mapLatest {
                // TODO(b/400460777): check for hasSystemFeature only once
                val hasRadioAccess: Boolean =
                    context.packageManager.hasSystemFeature(
                        PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS
                    )
                if (!hasRadioAccess) {
                    return@mapLatest false
                }

                val modems = telephonyManager.activeModemCount
                // Check the service state for every modem. If any state reports emergency calling
                // capable, then consider the device to have emergency call capabilities