package com.appsflyer.internal;

import X.8e1;
import X.8e2;
import X.8eG;
import X.8eL;
import android.net.TrafficStats;
import com.appsflyer.AFLogger;
import com.bytedance.covode.number.Covode;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public final class k {
    public static k values;
    public ScheduledExecutorService AFInAppEventParameterName;
    public final ThreadFactory AFInAppEventType = new ThreadFactory() {
        static {
            Covode.recordClassIndex(2705);
        }

        public final Thread newThread(final Runnable runnable) {
            return new Thread(new Runnable() {
                static {
                    Covode.recordClassIndex(2706);
                }

                public final void run() {
                    TrafficStats.setThreadStatsTag("AppsFlyer".hashCode());
                    runnable.run();
                }
            });
        }
    };
    public Executor AFKeystoreWrapper;
    public ScheduledExecutorService valueOf;

    static {
        Covode.recordClassIndex(2704);
    }

    public final ScheduledThreadPoolExecutor AFInAppEventType() {
        ScheduledExecutorService scheduledExecutorService = this.valueOf;
        if (scheduledExecutorService == null || scheduledExecutorService.isShutdown() || this.valueOf.isTerminated()) {
            this.valueOf = INVOKESTATIC_com_appsflyer_internal_k_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newScheduledThreadPool(2, this.AFInAppEventType);
        }
        return (ScheduledThreadPoolExecutor) this.valueOf;
    }

    public final Executor AFKeystoreWrapper() {
        Executor executor = this.AFKeystoreWrapper;
        if (executor == null || ((executor instanceof ThreadPoolExecutor) && (((ThreadPoolExecutor) executor).isShutdown() || ((ThreadPoolExecutor) this.AFKeystoreWrapper).isTerminated() || ((ThreadPoolExecutor) this.AFKeystoreWrapper).isTerminating()))) {
            this.AFKeystoreWrapper = INVOKESTATIC_com_appsflyer_internal_k_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newFixedThreadPool(2, this.AFInAppEventType);
        }
        return this.AFKeystoreWrapper;
    }

    public static void valueOf(ExecutorService executorService) {
        try {
            AFLogger.AFInAppEventParameterName("shut downing executor ...");
            executorService.shutdown();
            executorService.awaitTermination(10, TimeUnit.SECONDS);
            if (!executorService.isTerminated()) {
                AFLogger.AFInAppEventParameterName("killing non-finished tasks");
            }
            executorService.shutdownNow();
        } catch (InterruptedException unused) {
            AFLogger.AFInAppEventParameterName("InterruptedException!!!");
            if (!executorService.isTerminated()) {
                AFLogger.AFInAppEventParameterName("killing non-finished tasks");
            }
            executorService.shutdownNow();
        } catch (Throwable th) {
            if (!executorService.isTerminated()) {
                AFLogger.AFInAppEventParameterName("killing non-finished tasks");
            }
            executorService.shutdownNow();
            throw th;
        }
    }

    public static ExecutorService INVOKESTATIC_com_appsflyer_internal_k_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newFixedThreadPool(int i, ThreadFactory threadFactory) {
        8e1 LIZ = 8e2.LIZ(8eG.FIXED);
        LIZ.LIZJ = i;
        LIZ.LJI = threadFactory;
        return 8eL.LIZ(LIZ.LIZ());
    }

    public static ScheduledExecutorService INVOKESTATIC_com_appsflyer_internal_k_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newScheduledThreadPool(int i, ThreadFactory threadFactory) {
        8e1 LIZ = 8e2.LIZ(8eG.SCHEDULED);
        LIZ.LIZJ = i;
        LIZ.LJI = threadFactory;
        return (ScheduledExecutorService) 8eL.LIZ(LIZ.LIZ());
    }
}
