package p138.p176.p177.p242.p269;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.PowerManager;
import android.os.Process;
import android.os.WorkSource;
import android.text.TextUtils;
import android.util.Log;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.concurrent.ThreadSafe;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p176.p177.p242.p246.p251.C4305;
import p138.p176.p177.p242.p246.p252.C4308;
import p138.p176.p177.p242.p246.p253.C4315;
import p138.p176.p177.p242.p246.p253.C4316;
import p138.p176.p177.p242.p246.p255.C4322;

/* JADX INFO: renamed from: ދ.ހ.֏.ހ.ކ.֏, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@ThreadSafe
public class C5054 {

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public static ScheduledExecutorService f15201;

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Object f15202;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final PowerManager.WakeLock f15203;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public WorkSource f15204;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final int f15205;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final String f15206;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final String f15207;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final Context f15208;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public boolean f15209;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final Map<String, Integer[]> f15210;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public int f15211;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public AtomicInteger f15212;

    /* JADX WARN: Removed duplicated region for block: B:51:0x0107  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x0113  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x0117  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C5054(Context context, int i, String str) {
        WorkSource workSource;
        WorkSource workSource2;
        ApplicationInfo applicationInfo;
        String packageName = context == null ? null : context.getPackageName();
        this.f15202 = this;
        this.f15209 = true;
        this.f15210 = new HashMap();
        Collections.synchronizedSet(new HashSet());
        this.f15212 = new AtomicInteger(0);
        C0567.m1857(context, (Object) "WakeLock: context must not be null");
        C0567.m1860(str, (Object) "WakeLock: wakeLockName must not be empty");
        this.f15205 = i;
        this.f15207 = null;
        this.f15208 = context.getApplicationContext();
        if ("com.google.android.gms".equals(context.getPackageName())) {
            this.f15206 = str;
        } else {
            String strValueOf = String.valueOf(str);
            this.f15206 = strValueOf.length() != 0 ? "*gcore*:".concat(strValueOf) : new String("*gcore*:");
        }
        this.f15203 = ((PowerManager) context.getSystemService("power")).newWakeLock(i, str);
        if (C4316.m7216(context)) {
            packageName = C4315.m7214(packageName) ? context.getPackageName() : packageName;
            if (context.getPackageManager() == null || packageName == null) {
                workSource = null;
                this.f15204 = workSource;
                if (workSource != null && C4316.m7216(this.f15208)) {
                    workSource2 = this.f15204;
                    if (workSource2 == null) {
                        workSource2.add(workSource);
                    } else {
                        this.f15204 = workSource;
                    }
                    try {
                        this.f15203.setWorkSource(this.f15204);
                    } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException e) {
                        Log.wtf("WakeLock", e.toString());
                    }
                }
            } else {
                try {
                    applicationInfo = C4322.m7223(context).f13621.getPackageManager().getApplicationInfo(packageName, 0);
                } catch (PackageManager.NameNotFoundException unused) {
                    Log.e("WorkSourceUtil", packageName.length() != 0 ? "Could not find package: ".concat(packageName) : new String("Could not find package: "));
                }
                if (applicationInfo == null) {
                    Log.e("WorkSourceUtil", packageName.length() != 0 ? "Could not get applicationInfo from package: ".concat(packageName) : new String("Could not get applicationInfo from package: "));
                    workSource = null;
                    this.f15204 = workSource;
                    if (workSource != null) {
                        workSource2 = this.f15204;
                        if (workSource2 == null) {
                        }
                        this.f15203.setWorkSource(this.f15204);
                    }
                } else {
                    int i2 = applicationInfo.uid;
                    workSource = new WorkSource();
                    Method method = C4316.f13609;
                    if (method != null) {
                        try {
                            method.invoke(workSource, Integer.valueOf(i2), packageName);
                        } catch (Exception e2) {
                            Log.wtf("WorkSourceUtil", "Unable to assign blame through WorkSource", e2);
                        }
                    } else {
                        Method method2 = C4316.f13608;
                        if (method2 != null) {
                            try {
                                method2.invoke(workSource, Integer.valueOf(i2));
                            } catch (Exception e3) {
                                Log.wtf("WorkSourceUtil", "Unable to assign blame through WorkSource", e3);
                            }
                        }
                    }
                    this.f15204 = workSource;
                    if (workSource != null) {
                    }
                }
            }
        }
        if (f15201 == null) {
            if (((C4305) C4303.m7052()) == null) {
                throw null;
            }
            f15201 = Executors.newSingleThreadScheduledExecutor();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x0065 A[Catch: all -> 0x00d8, TryCatch #0 {, blocks: (B:10:0x001c, B:12:0x0025, B:17:0x0038, B:19:0x003d, B:21:0x0047, B:28:0x006d, B:32:0x0093, B:34:0x009d, B:36:0x00a8, B:37:0x00bf, B:35:0x00a3, B:22:0x0056, B:24:0x0065, B:26:0x0069, B:14:0x0029, B:16:0x0031), top: B:45:0x001c }] */
    /* JADX WARN: Removed duplicated region for block: B:28:0x006d A[Catch: all -> 0x00d8, TryCatch #0 {, blocks: (B:10:0x001c, B:12:0x0025, B:17:0x0038, B:19:0x003d, B:21:0x0047, B:28:0x006d, B:32:0x0093, B:34:0x009d, B:36:0x00a8, B:37:0x00bf, B:35:0x00a3, B:22:0x0056, B:24:0x0065, B:26:0x0069, B:14:0x0029, B:16:0x0031), top: B:45:0x001c }] */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void m8536(long j) {
        this.f15212.incrementAndGet();
        String str = (!this.f15209 || TextUtils.isEmpty(null)) ? this.f15207 : null;
        synchronized (this.f15202) {
            boolean z = false;
            if ((!this.f15210.isEmpty() || this.f15211 > 0) && !this.f15203.isHeld()) {
                this.f15210.clear();
                this.f15211 = 0;
            }
            if (this.f15209) {
                Integer[] numArr = this.f15210.get(str);
                if (numArr == null) {
                    this.f15210.put(str, new Integer[]{1});
                    z = true;
                } else {
                    numArr[0] = Integer.valueOf(numArr[0].intValue() + 1);
                }
                if (!z) {
                }
            } else if (!this.f15209 && this.f15211 == 0) {
                C4308 c4308 = C4308.f13601;
                Context context = this.f15208;
                String strValueOf = String.valueOf(String.valueOf((((long) Process.myPid()) << 32) | ((long) System.identityHashCode(this.f15203))));
                String strValueOf2 = String.valueOf(TextUtils.isEmpty(str) ? "" : str);
                c4308.m7209(context, strValueOf2.length() != 0 ? strValueOf.concat(strValueOf2) : new String(strValueOf), 7, this.f15206, str, null, this.f15205, C4316.m7215(this.f15204), j);
                this.f15211++;
            }
        }
        this.f15203.acquire();
        if (j > 0) {
            f15201.schedule(new RunnableC5055(this), j, TimeUnit.MILLISECONDS);
        }
    }
}
