Merge "[Satellite] Refactor about content of Satellite setting" into main

This commit is contained in:
Treehugger Robot
2025-03-14 02:22:41 -07:00
committed by Android (Google) Code Review
5 changed files with 142 additions and 25 deletions

View File

@@ -12695,10 +12695,10 @@ Data usage charges may apply.</string>
<string name="satellite_setting_summary_without_entitlement">Send and receive text messages by satellite. Contact your carrier for details.</string> <string name="satellite_setting_summary_without_entitlement">Send and receive text messages by satellite. Contact your carrier for details.</string>
<!-- Search keywords for "_satellite_setting_preference_layout" [CHAR_LIMIT=NONE] --> <!-- Search keywords for "_satellite_setting_preference_layout" [CHAR_LIMIT=NONE] -->
<string name="keywords_satellite_setting">Satellite messaging, satellite connectivity</string> <string name="keywords_satellite_setting">Satellite messaging, satellite connectivity</string>
<!-- Category name "About satellite messaging" [CHAR_LIMIT=NONE] --> <!-- Category name "About satellite connectivity" [CHAR_LIMIT=NONE] -->
<string name="category_name_about_satellite_messaging">About <xliff:g id="subject" example="satellite messaging">%1$s</xliff:g></string> <string name="category_name_about_satellite_connectivity">About satellite connectivity</string>
<!-- Summary for category "About satellite messaging" [CHAR_LIMIT=NONE] --> <!-- Description for category "About satellite connectivity" [CHAR_LIMIT=NONE] -->
<string name="title_about_satellite_setting">You can send and receive text messages by satellite with an eligible <xliff:g id="carrier_name" example="T-Mobile">%1$s</xliff:g> account</string> <string name="description_about_satellite_setting">You can send and receive text messages and use some apps by satellite with an eligible <xliff:g id="carrier_name" example="T-Mobile">%1$s</xliff:g> account</string>
<!-- Category title "Your mobile plan" [CHAR_LIMIT=NONE] --> <!-- Category title "Your mobile plan" [CHAR_LIMIT=NONE] -->
<string name="category_title_your_satellite_plan">Your <xliff:g id="carrier_name" example="T-Mobile">%1$s</xliff:g> account</string> <string name="category_title_your_satellite_plan">Your <xliff:g id="carrier_name" example="T-Mobile">%1$s</xliff:g> account</string>
<!-- Title for category "Your mobile plan when satellite is included in plan" [CHAR_LIMIT=NONE] --> <!-- Title for category "Your mobile plan when satellite is included in plan" [CHAR_LIMIT=NONE] -->

View File

@@ -22,10 +22,12 @@
settings:keywords="@string/keywords_satellite_setting"> settings:keywords="@string/keywords_satellite_setting">
<PreferenceCategory <PreferenceCategory
android:key="key_category_about_satellite"> android:title="@string/category_name_about_satellite_connectivity"
android:key="key_category_about_satellite"
settings:controller="com.android.settings.network.telephony.satellite.SatelliteSettingAboutContentController">
<com.android.settingslib.widget.TopIntroPreference <com.android.settingslib.widget.TopIntroPreference
android:key="key_about_satellite_messaging"/> android:key="key_about_satellite_connectivity"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory

View File

