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
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 3e48a9c..230c103 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -345,6 +345,7 @@
/* 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 3433e12..a5a2131 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.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 @@
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 b4b40ef..4188f8d 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -255,6 +255,11 @@
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 0000000..ecfa8e4
--- /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<Integer> 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 0000000..7de7fcb
--- /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<Integer> 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);
+ }
+}