265 lines
8.3 KiB
Java
265 lines
8.3 KiB
Java
package io.fabric.sdk.android.services.common;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.content.res.Resources;
|
|
import com.ijm.dataencryption.de.DataDecryptTool;
|
|
import io.fabric.sdk.android.Fabric;
|
|
import java.io.Closeable;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Iterator;
|
|
import java.util.Locale;
|
|
import java.util.Scanner;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class CommonUtils {
|
|
private static Boolean a;
|
|
private static final char[] b = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
|
|
static {
|
|
new Comparator<File>() { // from class: io.fabric.sdk.android.services.common.CommonUtils.1
|
|
@Override // java.util.Comparator
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public int compare(File file, File file2) {
|
|
return (int) (file.lastModified() - file2.lastModified());
|
|
}
|
|
};
|
|
}
|
|
|
|
public static String a(InputStream inputStream) {
|
|
return a(inputStream, "SHA-1");
|
|
}
|
|
|
|
public static String b(InputStream inputStream) throws IOException {
|
|
Scanner useDelimiter = new Scanner(inputStream).useDelimiter("\\A");
|
|
return useDelimiter.hasNext() ? useDelimiter.next() : "";
|
|
}
|
|
|
|
public static String c(Context context) {
|
|
int i = context.getApplicationContext().getApplicationInfo().icon;
|
|
return i > 0 ? context.getResources().getResourcePackageName(i) : context.getPackageName();
|
|
}
|
|
|
|
public static SharedPreferences d(Context context) {
|
|
return context.getSharedPreferences("com.crashlytics.prefs", 0);
|
|
}
|
|
|
|
public static boolean e(Context context) {
|
|
return (context.getApplicationInfo().flags & 2) != 0;
|
|
}
|
|
|
|
public static boolean f(Context context) {
|
|
if (a == null) {
|
|
a = Boolean.valueOf(a(context, "com.crashlytics.Trace", false));
|
|
}
|
|
return a.booleanValue();
|
|
}
|
|
|
|
public static String g(Context context) {
|
|
int a2 = a(context, "io.fabric.android.build_id", "string");
|
|
if (a2 == 0) {
|
|
a2 = a(context, "com.crashlytics.android.build_id", "string");
|
|
}
|
|
if (a2 == 0) {
|
|
return null;
|
|
}
|
|
String string = context.getResources().getString(a2);
|
|
Fabric.g().d("Fabric", "Build ID is: " + string);
|
|
return string;
|
|
}
|
|
|
|
private static String a(InputStream inputStream, String str) {
|
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
|
|
byte[] bArr = new byte[DataDecryptTool.DECRYPT_SP_FILE];
|
|
while (true) {
|
|
int read = inputStream.read(bArr);
|
|
if (read == -1) {
|
|
return a(messageDigest.digest());
|
|
}
|
|
messageDigest.update(bArr, 0, read);
|
|
}
|
|
} catch (Exception e) {
|
|
Fabric.g().b("Fabric", "Could not calculate hash for app icon.", e);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static String b(String str) {
|
|
return a(str, "SHA-1");
|
|
}
|
|
|
|
public static void b(Context context, String str) {
|
|
if (f(context)) {
|
|
Fabric.g().d("Fabric", str);
|
|
}
|
|
}
|
|
|
|
public static int b(Context context) {
|
|
return context.getApplicationContext().getApplicationInfo().icon;
|
|
}
|
|
|
|
private static String a(byte[] bArr, String str) {
|
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance(str);
|
|
messageDigest.update(bArr);
|
|
return a(messageDigest.digest());
|
|
} catch (NoSuchAlgorithmException e) {
|
|
Fabric.g().b("Fabric", "Could not create hashing algorithm: " + str + ", returning empty string.", e);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
private static String a(String str, String str2) {
|
|
return a(str.getBytes(), str2);
|
|
}
|
|
|
|
public static String a(String... strArr) {
|
|
if (strArr == null || strArr.length == 0) {
|
|
return null;
|
|
}
|
|
ArrayList arrayList = new ArrayList();
|
|
for (String str : strArr) {
|
|
if (str != null) {
|
|
arrayList.add(str.replace("-", "").toLowerCase(Locale.US));
|
|
}
|
|
}
|
|
Collections.sort(arrayList);
|
|
StringBuilder sb = new StringBuilder();
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
sb.append((String) it.next());
|
|
}
|
|
String sb2 = sb.toString();
|
|
if (sb2.length() > 0) {
|
|
return b(sb2);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static void a(Context context, String str, Throwable th) {
|
|
if (f(context)) {
|
|
Fabric.g().e("Fabric", str);
|
|
}
|
|
}
|
|
|
|
public static void a(Context context, int i, String str, String str2) {
|
|
if (f(context)) {
|
|
Fabric.g().a(i, "Fabric", str2);
|
|
}
|
|
}
|
|
|
|
public static boolean a(Context context, String str, boolean z) {
|
|
Resources resources;
|
|
if (context != null && (resources = context.getResources()) != null) {
|
|
int a2 = a(context, str, "bool");
|
|
if (a2 > 0) {
|
|
return resources.getBoolean(a2);
|
|
}
|
|
int a3 = a(context, str, "string");
|
|
if (a3 > 0) {
|
|
return Boolean.parseBoolean(context.getString(a3));
|
|
}
|
|
}
|
|
return z;
|
|
}
|
|
|
|
public static int a(Context context, String str, String str2) {
|
|
return context.getResources().getIdentifier(str, str2, c(context));
|
|
}
|
|
|
|
public static String a(byte[] bArr) {
|
|
char[] cArr = new char[bArr.length * 2];
|
|
for (int i = 0; i < bArr.length; i++) {
|
|
int i2 = bArr[i] & 255;
|
|
int i3 = i * 2;
|
|
char[] cArr2 = b;
|
|
cArr[i3] = cArr2[i2 >>> 4];
|
|
cArr[i3 + 1] = cArr2[i2 & 15];
|
|
}
|
|
return new String(cArr);
|
|
}
|
|
|
|
public static String a(Context context, String str) {
|
|
int a2 = a(context, str, "string");
|
|
return a2 > 0 ? context.getString(a2) : "";
|
|
}
|
|
|
|
public static void a(Closeable closeable, String str) {
|
|
if (closeable != null) {
|
|
try {
|
|
closeable.close();
|
|
} catch (IOException e) {
|
|
Fabric.g().b("Fabric", str, e);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static boolean a(String str) {
|
|
return str == null || str.length() == 0;
|
|
}
|
|
|
|
public static void a(InputStream inputStream, OutputStream outputStream, byte[] bArr) throws IOException {
|
|
while (true) {
|
|
int read = inputStream.read(bArr);
|
|
if (read == -1) {
|
|
return;
|
|
} else {
|
|
outputStream.write(bArr, 0, read);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static String a(Context context) {
|
|
Throwable th;
|
|
InputStream inputStream;
|
|
try {
|
|
inputStream = context.getResources().openRawResource(b(context));
|
|
} catch (Exception e) {
|
|
e = e;
|
|
inputStream = null;
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
inputStream = null;
|
|
a((Closeable) inputStream, "Failed to close icon input stream.");
|
|
throw th;
|
|
}
|
|
try {
|
|
try {
|
|
String a2 = a(inputStream);
|
|
String str = a(a2) ? null : a2;
|
|
a((Closeable) inputStream, "Failed to close icon input stream.");
|
|
return str;
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
a((Closeable) inputStream, "Failed to close icon input stream.");
|
|
throw th;
|
|
}
|
|
} catch (Exception e2) {
|
|
e = e2;
|
|
Fabric.g().b("Fabric", "Could not calculate hash for app icon.", e);
|
|
a((Closeable) inputStream, "Failed to close icon input stream.");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static void a(Closeable closeable) {
|
|
if (closeable != null) {
|
|
try {
|
|
closeable.close();
|
|
} catch (RuntimeException e) {
|
|
throw e;
|
|
} catch (Exception unused) {
|
|
}
|
|
}
|
|
}
|
|
}
|