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

Commit efad242f authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Wait until any background events are processed.

Some MediaProvider events (such as thumbnail invalidation) are
handled on a background thread.  To reduce flaky tests, wait until
all background events have been processed, which is more robust
than sleep.

Bug: 134879702
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: Ia032b19c1b0e5c0096c55bf3d46a5153525e89fa
parent d9b74bad
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2319,6 +2319,7 @@ package android.provider {
    method public static android.net.Uri scanFile(android.content.Context, java.io.File);
    method public static android.net.Uri scanFileFromShell(android.content.Context, java.io.File);
    method public static void scanVolume(android.content.Context, java.io.File);
    method public static void waitForIdle(android.content.Context);
  }

  public final class Settings {
+13 −0
Original line number Diff line number Diff line
@@ -136,6 +136,8 @@ public final class MediaStore {
     */
    public static final String VOLUME_EXTERNAL_PRIMARY = "external_primary";

    /** {@hide} */
    public static final String WAIT_FOR_IDLE_CALL = "wait_for_idle";
    /** {@hide} */
    public static final String SCAN_FILE_CALL = "scan_file";
    /** {@hide} */
@@ -3560,6 +3562,17 @@ public final class MediaStore {
        }
    }

    /** @hide */
    @TestApi
    public static void waitForIdle(Context context) {
        final ContentResolver resolver = context.getContentResolver();
        try (ContentProviderClient client = resolver.acquireContentProviderClient(AUTHORITY)) {
            client.call(WAIT_FOR_IDLE_CALL, null, null);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    /** @hide */
    @TestApi
    public static Uri scanFile(Context context, File file) {