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

Commit 2ec454f2 authored by mayankkk's avatar mayankkk Committed by Mayank Dandwani
Browse files

Cache for null results in BroadcastStickyCache.

Bug: 356148006
Test: atest BroadcastStickyCacheTest
Flag: android.app.use_sticky_bcast_cache
Change-Id: Ia9abb53b035ab7eae9dad259aa7aa59206c1f89d
parent ab988ebe
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);
    }
}