Loading src/java/com/android/internal/telephony/satellite/SatelliteController.java +15 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,7 @@ import android.telephony.ServiceState; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.TelephonyRegistryManager; import android.telephony.satellite.INtnSignalStrengthCallback; import android.telephony.satellite.ISatelliteCapabilitiesCallback; import android.telephony.satellite.ISatelliteDatagramCallback; Loading Loading @@ -4326,6 +4327,9 @@ public class SatelliteController extends Handler { if (!enabled) { mIsModemEnabledReportingNtnSignalStrength.set(false); } if (mFeatureFlags.satelliteStateChangeListener()) { notifyEnabledStateChanged(enabled); } } private void registerForPendingDatagramCount() { Loading Loading @@ -7543,4 +7547,15 @@ public class SatelliteController extends Handler { mContext.registerReceiver(mPackageStateChangedReceiver, packageFilter, mContext.RECEIVER_EXPORTED); } private void notifyEnabledStateChanged(boolean isEnabled) { TelephonyRegistryManager trm = mContext.getSystemService(TelephonyRegistryManager.class); if (trm == null) { loge("Telephony registry service is down!"); return; } trm.notifySatelliteStateChanged(isEnabled); logd("notifyEnabledStateChanged to " + isEnabled); } } tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +88 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import android.content.Intent; import android.content.pm.UserInfo; import android.net.LinkProperties; import android.os.Build; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; Loading Loading @@ -104,6 +105,7 @@ public class TelephonyRegistryTest extends TelephonyTest { // Mocked classes private SubscriptionInfo mMockSubInfo; private TelephonyRegistry.ConfigurationProvider mMockConfigurationProvider; private IBinder mMockIBinder; private TelephonyCallbackWrapper mTelephonyCallback; private List<LinkCapacityEstimate> mLinkCapacityEstimateList; Loading @@ -129,6 +131,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private boolean mCarrierRoamingNtnMode; private boolean mCarrierRoamingNtnEligible; private List<Integer> mCarrierRoamingNtnAvailableServices; private boolean mIsSatelliteEnabled; // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired private static final Set<Integer> READ_PHONE_STATE_EVENTS; Loading Loading @@ -342,6 +345,18 @@ public class TelephonyRegistryTest extends TelephonyTest { } } public class MySatelliteStateChangeListener implements ISatelliteStateChangeListener { @Override public void onSatelliteEnabledStateChanged(boolean isEnabled) throws RemoteException { mIsSatelliteEnabled = isEnabled; } @Override public IBinder asBinder() { return mMockIBinder; } } private void addTelephonyRegistryService() { mServiceManagerMockedServices.put("telephony.registry", mTelephonyRegistry.asBinder()); mTelephonyRegistry.systemRunning(); Loading @@ -354,6 +369,7 @@ public class TelephonyRegistryTest extends TelephonyTest { super.setUp(getClass().getSimpleName()); mMockSubInfo = mock(SubscriptionInfo.class); mMockConfigurationProvider = mock(TelephonyRegistry.ConfigurationProvider.class); mMockIBinder = mock(IBinder.class); when(mMockConfigurationProvider.getRegistrationLimit()).thenReturn(-1); when(mMockConfigurationProvider.isRegistrationLimitEnabledInPlatformCompat(anyInt())) .thenReturn(false); Loading Loading @@ -381,6 +397,7 @@ public class TelephonyRegistryTest extends TelephonyTest { processAllMessages(); assertEquals(mTelephonyRegistry.asBinder(), ServiceManager.getService("telephony.registry")); doReturn(new int[]{1}).when(mSubscriptionManager).getActiveSubscriptionIdList(); } @After Loading Loading @@ -1724,4 +1741,75 @@ public class TelephonyRegistryTest extends TelephonyTest { .mapToInt(Integer::intValue).toArray(); assertTrue(Arrays.equals(carrierServices, services)); } @Test @EnableFlags(Flags.FLAG_SATELLITE_STATE_CHANGE_LISTENER) public void testNotifySatelliteStateChanged_onRegistration_getNotified() { MySatelliteStateChangeListener listener = new MySatelliteStateChangeListener(); // Set initial satellite enabled state to true mTelephonyRegistry.notifySatelliteStateChanged(true); try { // Start monitoring mTelephonyRegistry.addSatelliteStateChangeListener(listener, mContext.getOpPackageName(), mContext.getAttributionTag()); processAllMessages(); // verify latest state is immediately available on registration assertTrue(mIsSatelliteEnabled); } finally { // Clean up mTelephonyRegistry.removeSatelliteStateChangeListener(listener, mContext.getOpPackageName()); } } @Test @EnableFlags(Flags.FLAG_SATELLITE_STATE_CHANGE_LISTENER) public void testNotifySatelliteStateChanged_duringRegistration_getNotified() { MySatelliteStateChangeListener listener = new MySatelliteStateChangeListener(); // Set initial satellite enabled state to true mTelephonyRegistry.notifySatelliteStateChanged(true); try { // Start monitoring mTelephonyRegistry.addSatelliteStateChangeListener(listener, mContext.getOpPackageName(), mContext.getAttributionTag()); // Satellite enabled state changed mTelephonyRegistry.notifySatelliteStateChanged(false); processAllMessages(); // We can receive the new state assertFalse(mIsSatelliteEnabled); } finally { // Clean up mTelephonyRegistry.removeSatelliteStateChangeListener(listener, mContext.getOpPackageName()); } } @Test @EnableFlags(Flags.FLAG_SATELLITE_STATE_CHANGE_LISTENER) public void testNotifySatelliteStateChanged_removeRegistration_notNotified() { MySatelliteStateChangeListener listener = new MySatelliteStateChangeListener(); // Set initial satellite enabled state to true mTelephonyRegistry.notifySatelliteStateChanged(true); try { // Start monitoring mTelephonyRegistry.addSatelliteStateChangeListener(listener, mContext.getOpPackageName(), mContext.getAttributionTag()); mTelephonyRegistry.notifySatelliteStateChanged(false); } finally { // Stop monitoring from now on mTelephonyRegistry.removeSatelliteStateChangeListener(listener, mContext.getOpPackageName()); } // Satellite enabled state changed again mTelephonyRegistry.notifySatelliteStateChanged(true); processAllMessages(); // We should not receive the new state change after monitoring end assertFalse(mIsSatelliteEnabled); } } tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyVararg; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; Loading Loading @@ -952,6 +953,7 @@ public class SatelliteControllerTest extends TelephonyTest { @Test public void testRequestSatelliteEnabled() { when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); when(mFeatureFlags.satelliteStateChangeListener()).thenReturn(true); mIsSatelliteEnabledSemaphore.drainPermits(); // Fail to enable satellite when SatelliteController is not fully loaded yet. Loading Loading @@ -1008,6 +1010,7 @@ public class SatelliteControllerTest extends TelephonyTest { doReturn(false).when(mTelecomManager).isInEmergencyCall(); // Successfully enable satellite reset(mTelephonyRegistryManager); mIIntegerConsumerResults.clear(); mIIntegerConsumerSemaphore.drainPermits(); mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; Loading @@ -1029,8 +1032,10 @@ public class SatelliteControllerTest extends TelephonyTest { verify(mMockDatagramController, times(2)).setDemoMode(eq(false)); verify(mMockControllerMetricsStats, times(1)).onSatelliteEnabled(); verify(mMockControllerMetricsStats, times(1)).reportServiceEnablementSuccessCount(); verify(mTelephonyRegistryManager).notifySatelliteStateChanged(eq(true)); // Successfully disable satellite when radio is turned off. reset(mTelephonyRegistryManager); clearInvocations(mMockSatelliteSessionController); clearInvocations(mMockDatagramController); mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); Loading @@ -1054,6 +1059,7 @@ public class SatelliteControllerTest extends TelephonyTest { verify(mMockDatagramController, times(2)).setDemoMode(eq(false)); verify(mMockControllerMetricsStats, times(1)).onSatelliteDisabled(); mSatelliteControllerUT.isSatelliteBeingDisabled = false; verify(mTelephonyRegistryManager, atLeastOnce()).notifySatelliteStateChanged(eq(false)); // Fail to enable satellite when radio is off. mIIntegerConsumerResults.clear(); Loading Loading @@ -1089,6 +1095,7 @@ public class SatelliteControllerTest extends TelephonyTest { verify(mMockControllerMetricsStats, times(1)).reportServiceEnablementFailCount(); // Successfully enable satellite when radio is on. reset(mTelephonyRegistryManager); mIIntegerConsumerResults.clear(); mIIntegerConsumerSemaphore.drainPermits(); mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; Loading @@ -1107,6 +1114,7 @@ public class SatelliteControllerTest extends TelephonyTest { verify(mMockDatagramController, times(3)).setDemoMode(eq(false)); verify(mMockControllerMetricsStats, times(2)).onSatelliteEnabled(); verify(mMockControllerMetricsStats, times(2)).reportServiceEnablementSuccessCount(); verify(mTelephonyRegistryManager).notifySatelliteStateChanged(eq(true)); // Successfully enable satellite when it is already enabled. mIIntegerConsumerResults.clear(); Loading @@ -1127,6 +1135,7 @@ public class SatelliteControllerTest extends TelephonyTest { verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); // Successfully disable satellite. reset(mTelephonyRegistryManager); mIIntegerConsumerResults.clear(); mIIntegerConsumerSemaphore.drainPermits(); setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); Loading @@ -1135,6 +1144,7 @@ public class SatelliteControllerTest extends TelephonyTest { assertTrue(waitForIIntegerConsumerResult(1)); assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); verify(mTelephonyRegistryManager, atLeastOnce()).notifySatelliteStateChanged(eq(false)); // Disable satellite when satellite is already disabled. mIIntegerConsumerResults.clear(); Loading Loading
src/java/com/android/internal/telephony/satellite/SatelliteController.java +15 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,7 @@ import android.telephony.ServiceState; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.TelephonyRegistryManager; import android.telephony.satellite.INtnSignalStrengthCallback; import android.telephony.satellite.ISatelliteCapabilitiesCallback; import android.telephony.satellite.ISatelliteDatagramCallback; Loading Loading @@ -4326,6 +4327,9 @@ public class SatelliteController extends Handler { if (!enabled) { mIsModemEnabledReportingNtnSignalStrength.set(false); } if (mFeatureFlags.satelliteStateChangeListener()) { notifyEnabledStateChanged(enabled); } } private void registerForPendingDatagramCount() { Loading Loading @@ -7543,4 +7547,15 @@ public class SatelliteController extends Handler { mContext.registerReceiver(mPackageStateChangedReceiver, packageFilter, mContext.RECEIVER_EXPORTED); } private void notifyEnabledStateChanged(boolean isEnabled) { TelephonyRegistryManager trm = mContext.getSystemService(TelephonyRegistryManager.class); if (trm == null) { loge("Telephony registry service is down!"); return; } trm.notifySatelliteStateChanged(isEnabled); logd("notifyEnabledStateChanged to " + isEnabled); } }
tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +88 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import android.content.Intent; import android.content.pm.UserInfo; import android.net.LinkProperties; import android.os.Build; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; Loading Loading @@ -104,6 +105,7 @@ public class TelephonyRegistryTest extends TelephonyTest { // Mocked classes private SubscriptionInfo mMockSubInfo; private TelephonyRegistry.ConfigurationProvider mMockConfigurationProvider; private IBinder mMockIBinder; private TelephonyCallbackWrapper mTelephonyCallback; private List<LinkCapacityEstimate> mLinkCapacityEstimateList; Loading @@ -129,6 +131,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private boolean mCarrierRoamingNtnMode; private boolean mCarrierRoamingNtnEligible; private List<Integer> mCarrierRoamingNtnAvailableServices; private boolean mIsSatelliteEnabled; // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired private static final Set<Integer> READ_PHONE_STATE_EVENTS; Loading Loading @@ -342,6 +345,18 @@ public class TelephonyRegistryTest extends TelephonyTest { } } public class MySatelliteStateChangeListener implements ISatelliteStateChangeListener { @Override public void onSatelliteEnabledStateChanged(boolean isEnabled) throws RemoteException { mIsSatelliteEnabled = isEnabled; } @Override public IBinder asBinder() { return mMockIBinder; } } private void addTelephonyRegistryService() { mServiceManagerMockedServices.put("telephony.registry", mTelephonyRegistry.asBinder()); mTelephonyRegistry.systemRunning(); Loading @@ -354,6 +369,7 @@ public class TelephonyRegistryTest extends TelephonyTest { super.setUp(getClass().getSimpleName()); mMockSubInfo = mock(SubscriptionInfo.class); mMockConfigurationProvider = mock(TelephonyRegistry.ConfigurationProvider.class); mMockIBinder = mock(IBinder.class); when(mMockConfigurationProvider.getRegistrationLimit()).thenReturn(-1); when(mMockConfigurationProvider.isRegistrationLimitEnabledInPlatformCompat(anyInt())) .thenReturn(false); Loading Loading @@ -381,6 +397,7 @@ public class TelephonyRegistryTest extends TelephonyTest { processAllMessages(); assertEquals(mTelephonyRegistry.asBinder(), ServiceManager.getService("telephony.registry")); doReturn(new int[]{1}).when(mSubscriptionManager).getActiveSubscriptionIdList(); } @After Loading Loading @@ -1724,4 +1741,75 @@ public class TelephonyRegistryTest extends TelephonyTest { .mapToInt(Integer::intValue).toArray(); assertTrue(Arrays.equals(carrierServices, services)); } @Test @EnableFlags(Flags.FLAG_SATELLITE_STATE_CHANGE_LISTENER) public void testNotifySatelliteStateChanged_onRegistration_getNotified() { MySatelliteStateChangeListener listener = new MySatelliteStateChangeListener(); // Set initial satellite enabled state to true mTelephonyRegistry.notifySatelliteStateChanged(true); try { // Start monitoring mTelephonyRegistry.addSatelliteStateChangeListener(listener, mContext.getOpPackageName(), mContext.getAttributionTag()); processAllMessages(); // verify latest state is immediately available on registration assertTrue(mIsSatelliteEnabled); } finally { // Clean up mTelephonyRegistry.removeSatelliteStateChangeListener(listener, mContext.getOpPackageName()); } } @Test @EnableFlags(Flags.FLAG_SATELLITE_STATE_CHANGE_LISTENER) public void testNotifySatelliteStateChanged_duringRegistration_getNotified() { MySatelliteStateChangeListener listener = new MySatelliteStateChangeListener(); // Set initial satellite enabled state to true mTelephonyRegistry.notifySatelliteStateChanged(true); try { // Start monitoring mTelephonyRegistry.addSatelliteStateChangeListener(listener, mContext.getOpPackageName(), mContext.getAttributionTag()); // Satellite enabled state changed mTelephonyRegistry.notifySatelliteStateChanged(false); processAllMessages(); // We can receive the new state assertFalse(mIsSatelliteEnabled); } finally { // Clean up mTelephonyRegistry.removeSatelliteStateChangeListener(listener, mContext.getOpPackageName()); } } @Test @EnableFlags(Flags.FLAG_SATELLITE_STATE_CHANGE_LISTENER) public void testNotifySatelliteStateChanged_removeRegistration_notNotified() { MySatelliteStateChangeListener listener = new MySatelliteStateChangeListener(); // Set initial satellite enabled state to true mTelephonyRegistry.notifySatelliteStateChanged(true); try { // Start monitoring mTelephonyRegistry.addSatelliteStateChangeListener(listener, mContext.getOpPackageName(), mContext.getAttributionTag()); mTelephonyRegistry.notifySatelliteStateChanged(false); } finally { // Stop monitoring from now on mTelephonyRegistry.removeSatelliteStateChangeListener(listener, mContext.getOpPackageName()); } // Satellite enabled state changed again mTelephonyRegistry.notifySatelliteStateChanged(true); processAllMessages(); // We should not receive the new state change after monitoring end assertFalse(mIsSatelliteEnabled); } }
tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyVararg; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; Loading Loading @@ -952,6 +953,7 @@ public class SatelliteControllerTest extends TelephonyTest { @Test public void testRequestSatelliteEnabled() { when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); when(mFeatureFlags.satelliteStateChangeListener()).thenReturn(true); mIsSatelliteEnabledSemaphore.drainPermits(); // Fail to enable satellite when SatelliteController is not fully loaded yet. Loading Loading @@ -1008,6 +1010,7 @@ public class SatelliteControllerTest extends TelephonyTest { doReturn(false).when(mTelecomManager).isInEmergencyCall(); // Successfully enable satellite reset(mTelephonyRegistryManager); mIIntegerConsumerResults.clear(); mIIntegerConsumerSemaphore.drainPermits(); mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; Loading @@ -1029,8 +1032,10 @@ public class SatelliteControllerTest extends TelephonyTest { verify(mMockDatagramController, times(2)).setDemoMode(eq(false)); verify(mMockControllerMetricsStats, times(1)).onSatelliteEnabled(); verify(mMockControllerMetricsStats, times(1)).reportServiceEnablementSuccessCount(); verify(mTelephonyRegistryManager).notifySatelliteStateChanged(eq(true)); // Successfully disable satellite when radio is turned off. reset(mTelephonyRegistryManager); clearInvocations(mMockSatelliteSessionController); clearInvocations(mMockDatagramController); mSatelliteControllerUT.setSatelliteSessionController(mMockSatelliteSessionController); Loading @@ -1054,6 +1059,7 @@ public class SatelliteControllerTest extends TelephonyTest { verify(mMockDatagramController, times(2)).setDemoMode(eq(false)); verify(mMockControllerMetricsStats, times(1)).onSatelliteDisabled(); mSatelliteControllerUT.isSatelliteBeingDisabled = false; verify(mTelephonyRegistryManager, atLeastOnce()).notifySatelliteStateChanged(eq(false)); // Fail to enable satellite when radio is off. mIIntegerConsumerResults.clear(); Loading Loading @@ -1089,6 +1095,7 @@ public class SatelliteControllerTest extends TelephonyTest { verify(mMockControllerMetricsStats, times(1)).reportServiceEnablementFailCount(); // Successfully enable satellite when radio is on. reset(mTelephonyRegistryManager); mIIntegerConsumerResults.clear(); mIIntegerConsumerSemaphore.drainPermits(); mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false; Loading @@ -1107,6 +1114,7 @@ public class SatelliteControllerTest extends TelephonyTest { verify(mMockDatagramController, times(3)).setDemoMode(eq(false)); verify(mMockControllerMetricsStats, times(2)).onSatelliteEnabled(); verify(mMockControllerMetricsStats, times(2)).reportServiceEnablementSuccessCount(); verify(mTelephonyRegistryManager).notifySatelliteStateChanged(eq(true)); // Successfully enable satellite when it is already enabled. mIIntegerConsumerResults.clear(); Loading @@ -1127,6 +1135,7 @@ public class SatelliteControllerTest extends TelephonyTest { verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS); // Successfully disable satellite. reset(mTelephonyRegistryManager); mIIntegerConsumerResults.clear(); mIIntegerConsumerSemaphore.drainPermits(); setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS); Loading @@ -1135,6 +1144,7 @@ public class SatelliteControllerTest extends TelephonyTest { assertTrue(waitForIIntegerConsumerResult(1)); assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0)); verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS); verify(mTelephonyRegistryManager, atLeastOnce()).notifySatelliteStateChanged(eq(false)); // Disable satellite when satellite is already disabled. mIIntegerConsumerResults.clear(); Loading