FileDocCategorySizeDatePackage
AudioPolicyConfig.javaAPI DocAndroid 5.1 API7908Thu Mar 12 22:22:30 GMT 2015android.media.audiopolicy

AudioPolicyConfig

public class AudioPolicyConfig extends Object implements android.os.Parcelable
hide
Internal storage class for AudioPolicy configuration.

Fields Summary
private static final String
TAG
protected ArrayList
mMixes
protected int
mDuckingPolicy
private String
mRegistrationId
public static final Parcelable.Creator
CREATOR
Constructors Summary
protected AudioPolicyConfig(AudioPolicyConfig conf)


       
        mMixes = conf.mMixes;
    
AudioPolicyConfig(ArrayList mixes)

        mMixes = mixes;
    
private AudioPolicyConfig(android.os.Parcel in)

        mMixes = new ArrayList<AudioMix>();
        int nbMixes = in.readInt();
        for (int i = 0 ; i < nbMixes ; i++) {
            final AudioMix.Builder mixBuilder = new AudioMix.Builder();
            // read mix route flags
            int routeFlags = in.readInt();
            mixBuilder.setRouteFlags(routeFlags);
            // read mix format
            int sampleRate = in.readInt();
            int encoding = in.readInt();
            int channelMask = in.readInt();
            final AudioFormat format = new AudioFormat.Builder().setSampleRate(sampleRate)
                    .setChannelMask(channelMask).setEncoding(encoding).build();
            mixBuilder.setFormat(format);
            // read mix rules
            int nbRules = in.readInt();
            AudioMixingRule.Builder ruleBuilder = new AudioMixingRule.Builder();
            for (int j = 0 ; j < nbRules ; j++) {
                // read the matching rules
                ruleBuilder.addRuleFromParcel(in);
            }
            mixBuilder.setMixingRule(ruleBuilder.build());
            mMixes.add(mixBuilder.build());
        }
    
Methods Summary
public voidaddMix(AudioMix mix)
Add an {@link AudioMix} to be part of the audio policy being built.

param
mix a non-null {@link AudioMix} to be part of the audio policy.
return
the same Builder instance.
throws
IllegalArgumentException

        if (mix == null) {
            throw new IllegalArgumentException("Illegal null AudioMix argument");
        }
        mMixes.add(mix);
    
public intdescribeContents()

        return 0;
    
protected java.lang.StringgetRegistration()

        return mRegistrationId;
    
public inthashCode()

        return Objects.hash(mMixes);
    
private static java.lang.StringmixTypeId(int type)

        if (type == AudioMix.MIX_TYPE_PLAYERS) return "p";
        else if (type == AudioMix.MIX_TYPE_RECORDERS) return "r";
        else return "i";
    
protected voidsetRegistration(java.lang.String regId)

        final boolean currentRegNull = (mRegistrationId == null) || mRegistrationId.isEmpty();
        final boolean newRegNull = (regId == null) || regId.isEmpty();
        if (!currentRegNull && !newRegNull && !mRegistrationId.equals(regId)) {
            Log.e(TAG, "Invalid registration transition from " + mRegistrationId + " to " + regId);
            return;
        }
        mRegistrationId = regId == null ? "" : regId;
        int mixIndex = 0;
        for (AudioMix mix : mMixes) {
            if (!mRegistrationId.isEmpty()) {
                mix.setRegistration(mRegistrationId + "mix" + mixTypeId(mix.getMixType()) + ":"
                        + mixIndex++);
            } else {
                mix.setRegistration("");
            }
        }
    
public java.lang.StringtoLogFriendlyString()


        
        String textDump = new String("android.media.audiopolicy.AudioPolicyConfig:\n");
        textDump += mMixes.size() + " AudioMix: "+ mRegistrationId + "\n";
        for(AudioMix mix : mMixes) {
            // write mix route flags
            textDump += "* route flags=0x" + Integer.toHexString(mix.getRouteFlags()) + "\n";
            // write mix format
            textDump += "  rate=" + mix.getFormat().getSampleRate() + "Hz\n";
            textDump += "  encoding=" + mix.getFormat().getEncoding() + "\n";
            textDump += "  channels=0x";
            textDump += Integer.toHexString(mix.getFormat().getChannelMask()).toUpperCase() +"\n";
            // write mix rules
            final ArrayList<AttributeMatchCriterion> criteria = mix.getRule().getCriteria();
            for (AttributeMatchCriterion criterion : criteria) {
                switch(criterion.mRule) {
                    case AudioMixingRule.RULE_EXCLUDE_ATTRIBUTE_USAGE:
                        textDump += "  exclude usage ";
                        textDump += criterion.mAttr.usageToString();
                        break;
                    case AudioMixingRule.RULE_MATCH_ATTRIBUTE_USAGE:
                        textDump += "  match usage ";
                        textDump += criterion.mAttr.usageToString();
                        break;
                    case AudioMixingRule.RULE_EXCLUDE_ATTRIBUTE_CAPTURE_PRESET:
                        textDump += "  exclude capture preset ";
                        textDump += criterion.mAttr.getCapturePreset();
                        break;
                    case AudioMixingRule.RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET:
                        textDump += "  match capture preset ";
                        textDump += criterion.mAttr.getCapturePreset();
                        break;
                    default:
                        textDump += "invalid rule!";
                }
                textDump += "\n";
            }
        }
        return textDump;
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeInt(mMixes.size());
        for (AudioMix mix : mMixes) {
            // write mix route flags
            dest.writeInt(mix.getRouteFlags());
            // write mix format
            dest.writeInt(mix.getFormat().getSampleRate());
            dest.writeInt(mix.getFormat().getEncoding());
            dest.writeInt(mix.getFormat().getChannelMask());
            // write mix rules
            final ArrayList<AttributeMatchCriterion> criteria = mix.getRule().getCriteria();
            dest.writeInt(criteria.size());
            for (AttributeMatchCriterion criterion : criteria) {
                criterion.writeToParcel(dest);
            }
        }