From 2f57f538315c335ad9649285260094fcb66b6d03 Mon Sep 17 00:00:00 2001 From: Hakjun Choi Date: Tue, 9 Jan 2024 20:00:15 +0000 Subject: [PATCH] Add Satellite Messaging activity Add satellite messaging activity into Settings for carrier satellite service Bug: 319035517 Test: manual 1. Set CarrierConfig Key KEY_SATELLITE_ATTACH_SUPPORTED_BOOL as false then verify satellite messaging menu is not shwon from Settings > Network & internet > SIMs > test sim 2. Set CarrierConfig key KEY_SATELLITE_ATTACH_SUPPORTED_BOOL as true 3. Insert test SIM 3. Get into to Settings > Network & internet > SIMs > test sim > verify Satellite messaging is shown 4. Verify whether descriptions are as directed. icons are as directed. 5. Add satellite messaging does not work when click 6. Invoke web browser with test website when click 'More about satellite messaging' 7. Replace SIM of which MCC/MNC is not test sim 8. verify no action happen when click 'More about satellite messaging' Change-Id: Iee8fad58b41cbca34f373d2a9df1d074c447cfb1 --- AndroidManifest.xml | 23 +- res/drawable/ic_block_24px.xml | 25 +++ res/drawable/ic_check_circle_24px.xml | 25 +++ res/drawable/ic_satellite_alt_24px.xml | 25 +++ .../ic_signal_cellular_nodata_24px.xml | 25 +++ ...te_more_information_background_outline.xml | 24 +++ ...ellite_setting_more_information_layout.xml | 50 +++++ res/values/strings.xml | 41 ++++ res/xml/mobile_network_settings.xml | 12 +- res/xml/satellite_setting.xml | 65 ++++++ src/com/android/settings/Settings.java | 1 + .../core/gateway/SettingsGateway.java | 2 + .../telephony/MobileNetworkSettings.java | 5 + .../network/telephony/SatelliteSetting.java | 198 ++++++++++++++++++ .../SatelliteSettingPreferenceController.java | 139 ++++++++++++ 15 files changed, 657 insertions(+), 3 deletions(-) create mode 100644 res/drawable/ic_block_24px.xml create mode 100644 res/drawable/ic_check_circle_24px.xml create mode 100644 res/drawable/ic_satellite_alt_24px.xml create mode 100644 res/drawable/ic_signal_cellular_nodata_24px.xml create mode 100644 res/drawable/satellite_more_information_background_outline.xml create mode 100644 res/layout/satellite_setting_more_information_layout.xml create mode 100644 res/xml/satellite_setting.xml create mode 100644 src/com/android/settings/network/telephony/SatelliteSetting.java create mode 100644 src/com/android/settings/network/telephony/SatelliteSettingPreferenceController.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2ba87d7099a..64455b6746f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -627,6 +627,27 @@ android:value="true" /> + + + + + + + + + + + + + + + + android:value="true" /> + + + diff --git a/res/drawable/ic_check_circle_24px.xml b/res/drawable/ic_check_circle_24px.xml new file mode 100644 index 00000000000..c0fdefbee19 --- /dev/null +++ b/res/drawable/ic_check_circle_24px.xml @@ -0,0 +1,25 @@ + + + + diff --git a/res/drawable/ic_satellite_alt_24px.xml b/res/drawable/ic_satellite_alt_24px.xml new file mode 100644 index 00000000000..f9ca7dc6679 --- /dev/null +++ b/res/drawable/ic_satellite_alt_24px.xml @@ -0,0 +1,25 @@ + + + + diff --git a/res/drawable/ic_signal_cellular_nodata_24px.xml b/res/drawable/ic_signal_cellular_nodata_24px.xml new file mode 100644 index 00000000000..9b9f3918d14 --- /dev/null +++ b/res/drawable/ic_signal_cellular_nodata_24px.xml @@ -0,0 +1,25 @@ + + + + diff --git a/res/drawable/satellite_more_information_background_outline.xml b/res/drawable/satellite_more_information_background_outline.xml new file mode 100644 index 00000000000..b11ef07507d --- /dev/null +++ b/res/drawable/satellite_more_information_background_outline.xml @@ -0,0 +1,24 @@ + + + + + + + diff --git a/res/layout/satellite_setting_more_information_layout.xml b/res/layout/satellite_setting_more_information_layout.xml new file mode 100644 index 00000000000..ce2fabe23d2 --- /dev/null +++ b/res/layout/satellite_setting_more_information_layout.xml @@ -0,0 +1,50 @@ + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 35c175997c0..8eee0957150 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3256,6 +3256,10 @@ Communal settings + + + Satellite Messaging + APNs @@ -11405,6 +11409,43 @@ App data usage Invalid Network Mode %1$d. Ignore. + + Satellite messaging + + Send and receive text messages by satellite. Included with your account. + + Send and receive text messages by satellite. Non included with your account. + + Satellite messaging + + About satellite messaging + + You can send and receive text messages by satellite as part of an eligible %1$s account + + Your %1$s plan + + Satellite messaging is included with your account + + Satellite messaging isn\u2019t included with your account + + Add satellite messaging + + How it works + + When you don\u2019t have a mobile network + + Your phone will auto-connect to a satellite. For the best connection, keep a clear view of the sky. + + After your phone connects to a satellite + + You can text anyone, including emergency services. Your phone will reconnect to a mobile network when available. + + 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.\n\nIt may take some time for changes to your account to show in Settings. Contact %1$s for details. + + More about satellite messaging + + + Access Point Names diff --git a/res/xml/mobile_network_settings.xml b/res/xml/mobile_network_settings.xml index 038688e390c..b5d0c5939ed 100644 --- a/res/xml/mobile_network_settings.xml +++ b/res/xml/mobile_network_settings.xml @@ -208,6 +208,7 @@ + + @@ -249,7 +257,7 @@ android:title="@string/require_cellular_encryption_title" android:summary="@string/require_cellular_encryption_summary" settings:controller= - "com.android.settings.network.telephony.NullAlgorithmsPreferenceController" /> + "com.android.settings.network.telephony.NullAlgorithmsPreferenceController"/> + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 3e48a9cf1e8..230c103128b 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -345,6 +345,7 @@ public class Settings extends SettingsActivity { /* empty */ } + public static class SatelliteSettingActivity extends SettingsActivity { /* empty */ } public static class ApnSettingsActivity extends SettingsActivity { /* empty */ } public static class WifiCallingSettingsActivity extends SettingsActivity { /* empty */ } public static class MemorySettingsActivity extends SettingsActivity { /* empty */ } diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java index 3433e12ad33..a5a21314ec8 100644 --- a/src/com/android/settings/core/gateway/SettingsGateway.java +++ b/src/com/android/settings/core/gateway/SettingsGateway.java @@ -143,6 +143,7 @@ import com.android.settings.network.apn.ApnEditor; import com.android.settings.network.apn.ApnSettings; import com.android.settings.network.telephony.MobileNetworkSettings; import com.android.settings.network.telephony.NetworkSelectSettings; +import com.android.settings.network.telephony.SatelliteSetting; import com.android.settings.network.tether.TetherSettings; import com.android.settings.nfc.PaymentSettings; import com.android.settings.notification.ConfigureNotificationSettings; @@ -300,6 +301,7 @@ public class SettingsGateway { AppNotificationSettings.class.getName(), NotificationAssistantPicker.class.getName(), ChannelNotificationSettings.class.getName(), + SatelliteSetting.class.getName(), ApnSettings.class.getName(), ApnEditor.class.getName(), WifiCallingSettings.class.getName(), diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java index b4b40efae9b..4188f8d1ad7 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java @@ -255,6 +255,11 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme roamingPreferenceController.init(getFragmentManager(), mSubId, mMobileNetworkInfoEntity); } + final SatelliteSettingPreferenceController satelliteSettingPreferenceController = use( + SatelliteSettingPreferenceController.class); + if (satelliteSettingPreferenceController != null) { + satelliteSettingPreferenceController.init(mSubId); + } use(ApnPreferenceController.class).init(mSubId); use(CarrierPreferenceController.class).init(mSubId); use(DataUsagePreferenceController.class).init(mSubId); diff --git a/src/com/android/settings/network/telephony/SatelliteSetting.java b/src/com/android/settings/network/telephony/SatelliteSetting.java new file mode 100644 index 00000000000..ecfa8e4000a --- /dev/null +++ b/src/com/android/settings/network/telephony/SatelliteSetting.java @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2024 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; + +import android.app.Activity; +import android.app.settings.SettingsEnums; +import android.content.Intent; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Bundle; +import android.os.UserManager; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; +import android.telephony.satellite.SatelliteManager; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.style.StyleSpan; +import android.text.style.UnderlineSpan; +import android.util.Log; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; + +import com.android.settings.R; +import com.android.settings.dashboard.RestrictedDashboardFragment; +import com.android.settingslib.HelpUtils; +import com.android.settingslib.Utils; +import com.android.settingslib.widget.FooterPreference; + +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 = + "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 KEY_FOOTER_PREFERENCE = "satellite_setting_extra_info_footer_pref"; + public static final String SUB_ID = "sub_id"; + + private Activity mActivity; + private TelephonyManager mTelephonymanager; + private SatelliteManager mSatelliteManager; + private int mSubId; + + public SatelliteSetting() { + super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS); + } + + @Override + public int getMetricsCategory() { + return SettingsEnums.SATELLITE_SETTING; + } + + @Override + public void onCreate(@NonNull Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mActivity = getActivity(); + mTelephonymanager = mActivity.getSystemService(TelephonyManager.class); + mSatelliteManager = mActivity.getSystemService(SatelliteManager.class); + mSubId = mActivity.getIntent().getIntExtra(SUB_ID, + SubscriptionManager.INVALID_SUBSCRIPTION_ID); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + updateDynamicPreferenceViews(); + } + + @Override + protected String getLogTag() { + return TAG; + } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.satellite_setting; + } + + private void updateDynamicPreferenceViews() { + String operatorName = mTelephonymanager.getSimOperatorName(mSubId); + boolean isSatelliteEligible = isSatelliteEligible(); + + // About satellite messaging + Preference preference = findPreference(PREF_KEY_ABOUT_SATELLITE_MESSAGING); + preference.setTitle( + getResources().getString(R.string.title_about_satellite_setting, operatorName)); + + // Your mobile plan + PreferenceCategory prefCategory = findPreference(PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN); + prefCategory.setTitle(getResources().getString(R.string.category_title_your_satellite_plan, + operatorName)); + + preference = findPreference(PREF_KEY_YOUR_SATELLITE_PLAN); + Drawable icon; + 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 = getResources().getDrawable(R.drawable.ic_check_circle_24px); + } 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); + /* 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)); + spannable.setSpan(new UnderlineSpan(), 0, spannable.length(), + Spanned.SPAN_INCLUSIVE_INCLUSIVE); + spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, spannable.length(), + Spanned.SPAN_INCLUSIVE_INCLUSIVE); + preference.setSummary(spannable); + /* The link will lead users to a guide page */ + preference.setOnPreferenceClickListener(pref -> { + String url = getResources().getString(R.string.more_info_satellite_messaging_link); + if (!url.isEmpty()) { + Uri uri = Uri.parse(url); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(intent); + } + return true; + }); + icon = getResources().getDrawable(R.drawable.ic_block_24px); + } + icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary)); + preference.setIcon(icon); + + /* 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) { + PreferenceCategory category = findPreference(PREF_KEY_CATEGORY_HOW_IT_WORKS); + category.setEnabled(false); + category.setShouldDisableView(true); + } + + // 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)); + + final String[] link = new String[1]; + link[0] = getResources().getString(R.string.more_info_satellite_messaging_link); + footerPreference.setLearnMoreAction(view -> { + if (!link[0].isEmpty()) { + Intent helpIntent = HelpUtils.getHelpIntent(mActivity, link[0], + this.getClass().getName()); + if (helpIntent != null) { + mActivity.startActivityForResult(helpIntent, /*requestCode=*/ 0); + } + } + }); + footerPreference.setLearnMoreText( + getResources().getString(R.string.more_about_satellite_messaging)); + + // TODO : b/320467418 add rounded rectangle border line to footer preference. + } + } + + private boolean isSatelliteEligible() { + try { + Set restrictionReason = + mSatelliteManager.getSatelliteAttachRestrictionReasonsForCarrier(mSubId); + return !restrictionReason.contains( + SatelliteManager.SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT); + } catch (SecurityException | IllegalStateException | IllegalArgumentException ex) { + loge(ex.toString()); + return false; + } + } + + private static void loge(String message) { + Log.e(TAG, message); + } +} diff --git a/src/com/android/settings/network/telephony/SatelliteSettingPreferenceController.java b/src/com/android/settings/network/telephony/SatelliteSettingPreferenceController.java new file mode 100644 index 00000000000..7de7fcba64e --- /dev/null +++ b/src/com/android/settings/network/telephony/SatelliteSettingPreferenceController.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2024 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; + +import android.content.Context; +import android.content.Intent; +import android.os.PersistableBundle; +import android.provider.Settings; +import android.telephony.CarrierConfigManager; +import android.telephony.satellite.SatelliteManager; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.preference.Preference; +import androidx.preference.PreferenceScreen; + +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.Set; + +/** + * Preference controller for "Satellite Setting" + */ +public class SatelliteSettingPreferenceController extends + TelephonyBasePreferenceController implements LifecycleObserver, OnStart, OnStop { + + private static final String TAG = "SatelliteSettingPreferenceController"; + + CarrierConfigCache mCarrierConfigCache; + SatelliteManager mSatelliteManager; + @Nullable private Boolean mIsSatelliteEligible = null; + + public SatelliteSettingPreferenceController(@NonNull Context context, @NonNull String key) { + super(context, key); + mCarrierConfigCache = CarrierConfigCache.getInstance(context); + mSatelliteManager = context.getSystemService(SatelliteManager.class); + } + + @Override + public int getAvailabilityStatus(int subId) { + final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId); + final boolean isSatelliteAttachSupported = carrierConfig.getBoolean( + CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL); + + return isSatelliteAttachSupported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; + } + + @Override + public void onStart() { + } + + @Override + public void onStop() { + } + + @Override + public void displayPreference(@NonNull PreferenceScreen screen) { + super.displayPreference(screen); + } + + @Override + public void updateState(@Nullable Preference preference) { + super.updateState(preference); + if (preference != null) { + updateSummary(preference); + } + } + + @Override + public boolean handlePreferenceTreeClick(@NonNull Preference preference) { + if (getPreferenceKey().equals(preference.getKey())) { + // This activity runs in phone process, we must use intent to start + final Intent intent = new Intent(Settings.ACTION_SATELLITE_SETTING); + // This will setup the Home and Search affordance + intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true); + intent.putExtra(SatelliteSetting.SUB_ID, mSubId); + mContext.startActivity(intent); + return true; + } + + return false; + } + + /** + * Set subId for Satellite Settings page. + * @param subId subscription ID. + */ + public void init(int subId) { + logd("init(), subId=" + subId); + mSubId = subId; + } + + private void updateSummary(Preference preference) { + try { + Set restrictionReason = + mSatelliteManager.getSatelliteAttachRestrictionReasonsForCarrier(mSubId); + boolean isSatelliteEligible = !restrictionReason.contains( + SatelliteManager.SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT); + if (mIsSatelliteEligible == null || mIsSatelliteEligible != isSatelliteEligible) { + mIsSatelliteEligible = isSatelliteEligible; + String summary = mContext.getString( + mIsSatelliteEligible ? R.string.satellite_setting_enabled_summary + : R.string.satellite_setting_disabled_summary); + preference.setSummary(summary); + } + } catch (SecurityException | IllegalStateException | IllegalArgumentException ex) { + loge(ex.toString()); + preference.setSummary(R.string.satellite_setting_disabled_summary); + } + } + + private static void logd(String message) { + Log.d(TAG, message); + } + + private static void loge(String message) { + Log.e(TAG, message); + } +}