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

Commit 493b23e3 authored by Lee Shombert's avatar Lee Shombert Committed by Android (Google) Code Review
Browse files

Merge "Make setCacheTestMode() a module API" into main

parents 815fdd84 06701b0e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -412,6 +412,7 @@ package android.os {
    method public void invalidateCache();
    method public static void invalidateCache(@NonNull String, @NonNull String);
    method @Nullable public Result query(@NonNull Query);
    method @FlaggedApi("android.os.ipc_data_cache_test_apis") public static void setCacheTestMode(boolean);
    field public static final String MODULE_BLUETOOTH = "bluetooth";
  }

+20 −0
Original line number Diff line number Diff line
@@ -733,4 +733,24 @@ public class IpcDataCache<Query, Result> extends PropertyInvalidatedCache<Query,
    public static void setTestMode(boolean mode) {
        PropertyInvalidatedCache.setTestMode(mode);
    }

    /**
     * Enable or disable test mode.  The protocol requires that the mode toggle: for instance, it is
     * illegal to clear the test mode if the test mode is already off.  Enabling test mode puts
     * all caches in the process into test mode; all nonces are initialized to UNSET and
     * subsequent reads and writes are to process memory.  This has the effect of disabling all
     * caches that are not local to the process.  Disabling test mode restores caches to normal
     * operation.
     * @param mode The desired test mode.
     * @throws IllegalStateException if the supplied mode is already set.
     * @throws IllegalStateException if the process is not running an instrumentation test.
     * @hide
     */
    @FlaggedApi(android.os.Flags.FLAG_IPC_DATA_CACHE_TEST_APIS)
    @SystemApi(client=SystemApi.Client.MODULE_LIBRARIES)
    public static void setCacheTestMode(boolean mode) {
        // Trunk-stable flagging requires that this API have a name different from the existing
        // setTestMode() API.  However, the functionality is identical.
        setTestMode(mode);
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -245,6 +245,14 @@ flag {
    is_exported: true
}

flag {
     name: "ipc_data_cache_test_apis"
     namespace: "system_performance"
     description: "Expose IpcDataCache test apis to mainline modules."
     bug: "396173886"
     is_exported: true
}

flag {
     name: "mainline_vcn_platform_api"
     namespace: "vcn"
+42 −0
Original line number Diff line number Diff line
@@ -518,6 +518,48 @@ public class IpcDataCacheTest {
        IpcDataCache.setTestMode(true);
    }

    // Verify that test cache mode works properly.  This test is identical to testTestMode except
    // that it uses the alternative name (the API that is visible to mainline modules).
    @Test
    public void testCacheTestMode() {
        // Create a cache that will write a system nonce.
        TestCache sysCache = new TestCache(IpcDataCache.MODULE_SYSTEM, "mode1");

        sysCache.testPropertyName();
        // Invalidate the cache.  This must succeed because the property has been marked for
        // testing.
        sysCache.invalidateCache();

        // Create a cache that uses MODULE_TEST.  Invalidation succeeds whether or not the
        // property is tagged as being tested.
        TestCache testCache = new TestCache(IpcDataCache.MODULE_TEST, "mode2");
        testCache.invalidateCache();
        testCache.testPropertyName();
        testCache.invalidateCache();

        // Clear test mode.  This fails if test mode is not enabled.
        IpcDataCache.setCacheTestMode(false);
        try {
            IpcDataCache.setCacheTestMode(false);
            if (android.app.Flags.enforcePicTestmodeProtocol()) {
                fail("expected an IllegalStateException");
            }
        } catch (IllegalStateException e) {
            // The expected exception.
        }
        // Configuring a property for testing must fail if test mode is false.
        TestCache cache2 = new TestCache(IpcDataCache.MODULE_SYSTEM, "mode3");
        try {
            cache2.testPropertyName();
            fail("expected an IllegalStateException");
        } catch (IllegalStateException e) {
            // The expected exception.
        }

        // Re-enable test mode (so that the cleanup for the test does not throw).
        IpcDataCache.setCacheTestMode(true);
    }

    @Test
    public void testCachingNulls() {
        IpcDataCache.Config c =