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

Commit 364142ff authored by Atneya Nair's avatar Atneya Nair
Browse files

audio: Add test API to wait for AudioHandler

Adds a test-only barrier to synchronize with the AudioService handler
thread. This allows tests to wait for pending async operations to
complete before proceeding, preventing flake due to test predicates.

Test: m
Bug: None
Flag: EXEMPT Test infrastructure
Change-Id: I6367949d7197e210c3c55ff887f592630b607c73
parent 730e53f8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2096,6 +2096,7 @@ package android.media {
    method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public void setTestDeviceConnectionState(@NonNull android.media.AudioDeviceAttributes, boolean);
    method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED) public void setVolumeControllerLongPressTimeoutEnabled(boolean);
    method @FlaggedApi("android.media.audio.focus_exclusive_with_recording") @RequiresPermission(android.Manifest.permission.QUERY_AUDIO_STATE) public boolean shouldNotificationSoundPlay(@NonNull android.media.AudioAttributes);
    method public void waitForAudioHandlerBarrier();
  }

  public static final class AudioRecord.MetricsConstants {
+16 −0
Original line number Diff line number Diff line
@@ -10366,6 +10366,22 @@ public class AudioManager {
        }
    }

    /**
     * @hide
     * Blocks until all messages on the AudioService handler have been processed.
     * Only useful in tests.
     */
    @TestApi
    @SuppressWarnings("UnflaggedApi") // @TestApi without associated feature.
    public void waitForAudioHandlerBarrier() {
        final IAudioService service = getService();
        try {
            service.waitForAudioHandlerBarrier();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }


    /**
     * @hide
+2 −0
Original line number Diff line number Diff line
@@ -106,6 +106,8 @@ interface IAudioService {

    void permissionUpdateBarrier();

    void waitForAudioHandlerBarrier();

    // Java-only methods below.
    void adjustStreamVolume(int streamType, int direction, int flags, String callingPackage);

+6 −0
Original line number Diff line number Diff line
@@ -15918,6 +15918,12 @@ public class AudioService extends IAudioService.Stub
        }
    }
    @Override
    /** @see AudioManager#waitForAudioHandlerBarrier() */
    public void waitForAudioHandlerBarrier() {
        mAudioHandler.runWithScissors(() -> {}, 0);
    }
    List<String> getDeviceIdentityAddresses(AudioDeviceAttributes device) {
        return mDeviceBroker.getDeviceIdentityAddresses(device);
    }