TikTok.apk(点击下载) / C61018NxX.java


package X;

import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import com.bytedance.apm.core.ActivityLifeObserver;
import com.bytedance.covode.number.Covode;
import com.bytedance.services.slardar.config.IConfigManager;
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

/* renamed from: X.NxX  reason: case insensitive filesystem */
public final class C61018NxX extends AnonymousClass14U {
    public static String LIZLLL;
    public static String LJFF;
    public static long LJIJI = 17179869184L;
    public long LIZ = 524288000;
    public long LIZIZ = 524288000;
    public AnonymousClass0HU LIZJ;
    public String LJ;
    public String LJI;
    public long LJII;
    public long LJIIIIZZ;
    public long LJIIIZ;
    public long LJIIJ;
    public boolean LJIIJJI;
    public boolean LJIIL;
    public int LJIIZILJ = 20;
    public long LJIJ = 2592000000L;
    public boolean LJIJJ;
    public List<C61019NxY> LJIJJLI;
    public List<String> LJIL = new ArrayList();
    public List<String> LJJ = new ArrayList();
    public List<String> LJJI = new ArrayList();
    public List<String> LJJIFFI = new ArrayList();
    public AnonymousClass0JE<C61021Nxa> LJJII;
    public AnonymousClass0JE<C61021Nxa> LJJIII;
    public AnonymousClass0JE<C61022Nxb> LJJIIJ;

    static {
        Covode.recordClassIndex(18480);
    }

    public C61018NxX() {
        this.LJIILL = "disk";
    }

    private float LIZ(long j, BigDecimal bigDecimal) {
        return (float) new BigDecimal(j).divide(bigDecimal, 4, 4).doubleValue();
    }

