package p7;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Looper;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.h71;
import com.google.android.gms.internal.ads.h81;
import com.google.android.gms.internal.ads.na1;
import com.google.android.gms.internal.ads.sl0;
import com.google.android.gms.internal.ads.sq0;
import com.google.android.gms.internal.ads.tn;
import com.google.android.gms.internal.ads.uz0;
import com.google.common.base.Optional;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes2.dex */
public final class i0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f31694a;

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Object f31699f;

    public i0() {
        this.f31694a = 0;
        this.f31695b = false;
        this.f31698e = new WeakHashMap();
        this.f31697d = new e.i0(this);
    }

    public final synchronized void a(Context context) {
        try {
            if (this.f31695b) {
                return;
            }
            Context applicationContext = context.getApplicationContext();
            this.f31699f = applicationContext;
            if (applicationContext == null) {
                this.f31699f = context;
            }
            ao.a((Context) this.f31699f);
            tn tnVar = ao.f9180z4;
            n7.y yVar = n7.y.f31093e;
            this.f31696c = ((Boolean) yVar.f31096c.b(tnVar)).booleanValue();
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.intent.action.SCREEN_ON");
            intentFilter.addAction("android.intent.action.SCREEN_OFF");
            intentFilter.addAction("android.intent.action.USER_PRESENT");
            if (!((Boolean) yVar.f31096c.b(ao.f8938kc)).booleanValue() || Build.VERSION.SDK_INT < 33) {
                ((Context) this.f31699f).registerReceiver((BroadcastReceiver) this.f31697d, intentFilter);
            } else {
                ((Context) this.f31699f).registerReceiver((BroadcastReceiver) this.f31697d, intentFilter, 4);
            }
            this.f31695b = true;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final void b(boolean z10) {
        if (this.f31696c == z10) {
            return;
        }
        this.f31696c = z10;
        if (this.f31695b) {
            d(true, z10);
        }
    }

    public final synchronized void c(Context context, BroadcastReceiver broadcastReceiver) {
        if (this.f31696c) {
            ((Map) this.f31698e).remove(broadcastReceiver);
        } else {
            context.unregisterReceiver(broadcastReceiver);
        }
    }

    public final void d(final boolean z10, final boolean z11) {
        int i10 = 1;
        boolean z12 = z10 && z11;
        Object obj = this.f31698e;
        if (z12) {
            ((h81) ((sq0) obj)).c(new com.google.android.gms.ads.nonagon.signalgeneration.m0(this, z10, z11, i10));
            return;
        }
        uz0 uz0Var = (uz0) this.f31697d;
        Objects.requireNonNull(uz0Var);
        final na1 na1Var = new na1(uz0Var, 2);
        ((h81) ((sq0) this.f31699f)).f12056a.postDelayed(na1Var, 1000L);
        ((h81) ((sq0) obj)).c(new Runnable() { // from class: com.google.android.gms.internal.ads.oc1
            @Override // java.lang.Runnable
            public final void run() {
                p7.i0 i0Var = this.f15006a;
                ((h81) ((sq0) i0Var.f31699f)).f12056a.removeCallbacks(na1Var);
                ((uz0) i0Var.f31697d).g(z10, z11);
            }
        });
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x007e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final String toString() {
        boolean zIsEmpty;
        switch (this.f31694a) {
            case 2:
                boolean z10 = this.f31695b;
                boolean z11 = this.f31696c;
                StringBuilder sb = new StringBuilder(32);
                sb.append((String) this.f31697d);
                sb.append('{');
                String str = "";
                for (xyz.stream.utils.t tVar = (xyz.stream.utils.t) ((xyz.stream.utils.t) this.f31698e).f36174d; tVar != null; tVar = (xyz.stream.utils.t) tVar.f36174d) {
                    Object obj = tVar.f36173c;
                    if (obj == null) {
                        if (!z10) {
                            sb.append(str);
                            String str2 = (String) tVar.f36172b;
                            if (str2 != null) {
                                sb.append(str2);
                                sb.append('=');
                            }
                            if (obj == null || !obj.getClass().isArray()) {
                                sb.append(obj);
                            } else {
                                String strDeepToString = Arrays.deepToString(new Object[]{obj});
                                sb.append((CharSequence) strDeepToString, 1, strDeepToString.length() - 1);
                            }
                            str = ", ";
                        }
                    } else if (z11) {
                        if (!(obj instanceof CharSequence)) {
                            if (obj instanceof Collection) {
                                zIsEmpty = ((Collection) obj).isEmpty();
                            } else if (obj instanceof Map) {
                                zIsEmpty = ((Map) obj).isEmpty();
                            } else if (obj instanceof Optional) {
                                zIsEmpty = !((Optional) obj).c();
                            } else if (!obj.getClass().isArray() || Array.getLength(obj) != 0) {
                            }
                            if (!zIsEmpty) {
                            }
                        } else if (((CharSequence) obj).length() == 0) {
                        }
                    }
                }
                sb.append('}');
                return sb.toString();
            default:
                return super.toString();
        }
    }

    public i0(Context context, Looper looper, sl0 sl0Var) {
        this.f31694a = 1;
        this.f31697d = new uz0(context.getApplicationContext());
        h71 h71Var = (h71) sl0Var;
        this.f31698e = h71Var.zzd(looper, null);
        this.f31699f = h71Var.zzd(Looper.getMainLooper(), null);
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ i0(String str, int i10) {
        this(str);
        this.f31694a = 2;
    }

    public i0(String str) {
        this.f31694a = 2;
        xyz.stream.utils.t tVar = new xyz.stream.utils.t(18, 0);
        this.f31698e = tVar;
        this.f31699f = tVar;
        this.f31695b = false;
        this.f31696c = false;
        this.f31697d = str;
    }
}
