package com.xiaomi.push; import android.text.TextUtils; import com.coloros.mcssdk.mode.CommandMessage; import com.google.android.exoplayer2.text.ttml.TtmlNode; import com.umeng.socialize.net.dplus.CommonNetImpl; import com.xiaomi.channel.commonutils.logger.b; import com.xiaomi.push.hd; import com.xiaomi.push.hh; import com.xiaomi.push.hj; import com.xiaomi.push.service.al; import com.xiaomi.push.service.au; import com.xiaomi.push.service.e; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.io.PrintStream; 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 hn { /* renamed from: a reason: collision with root package name */ private static XmlPullParser f6756a; public static hc a(String str, String str2, XmlPullParser xmlPullParser) { Object a2 = hm.a().m3354a("all", "xm:chat"); if (a2 == null || !(a2 instanceof e)) { return null; } return ((e) a2).b(xmlPullParser); } public static hd a(XmlPullParser xmlPullParser, go goVar) { String attributeValue = xmlPullParser.getAttributeValue("", "id"); String attributeValue2 = xmlPullParser.getAttributeValue("", "to"); String attributeValue3 = xmlPullParser.getAttributeValue("", "from"); String attributeValue4 = xmlPullParser.getAttributeValue("", "chid"); hd.a a2 = hd.a.a(xmlPullParser.getAttributeValue("", "type")); HashMap hashMap = new HashMap(); boolean z = false; for (int i = 0; i < xmlPullParser.getAttributeCount(); i++) { String attributeName = xmlPullParser.getAttributeName(i); hashMap.put(attributeName, xmlPullParser.getAttributeValue("", attributeName)); } hd hdVar = null; hj hjVar = null; while (!z) { int next = xmlPullParser.next(); if (next == 2) { String name = xmlPullParser.getName(); String namespace = xmlPullParser.getNamespace(); if (name.equals("error")) { hjVar = m3358a(xmlPullParser); } else { hdVar = new hd(); hdVar.a(a(name, namespace, xmlPullParser)); } } else if (next == 3 && xmlPullParser.getName().equals("iq")) { z = true; } } if (hdVar == null) { if (hd.a.f6746a == a2 || hd.a.b == a2) { ho hoVar = new ho(); hoVar.k(attributeValue); hoVar.m(attributeValue3); hoVar.n(attributeValue2); hoVar.a(hd.a.d); hoVar.l(attributeValue4); hoVar.a(new hj(hj.a.e)); goVar.a(hoVar); b.d("iq usage error. send packet in packet parser."); return null; } hdVar = new hp(); } hdVar.k(attributeValue); hdVar.m(attributeValue2); hdVar.l(attributeValue4); hdVar.n(attributeValue3); hdVar.a(a2); hdVar.a(hjVar); hdVar.a(hashMap); return hdVar; } public static hf a(XmlPullParser xmlPullParser) { String str; boolean z = false; String str2 = null; if ("1".equals(xmlPullParser.getAttributeValue("", "s"))) { 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"); al.b a2 = al.a().a(attributeValue, attributeValue4); if (a2 == null) { a2 = al.a().a(attributeValue, attributeValue3); } if (a2 != null) { hf hfVar = null; while (!z) { int next = xmlPullParser.next(); if (next == 2) { if (!"s".equals(xmlPullParser.getName())) { throw new gz("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)) { he heVar = new he(); heVar.l(attributeValue); heVar.b(true); heVar.n(attributeValue3); heVar.m(attributeValue4); heVar.k(attributeValue2); heVar.f(attributeValue5); hc hcVar = new hc("s", null, null, null); hcVar.m3342a(text); heVar.a(hcVar); return heVar; } a(au.a(au.a(a2.h, attributeValue2), text)); f6756a.next(); hfVar = a(f6756a); } else { throw new gz("error while receiving a encrypted message with wrong format"); } } else if (next == 3 && xmlPullParser.getName().equals("message")) { z = true; } } if (hfVar != null) { return hfVar; } throw new gz("error while receiving a encrypted message with wrong format"); } throw new gz("the channel id is wrong while receiving a encrypted message"); } he heVar2 = new he(); String attributeValue6 = xmlPullParser.getAttributeValue("", "id"); if (attributeValue6 == null) { attributeValue6 = "ID_NOT_AVAILABLE"; } heVar2.k(attributeValue6); heVar2.m(xmlPullParser.getAttributeValue("", "to")); heVar2.n(xmlPullParser.getAttributeValue("", "from")); heVar2.l(xmlPullParser.getAttributeValue("", "chid")); heVar2.a(xmlPullParser.getAttributeValue("", "appid")); try { str = xmlPullParser.getAttributeValue("", "transient"); } catch (Exception unused) { str = null; } try { String attributeValue7 = xmlPullParser.getAttributeValue("", "seq"); if (!TextUtils.isEmpty(attributeValue7)) { heVar2.b(attributeValue7); } } catch (Exception unused2) { } try { String attributeValue8 = xmlPullParser.getAttributeValue("", "mseq"); if (!TextUtils.isEmpty(attributeValue8)) { heVar2.c(attributeValue8); } } catch (Exception unused3) { } try { String attributeValue9 = xmlPullParser.getAttributeValue("", "fseq"); if (!TextUtils.isEmpty(attributeValue9)) { heVar2.d(attributeValue9); } } catch (Exception unused4) { } try { String attributeValue10 = xmlPullParser.getAttributeValue("", "status"); if (!TextUtils.isEmpty(attributeValue10)) { heVar2.e(attributeValue10); } } catch (Exception unused5) { } heVar2.a(!TextUtils.isEmpty(str) && str.equalsIgnoreCase("true")); heVar2.f(xmlPullParser.getAttributeValue("", "type")); String b = b(xmlPullParser); if (b == null || "".equals(b.trim())) { hf.q(); } else { heVar2.j(b); } while (!z) { 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")) { b(xmlPullParser); heVar2.g(m3359a(xmlPullParser)); } else if (name.equals(TtmlNode.TAG_BODY)) { String attributeValue11 = xmlPullParser.getAttributeValue("", "encode"); String a3 = m3359a(xmlPullParser); if (!TextUtils.isEmpty(attributeValue11)) { heVar2.a(a3, attributeValue11); } else { heVar2.h(a3); } } else if (name.equals("thread")) { if (str2 == null) { str2 = xmlPullParser.nextText(); } } else if (name.equals("error")) { heVar2.a(m3358a(xmlPullParser)); } else { heVar2.a(a(name, namespace, xmlPullParser)); } } else if (next2 == 3 && xmlPullParser.getName().equals("message")) { z = true; } } heVar2.i(str2); return heVar2; } /* renamed from: a reason: collision with other method in class */ public static hh m3356a(XmlPullParser xmlPullParser) { hh.b bVar = hh.b.available; String attributeValue = xmlPullParser.getAttributeValue("", "type"); if (attributeValue != null && !attributeValue.equals("")) { try { bVar = hh.b.valueOf(attributeValue); } catch (IllegalArgumentException unused) { PrintStream printStream = System.err; printStream.println("Found invalid presence type " + attributeValue); } } hh hhVar = new hh(bVar); hhVar.m(xmlPullParser.getAttributeValue("", "to")); hhVar.n(xmlPullParser.getAttributeValue("", "from")); hhVar.l(xmlPullParser.getAttributeValue("", "chid")); String attributeValue2 = xmlPullParser.getAttributeValue("", "id"); if (attributeValue2 == null) { attributeValue2 = "ID_NOT_AVAILABLE"; } hhVar.k(attributeValue2); boolean z = false; while (!z) { int next = xmlPullParser.next(); if (next == 2) { String name = xmlPullParser.getName(); String namespace = xmlPullParser.getNamespace(); if (name.equals("status")) { hhVar.a(xmlPullParser.nextText()); } else if (name.equals("priority")) { try { hhVar.a(Integer.parseInt(xmlPullParser.nextText())); } catch (NumberFormatException unused2) { } catch (IllegalArgumentException unused3) { hhVar.a(0); } } else if (name.equals("show")) { String nextText = xmlPullParser.nextText(); try { hhVar.a(hh.a.valueOf(nextText)); } catch (IllegalArgumentException unused4) { PrintStream printStream2 = System.err; printStream2.println("Found invalid presence mode " + nextText); } } else if (name.equals("error")) { hhVar.a(m3358a(xmlPullParser)); } else { hhVar.a(a(name, namespace, xmlPullParser)); } } else if (next == 3 && xmlPullParser.getName().equals("presence")) { z = true; } } return hhVar; } /* renamed from: a reason: collision with other method in class */ public static hi m3357a(XmlPullParser xmlPullParser) { hi hiVar = null; boolean z = false; while (!z) { int next = xmlPullParser.next(); if (next == 2) { hiVar = new hi(xmlPullParser.getName()); } else if (next == 3 && xmlPullParser.getName().equals("error")) { z = true; } } return hiVar; } /* renamed from: a reason: collision with other method in class */ public static hj m3358a(XmlPullParser xmlPullParser) { ArrayList arrayList = new ArrayList(); boolean z = false; String str = null; String str2 = null; String str3 = "-1"; for (int i = 0; i < xmlPullParser.getAttributeCount(); i++) { if (xmlPullParser.getAttributeName(i).equals(CommandMessage.CODE)) { str3 = xmlPullParser.getAttributeValue("", CommandMessage.CODE); } if (xmlPullParser.getAttributeName(i).equals("type")) { str = xmlPullParser.getAttributeValue("", "type"); } if (xmlPullParser.getAttributeName(i).equals("reason")) { str2 = xmlPullParser.getAttributeValue("", "reason"); } } String str4 = null; String str5 = null; while (!z) { 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")) { z = true; } } else if (next == 4) { str5 = xmlPullParser.getText(); } } return new hj(Integer.parseInt(str3), str == null ? CommonNetImpl.CANCEL : str, str2, str4, str5, arrayList); } /* renamed from: a reason: collision with other method in class */ private static String m3359a(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 a(byte[] bArr) { if (f6756a == null) { try { f6756a = XmlPullParserFactory.newInstance().newPullParser(); f6756a.setFeature("http://xmlpull.org/v1/doc/features.html#process-namespaces", true); } catch (XmlPullParserException e) { e.printStackTrace(); } } f6756a.setInput(new InputStreamReader(new ByteArrayInputStream(bArr))); } private static String b(XmlPullParser xmlPullParser) { for (int i = 0; i < xmlPullParser.getAttributeCount(); i++) { String attributeName = xmlPullParser.getAttributeName(i); if ("xml:lang".equals(attributeName) || ("lang".equals(attributeName) && "xml".equals(xmlPullParser.getAttributePrefix(i)))) { return xmlPullParser.getAttributeValue(i); } } return null; } }