- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
331 lines
13 KiB
Java
331 lines
13 KiB
Java
package com.google.firebase.crashlytics.internal.common;
|
|
|
|
import android.app.ActivityManager;
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.content.res.Resources;
|
|
import android.hardware.SensorManager;
|
|
import android.net.ConnectivityManager;
|
|
import android.net.NetworkInfo;
|
|
import android.os.Build;
|
|
import android.os.Debug;
|
|
import android.os.StatFs;
|
|
import android.text.TextUtils;
|
|
import com.applovin.exoplayer2.common.base.Ascii;
|
|
import com.google.firebase.crashlytics.internal.Logger;
|
|
import com.unity3d.ads.core.data.datasource.AndroidStaticDeviceInfoDataSource;
|
|
import java.io.Closeable;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import java.util.Scanner;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public abstract class CommonUtils {
|
|
public static final char[] HEX_VALUES = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
|
|
public static SharedPreferences getSharedPrefs(Context context) {
|
|
return context.getSharedPreferences("com.google.firebase.crashlytics", 0);
|
|
}
|
|
|
|
public static int getCpuArchitectureInt() {
|
|
return Architecture.getValue().ordinal();
|
|
}
|
|
|
|
/* JADX WARN: Enum visitor error
|
|
jadx.core.utils.exceptions.JadxRuntimeException: Can't remove SSA var: r0v0 com.google.firebase.crashlytics.internal.common.CommonUtils$Architecture, still in use, count: 1, list:
|
|
(r0v0 com.google.firebase.crashlytics.internal.common.CommonUtils$Architecture) from 0x0084: INVOKE (r5v5 java.util.HashMap), ("x86"), (r0v0 com.google.firebase.crashlytics.internal.common.CommonUtils$Architecture) INTERFACE call: java.util.Map.put(java.lang.Object, java.lang.Object):java.lang.Object A[MD:(K, V):V (c)] (LINE:114)
|
|
at jadx.core.utils.InsnRemover.removeSsaVar(InsnRemover.java:162)
|
|
at jadx.core.utils.InsnRemover.unbindResult(InsnRemover.java:127)
|
|
at jadx.core.utils.InsnRemover.lambda$unbindInsns$1(InsnRemover.java:99)
|
|
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
|
|
at jadx.core.utils.InsnRemover.unbindInsns(InsnRemover.java:98)
|
|
at jadx.core.utils.InsnRemover.removeAllAndUnbind(InsnRemover.java:252)
|
|
at jadx.core.dex.visitors.EnumVisitor.convertToEnum(EnumVisitor.java:180)
|
|
at jadx.core.dex.visitors.EnumVisitor.visit(EnumVisitor.java:100)
|
|
*/
|
|
/* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
|
|
public static final class Architecture {
|
|
X86_32,
|
|
X86_64,
|
|
ARM_UNKNOWN,
|
|
PPC,
|
|
PPC64,
|
|
ARMV6,
|
|
ARMV7,
|
|
UNKNOWN,
|
|
ARMV7S,
|
|
ARM64;
|
|
|
|
private static final Map<String, Architecture> matcher;
|
|
|
|
private Architecture() {
|
|
}
|
|
|
|
public static Architecture valueOf(String str) {
|
|
return (Architecture) Enum.valueOf(Architecture.class, str);
|
|
}
|
|
|
|
public static Architecture[] values() {
|
|
return (Architecture[]) $VALUES.clone();
|
|
}
|
|
|
|
static {
|
|
HashMap hashMap = new HashMap(4);
|
|
matcher = hashMap;
|
|
hashMap.put("armeabi-v7a", new Architecture());
|
|
hashMap.put("armeabi", new Architecture());
|
|
hashMap.put("arm64-v8a", new Architecture());
|
|
hashMap.put("x86", new Architecture());
|
|
}
|
|
|
|
public static Architecture getValue() {
|
|
String str = Build.CPU_ABI;
|
|
if (TextUtils.isEmpty(str)) {
|
|
Logger.getLogger().v("Architecture#getValue()::Build.CPU_ABI returned null or empty");
|
|
return UNKNOWN;
|
|
}
|
|
Architecture architecture = matcher.get(str.toLowerCase(Locale.US));
|
|
return architecture == null ? UNKNOWN : architecture;
|
|
}
|
|
}
|
|
|
|
public static String streamToString(InputStream inputStream) {
|
|
Scanner useDelimiter = new Scanner(inputStream).useDelimiter("\\A");
|
|
return useDelimiter.hasNext() ? useDelimiter.next() : "";
|
|
}
|
|
|
|
public static String sha1(String str) {
|
|
return hash(str, AndroidStaticDeviceInfoDataSource.ALGORITHM_SHA1);
|
|
}
|
|
|
|
public static String hash(String str, String str2) {
|
|
return hash(str.getBytes(), str2);
|
|
}
|
|
|
|
public static String hash(byte[] bArr, String str) {
|
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance(str);
|
|
messageDigest.update(bArr);
|
|
return hexify(messageDigest.digest());
|
|
} catch (NoSuchAlgorithmException e) {
|
|
Logger.getLogger().e("Could not create hashing algorithm: " + str + ", returning empty string.", e);
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static String createInstanceIdFrom(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 sha1(sb2);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static synchronized long calculateTotalRamInBytes(Context context) {
|
|
long j;
|
|
synchronized (CommonUtils.class) {
|
|
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
|
|
((ActivityManager) context.getSystemService("activity")).getMemoryInfo(memoryInfo);
|
|
j = memoryInfo.totalMem;
|
|
}
|
|
return j;
|
|
}
|
|
|
|
public static long calculateFreeRamInBytes(Context context) {
|
|
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
|
|
((ActivityManager) context.getSystemService("activity")).getMemoryInfo(memoryInfo);
|
|
return memoryInfo.availMem;
|
|
}
|
|
|
|
public static long calculateUsedDiskSpaceInBytes(String str) {
|
|
long blockSize = new StatFs(str).getBlockSize();
|
|
return (r0.getBlockCount() * blockSize) - (blockSize * r0.getAvailableBlocks());
|
|
}
|
|
|
|
public static boolean getProximitySensorEnabled(Context context) {
|
|
return (isEmulator() || ((SensorManager) context.getSystemService("sensor")).getDefaultSensor(8) == null) ? false : true;
|
|
}
|
|
|
|
public static boolean getBooleanResourceValue(Context context, String str, boolean z) {
|
|
Resources resources;
|
|
if (context != null && (resources = context.getResources()) != null) {
|
|
int resourcesIdentifier = getResourcesIdentifier(context, str, "bool");
|
|
if (resourcesIdentifier > 0) {
|
|
return resources.getBoolean(resourcesIdentifier);
|
|
}
|
|
int resourcesIdentifier2 = getResourcesIdentifier(context, str, "string");
|
|
if (resourcesIdentifier2 > 0) {
|
|
return Boolean.parseBoolean(context.getString(resourcesIdentifier2));
|
|
}
|
|
}
|
|
return z;
|
|
}
|
|
|
|
public static int getResourcesIdentifier(Context context, String str, String str2) {
|
|
return context.getResources().getIdentifier(str, str2, getResourcePackageName(context));
|
|
}
|
|
|
|
public static boolean isEmulator() {
|
|
if (!Build.PRODUCT.contains("sdk")) {
|
|
String str = Build.HARDWARE;
|
|
if (!str.contains("goldfish") && !str.contains("ranchu")) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static boolean isRooted() {
|
|
boolean isEmulator = isEmulator();
|
|
String str = Build.TAGS;
|
|
if ((isEmulator || str == null || !str.contains("test-keys")) && !new File("/system/app/Superuser.apk").exists()) {
|
|
return !isEmulator && new File("/system/xbin/su").exists();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static boolean isDebuggerAttached() {
|
|
return Debug.isDebuggerConnected() || Debug.waitingForDebugger();
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX WARN: Type inference failed for: r0v1, types: [int] */
|
|
/* JADX WARN: Type inference failed for: r0v5 */
|
|
/* JADX WARN: Type inference failed for: r0v6 */
|
|
public static int getDeviceState() {
|
|
boolean isEmulator = isEmulator();
|
|
?? r0 = isEmulator;
|
|
if (isRooted()) {
|
|
r0 = (isEmulator ? 1 : 0) | 2;
|
|
}
|
|
return isDebuggerAttached() ? r0 | 4 : r0;
|
|
}
|
|
|
|
public static String hexify(byte[] bArr) {
|
|
char[] cArr = new char[bArr.length * 2];
|
|
for (int i = 0; i < bArr.length; i++) {
|
|
byte b = bArr[i];
|
|
int i2 = i * 2;
|
|
char[] cArr2 = HEX_VALUES;
|
|
cArr[i2] = cArr2[(b & 255) >>> 4];
|
|
cArr[i2 + 1] = cArr2[b & Ascii.SI];
|
|
}
|
|
return new String(cArr);
|
|
}
|
|
|
|
public static boolean isAppDebuggable(Context context) {
|
|
return (context.getApplicationInfo().flags & 2) != 0;
|
|
}
|
|
|
|
public static void closeOrLog(Closeable closeable, String str) {
|
|
if (closeable != null) {
|
|
try {
|
|
closeable.close();
|
|
} catch (IOException e) {
|
|
Logger.getLogger().e(str, e);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static String getResourcePackageName(Context context) {
|
|
int i = context.getApplicationContext().getApplicationInfo().icon;
|
|
if (i > 0) {
|
|
try {
|
|
String resourcePackageName = context.getResources().getResourcePackageName(i);
|
|
return "android".equals(resourcePackageName) ? context.getPackageName() : resourcePackageName;
|
|
} catch (Resources.NotFoundException unused) {
|
|
return context.getPackageName();
|
|
}
|
|
}
|
|
return context.getPackageName();
|
|
}
|
|
|
|
public static String getMappingFileId(Context context) {
|
|
int resourcesIdentifier = getResourcesIdentifier(context, "com.google.firebase.crashlytics.mapping_file_id", "string");
|
|
if (resourcesIdentifier == 0) {
|
|
resourcesIdentifier = getResourcesIdentifier(context, "com.crashlytics.android.build_id", "string");
|
|
}
|
|
if (resourcesIdentifier != 0) {
|
|
return context.getResources().getString(resourcesIdentifier);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static List getBuildIdInfo(Context context) {
|
|
ArrayList arrayList = new ArrayList();
|
|
int resourcesIdentifier = getResourcesIdentifier(context, "com.google.firebase.crashlytics.build_ids_lib", "array");
|
|
int resourcesIdentifier2 = getResourcesIdentifier(context, "com.google.firebase.crashlytics.build_ids_arch", "array");
|
|
int resourcesIdentifier3 = getResourcesIdentifier(context, "com.google.firebase.crashlytics.build_ids_build_id", "array");
|
|
if (resourcesIdentifier == 0 || resourcesIdentifier2 == 0 || resourcesIdentifier3 == 0) {
|
|
Logger.getLogger().d(String.format("Could not find resources: %d %d %d", Integer.valueOf(resourcesIdentifier), Integer.valueOf(resourcesIdentifier2), Integer.valueOf(resourcesIdentifier3)));
|
|
return arrayList;
|
|
}
|
|
String[] stringArray = context.getResources().getStringArray(resourcesIdentifier);
|
|
String[] stringArray2 = context.getResources().getStringArray(resourcesIdentifier2);
|
|
String[] stringArray3 = context.getResources().getStringArray(resourcesIdentifier3);
|
|
if (stringArray.length != stringArray3.length || stringArray2.length != stringArray3.length) {
|
|
Logger.getLogger().d(String.format("Lengths did not match: %d %d %d", Integer.valueOf(stringArray.length), Integer.valueOf(stringArray2.length), Integer.valueOf(stringArray3.length)));
|
|
return arrayList;
|
|
}
|
|
for (int i = 0; i < stringArray3.length; i++) {
|
|
arrayList.add(new BuildIdInfo(stringArray[i], stringArray2[i], stringArray3[i]));
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
public static void closeQuietly(Closeable closeable) {
|
|
if (closeable != null) {
|
|
try {
|
|
closeable.close();
|
|
} catch (RuntimeException e) {
|
|
throw e;
|
|
} catch (Exception unused) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public static boolean checkPermission(Context context, String str) {
|
|
return context.checkCallingOrSelfPermission(str) == 0;
|
|
}
|
|
|
|
public static boolean canTryConnection(Context context) {
|
|
if (!checkPermission(context, "android.permission.ACCESS_NETWORK_STATE")) {
|
|
return true;
|
|
}
|
|
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
|
|
return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
|
|
}
|
|
|
|
public static boolean nullSafeEquals(String str, String str2) {
|
|
if (str == null) {
|
|
return str2 == null;
|
|
}
|
|
return str.equals(str2);
|
|
}
|
|
}
|