mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add missing overrides in DefaultTrackSelector.Parameters.Builder
Also add a test for this to avoid missing any others in future. Also flesh out the existing test for the deprecated builder, to assert the return type is correctly updated. PiperOrigin-RevId: 688948768
This commit is contained in:
parent
75f29b6997
commit
7b66209bca
@ -1320,6 +1320,13 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
||||
return this;
|
||||
}
|
||||
|
||||
@CanIgnoreReturnValue
|
||||
@Override
|
||||
public Builder setAudioOffloadPreferences(AudioOffloadPreferences audioOffloadPreferences) {
|
||||
super.setAudioOffloadPreferences(audioOffloadPreferences);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to allow adaptive audio selections where adaptation may not be completely
|
||||
* seamless.
|
||||
@ -1421,6 +1428,15 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
||||
return setIgnoredTextSelectionFlags(disabledTextTrackSelectionFlags);
|
||||
}
|
||||
|
||||
// Image
|
||||
|
||||
@CanIgnoreReturnValue
|
||||
@Override
|
||||
public Builder setPrioritizeImageOverVideoEnabled(boolean isPrioritizeImageOverVideoEnabled) {
|
||||
super.setPrioritizeImageOverVideoEnabled(isPrioritizeImageOverVideoEnabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
// General
|
||||
|
||||
@CanIgnoreReturnValue
|
||||
|
@ -3038,12 +3038,32 @@ public final class DefaultTrackSelectorTest {
|
||||
assertThat(selectionOverrideFromBundle).isEqualTo(selectionOverrideToBundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link DefaultTrackSelector.Parameters.Builder} must override every method in {@link
|
||||
* TrackSelectionParameters.Builder} in order to 'fix' the return type to correctly allow chaining
|
||||
* the method calls.
|
||||
*/
|
||||
@Test
|
||||
public void parametersBuilderOverridesAllTrackSelectionParametersBuilderMethods()
|
||||
throws Exception {
|
||||
List<Method> methods = TestUtil.getPublicMethods(TrackSelectionParameters.Builder.class);
|
||||
for (Method method : methods) {
|
||||
Method declaredMethod =
|
||||
Parameters.Builder.class.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||
assertThat(declaredMethod.getDeclaringClass()).isEqualTo(Parameters.Builder.class);
|
||||
if (method.getReturnType().equals(TrackSelectionParameters.Builder.class)) {
|
||||
assertThat(declaredMethod.getReturnType()).isEqualTo(Parameters.Builder.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The deprecated {@link DefaultTrackSelector.ParametersBuilder} is implemented by delegating to
|
||||
* an instance of {@link DefaultTrackSelector.Parameters.Builder}. However, it <b>also</b> extends
|
||||
* {@link TrackSelectionParameters.Builder}, and for the delegation-pattern to work correctly it
|
||||
* needs to override <b>every</b> setter method from the superclass (otherwise the setter won't be
|
||||
* propagated to the delegate). This test ensures that invariant.
|
||||
* propagated to the delegate). This test ensures that invariant. It also ensures the return type
|
||||
* is updated to correctly allow chaining the method calls.
|
||||
*
|
||||
* <p>The test can be removed when the deprecated {@link DefaultTrackSelector.ParametersBuilder}
|
||||
* is removed.
|
||||
@ -3054,11 +3074,15 @@ public final class DefaultTrackSelectorTest {
|
||||
throws Exception {
|
||||
List<Method> methods = TestUtil.getPublicMethods(TrackSelectionParameters.Builder.class);
|
||||
for (Method method : methods) {
|
||||
assertThat(
|
||||
DefaultTrackSelector.ParametersBuilder.class
|
||||
.getDeclaredMethod(method.getName(), method.getParameterTypes())
|
||||
.getDeclaringClass())
|
||||
Method declaredMethod =
|
||||
DefaultTrackSelector.ParametersBuilder.class.getDeclaredMethod(
|
||||
method.getName(), method.getParameterTypes());
|
||||
assertThat(declaredMethod.getDeclaringClass())
|
||||
.isEqualTo(DefaultTrackSelector.ParametersBuilder.class);
|
||||
if (method.getReturnType().equals(TrackSelectionParameters.Builder.class)) {
|
||||
assertThat(declaredMethod.getReturnType())
|
||||
.isEqualTo(DefaultTrackSelector.ParametersBuilder.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user