Loading src/java/com/android/internal/telephony/CarrierServiceStateTracker.java +58 −6 Original line number Diff line number Diff line Loading @@ -116,14 +116,15 @@ public class CarrierServiceStateTracker extends Handler { mPhone.getContext(), mPhone.getSubId(), CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT, CarrierConfigManager .KEY_PREF_NETWORK_NOTIFICATION_DELAY_INT); CarrierConfigManager.KEY_PREF_NETWORK_NOTIFICATION_DELAY_INT, CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL); if (b.isEmpty()) return; for (Map.Entry<Integer, NotificationType> entry : mNotificationTypeMap.entrySet()) { NotificationType notificationType = entry.getValue(); notificationType.setDelay(b); notificationType.setEnabled(b); } handleConfigChanges(); }); Loading Loading @@ -429,6 +430,18 @@ public class CarrierServiceStateTracker extends Handler { **/ void setDelay(PersistableBundle bundle); /** * Checks whether this Notification is enabled. * @return {@code true} if this Notification is enabled, false otherwise */ boolean isEnabled(); /** * Sets whether this Notification is enabled. If disabled, it will not build notification. * @param bundle PersistableBundle */ void setEnabled(PersistableBundle bundle); /** * returns notification type id. **/ Loading Loading @@ -458,6 +471,7 @@ public class CarrierServiceStateTracker extends Handler { private final int mTypeId; private int mDelay = UNINITIALIZED_DELAY_VALUE; private boolean mEnabled = false; PrefNetworkNotification(int typeId) { this.mTypeId = typeId; Loading @@ -480,6 +494,28 @@ public class CarrierServiceStateTracker extends Handler { return mDelay; } /** * Checks whether this Notification is enabled. * @return {@code true} if this Notification is enabled, false otherwise */ public boolean isEnabled() { return mEnabled; } /** * Sets whether this Notification is enabled. If disabled, it will not build notification. * @param bundle PersistableBundle */ public void setEnabled(PersistableBundle bundle) { if (bundle == null) { Rlog.e(LOG_TAG, "bundle is null"); return; } mEnabled = !bundle.getBoolean( CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL); Rlog.i(LOG_TAG, "reading enabled notification pref network: " + mEnabled); } public int getTypeId() { return mTypeId; } Loading @@ -497,10 +533,10 @@ public class CarrierServiceStateTracker extends Handler { */ public boolean sendMessage() { Rlog.i(LOG_TAG, "PrefNetworkNotification: sendMessage() w/values: " + "," + isPhoneStillRegistered() + "," + mDelay + "," + isGlobalMode() + "," + mSST.isRadioOn()); if (mDelay == UNINITIALIZED_DELAY_VALUE || isPhoneStillRegistered() || isGlobalMode() || isRadioOffOrAirplaneMode()) { + "," + mEnabled + "," + isPhoneStillRegistered() + "," + mDelay + "," + isGlobalMode() + "," + mSST.isRadioOn()); if (!mEnabled || mDelay == UNINITIALIZED_DELAY_VALUE || isPhoneStillRegistered() || isGlobalMode() || isRadioOffOrAirplaneMode()) { return false; } return true; Loading Loading @@ -559,6 +595,22 @@ public class CarrierServiceStateTracker extends Handler { return mDelay; } /** * Checks whether this Notification is enabled. * @return {@code true} if this Notification is enabled, false otherwise */ public boolean isEnabled() { return true; } /** * Sets whether this Notification is enabled. If disabled, it will not build notification. * @param bundle PersistableBundle */ public void setEnabled(PersistableBundle bundle) { // always allowed. There is no config to hide notifications. } public int getTypeId() { return mTypeId; } Loading tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -16,12 +16,15 @@ package com.android.internal.telephony; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.isA; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -97,6 +100,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { private void setDefaultValues() { mBundle.putInt(CarrierConfigManager.KEY_PREF_NETWORK_NOTIFICATION_DELAY_INT, 0); mBundle.putInt(CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT, 0); mBundle.putBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL, false); } @After Loading Loading @@ -232,4 +236,39 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { verify(mNotificationManager, atLeast(2)).cancel( CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID); } @Test public void testSetEnabledNotifications() { logd(LOG_TAG + ":testSetEnabledNotifications()"); mBundle.putBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL, true); Notification.Builder mNotificationBuilder = new Notification.Builder(mContext); doReturn(mNotificationBuilder).when(mSpyCarrierSST).getNotificationBuilder(any()); doReturn(mNotificationManager).when(mSpyCarrierSST).getNotificationManager(any()); doReturn(true).when(mPhone).isWifiCallingEnabled(); // notifiable for emergency mCarrierConfigChangeListener.onCarrierConfigChanged(0 /* slotIndex */, SUB_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); Map<Integer, CarrierServiceStateTracker.NotificationType> notificationTypeMap = mCarrierSST.getNotificationTypeMap(); CarrierServiceStateTracker.NotificationType prefNetworkNotification = notificationTypeMap.get(CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK); CarrierServiceStateTracker.NotificationType emergencyNetworkNotification = notificationTypeMap.get(CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK); assertFalse(prefNetworkNotification.isEnabled()); assertTrue(emergencyNetworkNotification.isEnabled()); verify(mNotificationManager, never()).notify( eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); verify(mNotificationManager, atLeast(1)).cancel( CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID); verify(mNotificationManager, atLeast(1)).notify( eq(CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); verify(mNotificationManager, never()).cancel( CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID); } } Loading
src/java/com/android/internal/telephony/CarrierServiceStateTracker.java +58 −6 Original line number Diff line number Diff line Loading @@ -116,14 +116,15 @@ public class CarrierServiceStateTracker extends Handler { mPhone.getContext(), mPhone.getSubId(), CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT, CarrierConfigManager .KEY_PREF_NETWORK_NOTIFICATION_DELAY_INT); CarrierConfigManager.KEY_PREF_NETWORK_NOTIFICATION_DELAY_INT, CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL); if (b.isEmpty()) return; for (Map.Entry<Integer, NotificationType> entry : mNotificationTypeMap.entrySet()) { NotificationType notificationType = entry.getValue(); notificationType.setDelay(b); notificationType.setEnabled(b); } handleConfigChanges(); }); Loading Loading @@ -429,6 +430,18 @@ public class CarrierServiceStateTracker extends Handler { **/ void setDelay(PersistableBundle bundle); /** * Checks whether this Notification is enabled. * @return {@code true} if this Notification is enabled, false otherwise */ boolean isEnabled(); /** * Sets whether this Notification is enabled. If disabled, it will not build notification. * @param bundle PersistableBundle */ void setEnabled(PersistableBundle bundle); /** * returns notification type id. **/ Loading Loading @@ -458,6 +471,7 @@ public class CarrierServiceStateTracker extends Handler { private final int mTypeId; private int mDelay = UNINITIALIZED_DELAY_VALUE; private boolean mEnabled = false; PrefNetworkNotification(int typeId) { this.mTypeId = typeId; Loading @@ -480,6 +494,28 @@ public class CarrierServiceStateTracker extends Handler { return mDelay; } /** * Checks whether this Notification is enabled. * @return {@code true} if this Notification is enabled, false otherwise */ public boolean isEnabled() { return mEnabled; } /** * Sets whether this Notification is enabled. If disabled, it will not build notification. * @param bundle PersistableBundle */ public void setEnabled(PersistableBundle bundle) { if (bundle == null) { Rlog.e(LOG_TAG, "bundle is null"); return; } mEnabled = !bundle.getBoolean( CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL); Rlog.i(LOG_TAG, "reading enabled notification pref network: " + mEnabled); } public int getTypeId() { return mTypeId; } Loading @@ -497,10 +533,10 @@ public class CarrierServiceStateTracker extends Handler { */ public boolean sendMessage() { Rlog.i(LOG_TAG, "PrefNetworkNotification: sendMessage() w/values: " + "," + isPhoneStillRegistered() + "," + mDelay + "," + isGlobalMode() + "," + mSST.isRadioOn()); if (mDelay == UNINITIALIZED_DELAY_VALUE || isPhoneStillRegistered() || isGlobalMode() || isRadioOffOrAirplaneMode()) { + "," + mEnabled + "," + isPhoneStillRegistered() + "," + mDelay + "," + isGlobalMode() + "," + mSST.isRadioOn()); if (!mEnabled || mDelay == UNINITIALIZED_DELAY_VALUE || isPhoneStillRegistered() || isGlobalMode() || isRadioOffOrAirplaneMode()) { return false; } return true; Loading Loading @@ -559,6 +595,22 @@ public class CarrierServiceStateTracker extends Handler { return mDelay; } /** * Checks whether this Notification is enabled. * @return {@code true} if this Notification is enabled, false otherwise */ public boolean isEnabled() { return true; } /** * Sets whether this Notification is enabled. If disabled, it will not build notification. * @param bundle PersistableBundle */ public void setEnabled(PersistableBundle bundle) { // always allowed. There is no config to hide notifications. } public int getTypeId() { return mTypeId; } Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -16,12 +16,15 @@ package com.android.internal.telephony; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.isA; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -97,6 +100,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { private void setDefaultValues() { mBundle.putInt(CarrierConfigManager.KEY_PREF_NETWORK_NOTIFICATION_DELAY_INT, 0); mBundle.putInt(CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT, 0); mBundle.putBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL, false); } @After Loading Loading @@ -232,4 +236,39 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { verify(mNotificationManager, atLeast(2)).cancel( CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID); } @Test public void testSetEnabledNotifications() { logd(LOG_TAG + ":testSetEnabledNotifications()"); mBundle.putBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL, true); Notification.Builder mNotificationBuilder = new Notification.Builder(mContext); doReturn(mNotificationBuilder).when(mSpyCarrierSST).getNotificationBuilder(any()); doReturn(mNotificationManager).when(mSpyCarrierSST).getNotificationManager(any()); doReturn(true).when(mPhone).isWifiCallingEnabled(); // notifiable for emergency mCarrierConfigChangeListener.onCarrierConfigChanged(0 /* slotIndex */, SUB_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); Map<Integer, CarrierServiceStateTracker.NotificationType> notificationTypeMap = mCarrierSST.getNotificationTypeMap(); CarrierServiceStateTracker.NotificationType prefNetworkNotification = notificationTypeMap.get(CarrierServiceStateTracker.NOTIFICATION_PREF_NETWORK); CarrierServiceStateTracker.NotificationType emergencyNetworkNotification = notificationTypeMap.get(CarrierServiceStateTracker.NOTIFICATION_EMERGENCY_NETWORK); assertFalse(prefNetworkNotification.isEnabled()); assertTrue(emergencyNetworkNotification.isEnabled()); verify(mNotificationManager, never()).notify( eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); verify(mNotificationManager, atLeast(1)).cancel( CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID); verify(mNotificationManager, atLeast(1)).notify( eq(CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); verify(mNotificationManager, never()).cancel( CarrierServiceStateTracker.EMERGENCY_NOTIFICATION_TAG, SUB_ID); } }