package com.netease.nimlib.d.f; import android.content.Context; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; import android.os.Build; import android.util.Log; import androidx.core.app.NotificationCompat; import com.health.doctor.networkhospital.exame.ExamSearchResultItem; import com.netease.nimlib.m.a.d.b; import com.netease.nimlib.push.e; import com.netease.nimlib.s.a.b; import com.netease.nimlib.s.a.c; import com.netease.nimlib.s.i; import com.sina.weibo.sdk.statistic.LogBuilder; import com.umeng.analytics.pro.ai; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Semaphore; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class a { /* renamed from: a reason: collision with root package name */ private static final String f8961a = c.b(b.TYPE_LOG); /* renamed from: b reason: collision with root package name */ private static final String f8962b = e.a(); /* renamed from: c reason: collision with root package name */ private static volatile int f8963c = 0; /* renamed from: d reason: collision with root package name */ private static volatile a f8964d = null; /* renamed from: e reason: collision with root package name */ private final Semaphore f8965e = new Semaphore(1); /* access modifiers changed from: private */ /* renamed from: com.netease.nimlib.d.f.a$a reason: collision with other inner class name */ public static class C0081a { /* renamed from: a reason: collision with root package name */ private final short f8966a; /* renamed from: b reason: collision with root package name */ private final String f8967b; /* renamed from: c reason: collision with root package name */ private final long f8968c; /* renamed from: d reason: collision with root package name */ private final String f8969d; /* renamed from: e reason: collision with root package name */ private final String f8970e; /* renamed from: f reason: collision with root package name */ private int f8971f; C0081a(short s, byte b2, byte b3) { this(s, com.netease.nimlib.c.k(), System.currentTimeMillis(), "" + ((int) b2), "" + ((int) b3), 1); } C0081a(short s, String str, long j, String str2, String str3, int i) { this.f8966a = s; String str4 = ""; this.f8967b = str == null ? str4 : str; this.f8968c = j; this.f8969d = str2 == null ? str4 : str2; this.f8970e = str3 != null ? str3 : str4; this.f8971f = i; } static C0081a a(JSONObject jSONObject) { return new C0081a((short) jSONObject.optInt("errorCode"), jSONObject.optString("accid"), jSONObject.optLong("timestamp"), jSONObject.optString(ai.f13736e), jSONObject.optString("file"), jSONObject.optInt(ExamSearchResultItem.KEY_COUNT)); } /* access modifiers changed from: package-private */ public int a() { return this.f8971f; } /* access modifiers changed from: package-private */ public void a(int i) { this.f8971f = i; } public String b() { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("errorCode", (int) this.f8966a); jSONObject.put("accid", this.f8967b); jSONObject.put("timestamp", this.f8968c); jSONObject.put(ai.f13736e, this.f8969d); jSONObject.put("file", this.f8970e); jSONObject.put(ExamSearchResultItem.KEY_COUNT, this.f8971f); } catch (JSONException e2) { e2.printStackTrace(); } return jSONObject.toString(); } /* access modifiers changed from: package-private */ public String c() { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("errorCode", (int) this.f8966a); jSONObject.put("accid", this.f8967b); jSONObject.put(ai.f13736e, this.f8969d); jSONObject.put("file", this.f8970e); return jSONObject.toString(); } catch (JSONException e2) { e2.printStackTrace(); return null; } } } private a() { e(); try { d(); } catch (IOException e2) { e2.printStackTrace(); } } public static a a() { if (f8964d == null) { synchronized (a.class) { if (f8964d == null) { f8964d = new a(); return f8964d; } } } return f8964d; } private static void a(b.a aVar) { if (f8963c == 0 && com.netease.nimlib.c.g().reportImLog) { f8963c = 1; JSONObject jSONObject = new JSONObject(); try { jSONObject.put("common", new JSONObject().put(ai.u, "IM").put("device_id", f8962b)).put(NotificationCompat.CATEGORY_EVENT, new JSONObject().put("deviceinfo", new JSONObject().put("app_key", com.netease.nimlib.c.f()).put("sdk_ver", "7.8.0").put(LogBuilder.KEY_PLATFORM, "Android").put("compat_id", b()).put("os_ver", Build.VERSION.RELEASE).put("manufacturer", Build.BRAND).put("model", Build.MODEL))); } catch (JSONException e2) { e2.printStackTrace(); } HashMap hashMap = new HashMap(); hashMap.put("Content-Type", "application/json"); com.netease.nimlib.m.a.d.b.a().a(com.netease.nimlib.c.d()); com.netease.nimlib.m.a.d.b.a().a("http://statistic.live.126.net/statics/report/common/form", hashMap, jSONObject.toString(), new g(aVar)); } } /* access modifiers changed from: private */ public static /* synthetic */ void a(b.a aVar, String str, int i, Throwable th) { f8963c = i == 200 ? 2 : 0; aVar.onResponse(str, i, th); } /* access modifiers changed from: private */ public /* synthetic */ void a(String str, int i, Throwable th) { if (i == 200) { f(); } this.f8965e.release(); } private boolean a(ConcurrentHashMap<String, C0081a> concurrentHashMap) { try { File d2 = d(); JSONArray jSONArray = new JSONArray(); for (String str : concurrentHashMap.keySet()) { C0081a aVar = concurrentHashMap.get(str); if (aVar != null) { jSONArray.put(new JSONObject(aVar.b())); } } d2.setWritable(true); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(d2)); outputStreamWriter.write(jSONArray.toString()); outputStreamWriter.flush(); outputStreamWriter.close(); return true; } catch (IOException e2) { e2.printStackTrace(); return false; } catch (JSONException e3) { e3.printStackTrace(); return false; } } private static String b() { String str = Build.BRAND + "#" + Build.BOARD + "#" + Build.MODEL; String c2 = c(); if (c2 == null || c2.isEmpty()) { return str; } return str + "#" + c2; } /* access modifiers changed from: private */ public /* synthetic */ void b(String str, int i, Throwable th) { String str2 = "@CJL/注册返回" + i; if (str == null) { str = ""; } Log.i(str2, str); if (i == 200) { g(); } } private boolean b(short s) { if (!com.netease.nimlib.c.g().reportImLog) { return false; } return s == 408 || s == 415 || s == 500; } private static String c() { UsbManager usbManager; Context d2 = com.netease.nimlib.c.d(); if (d2 == null || (usbManager = (UsbManager) d2.getSystemService("usb")) == null) { return ""; } UsbDevice usbDevice = null; for (UsbDevice usbDevice2 : usbManager.getDeviceList().values()) { int deviceClass = usbDevice2.getDeviceClass(); if (deviceClass == 239 || deviceClass == 14) { int interfaceCount = usbDevice2.getInterfaceCount(); int i = 0; while (true) { if (i >= interfaceCount) { break; } else if (usbDevice2.getInterface(i).getInterfaceClass() == 14) { usbDevice = usbDevice2; break; } else { i++; } } } } if (usbDevice == null) { return ""; } return usbDevice.getVendorId() + ":" + usbDevice.getProductId(); } private File d() throws IOException { File file = new File(f8961a, "IMLogMsg.log"); if (!file.exists()) { com.netease.nimlib.k.b.a.a.b(f8961a, "IMLogMsg.log"); file.createNewFile(); file.setReadable(true); file.setWritable(true); } return file; } private void e() { File file = new File(f8961a, "JsonBody.log"); if (file.exists()) { file.delete(); } } private void f() { com.netease.nimlib.k.a.a(); } private void g() { if (!k() && this.f8965e.tryAcquire()) { com.netease.nimlib.m.a.d.b.a().a(com.netease.nimlib.c.d()); com.netease.nimlib.m.a.d.b.a().a("http://statistic.live.126.net/statics/report/common/form", h(), i(), new h(this)); } } private Map<String, String> h() { HashMap hashMap = new HashMap(); hashMap.put("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryyEePCbPKpBvrs9OE"); return hashMap; } private byte[] i() { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); StringBuilder sb = new StringBuilder(); sb.append("------WebKitFormBoundaryyEePCbPKpBvrs9OE"); sb.append("\r\n"); sb.append("Content-Disposition: form-data; name=\"reporterHeader\""); sb.append("\r\n"); sb.append("\r\n"); String a2 = com.netease.nimlib.k.a.a(true); File file = new File(a2); JSONObject jSONObject = new JSONObject(); try { jSONObject.put("common", new JSONObject().put(ai.u, "IM").put("device_id", f8962b)).put(NotificationCompat.CATEGORY_EVENT, new JSONObject().put("logReport", new JSONObject().put("fileMD5", i.b(a2)).put("errorList", m()))); } catch (JSONException e2) { e2.printStackTrace(); } catch (Throwable th) { sb.append(jSONObject.toString()); sb.append("\r\n"); throw th; } sb.append(jSONObject.toString()); sb.append("\r\n"); sb.append("------WebKitFormBoundaryyEePCbPKpBvrs9OE"); sb.append("\r\n"); sb.append("Content-Disposition: form-data; name=\"logReport\"; filename=\""); sb.append(l()); sb.append("\""); sb.append("\r\n"); sb.append("Content-Type: application/octet-stream"); sb.append("\r\n"); sb.append("\r\n"); byte[] bArr = null; try { byteArrayOutputStream.write(sb.toString().getBytes()); FileInputStream fileInputStream = new FileInputStream(file); byte[] bArr2 = new byte[4096]; while (fileInputStream.read(bArr2) != -1) { byteArrayOutputStream.write(bArr2); } byteArrayOutputStream.write("\r\n------WebKitFormBoundaryyEePCbPKpBvrs9OE--".getBytes()); bArr = byteArrayOutputStream.toByteArray(); byteArrayOutputStream.flush(); byteArrayOutputStream.close(); fileInputStream.close(); } catch (IOException e3) { e3.printStackTrace(); } file.delete(); return bArr == null ? new byte[0] : bArr; } private ConcurrentHashMap<String, C0081a> j() { JSONArray m = m(); ConcurrentHashMap<String, C0081a> concurrentHashMap = new ConcurrentHashMap<>(); for (int i = 0; i < m.length(); i++) { Object opt = m.opt(i); if (opt instanceof JSONObject) { C0081a a2 = C0081a.a((JSONObject) opt); concurrentHashMap.put(a2.c(), a2); } } return concurrentHashMap; } private boolean k() { return m().length() == 0; } private String l() { return "logs_" + new SimpleDateFormat("yyyyMMddhhmm", Locale.CHINA).format(new Date()) + ".zip"; } private JSONArray m() { try { BufferedReader bufferedReader = new BufferedReader(new FileReader(d())); StringBuilder sb = new StringBuilder(); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } sb.append(readLine); } String sb2 = sb.toString(); return sb2.isEmpty() ? new JSONArray() : new JSONArray(sb2); } catch (FileNotFoundException e2) { e2.printStackTrace(); Log.e("@CJL/文件不存在", e2.getMessage()); return new JSONArray(); } catch (IOException e3) { e3.printStackTrace(); Log.e("@CJL/读写异常", e3.getMessage()); return new JSONArray(); } catch (JSONException e4) { e4.printStackTrace(); Log.e("@CJL/字符串转JSONArray异常", e4.getMessage()); return new JSONArray(); } } public void a(com.netease.nimlib.d.d.a aVar) { a(aVar.r(), aVar.j().i(), aVar.j().j()); } public void a(short s) { if (s == 200) { int i = f8963c; if (i == 0) { a(new f(this)); } else if (i != 1 && i == 2) { g(); } } } public void a(short s, byte b2, byte b3) { if (b(s)) { ConcurrentHashMap<String, C0081a> j = j(); C0081a aVar = new C0081a(s, b2, b3); String c2 = aVar.c(); C0081a aVar2 = j.get(aVar.c()); if (aVar2 == null) { j.put(c2, aVar); } else { aVar.a(aVar2.a() + aVar.a()); j.replace(c2, aVar); } a(j); } } }