Loading src/java/com/android/internal/telephony/ServiceStateTracker.java +12 −3 Original line number Original line Diff line number Diff line Loading @@ -71,6 +71,7 @@ import android.telephony.PhysicalChannelConfig; import android.telephony.Rlog; import android.telephony.Rlog; import android.telephony.ServiceState; import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; Loading Loading @@ -4007,17 +4008,25 @@ public class ServiceStateTracker extends Handler { loge("cannot setNotification on invalid subid mSubId=" + mSubId); loge("cannot setNotification on invalid subid mSubId=" + mSubId); return; return; } } Context context = mPhone.getContext(); SubscriptionInfo info = mSubscriptionController .getActiveSubscriptionInfo(mPhone.getSubId(), context.getOpPackageName()); //if subscription is part of a group and non-primary, suppress all notifications if (info == null || (info.isOpportunistic() && info.getGroupUuid() != null)) { log("cannot setNotification on invisible subid mSubId=" + mSubId); return; } // Needed because sprout RIL sends these when they shouldn't? // Needed because sprout RIL sends these when they shouldn't? boolean isSetNotification = mPhone.getContext().getResources().getBoolean( boolean isSetNotification = context.getResources().getBoolean( com.android.internal.R.bool.config_user_notification_of_restrictied_mobile_access); com.android.internal.R.bool.config_user_notification_of_restrictied_mobile_access); if (!isSetNotification) { if (!isSetNotification) { if (DBG) log("Ignore all the notifications"); if (DBG) log("Ignore all the notifications"); return; return; } } Context context = mPhone.getContext(); boolean autoCancelCsRejectNotification = false; boolean autoCancelCsRejectNotification = false; PersistableBundle bundle = getCarrierConfig(); PersistableBundle bundle = getCarrierConfig(); Loading tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +60 −4 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify; Loading Loading @@ -81,6 +82,7 @@ import android.telephony.NetworkService; import android.telephony.PhysicalChannelConfig; import android.telephony.PhysicalChannelConfig; import android.telephony.ServiceState; import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; import android.telephony.cdma.CdmaCellLocation; import android.telephony.cdma.CdmaCellLocation; Loading Loading @@ -126,6 +128,9 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Mock @Mock private INetworkService.Stub mIwlanNetworkServiceStub; private INetworkService.Stub mIwlanNetworkServiceStub; @Mock private SubscriptionInfo mSubInfo; private ServiceStateTracker sst; private ServiceStateTracker sst; private ServiceStateTrackerTestHandler mSSTTestHandler; private ServiceStateTrackerTestHandler mSSTTestHandler; private PersistableBundle mBundle; private PersistableBundle mBundle; Loading Loading @@ -1380,7 +1385,13 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testSetPsNotifications() { public void testSetPsNotifications() { sst.mSubId = 1; int subId = 1; sst.mSubId = subId; doReturn(subId).when(mSubInfo).getSubscriptionId(); doReturn(mSubInfo).when(mSubscriptionController).getActiveSubscriptionInfo( anyInt(), anyString()); final NotificationManager nm = (NotificationManager) final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( mContextFixture.putBooleanResource( Loading @@ -1407,7 +1418,12 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testSetCsNotifications() { public void testSetCsNotifications() { sst.mSubId = 1; int subId = 1; sst.mSubId = subId; doReturn(subId).when(mSubInfo).getSubscriptionId(); doReturn(mSubInfo).when(mSubscriptionController) .getActiveSubscriptionInfo(anyInt(), anyString()); final NotificationManager nm = (NotificationManager) final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( mContextFixture.putBooleanResource( Loading Loading @@ -1435,7 +1451,12 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testSetCsNormalNotifications() { public void testSetCsNormalNotifications() { sst.mSubId = 1; int subId = 1; sst.mSubId = subId; doReturn(subId).when(mSubInfo).getSubscriptionId(); doReturn(mSubInfo).when(mSubscriptionController) .getActiveSubscriptionInfo(anyInt(), anyString()); final NotificationManager nm = (NotificationManager) final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( mContextFixture.putBooleanResource( Loading @@ -1462,7 +1483,12 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testSetCsEmergencyNotifications() { public void testSetCsEmergencyNotifications() { sst.mSubId = 1; int subId = 1; sst.mSubId = subId; doReturn(subId).when(mSubInfo).getSubscriptionId(); doReturn(mSubInfo).when(mSubscriptionController) .getActiveSubscriptionInfo(anyInt(), anyString()); final NotificationManager nm = (NotificationManager) final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( mContextFixture.putBooleanResource( Loading @@ -1488,6 +1514,36 @@ public class ServiceStateTrackerTest extends TelephonyTest { sst.setNotification(ServiceStateTracker.CS_REJECT_CAUSE_ENABLED); sst.setNotification(ServiceStateTracker.CS_REJECT_CAUSE_ENABLED); } } @Test @SmallTest public void testSetNotificationsForGroupedSubs() { //if subscription is grouped, no notification should be set whatsoever int subId = 1; int otherSubId = 2; sst.mSubId = otherSubId; doReturn(subId).when(mSubInfo).getSubscriptionId(); final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( R.bool.config_user_notification_of_restrictied_mobile_access, true); doReturn(new ApplicationInfo()).when(mContext).getApplicationInfo(); Drawable mockDrawable = mock(Drawable.class); Resources mockResources = mContext.getResources(); when(mockResources.getDrawable(anyInt(), any())).thenReturn(mockDrawable); mContextFixture.putResource(com.android.internal.R.string.RestrictedOnDataTitle, "test1"); sst.setNotification(ServiceStateTracker.EVENT_NETWORK_STATE_CHANGED); ArgumentCaptor<Notification> notificationArgumentCaptor = ArgumentCaptor.forClass(Notification.class); verify(nm, never()).notify(anyString(), anyInt(), notificationArgumentCaptor.capture()); sst.setNotification(ServiceStateTracker.PS_DISABLED); verify(nm, never()).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.PS_NOTIFICATION); } @Test @Test @MediumTest @MediumTest public void testRegisterForSubscriptionInfoReady() { public void testRegisterForSubscriptionInfoReady() { Loading Loading
src/java/com/android/internal/telephony/ServiceStateTracker.java +12 −3 Original line number Original line Diff line number Diff line Loading @@ -71,6 +71,7 @@ import android.telephony.PhysicalChannelConfig; import android.telephony.Rlog; import android.telephony.Rlog; import android.telephony.ServiceState; import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; Loading Loading @@ -4007,17 +4008,25 @@ public class ServiceStateTracker extends Handler { loge("cannot setNotification on invalid subid mSubId=" + mSubId); loge("cannot setNotification on invalid subid mSubId=" + mSubId); return; return; } } Context context = mPhone.getContext(); SubscriptionInfo info = mSubscriptionController .getActiveSubscriptionInfo(mPhone.getSubId(), context.getOpPackageName()); //if subscription is part of a group and non-primary, suppress all notifications if (info == null || (info.isOpportunistic() && info.getGroupUuid() != null)) { log("cannot setNotification on invisible subid mSubId=" + mSubId); return; } // Needed because sprout RIL sends these when they shouldn't? // Needed because sprout RIL sends these when they shouldn't? boolean isSetNotification = mPhone.getContext().getResources().getBoolean( boolean isSetNotification = context.getResources().getBoolean( com.android.internal.R.bool.config_user_notification_of_restrictied_mobile_access); com.android.internal.R.bool.config_user_notification_of_restrictied_mobile_access); if (!isSetNotification) { if (!isSetNotification) { if (DBG) log("Ignore all the notifications"); if (DBG) log("Ignore all the notifications"); return; return; } } Context context = mPhone.getContext(); boolean autoCancelCsRejectNotification = false; boolean autoCancelCsRejectNotification = false; PersistableBundle bundle = getCarrierConfig(); PersistableBundle bundle = getCarrierConfig(); Loading
tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +60 −4 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify; Loading Loading @@ -81,6 +82,7 @@ import android.telephony.NetworkService; import android.telephony.PhysicalChannelConfig; import android.telephony.PhysicalChannelConfig; import android.telephony.ServiceState; import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; import android.telephony.cdma.CdmaCellLocation; import android.telephony.cdma.CdmaCellLocation; Loading Loading @@ -126,6 +128,9 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Mock @Mock private INetworkService.Stub mIwlanNetworkServiceStub; private INetworkService.Stub mIwlanNetworkServiceStub; @Mock private SubscriptionInfo mSubInfo; private ServiceStateTracker sst; private ServiceStateTracker sst; private ServiceStateTrackerTestHandler mSSTTestHandler; private ServiceStateTrackerTestHandler mSSTTestHandler; private PersistableBundle mBundle; private PersistableBundle mBundle; Loading Loading @@ -1380,7 +1385,13 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testSetPsNotifications() { public void testSetPsNotifications() { sst.mSubId = 1; int subId = 1; sst.mSubId = subId; doReturn(subId).when(mSubInfo).getSubscriptionId(); doReturn(mSubInfo).when(mSubscriptionController).getActiveSubscriptionInfo( anyInt(), anyString()); final NotificationManager nm = (NotificationManager) final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( mContextFixture.putBooleanResource( Loading @@ -1407,7 +1418,12 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testSetCsNotifications() { public void testSetCsNotifications() { sst.mSubId = 1; int subId = 1; sst.mSubId = subId; doReturn(subId).when(mSubInfo).getSubscriptionId(); doReturn(mSubInfo).when(mSubscriptionController) .getActiveSubscriptionInfo(anyInt(), anyString()); final NotificationManager nm = (NotificationManager) final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( mContextFixture.putBooleanResource( Loading Loading @@ -1435,7 +1451,12 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testSetCsNormalNotifications() { public void testSetCsNormalNotifications() { sst.mSubId = 1; int subId = 1; sst.mSubId = subId; doReturn(subId).when(mSubInfo).getSubscriptionId(); doReturn(mSubInfo).when(mSubscriptionController) .getActiveSubscriptionInfo(anyInt(), anyString()); final NotificationManager nm = (NotificationManager) final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( mContextFixture.putBooleanResource( Loading @@ -1462,7 +1483,12 @@ public class ServiceStateTrackerTest extends TelephonyTest { @Test @Test @SmallTest @SmallTest public void testSetCsEmergencyNotifications() { public void testSetCsEmergencyNotifications() { sst.mSubId = 1; int subId = 1; sst.mSubId = subId; doReturn(subId).when(mSubInfo).getSubscriptionId(); doReturn(mSubInfo).when(mSubscriptionController) .getActiveSubscriptionInfo(anyInt(), anyString()); final NotificationManager nm = (NotificationManager) final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( mContextFixture.putBooleanResource( Loading @@ -1488,6 +1514,36 @@ public class ServiceStateTrackerTest extends TelephonyTest { sst.setNotification(ServiceStateTracker.CS_REJECT_CAUSE_ENABLED); sst.setNotification(ServiceStateTracker.CS_REJECT_CAUSE_ENABLED); } } @Test @SmallTest public void testSetNotificationsForGroupedSubs() { //if subscription is grouped, no notification should be set whatsoever int subId = 1; int otherSubId = 2; sst.mSubId = otherSubId; doReturn(subId).when(mSubInfo).getSubscriptionId(); final NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mContextFixture.putBooleanResource( R.bool.config_user_notification_of_restrictied_mobile_access, true); doReturn(new ApplicationInfo()).when(mContext).getApplicationInfo(); Drawable mockDrawable = mock(Drawable.class); Resources mockResources = mContext.getResources(); when(mockResources.getDrawable(anyInt(), any())).thenReturn(mockDrawable); mContextFixture.putResource(com.android.internal.R.string.RestrictedOnDataTitle, "test1"); sst.setNotification(ServiceStateTracker.EVENT_NETWORK_STATE_CHANGED); ArgumentCaptor<Notification> notificationArgumentCaptor = ArgumentCaptor.forClass(Notification.class); verify(nm, never()).notify(anyString(), anyInt(), notificationArgumentCaptor.capture()); sst.setNotification(ServiceStateTracker.PS_DISABLED); verify(nm, never()).cancel(Integer.toString(sst.mSubId), ServiceStateTracker.PS_NOTIFICATION); } @Test @Test @MediumTest @MediumTest public void testRegisterForSubscriptionInfoReady() { public void testRegisterForSubscriptionInfoReady() { Loading