diff options
| -rw-r--r-- | core/api/test-current.txt | 22 | ||||
| -rw-r--r-- | media/java/android/media/AudioHalVersionInfo.aidl | 18 | ||||
| -rw-r--r-- | media/java/android/media/AudioHalVersionInfo.java | 174 | ||||
| -rw-r--r-- | media/java/android/media/AudioManager.java | 7 | ||||
| -rw-r--r--[-rwxr-xr-x] | media/java/android/media/IAudioService.aidl | 3 | ||||
| -rw-r--r-- | services/core/java/com/android/server/audio/AudioService.java | 26 |
6 files changed, 235 insertions, 15 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt index fafaf606d0ee..43d4530cbf1d 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -1511,13 +1511,33 @@ package android.media { method public static boolean isEncodingLinearPcm(int); } + public final class AudioHalVersionInfo implements java.lang.Comparable<android.media.AudioHalVersionInfo> android.os.Parcelable { + method public int compareTo(@NonNull android.media.AudioHalVersionInfo); + method public int describeContents(); + method public int getHalType(); + method public int getMajorVersion(); + method public int getMinorVersion(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.media.AudioHalVersionInfo AIDL_1_0; + field public static final int AUDIO_HAL_TYPE_AIDL = 1; // 0x1 + field public static final int AUDIO_HAL_TYPE_HIDL = 0; // 0x0 + field @NonNull public static final android.os.Parcelable.Creator<android.media.AudioHalVersionInfo> CREATOR; + field @NonNull public static final android.media.AudioHalVersionInfo HIDL_2_0; + field @NonNull public static final android.media.AudioHalVersionInfo HIDL_4_0; + field @NonNull public static final android.media.AudioHalVersionInfo HIDL_5_0; + field @NonNull public static final android.media.AudioHalVersionInfo HIDL_6_0; + field @NonNull public static final android.media.AudioHalVersionInfo HIDL_7_0; + field @NonNull public static final android.media.AudioHalVersionInfo HIDL_7_1; + field @NonNull public static final java.util.List<android.media.AudioHalVersionInfo> VERSIONS; + } + public class AudioManager { method @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public int abandonAudioFocusForTest(@NonNull android.media.AudioFocusRequest, @NonNull String); method @NonNull @RequiresPermission(android.Manifest.permission.CALL_AUDIO_INTERCEPTION) public android.media.AudioRecord getCallDownlinkExtractionAudioRecord(@NonNull android.media.AudioFormat); 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 @Nullable public static android.media.AudioHalVersionInfo getHalVersion(); method public static final int[] getPublicStreamTypes(); method @NonNull public java.util.List<java.lang.Integer> getReportedSurroundFormats(); method public int getStreamMinVolumeInt(int); diff --git a/media/java/android/media/AudioHalVersionInfo.aidl b/media/java/android/media/AudioHalVersionInfo.aidl new file mode 100644 index 000000000000..a83f8c81fb21 --- /dev/null +++ b/media/java/android/media/AudioHalVersionInfo.aidl @@ -0,0 +1,18 @@ +/* Copyright 2022, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +package android.media; + +parcelable AudioHalVersionInfo; diff --git a/media/java/android/media/AudioHalVersionInfo.java b/media/java/android/media/AudioHalVersionInfo.java new file mode 100644 index 000000000000..985a7584ffe2 --- /dev/null +++ b/media/java/android/media/AudioHalVersionInfo.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.TestApi; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.List; + +/** + * Defines the audio HAL version. + * + * @hide + */ +@TestApi +public final class AudioHalVersionInfo implements Parcelable, Comparable<AudioHalVersionInfo> { + /** + * Indicate the audio HAL is implemented with HIDL (HAL interface definition language). + * + * @see <a href="https://source.android.com/docs/core/architecture/hidl/">HIDL</a> + * <p>The value of AUDIO_HAL_TYPE_HIDL should match the value of {@link + * android.media.AudioHalVersion.Type#HIDL}. + */ + public static final int AUDIO_HAL_TYPE_HIDL = 0; + + /** + * Indicate the audio HAL is implemented with AIDL (Android Interface Definition Language). + * + * @see <a href="https://source.android.com/docs/core/architecture/aidl/">AIDL</a> + * <p>The value of AUDIO_HAL_TYPE_AIDL should match the value of {@link + * android.media.AudioHalVersion.Type#AIDL}. + */ + public static final int AUDIO_HAL_TYPE_AIDL = 1; + + /** @hide */ + @IntDef( + flag = false, + prefix = "AUDIO_HAL_TYPE_", + value = {AUDIO_HAL_TYPE_HIDL, AUDIO_HAL_TYPE_AIDL}) + public @interface AudioHalType {} + + /** AudioHalVersionInfo object of all valid Audio HAL versions. */ + public static final @NonNull AudioHalVersionInfo AIDL_1_0 = + new AudioHalVersionInfo(AUDIO_HAL_TYPE_AIDL, 1 /* major */, 0 /* minor */); + + public static final @NonNull AudioHalVersionInfo HIDL_7_1 = + new AudioHalVersionInfo(AUDIO_HAL_TYPE_HIDL, 7 /* major */, 1 /* minor */); + public static final @NonNull AudioHalVersionInfo HIDL_7_0 = + new AudioHalVersionInfo(AUDIO_HAL_TYPE_HIDL, 7 /* major */, 0 /* minor */); + public static final @NonNull AudioHalVersionInfo HIDL_6_0 = + new AudioHalVersionInfo(AUDIO_HAL_TYPE_HIDL, 6 /* major */, 0 /* minor */); + public static final @NonNull AudioHalVersionInfo HIDL_5_0 = + new AudioHalVersionInfo(AUDIO_HAL_TYPE_HIDL, 5 /* major */, 0 /* minor */); + public static final @NonNull AudioHalVersionInfo HIDL_4_0 = + new AudioHalVersionInfo(AUDIO_HAL_TYPE_HIDL, 4 /* major */, 0 /* minor */); + public static final @NonNull AudioHalVersionInfo HIDL_2_0 = + new AudioHalVersionInfo(AUDIO_HAL_TYPE_HIDL, 2 /* major */, 0 /* minor */); + + /** + * List of all valid Audio HAL versions. This list need to be in sync with sAudioHALVersions + * defined in frameworks/av/media/libaudiohal/FactoryHalHidl.cpp. + */ + // TODO: add AIDL_1_0 with sAudioHALVersions. + public static final @NonNull List<AudioHalVersionInfo> VERSIONS = + List.of(HIDL_7_1, HIDL_7_0, HIDL_6_0, HIDL_5_0, HIDL_4_0); + + private static final String TAG = "AudioHalVersionInfo"; + private AudioHalVersion mHalVersion = new AudioHalVersion(); + + public @AudioHalType int getHalType() { + return mHalVersion.type; + } + + public int getMajorVersion() { + return mHalVersion.major; + } + + public int getMinorVersion() { + return mHalVersion.minor; + } + + /** String representative of AudioHalVersion.Type */ + private static @NonNull String typeToString(@AudioHalType int type) { + if (type == AudioHalVersion.Type.HIDL) { + return "HIDL"; + } else if (type == AudioHalVersion.Type.AIDL) { + return "AIDL"; + } else { + return "INVALID"; + } + } + + /** String representative of type, major and minor */ + private static @NonNull String toString(@AudioHalType int type, int major, int minor) { + return typeToString(type) + ":" + Integer.toString(major) + "." + Integer.toString(minor); + } + + private AudioHalVersionInfo(@AudioHalType int type, int major, int minor) { + mHalVersion.type = type; + mHalVersion.major = major; + mHalVersion.minor = minor; + } + + private AudioHalVersionInfo(Parcel in) { + mHalVersion = in.readTypedObject(AudioHalVersion.CREATOR); + } + + /** String representative of this (AudioHalVersionInfo) object */ + @Override + public String toString() { + return toString(mHalVersion.type, mHalVersion.major, mHalVersion.minor); + } + + /** + * Compare two HAL versions by comparing their index in VERSIONS. + * + * <p>Normally all AudioHalVersionInfo object to compare should exist in the VERSIONS list. If + * both candidates exist in the VERSIONS list, smaller index means newer. Any candidate not + * exist in the VERSIONS list will be considered to be oldest version. + * + * @return 0 if the HAL version is the same as the other HAL version. Positive if the HAL + * version is newer than the other HAL version. Negative if the HAL version is older than + * the other version. + */ + @Override + public int compareTo(@NonNull AudioHalVersionInfo other) { + int indexOther = VERSIONS.indexOf(other); + int indexThis = VERSIONS.indexOf(this); + if (indexThis < 0 || indexOther < 0) { + return indexThis - indexOther; + } + return indexOther - indexThis; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull android.os.Parcel out, int flag) { + out.writeTypedObject(mHalVersion, flag); + } + + public static final @NonNull Parcelable.Creator<AudioHalVersionInfo> CREATOR = + new Parcelable.Creator<AudioHalVersionInfo>() { + @Override + public AudioHalVersionInfo createFromParcel(@NonNull Parcel in) { + return new AudioHalVersionInfo(in); + } + + @Override + public AudioHalVersionInfo[] newArray(int size) { + return new AudioHalVersionInfo[size]; + } + }; +} diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 9c5313aa3261..ae0d45ffca24 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -8502,13 +8502,14 @@ public class AudioManager { } /** - * Returns the audio HAL version in the form MAJOR.MINOR. If there is no audio HAL found, null - * will be returned. + * Returns an {@link AudioHalVersionInfo} indicating the Audio Hal Version. If there is no audio + * HAL found, null will be returned. * + * @return @see @link #AudioHalVersionInfo The version of Audio HAL. * @hide */ @TestApi - public static @Nullable String getHalVersion() { + public static @Nullable AudioHalVersionInfo getHalVersion() { try { return getService().getHalVersion(); } catch (RemoteException e) { diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl index 2e766d59fbb3..ee453a4541c2 100755..100644 --- a/media/java/android/media/IAudioService.aidl +++ b/media/java/android/media/IAudioService.aidl @@ -22,6 +22,7 @@ import android.media.AudioAttributes; import android.media.AudioDeviceAttributes; import android.media.AudioFormat; import android.media.AudioFocusInfo; +import android.media.AudioHalVersionInfo; import android.media.AudioPlaybackConfiguration; import android.media.AudioRecordingConfiguration; import android.media.AudioRoutesInfo; @@ -571,5 +572,5 @@ interface IAudioService { in AudioDeviceAttributes device, in List<VolumeInfo> volumes, boolean handlesvolumeAdjustment); - String getHalVersion(); + AudioHalVersionInfo getHalVersion(); } diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 0b1fb9574e3d..aa8ee3d2d8aa 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -86,6 +86,7 @@ import android.media.AudioDeviceVolumeManager; import android.media.AudioFocusInfo; import android.media.AudioFocusRequest; import android.media.AudioFormat; +import android.media.AudioHalVersionInfo; import android.media.AudioManager; import android.media.AudioManagerInternal; import android.media.AudioPlaybackConfiguration; @@ -6638,9 +6639,13 @@ public class AudioService extends IAudioService.Stub return AudioSystem.STREAM_RING; } else if (wasStreamActiveRecently( AudioSystem.STREAM_NOTIFICATION, sStreamOverrideDelayMs)) { - if (DEBUG_VOL) - Log.v(TAG, "getActiveStreamType: Forcing STREAM_NOTIFICATION stream active"); - return AudioSystem.STREAM_NOTIFICATION; + if (DEBUG_VOL) { + Log.v( + TAG, + "getActiveStreamType: Forcing STREAM_NOTIFICATION stream" + + " active"); + } + return AudioSystem.STREAM_NOTIFICATION; } else { if (DEBUG_VOL) { Log.v(TAG, "getActiveStreamType: Forcing DEFAULT_VOL_STREAM_NO_PLAYBACK(" @@ -11319,15 +11324,16 @@ public class AudioService extends IAudioService.Stub return mMediaFocusControl.sendFocusLoss(focusLoser); } - private static final String[] HAL_VERSIONS = - new String[] {"7.1", "7.0", "6.0", "5.0", "4.0", "2.0"}; - - /** @see AudioManager#getHalVersion */ - public @Nullable String getHalVersion() { - for (String version : HAL_VERSIONS) { + /** + * @see AudioManager#getHalVersion + */ + public @Nullable AudioHalVersionInfo getHalVersion() { + for (AudioHalVersionInfo version : AudioHalVersionInfo.VERSIONS) { try { + // TODO: check AIDL service. + String versionStr = version.getMajorVersion() + "." + version.getMinorVersion(); HwBinder.getService( - String.format("android.hardware.audio@%s::IDevicesFactory", version), + String.format("android.hardware.audio@%s::IDevicesFactory", versionStr), "default"); return version; } catch (NoSuchElementException e) { |