Loading src/java/com/android/internal/telephony/CarrierServiceStateTracker.java +46 −10 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.database.ContentObserver; import android.os.Handler; import android.os.Message; Loading Loading @@ -64,6 +65,12 @@ public class CarrierServiceStateTracker extends Handler { public static final int NOTIFICATION_PREF_NETWORK = 1000; public static final int NOTIFICATION_EMERGENCY_NETWORK = 1001; @VisibleForTesting public static final String EMERGENCY_NOTIFICATION_TAG = "EmergencyNetworkNotification"; @VisibleForTesting public static final String PREF_NETWORK_NOTIFICATION_TAG = "PrefNetworkNotification"; public CarrierServiceStateTracker(Phone phone, ServiceStateTracker sst) { this.mPhone = phone; this.mSST = sst; Loading Loading @@ -238,7 +245,7 @@ public class CarrierServiceStateTracker extends Handler { Rlog.i(LOG_TAG, "starting timer for notifications." + notificationType.getTypeId()); sendMessageDelayed(notificationMsg, getDelay(notificationType)); } else { cancelNotification(notificationType.getTypeId()); cancelNotification(notificationType); Rlog.i(LOG_TAG, "canceling notifications: " + notificationType.getTypeId()); } } Loading Loading @@ -307,17 +314,18 @@ public class CarrierServiceStateTracker extends Handler { .setSmallIcon(com.android.internal.R.drawable.stat_sys_warning) .setColor(context.getResources().getColor( com.android.internal.R.color.system_notification_accent_color)); getNotificationManager(context).notify(notificationType.getTypeId(), builder.build()); getNotificationManager(context).notify(notificationType.getNotificationTag(), notificationType.getNotificationId(), builder.build()); } /** * Cancel notifications if a registration is pending or has been sent. **/ public void cancelNotification(int notificationId) { public void cancelNotification(NotificationType notificationType) { Context context = mPhone.getContext(); removeMessages(notificationId); getNotificationManager(context).cancel(notificationId); removeMessages(notificationType.getTypeId()); getNotificationManager(context).cancel( notificationType.getNotificationTag(), notificationType.getNotificationId()); } /** Loading Loading @@ -352,6 +360,16 @@ public class CarrierServiceStateTracker extends Handler { **/ int getTypeId(); /** * returns notification id. **/ int getNotificationId(); /** * returns notification tag. **/ String getNotificationTag(); /** * returns the notification builder, for the notification to be displayed. **/ Loading Loading @@ -392,6 +410,14 @@ public class CarrierServiceStateTracker extends Handler { return mTypeId; } public int getNotificationId() { return mPhone.getSubId(); } public String getNotificationTag() { return PREF_NETWORK_NOTIFICATION_TAG; } /** * Contains logic on sending notifications. */ Loading @@ -415,9 +441,10 @@ public class CarrierServiceStateTracker extends Handler { notificationIntent.putExtra("expandable", true); PendingIntent settingsIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT); CharSequence title = context.getText( Resources res = SubscriptionManager.getResourcesForSubId(context, mPhone.getSubId()); CharSequence title = res.getText( com.android.internal.R.string.NetworkPreferenceSwitchTitle); CharSequence details = context.getText( CharSequence details = res.getText( com.android.internal.R.string.NetworkPreferenceSwitchSummary); return new Notification.Builder(context) .setContentTitle(title) Loading Loading @@ -462,6 +489,14 @@ public class CarrierServiceStateTracker extends Handler { return mTypeId; } public int getNotificationId() { return mPhone.getSubId(); } public String getNotificationTag() { return EMERGENCY_NOTIFICATION_TAG; } /** * Contains logic on sending notifications, */ Loading @@ -481,9 +516,10 @@ public class CarrierServiceStateTracker extends Handler { */ public Notification.Builder getNotificationBuilder() { Context context = mPhone.getContext(); CharSequence title = context.getText( Resources res = SubscriptionManager.getResourcesForSubId(context, mPhone.getSubId()); CharSequence title = res.getText( com.android.internal.R.string.EmergencyCallWarningTitle); CharSequence details = context.getText( CharSequence details = res.getText( com.android.internal.R.string.EmergencyCallWarningSummary); return new Notification.Builder(context) .setContentTitle(title) Loading tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java +17 −10 Original line number Diff line number Diff line Loading @@ -57,6 +57,8 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { private CarrierServiceStateTracker mCarrierSST; private CarrierServiceStateTrackerTestHandler mCarrierServiceStateTrackerTestHandler; private static final int SUB_ID = 1; NotificationManager mNotificationManager; PersistableBundle mBundle; Loading @@ -79,7 +81,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { logd(LOG_TAG + "Setup!"); super.setUp(getClass().getSimpleName()); mBundle = mContextFixture.getCarrierConfigBundle(); when(mPhone.getSubId()).thenReturn(1); when(mPhone.getSubId()).thenReturn(SUB_ID); mCarrierServiceStateTrackerTestHandler = new CarrierServiceStateTrackerTestHandler(getClass().getSimpleName()); mCarrierServiceStateTrackerTestHandler.start(); Loading Loading @@ -115,9 +117,10 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { mSpyCarrierSST.handleMessage(notificationMsg); waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT); verify(mNotificationManager).cancel( CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK); CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID); verify(mNotificationManager).cancel( CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK); CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID); } @Test Loading @@ -135,9 +138,11 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { mSpyCarrierSST.handleMessage(notificationMsg); waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT); verify(mNotificationManager).notify( eq(CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK), isA(Notification.class)); eq(CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); verify(mNotificationManager).notify( eq(CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK), any()); eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG), eq(SUB_ID), any()); } @Test Loading Loading @@ -169,7 +174,9 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { Settings.Global.getUriFor(prefNetworkMode)); waitForMs(500); verify(mNotificationManager, atLeast(1)).notify( eq(CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK), isA(Notification.class)); eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); Settings.Global.putInt(mContext.getContentResolver(), prefNetworkMode, RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); Loading @@ -177,7 +184,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { Settings.Global.getUriFor(prefNetworkMode)); waitForMs(500); verify(mNotificationManager, atLeast(1)).cancel( CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK); CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID); } @Test Loading Loading @@ -207,13 +214,13 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { mSpyCarrierSST.handleMessage(notificationMsg); waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT); verify(mNotificationManager).notify( eq(CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK), isA(Notification.class)); eq(CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); doReturn(false).when(mPhone).isWifiCallingEnabled(); mSpyCarrierSST.handleMessage(notificationMsg); waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT); verify(mNotificationManager, atLeast(2)).cancel( CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK); CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID); } } tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -1332,7 +1332,7 @@ public class ServiceStateTrackerTest extends TelephonyTest { assertEquals("test1", getNotificationTitle(postedNotification)); sst.setNotification(ServiceStateTracker.PS_DISABLED); verify(nm).cancel(anyString(), anyInt()); verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.PS_NOTIFICATION); } @Test Loading Loading @@ -1360,7 +1360,7 @@ public class ServiceStateTrackerTest extends TelephonyTest { assertEquals("test2", getNotificationTitle(postedNotification)); sst.setNotification(ServiceStateTracker.CS_DISABLED); verify(nm).cancel(anyString(), anyInt()); verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION); } @Test Loading @@ -1387,7 +1387,7 @@ public class ServiceStateTrackerTest extends TelephonyTest { assertEquals("test3", getNotificationTitle(postedNotification)); sst.setNotification(ServiceStateTracker.CS_DISABLED); verify(nm).cancel(anyString(), anyInt()); verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION); } @Test Loading Loading @@ -1415,7 +1415,7 @@ public class ServiceStateTrackerTest extends TelephonyTest { assertEquals("test4", getNotificationTitle(postedNotification)); sst.setNotification(ServiceStateTracker.CS_DISABLED); verify(nm).cancel(anyString(), anyInt()); verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION); sst.setNotification(ServiceStateTracker.CS_REJECT_CAUSE_ENABLED); } Loading Loading
src/java/com/android/internal/telephony/CarrierServiceStateTracker.java +46 −10 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.database.ContentObserver; import android.os.Handler; import android.os.Message; Loading Loading @@ -64,6 +65,12 @@ public class CarrierServiceStateTracker extends Handler { public static final int NOTIFICATION_PREF_NETWORK = 1000; public static final int NOTIFICATION_EMERGENCY_NETWORK = 1001; @VisibleForTesting public static final String EMERGENCY_NOTIFICATION_TAG = "EmergencyNetworkNotification"; @VisibleForTesting public static final String PREF_NETWORK_NOTIFICATION_TAG = "PrefNetworkNotification"; public CarrierServiceStateTracker(Phone phone, ServiceStateTracker sst) { this.mPhone = phone; this.mSST = sst; Loading Loading @@ -238,7 +245,7 @@ public class CarrierServiceStateTracker extends Handler { Rlog.i(LOG_TAG, "starting timer for notifications." + notificationType.getTypeId()); sendMessageDelayed(notificationMsg, getDelay(notificationType)); } else { cancelNotification(notificationType.getTypeId()); cancelNotification(notificationType); Rlog.i(LOG_TAG, "canceling notifications: " + notificationType.getTypeId()); } } Loading Loading @@ -307,17 +314,18 @@ public class CarrierServiceStateTracker extends Handler { .setSmallIcon(com.android.internal.R.drawable.stat_sys_warning) .setColor(context.getResources().getColor( com.android.internal.R.color.system_notification_accent_color)); getNotificationManager(context).notify(notificationType.getTypeId(), builder.build()); getNotificationManager(context).notify(notificationType.getNotificationTag(), notificationType.getNotificationId(), builder.build()); } /** * Cancel notifications if a registration is pending or has been sent. **/ public void cancelNotification(int notificationId) { public void cancelNotification(NotificationType notificationType) { Context context = mPhone.getContext(); removeMessages(notificationId); getNotificationManager(context).cancel(notificationId); removeMessages(notificationType.getTypeId()); getNotificationManager(context).cancel( notificationType.getNotificationTag(), notificationType.getNotificationId()); } /** Loading Loading @@ -352,6 +360,16 @@ public class CarrierServiceStateTracker extends Handler { **/ int getTypeId(); /** * returns notification id. **/ int getNotificationId(); /** * returns notification tag. **/ String getNotificationTag(); /** * returns the notification builder, for the notification to be displayed. **/ Loading Loading @@ -392,6 +410,14 @@ public class CarrierServiceStateTracker extends Handler { return mTypeId; } public int getNotificationId() { return mPhone.getSubId(); } public String getNotificationTag() { return PREF_NETWORK_NOTIFICATION_TAG; } /** * Contains logic on sending notifications. */ Loading @@ -415,9 +441,10 @@ public class CarrierServiceStateTracker extends Handler { notificationIntent.putExtra("expandable", true); PendingIntent settingsIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT); CharSequence title = context.getText( Resources res = SubscriptionManager.getResourcesForSubId(context, mPhone.getSubId()); CharSequence title = res.getText( com.android.internal.R.string.NetworkPreferenceSwitchTitle); CharSequence details = context.getText( CharSequence details = res.getText( com.android.internal.R.string.NetworkPreferenceSwitchSummary); return new Notification.Builder(context) .setContentTitle(title) Loading Loading @@ -462,6 +489,14 @@ public class CarrierServiceStateTracker extends Handler { return mTypeId; } public int getNotificationId() { return mPhone.getSubId(); } public String getNotificationTag() { return EMERGENCY_NOTIFICATION_TAG; } /** * Contains logic on sending notifications, */ Loading @@ -481,9 +516,10 @@ public class CarrierServiceStateTracker extends Handler { */ public Notification.Builder getNotificationBuilder() { Context context = mPhone.getContext(); CharSequence title = context.getText( Resources res = SubscriptionManager.getResourcesForSubId(context, mPhone.getSubId()); CharSequence title = res.getText( com.android.internal.R.string.EmergencyCallWarningTitle); CharSequence details = context.getText( CharSequence details = res.getText( com.android.internal.R.string.EmergencyCallWarningSummary); return new Notification.Builder(context) .setContentTitle(title) Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java +17 −10 Original line number Diff line number Diff line Loading @@ -57,6 +57,8 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { private CarrierServiceStateTracker mCarrierSST; private CarrierServiceStateTrackerTestHandler mCarrierServiceStateTrackerTestHandler; private static final int SUB_ID = 1; NotificationManager mNotificationManager; PersistableBundle mBundle; Loading @@ -79,7 +81,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { logd(LOG_TAG + "Setup!"); super.setUp(getClass().getSimpleName()); mBundle = mContextFixture.getCarrierConfigBundle(); when(mPhone.getSubId()).thenReturn(1); when(mPhone.getSubId()).thenReturn(SUB_ID); mCarrierServiceStateTrackerTestHandler = new CarrierServiceStateTrackerTestHandler(getClass().getSimpleName()); mCarrierServiceStateTrackerTestHandler.start(); Loading Loading @@ -115,9 +117,10 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { mSpyCarrierSST.handleMessage(notificationMsg); waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT); verify(mNotificationManager).cancel( CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK); CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID); verify(mNotificationManager).cancel( CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK); CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID); } @Test Loading @@ -135,9 +138,11 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { mSpyCarrierSST.handleMessage(notificationMsg); waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT); verify(mNotificationManager).notify( eq(CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK), isA(Notification.class)); eq(CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); verify(mNotificationManager).notify( eq(CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK), any()); eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG), eq(SUB_ID), any()); } @Test Loading Loading @@ -169,7 +174,9 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { Settings.Global.getUriFor(prefNetworkMode)); waitForMs(500); verify(mNotificationManager, atLeast(1)).notify( eq(CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK), isA(Notification.class)); eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); Settings.Global.putInt(mContext.getContentResolver(), prefNetworkMode, RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); Loading @@ -177,7 +184,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { Settings.Global.getUriFor(prefNetworkMode)); waitForMs(500); verify(mNotificationManager, atLeast(1)).cancel( CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK); CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID); } @Test Loading Loading @@ -207,13 +214,13 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { mSpyCarrierSST.handleMessage(notificationMsg); waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT); verify(mNotificationManager).notify( eq(CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK), isA(Notification.class)); eq(CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); doReturn(false).when(mPhone).isWifiCallingEnabled(); mSpyCarrierSST.handleMessage(notificationMsg); waitForHandlerAction(mSpyCarrierSST, TEST_TIMEOUT); verify(mNotificationManager, atLeast(2)).cancel( CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK); CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID); } }
tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -1332,7 +1332,7 @@ public class ServiceStateTrackerTest extends TelephonyTest { assertEquals("test1", getNotificationTitle(postedNotification)); sst.setNotification(ServiceStateTracker.PS_DISABLED); verify(nm).cancel(anyString(), anyInt()); verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.PS_NOTIFICATION); } @Test Loading Loading @@ -1360,7 +1360,7 @@ public class ServiceStateTrackerTest extends TelephonyTest { assertEquals("test2", getNotificationTitle(postedNotification)); sst.setNotification(ServiceStateTracker.CS_DISABLED); verify(nm).cancel(anyString(), anyInt()); verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION); } @Test Loading @@ -1387,7 +1387,7 @@ public class ServiceStateTrackerTest extends TelephonyTest { assertEquals("test3", getNotificationTitle(postedNotification)); sst.setNotification(ServiceStateTracker.CS_DISABLED); verify(nm).cancel(anyString(), anyInt()); verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION); } @Test Loading Loading @@ -1415,7 +1415,7 @@ public class ServiceStateTrackerTest extends TelephonyTest { assertEquals("test4", getNotificationTitle(postedNotification)); sst.setNotification(ServiceStateTracker.CS_DISABLED); verify(nm).cancel(anyString(), anyInt()); verify(nm).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.CS_NOTIFICATION); sst.setNotification(ServiceStateTracker.CS_REJECT_CAUSE_ENABLED); } Loading