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

Commit 5c528c03 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Improve `UriPermissionTest` flakiness.

Public API docs indicate that taking a grant a second time should
result in a "touch" of the `persistedCreateTime` value; we update
the test to confirm this, which was uncovered via a flaky test.

Bug: 322805216
Test: atest FrameworksServicesTestsRavenwood
Change-Id: Id5c6e6c70e639df37327b98c7647d065a2300d32
parent 919032ef
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -33,8 +33,10 @@ import static com.android.server.uri.UriPermission.STRENGTH_PERSISTABLE;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import android.os.SystemClock;
import android.platform.test.ravenwood.RavenwoodRule;

import org.junit.Before;
@@ -154,10 +156,12 @@ public class UriPermissionTest {
            assertEquals(FLAG_WRITE, perm.persistableModeFlags);
            assertEquals(FLAG_WRITE, perm.persistedModeFlags);

            // Attempting to take a second time should be a no-op
            // Attempting to take a second time should "touch" timestamp, per public API
            // docs on ContentResolver.takePersistableUriPermission()
            final long createTime = perm.persistedCreateTime;
            SystemClock.sleep(10);
            assertFalse(perm.takePersistableModes(FLAG_WRITE));
            assertEquals(createTime, perm.persistedCreateTime);
            assertNotEquals(createTime, perm.persistedCreateTime);

            assertTrue(perm.releasePersistableModes(FLAG_WRITE));
            assertEquals(FLAG_WRITE, perm.persistableModeFlags);