package cn.jiguang.ao; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.graphics.Point; import android.os.Build; import android.os.Environment; import android.os.StatFs; import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.Display; import cn.jiguang.an.b; import com.baidu.speech.asr.SpeechConstant; import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileReader; import java.util.Locale; import java.util.TimeZone; import org.json.JSONException; import org.json.JSONObject; public class a { private static String a = ""; private static String b = ""; private static final FileFilter c = new FileFilter() { /* class cn.jiguang.ao.a.AnonymousClass1 */ public boolean accept(File file) { String name = file.getName(); if (!name.startsWith("cpu")) { return false; } for (int i = 3; i < name.length(); i++) { if (name.charAt(i) < '0' || name.charAt(i) > '9') { return false; } } return true; } }; private static int a(String str, FileInputStream fileInputStream) { byte[] bArr = new byte[1024]; try { int read = fileInputStream.read(bArr); int i = 0; while (i < read) { if (bArr[i] == 10 || i == 0) { if (bArr[i] == 10) { i++; } int i2 = i; while (true) { if (i2 >= read) { continue; break; } int i3 = i2 - i; if (bArr[i2] != str.charAt(i3)) { break; } else if (i3 == str.length() - 1) { return a(bArr, i2); } else { i2++; } } } i++; } return -1; } catch (Throwable unused) { return -1; } } private static int a(byte[] bArr, int i) { while (i < bArr.length && bArr[i] != 10) { if (bArr[i] < 48 || bArr[i] > 57) { i++; } else { int i2 = i + 1; while (i2 < bArr.length && bArr[i2] >= 48 && bArr[i2] <= 57) { i2++; } return Integer.parseInt(new String(bArr, 0, i, i2 - i)); } } return -1; } private static long a(String str) { String readLine; try { BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/meminfo"), 4096); do { readLine = bufferedReader.readLine(); if (readLine == null) { break; } } while (!readLine.contains(str)); bufferedReader.close(); return (long) Integer.valueOf(readLine.split("\\s+")[1]).intValue(); } catch (Throwable unused) { return -1; } } public static String a() { if (!TextUtils.isEmpty(a)) { return a; } e(); return a; } public static JSONObject a(Context context) { StringBuilder sb; String str; String str2; StringBuilder sb2; if (context == null) { b.e("JDeviceHelper", "when getDInfo, context can't be null"); return null; } try { String a2 = a(); String b2 = b(context); String format = String.format(Locale.ENGLISH, "%.1f", Double.valueOf(c(context))); String format2 = String.format(Locale.ENGLISH, Build.VERSION.RELEASE, new Object[0]); String format3 = String.format(Locale.ENGLISH, Build.MODEL, new Object[0]); String format4 = String.format(Locale.ENGLISH, Build.BRAND, new Object[0]); String format5 = String.format(Locale.ENGLISH, Build.PRODUCT, new Object[0]); String locale = context.getResources().getConfiguration().locale.toString(); String format6 = String.format(Locale.ENGLISH, Build.MANUFACTURER, new Object[0]); long rawOffset = (long) (TimeZone.getDefault().getRawOffset() / 3600000); if (rawOffset > 0) { sb2 = new StringBuilder(); sb2.append("+"); sb2.append(rawOffset); } else if (rawOffset < 0) { sb2 = new StringBuilder(); sb2.append("-"); sb2.append(rawOffset); } else { sb2 = new StringBuilder(); sb2.append(""); sb2.append(rawOffset); } String sb3 = sb2.toString(); long d = d(context); long e = e(context); int c2 = c(); String b3 = b(); int d2 = d(); JSONObject jSONObject = new JSONObject(); if (TextUtils.isEmpty(a2)) { a2 = ""; } jSONObject.put("cpu_info", a2); jSONObject.put("cpu_count", c2); jSONObject.put("cpu_max_freq", d2); jSONObject.put("cpu_hardware", b3); jSONObject.put("ram", d); jSONObject.put("rom", e); if (TextUtils.isEmpty(b2)) { b2 = ""; } jSONObject.put("resolution", b2); if (TextUtils.isEmpty(format)) { format = ""; } jSONObject.put("screensize", format); if (TextUtils.isEmpty(format2)) { format2 = ""; } jSONObject.put("os_version", format2); if (TextUtils.isEmpty(format3)) { format3 = ""; } jSONObject.put("model", format3); if (TextUtils.isEmpty(format4)) { format4 = ""; } jSONObject.put("brand", format4); if (TextUtils.isEmpty(format5)) { format5 = ""; } jSONObject.put("product", format5); jSONObject.put(SpeechConstant.LANGUAGE, TextUtils.isEmpty(locale) ? "" : locale); jSONObject.put("manufacturer", TextUtils.isEmpty(format6) ? "" : format6); jSONObject.put("timezone", TextUtils.isEmpty(sb3) ? "" : sb3); return jSONObject; } catch (JSONException e2) { str = "JDeviceHelper"; sb = new StringBuilder(); sb.append("package json exception: "); str2 = e2.getMessage(); sb.append(str2); b.e(str, sb.toString()); return null; } catch (Throwable th) { str = "JDeviceHelper"; sb = new StringBuilder(); sb.append("getDInfo exception: "); str2 = th.getMessage(); sb.append(str2); b.e(str, sb.toString()); return null; } } public static String b() { if (!TextUtils.isEmpty(b)) { return b; } e(); return b; } public static String b(Context context) { DisplayMetrics displayMetrics; if (context == null || context.getResources() == null || (displayMetrics = context.getResources().getDisplayMetrics()) == null) { return "0*0"; } int i = displayMetrics.widthPixels; int i2 = displayMetrics.heightPixels; return i + "*" + i2; } public static double c(Context context) { double d; int i; Point point = new Point(); boolean z = context instanceof Activity; if (z) { Display defaultDisplay = ((Activity) context).getWindowManager().getDefaultDisplay(); if (Build.VERSION.SDK_INT >= 17) { defaultDisplay.getRealSize(point); } else if (Build.VERSION.SDK_INT >= 13) { defaultDisplay.getSize(point); } else { point.x = defaultDisplay.getWidth(); point.y = defaultDisplay.getHeight(); } } DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); if (z) { d = Math.pow((double) (((float) point.x) / displayMetrics.xdpi), 2.0d); i = point.y; } else { d = Math.pow((double) (((float) displayMetrics.widthPixels) / displayMetrics.xdpi), 2.0d); i = displayMetrics.heightPixels; } return Math.sqrt(d + Math.pow((double) (((float) i) / displayMetrics.ydpi), 2.0d)); } public static int c() { if (Build.VERSION.SDK_INT <= 10) { return 1; } try { return new File("/sys/devices/system/cpu/").listFiles(c).length; } catch (Throwable unused) { return -1; } } public static int d() { int i = -1; for (int i2 = 0; i2 < c(); i2++) { try { File file = new File("/sys/devices/system/cpu/cpu" + i2 + "/cpufreq/cpuinfo_max_freq"); if (file.exists()) { byte[] bArr = new byte[128]; FileInputStream fileInputStream = new FileInputStream(file); try { fileInputStream.read(bArr); int i3 = 0; while (bArr[i3] >= 48 && bArr[i3] <= 57 && i3 < bArr.length) { i3++; } Integer valueOf = Integer.valueOf(Integer.parseInt(new String(bArr, 0, i3))); if (valueOf.intValue() > i) { i = valueOf.intValue(); } } catch (Throwable th) { fileInputStream.close(); throw th; } fileInputStream.close(); } } catch (Throwable unused) { return -1; } } if (i != -1) { return i; } FileInputStream fileInputStream2 = new FileInputStream("/proc/cpuinfo"); try { int a2 = a("cpu MHz", fileInputStream2) * 1000; if (a2 <= i) { a2 = i; } return a2; } finally { fileInputStream2.close(); } } public static long d(Context context) { try { if (Build.VERSION.SDK_INT >= 16) { ActivityManager activityManager = (ActivityManager) context.getSystemService("activity"); activityManager.getProcessMemoryInfo(new int[]{0}); ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); return memoryInfo.totalMem / 1024; } } catch (Throwable unused) { } return a("MemTotal"); } public static long e(Context context) { try { StatFs statFs = new StatFs(Environment.getDataDirectory().getPath()); return (((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) / 1024; } catch (Throwable unused) { return -1; } } private static void e() { StringBuffer stringBuffer = new StringBuffer(); try { if (new File("/proc/cpuinfo").exists()) { BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("/proc/cpuinfo"))); String str = null; while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } if (readLine.contains("Processor")) { int indexOf = readLine.indexOf(":"); if (indexOf >= 0 && indexOf < readLine.length() - 1) { str = readLine.substring(indexOf + 1).trim(); } if (str != null && !stringBuffer.toString().contains(str)) { stringBuffer.append(str); } } if (readLine.contains("Hardware")) { try { String trim = readLine.substring(readLine.indexOf(":") + 1).trim(); if (!TextUtils.isEmpty(trim)) { b = trim; } } catch (Throwable unused) { } } } bufferedReader.close(); } } catch (Throwable unused2) { } a = stringBuffer.toString(); } }