Loading src/java/com/android/internal/telephony/satellite/SatelliteController.java +41 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ import android.content.res.Resources; import android.database.ContentObserver; import android.hardware.devicestate.DeviceState; import android.hardware.devicestate.DeviceStateManager; import android.location.LocationManager; import android.net.Uri; import android.net.wifi.WifiManager; import android.nfc.NfcAdapter; Loading Loading @@ -315,6 +316,7 @@ public class SatelliteController extends Handler { private static final int EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE = 59; private static final int EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED = 60; private static final int CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE = 61; private static final int CMD_LOCATION_SERVICE_STATE_CHANGED = 62; @NonNull private static SatelliteController sInstance; @NonNull private final Context mContext; Loading Loading @@ -740,6 +742,17 @@ public class SatelliteController extends Handler { } }; protected BroadcastReceiver mLocationServiceStateChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Check whether user has turned on/off location manager from settings menu if (intent.getAction().equals(LocationManager.MODE_CHANGED_ACTION)) { plogd("mLocationServiceStateChangedReceiver"); sendRequestAsync(CMD_LOCATION_SERVICE_STATE_CHANGED, null, null); } } }; // List of device states returned from DeviceStateManager to determine if running on a foldable // device. private List<DeviceState> mDeviceStates = new ArrayList(); Loading Loading @@ -936,6 +949,7 @@ public class SatelliteController extends Handler { mSatellitePlmnListFromOverlayConfig = readSatellitePlmnsFromOverlayConfig(); registerApplicationStateChanged(); registerLocationServiceStateChanged(); updateSupportedSatelliteServicesForActiveSubscriptions(); mCarrierConfigChangeListener = (slotIndex, subId, carrierId, specificCarrierId) -> Loading Loading @@ -2194,6 +2208,9 @@ public class SatelliteController extends Handler { break; } case CMD_LOCATION_SERVICE_STATE_CHANGED: plogd("CMD_LOCATION_SERVICE_STATE_CHANGED"); // Fall through case CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE: { plogd("CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE"); evaluateCarrierRoamingNtnEligibilityChange(); Loading Loading @@ -7842,6 +7859,13 @@ public class SatelliteController extends Handler { return false; } // Even if Location service is off, isSatelliteAccessAllowed can be true // when the device is in emergency call and the allowed cache is valid. if (!isLocationServiceEnabled()) { plogd("isCarrierRoamingNtnEligible: Location service is off"); return false; } if (phone == null) { plogd("isCarrierRoamingNtnEligible: phone is null"); return false; Loading Loading @@ -8470,6 +8494,12 @@ public class SatelliteController extends Handler { mContext.RECEIVER_EXPORTED); } private void registerLocationServiceStateChanged() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION); mContext.registerReceiver(mLocationServiceStateChangedReceiver, intentFilter); } private void notifyEnabledStateChanged(boolean isEnabled) { TelephonyRegistryManager trm = mContext.getSystemService(TelephonyRegistryManager.class); Loading Loading @@ -8710,6 +8740,17 @@ public class SatelliteController extends Handler { == NetworkRegistrationInfo.SERVICE_TYPE_DATA); } @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) protected boolean isLocationServiceEnabled() { LocationManager lm = mContext.createAttributionContext("telephony") .getSystemService(LocationManager.class); if (lm != null) { return lm.isLocationEnabled(); } return true; } /** * Method to return the current satellite data service policy supported mode for the registered * plmn based on entitlement provisioning information. Note: If no information at Loading tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +78 −0 Original line number Diff line number Diff line Loading @@ -134,6 +134,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; import android.hardware.devicestate.DeviceState; import android.location.LocationManager; import android.net.Uri; import android.os.AsyncResult; import android.os.Bundle; Loading Loading @@ -285,6 +286,7 @@ public class SatelliteControllerTest extends TelephonyTest { @Mock private SubscriptionManager mSubscriptionManager; @Mock private SubscriptionInfo mSubscriptionInfo; @Mock private PackageManager mMockPManager; @Mock private Intent mMockLocationIntent; private Semaphore mIIntegerConsumerSemaphore = new Semaphore(0); private IIntegerConsumer mIIntegerConsumer = new IIntegerConsumer.Stub() { Loading Loading @@ -5876,6 +5878,8 @@ public class SatelliteControllerTest extends TelephonyTest { private boolean callOnlySuperMethod = false; public boolean isSatelliteEnabledOrBeingEnabled = false; private boolean mLocationServiceEnabled = true; TestSatelliteController( Context context, Looper looper, @NonNull FeatureFlags featureFlags) { super(context, looper, featureFlags); Loading Loading @@ -5997,6 +6001,11 @@ public class SatelliteControllerTest extends TelephonyTest { return selectedSatelliteSubId; } @Override protected boolean isLocationServiceEnabled() { return mLocationServiceEnabled; } void setSatelliteProvisioned(@Nullable Boolean isProvisioned) { synchronized (mDeviceProvisionLock) { mIsDeviceProvisioned = isProvisioned; Loading Loading @@ -6074,6 +6083,14 @@ public class SatelliteControllerTest extends TelephonyTest { public void setCallOnlySuperMethod() { callOnlySuperMethod = true; } public void setLocationServiceEnabled(boolean locationServiceEnabled) { mLocationServiceEnabled = locationServiceEnabled; } public BroadcastReceiver getLocationReceiver() { return mLocationServiceStateChangedReceiver; } } @Test Loading Loading @@ -6790,4 +6807,65 @@ public class SatelliteControllerTest extends TelephonyTest { processAllMessages(); verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); } @Test public void testNotifyNtnEligibilityLocationServiceStatusChanged() { // Enable CarrierRoamingNtn mContextFixture.putBooleanResource( R.bool.config_satellite_should_notify_availability, true); when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); when(mServiceState2.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); mSatelliteControllerUT.mIsApplicationSupportsP2P = true; mSatelliteControllerUT.setIsSatelliteSupported(true); mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, CARRIER_ROAMING_NTN_CONNECT_MANUAL); mCarrierConfigBundle.putInt( KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT, 1 * 60); mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ROAMING_P2P_SMS_SUPPORTED_BOOL, true); int[] supportedServices2 = {2}; int[] supportedServices3 = {1, 3}; PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle(); carrierSupportedSatelliteServicesPerProvider.putIntArray( "00102", supportedServices2); carrierSupportedSatelliteServicesPerProvider.putIntArray( "00103", supportedServices3); mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, carrierSupportedSatelliteServicesPerProvider); for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair : mCarrierConfigChangedListenerList) { pair.first.execute(() -> pair.second.onCarrierConfigChanged( /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) ); } mSatelliteControllerUT.setSatellitePhone(1); mSatelliteControllerUT.setSelectedSatelliteSubId(SUB_ID); mSatelliteControllerUT.isSatelliteProvisioned = true; mSatelliteControllerUT.isSatelliteAllowedCallback = null; mSatelliteControllerUT.setIsSatelliteAllowedState(true); processAllMessages(); clearInvocations(mPhone); doReturn(LocationManager.MODE_CHANGED_ACTION).when(mMockLocationIntent).getAction(); // Location service off mSatelliteControllerUT.setLocationServiceEnabled(false); BroadcastReceiver receiver = mSatelliteControllerUT.getLocationReceiver(); receiver.onReceive(mContext, mMockLocationIntent); processAllMessages(); verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(false)); clearInvocations(mPhone); // Location service off mSatelliteControllerUT.setLocationServiceEnabled(true); receiver.onReceive(mContext, mMockLocationIntent); processAllMessages(); verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); } } Loading
src/java/com/android/internal/telephony/satellite/SatelliteController.java +41 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ import android.content.res.Resources; import android.database.ContentObserver; import android.hardware.devicestate.DeviceState; import android.hardware.devicestate.DeviceStateManager; import android.location.LocationManager; import android.net.Uri; import android.net.wifi.WifiManager; import android.nfc.NfcAdapter; Loading Loading @@ -315,6 +316,7 @@ public class SatelliteController extends Handler { private static final int EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE = 59; private static final int EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED = 60; private static final int CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE = 61; private static final int CMD_LOCATION_SERVICE_STATE_CHANGED = 62; @NonNull private static SatelliteController sInstance; @NonNull private final Context mContext; Loading Loading @@ -740,6 +742,17 @@ public class SatelliteController extends Handler { } }; protected BroadcastReceiver mLocationServiceStateChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Check whether user has turned on/off location manager from settings menu if (intent.getAction().equals(LocationManager.MODE_CHANGED_ACTION)) { plogd("mLocationServiceStateChangedReceiver"); sendRequestAsync(CMD_LOCATION_SERVICE_STATE_CHANGED, null, null); } } }; // List of device states returned from DeviceStateManager to determine if running on a foldable // device. private List<DeviceState> mDeviceStates = new ArrayList(); Loading Loading @@ -936,6 +949,7 @@ public class SatelliteController extends Handler { mSatellitePlmnListFromOverlayConfig = readSatellitePlmnsFromOverlayConfig(); registerApplicationStateChanged(); registerLocationServiceStateChanged(); updateSupportedSatelliteServicesForActiveSubscriptions(); mCarrierConfigChangeListener = (slotIndex, subId, carrierId, specificCarrierId) -> Loading Loading @@ -2194,6 +2208,9 @@ public class SatelliteController extends Handler { break; } case CMD_LOCATION_SERVICE_STATE_CHANGED: plogd("CMD_LOCATION_SERVICE_STATE_CHANGED"); // Fall through case CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE: { plogd("CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE"); evaluateCarrierRoamingNtnEligibilityChange(); Loading Loading @@ -7842,6 +7859,13 @@ public class SatelliteController extends Handler { return false; } // Even if Location service is off, isSatelliteAccessAllowed can be true // when the device is in emergency call and the allowed cache is valid. if (!isLocationServiceEnabled()) { plogd("isCarrierRoamingNtnEligible: Location service is off"); return false; } if (phone == null) { plogd("isCarrierRoamingNtnEligible: phone is null"); return false; Loading Loading @@ -8470,6 +8494,12 @@ public class SatelliteController extends Handler { mContext.RECEIVER_EXPORTED); } private void registerLocationServiceStateChanged() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION); mContext.registerReceiver(mLocationServiceStateChangedReceiver, intentFilter); } private void notifyEnabledStateChanged(boolean isEnabled) { TelephonyRegistryManager trm = mContext.getSystemService(TelephonyRegistryManager.class); Loading Loading @@ -8710,6 +8740,17 @@ public class SatelliteController extends Handler { == NetworkRegistrationInfo.SERVICE_TYPE_DATA); } @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) protected boolean isLocationServiceEnabled() { LocationManager lm = mContext.createAttributionContext("telephony") .getSystemService(LocationManager.class); if (lm != null) { return lm.isLocationEnabled(); } return true; } /** * Method to return the current satellite data service policy supported mode for the registered * plmn based on entitlement provisioning information. Note: If no information at Loading
tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +78 −0 Original line number Diff line number Diff line Loading @@ -134,6 +134,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; import android.hardware.devicestate.DeviceState; import android.location.LocationManager; import android.net.Uri; import android.os.AsyncResult; import android.os.Bundle; Loading Loading @@ -285,6 +286,7 @@ public class SatelliteControllerTest extends TelephonyTest { @Mock private SubscriptionManager mSubscriptionManager; @Mock private SubscriptionInfo mSubscriptionInfo; @Mock private PackageManager mMockPManager; @Mock private Intent mMockLocationIntent; private Semaphore mIIntegerConsumerSemaphore = new Semaphore(0); private IIntegerConsumer mIIntegerConsumer = new IIntegerConsumer.Stub() { Loading Loading @@ -5876,6 +5878,8 @@ public class SatelliteControllerTest extends TelephonyTest { private boolean callOnlySuperMethod = false; public boolean isSatelliteEnabledOrBeingEnabled = false; private boolean mLocationServiceEnabled = true; TestSatelliteController( Context context, Looper looper, @NonNull FeatureFlags featureFlags) { super(context, looper, featureFlags); Loading Loading @@ -5997,6 +6001,11 @@ public class SatelliteControllerTest extends TelephonyTest { return selectedSatelliteSubId; } @Override protected boolean isLocationServiceEnabled() { return mLocationServiceEnabled; } void setSatelliteProvisioned(@Nullable Boolean isProvisioned) { synchronized (mDeviceProvisionLock) { mIsDeviceProvisioned = isProvisioned; Loading Loading @@ -6074,6 +6083,14 @@ public class SatelliteControllerTest extends TelephonyTest { public void setCallOnlySuperMethod() { callOnlySuperMethod = true; } public void setLocationServiceEnabled(boolean locationServiceEnabled) { mLocationServiceEnabled = locationServiceEnabled; } public BroadcastReceiver getLocationReceiver() { return mLocationServiceStateChangedReceiver; } } @Test Loading Loading @@ -6790,4 +6807,65 @@ public class SatelliteControllerTest extends TelephonyTest { processAllMessages(); verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); } @Test public void testNotifyNtnEligibilityLocationServiceStatusChanged() { // Enable CarrierRoamingNtn mContextFixture.putBooleanResource( R.bool.config_satellite_should_notify_availability, true); when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); when(mServiceState2.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); mSatelliteControllerUT.mIsApplicationSupportsP2P = true; mSatelliteControllerUT.setIsSatelliteSupported(true); mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true); mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT, CARRIER_ROAMING_NTN_CONNECT_MANUAL); mCarrierConfigBundle.putInt( KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT, 1 * 60); mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ROAMING_P2P_SMS_SUPPORTED_BOOL, true); int[] supportedServices2 = {2}; int[] supportedServices3 = {1, 3}; PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle(); carrierSupportedSatelliteServicesPerProvider.putIntArray( "00102", supportedServices2); carrierSupportedSatelliteServicesPerProvider.putIntArray( "00103", supportedServices3); mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE, carrierSupportedSatelliteServicesPerProvider); for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair : mCarrierConfigChangedListenerList) { pair.first.execute(() -> pair.second.onCarrierConfigChanged( /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0) ); } mSatelliteControllerUT.setSatellitePhone(1); mSatelliteControllerUT.setSelectedSatelliteSubId(SUB_ID); mSatelliteControllerUT.isSatelliteProvisioned = true; mSatelliteControllerUT.isSatelliteAllowedCallback = null; mSatelliteControllerUT.setIsSatelliteAllowedState(true); processAllMessages(); clearInvocations(mPhone); doReturn(LocationManager.MODE_CHANGED_ACTION).when(mMockLocationIntent).getAction(); // Location service off mSatelliteControllerUT.setLocationServiceEnabled(false); BroadcastReceiver receiver = mSatelliteControllerUT.getLocationReceiver(); receiver.onReceive(mContext, mMockLocationIntent); processAllMessages(); verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(false)); clearInvocations(mPhone); // Location service off mSatelliteControllerUT.setLocationServiceEnabled(true); receiver.onReceive(mContext, mMockLocationIntent); processAllMessages(); verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); } }