Loading tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java +4 −6 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.internal.telephony; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static org.mockito.Mockito.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; Loading Loading @@ -151,7 +149,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { logd(LOG_TAG + ":testSendPrefNetworkNotification()"); Intent intent = new Intent().setAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); mContext.sendBroadcast(intent); waitForMs(300); waitForLastHandlerAction(mCarrierServiceStateTrackerTestHandler.getThreadHandler()); Map<Integer, CarrierServiceStateTracker.NotificationType> notificationTypeMap = mCarrierSST.getNotificationTypeMap(); Loading @@ -172,7 +170,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { RILConstants.NETWORK_MODE_LTE_CDMA_EVDO); mSpyCarrierSST.getContentObserver().dispatchChange(false, Settings.Global.getUriFor(prefNetworkMode)); waitForMs(500); waitForLastHandlerAction(mCarrierServiceStateTrackerTestHandler.getThreadHandler()); verify(mNotificationManager, atLeast(1)).notify( eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); Loading @@ -182,7 +180,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); mSpyCarrierSST.getContentObserver().dispatchChange(false, Settings.Global.getUriFor(prefNetworkMode)); waitForMs(500); waitForLastHandlerAction(mCarrierServiceStateTrackerTestHandler.getThreadHandler()); verify(mNotificationManager, atLeast(1)).cancel( CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID); } Loading @@ -193,7 +191,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { logd(LOG_TAG + ":testSendEmergencyNetworkNotification()"); Intent intent = new Intent().setAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); mContext.sendBroadcast(intent); waitForMs(300); waitForLastHandlerAction(mCarrierServiceStateTrackerTestHandler.getThreadHandler()); Map<Integer, CarrierServiceStateTracker.NotificationType> notificationTypeMap = mCarrierSST.getNotificationTypeMap(); Loading tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +88 −90 File changed.Preview size limit exceeded, changes collapsed. Show changes tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.internal.telephony; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Matchers.anyBoolean; Loading Loading @@ -708,6 +709,32 @@ public abstract class TelephonyTest { } } /** * Wait for up to 1 second for the handler message queue to clear. */ protected final void waitForLastHandlerAction(Handler h) { CountDownLatch lock = new CountDownLatch(1); // Allow the handler to start work on stuff. h.postDelayed(lock::countDown, 100); int timeoutCount = 0; while (timeoutCount < 5) { try { if (lock.await(200, TimeUnit.MILLISECONDS)) { // no messages in queue, stop waiting. if (!h.hasMessagesOrCallbacks()) break; lock = new CountDownLatch(1); // Delay to allow the handler thread to start work on stuff. h.postDelayed(lock::countDown, 100); } } catch (InterruptedException e) { // do nothing } timeoutCount++; } assertTrue("Handler was not empty before timeout elapsed", timeoutCount < 5); } protected final void waitForHandlerActionDelayed(Handler h, long timeoutMillis, long delayMs) { final CountDownLatch lock = new CountDownLatch(1); h.postDelayed(lock::countDown, delayMs); Loading Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierServiceStateTrackerTest.java +4 −6 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.internal.telephony; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static org.mockito.Mockito.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doReturn; Loading Loading @@ -151,7 +149,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { logd(LOG_TAG + ":testSendPrefNetworkNotification()"); Intent intent = new Intent().setAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); mContext.sendBroadcast(intent); waitForMs(300); waitForLastHandlerAction(mCarrierServiceStateTrackerTestHandler.getThreadHandler()); Map<Integer, CarrierServiceStateTracker.NotificationType> notificationTypeMap = mCarrierSST.getNotificationTypeMap(); Loading @@ -172,7 +170,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { RILConstants.NETWORK_MODE_LTE_CDMA_EVDO); mSpyCarrierSST.getContentObserver().dispatchChange(false, Settings.Global.getUriFor(prefNetworkMode)); waitForMs(500); waitForLastHandlerAction(mCarrierServiceStateTrackerTestHandler.getThreadHandler()); verify(mNotificationManager, atLeast(1)).notify( eq(CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG), eq(SUB_ID), isA(Notification.class)); Loading @@ -182,7 +180,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); mSpyCarrierSST.getContentObserver().dispatchChange(false, Settings.Global.getUriFor(prefNetworkMode)); waitForMs(500); waitForLastHandlerAction(mCarrierServiceStateTrackerTestHandler.getThreadHandler()); verify(mNotificationManager, atLeast(1)).cancel( CarrierServiceStateTracker.PREF_NETWORK_NOTIFICATION_TAG, SUB_ID); } Loading @@ -193,7 +191,7 @@ public class CarrierServiceStateTrackerTest extends TelephonyTest { logd(LOG_TAG + ":testSendEmergencyNetworkNotification()"); Intent intent = new Intent().setAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); mContext.sendBroadcast(intent); waitForMs(300); waitForLastHandlerAction(mCarrierServiceStateTrackerTestHandler.getThreadHandler()); Map<Integer, CarrierServiceStateTracker.NotificationType> notificationTypeMap = mCarrierSST.getNotificationTypeMap(); Loading
tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +88 −90 File changed.Preview size limit exceeded, changes collapsed. Show changes
tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.internal.telephony; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Matchers.anyBoolean; Loading Loading @@ -708,6 +709,32 @@ public abstract class TelephonyTest { } } /** * Wait for up to 1 second for the handler message queue to clear. */ protected final void waitForLastHandlerAction(Handler h) { CountDownLatch lock = new CountDownLatch(1); // Allow the handler to start work on stuff. h.postDelayed(lock::countDown, 100); int timeoutCount = 0; while (timeoutCount < 5) { try { if (lock.await(200, TimeUnit.MILLISECONDS)) { // no messages in queue, stop waiting. if (!h.hasMessagesOrCallbacks()) break; lock = new CountDownLatch(1); // Delay to allow the handler thread to start work on stuff. h.postDelayed(lock::countDown, 100); } } catch (InterruptedException e) { // do nothing } timeoutCount++; } assertTrue("Handler was not empty before timeout elapsed", timeoutCount < 5); } protected final void waitForHandlerActionDelayed(Handler h, long timeoutMillis, long delayMs) { final CountDownLatch lock = new CountDownLatch(1); h.postDelayed(lock::countDown, delayMs); Loading