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
This commit is contained in:
jiabin
2022-02-04 18:45:44 +00:00
committed by Jiabin Huang
parent 3dee9e9f0c
commit fe6b7f19fd
4 changed files with 39 additions and 1 deletions

View File

@@ -1465,6 +1465,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);

View File

@@ -8450,6 +8450,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")

View File

@@ -480,7 +480,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);
@@ -501,4 +500,6 @@ interface IAudioService {
in IAudioDeviceVolumeDispatcher cb,
in String packageName,
in AudioDeviceAttributes device, in List<VolumeInfo> volumes);
String getHalVersion();
}

View File

@@ -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;
@@ -10471,6 +10472,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) {