X-plore v4.37.09版本的 MD5 值为:1ac588cd7c13e9578c2d4266387e2f4f

以下内容为反编译后的 AbstractC7292g.java 源代码,内容仅作参考


package r6;

import F7.AbstractC1158b;
import F7.C1160d;
import F7.w;
import F7.x;
import F7.z;
import H7.AbstractC1204h;
import H7.AbstractC1208j;
import H7.C1191a0;
import H7.H;
import H7.InterfaceC1230u0;
import H7.L;
import H7.M;
import H7.N;
import H7.Q0;
import H7.W;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Build;
import com.google.firebase.remoteconfig.lE.PkPO;
import h7.AbstractC6732u;
import h7.AbstractC6736y;
import h7.C6709J;
import h7.C6730s;
import i7.AbstractC6821C;
import i7.S;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.DatagramPacket;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.InterfaceAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
import l7.AbstractC7026a;
import m7.InterfaceC7068d;
import m7.InterfaceC7071g;
import o7.AbstractC7136l;
import r6.C7289d;
import v7.InterfaceC7625a;
import v7.r;
import w7.AbstractC7771k;
import w7.AbstractC7777q;
import w7.AbstractC7780t;
import w7.AbstractC7781u;

public abstract class AbstractC7292g {

    public static final d f54145n;

    private static String f54146o;

    private final Context f54147a;

    private final WifiManager f54148b;

    private final n f54149c;

    private WifiManager.MulticastLock f54150d;

    private WifiManager.WifiLock f54151e;

    private final HashSet f54152f;

    private final HashSet f54153g;

    private final Thread f54154h;

    private final Thread f54155i;

    private final MulticastSocket f54156j;

    private final MulticastSocket f54157k;

    private InterfaceC1230u0 f54158l;

    private boolean f54159m;

    static final class a extends AbstractC7781u implements InterfaceC7625a {

        final SocketException f54160b;

        a(SocketException socketException) {
            super(0);
            this.f54160b = socketException;
        }

        @Override
        public final String c() {
            return "SocketException: " + this.f54160b.getMessage();
        }
    }

    class b extends AbstractC7777q implements InterfaceC7625a {
        b(Object obj) {
            super(0, obj, AbstractC7292g.class, "processSsdp", "processSsdp()V", 0);
        }

        @Override
        public Object c() {
            o();
            return C6709J.f49946a;
        }

        public final void o() {
            ((AbstractC7292g) this.f58225b).y();
        }
    }

    class c extends AbstractC7777q implements InterfaceC7625a {
        c(Object obj) {
            super(0, obj, AbstractC7292g.class, "processDIO", "processDIO()V", 0);
        }

        @Override
        public Object c() {
            o();
            return C6709J.f49946a;
        }

        public final void o() {
            ((AbstractC7292g) this.f58225b).w();
        }
    }

    public static final class d {
        private d() {
        }

        public d(AbstractC7771k abstractC7771k) {
            this();
        }

        public final void a(InterfaceC7625a interfaceC7625a) {
            AbstractC7780t.f(interfaceC7625a, "cb");
        }

        public final String b() {
            String str = AbstractC7292g.f54146o;
            if (str != null) {
                return str;
            }
            AbstractC7780t.r("userAgent");
            return null;
        }

        public final void c(String str, String str2) {
            AbstractC7780t.f(str, "appName");
            AbstractC7780t.f(str2, "version");
            AbstractC7292g.f54146o = "Android/" + Build.VERSION.RELEASE + " UPnP/1.0 " + str + '/' + str2;
        }
    }

    public static final class e extends HashMap {

        public static final a f54161a = new a(null);

        public static final class a {
            private a() {
            }

            public a(AbstractC7771k abstractC7771k) {
                this();
            }
        }

        public static final class b extends AbstractC7781u implements InterfaceC7625a {

            final String f54162b;

            b(String str) {
                super(0);
                this.f54162b = str;
            }

            @Override
            public final String c() {
                return "Invalid USN header: " + this.f54162b;
            }
        }

