package X; import android.app.Application; import android.app.usage.StorageStatsManager; import android.content.ClipboardManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.os.StatFs; import android.os.storage.StorageManager; import android.os.storage.StorageVolume; import android.text.TextUtils; import android.util.Pair; import com.bytedance.covode.number.Covode; import com.swift.sandhook.utils.FileUtils; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigDecimal; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.UUID; import org.json.JSONArray; import org.json.JSONObject; /* renamed from: X.0KV reason: invalid class name */ public final class AnonymousClass0KV { public static AnonymousClass0KV LIZ = new AnonymousClass0KV(); public String LIZIZ; public String LIZJ; public String LIZLLL; public String LJ; public volatile boolean LJFF; public List<String> LJI; public List<String> LJII; public boolean LJIIIIZZ; public AnonymousClass0KP LJIIIZ; public AnonymousClass0HU LJIIJ; public long LJIIJJI; public long LJIIL; public long LJIILIIL; public long LJIILJJIL; static { Covode.recordClassIndex(18661); } private float LIZ(long j, BigDecimal bigDecimal) { return (float) new BigDecimal(j).divide(bigDecimal, 4, 4).doubleValue(); } public static ApplicationInfo LIZ(PackageManager packageManager, String str, int i2) { Context LIZ2 = AnonymousClass0WE.LJJI.LIZ(); if (C16420l5.LJIIIZ && TextUtils.equals(str, LIZ2.getPackageName()) && i2 == 128) { if (C16420l5.LIZ == null) { C16420l5.LIZ = packageManager.getApplicationInfo(str, i2); } return C16420l5.LIZ; } else if (!C16420l5.LJIIIZ || !TextUtils.equals(str, LIZ2.getPackageName()) || i2 != 0) { return packageManager.getApplicationInfo(str, i2); } else { if (C16420l5.LIZJ == null) { C16420l5.LIZJ = packageManager.getApplicationInfo(str, i2); } return C16420l5.LIZJ; } } private Pair<Long, Long> LIZ() { try { long j = 0; if (Build.VERSION.SDK_INT >= 26) { StorageStatsManager storageStatsManager = (StorageStatsManager) LIZ(C05670Lc.LJII, "storagestats"); StorageManager storageManager = (StorageManager) LIZ(C05670Lc.LJII, "storage"); long j2 = 0; for (StorageVolume storageVolume : storageManager.getStorageVolumes()) { String uuid = storageVolume.getUuid(); UUID fromString = uuid == null ? StorageManager.UUID_DEFAULT : UUID.fromString(uuid); j += storageStatsManager.getTotalBytes(fromString); j2 += storageManager.getAllocatableBytes(fromString); } return new Pair<>(Long.valueOf(((j / 1000) / 1000) * 1024 * 1024), Long.valueOf(((j2 / 1000) / 1000) * 1024 * 1024)); } else if (Build.VERSION.SDK_INT >= 24) { List<StorageVolume> storageVolumes = ((StorageManager) LIZ(C05670Lc.LJII, "storage")).getStorageVolumes(); if (C05810Lq.LIZ(storageVolumes)) { return null; } long j3 = 0; for (StorageVolume storageVolume2 : storageVolumes) { File file = (File) LIZ(LIZ(storageVolume2.getClass(), "getPathFile", new Class[0]), storageVolume2, new Object[0]); j += file.getTotalSpace(); j3 += file.getFreeSpace(); } return new Pair<>(Long.valueOf(((j / 1000) / 1000) * 1024 * 1024), Long.valueOf(((j3 / 1000) / 1000) * 1024 * 1024)); } else { StorageManager storageManager2 = (StorageManager) LIZ(C05670Lc.LJII, "storage"); long j4 = 0; for (Object obj : (List) LIZ(LIZ(storageManager2.getClass(), "getVolumes", new Class[0]), storageManager2, new Object[0])) { File file2 = (File) LIZ(LIZ(obj.getClass(), "getPathFile", new Class[0]), obj, new Object[0]); j4 += file2.getFreeSpace(); j += file2.getFreeSpace(); } return new Pair<>(Long.valueOf(j), Long.valueOf(j4)); } } catch (Throwable unused) { Long valueOf = Long.valueOf(C05720Lh.LIZ(Environment.getDataDirectory().getPath()) + C05720Lh.LIZ(Environment.getRootDirectory().getPath())); StatFs statFs = new StatFs(Environment.getDataDirectory().getPath()); int i2 = Build.VERSION.SDK_INT; return new Pair<>(valueOf, Long.valueOf(statFs.getAvailableBytes())); } } public static Object LIZ(Application application, String str) { Object systemService; if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) { if (!C16520lF.LIZIZ && "connectivity".equals(str)) { try { new AnonymousClass1ME().LIZ(); C16520lF.LIZIZ = true; return application.getSystemService(str); } catch (Throwable unused) { } } return application.getSystemService(str); } else if (!C16520lF.LIZ) { return application.getSystemService(str); } else { synchronized (ClipboardManager.class) { systemService = application.getSystemService(str); if (Thread.currentThread() != Looper.getMainLooper().getThread()) { try { Field declaredField = ClipboardManager.class.getDeclaredField("mHandler"); declaredField.setAccessible(true); declaredField.set(systemService, new HandlerC16510lE((Handler) declaredField.get(systemService))); } catch (Exception e) { AnonymousClass0O2.LIZ(e, "ClipboardManager Handler Reflect Fail"); } } C16520lF.LIZ = false; } return systemService; } } public static Object LIZ(Context context, String str) { Object systemService; if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) { if (!C16520lF.LIZIZ && "connectivity".equals(str)) { try { new AnonymousClass1ME().LIZ(); C16520lF.LIZIZ = true; return context.getSystemService(str); } catch (Throwable unused) { } } return context.getSystemService(str); } else if (!C16520lF.LIZ) { return context.getSystemService(str); } else { synchronized (ClipboardManager.class) { systemService = context.getSystemService(str); if (Thread.currentThread() != Looper.getMainLooper().getThread()) { try { Field declaredField = ClipboardManager.class.getDeclaredField("mHandler"); declaredField.setAccessible(true); declaredField.set(systemService, new HandlerC16510lE((Handler) declaredField.get(systemService))); } catch (Exception e) { AnonymousClass0O2.LIZ(e, "ClipboardManager Handler Reflect Fail"); } } C16520lF.LIZ = false; } return systemService; } } public static Object LIZ(Method method, Object obj, Object[] objArr) { Pair<Boolean, Object> LIZ2 = AnonymousClass0UU.LIZ(method, new Object[]{obj, objArr}, 110000, "java.lang.Object", true, "com_bytedance_apm6_disk_DiskStatistics_java_lang_reflect_Method_invoke(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"); if (((Boolean) LIZ2.first).booleanValue()) { return LIZ2.second; } Object invoke = method.invoke(obj, objArr); AnonymousClass0UU.LIZ(invoke, method, new Object[]{obj, objArr}, "com_bytedance_apm6_disk_DiskStatistics_java_lang_reflect_Method_invoke(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"); return invoke; } public static Method LIZ(Class cls, String str, Class<?>... clsArr) { try { Method method = (Method) Class.class.getDeclaredMethod("getDeclaredMethod", String.class, Class[].class).invoke(cls, str, clsArr); method.setAccessible(true); return method; } catch (Exception unused) { return null; } } public static List<String> LIZ(AnonymousClass0JE<? extends AnonymousClass0KT> r3) { if (r3 == null) { return null; } LinkedList linkedList = new LinkedList(); for (AnonymousClass0KT r0 : r3.LIZ()) { linkedList.add(r0.LIZ); } return linkedList; } private JSONArray LIZ(List<AnonymousClass0KS> list, long j) { if (list == null || list.isEmpty()) { return null; } BigDecimal bigDecimal = new BigDecimal(j); JSONArray jSONArray = new JSONArray(); for (AnonymousClass0KS r7 : list) { if (LIZ(r7)) { r7.LIZJ = 0.0f; } else { r7.LIZJ = LIZ(r7.LIZIZ, bigDecimal); } List<AnonymousClass0KS> list2 = r7.LJFF; if (list2 != null && list2.size() > 0) { for (AnonymousClass0KS r2 : list2) { if (LIZ(r2)) { r2.LIZJ = 0.0f; } else { r2.LIZJ = LIZ(r2.LIZIZ, bigDecimal); } } } jSONArray.put(r7.LIZ()); } return jSONArray; } private boolean LIZ(AnonymousClass0KS r4) { for (String str : this.LJI) { if (r4.LIZ.contains(str)) { return true; } } return false; } private boolean LIZ(File file) { if (!C05810Lq.LIZ(this.LJI)) { return this.LJI.contains(file.getAbsolutePath()); } return false; } /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x0042 */ private long LIZIZ() { if (Build.VERSION.SDK_INT >= 26) { Application application = C05670Lc.LJII; String packageName = application.getPackageName(); return ((StorageStatsManager) LIZ((Context) application, "storagestats")).queryStatsForUid(((StorageManager) LIZ((Context) application, "storage")).getUuidForPath(new File(application.getDataDir().getParent(), packageName)), LIZ(application.getPackageManager(), packageName, (int) FileUtils.FileMode.MODE_IWUSR).uid).getAppBytes(); } try { return LIZIZ(new File(LIZ(C05670Lc.LJII.getPackageManager(), C05670Lc.LJII.getPackageName(), 0).sourceDir).getParentFile()) + LIZJ() + this.LJIIJJI + this.LJIIL; } catch (Exception unused) { return 0; } } private long LIZIZ(File file) { long j = 0; try { File[] listFiles = file.listFiles(); if (listFiles != null) { if (listFiles.length != 0) { for (File file2 : listFiles) { j += file2.isDirectory() ? LIZIZ(file2) : file2.length(); } return j; } } return 0; } catch (Exception e) { e.printStackTrace(); } } private long LIZIZ(File file, List<AnonymousClass0KS> list) { long j = 0; if (file != null && file.exists() && !LIZ(file)) { if (file.isFile()) { long length = file.length(); if (length < this.LJIIIZ.LIZLLL) { return length; } AnonymousClass0KS r1 = new AnonymousClass0KS(this, (byte) 0); r1.LIZLLL = false; r1.LIZ = file.getAbsolutePath(); r1.LIZIZ = length; list.add(r1); return length; } File[] listFiles = file.listFiles(); if (!(listFiles == null || listFiles.length == 0)) { AnonymousClass0KS r7 = new AnonymousClass0KS(this, (byte) 0); r7.LIZLLL = file.isDirectory(); r7.LIZ = file.getAbsolutePath(); ArrayList arrayList = new ArrayList(); r7.LJFF = arrayList; list.add(r7); for (File file2 : listFiles) { if (file2 != null && file2.exists() && !LIZ(file2)) { j += LIZIZ(file2, arrayList); } } r7.LIZIZ = j; } } return j; } private JSONArray LIZIZ(AnonymousClass0JE<AnonymousClass0KT> r4) { JSONArray jSONArray = new JSONArray(); for (AnonymousClass0KT r0 : r4.LIZ()) { JSONObject LIZ2 = r0.LIZ(); if (LIZ2 != null) { jSONArray.put(LIZ2); } } return jSONArray; } private long LIZJ() { long j = 0; if (Build.VERSION.SDK_INT >= 21) { Context applicationContext = C05670Lc.LJII.getApplicationContext(); if (C16360kz.LIZJ && applicationContext == null) { applicationContext = C16360kz.LIZ; } for (File file : applicationContext.getExternalMediaDirs()) { j += LIZIZ(file); } } return j; } private long LIZJ(long j) { long currentTimeMillis = System.currentTimeMillis() - j; if (currentTimeMillis < this.LJIIIZ.LJIIIIZZ || currentTimeMillis >= 62899200000L) { return 0; } return currentTimeMillis; } public final C31191Lg LIZ(AnonymousClass0JE<AnonymousClass0KT> r38, AnonymousClass0JE<AnonymousClass0KT> r39, AnonymousClass0JE<AnonymousClass0KT> r40, List<AnonymousClass0KS> list) { try { long j = this.LJIIJJI + this.LJIIL; long j2 = this.LJIILIIL + this.LJIILJJIL; long totalSpace = Environment.getDataDirectory().getTotalSpace() + Environment.getRootDirectory().getTotalSpace(); long freeSpace = Environment.getDataDirectory().getFreeSpace(); long j3 = j > 17179869184L ? 17179869184L : j; if (j2 > 17179869184L) { j2 = 17179869184L; } if (j3 < 0) { return null; } if (this.LJIIJ != null) { LIZ(r38); LIZ(r39); LIZ(r40); } Pair<Long, Long> LIZ2 = LIZ(); long LIZIZ2 = LIZIZ(); try { return new C31191Lg(j, j2, totalSpace, freeSpace, LIZIZ2, ((Long) LIZ2.first).longValue(), ((Long) LIZ2.second).longValue(), (double) LIZ(LIZIZ2, new BigDecimal(totalSpace)), LIZIZ(r38), LIZIZ(r39), LIZIZ(r40), LIZ(list, j3)); } catch (Throwable unused) { return null; } } catch (Throwable unused2) { return null; } } public final String LIZ(Context context) { File file; try { if (!TextUtils.isEmpty(null)) { file = context.getExternalFilesDir(null); } else { if (C16490lC.LIZLLL == null || !C16490lC.LJ) { C16490lC.LIZLLL = context.getExternalFilesDir(null); } file = C16490lC.LIZLLL; } return file.getParentFile().getAbsolutePath(); } catch (Exception unused) { return null; } } public final List<AnonymousClass0KU> LIZ(String str, AnonymousClass0JE<AnonymousClass0KT> r23, AnonymousClass0JE<AnonymousClass0KT> r24, AnonymousClass0JE<AnonymousClass0KT> r25, List<String> list) { String str2; ArrayList arrayList = new ArrayList(); File file = new File(str); AnonymousClass0KU r2 = new AnonymousClass0KU(this, (byte) 0); r2.LIZ = str; r2.LIZIZ = new AnonymousClass0KU(this, (byte) 0); File[] listFiles = file.listFiles(); if (listFiles == null || listFiles.length == 0) { return null; } if (list.contains(file.getAbsolutePath())) { arrayList.add(r2); list.remove(file.getAbsolutePath()); } r2.LIZLLL = listFiles.length; LinkedList linkedList = new LinkedList(); linkedList.offer(r2); while (!linkedList.isEmpty()) { int size = linkedList.size(); for (int i2 = 0; i2 < size; i2++) { AnonymousClass0KU r11 = (AnonymousClass0KU) linkedList.poll(); if (r11 != null) { String str3 = r11.LIZ; File file2 = new File(str3); if (!file2.exists() || LIZ(file2)) { r11.LIZIZ.LIZLLL--; } else if (file2.isFile()) { long length = file2.length(); if (!LIZ(length)) { str2 = str3; r23.LIZ(new AnonymousClass0KT(this, str3, length, 1)); } else { str2 = str3; } if (r11.LIZIZ != null) { r11.LIZIZ.LIZ(length, r25, r24); if (!r11.LIZIZ.LJ) { long LIZJ2 = LIZJ(file2.lastModified()); if (LIZJ2 > 0 && LIZIZ(length)) { r25.LIZ(new AnonymousClass15I(this, str2, (long) size, 0, LIZJ2)); } } } } else { if (list.contains(file2.getAbsolutePath())) { arrayList.add(r11); list.remove(file2.getAbsolutePath()); } File[] listFiles2 = file2.listFiles(); if (listFiles2 == null || listFiles2.length == 0) { r11.LIZIZ.LIZ(0, r25, r24); } else { r11.LIZLLL = listFiles2.length; for (File file3 : listFiles2) { AnonymousClass0KU r22 = new AnonymousClass0KU(this, (byte) 0); r22.LIZIZ = r11; r22.LIZ = file3.getAbsolutePath(); if (file3.isDirectory() && !r11.LJ) { long LIZJ3 = LIZJ(file3.lastModified()); if (LIZJ3 > 0) { r22.LJ = true; r22.LJFF = LIZJ3; } } linkedList.offer(r22); } } } } } } return arrayList; } public final void LIZ(File file, List<AnonymousClass0KS> list) { File[] listFiles = file.listFiles(); if (!(listFiles == null || listFiles.length == 0)) { for (File file2 : listFiles) { LIZIZ(file2, list); } } } public final void LIZ(List<AnonymousClass0KU> list) { if (!C05810Lq.LIZ(list)) { for (AnonymousClass0KU r2 : list) { if (TextUtils.equals(r2.LIZ, this.LIZIZ)) { this.LJIIJJI = r2.LIZJ; } else if (TextUtils.equals(r2.LIZ, this.LIZLLL)) { this.LJIIL = r2.LIZJ; } else if (TextUtils.equals(r2.LIZ, this.LIZJ)) { this.LJIILIIL = r2.LIZJ; } else if (TextUtils.equals(r2.LIZ, this.LJ)) { this.LJIILJJIL = r2.LIZJ; } } } } public final boolean LIZ(long j) { return j < 0 || j > 17179869184L; } public final List<String> LIZIZ(List<String> list) { ArrayList arrayList = new ArrayList(); if (C05810Lq.LIZ(list)) { return arrayList; } for (String str : list) { if (str.contains("internal")) { arrayList.add(str.replace("internal", this.LIZIZ)); } else if (str.contains("external")) { arrayList.add(str.replace("external", this.LIZLLL)); } } return arrayList; } public final boolean LIZIZ(long j) { return j >= 104857600 && j <= 17179869184L; } public final void LIZJ(List<AnonymousClass0KS> list) { if (!C05810Lq.LIZ(this.LJII)) { for (String str : this.LJII) { File file = new File(str); if (file.exists() && !LIZ(file)) { if (file.isFile()) { long length = file.length(); AnonymousClass0KS r1 = new AnonymousClass0KS(this, (byte) 0); r1.LIZLLL = false; r1.LIZ = file.getAbsolutePath(); r1.LIZIZ = length; r1.LJ = "custom"; list.add(r1); } else { AnonymousClass0KS r2 = new AnonymousClass0KS(this, (byte) 0); r2.LIZLLL = true; r2.LJ = "custom"; r2.LIZ = file.getAbsolutePath(); r2.LIZIZ = LIZIZ(file); list.add(r2); } } } } } }