Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 721bb4ae authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Cache for null results in BroadcastStickyCache." into main

parents 9fc1515d 2ec454f2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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);
+18 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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 {
@@ -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);
    }
}