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

Commit 9647c7eb authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Satellite setting] Change string dynamically w/ or w/o data supported" into main

parents c0bbc1c0 ea01b427
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -12800,8 +12800,10 @@ Data usage charges may apply.</string>
    <string name="title_supported_service">After your phone connects to a satellite</string>
    <!-- Title for satellite supported service for NTN manual connection type. [CHAR_LIMIT=NONE] -->
    <string name="title_supported_service_for_manual_type">Follow steps to connect to the satellite</string>
    <!-- Summary for satellite supported service [CHAR_LIMIT=NONE] -->
    <string name="summary_supported_service">You can text anyone, including emergency services. Your phone will reconnect to a mobile network when available.</string>
    <!-- Summary for satellite supported service [CHAR_LIMIT=NONE] [SCREENSHOT=screen/AmfBYoNmdgkK9ER] -->
    <string name="summary_supported_service">You can text anyone, including emergency services, and use limited data on some apps. Your phone will reconnect to a mobile network when available.</string>
    <!-- Summary for satellite supported service without data supported [CHAR_LIMIT=NONE] [SCREENSHOT=screen/7sidqhHfwNNoacB] -->
    <string name="summary_supported_service_without_data_supported">You can text anyone, including emergency services. Your phone will reconnect to a mobile network when available.</string>
    <!-- Summary for satellite supported service for NTN manual connection type. [CHAR_LIMIT=NONE] -->
    <string name="summary_supported_service_for_manual_type">After your phone is connected, you can text anyone, including emergency services.</string>
    <!-- learn more text - title of disclaimer of satellite connectivity  [CHAR_LIMIT=NONE] -->
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@
        <Preference
            android:key="key_supported_service"
            android:title="@string/title_supported_service"
            android:summary="@string/summary_supported_service"
            android:summary="@string/summary_supported_service_without_data_supported"
            android:icon="@drawable/ic_android_satellite_24px"/>
    </PreferenceCategory>

+2 −0
Original line number Diff line number Diff line
@@ -127,6 +127,8 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
                isSmsAvailable, isDataAvailableAndNotRestricted);
        use(SatelliteSettingAccountInfoController.class).setCarrierRoamingNtnAvailability(
                isSmsAvailable, isDataAvailableAndNotRestricted);
        use(SatelliteSettingIndicatorController.class).setCarrierRoamingNtnAvailability(
                isSmsAvailable, isDataAvailableAndNotRestricted);
        forceUpdatePreferences();
    }

