package com.ss.android.ugc.aweme.legoImp.task;

import X.0Ll;
import X.2nK;
import X.4Ms;
import X.6J4;
import X.C22428Zd;
import X.C22438Ze;
import X.C25518ec;
import X.C42869Ft;
import X.C42909Fx;
import X.C43519Ig;
import android.content.Context;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.abmock.SettingsManager;
import com.bytedance.keva.Keva;
import java.io.File;
import java.util.List;
import kotlin.h.b.n;

public final class LiveGiftAssetStatisticTask implements C22438Ze {
    static {
        Covode.recordClassIndex(90515);
    }

    public final boolean meetTrigger() {
        return true;
    }

    public final String prefix() {
        return "task_";
    }

    public final boolean serialExecute() {
        return false;
    }

    public final int targetProcess() {
        return 1;
    }

    public final List triggerOtherLegoComponents() {
        return null;
    }

    public final C42869Ft triggerType() {
        return C22428Zd.LIZ(this);
    }

    public final C42909Fx scenesType() {
        return C42909Fx.DEFAULT;
    }

    public final C25518ec type() {
        return C25518ec.APP_BACKGROUND;
    }

    public static final class LiveEnableReportEffectCacheSizeAfterAppLaunch {
        public static final boolean DEFAULT = true;
        public static final LiveEnableReportEffectCacheSizeAfterAppLaunch INSTANCE = new LiveEnableReportEffectCacheSizeAfterAppLaunch();

        static {
            Covode.recordClassIndex(90516);
        }

        public final boolean getValue() {
            return SettingsManager.LIZ().LIZ("enable_report_gift_asset_size_background", true);
        }
    }

    public final String key() {
        return getClass().getSimpleName();
    }

    public final void run(Context context) {
        File parentFile;
        String absolutePath;
        int i;
        String[] list;
        Keva repo = Keva.getRepo("live_gift");
        if (LiveEnableReportEffectCacheSizeAfterAppLaunch.INSTANCE.getValue() && context != null) {
            if (4Ms.LIZJ == null || !4Ms.LJ) {
                4Ms.LIZJ = context.getFilesDir();
            }
            File file = 4Ms.LIZJ;
            if (file != null && (parentFile = file.getParentFile()) != null && (absolutePath = new File(parentFile, "app_assets").getAbsolutePath()) != null) {
                long currentTimeMillis = System.currentTimeMillis();
                long j = currentTimeMillis - repo.getLong("gift_asset_disk_timestamp", 0);
                if (j > 86400000) {
                    long elapsedRealtime = SystemClock.elapsedRealtime();
                    long LIZ = 0Ll.LIZ(absolutePath);
                    long elapsedRealtime2 = SystemClock.elapsedRealtime();
                    File file2 = new File(absolutePath);
                    if (!file2.exists() || !file2.isDirectory() || (list = file2.list(C43519Ig.LIZ)) == null) {
                        i = 0;
                    } else {
                        i = list.length;
                    }
                    long elapsedRealtime3 = SystemClock.elapsedRealtime();
                    6J4 r8 = new 6J4();
                    r8.LIZ("cache_size", LIZ / 1048576);
                    r8.LIZ("calculate_cache_size_duration", elapsedRealtime2 - elapsedRealtime);
                    r8.LIZ("local_resources_count", i);
                    r8.LIZ("calculate_local_resources_count_duration", elapsedRealtime3 - elapsedRealtime2);
                    File dataDirectory = Environment.getDataDirectory();
                    n.LIZIZ(dataDirectory, "");
                    StatFs statFs = new StatFs(dataDirectory.getPath());
                    r8.LIZ("free_disk_size", (statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong()) / 1048576);
                    r8.LIZ("last_report_pass_interval", j);
                    r8.LIZ("total_duration", elapsedRealtime3 - elapsedRealtime);
                    2nK.LIZ("livesdk_gift_assets_info", r8.LIZ);
                    repo.storeLong("gift_asset_disk_timestamp", currentTimeMillis);
                }
            }
        }
    }
}
