Loading res/values/config.xml +7 −0 Original line number Diff line number Diff line Loading @@ -875,4 +875,11 @@ <!-- Whether to allow other device users to edit network configuration of a shared network by default. --> <bool name="config_allow_edit_network_configuration_by_default">true</bool> <!-- Array of carrier id that use to check current region be in satellite GEO fence or not. --> <integer-array name="config_carrier_id_list_for_satellite_geo_fence_check" translatable="false"> <!-- <item>1234</item> --> </integer-array> </resources> src/com/android/settings/network/telephony/satellite/SatelliteCarrierSettingUtils.java +30 −0 Original line number Diff line number Diff line Loading @@ -22,15 +22,26 @@ import android.content.Context; import android.telephony.satellite.SatelliteManager; import android.util.Log; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; /** A until for carrier satellite setting. */ public class SatelliteCarrierSettingUtils { private static final String TAG = "SatelliteCarrierSettingUtils"; /** * {@link android.telephony.satellite.SatelliteAccessConfiguration} is used to store satellite * access configuration that will be applied to the satellite communication at the corresponding * region. 1001 is one of the Tag ID, and is pointed out current region is supported by carrier * satellite service. */ public static final int SATELLITE_REGION_TAG_ID = 1001; @VisibleForTesting static SatelliteManagerWrapper sSatelliteManagerWrapper; Loading Loading @@ -62,6 +73,25 @@ public class SatelliteCarrierSettingUtils { } /** * Check if current carrier is supported in this region. */ public static boolean isCarrierSatelliteRegionSupported(Context context, @Nullable List<Integer> tagIds, int carrierId) { if (tagIds == null) { return true; } int[] carrierIds = context.getResources().getIntArray( com.android.settings.R.array.config_carrier_id_list_for_satellite_geo_fence_check); boolean isCarrierNeedToCheckRegion = Arrays.stream(carrierIds).anyMatch( it -> it == carrierId); if (!isCarrierNeedToCheckRegion) { return true; } return tagIds.stream().anyMatch(tagId -> tagId == SATELLITE_REGION_TAG_ID); } @VisibleForTesting static class SatelliteManagerWrapper { private final SatelliteManager mSatelliteManager; Loading src/com/android/settings/network/telephony/satellite/SatelliteSettingPreferenceController.java +22 −0 Original line number Diff line number Diff line Loading @@ -25,11 +25,13 @@ import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS; import android.content.Context; import android.content.Intent; import android.os.OutcomeReceiver; import android.os.PersistableBundle; import android.provider.Settings; import android.telephony.TelephonyCallback; import android.telephony.TelephonyManager; import android.telephony.satellite.NtnSignalStrength; import android.telephony.satellite.SatelliteAccessConfiguration; import android.telephony.satellite.SatelliteManager; import android.util.Log; Loading Loading @@ -65,12 +67,28 @@ public class SatelliteSettingPreferenceController extends private Boolean mIsSatelliteEligible = null; private PersistableBundle mCarrierConfigs = new PersistableBundle(); private PreferenceScreen mPreferenceScreen; @VisibleForTesting @Nullable List<Integer> mTagIds = null; public SatelliteSettingPreferenceController(@NonNull Context context, @NonNull String key) { super(context, key); mCarrierConfigCache = CarrierConfigCache.getInstance(mContext); mSatelliteManager = mContext.getSystemService(SatelliteManager.class); mTelephonyManager = mContext.getSystemService(TelephonyManager.class); if (mSatelliteManager != null) { mSatelliteManager.requestSatelliteAccessConfigurationForCurrentLocation( context.getMainExecutor(), new OutcomeReceiver<>() { @Override public void onResult(@Nullable SatelliteAccessConfiguration result) { if (result == null) { return; } mTagIds = result.getTagIds(); } }); } } /** Loading Loading @@ -155,7 +173,11 @@ public class SatelliteSettingPreferenceController extends super.updateState(preference); if (preference != null && preference.getKey().equals(getPreferenceKey())) { updateSummary(preference); preference.setEnabled( SatelliteCarrierSettingUtils.isCarrierSatelliteRegionSupported(mContext, mTagIds, mTelephonyManager.getSimSpecificCarrierId())); } } @Override Loading tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingPreferenceControllerTest.java +85 −0 Original line number Diff line number Diff line Loading @@ -28,12 +28,14 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.res.Resources; import android.os.Looper; import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; Loading @@ -58,11 +60,14 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.util.List; @RunWith(AndroidJUnit4.class) @UiThreadTest public class SatelliteSettingPreferenceControllerTest { private static final String KEY = "SatelliteSettingsPreferenceControllerTest"; private static final int TEST_SUB_ID = 5; private static final int TEST_CARRIER_ID = 1234; @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); Loading @@ -71,6 +76,8 @@ public class SatelliteSettingPreferenceControllerTest { private CarrierConfigCache mCarrierConfigCache; @Mock private TelephonyManager mTelephonyManager; @Mock private Resources mResources; private Context mContext; private SatelliteSettingPreferenceController mController; Loading @@ -90,6 +97,8 @@ public class SatelliteSettingPreferenceControllerTest { when(mCarrierConfigCache.getSpecificConfigsForSubId(eq(TEST_SUB_ID), any())).thenReturn( mCarrierConfig); mController = new SatelliteSettingPreferenceController(mContext, KEY); when(mTelephonyManager.getSimSpecificCarrierId()).thenReturn(TEST_CARRIER_ID); when(mContext.getResources()).thenReturn(mResources); } @Test Loading Loading @@ -243,4 +252,80 @@ public class SatelliteSettingPreferenceControllerTest { assertThat(preference.getSummary()).isEqualTo(ResourcesUtils.getResourcesString(mContext, "satellite_setting_disabled_summary")); } @Test public void updateState_regionIsAllowed_preferenceEnabled() { mCarrierConfig.putBoolean( KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); mCarrierConfig.putInt( CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, CARRIER_ROAMING_NTN_CONNECT_MANUAL); mController.initialize(TEST_SUB_ID); int[] testCarrierId = new int[]{TEST_CARRIER_ID}; when(mResources.getIntArray(anyInt())).thenReturn(testCarrierId); PreferenceManager preferenceManager = new PreferenceManager(mContext); PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext); Preference preference = new Preference(mContext); preference.setKey(KEY); preference.setTitle("test title"); preferenceScreen.addPreference(preference); mController.displayPreference(preferenceScreen); mController.mTagIds = List.of(1001); mController.updateState(preference); assertThat(preference.isEnabled()).isEqualTo(true); } @Test public void updateState_noCorrespondingCarrierId_preferenceEnabled() { mCarrierConfig.putBoolean( KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); mCarrierConfig.putInt( CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, CARRIER_ROAMING_NTN_CONNECT_MANUAL); mController.initialize(TEST_SUB_ID); when(mResources.getIntArray(anyInt())).thenReturn(new int[]{}); PreferenceManager preferenceManager = new PreferenceManager(mContext); PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext); Preference preference = new Preference(mContext); preference.setKey(KEY); preference.setTitle("test title"); preferenceScreen.addPreference(preference); mController.displayPreference(preferenceScreen); mController.updateState(preference); assertThat(preference.isEnabled()).isEqualTo(true); } @Test public void updateState_regionIsNotAllowed_preferenceDisabled() { mCarrierConfig.putBoolean( KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); mCarrierConfig.putInt( CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, CARRIER_ROAMING_NTN_CONNECT_MANUAL); mController.initialize(TEST_SUB_ID); int[] testCarrierId = new int[]{TEST_CARRIER_ID}; when(mResources.getIntArray(anyInt())).thenReturn(testCarrierId); PreferenceManager preferenceManager = new PreferenceManager(mContext); PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext); Preference preference = new Preference(mContext); preference.setKey(KEY); preference.setTitle("test title"); preferenceScreen.addPreference(preference); mController.displayPreference(preferenceScreen); mController.mTagIds = List.of(100); mController.updateState(preference); assertThat(preference.isEnabled()).isEqualTo(false); } } Loading
res/values/config.xml +7 −0 Original line number Diff line number Diff line Loading @@ -875,4 +875,11 @@ <!-- Whether to allow other device users to edit network configuration of a shared network by default. --> <bool name="config_allow_edit_network_configuration_by_default">true</bool> <!-- Array of carrier id that use to check current region be in satellite GEO fence or not. --> <integer-array name="config_carrier_id_list_for_satellite_geo_fence_check" translatable="false"> <!-- <item>1234</item> --> </integer-array> </resources>
src/com/android/settings/network/telephony/satellite/SatelliteCarrierSettingUtils.java +30 −0 Original line number Diff line number Diff line Loading @@ -22,15 +22,26 @@ import android.content.Context; import android.telephony.satellite.SatelliteManager; import android.util.Log; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; /** A until for carrier satellite setting. */ public class SatelliteCarrierSettingUtils { private static final String TAG = "SatelliteCarrierSettingUtils"; /** * {@link android.telephony.satellite.SatelliteAccessConfiguration} is used to store satellite * access configuration that will be applied to the satellite communication at the corresponding * region. 1001 is one of the Tag ID, and is pointed out current region is supported by carrier * satellite service. */ public static final int SATELLITE_REGION_TAG_ID = 1001; @VisibleForTesting static SatelliteManagerWrapper sSatelliteManagerWrapper; Loading Loading @@ -62,6 +73,25 @@ public class SatelliteCarrierSettingUtils { } /** * Check if current carrier is supported in this region. */ public static boolean isCarrierSatelliteRegionSupported(Context context, @Nullable List<Integer> tagIds, int carrierId) { if (tagIds == null) { return true; } int[] carrierIds = context.getResources().getIntArray( com.android.settings.R.array.config_carrier_id_list_for_satellite_geo_fence_check); boolean isCarrierNeedToCheckRegion = Arrays.stream(carrierIds).anyMatch( it -> it == carrierId); if (!isCarrierNeedToCheckRegion) { return true; } return tagIds.stream().anyMatch(tagId -> tagId == SATELLITE_REGION_TAG_ID); } @VisibleForTesting static class SatelliteManagerWrapper { private final SatelliteManager mSatelliteManager; Loading
src/com/android/settings/network/telephony/satellite/SatelliteSettingPreferenceController.java +22 −0 Original line number Diff line number Diff line Loading @@ -25,11 +25,13 @@ import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS; import android.content.Context; import android.content.Intent; import android.os.OutcomeReceiver; import android.os.PersistableBundle; import android.provider.Settings; import android.telephony.TelephonyCallback; import android.telephony.TelephonyManager; import android.telephony.satellite.NtnSignalStrength; import android.telephony.satellite.SatelliteAccessConfiguration; import android.telephony.satellite.SatelliteManager; import android.util.Log; Loading Loading @@ -65,12 +67,28 @@ public class SatelliteSettingPreferenceController extends private Boolean mIsSatelliteEligible = null; private PersistableBundle mCarrierConfigs = new PersistableBundle(); private PreferenceScreen mPreferenceScreen; @VisibleForTesting @Nullable List<Integer> mTagIds = null; public SatelliteSettingPreferenceController(@NonNull Context context, @NonNull String key) { super(context, key); mCarrierConfigCache = CarrierConfigCache.getInstance(mContext); mSatelliteManager = mContext.getSystemService(SatelliteManager.class); mTelephonyManager = mContext.getSystemService(TelephonyManager.class); if (mSatelliteManager != null) { mSatelliteManager.requestSatelliteAccessConfigurationForCurrentLocation( context.getMainExecutor(), new OutcomeReceiver<>() { @Override public void onResult(@Nullable SatelliteAccessConfiguration result) { if (result == null) { return; } mTagIds = result.getTagIds(); } }); } } /** Loading Loading @@ -155,7 +173,11 @@ public class SatelliteSettingPreferenceController extends super.updateState(preference); if (preference != null && preference.getKey().equals(getPreferenceKey())) { updateSummary(preference); preference.setEnabled( SatelliteCarrierSettingUtils.isCarrierSatelliteRegionSupported(mContext, mTagIds, mTelephonyManager.getSimSpecificCarrierId())); } } @Override Loading
tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingPreferenceControllerTest.java +85 −0 Original line number Diff line number Diff line Loading @@ -28,12 +28,14 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.res.Resources; import android.os.Looper; import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; Loading @@ -58,11 +60,14 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.util.List; @RunWith(AndroidJUnit4.class) @UiThreadTest public class SatelliteSettingPreferenceControllerTest { private static final String KEY = "SatelliteSettingsPreferenceControllerTest"; private static final int TEST_SUB_ID = 5; private static final int TEST_CARRIER_ID = 1234; @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); Loading @@ -71,6 +76,8 @@ public class SatelliteSettingPreferenceControllerTest { private CarrierConfigCache mCarrierConfigCache; @Mock private TelephonyManager mTelephonyManager; @Mock private Resources mResources; private Context mContext; private SatelliteSettingPreferenceController mController; Loading @@ -90,6 +97,8 @@ public class SatelliteSettingPreferenceControllerTest { when(mCarrierConfigCache.getSpecificConfigsForSubId(eq(TEST_SUB_ID), any())).thenReturn( mCarrierConfig); mController = new SatelliteSettingPreferenceController(mContext, KEY); when(mTelephonyManager.getSimSpecificCarrierId()).thenReturn(TEST_CARRIER_ID); when(mContext.getResources()).thenReturn(mResources); } @Test Loading Loading @@ -243,4 +252,80 @@ public class SatelliteSettingPreferenceControllerTest { assertThat(preference.getSummary()).isEqualTo(ResourcesUtils.getResourcesString(mContext, "satellite_setting_disabled_summary")); } @Test public void updateState_regionIsAllowed_preferenceEnabled() { mCarrierConfig.putBoolean( KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); mCarrierConfig.putInt( CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, CARRIER_ROAMING_NTN_CONNECT_MANUAL); mController.initialize(TEST_SUB_ID); int[] testCarrierId = new int[]{TEST_CARRIER_ID}; when(mResources.getIntArray(anyInt())).thenReturn(testCarrierId); PreferenceManager preferenceManager = new PreferenceManager(mContext); PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext); Preference preference = new Preference(mContext); preference.setKey(KEY); preference.setTitle("test title"); preferenceScreen.addPreference(preference); mController.displayPreference(preferenceScreen); mController.mTagIds = List.of(1001); mController.updateState(preference); assertThat(preference.isEnabled()).isEqualTo(true); } @Test public void updateState_noCorrespondingCarrierId_preferenceEnabled() { mCarrierConfig.putBoolean( KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); mCarrierConfig.putInt( CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, CARRIER_ROAMING_NTN_CONNECT_MANUAL); mController.initialize(TEST_SUB_ID); when(mResources.getIntArray(anyInt())).thenReturn(new int[]{}); PreferenceManager preferenceManager = new PreferenceManager(mContext); PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext); Preference preference = new Preference(mContext); preference.setKey(KEY); preference.setTitle("test title"); preferenceScreen.addPreference(preference); mController.displayPreference(preferenceScreen); mController.updateState(preference); assertThat(preference.isEnabled()).isEqualTo(true); } @Test public void updateState_regionIsNotAllowed_preferenceDisabled() { mCarrierConfig.putBoolean( KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true); mCarrierConfig.putInt( CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, CARRIER_ROAMING_NTN_CONNECT_MANUAL); mController.initialize(TEST_SUB_ID); int[] testCarrierId = new int[]{TEST_CARRIER_ID}; when(mResources.getIntArray(anyInt())).thenReturn(testCarrierId); PreferenceManager preferenceManager = new PreferenceManager(mContext); PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext); Preference preference = new Preference(mContext); preference.setKey(KEY); preference.setTitle("test title"); preferenceScreen.addPreference(preference); mController.displayPreference(preferenceScreen); mController.mTagIds = List.of(100); mController.updateState(preference); assertThat(preference.isEnabled()).isEqualTo(false); } }