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

Commit 0289e155 authored by jiabin's avatar jiabin
Browse files

Add a test API to query audio HAL version.

Add a test API to query audio HAL version. The HAL version is useful
for test since the HAL version cannot be determined from the platform
version. There can be some test requiring external devices connection
that can only run in CTS verifier but not the VTS. With a different HAL
version, there can be different CDD requirements for a given API. In
that case, the test will need to know the HAL version to behave
differently.

Bug: 195401076
Test: atest AudioManagerTest
Change-Id: I18cbf2f181e799e56b48916aefaede50389051fe
parent 99deef06
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1455,6 +1455,7 @@ package android.media {
    method @NonNull @RequiresPermission(android.Manifest.permission.CALL_AUDIO_INTERCEPTION) public android.media.AudioTrack getCallUplinkInjectionAudioTrack(@NonNull android.media.AudioFormat);
    method @Nullable public static android.media.AudioDeviceInfo getDeviceInfoFromType(int);
    method @IntRange(from=0) @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public long getFadeOutDurationOnFocusLossMillis(@NonNull android.media.AudioAttributes);
    method @Nullable public static String getHalVersion();
    method public static final int[] getPublicStreamTypes();
    method @NonNull public java.util.List<java.lang.Integer> getReportedSurroundFormats();
    method public int getStreamMinVolumeInt(int);
+16 −0
Original line number Diff line number Diff line
@@ -8443,6 +8443,22 @@ public class AudioManager {
        }
    }

    /**
     * Returns the audio HAL version in the form MAJOR.MINOR. If there is no audio HAL found, null
     * will be returned.
     *
     * @hide
     */
    @TestApi
    public static @Nullable String getHalVersion() {
        try {
            return getService().getHalVersion();
        } catch (RemoteException e) {
            Log.e(TAG, "Error querying getHalVersion", e);
            throw e.rethrowFromSystemServer();
        }
    }

    private final Object mMuteAwaitConnectionListenerLock = new Object();

    @GuardedBy("mMuteAwaitConnectionListenerLock")
+2 −1
Original line number Diff line number Diff line
@@ -478,7 +478,6 @@ interface IAudioService {

    boolean sendFocusLoss(in AudioFocusInfo focusLoser, in IAudioPolicyCallback apcb);


    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)")
    void addAssistantServicesUids(in int[] assistantUID);

@@ -499,4 +498,6 @@ interface IAudioService {
            in IAudioDeviceVolumeDispatcher cb,
            in String packageName,
            in AudioDeviceAttributes device, in List<VolumeInfo> volumes);

    String getHalVersion();
}
+20 −0
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HwBinder;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
@@ -10397,6 +10398,25 @@ public class AudioService extends IAudioService.Stub
        return mMediaFocusControl.sendFocusLoss(focusLoser);
    }

    private static final String[] HAL_VERSIONS = new String[] {"7.1", "7.0", "6.0", "4.0", "2.0"};

    /** @see AudioManager#getHalVersion */
    public @Nullable String getHalVersion() {
        for (String version : HAL_VERSIONS) {
            try {
                HwBinder.getService(
                        String.format("android.hardware.audio@%s::IDevicesFactory", version),
                        "default");
                return version;
            } catch (NoSuchElementException e) {
                // Ignore, the specified HAL interface is not found.
            } catch (RemoteException re) {
                Log.e(TAG, "Remote exception when getting hardware audio service:", re);
            }
        }
        return null;
    }

    /** see AudioManager.hasRegisteredDynamicPolicy */
    public boolean hasRegisteredDynamicPolicy() {
        synchronized (mAudioPolicies) {