package com.google.android.gms.internal.ads;

import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.content.Context;
import android.graphics.Rect;
import android.os.Process;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes2.dex */
public final class wj extends Thread {
    public final boolean Q;
    public final boolean R;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public boolean f18082a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f18083b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object f18084c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final bp f18085d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f18086e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final int f18087f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int f18088g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final int f18089h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final int f18090i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final int f18091j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final int f18092k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final int f18093l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final String f18094m;

    public wj() {
        bp bpVar = new bp();
        this.f18082a = false;
        this.f18083b = false;
        this.f18085d = bpVar;
        this.f18084c = new Object();
        this.f18087f = ((Long) gp.f11823d.j()).intValue();
        this.f18088g = ((Long) gp.f11820a.j()).intValue();
        this.f18089h = ((Long) gp.f11824e.j()).intValue();
        this.f18090i = ((Long) gp.f11822c.j()).intValue();
        tn tnVar = ao.f9077t0;
        n7.y yVar = n7.y.f31093e;
        this.f18091j = ((Integer) yVar.f31096c.b(tnVar)).intValue();
        tn tnVar2 = ao.f9094u0;
        yn ynVar = yVar.f31096c;
        this.f18092k = ((Integer) ynVar.b(tnVar2)).intValue();
        this.f18093l = ((Integer) ynVar.b(ao.f9110v0)).intValue();
        this.f18086e = ((Long) gp.f11825f.j()).intValue();
        this.f18094m = (String) ynVar.b(ao.f9144x0);
        this.Q = ((Boolean) ynVar.b(ao.f9161y0)).booleanValue();
        this.R = ((Boolean) ynVar.b(ao.z0)).booleanValue();
        ((Boolean) ynVar.b(ao.A0)).booleanValue();
        setName("ContentFetchTask");
    }

    public final void a() {
        synchronized (this.f18084c) {
            this.f18083b = true;
            StringBuilder sb = new StringBuilder(40);
            sb.append("ContentFetchThread: paused, pause = true");
            q7.j.a(sb.toString());
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:16:0x0042, code lost:
    
        if (r3.importance != 100) goto L42;
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x0048, code lost:
    
        if (r2.inKeyguardRestrictedInputMode() != false) goto L42;
     */
    /* JADX WARN: Code restructure failed: missing block: B:19:0x004a, code lost:
    
        r0 = (android.os.PowerManager) r0.getSystemService("power");
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x0052, code lost:
    
        if (r0 == null) goto L42;
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x0058, code lost:
    
        if (r0.isScreenOn() == false) goto L42;
     */
    /* JADX WARN: Code restructure failed: missing block: B:23:0x005a, code lost:
    
        r0 = m7.n.C.f30468g.zzd();
     */
    /* JADX WARN: Code restructure failed: missing block: B:24:0x0062, code lost:
    
        if (r0 != null) goto L29;
     */
    /* JADX WARN: Code restructure failed: missing block: B:25:0x0064, code lost:
    
        q7.j.a("ContentFetchThread: no activity. Sleeping.");
        a();
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x006d, code lost:
    
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:29:0x006f, code lost:
    
        r1 = null;
     */
    /* JADX WARN: Code restructure failed: missing block: B:31:0x0074, code lost:
    
        if (r0.getWindow() == null) goto L38;
     */
    /* JADX WARN: Code restructure failed: missing block: B:33:0x007e, code lost:
    
        if (r0.getWindow().getDecorView() == null) goto L38;
     */
    /* JADX WARN: Code restructure failed: missing block: B:34:0x0080, code lost:
    
        r1 = r0.getWindow().getDecorView().findViewById(android.R.id.content);
     */
    /* JADX WARN: Code restructure failed: missing block: B:36:0x0090, code lost:
    
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x0091, code lost:
    
        m7.n.C.f30469h.d("ContentFetchTask.extractContent", r0);
        q7.j.a("Failed getting root view of activity. Content not extracted.");
     */
    /* JADX WARN: Code restructure failed: missing block: B:45:0x00c5, code lost:
    
        m7.n.C.f30469h.d("ContentFetchTask.run", r0);
     */
    /* JADX WARN: Removed duplicated region for block: B:66:0x00d1 A[EXC_TOP_SPLITTER, LOOP:1: B:66:0x00d1->B:71:0x00d1, LOOP_START, SYNTHETIC] */
    @Override // java.lang.Thread, java.lang.Runnable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void run() {
        Object obj;
        Context contextZze;
        List<ActivityManager.RunningAppProcessInfo> runningAppProcesses;
        View viewFindViewById;
        while (true) {
            try {
                contextZze = m7.n.C.f30468g.zze();
            } catch (Throwable th) {
                m7.n.C.f30469h.d("ContentFetchTask.isInForeground", th);
            }
            if (contextZze != null) {
                ActivityManager activityManager = (ActivityManager) contextZze.getSystemService("activity");
                KeyguardManager keyguardManager = (KeyguardManager) contextZze.getSystemService("keyguard");
                if (activityManager != null && keyguardManager != null && (runningAppProcesses = activityManager.getRunningAppProcesses()) != null) {
                    Iterator<ActivityManager.RunningAppProcessInfo> it = runningAppProcesses.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        ActivityManager.RunningAppProcessInfo next = it.next();
                        if (Process.myPid() == next.pid) {
                            break;
                        }
                    }
                    Thread.sleep(this.f18086e * 1000);
                }
                obj = this.f18084c;
                synchronized (obj) {
                    while (this.f18083b) {
                        try {
                            q7.j.a("ContentFetchTask: waiting");
                            obj.wait();
                        } catch (InterruptedException unused) {
                        }
                    }
                }
            }
            q7.j.a("ContentFetchTask: sleeping");
            a();
            Thread.sleep(this.f18086e * 1000);
            obj = this.f18084c;
            synchronized (obj) {
            }
        }
        if (viewFindViewById != null) {
            viewFindViewById.post(new bv(this, viewFindViewById));
        }
        Thread.sleep(this.f18086e * 1000);
        obj = this.f18084c;
        synchronized (obj) {
        }
    }

    @VisibleForTesting
    public final vj zzc(@Nullable View view, pj pjVar) {
        if (view == null) {
            return new vj(this, 0, 0);
        }
        boolean globalVisibleRect = view.getGlobalVisibleRect(new Rect());
        if ((view instanceof TextView) && !(view instanceof EditText)) {
            CharSequence text = ((TextView) view).getText();
            if (TextUtils.isEmpty(text)) {
                return new vj(this, 0, 0);
            }
            pjVar.b(text.toString(), globalVisibleRect, view.getX(), view.getY(), view.getWidth(), view.getHeight());
            return new vj(this, 1, 0);
        }
        if ((view instanceof WebView) && !(view instanceof x50)) {
            WebView webView = (WebView) view;
            synchronized (pjVar.f15432g) {
                pjVar.f15438m++;
            }
            webView.post(new d8.i(this, pjVar, webView, globalVisibleRect));
            return new vj(this, 0, 1);
        }
        if (!(view instanceof ViewGroup)) {
            return new vj(this, 0, 0);
        }
        ViewGroup viewGroup = (ViewGroup) view;
        int i10 = 0;
        int i11 = 0;
        for (int i12 = 0; i12 < viewGroup.getChildCount(); i12++) {
            vj vjVarZzc = zzc(viewGroup.getChildAt(i12), pjVar);
            i10 += vjVarZzc.f17650a;
            i11 += vjVarZzc.f17651b;
        }
        return new vj(this, i10, i11);
    }
}
