Loading src/java/com/android/internal/telephony/satellite/SatelliteController.java +47 −11 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.internal.telephony.satellite; import static android.provider.Settings.ACTION_SATELLITE_SETTING; import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_TYPE; import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL; import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT; import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_SATELLITE_DEFAULT_SERVICES_INT_ARRAY; Loading Loading @@ -4641,7 +4642,6 @@ public class SatelliteController extends Handler { private void handleEventServiceStateChanged() { handleStateChangedForCarrierRoamingNtnEligibility(); handleServiceStateForSatelliteConnectionViaCarrier(); determineSystemNotification(); } private void handleServiceStateForSatelliteConnectionViaCarrier() { Loading Loading @@ -4702,6 +4702,7 @@ public class SatelliteController extends Handler { updateLastNotifiedNtnModeAndNotify(phone); } } determineAutoConnectSystemNotification(); } private void updateLastNotifiedNtnModeAndNotify(@Nullable Phone phone) { Loading Loading @@ -4829,6 +4830,9 @@ public class SatelliteController extends Handler { || mLastNotifiedNtnEligibility != currentNtnEligibility) { mLastNotifiedNtnEligibility = currentNtnEligibility; mSatellitePhone.notifyCarrierRoamingNtnEligibleStateChanged(currentNtnEligibility); updateSatelliteSystemNotification(mSatellitePhone.getSubId(), CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL, currentNtnEligibility); } } } Loading Loading @@ -5094,7 +5098,7 @@ public class SatelliteController extends Handler { return true; } private void determineSystemNotification() { private void determineAutoConnectSystemNotification() { if (!mFeatureFlags.carrierEnabledSatelliteFlag()) { logd("determineSystemNotification: carrierEnabledSatelliteFlag is disabled"); return; Loading @@ -5115,15 +5119,32 @@ public class SatelliteController extends Handler { return; } if (!mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)) { showSatelliteSystemNotification(isNtn.second); updateSatelliteSystemNotification(isNtn.second, CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC, /*visible*/ true); mSharedPreferences.edit().putBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, true).apply(); } } } private void showSatelliteSystemNotification(int subId) { plogd("showSatelliteSystemNotification"); /** * Update the system notification to reflect the current satellite status, that's either already * connected OR needs to be manually enabled. The device should only display one notification * at a time to prevent confusing the user, so the same NOTIFICATION_CHANNEL and NOTIFICATION_ID * are used. * * @param subId The subId that provides the satellite connection. * @param carrierRoamingNtnConnectType {@link CarrierConfigManager * .CARRIER_ROAMING_NTN_CONNECT_TYPE} * @param visible {@code true} to show the notification, {@code false} to cancel it. */ private void updateSatelliteSystemNotification(int subId, @CARRIER_ROAMING_NTN_CONNECT_TYPE int carrierRoamingNtnConnectType, boolean visible) { plogd("updateSatelliteSystemNotification subId=" + subId + ", carrierRoamingNtnConnectType=" + SatelliteServiceUtils .carrierRoamingNtnConnectTypeToString(carrierRoamingNtnConnectType) + ", visible=" + visible); final NotificationChannel notificationChannel = new NotificationChannel( NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL, Loading @@ -5132,15 +5153,30 @@ public class SatelliteController extends Handler { notificationChannel.setSound(null, null); NotificationManager notificationManager = mContext.getSystemService( NotificationManager.class); if (notificationManager == null) { ploge("updateSatelliteSystemNotification: notificationManager is null"); return; } if (!visible) { // Cancel if any. notificationManager.cancelAsUser(NOTIFICATION_TAG, NOTIFICATION_ID, UserHandle.ALL); return; } notificationManager.createNotificationChannel(notificationChannel); Notification.Builder notificationBuilder = new Notification.Builder(mContext) .setContentTitle(mContext.getResources().getString( R.string.satellite_notification_title)) .setContentText(mContext.getResources().getString( R.string.satellite_notification_summary)) // if carrierRoamingNtnConnectType is CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC int title = R.string.satellite_notification_title; int summary = R.string.satellite_notification_summary; if (carrierRoamingNtnConnectType == CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL) { title = R.string.satellite_notification_manual_title; summary = R.string.satellite_notification_manual_summary; } Notification.Builder notificationBuilder = new Notification.Builder(mContext, NOTIFICATION_CHANNEL_ID) .setContentTitle(mContext.getResources().getString(title)) .setContentText(mContext.getResources().getString(summary)) .setSmallIcon(R.drawable.ic_android_satellite_24px) .setChannelId(NOTIFICATION_CHANNEL_ID) .setAutoCancel(true) .setColor(mContext.getColor( com.android.internal.R.color.system_notification_accent_color)) Loading src/java/com/android/internal/telephony/satellite/SatelliteServiceUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.os.AsyncResult; import android.os.Binder; import android.os.PersistableBundle; import android.telephony.AccessNetworkConstants; import android.telephony.CarrierConfigManager; import android.telephony.CellIdentity; import android.telephony.NetworkRegistrationInfo; import android.telephony.Rlog; Loading Loading @@ -63,6 +64,21 @@ import java.util.stream.Collectors; public class SatelliteServiceUtils { private static final String TAG = "SatelliteServiceUtils"; /** * Converts a carrier roaming NTN (Non-Terrestrial Network) connect type constant * from {@link CarrierConfigManager} to string. * @param type The carrier roaming NTN connect type constant. * @return A string representation of the connect type, or "Unknown(type)" if not recognized. */ public static String carrierRoamingNtnConnectTypeToString( @CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_TYPE int type) { return switch (type) { case CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC -> "AUTOMATIC"; case CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL -> "MANUAL"; default -> "Unknown(" + type + ")"; }; } /** * Convert radio technology from service definition to framework definition. * @param radioTechnology The NTRadioTechnology from the satellite service. Loading tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +7 −5 Original line number Diff line number Diff line Loading @@ -3394,14 +3394,13 @@ public class SatelliteControllerTest extends TelephonyTest { } @Test public void testHandleEventServiceStateChanged() throws Exception { public void testHandleEventServiceStateChanged() { when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); // Do nothing when the satellite is not connected doReturn(false).when(mServiceState).isUsingNonTerrestrialNetwork(); sendServiceStateChangedEvent(); processAllMessages(); assertEquals(false, mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); assertFalse(mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); verify(mMockNotificationManager, never()).notifyAsUser(anyString(), anyInt(), any(), any()); // Check sending a system notification when the satellite is connected Loading @@ -3410,8 +3409,7 @@ public class SatelliteControllerTest extends TelephonyTest { processAllMessages(); verify(mMockNotificationManager, times(1)).notifyAsUser(anyString(), anyInt(), any(), any()); assertEquals(true, mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); assertTrue(mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); // Check don't display again after displayed already a system notification. sendServiceStateChangedEvent(); Loading Loading @@ -3904,6 +3902,8 @@ public class SatelliteControllerTest extends TelephonyTest { assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); verify(mMockNotificationManager, times(1)).notifyAsUser(anyString(), anyInt(), any(), any()); clearInvocations(mPhone); when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); Loading Loading @@ -3935,6 +3935,8 @@ public class SatelliteControllerTest extends TelephonyTest { assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), anyInt(), any()); } @Test Loading Loading
src/java/com/android/internal/telephony/satellite/SatelliteController.java +47 −11 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.internal.telephony.satellite; import static android.provider.Settings.ACTION_SATELLITE_SETTING; import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_TYPE; import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL; import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT; import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_SATELLITE_DEFAULT_SERVICES_INT_ARRAY; Loading Loading @@ -4641,7 +4642,6 @@ public class SatelliteController extends Handler { private void handleEventServiceStateChanged() { handleStateChangedForCarrierRoamingNtnEligibility(); handleServiceStateForSatelliteConnectionViaCarrier(); determineSystemNotification(); } private void handleServiceStateForSatelliteConnectionViaCarrier() { Loading Loading @@ -4702,6 +4702,7 @@ public class SatelliteController extends Handler { updateLastNotifiedNtnModeAndNotify(phone); } } determineAutoConnectSystemNotification(); } private void updateLastNotifiedNtnModeAndNotify(@Nullable Phone phone) { Loading Loading @@ -4829,6 +4830,9 @@ public class SatelliteController extends Handler { || mLastNotifiedNtnEligibility != currentNtnEligibility) { mLastNotifiedNtnEligibility = currentNtnEligibility; mSatellitePhone.notifyCarrierRoamingNtnEligibleStateChanged(currentNtnEligibility); updateSatelliteSystemNotification(mSatellitePhone.getSubId(), CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL, currentNtnEligibility); } } } Loading Loading @@ -5094,7 +5098,7 @@ public class SatelliteController extends Handler { return true; } private void determineSystemNotification() { private void determineAutoConnectSystemNotification() { if (!mFeatureFlags.carrierEnabledSatelliteFlag()) { logd("determineSystemNotification: carrierEnabledSatelliteFlag is disabled"); return; Loading @@ -5115,15 +5119,32 @@ public class SatelliteController extends Handler { return; } if (!mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)) { showSatelliteSystemNotification(isNtn.second); updateSatelliteSystemNotification(isNtn.second, CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC, /*visible*/ true); mSharedPreferences.edit().putBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, true).apply(); } } } private void showSatelliteSystemNotification(int subId) { plogd("showSatelliteSystemNotification"); /** * Update the system notification to reflect the current satellite status, that's either already * connected OR needs to be manually enabled. The device should only display one notification * at a time to prevent confusing the user, so the same NOTIFICATION_CHANNEL and NOTIFICATION_ID * are used. * * @param subId The subId that provides the satellite connection. * @param carrierRoamingNtnConnectType {@link CarrierConfigManager * .CARRIER_ROAMING_NTN_CONNECT_TYPE} * @param visible {@code true} to show the notification, {@code false} to cancel it. */ private void updateSatelliteSystemNotification(int subId, @CARRIER_ROAMING_NTN_CONNECT_TYPE int carrierRoamingNtnConnectType, boolean visible) { plogd("updateSatelliteSystemNotification subId=" + subId + ", carrierRoamingNtnConnectType=" + SatelliteServiceUtils .carrierRoamingNtnConnectTypeToString(carrierRoamingNtnConnectType) + ", visible=" + visible); final NotificationChannel notificationChannel = new NotificationChannel( NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL, Loading @@ -5132,15 +5153,30 @@ public class SatelliteController extends Handler { notificationChannel.setSound(null, null); NotificationManager notificationManager = mContext.getSystemService( NotificationManager.class); if (notificationManager == null) { ploge("updateSatelliteSystemNotification: notificationManager is null"); return; } if (!visible) { // Cancel if any. notificationManager.cancelAsUser(NOTIFICATION_TAG, NOTIFICATION_ID, UserHandle.ALL); return; } notificationManager.createNotificationChannel(notificationChannel); Notification.Builder notificationBuilder = new Notification.Builder(mContext) .setContentTitle(mContext.getResources().getString( R.string.satellite_notification_title)) .setContentText(mContext.getResources().getString( R.string.satellite_notification_summary)) // if carrierRoamingNtnConnectType is CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC int title = R.string.satellite_notification_title; int summary = R.string.satellite_notification_summary; if (carrierRoamingNtnConnectType == CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL) { title = R.string.satellite_notification_manual_title; summary = R.string.satellite_notification_manual_summary; } Notification.Builder notificationBuilder = new Notification.Builder(mContext, NOTIFICATION_CHANNEL_ID) .setContentTitle(mContext.getResources().getString(title)) .setContentText(mContext.getResources().getString(summary)) .setSmallIcon(R.drawable.ic_android_satellite_24px) .setChannelId(NOTIFICATION_CHANNEL_ID) .setAutoCancel(true) .setColor(mContext.getColor( com.android.internal.R.color.system_notification_accent_color)) Loading
src/java/com/android/internal/telephony/satellite/SatelliteServiceUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.os.AsyncResult; import android.os.Binder; import android.os.PersistableBundle; import android.telephony.AccessNetworkConstants; import android.telephony.CarrierConfigManager; import android.telephony.CellIdentity; import android.telephony.NetworkRegistrationInfo; import android.telephony.Rlog; Loading Loading @@ -63,6 +64,21 @@ import java.util.stream.Collectors; public class SatelliteServiceUtils { private static final String TAG = "SatelliteServiceUtils"; /** * Converts a carrier roaming NTN (Non-Terrestrial Network) connect type constant * from {@link CarrierConfigManager} to string. * @param type The carrier roaming NTN connect type constant. * @return A string representation of the connect type, or "Unknown(type)" if not recognized. */ public static String carrierRoamingNtnConnectTypeToString( @CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_TYPE int type) { return switch (type) { case CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC -> "AUTOMATIC"; case CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL -> "MANUAL"; default -> "Unknown(" + type + ")"; }; } /** * Convert radio technology from service definition to framework definition. * @param radioTechnology The NTRadioTechnology from the satellite service. Loading
tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +7 −5 Original line number Diff line number Diff line Loading @@ -3394,14 +3394,13 @@ public class SatelliteControllerTest extends TelephonyTest { } @Test public void testHandleEventServiceStateChanged() throws Exception { public void testHandleEventServiceStateChanged() { when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true); // Do nothing when the satellite is not connected doReturn(false).when(mServiceState).isUsingNonTerrestrialNetwork(); sendServiceStateChangedEvent(); processAllMessages(); assertEquals(false, mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); assertFalse(mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); verify(mMockNotificationManager, never()).notifyAsUser(anyString(), anyInt(), any(), any()); // Check sending a system notification when the satellite is connected Loading @@ -3410,8 +3409,7 @@ public class SatelliteControllerTest extends TelephonyTest { processAllMessages(); verify(mMockNotificationManager, times(1)).notifyAsUser(anyString(), anyInt(), any(), any()); assertEquals(true, mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); assertTrue(mSharedPreferences.getBoolean(SATELLITE_SYSTEM_NOTIFICATION_DONE_KEY, false)); // Check don't display again after displayed already a system notification. sendServiceStateChangedEvent(); Loading Loading @@ -3904,6 +3902,8 @@ public class SatelliteControllerTest extends TelephonyTest { assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); verify(mMockNotificationManager, times(1)).notifyAsUser(anyString(), anyInt(), any(), any()); clearInvocations(mPhone); when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); Loading Loading @@ -3935,6 +3935,8 @@ public class SatelliteControllerTest extends TelephonyTest { assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone)); verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true)); verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean()); verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), anyInt(), any()); } @Test Loading