summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--media/java/android/media/AudioAttributes.java12
-rw-r--r--media/java/android/media/FadeManagerConfiguration.java3
-rw-r--r--media/tests/AudioPolicyTest/src/com/android/audiopolicytest/FadeManagerConfigurationUnitTest.java81
3 files changed, 95 insertions, 1 deletions
diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java
index 4be282b5de87..42175628a45d 100644
--- a/media/java/android/media/AudioAttributes.java
+++ b/media/java/android/media/AudioAttributes.java
@@ -1690,6 +1690,18 @@ public final class AudioAttributes implements Parcelable {
}
/**
+ * Query if the usage is a hidden (neither sdk nor SystemApi) usage
+ *
+ * @param usage the {@link android.media.AudioAttributes usage}
+ * @return {@code true} if the usage is {@link AudioAttributes#USAGE_VIRTUAL_SOURCE} or
+ * {@code false} otherwise
+ * @hide
+ */
+ public static boolean isHiddenUsage(@AttributeUsage int usage) {
+ return usage == USAGE_VIRTUAL_SOURCE;
+ }
+
+ /**
* Query if the content type is a valid sdk content type
* @param contentType one of {@link AttributeContentType}
* @return {@code true} if the content type is valid for sdk or {@code false} otherwise
diff --git a/media/java/android/media/FadeManagerConfiguration.java b/media/java/android/media/FadeManagerConfiguration.java
index e6ec2c330340..eaafa595ae4f 100644
--- a/media/java/android/media/FadeManagerConfiguration.java
+++ b/media/java/android/media/FadeManagerConfiguration.java
@@ -694,7 +694,8 @@ public final class FadeManagerConfiguration implements Parcelable {
}
private static boolean isUsageValid(int usage) {
- return AudioAttributes.isSdkUsage(usage) || AudioAttributes.isSystemUsage(usage);
+ return AudioAttributes.isSdkUsage(usage) || AudioAttributes.isSystemUsage(usage)
+ || AudioAttributes.isHiddenUsage(usage);
}
private void ensureFadingIsEnabled() {
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/FadeManagerConfigurationUnitTest.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/FadeManagerConfigurationUnitTest.java
index cd987039495e..c48a95625e8f 100644
--- a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/FadeManagerConfigurationUnitTest.java
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/FadeManagerConfigurationUnitTest.java
@@ -758,6 +758,87 @@ public final class FadeManagerConfigurationUnitTest {
.isEqualTo(FadeManagerConfiguration.CREATOR.createFromParcel(parcel));
}
+ @Test
+ public void testGetFadeOutVolumeShaperConfigForUsage_withInvalidUsage_fails() {
+ IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () ->
+ mFmc.getFadeOutVolumeShaperConfigForUsage(TEST_INVALID_USAGE)
+ );
+
+ expect.withMessage("Fade out volume shaper config for invalid usage exception")
+ .that(thrown).hasMessageThat().contains("Invalid usage");
+ }
+
+ @Test
+ public void testGetFadeInVolumeShaperConfigForUsage_withInvalidUsage_fails() {
+ IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () ->
+ mFmc.getFadeInVolumeShaperConfigForUsage(TEST_INVALID_USAGE)
+ );
+
+ expect.withMessage("Fade in volume shaper config for invalid usage exception")
+ .that(thrown).hasMessageThat().contains("Invalid usage");
+ }
+
+ @Test
+ public void testGetFadeVolumeShaperConfigForUsage_forSdkUsages() {
+ FadeManagerConfiguration.Builder builder = new FadeManagerConfiguration.Builder();
+ for (int usage : AudioAttributes.getSdkUsages()) {
+ builder.addFadeableUsage(usage);
+ builder.setFadeOutVolumeShaperConfigForUsage(usage, TEST_FADE_OUT_VOLUME_SHAPER_CONFIG);
+ builder.setFadeInVolumeShaperConfigForUsage(usage, TEST_FADE_IN_VOLUME_SHAPER_CONFIG);
+ }
+ FadeManagerConfiguration fmc = builder.build();
+
+ for (int usage : AudioAttributes.getSdkUsages()) {
+ expect.withMessage("Fade out volume shaper config for sdk usage")
+ .that(fmc.getFadeOutVolumeShaperConfigForUsage(usage))
+ .isEqualTo(TEST_FADE_OUT_VOLUME_SHAPER_CONFIG);
+ expect.withMessage("Fade in volume shaper config for sdk usage")
+ .that(fmc.getFadeInVolumeShaperConfigForUsage(usage))
+ .isEqualTo(TEST_FADE_IN_VOLUME_SHAPER_CONFIG);
+ }
+ }
+
+ @Test
+ public void testGetFadeVolumeShaperConfigForUsage_forSystemUsages() {
+ int[] systemUsages = {AudioAttributes.USAGE_CALL_ASSISTANT, AudioAttributes.USAGE_EMERGENCY,
+ AudioAttributes.USAGE_SAFETY, AudioAttributes.USAGE_VEHICLE_STATUS,
+ AudioAttributes.USAGE_ANNOUNCEMENT};
+ FadeManagerConfiguration.Builder builder = new FadeManagerConfiguration.Builder();
+ for (int usage : systemUsages) {
+ builder.addFadeableUsage(usage);
+ builder.setFadeOutVolumeShaperConfigForUsage(usage, TEST_FADE_OUT_VOLUME_SHAPER_CONFIG);
+ builder.setFadeInVolumeShaperConfigForUsage(usage, TEST_FADE_IN_VOLUME_SHAPER_CONFIG);
+ }
+ FadeManagerConfiguration fmc = builder.build();
+
+ for (int usage : systemUsages) {
+ expect.withMessage("Fade out volume shaper config for system usage")
+ .that(fmc.getFadeOutVolumeShaperConfigForUsage(usage))
+ .isEqualTo(TEST_FADE_OUT_VOLUME_SHAPER_CONFIG);
+ expect.withMessage("Fade in volume shaper config for system usage")
+ .that(fmc.getFadeInVolumeShaperConfigForUsage(usage))
+ .isEqualTo(TEST_FADE_IN_VOLUME_SHAPER_CONFIG);
+ }
+ }
+
+ @Test
+ public void testGetFadeVolumeShaperConfigForUsage_forHiddenUsage() {
+ int hiddenUsage = AudioAttributes.USAGE_VIRTUAL_SOURCE;
+ FadeManagerConfiguration fmc = new FadeManagerConfiguration.Builder()
+ .addFadeableUsage(hiddenUsage)
+ .setFadeOutVolumeShaperConfigForUsage(hiddenUsage,
+ TEST_FADE_OUT_VOLUME_SHAPER_CONFIG)
+ .setFadeInVolumeShaperConfigForUsage(hiddenUsage,
+ TEST_FADE_IN_VOLUME_SHAPER_CONFIG).build();
+
+ expect.withMessage("Fade out volume shaper config for hidden usage")
+ .that(fmc.getFadeOutVolumeShaperConfigForUsage(hiddenUsage))
+ .isEqualTo(TEST_FADE_OUT_VOLUME_SHAPER_CONFIG);
+ expect.withMessage("Fade in volume shaper config for hidden usage")
+ .that(fmc.getFadeInVolumeShaperConfigForUsage(hiddenUsage))
+ .isEqualTo(TEST_FADE_IN_VOLUME_SHAPER_CONFIG);
+ }
+
private static AudioAttributes createAudioAttributesForUsage(int usage) {
if (AudioAttributes.isSystemUsage(usage)) {
return new AudioAttributes.Builder().setSystemUsage(usage).build();