package h2;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import androidx.recyclerview.widget.i0;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/* JADX INFO: loaded from: classes.dex */
public final class c {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final Object f16642f = new Object();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static c f16643g;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f16644a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashMap f16645b = new HashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final HashMap f16646c = new HashMap();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final ArrayList f16647d = new ArrayList();

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

    public c(Context context) {
        this.f16644a = context;
        this.f16648e = new a(this, context.getMainLooper());
    }

    public static c a(Context context) {
        c cVar;
        synchronized (f16642f) {
            try {
                if (f16643g == null) {
                    f16643g = new c(context.getApplicationContext());
                }
                cVar = f16643g;
            } catch (Throwable th) {
                throw th;
            }
        }
        return cVar;
    }

    public final boolean b(Intent intent) {
        ArrayList arrayList;
        synchronized (this.f16645b) {
            try {
                String action = intent.getAction();
                String strResolveTypeIfNeeded = intent.resolveTypeIfNeeded(this.f16644a.getContentResolver());
                Uri data = intent.getData();
                String scheme = intent.getScheme();
                Set<String> categories = intent.getCategories();
                boolean z6 = (intent.getFlags() & 8) != 0;
                if (z6) {
                    Log.v("LocalBroadcastManager", "Resolving type " + strResolveTypeIfNeeded + " scheme " + scheme + " of intent " + intent);
                }
                ArrayList arrayList2 = (ArrayList) this.f16646c.get(intent.getAction());
                if (arrayList2 != null) {
                    if (z6) {
                        Log.v("LocalBroadcastManager", "Action list: " + arrayList2);
                    }
                    ArrayList arrayList3 = null;
                    int i6 = 0;
                    while (i6 < arrayList2.size()) {
                        b bVar = (b) arrayList2.get(i6);
                        if (z6) {
                            Log.v("LocalBroadcastManager", "Matching against filter " + bVar.f16638a);
                        }
                        if (bVar.f16640c) {
                            if (z6) {
                                Log.v("LocalBroadcastManager", "  Filter's target already added");
                            }
                            arrayList = arrayList2;
                        } else {
                            int iMatch = bVar.f16638a.match(action, strResolveTypeIfNeeded, scheme, data, categories, "LocalBroadcastManager");
                            if (iMatch >= 0) {
                                if (z6) {
                                    StringBuilder sb = new StringBuilder();
                                    arrayList = arrayList2;
                                    sb.append("  Filter matched!  match=0x");
                                    sb.append(Integer.toHexString(iMatch));
                                    Log.v("LocalBroadcastManager", sb.toString());
                                } else {
                                    arrayList = arrayList2;
                                }
                                if (arrayList3 == null) {
                                    arrayList3 = new ArrayList();
                                }
                                arrayList3.add(bVar);
                                bVar.f16640c = true;
                            } else {
                                arrayList = arrayList2;
                                if (z6) {
                                    Log.v("LocalBroadcastManager", "  Filter did not match: " + (iMatch != -4 ? iMatch != -3 ? iMatch != -2 ? iMatch != -1 ? "unknown reason" : "type" : "data" : "action" : "category"));
                                }
                            }
                        }
                        i6++;
                        arrayList2 = arrayList;
                    }
                    if (arrayList3 != null) {
                        for (int i7 = 0; i7 < arrayList3.size(); i7++) {
                            ((b) arrayList3.get(i7)).f16640c = false;
                        }
                        this.f16647d.add(new i0(2, intent, arrayList3));
                        if (!this.f16648e.hasMessages(1)) {
                            this.f16648e.sendEmptyMessage(1);
                        }
                        return true;
                    }
                }
                return false;
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
