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

Commit 8f6145c1 authored by songferngwang's avatar songferngwang
Browse files

Add the condition to hide the MMS messages preference

If the carrier config KEY_MMS_MMS_ENABLED_BOOL is false, then the
settings hide the MMS messages preference

Test: atest MmsMessagePreferenceControllerTest
Bug: 371965435
Flag: EXEMPT bugfix
Change-Id: I93479bba28120f7b6cc5449f4a8277945d308e40
parent fd699a75
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -224,7 +224,10 @@ class CarrierConfigRepository(private val context: Context) {
        }

        private val BooleanKeysWhichNotFollowingsNamingConventions =
            listOf(CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
            listOf(
                CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS,
                CarrierConfigManager.KEY_MMS_MMS_ENABLED_BOOL,
            )

        private fun checkBooleanKey(key: String) {
            check(key.endsWith("_bool") || key in BooleanKeysWhichNotFollowingsNamingConventions) {
+19 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.network.telephony

import android.content.Context
import android.telephony.CarrierConfigManager
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
import android.telephony.data.ApnSetting
@@ -45,7 +46,7 @@ constructor(
    private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
    private var telephonyManager: TelephonyManager =
        context.getSystemService(TelephonyManager::class.java)!!

    private val carrierConfigRepository = CarrierConfigRepository(context)
    private var preferenceScreen: PreferenceScreen? = null

    fun init(subId: Int) {
@@ -54,7 +55,13 @@ constructor(
    }

    override fun getAvailabilityStatus() =
        if (getAvailabilityStatus(telephonyManager, subId, getDefaultDataSubId)) AVAILABLE
        if (getAvailabilityStatus(
                telephonyManager,
                subId,
                getDefaultDataSubId,
                carrierConfigRepository
            )
        ) AVAILABLE
        else CONDITIONALLY_UNAVAILABLE

    override fun displayPreference(screen: PreferenceScreen) {
@@ -92,11 +99,14 @@ constructor(
            telephonyManager: TelephonyManager,
            subId: Int,
            getDefaultDataSubId: () -> Int,
            carrierConfigRepository: CarrierConfigRepository,
        ): Boolean {
            return SubscriptionManager.isValidSubscriptionId(subId) &&
                !telephonyManager.isDataEnabled &&
                telephonyManager.isApnMetered(ApnSetting.TYPE_MMS) &&
                !isFallbackDataEnabled(telephonyManager, subId, getDefaultDataSubId())
                !isFallbackDataEnabled(telephonyManager, subId, getDefaultDataSubId()) &&
                carrierConfigRepository.getBoolean(
                    subId, CarrierConfigManager.KEY_MMS_MMS_ENABLED_BOOL)
        }

        private fun isFallbackDataEnabled(
@@ -118,11 +128,16 @@ constructor(
        ) : MobileNetworkSettingsSearchItem {
            private var telephonyManager: TelephonyManager =
                context.getSystemService(TelephonyManager::class.java)!!
            private val carrierConfigRepository = CarrierConfigRepository(context)

            @VisibleForTesting
            fun isAvailable(subId: Int): Boolean =
                getAvailabilityStatus(
                    telephonyManager.createForSubscriptionId(subId), subId, getDefaultDataSubId)
                    telephonyManager.createForSubscriptionId(subId),
                    subId,
                    getDefaultDataSubId,
                    carrierConfigRepository
                )

            override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? {
                if (!isAvailable(subId)) return null
+59 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.network.telephony

import android.content.Context
import android.telephony.CarrierConfigManager
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
import android.telephony.TelephonyManager
import android.telephony.data.ApnSetting
@@ -26,6 +27,7 @@ import com.android.settings.core.BasePreferenceController.AVAILABLE
import com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE
import com.android.settings.network.telephony.MmsMessagePreferenceController.Companion.MmsMessageSearchItem
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.doReturn
@@ -63,6 +65,21 @@ class MmsMessagePreferenceControllerTest {
        getDefaultDataSubId = { defaultDataSubId },
    )

    @Before
    fun setUp() {
        CarrierConfigRepository.resetForTest()
        CarrierConfigRepository.setBooleanForTest(
            subId = SUB_1_ID,
            key = CarrierConfigManager.KEY_MMS_MMS_ENABLED_BOOL,
            value = true,
        )
        CarrierConfigRepository.setBooleanForTest(
            subId = SUB_2_ID,
            key = CarrierConfigManager.KEY_MMS_MMS_ENABLED_BOOL,
            value = true,
        )
    }

    @Test
    fun getAvailabilityStatus_invalidSubscription_unavailable() {
        controller.init(INVALID_SUBSCRIPTION_ID)
@@ -164,6 +181,27 @@ class MmsMessagePreferenceControllerTest {
        assertThat(availabilityStatus).isEqualTo(AVAILABLE)
    }

    @Test
    fun getAvailabilityStatus_carrierConfigEnabledMmsFalse_unavailable() {
        defaultDataSubId = SUB_2_ID
        mockTelephonyManager2.stub {
            on { isDataEnabled } doReturn false
            on {
                isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH)
            } doReturn true
        }
        CarrierConfigRepository.setBooleanForTest(
            subId = SUB_2_ID,
            key = CarrierConfigManager.KEY_MMS_MMS_ENABLED_BOOL,
            value = false,
        )
        controller.init(SUB_2_ID)

        val availabilityStatus = controller.getAvailabilityStatus()

        assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
    }

    @Test
    fun searchIsAvailable_notDefaultDataAndDataOnAndAutoDataSwitchOn_unavailable() {
        mockTelephonyManager1.stub {
@@ -200,6 +238,27 @@ class MmsMessagePreferenceControllerTest {
        assertThat(isAvailable).isTrue()
    }

    @Test
    fun searchIsAvailable_carrierConfigEnabledMmsFalse_unavailable() {
        defaultDataSubId = SUB_2_ID
        mockTelephonyManager2.stub {
            on { isDataEnabled } doReturn false
            on {
                isMobileDataPolicyEnabled(TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH)
            } doReturn true
        }
        CarrierConfigRepository.setBooleanForTest(
            subId = SUB_2_ID,
            key = CarrierConfigManager.KEY_MMS_MMS_ENABLED_BOOL,
            value = false,
        )
        controller.init(SUB_2_ID)

        val availabilityStatus = controller.getAvailabilityStatus()

        assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
    }

    @Test
    fun isChecked_whenMmsNotAlwaysAllowed_returnFalse() {
        mockTelephonyManager2.stub {