@@ -61,8 +61,6 @@ import java.util.Set;
/** Handle Satellite Setting Preference Layout. */ /** Handle Satellite Setting Preference Layout. */
public class SatelliteSetting extends RestrictedDashboardFragment { public class SatelliteSetting extends RestrictedDashboardFragment {
private static final String TAG = "SatelliteSetting"; private static final String TAG = "SatelliteSetting";
private static final String PREF_KEY_ABOUT_SATELLITE_MESSAGING =
"key_about_satellite_messaging";
private static final String PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN = private static final String PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN =
"key_category_your_satellite_plan"; "key_category_your_satellite_plan";
private static final String PREF_KEY_YOUR_SATELLITE_PLAN = "key_your_satellite_plan"; private static final String PREF_KEY_YOUR_SATELLITE_PLAN = "key_your_satellite_plan";
@@ -98,14 +96,17 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
mActivity = getActivity();
mSubId = mActivity.getIntent().getIntExtra(SUB_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
use(SatelliteAppListCategoryController.class).init(); use(SatelliteAppListCategoryController.class).init();
use(SatelliteSettingAboutContentController.class).init(mSubId);
} }
@Override @Override
public void onCreate(@NonNull Bundle savedInstanceState) { public void onCreate(@NonNull Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mActivity = getActivity();
mSatelliteManager = mActivity.getSystemService(SatelliteManager.class); mSatelliteManager = mActivity.getSystemService(SatelliteManager.class);
if (mSatelliteManager == null) { if (mSatelliteManager == null) {
Log.d(TAG, "SatelliteManager is null, do nothing."); Log.d(TAG, "SatelliteManager is null, do nothing.");
@@ -113,8 +114,6 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
return; return;
} }
mSubId = mActivity.getIntent().getIntExtra(SUB_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mConfigBundle = fetchCarrierConfigData(mSubId); mConfigBundle = fetchCarrierConfigData(mSubId);
if (!isSatelliteAttachSupported(mSubId)) { if (!isSatelliteAttachSupported(mSubId)) {
@@ -135,7 +134,6 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
boolean isSatelliteEligible = isSatelliteEligible(); boolean isSatelliteEligible = isSatelliteEligible();
updateTitle(); updateTitle();
updateAboutSatelliteContent();
updateMobilePlan(isSatelliteEligible); updateMobilePlan(isSatelliteEligible);
updateHowItWorksContent(isSatelliteEligible); updateHowItWorksContent(isSatelliteEligible);
updateFooterContent(); updateFooterContent();
@@ -155,18 +153,6 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
findPreference("satellite_setting").setTitle(getSubjectString()); findPreference("satellite_setting").setTitle(getSubjectString());
} }
// About satellite content
private void updateAboutSatelliteContent() {
Preference categoryTitle = findPreference(PREF_KEY_CATEGORY_ABOUT_SATELLITE);
categoryTitle.setTitle(
getString(R.string.category_name_about_satellite_messaging,
getDescriptionString()));
Preference preference = findPreference(PREF_KEY_ABOUT_SATELLITE_MESSAGING);
preference.setTitle(
getResources().getString(R.string.title_about_satellite_setting, mSimOperatorName));
}
private void updateMobilePlan(boolean isSatelliteEligible) { private void updateMobilePlan(boolean isSatelliteEligible) {
PreferenceCategory prefCategory = findPreference(PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN); PreferenceCategory prefCategory = findPreference(PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN);
if (prefCategory == null || !mConfigBundle.getBoolean( if (prefCategory == null || !mConfigBundle.getBoolean(

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2025 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.settings.network.telephony.satellite
import android.content.Context
import android.telephony.TelephonyManager
import androidx.preference.PreferenceScreen
import com.android.settings.network.telephony.TelephonyBasePreferenceController
import com.android.settingslib.widget.TopIntroPreference
import com.android.settings.R;
/** A controller to show the introduction of satellite connectivity. */
class SatelliteSettingAboutContentController(context: Context, key: String) :
TelephonyBasePreferenceController(context, key) {
private lateinit var simOperatorName: String
fun init(subId: Int) {
mSubId = subId
simOperatorName =
mContext.getSystemService(TelephonyManager::class.java)?.getSimOperatorName(mSubId) ?: ""
}
override fun displayPreference(screen: PreferenceScreen?) {
super.displayPreference(screen)
val preference: TopIntroPreference? =
screen?.findPreference(PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY)
preference?.title =
mContext.getString(R.string.description_about_satellite_setting, simOperatorName)
}
override fun getAvailabilityStatus(subId: Int): Int {
return AVAILABLE
}
companion object {
const val PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY = "key_about_satellite_connectivity";
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2025 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.settings.network.telephony.satellite
import android.content.Context
import android.telephony.TelephonyManager
import androidx.preference.PreferenceManager
import androidx.preference.PreferenceScreen
import androidx.test.core.app.ApplicationProvider
import com.android.settings.R
import com.android.settings.network.telephony.satellite.SatelliteSettingAboutContentController.Companion.PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY
import com.android.settingslib.widget.TopIntroPreference
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
class SatelliteSettingAboutContentControllerTest {
private val mockTelephonyManager: TelephonyManager = mock<TelephonyManager> {
on { getSimOperatorName(TEST_SUB_ID) } doReturn TEST_SIM_OPERATOR_NAME
}
private var context: Context = spy(ApplicationProvider.getApplicationContext()) {
on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
}
private val controller = SatelliteSettingAboutContentController(
context = context,
key = PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY,
)
private lateinit var screen: PreferenceScreen
private lateinit var preference: TopIntroPreference
@Before
fun setUp() {
preference =
TopIntroPreference(context).apply { key = PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY }
screen = PreferenceManager(context).createPreferenceScreen(context)
screen.addPreference(preference)
}
@Test
fun displayPreference_preferenceTitle_hasSimOperatorName() {
controller.init(TEST_SUB_ID)
controller.displayPreference(screen)
assertThat(preference.title).isEqualTo(
context.getString(
R.string.description_about_satellite_setting,
TEST_SIM_OPERATOR_NAME
)
)
}
private companion object {
const val TEST_SUB_ID = 1
const val TEST_SIM_OPERATOR_NAME = "Test Carrier"
}
}