Fixed AudioMixingRule usage of AudioAttribute#getUsage
Given that system usages were added to the AudioAttributes, system
components need to use the API were applicable. AudioMixingRule was
missing this and thus the audio attribute usage base routing did not
work correctly. In particular the registration of the audio policy mixing
rules would not register the system usages based routing correctly.
Instead, the match usage rule would default to unknown usage instead of
the requested system usage.
Bug: 186661937
Bug: 186442942
Bug: 186158497
Test: build gcar_emu_x86 and run car kitchen sink to make sure routing
performed as expected.
Change-Id: I4aaedf1b6b9144bd2e84d2d7112b5ebcf744a8b2
This commit is contained in:
@@ -267,14 +267,18 @@ public final class AudioPlaybackConfiguration implements Parcelable {
|
||||
final AudioPlaybackConfiguration anonymCopy = new AudioPlaybackConfiguration(in.mPlayerIId);
|
||||
anonymCopy.mPlayerState = in.mPlayerState;
|
||||
// do not reuse the full attributes: only usage, content type and public flags are allowed
|
||||
anonymCopy.mPlayerAttr = new AudioAttributes.Builder()
|
||||
.setUsage(in.mPlayerAttr.getUsage())
|
||||
AudioAttributes.Builder builder = new AudioAttributes.Builder()
|
||||
.setContentType(in.mPlayerAttr.getContentType())
|
||||
.setFlags(in.mPlayerAttr.getFlags())
|
||||
.setAllowedCapturePolicy(
|
||||
in.mPlayerAttr.getAllowedCapturePolicy() == ALLOW_CAPTURE_BY_ALL
|
||||
? ALLOW_CAPTURE_BY_ALL : ALLOW_CAPTURE_BY_NONE)
|
||||
.build();
|
||||
? ALLOW_CAPTURE_BY_ALL : ALLOW_CAPTURE_BY_NONE);
|
||||
if (AudioAttributes.isSystemUsage(in.mPlayerAttr.getSystemUsage())) {
|
||||
builder.setSystemUsage(in.mPlayerAttr.getSystemUsage());
|
||||
} else {
|
||||
builder.setUsage(in.mPlayerAttr.getUsage());
|
||||
}
|
||||
anonymCopy.mPlayerAttr = builder.build();
|
||||
anonymCopy.mDeviceId = in.mDeviceId;
|
||||
// anonymized data
|
||||
anonymCopy.mPlayerType = PLAYER_TYPE_UNKNOWN;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class AudioMixingRule {
|
||||
final int match_rule = mRule & ~RULE_EXCLUSION_MASK;
|
||||
switch (match_rule) {
|
||||
case RULE_MATCH_ATTRIBUTE_USAGE:
|
||||
dest.writeInt(mAttr.getUsage());
|
||||
dest.writeInt(mAttr.getSystemUsage());
|
||||
break;
|
||||
case RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET:
|
||||
dest.writeInt(mAttr.getCapturePreset());
|
||||
@@ -165,7 +165,7 @@ public class AudioMixingRule {
|
||||
for (AudioMixMatchCriterion criterion : mCriteria) {
|
||||
if ((criterion.mRule & RULE_MATCH_ATTRIBUTE_USAGE) != 0
|
||||
&& criterion.mAttr != null
|
||||
&& criterion.mAttr.getUsage() == usage) {
|
||||
&& criterion.mAttr.getSystemUsage() == usage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class AudioMixingRule {
|
||||
for (AudioMixMatchCriterion criterion : mCriteria) {
|
||||
if (criterion.mRule == RULE_MATCH_ATTRIBUTE_USAGE
|
||||
&& criterion.mAttr != null
|
||||
&& criterion.mAttr.getUsage() == usage) {
|
||||
&& criterion.mAttr.getSystemUsage() == usage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -565,7 +565,7 @@ public class AudioMixingRule {
|
||||
switch (match_rule) {
|
||||
case RULE_MATCH_ATTRIBUTE_USAGE:
|
||||
// "usage"-based rule
|
||||
if (criterion.mAttr.getUsage() == attrToMatch.getUsage()) {
|
||||
if (criterion.mAttr.getSystemUsage() == attrToMatch.getSystemUsage()) {
|
||||
if (criterion.mRule == rule) {
|
||||
// rule already exists, we're done
|
||||
return this;
|
||||
@@ -646,8 +646,13 @@ public class AudioMixingRule {
|
||||
switch (match_rule) {
|
||||
case RULE_MATCH_ATTRIBUTE_USAGE:
|
||||
int usage = in.readInt();
|
||||
attr = new AudioAttributes.Builder()
|
||||
.setUsage(usage).build();
|
||||
if (AudioAttributes.isSystemUsage(usage)) {
|
||||
attr = new AudioAttributes.Builder()
|
||||
.setSystemUsage(usage).build();
|
||||
} else {
|
||||
attr = new AudioAttributes.Builder()
|
||||
.setUsage(usage).build();
|
||||
}
|
||||
break;
|
||||
case RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET:
|
||||
int preset = in.readInt();
|
||||
|
||||
Reference in New Issue
Block a user