+38 −6
Original line number Diff line number Diff line
@@ -28,15 +28,30 @@ import com.android.settings.network.telephony.TelephonyBasePreferenceController
/** A controller to control How is work paragraph.  */
class SatelliteSettingIndicatorController(context: Context?, preferenceKey: String?) :
    TelephonyBasePreferenceController(context, preferenceKey) {
    private var mCarrierConfigs: PersistableBundle? = null
    private var mCarrierConfigs: PersistableBundle = PersistableBundle()
    private var mIsSmsAvailable = false
    private var mIsDataAvailable = false
    private var mIsSatelliteEligible = false
    private var screen: PreferenceScreen? = null

    fun init(subId: Int, carrierConfigs: PersistableBundle) {
        mSubId = subId
        mCarrierConfigs = carrierConfigs
    }

    fun setCarrierRoamingNtnAvailability(isSmsAvailable: Boolean, isDataAvailable: Boolean) {
        mIsSmsAvailable = isSmsAvailable
        mIsDataAvailable = isDataAvailable
        mIsSatelliteEligible = isSatelliteEligible()
    }

    override fun displayPreference(screen: PreferenceScreen) {
        this.screen = screen
        super.displayPreference(screen)
    }

    override fun updateState(preference: Preference?) {
        super.updateState(preference)
        updateHowItWorksContent(
            screen,
            SatelliteCarrierSettingUtils.isSatelliteAccountEligible(mContext, mSubId)
@@ -48,7 +63,10 @@ class SatelliteSettingIndicatorController(context: Context?, preferenceKey: Stri
    }

    @VisibleForTesting
    fun updateHowItWorksContent(screen: PreferenceScreen, isSatelliteEligible: Boolean) {
    fun updateHowItWorksContent(screen: PreferenceScreen?, isSatelliteEligible: Boolean) {
        if (screen == null) {
            return
        }
        /* Composes "How it works" section, which guides how users can use satellite messaging, when
           satellite messaging is included in user's mobile plan, or it'll will be grey out. */
        if (!isSatelliteEligible) {
@@ -58,25 +76,39 @@ class SatelliteSettingIndicatorController(context: Context?, preferenceKey: Stri
            category.isEnabled = false
            category.shouldDisableView = true
        }
        if (!this.isCarrierRoamingNtnConnectedTypeManual) {

        val supportedService: Preference = screen.findPreference(KEY_SUPPORTED_SERVICE)!!
        if (mIsDataAvailable) {
            supportedService.setSummary(R.string.summary_supported_service)
        }

        if (!isCarrierRoamingNtnConnectedTypeManual) {
            return
        }
        val connectionGuide: Preference = screen.findPreference(KEY_SATELLITE_CONNECTION_GUIDE)!!
        connectionGuide.setTitle(R.string.title_satellite_connection_guide_for_manual_type)
        connectionGuide.setSummary(R.string.summary_satellite_connection_guide_for_manual_type)

        val supportedService: Preference = screen.findPreference(KEY_SUPPORTED_SERVICE)!!
        supportedService.setTitle(R.string.title_supported_service_for_manual_type)
        supportedService.setSummary(R.string.summary_supported_service_for_manual_type)

    }

    private val isCarrierRoamingNtnConnectedTypeManual: Boolean
        get() = CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL == mCarrierConfigs!!.getInt(
        get() = CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL == mCarrierConfigs.getInt(
            CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT,
            CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC
        )


    private fun isSatelliteEligible(): Boolean {
        if (mCarrierConfigs.getInt(CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT)
            == CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL
        ) {
            return mIsSmsAvailable
        }
        return SatelliteCarrierSettingUtils.isSatelliteAccountEligible(mContext, mSubId)
    }

    companion object {
        @VisibleForTesting
        const val PREF_KEY_CATEGORY_HOW_IT_WORKS: String = "key_category_how_it_works"
+34 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ class SatelliteSettingIndicatorControllerTest {

    @Before
    fun setUp() {
        mContext = Mockito.spy<Context>(ApplicationProvider.getApplicationContext<Context?>())
        mContext = ApplicationProvider.getApplicationContext()
        mController = SatelliteSettingIndicatorController(mContext, KEY)
    }

@@ -59,7 +59,11 @@ class SatelliteSettingIndicatorControllerTest {
        category.setKey(SatelliteSettingIndicatorController.Companion.PREF_KEY_CATEGORY_HOW_IT_WORKS)
        category.title = "test title"
        category.isEnabled = true
        val preference = Mockito.spy<Preference>(Preference(mContext!!))
        preference.setKey(SatelliteSettingIndicatorController.Companion.KEY_SUPPORTED_SERVICE)
        preference.title = "preference"
        preferenceScreen.addPreference(category)
        preferenceScreen.addPreference(preference)

        mController?.updateHowItWorksContent(preferenceScreen, false)

@@ -80,7 +84,11 @@ class SatelliteSettingIndicatorControllerTest {
        category.setKey(SatelliteSettingIndicatorController.Companion.PREF_KEY_CATEGORY_HOW_IT_WORKS)
        category.title = "test title"
        category.isEnabled = true
        val preference = Mockito.spy<Preference>(Preference(mContext!!))
        preference.setKey(SatelliteSettingIndicatorController.Companion.KEY_SUPPORTED_SERVICE)
        preference.title = "preference"
        preferenceScreen.addPreference(category)
        preferenceScreen.addPreference(preference)

        mController!!.updateHowItWorksContent(preferenceScreen, true)

@@ -88,6 +96,31 @@ class SatelliteSettingIndicatorControllerTest {
        Mockito.verify(category, Mockito.times(0)).shouldDisableView = true
    }

    @Test
    fun updateHowItWorksContent_dataAvailable_summaryChanged() {
        mCarrierConfig.putInt(
            CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT,
            CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC
        )
        mController?.init(TEST_SUB_ID, mCarrierConfig)
        mController?.setCarrierRoamingNtnAvailability(true, true)
        val preferenceManager = PreferenceManager(mContext!!)
        val preferenceScreen = preferenceManager.createPreferenceScreen(mContext!!)
        val category = Mockito.spy<PreferenceCategory>(PreferenceCategory(mContext!!))
        category.setKey(SatelliteSettingIndicatorController.Companion.PREF_KEY_CATEGORY_HOW_IT_WORKS)
        category.title = "test title"
        category.isEnabled = true
        val preference = Mockito.spy<Preference>(Preference(mContext!!))
        preference.setKey(SatelliteSettingIndicatorController.Companion.KEY_SUPPORTED_SERVICE)
        preference.title = "preference"
        preferenceScreen.addPreference(category)
        preferenceScreen.addPreference(preference)

        mController!!.updateHowItWorksContent(preferenceScreen, true)

        Mockito.verify(preference).setSummary(ArgumentMatchers.any<CharSequence?>())
    }

    @Test
    fun updateHowItWorksContent_ntnConnectIsManual_summaryChanged() {
        mCarrierConfig.putInt(