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

Commit 474715c7 authored by Raj Goparaju's avatar Raj Goparaju Committed by Android (Google) Code Review
Browse files

Merge "Address review comments for fade manager clear APIs" into main

parents 657f3513 c8c851fd
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -6995,10 +6995,10 @@ package android.media {
    method @NonNull public android.media.FadeManagerConfiguration.Builder addUnfadeableContentType(int);
    method @NonNull public android.media.FadeManagerConfiguration.Builder addUnfadeableUid(int);
    method @NonNull public android.media.FadeManagerConfiguration build();
    method @NonNull public android.media.FadeManagerConfiguration.Builder clearFadeableUsage(int);
    method @NonNull public android.media.FadeManagerConfiguration.Builder clearUnfadeableAudioAttributes(@NonNull android.media.AudioAttributes);
    method @NonNull public android.media.FadeManagerConfiguration.Builder clearUnfadeableContentType(int);
    method @NonNull public android.media.FadeManagerConfiguration.Builder clearUnfadeableUid(int);
    method @NonNull public android.media.FadeManagerConfiguration.Builder clearFadeableUsages();
    method @NonNull public android.media.FadeManagerConfiguration.Builder clearUnfadeableAudioAttributes();
    method @NonNull public android.media.FadeManagerConfiguration.Builder clearUnfadeableContentTypes();
    method @NonNull public android.media.FadeManagerConfiguration.Builder clearUnfadeableUids();
    method @NonNull public android.media.FadeManagerConfiguration.Builder setFadeInDelayForOffenders(long);
    method @NonNull public android.media.FadeManagerConfiguration.Builder setFadeInDurationForAudioAttributes(@NonNull android.media.AudioAttributes, long);
    method @NonNull public android.media.FadeManagerConfiguration.Builder setFadeInDurationForUsage(int, long);
+21 −45
Original line number Diff line number Diff line
@@ -1101,9 +1101,6 @@ public final class FadeManagerConfiguration implements Parcelable {
         * <p>This is a positive list. Players with matching usage will be considered for fading.
         * Usages that are not part of this list will not be faded
         *
         * <p>Passing an empty list as input clears the existing list. This can be used to
         * reset the list when using a copy constructor
         *
         * <p><b>Warning:</b> When fade state is set to enabled, the builder expects at least one
         * usage to be set/added. Failure to do so will result in an exception during
         * {@link #build()}
@@ -1143,24 +1140,18 @@ public final class FadeManagerConfiguration implements Parcelable {
        }

        /**
         * Remove the {@link android.media.AudioAttributes usage} from the fadeable list
         * <p>
         * Players of this usage type will not be faded.
         * Clears the fadeable {@link android.media.AudioAttributes usage} list
         *
         * <p>This can be used to reset the list when using a copy constructor
         *
         * @param usage the {@link android.media.AudioAttributes usage}
         * @return the same Builder instance
         * @throws IllegalArgumentException if the usage is invalid
         * @see #getFadeableUsages()
         * @see #setFadeableUsages(List)
         */
        @NonNull
        public Builder clearFadeableUsage(@AudioAttributes.AttributeUsage int usage) {
            validateUsage(usage);
        public Builder clearFadeableUsages() {
            setFlag(IS_FADEABLE_USAGES_FIELD_SET);
            int index = mFadeableUsages.indexOf(usage);
            if (index != INVALID_INDEX) {
                mFadeableUsages.remove(index);
            }
            mFadeableUsages.clear();
            return this;
        }

@@ -1209,23 +1200,18 @@ public final class FadeManagerConfiguration implements Parcelable {
        }

        /**
         * Remove the {@link android.media.AudioAttributes content type} from the unfadeable list
         * Clears the unfadeable {@link android.media.AudioAttributes content type} list
         *
         * <p>This can be used to reset the list when using a copy constructor
         *
         * @param contentType the {@link android.media.AudioAttributes content type}
         * @return the same Builder instance
         * @throws IllegalArgumentException if the content type is invalid
         * @see #setUnfadeableContentTypes(List)
         * @see #getUnfadeableContentTypes()
         */
        @NonNull
        public Builder clearUnfadeableContentType(
                @AudioAttributes.AttributeContentType int contentType) {
            validateContentType(contentType);
        public Builder clearUnfadeableContentTypes() {
            setFlag(IS_UNFADEABLE_CONTENT_TYPE_FIELD_SET);
            int index = mUnfadeableContentTypes.indexOf(contentType);
            if (index != INVALID_INDEX) {
                mUnfadeableContentTypes.remove(index);
            }
            mUnfadeableContentTypes.clear();
            return this;
        }

@@ -1233,10 +1219,7 @@ public final class FadeManagerConfiguration implements Parcelable {
         * Set the uids that cannot be faded
         *
         * <p>This is a negative list. Players with matching uid of this list will not be faded.
         * Uids that are not part of this list shall be considered for fading
         *
         * <p>Passing an empty list as input clears the existing list. This can be used to
         * reset the list when using a copy constructor
         * Uids that are not part of this list shall be considered for fading.
         *
         * @param uids list of uids
         * @return the same Builder instance
@@ -1267,19 +1250,17 @@ public final class FadeManagerConfiguration implements Parcelable {
        }

        /**
         * Remove the uid from unfadeable list
         * Clears the unfadeable uid list
         *
         * <p>This can be used to reset the list when using a copy constructor.
         *
         * @param uid client uid
         * @return the same Builder instance
         * @see #setUnfadeableUids(List)
         * @see #getUnfadeableUids()
         */
        @NonNull
        public Builder clearUnfadeableUid(int uid) {
            int index = mUnfadeableUids.indexOf(uid);
            if (index != INVALID_INDEX) {
                mUnfadeableUids.remove(index);
            }
        public Builder clearUnfadeableUids() {
            mUnfadeableUids.clear();
            return this;
        }

@@ -1289,9 +1270,6 @@ public final class FadeManagerConfiguration implements Parcelable {
         * <p>This is a negative list. Players with matching audio attributes of this list will not
         * be faded. Audio attributes that are not part of this list shall be considered for fading.
         *
         * <p>Passing an empty list as input clears any existing list. This can be used to
         * reset the list when using a copy constructor
         *
         * <p><b>Note:</b> Be cautious when adding generic audio attributes into this list as it can
         * negatively impact fadeability decision (if such an audio attribute and corresponding
         * usage fall into opposing lists).
@@ -1333,18 +1311,16 @@ public final class FadeManagerConfiguration implements Parcelable {
        }

        /**
         * Remove the {@link android.media.AudioAttributes} from the unfadeable list.
         * Clears the unfadeable {@link android.media.AudioAttributes} list.
         *
         * <p>This can be used to reset the list when using a copy constructor.
         *
         * @param audioAttributes the {@link android.media.AudioAttributes}
         * @return the same Builder instance
         * @see #getUnfadeableAudioAttributes()
         */
        @NonNull
        public Builder clearUnfadeableAudioAttributes(@NonNull AudioAttributes audioAttributes) {
            Objects.requireNonNull(audioAttributes, "Audio attributes cannot be null");
            if (mUnfadeableAudioAttributes.contains(audioAttributes)) {
                mUnfadeableAudioAttributes.remove(audioAttributes);
            }
        public Builder clearUnfadeableAudioAttributes() {
            mUnfadeableAudioAttributes.clear();
            return this;
        }

+14 −46
Original line number Diff line number Diff line
@@ -302,13 +302,13 @@ public final class FadeManagerConfigurationUnitTest {
    }

    @Test
    public void testSetFadeVolShaperConfig_withNullVolumeShaper_getsNull() {
    public void testSetFadeOutVolShaperConfig_withNullVolumeShaper_getsNull() {
        FadeManagerConfiguration fmc = new FadeManagerConfiguration.Builder(mFmc)
                .setFadeOutVolumeShaperConfigForAudioAttributes(TEST_MEDIA_AUDIO_ATTRIBUTE,
                        /* VolumeShaper.Configuration= */ null)
                .setFadeInVolumeShaperConfigForAudioAttributes(TEST_MEDIA_AUDIO_ATTRIBUTE,
                        /* VolumeShaper.Configuration= */ null)
                .clearFadeableUsage(AudioAttributes.USAGE_MEDIA).build();
                .clearFadeableUsages().addFadeableUsage(AudioAttributes.USAGE_MEDIA).build();

        expect.withMessage("Fade out volume shaper config set with null value")
                .that(fmc.getFadeOutVolumeShaperConfigForAudioAttributes(
@@ -539,31 +539,13 @@ public final class FadeManagerConfigurationUnitTest {
    }

    @Test
    public void testClearFadeableUsage() {
        final int usageToClear = AudioAttributes.USAGE_MEDIA;
        List<Integer> updatedUsages = new ArrayList<>(mFmc.getFadeableUsages());
        updatedUsages.remove((Integer) usageToClear);

        FadeManagerConfiguration updatedFmc = new FadeManagerConfiguration
                .Builder(mFmc).clearFadeableUsage(usageToClear).build();
    public void testClearFadeableUsages() {
        FadeManagerConfiguration updatedFmc = new FadeManagerConfiguration.Builder(mFmc)
                .clearFadeableUsages().addFadeableUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
                .build();

        expect.withMessage("Clear fadeable usage").that(updatedFmc.getFadeableUsages())
                .containsExactlyElementsIn(updatedUsages);
    }

    @Test
    public void testClearFadeableUsage_withInvalidUsage_fails() {
        FadeManagerConfiguration.Builder fmcBuilder = new FadeManagerConfiguration.Builder(mFmc);

        IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () ->
                fmcBuilder.clearFadeableUsage(TEST_INVALID_USAGE)
        );

        FadeManagerConfiguration fmc = fmcBuilder.build();
        expect.withMessage("Clear invalid usage").that(thrown).hasMessageThat()
                .contains("Invalid usage");
        expect.withMessage("Fadeable usages").that(fmc.getFadeableUsages())
                .containsExactlyElementsIn(mFmc.getFadeableUsages());
        expect.withMessage("Clear fadeable usages").that(updatedFmc.getFadeableUsages())
                .containsExactlyElementsIn(List.of(AudioAttributes.USAGE_VOICE_COMMUNICATION));
    }

    @Test
@@ -665,7 +647,7 @@ public final class FadeManagerConfigurationUnitTest {
    }

    @Test
    public void testClearUnfadeableContentType() {
    public void testClearUnfadeableContentTypes() {
        List<Integer> unfadeableContentTypes = new ArrayList<>(Arrays.asList(
                AudioAttributes.CONTENT_TYPE_MOVIE,
                AudioAttributes.CONTENT_TYPE_SONIFICATION
@@ -674,23 +656,10 @@ public final class FadeManagerConfigurationUnitTest {

        FadeManagerConfiguration updatedFmc = new FadeManagerConfiguration.Builder()
                .setUnfadeableContentTypes(unfadeableContentTypes)
                .clearUnfadeableContentType(contentTypeToClear).build();
                .clearUnfadeableContentTypes().build();

        unfadeableContentTypes.remove((Integer) contentTypeToClear);
        expect.withMessage("Unfadeable content types").that(updatedFmc.getUnfadeableContentTypes())
                .containsExactlyElementsIn(unfadeableContentTypes);
    }

    @Test
    public void testClearUnfadeableContentType_withInvalidContentType_fails() {
        FadeManagerConfiguration.Builder fmcBuilder = new FadeManagerConfiguration.Builder(mFmc);

        IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () ->
                fmcBuilder.clearUnfadeableContentType(TEST_INVALID_CONTENT_TYPE).build()
        );

        expect.withMessage("Invalid content type exception").that(thrown).hasMessageThat()
                .contains("Invalid content type");
                .isEmpty();
    }

    @Test
@@ -727,7 +696,7 @@ public final class FadeManagerConfigurationUnitTest {
    }

    @Test
    public void testClearUnfadebaleUid() {
    public void testClearUnfadebaleUids() {
        final List<Integer> unfadeableUids = List.of(
                TEST_UID_1,
                TEST_UID_2
@@ -736,10 +705,9 @@ public final class FadeManagerConfigurationUnitTest {
                .setUnfadeableUids(unfadeableUids).build();

        FadeManagerConfiguration updatedFmc = new FadeManagerConfiguration.Builder(fmc)
                .clearUnfadeableUid(TEST_UID_1).build();
                .clearUnfadeableUids().build();

        expect.withMessage("Unfadeable uids").that(updatedFmc.getUnfadeableUids())
                .isEqualTo(List.of(TEST_UID_2));
        expect.withMessage("Unfadeable uids").that(updatedFmc.getUnfadeableUids()).isEmpty();
    }

    @Test