Loading core/java/android/app/BroadcastStickyCache.java +2 −1 Original line number Diff line number Diff line Loading @@ -214,7 +214,8 @@ public class BroadcastStickyCache { // We only need 1 entry per cache but just to be on the safer side we are choosing 32 // although we don't expect more than 1. sActionConfigMap.put(action, new Config(32, IpcDataCache.MODULE_SYSTEM, sActionApiNameMap.get(action))); new Config(32, IpcDataCache.MODULE_SYSTEM, sActionApiNameMap.get(action)).cacheNulls(true)); } return sActionConfigMap.get(action); Loading tests/broadcasts/unit/src/android/app/BroadcastStickyCacheTest.java +18 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -185,6 +186,22 @@ public class BroadcastStickyCacheTest { any(), anyString(), anyInt(), anyInt()); } @Test public void getIntent_queryActionTwiceWithNullResult_verifyRegisterReceiverIsCalledOnce() throws RemoteException { setActivityManagerMock(null); final Intent intent = queryIntent(new IntentFilter(Intent.ACTION_DEVICE_STORAGE_FULL)); final Intent cachedIntent = queryIntent( new IntentFilter(Intent.ACTION_DEVICE_STORAGE_FULL)); assertNull(intent); assertNull(cachedIntent); verify(mActivityManagerMock, times(1)).registerReceiverWithFeature( eq(mIApplicationThreadMock), anyString(), anyString(), anyString(), any(), any(), anyString(), anyInt(), anyInt()); } @Test public void getIntent_querySameActionWithDifferentFilter_verifyRegisterReceiverCalledTwice() throws RemoteException { Loading Loading @@ -226,6 +243,6 @@ public class BroadcastStickyCacheTest { when(ActivityManager.getService()).thenReturn(mActivityManagerMock); when(mActivityManagerMock.registerReceiverWithFeature(any(), anyString(), anyString(), anyString(), any(), any(), anyString(), anyInt(), anyInt())).thenReturn(new Intent(action)); anyInt())).thenReturn(action != null ? new Intent(action) : null); } } Loading
core/java/android/app/BroadcastStickyCache.java +2 −1 Original line number Diff line number Diff line Loading @@ -214,7 +214,8 @@ public class BroadcastStickyCache { // We only need 1 entry per cache but just to be on the safer side we are choosing 32 // although we don't expect more than 1. sActionConfigMap.put(action, new Config(32, IpcDataCache.MODULE_SYSTEM, sActionApiNameMap.get(action))); new Config(32, IpcDataCache.MODULE_SYSTEM, sActionApiNameMap.get(action)).cacheNulls(true)); } return sActionConfigMap.get(action); Loading
tests/broadcasts/unit/src/android/app/BroadcastStickyCacheTest.java +18 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -185,6 +186,22 @@ public class BroadcastStickyCacheTest { any(), anyString(), anyInt(), anyInt()); } @Test public void getIntent_queryActionTwiceWithNullResult_verifyRegisterReceiverIsCalledOnce() throws RemoteException { setActivityManagerMock(null); final Intent intent = queryIntent(new IntentFilter(Intent.ACTION_DEVICE_STORAGE_FULL)); final Intent cachedIntent = queryIntent( new IntentFilter(Intent.ACTION_DEVICE_STORAGE_FULL)); assertNull(intent); assertNull(cachedIntent); verify(mActivityManagerMock, times(1)).registerReceiverWithFeature( eq(mIApplicationThreadMock), anyString(), anyString(), anyString(), any(), any(), anyString(), anyInt(), anyInt()); } @Test public void getIntent_querySameActionWithDifferentFilter_verifyRegisterReceiverCalledTwice() throws RemoteException { Loading Loading @@ -226,6 +243,6 @@ public class BroadcastStickyCacheTest { when(ActivityManager.getService()).thenReturn(mActivityManagerMock); when(mActivityManagerMock.registerReceiverWithFeature(any(), anyString(), anyString(), anyString(), any(), any(), anyString(), anyInt(), anyInt())).thenReturn(new Intent(action)); anyInt())).thenReturn(action != null ? new Intent(action) : null); } }