package eg; import ag.c; import android.text.TextUtils; import com.huawei.hms.support.hianalytics.HiAnalyticsConstant; import com.meizu.cloud.pushsdk.constants.PushConstants; import com.meizu.cloud.pushsdk.notification.model.NotifyType; import com.xiaomi.push.service.f2; import com.xiaomi.push.service.i0; import com.xiaomi.push.service.r0; import eg.b6; import eg.d6; import eg.x5; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; public class h6 { /* renamed from: a reason: collision with root package name */ private static XmlPullParser f14851a; public static w5 a(String str, String str2, XmlPullParser xmlPullParser) { Object b10 = g6.a().b("all", "xm:chat"); if (b10 == null || !(b10 instanceof f2)) { return null; } return ((f2) b10).c(xmlPullParser); } public static x5 b(XmlPullParser xmlPullParser, h5 h5Var) { String attributeValue = xmlPullParser.getAttributeValue("", "id"); String attributeValue2 = xmlPullParser.getAttributeValue("", "to"); String attributeValue3 = xmlPullParser.getAttributeValue("", "from"); String attributeValue4 = xmlPullParser.getAttributeValue("", "chid"); x5.a a10 = x5.a.a(xmlPullParser.getAttributeValue("", "type")); HashMap hashMap = new HashMap(); boolean z10 = false; for (int i10 = 0; i10 < xmlPullParser.getAttributeCount(); i10++) { String attributeName = xmlPullParser.getAttributeName(i10); hashMap.put(attributeName, xmlPullParser.getAttributeValue("", attributeName)); } x5 x5Var = null; d6 d6Var = null; while (!z10) { int next = xmlPullParser.next(); if (next == 2) { String name = xmlPullParser.getName(); String namespace = xmlPullParser.getNamespace(); if (name.equals("error")) { d6Var = f(xmlPullParser); } else { x5Var = new x5(); x5Var.h(a(name, namespace, xmlPullParser)); } } else if (next == 3 && xmlPullParser.getName().equals("iq")) { z10 = true; } } if (x5Var == null) { if (x5.a.f15635b == a10 || x5.a.f15636c == a10) { i6 i6Var = new i6(); i6Var.n(attributeValue); i6Var.r(attributeValue3); i6Var.t(attributeValue2); i6Var.z(x5.a.f15638e); i6Var.p(attributeValue4); i6Var.i(new d6(d6.a.f14596f)); h5Var.l(i6Var); c.u("iq usage error. send packet in packet parser."); return null; } x5Var = new j6(); } x5Var.n(attributeValue); x5Var.r(attributeValue2); x5Var.p(attributeValue4); x5Var.t(attributeValue3); x5Var.z(a10); x5Var.i(d6Var); x5Var.A(hashMap); return x5Var; } public static z5 c(XmlPullParser xmlPullParser) { String str; boolean z10 = false; String str2 = null; if (PushConstants.PUSH_TYPE_THROUGH_MESSAGE.equals(xmlPullParser.getAttributeValue("", NotifyType.SOUND))) { String attributeValue = xmlPullParser.getAttributeValue("", "chid"); String attributeValue2 = xmlPullParser.getAttributeValue("", "id"); String attributeValue3 = xmlPullParser.getAttributeValue("", "from"); String attributeValue4 = xmlPullParser.getAttributeValue("", "to"); String attributeValue5 = xmlPullParser.getAttributeValue("", "type"); i0.b b10 = i0.c().b(attributeValue, attributeValue4); if (b10 == null) { b10 = i0.c().b(attributeValue, attributeValue3); } if (b10 != null) { z5 z5Var = null; while (!z10) { int next = xmlPullParser.next(); if (next == 2) { if (!NotifyType.SOUND.equals(xmlPullParser.getName())) { throw new t5("error while receiving a encrypted message with wrong format"); } else if (xmlPullParser.next() == 4) { String text = xmlPullParser.getText(); if ("5".equals(attributeValue) || "6".equals(attributeValue)) { y5 y5Var = new y5(); y5Var.p(attributeValue); y5Var.D(true); y5Var.t(attributeValue3); y5Var.r(attributeValue4); y5Var.n(attributeValue2); y5Var.L(attributeValue5); w5 w5Var = new w5(NotifyType.SOUND, null, null, null); w5Var.g(text); y5Var.h(w5Var); return y5Var; } h(r0.h(r0.g(b10.f12895i, attributeValue2), text)); f14851a.next(); z5Var = c(f14851a); } else { throw new t5("error while receiving a encrypted message with wrong format"); } } else if (next == 3 && xmlPullParser.getName().equals("message")) { z10 = true; } } if (z5Var != null) { return z5Var; } throw new t5("error while receiving a encrypted message with wrong format"); } throw new t5("the channel id is wrong while receiving a encrypted message"); } y5 y5Var2 = new y5(); String attributeValue6 = xmlPullParser.getAttributeValue("", "id"); if (attributeValue6 == null) { attributeValue6 = "ID_NOT_AVAILABLE"; } y5Var2.n(attributeValue6); y5Var2.r(xmlPullParser.getAttributeValue("", "to")); y5Var2.t(xmlPullParser.getAttributeValue("", "from")); y5Var2.p(xmlPullParser.getAttributeValue("", "chid")); y5Var2.y(xmlPullParser.getAttributeValue("", HiAnalyticsConstant.HaKey.BI_KEY_APPID)); try { str = xmlPullParser.getAttributeValue("", "transient"); } catch (Exception unused) { str = null; } try { String attributeValue7 = xmlPullParser.getAttributeValue("", "seq"); if (!TextUtils.isEmpty(attributeValue7)) { y5Var2.C(attributeValue7); } } catch (Exception unused2) { } try { String attributeValue8 = xmlPullParser.getAttributeValue("", "mseq"); if (!TextUtils.isEmpty(attributeValue8)) { y5Var2.F(attributeValue8); } } catch (Exception unused3) { } try { String attributeValue9 = xmlPullParser.getAttributeValue("", "fseq"); if (!TextUtils.isEmpty(attributeValue9)) { y5Var2.H(attributeValue9); } } catch (Exception unused4) { } try { String attributeValue10 = xmlPullParser.getAttributeValue("", "status"); if (!TextUtils.isEmpty(attributeValue10)) { y5Var2.J(attributeValue10); } } catch (Exception unused5) { } y5Var2.A(!TextUtils.isEmpty(str) && str.equalsIgnoreCase("true")); y5Var2.L(xmlPullParser.getAttributeValue("", "type")); String i10 = i(xmlPullParser); if (i10 == null || "".equals(i10.trim())) { z5.x(); } else { y5Var2.R(i10); } while (!z10) { int next2 = xmlPullParser.next(); if (next2 == 2) { String name = xmlPullParser.getName(); String namespace = xmlPullParser.getNamespace(); if (TextUtils.isEmpty(namespace)) { namespace = "xm"; } if (name.equals("subject")) { i(xmlPullParser); y5Var2.N(g(xmlPullParser)); } else if (name.equals("body")) { String attributeValue11 = xmlPullParser.getAttributeValue("", "encode"); String g10 = g(xmlPullParser); if (!TextUtils.isEmpty(attributeValue11)) { y5Var2.z(g10, attributeValue11); } else { y5Var2.P(g10); } } else if (name.equals("thread")) { if (str2 == null) { str2 = xmlPullParser.nextText(); } } else if (name.equals("error")) { y5Var2.i(f(xmlPullParser)); } else { y5Var2.h(a(name, namespace, xmlPullParser)); } } else if (next2 == 3 && xmlPullParser.getName().equals("message")) { z10 = true; } } y5Var2.Q(str2); return y5Var2; } public static b6 d(XmlPullParser xmlPullParser) { b6.b bVar = b6.b.available; String attributeValue = xmlPullParser.getAttributeValue("", "type"); if (attributeValue != null && !attributeValue.equals("")) { try { bVar = b6.b.valueOf(attributeValue); } catch (IllegalArgumentException unused) { System.err.println("Found invalid presence type " + attributeValue); } } b6 b6Var = new b6(bVar); b6Var.r(xmlPullParser.getAttributeValue("", "to")); b6Var.t(xmlPullParser.getAttributeValue("", "from")); b6Var.p(xmlPullParser.getAttributeValue("", "chid")); String attributeValue2 = xmlPullParser.getAttributeValue("", "id"); if (attributeValue2 == null) { attributeValue2 = "ID_NOT_AVAILABLE"; } b6Var.n(attributeValue2); boolean z10 = false; while (!z10) { int next = xmlPullParser.next(); if (next == 2) { String name = xmlPullParser.getName(); String namespace = xmlPullParser.getNamespace(); if (name.equals("status")) { b6Var.B(xmlPullParser.nextText()); } else if (name.equals("priority")) { try { b6Var.y(Integer.parseInt(xmlPullParser.nextText())); } catch (NumberFormatException unused2) { } catch (IllegalArgumentException unused3) { b6Var.y(0); } } else if (name.equals("show")) { String nextText = xmlPullParser.nextText(); try { b6Var.z(b6.a.valueOf(nextText)); } catch (IllegalArgumentException unused4) { System.err.println("Found invalid presence mode " + nextText); } } else if (name.equals("error")) { b6Var.i(f(xmlPullParser)); } else { b6Var.h(a(name, namespace, xmlPullParser)); } } else if (next == 3 && xmlPullParser.getName().equals("presence")) { z10 = true; } } return b6Var; } public static c6 e(XmlPullParser xmlPullParser) { c6 c6Var = null; boolean z10 = false; while (!z10) { int next = xmlPullParser.next(); if (next == 2) { c6Var = new c6(xmlPullParser.getName()); } else if (next == 3 && xmlPullParser.getName().equals("error")) { z10 = true; } } return c6Var; } public static d6 f(XmlPullParser xmlPullParser) { ArrayList arrayList = new ArrayList(); boolean z10 = false; String str = "-1"; String str2 = null; String str3 = null; for (int i10 = 0; i10 < xmlPullParser.getAttributeCount(); i10++) { if (xmlPullParser.getAttributeName(i10).equals(PushConstants.BASIC_PUSH_STATUS_CODE)) { str = xmlPullParser.getAttributeValue("", PushConstants.BASIC_PUSH_STATUS_CODE); } if (xmlPullParser.getAttributeName(i10).equals("type")) { str3 = xmlPullParser.getAttributeValue("", "type"); } if (xmlPullParser.getAttributeName(i10).equals("reason")) { str2 = xmlPullParser.getAttributeValue("", "reason"); } } String str4 = null; String str5 = null; while (!z10) { int next = xmlPullParser.next(); if (next == 2) { if (xmlPullParser.getName().equals("text")) { str5 = xmlPullParser.nextText(); } else { String name = xmlPullParser.getName(); String namespace = xmlPullParser.getNamespace(); if ("urn:ietf:params:xml:ns:xmpp-stanzas".equals(namespace)) { str4 = name; } else { arrayList.add(a(name, namespace, xmlPullParser)); } } } else if (next == 3) { if (xmlPullParser.getName().equals("error")) { z10 = true; } } else if (next == 4) { str5 = xmlPullParser.getText(); } } return new d6(Integer.parseInt(str), str3 == null ? "cancel" : str3, str2, str4, str5, arrayList); } private static String g(XmlPullParser xmlPullParser) { int depth = xmlPullParser.getDepth(); String str = ""; while (true) { if (xmlPullParser.next() == 3 && xmlPullParser.getDepth() == depth) { return str; } str = str + xmlPullParser.getText(); } } private static void h(byte[] bArr) { if (f14851a == null) { try { XmlPullParser newPullParser = XmlPullParserFactory.newInstance().newPullParser(); f14851a = newPullParser; newPullParser.setFeature("http://xmlpull.org/v1/doc/features.html#process-namespaces", true); } catch (XmlPullParserException e10) { e10.printStackTrace(); } } f14851a.setInput(new InputStreamReader(new ByteArrayInputStream(bArr))); } private static String i(XmlPullParser xmlPullParser) { for (int i10 = 0; i10 < xmlPullParser.getAttributeCount(); i10++) { String attributeName = xmlPullParser.getAttributeName(i10); if ("xml:lang".equals(attributeName) || ("lang".equals(attributeName) && "xml".equals(xmlPullParser.getAttributePrefix(i10)))) { return xmlPullParser.getAttributeValue(i10); } } return null; } }