        public e(BufferedReader bufferedReader) {
            char U02;
            boolean c9;
            List s02;
            CharSequence M02;
            Object W8;
            String str;
            CharSequence M03;
            AbstractC7780t.f(bufferedReader, "rd");
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null || readLine.length() == 0) {
                    return;
                }
                AbstractC7780t.c(readLine);
                U02 = z.U0(readLine);
                c9 = AbstractC1158b.c(U02);
                if (!c9) {
                    s02 = x.s0(readLine, new char[]{':'}, false, 2, 2, null);
                    M02 = x.M0((String) s02.get(0));
                    String obj = M02.toString();
                    W8 = AbstractC6821C.W(s02, 1);
                    String str2 = (String) W8;
                    if (str2 != null) {
                        M03 = x.M0(str2);
                        str = M03.toString();
                    } else {
                        str = null;
                    }
                    put(obj, str);
                }
            }
        }

        private final String o(String str) {
            String lowerCase = str.toLowerCase(Locale.ROOT);
            AbstractC7780t.e(lowerCase, "toLowerCase(...)");
            return lowerCase;
        }

        public boolean a(String str) {
            AbstractC7780t.f(str, "key");
            return super.containsKey(o(str));
        }

        public boolean b(String str) {
            return super.containsValue(str);
        }

        public String c(String str) {
            AbstractC7780t.f(str, "key");
            return (String) super.get(o(str));
        }

        @Override
        public final boolean containsKey(Object obj) {
            if (obj instanceof String) {
                return a((String) obj);
            }
            return false;
        }

        @Override
        public final boolean containsValue(Object obj) {
            if (obj != null && !(obj instanceof String)) {
                return false;
            }
            return b((String) obj);
        }

        public Set e() {
            return super.entrySet();
        }

        @Override
        public final Set entrySet() {
            return e();
        }

        public Set f() {
            return super.keySet();
        }

        @Override
        public final Object get(Object obj) {
            if (obj instanceof String) {
                return c((String) obj);
            }
            return null;
        }

        @Override
        public final Object getOrDefault(Object obj, Object obj2) {
            return !(obj instanceof String) ? obj2 : h((String) obj, (String) obj2);
        }

        public String h(String str, String str2) {
            return (String) super.getOrDefault(str, str2);
        }

        public int j() {
            return super.size();
        }

        public final String k() {
            boolean D8;
            List t02;
            boolean D9;
            boolean s9;
            boolean I8;
            String str = (String) get("USN");
            if (str != null) {
                D8 = w.D(str, "uuid:", false, 2, null);
                if (D8) {
                    s9 = w.s(str, "::upnp:rootdevice", false, 2, null);
                    if (s9) {
                        String substring = str.substring(5, str.length() - 17);
                        AbstractC7780t.e(substring, "substring(...)");
                        return substring;
                    }
                    I8 = x.I(str, "::urn", false, 2, null);
                    if (!I8) {
                        String substring2 = str.substring(5);
                        AbstractC7780t.e(substring2, "substring(...)");
                        return substring2;
                    }
                }
                t02 = x.t0(str, new String[]{"::"}, false, 0, 6, null);
                if (t02.size() == 2) {
                    String str2 = (String) t02.get(0);
                    D9 = w.D(str2, "uuid:", false, 2, null);
                    if (D9) {
                        str2 = str2.substring(5);
                        AbstractC7780t.e(str2, "substring(...)");
                    }
                    return str2;
                }
                AbstractC7292g.f54145n.a(new b(str));
            }
            return null;
        }

        @Override
        public final Set keySet() {
            return f();
        }

        public Collection m() {
            return super.values();
        }

        @Override
        public String put(String str, String str2) {
            AbstractC7780t.f(str, "key");
            return (String) super.put(o(str), str2);
        }

        public String q(String str) {
            return (String) super.remove(str);
        }

        public boolean r(String str, String str2) {
            return super.remove(str, str2);
        }

        @Override
        public final Object remove(Object obj) {
            if (obj instanceof String) {
                return q((String) obj);
            }
            return null;
        }

        @Override
        public final boolean remove(Object obj, Object obj2) {
            if (!(obj instanceof String)) {
                return false;
            }
            if (obj2 != null && !(obj2 instanceof String)) {
                return false;
            }
            return r((String) obj, (String) obj2);
        }

        @Override
        public final int size() {
            return j();
        }

        @Override
        public final Collection values() {
            return m();
        }
    }

    public static final class f extends AbstractC7781u implements InterfaceC7625a {

        final C7291f f54163b;

        f(C7291f c7291f) {
            super(0);
            this.f54163b = c7291f;
        }

        @Override
        public final String c() {
            return "Add device " + this.f54163b + ", udn: " + this.f54163b.k();
        }
    }

    static final class C0844g extends AbstractC7781u implements InterfaceC7625a {

        public static final C0844g f54164b = new C0844g();

        C0844g() {
            super(0);
        }

        @Override
        public final String c() {
            return "close";
        }
    }

    public static final class h extends AbstractC7781u implements r {

        public static final class a extends AbstractC7781u implements InterfaceC7625a {

            final C7291f f54166b;

            final String f54167c;

            a(C7291f c7291f, String str) {
                super(0);
                this.f54166b = c7291f;
                this.f54167c = str;
            }

            @Override
            public final String c() {
                return PkPO.QznrTm + this.f54166b + ", udn: " + this.f54167c;
            }
        }

        h() {
            super(4);
        }

        public final void a(String str, e eVar, String str2, String str3) {
            AbstractC7780t.f(str, "<anonymous parameter 0>");
            AbstractC7780t.f(eVar, "<anonymous parameter 1>");
            AbstractC7780t.f(str2, "udn");
            AbstractC7780t.f(str3, "loc");
            C7291f s9 = AbstractC7292g.this.s(str2);
            if (s9 == null) {
                AbstractC7292g.this.A(str2, str3);
            } else {
                AbstractC7292g.f54145n.a(new a(s9, str2));
            }
        }

        @Override
        public Object k(Object obj, Object obj2, Object obj3, Object obj4) {
            a((String) obj, (e) obj2, (String) obj3, (String) obj4);
            return C6709J.f49946a;
        }
    }

    public static final class i extends AbstractC7781u implements InterfaceC7625a {

        final String f54168b;

        i(String str) {
            super(0);
            this.f54168b = str;
        }

        @Override
        public final String c() {
            return "Ignore multicast: " + this.f54168b;
        }
    }

    public static final class j extends AbstractC7781u implements InterfaceC7625a {

        final Exception f54169b;

        j(Exception exc) {
            super(0);
            this.f54169b = exc;
        }

        @Override
        public final String c() {
            return "processMulticastSocket: " + this.f54169b.getMessage();
        }
    }

    public static final class k extends AbstractC7781u implements r {

        public static final class a extends AbstractC7781u implements InterfaceC7625a {

            final String f54171b;

            a(String str) {
                super(0);
                this.f54171b = str;
            }

            @Override
            public final String c() {
                return "Device already exist: " + this.f54171b;
            }
        }

        public static final class b extends AbstractC7781u implements InterfaceC7625a {

            final String f54172b;

            b(String str) {
                super(0);
                this.f54172b = str;
            }

            @Override
            public final String c() {
                return "ssdp:update: " + this.f54172b;
            }
        }

        public static final class c extends AbstractC7781u implements InterfaceC7625a {

            final String f54173b;

            c(String str) {
                super(0);
                this.f54173b = str;
            }

            @Override
            public final String c() {
                return "ssdp:byebye: " + this.f54173b;
            }
        }

        k() {
            super(4);
        }

        public final void a(String str, e eVar, String str2, String str3) {
            String str4;
            AbstractC7780t.f(str, "startLine");
            AbstractC7780t.f(eVar, "hh");
            AbstractC7780t.f(str2, "udn");
            AbstractC7780t.f(str3, "loc");
            if (!AbstractC7780t.a(str, "NOTIFY") || (str4 = (String) eVar.get("NTS")) == null) {
                return;
            }
            int hashCode = str4.hashCode();
            if (hashCode == -1489634930) {
                if (str4.equals("ssdp:byebye")) {
                    AbstractC7292g.f54145n.a(new c(str2));
                    AbstractC7292g.this.z(str2);
                    return;
                }
                return;
            }
            if (hashCode == -954023657) {
                if (str4.equals("ssdp:update")) {
                    AbstractC7292g.f54145n.a(new b(str2));
                    return;
                }
                return;
            }
            if (hashCode == 2028850879 && str4.equals("ssdp:alive")) {
                if (AbstractC7292g.this.s(str2) == null) {
                    AbstractC7292g.this.A(str2, str3);
                } else {
                    AbstractC7292g.f54145n.a(new a(str2));
                }
            }
        }

        @Override
        public Object k(Object obj, Object obj2, Object obj3, Object obj4) {
            a((String) obj, (e) obj2, (String) obj3, (String) obj4);
            return C6709J.f49946a;
        }
    }

    public static final class l extends AbstractC7781u implements InterfaceC7625a {

        final C7291f f54174b;

        l(C7291f c7291f) {
            super(0);
            this.f54174b = c7291f;
        }

        @Override
        public final String c() {
            return "Remove device " + this.f54174b;
        }
    }

    public static final class m extends AbstractC7136l implements v7.p {

        final String f54176F;

        final String f54177G;

        int f54178e;

        public static final class a extends AbstractC7781u implements InterfaceC7625a {

            final C7288c f54179b;

            a(C7288c c7288c) {
                super(0);
                this.f54179b = c7288c;
            }

            @Override
            public final String c() {
                return "failed: " + this.f54179b;
            }
        }

        public static final class b extends AbstractC7781u implements InterfaceC7625a {

            final Exception f54180b;

            b(Exception exc) {
                super(0);
                this.f54180b = exc;
            }

            @Override
            public final String c() {
                return "Describe failed: " + this.f54180b.getMessage();
            }
        }

        public static final class c extends AbstractC7136l implements v7.p {

            final String f54181E;

            int f54182e;

            c(String str, InterfaceC7068d interfaceC7068d) {
                super(2, interfaceC7068d);
                this.f54181E = str;
            }

            @Override
            public final Object r(L l9, InterfaceC7068d interfaceC7068d) {
                return ((c) u(l9, interfaceC7068d)).z(C6709J.f49946a);
            }

            @Override
            public final InterfaceC7068d u(Object obj, InterfaceC7068d interfaceC7068d) {
                return new c(this.f54181E, interfaceC7068d);
            }

            @Override
            public final Object z(Object obj) {
                n7.d.f();
                if (this.f54182e != 0) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                AbstractC6732u.b(obj);
                return AbstractC7287b.b("GET", this.f54181E, null, new C6730s[0], 4, null);
            }
        }

        m(String str, String str2, InterfaceC7068d interfaceC7068d) {
            super(2, interfaceC7068d);
            this.f54176F = str;
            this.f54177G = str2;
        }

        @Override
        public final Object r(L l9, InterfaceC7068d interfaceC7068d) {
            return ((m) u(l9, interfaceC7068d)).z(C6709J.f49946a);
        }

        @Override
        public final InterfaceC7068d u(Object obj, InterfaceC7068d interfaceC7068d) {
            return new m(this.f54176F, this.f54177G, interfaceC7068d);
        }

        @Override
        public final Object z(Object obj) {
            Object f9;
            HashSet hashSet;
            C7288c c7288c;
            byte[] a9;
            f9 = n7.d.f();
            int i9 = this.f54178e;
            try {
                try {
                    if (i9 == 0) {
                        AbstractC6732u.b(obj);
                        H b9 = C1191a0.b();
                        c cVar = new c(this.f54177G, null);
                        this.f54178e = 1;
                        obj = AbstractC1204h.g(b9, cVar, this);
                        if (obj == f9) {
                            return f9;
                        }
                    } else {
                        if (i9 != 1) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        AbstractC6732u.b(obj);
                    }
                    c7288c = (C7288c) obj;
                    a9 = c7288c.a();
                } catch (Throwable th) {
                    HashSet hashSet2 = AbstractC7292g.this.f54153g;
                    AbstractC7292g abstractC7292g = AbstractC7292g.this;
                    String str = this.f54177G;
                    synchronized (hashSet2) {
                        try {
                            abstractC7292g.f54153g.remove(str);
                            throw th;
                        } catch (Throwable th2) {
                            throw th2;
                        }
                    }
                }
            } catch (CancellationException unused) {
                hashSet = AbstractC7292g.this.f54153g;
                AbstractC7292g abstractC7292g2 = AbstractC7292g.this;
                String str2 = this.f54177G;
                synchronized (hashSet) {
                    try {
                        abstractC7292g2.f54153g.remove(str2);
                    } catch (Throwable th3) {
                        throw th3;
                    }
                }
            } catch (Exception e9) {
                AbstractC7292g.f54145n.a(new b(e9));
                hashSet = AbstractC7292g.this.f54153g;
                AbstractC7292g abstractC7292g3 = AbstractC7292g.this;
                String str3 = this.f54177G;
                synchronized (hashSet) {
                    try {
                        abstractC7292g3.f54153g.remove(str3);
                    } catch (Throwable th4) {
                        throw th4;
                    }
                }
            }
            if (!c7288c.d()) {
                if ((!(a9.length == 0)) && !AbstractC7292g.this.f54159m) {
                    AbstractC7292g.this.n(AbstractC7292g.this.p(this.f54176F, this.f54177G, a9, c7288c.b()));
                    hashSet = AbstractC7292g.this.f54153g;
                    AbstractC7292g abstractC7292g4 = AbstractC7292g.this;
                    String str4 = this.f54177G;
                    synchronized (hashSet) {
                        try {
                            abstractC7292g4.f54153g.remove(str4);
                            return C6709J.f49946a;
                        } catch (Throwable th5) {
                            throw th5;
                        }
                    }
                }
            }
            AbstractC7292g.f54145n.a(new a(c7288c));
            hashSet = AbstractC7292g.this.f54153g;
            AbstractC7292g abstractC7292g42 = AbstractC7292g.this;
            String str42 = this.f54177G;
            synchronized (hashSet) {
            }
        }
    }

    public static final class n implements L {

        private final InterfaceC7071g f54183a = Q0.b(null, 1, null);

        n() {
        }

        @Override
        public InterfaceC7071g getCoroutineContext() {
            return this.f54183a;
        }
    }

    static final class o extends AbstractC7136l implements v7.p {

        Object f54184E;

        Object f54185F;

        int f54186G;

        int f54187H;

        int f54188I;

        int f54189J;

        final int f54190K;

        final int f54191L;

        final AbstractC7292g f54192M;

        final int f54193N;

        Object f54194e;

        public static final class a extends AbstractC7781u implements InterfaceC7625a {

            public static final a f54195b = new a();

            a() {
                super(0);
            }

            @Override
            public final String c() {
                return "Search";
            }
        }

        public static final class b extends AbstractC7136l implements v7.p {

            final AbstractC7292g f54196E;

            final InetAddress f54197F;

            final Map f54198G;

            int f54199e;

            b(AbstractC7292g abstractC7292g, InetAddress inetAddress, Map map, InterfaceC7068d interfaceC7068d) {
                super(2, interfaceC7068d);
                this.f54196E = abstractC7292g;
                this.f54197F = inetAddress;
                this.f54198G = map;
            }

            @Override
            public final Object r(L l9, InterfaceC7068d interfaceC7068d) {
                return ((b) u(l9, interfaceC7068d)).z(C6709J.f49946a);
            }

            @Override
            public final InterfaceC7068d u(Object obj, InterfaceC7068d interfaceC7068d) {
                return new b(this.f54196E, this.f54197F, this.f54198G, interfaceC7068d);
            }

            @Override
            public final Object z(Object obj) {
                n7.d.f();
                if (this.f54199e != 0) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                AbstractC6732u.b(obj);
                this.f54196E.C(this.f54197F, 1900, this.f54198G);
                return C6709J.f49946a;
            }
        }

        public static final class c extends AbstractC7781u implements InterfaceC7625a {

            final Exception f54200b;

            c(Exception exc) {
                super(0);
                this.f54200b = exc;
            }

            @Override
            public final String c() {
                return "Search failed: " + this.f54200b.getMessage();
            }
        }

        public static final class d extends AbstractC7136l implements v7.p {

            int f54201e;

            d(InterfaceC7068d interfaceC7068d) {
                super(2, interfaceC7068d);
            }

            @Override
            public final Object r(L l9, InterfaceC7068d interfaceC7068d) {
                return ((d) u(l9, interfaceC7068d)).z(C6709J.f49946a);
            }

            @Override
            public final InterfaceC7068d u(Object obj, InterfaceC7068d interfaceC7068d) {
                return new d(interfaceC7068d);
            }

            @Override
            public final Object z(Object obj) {
                n7.d.f();
                if (this.f54201e != 0) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                AbstractC6732u.b(obj);
                return InetAddress.getByName("239.255.255.250");
            }
        }

        o(int i9, int i10, AbstractC7292g abstractC7292g, int i11, InterfaceC7068d interfaceC7068d) {
            super(2, interfaceC7068d);
            this.f54190K = i9;
            this.f54191L = i10;
            this.f54192M = abstractC7292g;
            this.f54193N = i11;
        }

        @Override
        public final Object r(L l9, InterfaceC7068d interfaceC7068d) {
            return ((o) u(l9, interfaceC7068d)).z(C6709J.f49946a);
        }

        @Override
        public final InterfaceC7068d u(Object obj, InterfaceC7068d interfaceC7068d) {
            return new o(this.f54190K, this.f54191L, this.f54192M, this.f54193N, interfaceC7068d);
        }

        @Override
        public final Object z(Object obj) {
            Object f9;
            Object g9;
            InetAddress inetAddress;
            Map j9;
            int i9;
            int i10;
            AbstractC7292g abstractC7292g;
            int i11;
            InetAddress inetAddress2;
            Map map;
            AbstractC7292g abstractC7292g2;
            int i12;
            int i13;
            f9 = n7.d.f();
            int i14 = this.f54189J;
            try {
            } catch (Exception e9) {
                AbstractC7292g.f54145n.a(new c(e9));
            }
            if (i14 == 0) {
                AbstractC6732u.b(obj);
                H b9 = C1191a0.b();
                d dVar = new d(null);
                this.f54189J = 1;
                g9 = AbstractC1204h.g(b9, dVar, this);
                if (g9 == f9) {
                    return f9;
                }
            } else {
                if (i14 != 1) {
                    if (i14 == 2) {
                        i13 = this.f54188I;
                        i12 = this.f54187H;
                        i9 = this.f54186G;
                        abstractC7292g2 = (AbstractC7292g) this.f54185F;
                        map = (Map) this.f54184E;
                        inetAddress2 = (InetAddress) this.f54194e;
                        AbstractC6732u.b(obj);
                        this.f54194e = inetAddress2;
                        this.f54184E = map;
                        this.f54185F = abstractC7292g2;
                        this.f54186G = i9;
                        this.f54187H = i12;
                        this.f54188I = i13;
                        this.f54189J = 3;
                        if (W.a(i12, this) == f9) {
                        }
                        AbstractC7292g abstractC7292g3 = abstractC7292g2;
                        i10 = i12;
                        j9 = map;
                        abstractC7292g = abstractC7292g3;
                        InetAddress inetAddress3 = inetAddress2;
                        i11 = i13 + 1;
                        inetAddress = inetAddress3;
                        if (i11 < i9) {
                        }
                        this.f54192M.f54158l = null;
                        return C6709J.f49946a;
                    }
                    if (i14 != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    i13 = this.f54188I;
                    i12 = this.f54187H;
                    i9 = this.f54186G;
                    abstractC7292g2 = (AbstractC7292g) this.f54185F;
                    map = (Map) this.f54184E;
                    inetAddress2 = (InetAddress) this.f54194e;
                    AbstractC6732u.b(obj);
                    AbstractC7292g abstractC7292g32 = abstractC7292g2;
                    i10 = i12;
                    j9 = map;
                    abstractC7292g = abstractC7292g32;
                    InetAddress inetAddress32 = inetAddress2;
                    i11 = i13 + 1;
                    inetAddress = inetAddress32;
                    if (i11 < i9) {
                        H b10 = C1191a0.b();
                        b bVar = new b(abstractC7292g, inetAddress, j9, null);
                        this.f54194e = inetAddress;
                        this.f54184E = j9;
                        this.f54185F = abstractC7292g;
                        this.f54186G = i9;
                        this.f54187H = i10;
                        this.f54188I = i11;
                        this.f54189J = 2;
                        if (AbstractC1204h.g(b10, bVar, this) == f9) {
                            return f9;
                        }
                        int i15 = i11;
                        inetAddress2 = inetAddress;
                        i13 = i15;
                        AbstractC7292g abstractC7292g4 = abstractC7292g;
                        map = j9;
                        i12 = i10;
                        abstractC7292g2 = abstractC7292g4;
                        this.f54194e = inetAddress2;
                        this.f54184E = map;
                        this.f54185F = abstractC7292g2;
                        this.f54186G = i9;
                        this.f54187H = i12;
                        this.f54188I = i13;
                        this.f54189J = 3;
                        if (W.a(i12, this) == f9) {
                            return f9;
                        }
                        AbstractC7292g abstractC7292g322 = abstractC7292g2;
                        i10 = i12;
                        j9 = map;
                        abstractC7292g = abstractC7292g322;
                        InetAddress inetAddress322 = inetAddress2;
                        i11 = i13 + 1;
                        inetAddress = inetAddress322;
                        if (i11 < i9) {
                        }
                    }
                    this.f54192M.f54158l = null;
                    return C6709J.f49946a;
                }
                AbstractC6732u.b(obj);
                g9 = obj;
            }
            AbstractC7780t.e(g9, "withContext(...)");
            inetAddress = (InetAddress) g9;
            j9 = S.j(AbstractC6736y.a("MAN", "\"ssdp:discover\""), AbstractC6736y.a("MX", String.valueOf(this.f54190K)), AbstractC6736y.a("ST", "ssdp:all"), AbstractC6736y.a("HOST", "239.255.255.250:1900"));
            AbstractC7292g.f54145n.a(a.f54195b);
            i9 = this.f54191L;
            i10 = this.f54193N;
            abstractC7292g = this.f54192M;
            i11 = 0;
            if (i11 < i9) {
            }
            this.f54192M.f54158l = null;
            return C6709J.f49946a;
        }
    }

    public static final class p extends AbstractC7781u implements v7.l {

        public static final p f54202b = new p();

        p() {
            super(1);
        }

        @Override
        public final CharSequence h(Map.Entry entry) {
            AbstractC7780t.f(entry, "<name for destructuring parameter 0>");
            return ((String) entry.getKey()) + ": " + ((String) entry.getValue());
        }
    }

    static {
        d dVar = new d(null);
        f54145n = dVar;
        dVar.c("LCG", "1");
    }

    public AbstractC7292g(Context context) {
        NetworkInterface networkInterface;
        Inet4Address inet4Address;
        SocketException e9;
        boolean D8;
        boolean D9;
        AbstractC7780t.f(context, "ctx");
        this.f54147a = context;
        Object systemService = context.getApplicationContext().getSystemService("wifi");
        AbstractC7780t.d(systemService, "null cannot be cast to non-null type android.net.wifi.WifiManager");
        this.f54148b = (WifiManager) systemService;
        this.f54149c = new n();
        this.f54152f = new HashSet();
        this.f54153g = new HashSet();
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            networkInterface = null;
            inet4Address = null;
            while (networkInterfaces.hasMoreElements()) {
                try {
                    NetworkInterface nextElement = networkInterfaces.nextElement();
                    Iterator<InterfaceAddress> it = nextElement.getInterfaceAddresses().iterator();
                    while (it.hasNext()) {
                        InetAddress address = it.next().getAddress();
                        if (!address.isLoopbackAddress() && (address instanceof Inet4Address)) {
                            String name = nextElement.getName();
                            AbstractC7780t.c(name);
                            String lowerCase = name.toLowerCase(Locale.ROOT);
                            AbstractC7780t.e(lowerCase, "toLowerCase(...)");
                            AbstractC7780t.c(lowerCase);
                            D8 = w.D(lowerCase, "wlan", false, 2, null);
                            if (!D8) {
                                AbstractC7780t.c(lowerCase);
                                D9 = w.D(lowerCase, "eth", false, 2, null);
                                if (!D9) {
                                    continue;
                                } else if (networkInterface != null) {
                                    continue;
                                }
                            }
                            try {
                                inet4Address = (Inet4Address) address;
                                networkInterface = nextElement;
                            } catch (SocketException e10) {
                                e9 = e10;
                                networkInterface = nextElement;
                                f54145n.a(new a(e9));
                                if (networkInterface != null) {
                                }
                                throw new IOException("No usable network interface and/or addresses available");
                            }
                        }
                    }
                } catch (SocketException e11) {
                    e9 = e11;
                }
            }
        } catch (SocketException e12) {
            networkInterface = null;
            inet4Address = null;
            e9 = e12;
        }
        if (networkInterface != null || inet4Address == null) {
            throw new IOException("No usable network interface and/or addresses available");
        }
        InetSocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getByName("239.255.255.250"), 1900);
        MulticastSocket multicastSocket = new MulticastSocket(1900);
        multicastSocket.setReuseAddress(true);
        multicastSocket.setReceiveBufferSize(32768);
        multicastSocket.joinGroup(inetSocketAddress, networkInterface);
        this.f54157k = multicastSocket;
        Thread b9 = AbstractC7026a.b(false, false, null, "SSDP", 0, new b(this), 22, null);
        this.f54155i = b9;
        MulticastSocket multicastSocket2 = new MulticastSocket(new InetSocketAddress(inet4Address, 0));
        multicastSocket2.setTimeToLive(4);
        multicastSocket2.setReceiveBufferSize(262144);
        this.f54156j = multicastSocket2;
        Thread b10 = AbstractC7026a.b(false, false, null, "Datagram IO", 0, new c(this), 22, null);
        this.f54154h = b10;
        NetworkInfo q9 = q();
        if (q9 != null && q9.getType() == 1) {
            WifiManager.MulticastLock createMulticastLock = this.f54148b.createMulticastLock("DLNA");
            createMulticastLock.acquire();
            this.f54150d = createMulticastLock;
            WifiManager.WifiLock createWifiLock = this.f54148b.createWifiLock(3, getClass().getSimpleName());
            createWifiLock.acquire();
            this.f54151e = createWifiLock;
        }
        b9.start();
        b10.start();
    }

    public final void A(String str, String str2) {
        HashSet hashSet = this.f54153g;
        synchronized (hashSet) {
            if (hashSet.contains(str2)) {
                return;
            }
            hashSet.add(str2);
            AbstractC1208j.d(this.f54149c, null, N.f5061d, new m(str, str2, null), 1, null);
        }
    }

    public final void C(InetAddress inetAddress, int i9, Map map) {
        String c02;
        String str = PkPO.bhbRcihN + "\r\n";
        StringBuilder sb = new StringBuilder();
        sb.append(str);
        c02 = AbstractC6821C.c0(map.entrySet(), "\r\n", null, "\r\n\r\n", 0, null, p.f54202b, 26, null);
        sb.append(c02);
        String sb2 = sb.toString();
        Charset charset = StandardCharsets.US_ASCII;
        AbstractC7780t.e(charset, "US_ASCII");
        byte[] bytes = sb2.getBytes(charset);
        AbstractC7780t.e(bytes, "getBytes(...)");
        this.f54156j.send(new DatagramPacket(bytes, bytes.length, inetAddress, i9));
    }

    public final void n(C7291f c7291f) {
        f54145n.a(new f(c7291f));
        synchronized (this.f54152f) {
            this.f54152f.add(c7291f);
        }
        u(c7291f);
    }

    public final C7291f p(String str, String str2, byte[] bArr, String str3) {
        String P02;
        Object s02;
        C7289d c7289d = new C7289d(new ByteArrayInputStream(bArr), str3, true);
        C7289d.c a9 = c7289d.a();
        if (!AbstractC7780t.a(a9 != null ? a9.j() : null, "root")) {
            a9 = null;
        }
        if (a9 == null) {
            StringBuilder sb = new StringBuilder();
            sb.append("Root element name is not <root>: ");
            C7289d.c a10 = c7289d.a();
            sb.append(a10 != null ? a10.j() : null);
            throw new IllegalStateException(sb.toString().toString());
        }
        String e9 = a9.e("URLBase");
        if (e9 == null) {
            e9 = Uri.parse(str2).buildUpon().path("").fragment("").clearQuery().toString();
            AbstractC7780t.e(e9, "toString(...)");
        }
        P02 = x.P0(e9, '/');
        List f9 = a9.f("device");
        if (f9 == null) {
            throw new IllegalStateException("No <device> element in <root>".toString());
        }
        s02 = AbstractC6821C.s0(f9);
        C7289d.c cVar = (C7289d.c) s02;
        if (cVar != null) {
            return C7291f.f54094i.a(cVar, str, P02);
        }
        throw new IllegalStateException("Found multiple <device> elements in <root>".toString());
    }

    private final NetworkInfo q() {
        ConnectivityManager connectivityManager = (ConnectivityManager) this.f54147a.getSystemService("connectivity");
        if (connectivityManager == null) {
            return null;
        }
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        if (!r(activeNetworkInfo)) {
            activeNetworkInfo = null;
        }
        if (activeNetworkInfo == null) {
            activeNetworkInfo = connectivityManager.getNetworkInfo(1);
            if (!r(activeNetworkInfo)) {
                activeNetworkInfo = null;
            }
            if (activeNetworkInfo == null) {
                activeNetworkInfo = connectivityManager.getNetworkInfo(0);
                if (!r(activeNetworkInfo)) {
                    activeNetworkInfo = null;
                }
                if (activeNetworkInfo == null) {
                    activeNetworkInfo = connectivityManager.getNetworkInfo(6);
                    if (!r(activeNetworkInfo)) {
                        activeNetworkInfo = null;
                    }
                    if (activeNetworkInfo == null) {
                        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(9);
                        if (r(networkInfo)) {
                            return networkInfo;
                        }
                        return null;
                    }
                }
            }
        }
        return activeNetworkInfo;
    }

    private static final boolean r(NetworkInfo networkInfo) {
        return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
    }

    public final C7291f s(String str) {
        Object obj;
        C7291f c7291f;
        synchronized (this.f54152f) {
            try {
                Iterator it = this.f54152f.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        obj = null;
                        break;
                    }
                    obj = it.next();
                    if (AbstractC7780t.a(((C7291f) obj).k(), str)) {
                        break;
                    }
                }
                c7291f = (C7291f) obj;
            } catch (Throwable th) {
                throw th;
            }
        }
        return c7291f;
    }

    public final void w() {
        x(this.f54156j, new h());
    }

    private final void x(MulticastSocket multicastSocket, r rVar) {
        List s02;
        try {
            byte[] bArr = new byte[640];
            while (!this.f54159m) {
                DatagramPacket datagramPacket = new DatagramPacket(bArr, 640);
                multicastSocket.receive(datagramPacket);
                Reader inputStreamReader = new InputStreamReader(new ByteArrayInputStream(datagramPacket.getData(), 0, datagramPacket.getLength()), C1160d.f4033b);
                BufferedReader bufferedReader = inputStreamReader instanceof BufferedReader ? (BufferedReader) inputStreamReader : new BufferedReader(inputStreamReader, 8192);
                try {
                    String readLine = bufferedReader.readLine();
                    if (readLine != null) {
                        AbstractC7780t.c(readLine);
                        e eVar = new e(bufferedReader);
                        Object k9 = eVar.k();
                        Object obj = (String) eVar.get("Location");
                        s02 = x.s0(readLine, new char[]{' '}, false, 0, 6, null);
                        String str = (String) s02.get(0);
                        if (k9 == null || obj == null) {
                            f54145n.a(new i(str));
                        } else {
                            rVar.k(str, eVar, k9, obj);
                        }
                        C6709J c6709j = C6709J.f49946a;
                    }
                    t7.c.a(bufferedReader, null);
                } catch (Throwable th) {
                    try {
                        throw th;
                    } catch (Throwable th2) {
                        t7.c.a(bufferedReader, th);
                        throw th2;
                    }
                }
            }
        } catch (SocketException unused) {
        } catch (Exception e9) {
            f54145n.a(new j(e9));
        }
    }

    public final void y() {
        x(this.f54157k, new k());
    }

    public final void z(String str) {
        synchronized (this.f54152f) {
            C7291f s9 = s(str);
            if (s9 != null) {
                f54145n.a(new l(s9));
                this.f54152f.remove(s9);
                v(s9);
                C6709J c6709j = C6709J.f49946a;
            }
        }
    }

    public final void B(int i9, int i10, int i11) {
        InterfaceC1230u0 d9;
        InterfaceC1230u0 interfaceC1230u0 = this.f54158l;
        if (interfaceC1230u0 != null) {
            InterfaceC1230u0.a.a(interfaceC1230u0, null, 1, null);
        }
        d9 = AbstractC1208j.d(this.f54149c, null, null, new o(i9, i10, this, i11, null), 3, null);
        this.f54158l = d9;
    }

    public final void o() {
        f54145n.a(C0844g.f54164b);
        M.d(this.f54149c, null, 1, null);
        this.f54156j.close();
        this.f54154h.interrupt();
        this.f54157k.close();
        this.f54155i.interrupt();
        WifiManager.MulticastLock multicastLock = this.f54150d;
        if (multicastLock != null && multicastLock.isHeld()) {
            multicastLock.release();
        }
        WifiManager.WifiLock wifiLock = this.f54151e;
        if (wifiLock != null && wifiLock.isHeld()) {
            wifiLock.release();
        }
        this.f54159m = true;
    }

    public final boolean t() {
        boolean z8;
        synchronized (this.f54153g) {
            z8 = !this.f54153g.isEmpty();
        }
        return z8;
    }

    public abstract void u(C7291f c7291f);

    public abstract void v(C7291f c7291f);
}