package com.appsflyer;

import android.content.Context;
import android.net.TrafficStats;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
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;
import ῲ.ᨨ.ῲ.C1806;

public class AFExecutor {

    /* renamed from: ˋ  reason: contains not printable characters */
    public static AFExecutor f1846;

    /* renamed from: ˊ  reason: contains not printable characters */
    public Executor f1847;

    /* renamed from: ˎ  reason: contains not printable characters */
    public ScheduledExecutorService f1848;

    /* renamed from: ˏ  reason: contains not printable characters */
    public final ThreadFactory f1849 = new AnonymousClass4();

    /* renamed from: ॱ  reason: contains not printable characters */
    public ScheduledExecutorService f1850;

    /* renamed from: com.appsflyer.AFExecutor$4  reason: invalid class name */
    public class AnonymousClass4 implements ThreadFactory {

        /* renamed from: com.appsflyer.AFExecutor$4$3  reason: invalid class name */
        public class AnonymousClass3 implements Runnable {

            /* renamed from: ˊ  reason: contains not printable characters */
            public /* synthetic */ Runnable f1852;

            public AnonymousClass3(Runnable runnable) {
                this.f1852 = runnable;
            }

            /* renamed from: ˋ  reason: contains not printable characters */
            public static boolean m1073(Context context, String str) {
                int r2 = C1806.m4687(context, str);
                StringBuilder sb = new StringBuilder("is Permission Available: ");
                sb.append(str);
                sb.append("; res: ");
                sb.append(r2);
                AFLogger.afRDLog(sb.toString());
                return r2 == 0;
            }

            public final void run() {
                TrafficStats.setThreadStatsTag("AppsFlyer".hashCode());
                this.f1852.run();
            }

            public AnonymousClass3() {
            }
        }

        public AnonymousClass4() {
        }

        /* renamed from: ˎ  reason: contains not printable characters */
        public static Map<String, String> m1072(Context context) {
            HashMap hashMap = new HashMap();
            try {
                DisplayMetrics displayMetrics = new DisplayMetrics();
                ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
                hashMap.put("x_px", String.valueOf(displayMetrics.widthPixels));
                hashMap.put("y_px", String.valueOf(displayMetrics.heightPixels));
                hashMap.put("d_dpi", String.valueOf(displayMetrics.densityDpi));
                hashMap.put("size", String.valueOf(context.getResources().getConfiguration().screenLayout & 15));
                hashMap.put("xdp", String.valueOf(displayMetrics.xdpi));
                hashMap.put("ydp", String.valueOf(displayMetrics.ydpi));
            } catch (Throwable th) {
                AFLogger.afErrorLog("Couldn't aggregate screen stats: ", th);
            }
            return hashMap;
        }

        public final Thread newThread(Runnable runnable) {
            return new Thread(new AnonymousClass3(runnable));
        }
    }

    public static AFExecutor getInstance() {
        if (f1846 == null) {
            f1846 = new AFExecutor();
        }
        return f1846;
    }

    public Executor getThreadPoolExecutor() {
        Executor executor = this.f1847;
        if (executor == null || ((executor instanceof ThreadPoolExecutor) && (((ThreadPoolExecutor) executor).isShutdown() || ((ThreadPoolExecutor) this.f1847).isTerminated() || ((ThreadPoolExecutor) this.f1847).isTerminating()))) {
            this.f1847 = Executors.newFixedThreadPool(2, this.f1849);
        }
        return this.f1847;
    }

    /* renamed from: ˏ  reason: contains not printable characters */
    public final ScheduledThreadPoolExecutor m1071() {
        ScheduledExecutorService scheduledExecutorService = this.f1850;
        if (scheduledExecutorService == null || scheduledExecutorService.isShutdown() || this.f1850.isTerminated()) {
            this.f1850 = Executors.newScheduledThreadPool(2, this.f1849);
        }
        return (ScheduledThreadPoolExecutor) this.f1850;
    }

    /* renamed from: ˏ  reason: contains not printable characters */
    public static void m1070(ExecutorService executorService) {
        try {
            AFLogger.afRDLog("shut downing executor ...");
            executorService.shutdown();
            executorService.awaitTermination(10, TimeUnit.SECONDS);
            if (!executorService.isTerminated()) {
                AFLogger.afRDLog("killing non-finished tasks");
            }
            executorService.shutdownNow();
        } catch (InterruptedException unused) {
            AFLogger.afRDLog("InterruptedException!!!");
            if (!executorService.isTerminated()) {
                AFLogger.afRDLog("killing non-finished tasks");
            }
            executorService.shutdownNow();
        } catch (Throwable th) {
            if (!executorService.isTerminated()) {
                AFLogger.afRDLog("killing non-finished tasks");
            }
            executorService.shutdownNow();
            throw th;
        }
    }
}
