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

Commit 22370a8a authored by tomhsu's avatar tomhsu Committed by Tom Hsu
Browse files

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
parent 8b4f683a
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -12275,13 +12275,13 @@
    <!-- Search keywords for "_satellite_setting_preference_layout" [CHAR_LIMIT=NONE] -->
    <string name="keywords_satellite_setting">Satellite messaging</string>
    <!-- Category name "About satellite messaging" [CHAR_LIMIT=NONE] -->
    <string name="category_name_about_satellite_messaging">About satellite messaging</string>
    <string name="category_name_about_satellite_messaging">About <xliff:g id="subject" example="satellite messaging">%1$s</xliff:g></string>
    <!-- Summary for category "About satellite messaging" [CHAR_LIMIT=NONE] -->
    <string name="title_about_satellite_setting">You can send and receive text messages by satellite as part of an eligible <xliff:g id="carrier_name" example="T-Mobile">%1$s</xliff:g> account</string>
    <!-- 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> plan</string>
    <!-- Title for category "Your mobile plan when satellite is included in plan" [CHAR_LIMIT=NONE] -->
    <string name="title_have_satellite_plan">Satellite messaging is included with your account</string>
    <string name="title_have_satellite_plan">Messaging is included with your account</string>
    <!-- Title for category "Your mobile plan when satellite is not included in plan" [CHAR_LIMIT=NONE] -->
    <string name="title_no_satellite_plan">Satellite messaging isn\u2019t included with your account</string>
    <!-- text view "Learn more" [CHAR_LIMIT=NONE] -->
@@ -12297,9 +12297,9 @@
    <!-- 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>
    <!-- learn more text - more about satellite messaging [CHAR_LIMIT=NONE] -->
    <string name="satellite_setting_summary_more_information">Satellite messaging may take longer and is available only in some areas. Weather and certain structures may affect your satellite connection. Calling by satellite isn\u2019t available. Emergency calls may still connect.\n\nIt may take some time for account changes to show in Settings. Contact your carrier for details.</string>
    <string name="satellite_setting_summary_more_information"><xliff:g id="subject" example="satellite messaging">%1$s</xliff:g> may take longer and is available only in some areas. Weather and certain structures may affect your satellite connection. Calling by satellite isn\u2019t available. Emergency calls may still connect.\n\nIt may take some time for account changes to show in Settings. Contact <xliff:g id="carrier_name" example="T-Mobile">%1$s</xliff:g> for details.</string>
    <!-- more about satellite messaging [CHAR_LIMIT=NONE] -->
    <string name="more_about_satellite_messaging">More about satellite messaging</string>
    <string name="more_about_satellite_messaging">More about <xliff:g id="subject" example="satellite messaging">%1$s</xliff:g></string>
    <!-- Title for satellite warning dialog to avoid user using wifi/bluetooth/airplane mode [CHAR_LIMIT=NONE] -->
    <string name="satellite_warning_dialog_title">Can’t turn on <xliff:g id="function" example="bluetooth">%1$s</xliff:g></string>
    <!-- Content for satellite warning dialog to avoid user using wifi/bluetooth/airplane mode [CHAR_LIMIT=NONE] -->
@@ -12307,7 +12307,14 @@
    <!-- Category title for satellite functions with data transmission in mobile network settings [CHAR LIMIT=60] -->
    <string name="category_title_satellite_connectivity">Satellite connectivity</string>
    <!-- Title for satellite functions with data transmission in mobile network settings [CHAR LIMIT=60] -->
    <string name="satellite_setting_connectivity">Satellite connectivity</string>
    <string name="title_satellite_setting_connectivity">Satellite connectivity</string>
    <!-- Description of satellite function with data transmission [CHAR LIMIT=60] -->
    <string name="description_satellite_setting_connectivity">satellite connectivity</string>
    <!-- Description of satellite function [CHAR LIMIT=60] -->
    <string name="description_satellite_setting_messaging">satellite messaging</string>
    <!-- Title for notifying user's account be able to use data transmission of Satellite" [CHAR_LIMIT=NONE] -->
    <string name="title_have_satellite_data_plan">Use of data is included with your account</string>
    <!-- Title for Apn settings in mobile network settings [CHAR LIMIT=60] -->
+7 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
    settings:keywords="@string/keywords_satellite_setting">

    <PreferenceCategory
        android:title="@string/category_name_about_satellite_messaging">
        android:key="key_category_about_satellite">

        <com.android.settingslib.widget.TopIntroPreference
            android:key="key_about_satellite_messaging"/>
@@ -35,6 +35,12 @@
        <Preference
            android:key="key_your_satellite_plan"
            android:icon="?android:attr/textColorPrimary"/>

        <Preference
            android:key="key_your_satellite_data_plan"
            android:icon="?android:attr/textColorPrimary"
            settings:isPreferenceVisible="false"/>

    </PreferenceCategory>

    <PreferenceCategory
+83 −26
Original line number Diff line number Diff line
@@ -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);
    }
+74 −8
Original line number Diff line number Diff line
@@ -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
        }
    }
}
+8 −3
Original line number Diff line number Diff line
@@ -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,14 +88,18 @@ public class SatelliteSettingsPreferenceCategoryController

    @Override
    public void onResume(@NonNull LifecycleOwner owner) {
        if (Flags.satelliteOemSettingsUxMigration()) {
            mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
                    mCarrierRoamingNtnModeCallback);
        }
    }

    @Override
    public void onPause(@NonNull LifecycleOwner owner) {
        if (Flags.satelliteOemSettingsUxMigration()) {
            mTelephonyManager.unregisterTelephonyCallback(mCarrierRoamingNtnModeCallback);
        }
    }

    @VisibleForTesting
    class CarrierRoamingNtnModeCallback extends TelephonyCallback implements
Loading