    private long LIZ(File file) {
        long j = 0;
        try {
            File[] listFiles = file.listFiles();
            if (listFiles != null) {
                if (listFiles.length != 0) {
                    for (File file2 : listFiles) {
                        j += file2.isDirectory() ? LIZ(file2) : file2.length();
                    }
                    return j;
                }
            }
            return 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static List<String> LIZ(AnonymousClass0JE<? extends C61021Nxa> r3) {
        if (r3 == null) {
            return null;
        }
        LinkedList linkedList = new LinkedList();
        for (C61021Nxa nxa : r3.LIZ()) {
            linkedList.add(nxa.LIZ);
        }
        return linkedList;
    }

    private void LIZ(long j, long j2, long j3, long j4) {
        try {
            if (C04470Gm.LJ()) {
                String[] strArr = new String[1];
                String str = "disk: data: " + j + " , cache: " + j2 + " , total: " + j3 + " , free: " + j4;
            }
            long j5 = LJIJI;
            long j6 = j > j5 ? j5 : j;
            if (j2 <= j5) {
                j5 = j2;
            }
            JSONObject jSONObject = new JSONObject();
            if (j > 0) {
                jSONObject.put("data", j6);
            }
            if (j2 > 0) {
                jSONObject.put("cache", j5);
            }
            if (j3 > 0) {
                jSONObject.put("total", j3 / 1073741824);
            }
            if (j4 > 0) {
                jSONObject.put("rom_free", j4 / 1073741824);
            }
            JSONObject jSONObject2 = new JSONObject();
            if (this.LJIIL && j6 > this.LIZ) {
                if (this.LJJII != null) {
                    JSONArray jSONArray = new JSONArray();
                    for (C61021Nxa nxa : this.LJJII.LIZ()) {
                        JSONObject LIZ2 = nxa.LIZ();
                        if (LIZ2 != null) {
                            jSONArray.put(LIZ2);
                        }
                    }
                    jSONObject2.put("top_usage", jSONArray);
                }
                if (this.LJJIII != null) {
                    JSONArray jSONArray2 = new JSONArray();
                    for (C61021Nxa nxa2 : this.LJJIII.LIZ()) {
                        JSONObject LIZ3 = nxa2.LIZ();
                        if (LIZ3 != null) {
                            jSONArray2.put(LIZ3);
                        }
                    }
                    jSONObject2.put("exception_folders", jSONArray2);
                }
                if (this.LJJIIJ != null) {
                    JSONArray jSONArray3 = new JSONArray();
                    for (C61022Nxb nxb : this.LJJIIJ.LIZ()) {
                        JSONObject LIZ4 = nxb.LIZ();
                        if (LIZ4 != null) {
                            jSONArray3.put(LIZ4);
                        }
                    }
                    jSONObject2.put("outdated_files", jSONArray3);
                }
                List<C61019NxY> list = this.LJIJJLI;
                if (list != null && !list.isEmpty()) {
                    BigDecimal bigDecimal = new BigDecimal(j6);
                    JSONArray jSONArray4 = new JSONArray();
                    for (C61019NxY nxY : this.LJIJJLI) {
                        if (LIZ(nxY)) {
                            nxY.LIZJ = 0.0f;
                        } else {
                            nxY.LIZJ = LIZ(nxY.LIZIZ, bigDecimal);
                        }
                        List<C61019NxY> list2 = nxY.LJFF;
                        if (list2 != null && list2.size() > 0) {
                            for (C61019NxY nxY2 : list2) {
                                if (LIZ(nxY2)) {
                                    nxY2.LIZJ = 0.0f;
                                } else {
                                    nxY2.LIZJ = LIZ(nxY2.LIZIZ, bigDecimal);
                                }
                            }
                        }
                        jSONArray4.put(nxY.LIZ());
                    }
                    jSONObject2.put("disk_info", jSONArray4);
                }
                if (this.LIZJ != null) {
                    C04900Id.LIZ.LIZIZ(new RunnableC61023Nxc(this, j6, LIZ(this.LJJII), LIZ(this.LJJIII), LIZ(this.LJJIIJ)));
                }
                this.LJJII = null;
                this.LJJIII = null;
                this.LJJIIJ = null;
                this.LJIJJLI = null;
            }
            LIZ(new AnonymousClass14F("disk", "storageUsed", jSONObject, null, jSONObject2));
        } catch (Exception unused) {
        }
    }

    private void LIZ(File file, int i2, boolean z, List<C61019NxY> list) {
        if (i2 <= 2 && file != null && file.exists() && !this.LJJI.contains(file.getAbsolutePath())) {
            if (!file.isDirectory()) {
                C61019NxY nxY = new C61019NxY((byte) 0);
                nxY.LIZLLL = false;
                nxY.LIZ = file.getAbsolutePath();
                nxY.LIZIZ = file.length();
                if (!z) {
                    nxY.LJ = "custom";
                }
                list.add(nxY);
            } else if (z) {
                File[] listFiles = file.listFiles();
                if (!(listFiles == null || listFiles.length == 0)) {
                    for (File file2 : listFiles) {
                        if (file2 != null && file2.exists() && !this.LJJI.contains(file2.getAbsolutePath())) {
                            C61019NxY nxY2 = new C61019NxY((byte) 0);
                            nxY2.LIZLLL = file2.isDirectory();
                            nxY2.LIZ = file2.getAbsolutePath();
                            if (file2.isDirectory()) {
                                ArrayList arrayList = new ArrayList();
                                nxY2.LJFF = arrayList;
                                if (i2 == 2) {
                                    nxY2.LIZIZ = LIZ(file2);
                                }
                                LIZ(file2, i2 + 1, z, arrayList);
                                list.add(nxY2);
                            } else {
                                nxY2.LIZIZ = file2.length();
                                list.add(nxY2);
                            }
                        }
                    }
                }
            } else {
                C61019NxY nxY3 = new C61019NxY((byte) 0);
                nxY3.LIZLLL = true;
                nxY3.LJ = "custom";
                nxY3.LIZ = file.getAbsolutePath();
                nxY3.LIZIZ = LIZ(file);
                list.add(nxY3);
            }
        }
    }

    private boolean LIZ(C61019NxY nxY) {
        for (String str : this.LJJI) {
            if (nxY.LIZ.contains(str)) {
                return true;
            }
        }
        return false;
    }

    private long LIZIZ(long j) {
        long currentTimeMillis = System.currentTimeMillis() - j;
        if (currentTimeMillis < this.LJIJ || currentTimeMillis >= 62899200000L) {
            return 0;
        }
        return currentTimeMillis;
    }

    public final void LIZ(String str, long j, int i2) {
        if (j <= LJIJI) {
            if (this.LJJIII == null) {
                this.LJJIII = new AnonymousClass0JE<>(this.LJIIZILJ);
            }
            this.LJJIII.LIZ(new C61021Nxa(str, j, i2));
        }
    }

    public final void LIZ(String str, long j, int i2, long j2) {
        if (C04470Gm.LJ()) {
            String[] strArr = new String[1];
            String str2 = "appendutdatedFileQueue: path: " + str + ", size: " + j;
        }
        if (j >= 102400 && j <= LJIJI) {
            if (this.LJJIIJ == null) {
                this.LJJIIJ = new AnonymousClass0JE<>(this.LJIIZILJ);
            }
            this.LJJIIJ.LIZ(new C61022Nxb(str, j, i2, j2));
        }
    }

    @Override // X.AnonymousClass14U
    public final void LIZ(JSONObject jSONObject) {
        boolean optBoolean = jSONObject.optBoolean("dump_switch", true);
        this.LJIIL = optBoolean;
        if (optBoolean) {
            long currentTimeMillis = System.currentTimeMillis() - C04770Hq.LIZ.LIZ.getLong("check_disk_last_time", 0);
            if (currentTimeMillis < 86400000 && currentTimeMillis > 0) {
                this.LJIIJJI = true;
            }
            if (jSONObject.optInt("dump_threshold") > 0) {
                this.LIZ = ((long) jSONObject.optInt("dump_threshold")) * 1024 * 1024;
            }
            if (jSONObject.optInt("abnormal_folder_size") > 0) {
                this.LIZIZ = ((long) jSONObject.optInt("abnormal_folder_size")) * 1024 * 1024;
            }
            if (jSONObject.optInt("dump_top_count") > 0) {
                this.LJIIZILJ = jSONObject.optInt("dump_top_count");
            }
            if (jSONObject.optInt("outdated_days") > 0) {
                this.LJIJ = ((long) jSONObject.optInt("outdated_days")) * 86400000;
            }
            this.LJIL = AnonymousClass0J4.LIZJ(jSONObject, "disk_customed_paths");
            this.LJJ = AnonymousClass0J4.LIZIZ(jSONObject, "ignored_relative_paths");
        }
        if (jSONObject.optBoolean("enable_collect_apm6", false)) {
            this.LJIIJJI = true;
        }
    }

    @Override // X.AnonymousClass14U
    public final boolean LIZIZ() {
        return true;
    }

    @Override // X.AnonymousClass14U
    public final long LIZJ() {
        return 120000;
    }

    @Override // X.AnonymousClass14U
    public final void LJ() {
        List<C61019NxY> list;
        File file;
        boolean z = this.LJIILJJIL;
        if (!this.LJIIJJI && z) {
            if (LIZLLL == null) {
                Context context = C04470Gm.LIZ;
                try {
                    context.getPackageName();
                    if (C16490lC.LIZJ == null || !C16490lC.LJ) {
                        C16490lC.LIZJ = context.getFilesDir();
                    }
                    LIZLLL = C16490lC.LIZJ.getParent();
                    if (C16490lC.LIZIZ == null || !C16490lC.LJ) {
                        C16490lC.LIZIZ = context.getCacheDir();
                    }
                    this.LJ = C16490lC.LIZIZ.getAbsolutePath();
                    if (!TextUtils.isEmpty(null)) {
                        file = context.getExternalFilesDir(null);
                    } else {
                        if (C16490lC.LIZLLL == null || !C16490lC.LJ) {
                            C16490lC.LIZLLL = context.getExternalFilesDir(null);
                        }
                        file = C16490lC.LIZLLL;
                    }
                    LJFF = file.getParentFile().getAbsolutePath();
                    if (C16490lC.LIZ == null || !C16490lC.LJ) {
                        C16490lC.LIZ = context.getExternalCacheDir();
                    }
                    File file2 = C16490lC.LIZ;
                    if (file2 != null) {
                        this.LJI = file2.getAbsolutePath();
                    }
                    List<String> list2 = this.LJJ;
                    if (list2 != null) {
                        for (String str : list2) {
                            if (str.contains("internal")) {
                                this.LJJI.add(str.replace("internal", LIZLLL));
                            } else if (str.contains("external")) {
                                this.LJJI.add(str.replace("external", LJFF));
                            }
                        }
                    }
                    List<String> list3 = this.LJIL;
                    if (list3 != null) {
                        for (String str2 : list3) {
                            if (str2.contains("internal")) {
                                this.LJJIFFI.add(str2.replace("internal", LIZLLL));
                            } else if (str2.contains("external")) {
                                this.LJJIFFI.add(str2.replace("external", LJFF));
                            }
                        }
                    }
                } catch (Exception unused) {
                    this.LJIJJ = true;
                }
            }
            if (this.LJIJJ) {
                this.LJIIJJI = true;
                return;
            }
            if (this.LJIIL) {
                try {
                    byte b = 0;
                    String[] strArr = {LIZLLL, LJFF};
                    this.LJIJJLI = new ArrayList();
                    int i2 = 0;
                    while (true) {
                        String str3 = strArr[i2];
                        LIZ(new File(str3), 1, true, this.LJIJJLI);
                        File file3 = new File(str3);
                        C61020NxZ nxZ = new C61020NxZ(this, b);
                        nxZ.LIZ = str3;
                        nxZ.LIZIZ = new C61020NxZ(this, b);
                        File[] listFiles = file3.listFiles();
                        if (!(listFiles == null || listFiles.length == 0)) {
                            nxZ.LIZLLL = listFiles.length;
                            LinkedList linkedList = new LinkedList();
                            linkedList.offer(nxZ);
                            while (!linkedList.isEmpty()) {
                                int size = linkedList.size();
                                int i3 = 0;
                                while (i3 < size) {
                                    C61020NxZ nxZ2 = (C61020NxZ) linkedList.poll();
                                    if (nxZ2 != null) {
                                        String str4 = nxZ2.LIZ;
                                        File file4 = new File(str4);
                                        if (!file4.exists() || this.LJJI.contains(str4)) {
                                            nxZ2.LIZIZ.LIZLLL--;
                                        } else if (file4.isFile()) {
                                            long length = file4.length();
                                            if (length > 0) {
                                                if (C04470Gm.LJ()) {
                                                    String[] strArr2 = new String[1];
                                                    String str5 = "appendExceptionFileQueue: path: " + str4 + ", size: " + length;
                                                }
                                                if (length <= LJIJI) {
                                                    if (this.LJJII == null) {
                                                        this.LJJII = new AnonymousClass0JE<>(this.LJIIZILJ);
                                                    }
                                                    this.LJJII.LIZ(new C61021Nxa(str4, length, 1));
                                                }
                                            }
                                            if (nxZ2.LIZIZ != null) {
                                                nxZ2.LIZIZ.LIZ(length);
                                                if (!nxZ2.LIZIZ.LJ) {
                                                    long LIZIZ2 = LIZIZ(file4.lastModified());
                                                    if (LIZIZ2 > 0) {
                                                        LIZ(str4, length, 0, LIZIZ2);
                                                    }
                                                }
                                            }
                                        } else {
                                            File[] listFiles2 = file4.listFiles();
                                            if (listFiles2 == null || listFiles2.length == 0) {
                                                nxZ2.LIZIZ.LIZ(0);
                                            } else {
                                                nxZ2.LIZLLL = listFiles2.length;
                                                int length2 = listFiles2.length;
                                                int i4 = 0;
                                                while (i4 < length2) {
                                                    File file5 = listFiles2[i4];
                                                    C61020NxZ nxZ3 = new C61020NxZ(this, b);
                                                    nxZ3.LIZIZ = nxZ2;
                                                    nxZ3.LIZ = file5.getAbsolutePath();
                                                    if (file5.isDirectory() && !nxZ2.LJ) {
                                                        long LIZIZ3 = LIZIZ(file5.lastModified());
                                                        if (LIZIZ3 > 0) {
                                                            nxZ3.LJ = true;
                                                            nxZ3.LJFF = LIZIZ3;
                                                        }
                                                    }
                                                    linkedList.offer(nxZ3);
                                                    i4++;
                                                    b = 0;
                                                }
                                            }
                                        }
                                    }
                                    i3++;
                                    b = 0;
                                }
                            }
                        }
                        i2++;
                        b = 0;
                        if (i2 >= 2) {
                            break;
                        }
                    }
                    List<String> list4 = this.LJJIFFI;
                    if (list4 != null && list4.size() > 0) {
                        for (String str6 : this.LJJIFFI) {
                            LIZ(new File(str6), 1, false, this.LJIJJLI);
                        }
                    }
                    for (C61019NxY nxY : this.LJIJJLI) {
                        if ("normal".equals(nxY.LJ) && (list = nxY.LJFF) != null && !list.isEmpty()) {
                            for (C61019NxY nxY2 : list) {
                                nxY.LIZIZ += nxY2.LIZIZ;
                            }
                        }
                    }
                    LIZ(this.LJIIIIZZ + this.LJII, this.LJIIJ + this.LJIIIZ, Environment.getRootDirectory().getTotalSpace() + Environment.getDataDirectory().getTotalSpace(), Environment.getDataDirectory().getFreeSpace());
                    C04770Hq.LIZ.LIZ.edit().putLong("check_disk_last_time", System.currentTimeMillis()).apply();
                } catch (Throwable unused2) {
                }
            } else {
                LIZ(C05030Iq.LIZ(C04470Gm.LIZ), C05030Iq.LIZIZ(C04470Gm.LIZ), C05030Iq.LJII() + C05030Iq.LIZ(Environment.getRootDirectory()), Environment.getDataDirectory().getFreeSpace());
            }
            this.LJIIJJI = true;
            LJIIIIZZ();
            ActivityLifeObserver.getInstance().unregister(this);
            ((IConfigManager) AnonymousClass0Y8.LIZ(IConfigManager.class)).unregisterConfigListener(this);
        }
    }
}