package defpackage;

import android.media.AudioDescriptor;
import android.media.AudioDeviceInfo;
import android.media.AudioProfile;
import android.os.Build;
import j$.util.Comparator;
import j$.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;

/* JADX INFO: renamed from: ᵼᵰˋ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC5316 {

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static final C2598 f20059 = AbstractC4509.m9553(12);

    /* JADX WARN: Removed duplicated region for block: B:120:0x017c  */
    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static AbstractC4509 m10901(AudioDeviceInfo audioDeviceInfo) {
        int type;
        AbstractC4509 abstractC4509M9559;
        int speakerLayoutChannelMask;
        boolean z = ᵻᵪ.ˑˊᵲ(audioDeviceInfo.getType());
        C2598 c2598 = f20059;
        if (!z) {
            if (audioDeviceInfo.getType() == 1) {
                return AbstractC4509.m9553(4);
            }
            if (audioDeviceInfo.getType() == 2) {
                if (Build.VERSION.SDK_INT >= 36 && (speakerLayoutChannelMask = audioDeviceInfo.getSpeakerLayoutChannelMask()) != 0 && speakerLayoutChannelMask != 1) {
                    return AbstractC4509.m9553(Integer.valueOf(speakerLayoutChannelMask));
                }
                ˋˀᵧ.ʿٴˇ("Built-in speaker's getSpeakerLayoutChannelMask not usable, defaulting to stereo.");
                return c2598;
            }
            int i = Build.VERSION.SDK_INT;
            if (i >= 31 && audioDeviceInfo.getType() == 10) {
                AbstractC4509 abstractC4509M10902 = m10902(audioDeviceInfo);
                if (!abstractC4509M10902.isEmpty()) {
                    return abstractC4509M10902;
                }
                AbstractC4509 abstractC4509M10803 = AbstractC5241.m10803(audioDeviceInfo.getAudioDescriptors());
                if (!abstractC4509M10803.isEmpty()) {
                    return abstractC4509M10803;
                }
            } else if (i >= 31) {
                int type2 = audioDeviceInfo.getType();
                if (i >= 31 && type2 == 29) {
                    AbstractC4509 abstractC4509M109022 = m10902(audioDeviceInfo);
                    if (!abstractC4509M109022.isEmpty()) {
                        return abstractC4509M109022;
                    }
                    List<AudioDescriptor> audioDescriptors = audioDeviceInfo.getAudioDescriptors();
                    if (i >= 34) {
                        if (i < 34 || audioDescriptors == null) {
                            C2822 c2822 = AbstractC4509.f17159;
                            abstractC4509M9559 = C2598.f10048;
                        } else {
                            ArrayList arrayList = new ArrayList();
                            Iterator<AudioDescriptor> it = audioDescriptors.iterator();
                            while (true) {
                                if (!it.hasNext()) {
                                    break;
                                }
                                AudioDescriptor audioDescriptorM4091 = C1418.m4091(it.next());
                                if (audioDescriptorM4091.getStandard() == 2) {
                                    byte[] descriptor = audioDescriptorM4091.getDescriptor();
                                    if (descriptor.length != 3) {
                                        ˋˀᵧ.ʿٴˇ("Invalid SADB length: " + descriptor.length);
                                    } else {
                                        if (Build.VERSION.SDK_INT >= 34 && descriptor.length == 3) {
                                            byte b = descriptor[0];
                                            i = (b & 1) != 0 ? 12 : 0;
                                            if ((b & 2) != 0) {
                                                i |= 32;
                                            }
                                            if ((b & 4) != 0) {
                                                i |= 16;
                                            }
                                            if ((b & 8) != 0) {
                                                i |= 192;
                                            }
                                            if ((b & 16) != 0) {
                                                i |= 1024;
                                            }
                                            if ((b & 32) != 0) {
                                                i |= 768;
                                            }
                                            if ((b & 128) != 0) {
                                                i |= 201326592;
                                            }
                                            byte b2 = descriptor[1];
                                            if ((b2 & 1) != 0) {
                                                i |= 81920;
                                            }
                                            if ((b2 & 2) != 0) {
                                                i |= 8192;
                                            }
                                            if ((b2 & 4) != 0) {
                                                i |= 32768;
                                            }
                                            if ((b2 & 8) != 0) {
                                                i |= 6144;
                                            }
                                            if ((b2 & 16) != 0) {
                                                i |= 33554432;
                                            }
                                            if ((b2 & 32) != 0) {
                                                i |= 262144;
                                            }
                                            if ((b2 & 64) != 0) {
                                                i |= 6144;
                                            }
                                            if ((b2 & 128) != 0) {
                                                i |= 3145728;
                                            }
                                            byte b3 = descriptor[2];
                                            if ((b3 & 1) != 0) {
                                                i |= 655360;
                                            }
                                            if ((b3 & 2) != 0) {
                                                i |= 8388608;
                                            }
                                            if ((b3 & 4) != 0) {
                                                i |= 20971520;
                                            }
                                        }
                                        arrayList.add(Integer.valueOf(i));
                                    }
                                }
                            }
                            List.EL.sort(arrayList, new C2262(0));
                            abstractC4509M9559 = AbstractC4509.m9559(arrayList);
                        }
                        if (!abstractC4509M9559.isEmpty()) {
                            return abstractC4509M9559;
                        }
                    }
                    AbstractC4509 abstractC4509M108032 = AbstractC5241.m10803(audioDescriptors);
                    if (!abstractC4509M108032.isEmpty()) {
                        return abstractC4509M108032;
                    }
                } else if (i >= 31 && ((type = audioDeviceInfo.getType()) == 11 || type == 12 || (i >= 31 && type == 22))) {
                    AbstractC4509 abstractC4509M109023 = m10902(audioDeviceInfo);
                    if (!abstractC4509M109023.isEmpty()) {
                        return abstractC4509M109023;
                    }
                }
            }
        }
        return c2598;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static AbstractC4509 m10902(AudioDeviceInfo audioDeviceInfo) {
        java.util.List<AudioProfile> audioProfiles = audioDeviceInfo.getAudioProfiles();
        TreeSet treeSet = new TreeSet(Comparator.EL.reversed(Comparator.CC.comparing(new C0394())));
        for (AudioProfile audioProfile : audioProfiles) {
            if (audioProfile.getEncapsulationType() != 1 && AbstractC0956.m3253(audioProfile.getFormat())) {
                for (int i : audioProfile.getChannelMasks()) {
                    treeSet.add(Integer.valueOf(i));
                }
            }
        }
        return AbstractC4509.m9559(treeSet);
    }
}
