Make Satellite messageing dynamically change wording by network type

Flag: com.android.settings.flags.satellite_oem_settings_ux_migration
Fix: b/378410271
Test: atest pass

Change-Id: I6d2d2ba656a6e2eb26ae103f8af84a1ce5fd49c8
This commit is contained in:
tomhsu
2024-11-25 15:09:56 +00:00
committed by Tom Hsu
parent 8b4f683af3
commit 22370a8a4a
7 changed files with 364 additions and 44 deletions

View File

@@ -56,20 +56,26 @@ import java.util.Set;
/** Handle Satellite Setting Preference Layout. */
public class SatelliteSetting extends RestrictedDashboardFragment {
private static final String TAG = "SatelliteSetting";
public static final String PREF_KEY_ABOUT_SATELLITE_MESSAGING = "key_about_satellite_messaging";
public static final String PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN =
private static final String PREF_KEY_ABOUT_SATELLITE_MESSAGING =
"key_about_satellite_messaging";
private static final String PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN =
"key_category_your_satellite_plan";
public static final String PREF_KEY_YOUR_SATELLITE_PLAN = "key_your_satellite_plan";
public static final String PREF_KEY_CATEGORY_HOW_IT_WORKS = "key_category_how_it_works";
private static final String PREF_KEY_YOUR_SATELLITE_PLAN = "key_your_satellite_plan";
private static final String PREF_KEY_CATEGORY_HOW_IT_WORKS = "key_category_how_it_works";
private static final String PREF_KEY_YOUR_SATELLITE_DATA_PLAN = "key_your_satellite_data_plan";
private static final String PREF_KEY_CATEGORY_ABOUT_SATELLITE = "key_category_about_satellite";
private static final String KEY_FOOTER_PREFERENCE = "satellite_setting_extra_info_footer_pref";
public static final String SUB_ID = "sub_id";
static final String SUB_ID = "sub_id";
static final String EXTRA_IS_SERVICE_DATA_TYPE = "is_service_data_type";
private Activity mActivity;
private TelephonyManager mTelephonymanager;
private CarrierConfigManager mCarrierConfigManager;
private SatelliteManager mSatelliteManager;
private PersistableBundle mConfigBundle;
private int mSubId;
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
private String mSimOperatorName = "";
private boolean mIsServiceDataType = false;
public SatelliteSetting() {
super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
@@ -111,13 +117,19 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
return;
}
mTelephonymanager = mActivity.getSystemService(TelephonyManager.class);
mIsServiceDataType = getIntent().getBooleanExtra(EXTRA_IS_SERVICE_DATA_TYPE, false);
mSimOperatorName = getSystemService(TelephonyManager.class).getSimOperatorName(mSubId);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
updateDynamicPreferenceViews();
boolean isSatelliteEligible = isSatelliteEligible();
updateTitle();
updateAboutSatelliteContent();
updateMobilePlan(isSatelliteEligible);
updateHowItWorksContent(isSatelliteEligible);
updateFooterContent();
}
@Override
@@ -130,31 +142,45 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
return R.xml.satellite_setting;
}
private void updateDynamicPreferenceViews() {
String operatorName = mTelephonymanager.getSimOperatorName(mSubId);
boolean isSatelliteEligible = isSatelliteEligible();
private void updateTitle() {
getActivity().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()));
// About satellite messaging
Preference preference = findPreference(PREF_KEY_ABOUT_SATELLITE_MESSAGING);
preference.setTitle(
getResources().getString(R.string.title_about_satellite_setting, operatorName));
getResources().getString(R.string.title_about_satellite_setting, mSimOperatorName));
}
private void updateMobilePlan(boolean isSatelliteEligible) {
// Your mobile plan
PreferenceCategory prefCategory = findPreference(PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN);
prefCategory.setTitle(getResources().getString(R.string.category_title_your_satellite_plan,
operatorName));
mSimOperatorName));
Preference messagingPreference = findPreference(PREF_KEY_YOUR_SATELLITE_PLAN);
preference = findPreference(PREF_KEY_YOUR_SATELLITE_PLAN);
Drawable icon;
Drawable icon = getContext().getDrawable(R.drawable.ic_check_circle_24px);
if (isSatelliteEligible) {
/* In case satellite is allowed by carrier's entitlement server, the page will show
the check icon with guidance that satellite is included in user's mobile plan */
preference.setTitle(R.string.title_have_satellite_plan);
icon = getContext().getDrawable(R.drawable.ic_check_circle_24px);
messagingPreference.setTitle(R.string.title_have_satellite_plan);
if (com.android.settings.flags.Flags.satelliteOemSettingsUxMigration()) {
Preference connectivityPreference = findPreference(
PREF_KEY_YOUR_SATELLITE_DATA_PLAN);
connectivityPreference.setTitle(R.string.title_have_satellite_data_plan);
connectivityPreference.setIcon(icon);
connectivityPreference.setVisible(true);
}
} else {
/* Or, it will show the blocked icon with the guidance that satellite is not included
in user's mobile plan */
preference.setTitle(R.string.title_no_satellite_plan);
messagingPreference.setTitle(R.string.title_no_satellite_plan);
/* And, the link url provides more information via web page will be shown */
SpannableString spannable = new SpannableString(
getResources().getString(R.string.summary_add_satellite_setting));
@@ -162,9 +188,9 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, spannable.length(),
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
preference.setSummary(spannable);
messagingPreference.setSummary(spannable);
/* The link will lead users to a guide page */
preference.setOnPreferenceClickListener(pref -> {
messagingPreference.setOnPreferenceClickListener(pref -> {
String url = readSatelliteMoreInfoString(mSubId);
if (!url.isEmpty()) {
Uri uri = Uri.parse(url);
@@ -173,11 +199,13 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
}
return true;
});
icon = getResources().getDrawable(R.drawable.ic_block_24px);
icon = getResources().getDrawable(R.drawable.ic_block_24px, null);
}
icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary));
preference.setIcon(icon);
messagingPreference.setIcon(icon);
}
private void updateHowItWorksContent(boolean isSatelliteEligible) {
/* 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) {
@@ -185,13 +213,15 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
category.setEnabled(false);
category.setShouldDisableView(true);
}
}
private void updateFooterContent() {
// More about satellite messaging
FooterPreference footerPreference = findPreference(KEY_FOOTER_PREFERENCE);
if (footerPreference != null) {
footerPreference.setSummary(
getResources().getString(R.string.satellite_setting_summary_more_information,
operatorName));
getSubjectString(), mSimOperatorName));
final String[] link = new String[1];
link[0] = readSatelliteMoreInfoString(mSubId);
@@ -205,8 +235,9 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
}
}
});
footerPreference.setLearnMoreText(
getResources().getString(R.string.more_about_satellite_messaging));
getString(R.string.more_about_satellite_messaging, getDescriptionString()));
}
}
}
@@ -245,6 +276,32 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
return bundle.getBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, false);
}
// This is for a word which first letter is uppercase. e.g. Satellite messaging.
private String getSubjectString() {
int result;
if (com.android.settings.flags.Flags.satelliteOemSettingsUxMigration()) {
result = mIsServiceDataType
? R.string.title_satellite_setting_connectivity
: R.string.satellite_setting_title;
} else {
result = R.string.satellite_setting_title;
}
return getString(result);
}
// This is for a word without uppercase letter. e.g. satellite messaging.
private String getDescriptionString() {
int result;
if (com.android.settings.flags.Flags.satelliteOemSettingsUxMigration()) {
result = mIsServiceDataType
? R.string.description_satellite_setting_connectivity
: R.string.description_satellite_setting_messaging;
} else {
result = R.string.satellite_setting_title;
}
return getString(result);
}
private static void loge(String message) {
Log.e(TAG, message);
}

View File

@@ -16,16 +16,25 @@
package com.android.settings.network.telephony;
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_DATA;
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS;
import android.content.Context;
import android.content.Intent;
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
import android.telephony.satellite.NtnSignalStrength;
import android.telephony.satellite.SatelliteManager;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -33,28 +42,33 @@ import com.android.internal.telephony.flags.Flags;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.network.CarrierConfigCache;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import java.util.List;
import java.util.Set;
/**
* Preference controller for "Satellite Setting"
*/
public class SatelliteSettingPreferenceController extends
TelephonyBasePreferenceController implements LifecycleObserver, OnStart, OnStop {
TelephonyBasePreferenceController implements DefaultLifecycleObserver {
private static final String TAG = "SatelliteSettingPreferenceController";
CarrierConfigCache mCarrierConfigCache;
SatelliteManager mSatelliteManager;
@Nullable private Boolean mIsSatelliteEligible = null;
private TelephonyManager mTelephonyManager = null;
@VisibleForTesting
final CarrierRoamingNtnModeCallback mCarrierRoamingNtnModeCallback =
new CarrierRoamingNtnModeCallback();
@Nullable
private Boolean mIsSatelliteEligible = null;
private boolean mIsServiceDataType = false;
public SatelliteSettingPreferenceController(@NonNull Context context, @NonNull String key) {
super(context, key);
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
mSatelliteManager = context.getSystemService(SatelliteManager.class);
mTelephonyManager = context.getSystemService(TelephonyManager.class);
}
@Override
@@ -76,11 +90,18 @@ public class SatelliteSettingPreferenceController extends
}
@Override
public void onStart() {
public void onResume(@NonNull LifecycleOwner owner) {
if (com.android.settings.flags.Flags.satelliteOemSettingsUxMigration()) {
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
mCarrierRoamingNtnModeCallback);
}
}
@Override
public void onStop() {
public void onPause(@NonNull LifecycleOwner owner) {
if (com.android.settings.flags.Flags.satelliteOemSettingsUxMigration()) {
mTelephonyManager.unregisterTelephonyCallback(mCarrierRoamingNtnModeCallback);
}
}
@Override
@@ -93,6 +114,7 @@ public class SatelliteSettingPreferenceController extends
public void updateState(@Nullable Preference preference) {
super.updateState(preference);
if (preference != null) {
mCarrierRoamingNtnModeCallback.mPref = preference;
updateSummary(preference);
}
}
@@ -106,6 +128,7 @@ public class SatelliteSettingPreferenceController extends
// This will setup the Home and Search affordance
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
intent.putExtra(SatelliteSetting.SUB_ID, mSubId);
intent.putExtra(SatelliteSetting.EXTRA_IS_SERVICE_DATA_TYPE, mIsServiceDataType);
mContext.startActivity(intent);
return true;
}
@@ -115,11 +138,13 @@ public class SatelliteSettingPreferenceController extends
/**
* Set subId for Satellite Settings page.
*
* @param subId subscription ID.
*/
public void init(int subId) {
logd("init(), subId=" + subId);
mSubId = subId;
mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
}
private void updateSummary(Preference preference) {
@@ -148,4 +173,45 @@ public class SatelliteSettingPreferenceController extends
private static void loge(String message) {
Log.e(TAG, message);
}
@VisibleForTesting
class CarrierRoamingNtnModeCallback extends TelephonyCallback implements
TelephonyCallback.CarrierRoamingNtnModeListener {
Preference mPref = null;
@Override
public void onCarrierRoamingNtnAvailableServicesChanged(List<Integer> availableServices) {
CarrierRoamingNtnModeListener.super.onCarrierRoamingNtnAvailableServicesChanged(
availableServices);
boolean isSmsAvailable = availableServices.contains(SERVICE_TYPE_SMS);
boolean isDataAvailable = availableServices.contains(SERVICE_TYPE_DATA);
logd("isSmsAvailable : " + isSmsAvailable
+ " / isDataAvailable " + isDataAvailable);
if (mPref == null) {
logd("Satellite preference is not initialized yet");
return;
}
if (isDataAvailable) {
mIsServiceDataType = true;
mPref.setTitle(R.string.title_satellite_setting_connectivity);
} else if (isSmsAvailable) {
mPref.setTitle(R.string.satellite_setting_title);
}
}
@Override
public void onCarrierRoamingNtnEligibleStateChanged(boolean eligible) {
// Do nothing
}
@Override
public void onCarrierRoamingNtnModeChanged(boolean active) {
// Do nothing
}
@Override
public void onCarrierRoamingNtnSignalStrengthChanged(NtnSignalStrength ntnSignalStrength) {
// Do nothing
}
}
}

View File

@@ -33,6 +33,7 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.flags.Flags;
import java.util.Arrays;
import java.util.List;
@@ -87,13 +88,17 @@ public class SatelliteSettingsPreferenceCategoryController
@Override
public void onResume(@NonNull LifecycleOwner owner) {
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
mCarrierRoamingNtnModeCallback);
if (Flags.satelliteOemSettingsUxMigration()) {
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
mCarrierRoamingNtnModeCallback);
}
}
@Override
public void onPause(@NonNull LifecycleOwner owner) {
mTelephonyManager.unregisterTelephonyCallback(mCarrierRoamingNtnModeCallback);
if (Flags.satelliteOemSettingsUxMigration()) {
mTelephonyManager.unregisterTelephonyCallback(mCarrierRoamingNtnModeCallback);
}
}
@VisibleForTesting