Throw exception when attempting to build empty AudioMixingRule.
This fixes android.media.audio.cts.AudioPlaybackCaptureTest#testMatchNothing. The test asserts that attempting to capture playback with no criteria specified throws and Exception. However, the reason why the test was passing and Exception thrown was not because of explicit check for empty AudioMixingRule, but because of invalid mix role (not adding any rules prior to ag/20001744 caused mix type not to be inferred). If the mix role was explicitly set for the AudioMixingRule.Builder the test would also fail the expectation. This cl is adding explicit check for the presence of rules when building AudioMixingRule to fix this. Bug: 252822301 Test: atest AudioPlaybackCaptureTest Change-Id: If3caa635b67eca779bb2026d2da1c4727e4636e9
This commit is contained in:
@@ -704,8 +704,12 @@ public class AudioMixingRule {
|
||||
* Combines all of the matching and exclusion rules that have been set and return a new
|
||||
* {@link AudioMixingRule} object.
|
||||
* @return a new {@link AudioMixingRule} object
|
||||
* @throws IllegalArgumentException if the rule is empty.
|
||||
*/
|
||||
public AudioMixingRule build() {
|
||||
if (mCriteria.isEmpty()) {
|
||||
throw new IllegalArgumentException("Cannot build AudioMixingRule with no rules.");
|
||||
}
|
||||
return new AudioMixingRule(
|
||||
mTargetMixType == AudioMix.MIX_TYPE_INVALID
|
||||
? AudioMix.MIX_TYPE_PLAYERS : mTargetMixType,
|
||||
|
||||
@@ -212,6 +212,12 @@ public class AudioMixingRuleUnitTests {
|
||||
containsInAnyOrder(isAudioMixSessionCriterion(TEST_SESSION_ID)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void audioMixingRuleWithNoRulesFails() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new AudioMixingRule.Builder().build());
|
||||
}
|
||||
|
||||
|
||||
private static Matcher isAudioMixUidCriterion(int uid, boolean exclude) {
|
||||
return new CustomTypeSafeMatcher<AudioMixMatchCriterion>("uid mix criterion") {
|
||||
|
||||
Reference in New Issue
Block a user