Merge "Throw exception when attempting to build empty AudioMixingRule."

This commit is contained in:
Ján Sebechlebský
2022-10-18 18:58:09 +00:00
committed by Android (Google) Code Review
2 changed files with 10 additions and 0 deletions

View File

@@ -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,

View File

@@ -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") {