From 1380c0e845e190d50fc7af540a72a5d745f8a72b Mon Sep 17 00:00:00 2001 From: Kriti Dang Date: Fri, 4 Jun 2021 14:51:48 +0200 Subject: [PATCH] Make AudioManager.getReportedSurroundFormats a TestApi Access to the API needed from a tunnel mode CTS test. TestAPIs dont work in CTS test if they intrenally call AudioSystem. Changing getSurroundFormats and getReportedSurroundFormats to call AudioService instead of AudioSystem. Bug: 189823767 Test: atest android.media.cts.DecoderTest#testTunneledAudioPTSGapsAc3 Change-Id: If6287743f57b77d0eb2639e4a2e9409c7d778f06 --- core/api/test-current.txt | 1 + media/java/android/media/AudioManager.java | 26 ++++++++----------- media/java/android/media/IAudioService.aidl | 4 +++ .../android/server/audio/AudioService.java | 26 +++++++++++++++++++ 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 51ca02f218e3f..94ce750b0b0bf 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -1419,6 +1419,7 @@ package android.media { 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 public static final int[] getPublicStreamTypes(); + method @NonNull public java.util.List getReportedSurroundFormats(); method public int getStreamMinVolumeInt(int); method @NonNull public java.util.Map getSurroundFormats(); method public boolean hasRegisteredDynamicPolicy(); diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index e40bd5762fbeb..74ac6310194b4 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -7078,14 +7078,11 @@ public class AudioManager { @TestApi @NonNull public Map getSurroundFormats() { - Map surroundFormats = new HashMap<>(); - int status = AudioSystem.getSurroundFormats(surroundFormats); - if (status != AudioManager.SUCCESS) { - // fail and bail! - Log.e(TAG, "getSurroundFormats failed:" + status); - return new HashMap(); // Always return a map. + try { + return getService().getSurroundFormats(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); } - return surroundFormats; } /** @@ -7132,15 +7129,14 @@ public class AudioManager { * * @return a list of surround formats */ - public ArrayList getReportedSurroundFormats() { - ArrayList reportedSurroundFormats = new ArrayList<>(); - int status = AudioSystem.getReportedSurroundFormats(reportedSurroundFormats); - if (status != AudioManager.SUCCESS) { - // fail and bail! - Log.e(TAG, "getReportedSurroundFormats failed:" + status); - return new ArrayList(); // Always return a list. + @TestApi + @NonNull + public List getReportedSurroundFormats() { + try { + return getService().getReportedSurroundFormats(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); } - return reportedSurroundFormats; } /** diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl index 357c414955120..b0c4a3ba6b48f 100755 --- a/media/java/android/media/IAudioService.aidl +++ b/media/java/android/media/IAudioService.aidl @@ -163,6 +163,10 @@ interface IAudioService { oneway void reloadAudioSettings(); + Map getSurroundFormats(); + + List getReportedSurroundFormats(); + boolean setSurroundFormatEnabled(int audioFormat, boolean enabled); boolean isSurroundFormatEnabled(int audioFormat); diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 5e749e29497f0..fcd198e8831c9 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -1932,6 +1932,32 @@ public class AudioService extends IAudioService.Stub } } + /** @see AudioManager#getSurroundFormats() */ + @Override + public Map getSurroundFormats() { + Map surroundFormats = new HashMap<>(); + int status = AudioSystem.getSurroundFormats(surroundFormats); + if (status != AudioManager.SUCCESS) { + // fail and bail! + Log.e(TAG, "getSurroundFormats failed:" + status); + return new HashMap<>(); // Always return a map. + } + return surroundFormats; + } + + /** @see AudioManager#getReportedSurroundFormats() */ + @Override + public List getReportedSurroundFormats() { + ArrayList reportedSurroundFormats = new ArrayList<>(); + int status = AudioSystem.getReportedSurroundFormats(reportedSurroundFormats); + if (status != AudioManager.SUCCESS) { + // fail and bail! + Log.e(TAG, "getReportedSurroundFormats failed:" + status); + return new ArrayList<>(); // Always return a list. + } + return reportedSurroundFormats; + } + /** @see AudioManager#isSurroundFormatEnabled(int) */ @Override public boolean isSurroundFormatEnabled(int audioFormat) {