package com.ss.android.ugc.aweme.app.launch;

import X.4Ms;
import X.4Tz;
import X.C11817xc;
import X.C146485f;
import X.C29958lm;
import X.C29968ln;
import X.F7R;
import X.Lnj;
import X.M12;
import X.S9K;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.keva.Keva;
import com.ss.android.ugc.aweme.launcher.service.system.ISystemServiceApi;
import java.io.File;

public final class SystemServiceApiImpl implements ISystemServiceApi {
    static {
        Covode.recordClassIndex(53341);
    }

    public final F7R LIZ() {
        return new 4Tz();
    }

    public static ISystemServiceApi LIZIZ() {
        MethodCollector.i(2099);
        ISystemServiceApi iSystemServiceApi = (ISystemServiceApi) Lnj.LIZ(ISystemServiceApi.class, false);
        if (iSystemServiceApi != null) {
            MethodCollector.o(2099);
            return iSystemServiceApi;
        }
        Object LIZIZ = Lnj.LIZIZ(ISystemServiceApi.class, false);
        if (LIZIZ != null) {
            ISystemServiceApi iSystemServiceApi2 = (ISystemServiceApi) LIZIZ;
            MethodCollector.o(2099);
            return iSystemServiceApi2;
        }
        if (Lnj.LJJJJJ == null) {
            synchronized (ISystemServiceApi.class) {
                try {
                    if (Lnj.LJJJJJ == null) {
                        Lnj.LJJJJJ = new SystemServiceApiImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(2099);
                    throw th;
                }
            }
        }
        SystemServiceApiImpl systemServiceApiImpl = (SystemServiceApiImpl) Lnj.LJJJJJ;
        MethodCollector.o(2099);
        return systemServiceApiImpl;
    }

    public final void LIZ(boolean z) {
        S9K.LIZIZ.LIZ(z);
    }

    public final void LIZ(Context context) {
        M12.LIZ(context);
        if (Keva.getRepoSync("ab_repo_cold_boot", 1).getInt("prefetcher_cold_start", 0) == 1 && C11817xc.LIZ(context)) {
            C146485f.LIZIZ("prefetcher");
            long j = Keva.getRepoSync("ab_repo_cold_boot", 1).getLong("prefetcher_step_size", 524288);
            long j2 = Keva.getRepoSync("ab_repo_cold_boot", 1).getLong("prefetcher_step_sleep_duration", 15000);
            C29958lm.LJIJ = C29958lm.LJIIZILJ;
            C29958lm.LJIJI = j;
            C29958lm.LJIJJ = j2;
            HandlerThread handlerThread = new HandlerThread("io_prefetcher");
            handlerThread.start();
            new File(C29958lm.LJIIIZ).exists();
            File file = new File("/proc/" + Process.myPid() + "/smaps");
            if (4Ms.LIZ == null || !4Ms.LJ) {
                4Ms.LIZ = context.getExternalCacheDir();
            }
            C29958lm.LIZ(file, new File(4Ms.LIZ, C29958lm.LJIIJ));
            Handler handler = new Handler(handlerThread.getLooper());
            C29958lm.LIZIZ = handler;
            handler.post(new C29968ln());
        }
    }
}
