package ῲ.㗽.K;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import com.facebook.internal.NativeProtocol;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/* renamed from: ῲ.㗽.K.K  reason: contains not printable characters */
/* compiled from: LocalBroadcastManager */
public final class C2243 {

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static C2243 f7732;

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final Object f7733 = new Object();

    /* renamed from: ʬ  reason: contains not printable characters */
    public final HashMap<String, ArrayList<C2244>> f7734 = new HashMap<>();

    /* renamed from: ඓ  reason: contains not printable characters */
    public final Handler f7735;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final HashMap<BroadcastReceiver, ArrayList<C2244>> f7736 = new HashMap<>();

    /* renamed from: K  reason: contains not printable characters */
    public final Context f7737;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final ArrayList<C2245> f7738 = new ArrayList<>();

    /* renamed from: ῲ.㗽.K.K$ʬ  reason: contains not printable characters */
    /* compiled from: LocalBroadcastManager */
    public static final class C2244 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public boolean f7739;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final BroadcastReceiver f7740;

        /* renamed from: K  reason: contains not printable characters */
        public final IntentFilter f7741;

        /* renamed from: 㸾  reason: contains not printable characters */
        public boolean f7742;

        public C2244(IntentFilter intentFilter, BroadcastReceiver broadcastReceiver) {
            this.f7741 = intentFilter;
            this.f7740 = broadcastReceiver;
        }

        public String toString() {
            StringBuilder sb = new StringBuilder(128);
            sb.append("Receiver{");
            sb.append(this.f7740);
            sb.append(" filter=");
            sb.append(this.f7741);
            if (this.f7742) {
                sb.append(" DEAD");
            }
            sb.append("}");
            return sb.toString();
        }
    }

    /* renamed from: ῲ.㗽.K.K$ῲ  reason: contains not printable characters */
    /* compiled from: LocalBroadcastManager */
    public static final class C2245 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final ArrayList<C2244> f7743;

        /* renamed from: K  reason: contains not printable characters */
        public final Intent f7744;

        public C2245(Intent intent, ArrayList<C2244> arrayList) {
            this.f7744 = intent;
            this.f7743 = arrayList;
        }
    }

    /* renamed from: ῲ.㗽.K.K$K  reason: contains not printable characters */
    /* compiled from: LocalBroadcastManager */
    public class HandlerC2246 extends Handler {
        public HandlerC2246(Looper looper) {
            super(looper);
        }

        public void handleMessage(Message message) {
            if (message.what != 1) {
                super.handleMessage(message);
            } else {
                C2243.this.m5867();
            }
        }
    }

    public C2243(Context context) {
        this.f7737 = context;
        this.f7735 = new HandlerC2246(context.getMainLooper());
    }

    /* renamed from: K  reason: contains not printable characters */
    public static C2243 m5866(Context context) {
        C2243 k;
        synchronized (f7733) {
            if (f7732 == null) {
                f7732 = new C2243(context.getApplicationContext());
            }
            k = f7732;
        }
        return k;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m5869(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter) {
        synchronized (this.f7736) {
            C2244 r1 = new C2244(intentFilter, broadcastReceiver);
            ArrayList<C2244> arrayList = this.f7736.get(broadcastReceiver);
            if (arrayList == null) {
                arrayList = new ArrayList<>(1);
                this.f7736.put(broadcastReceiver, arrayList);
            }
            arrayList.add(r1);
            for (int i = 0; i < intentFilter.countActions(); i++) {
                String action = intentFilter.getAction(i);
                ArrayList<C2244> arrayList2 = this.f7734.get(action);
                if (arrayList2 == null) {
                    arrayList2 = new ArrayList<>(1);
                    this.f7734.put(action, arrayList2);
                }
                arrayList2.add(r1);
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m5868(BroadcastReceiver broadcastReceiver) {
        synchronized (this.f7736) {
            ArrayList<C2244> remove = this.f7736.remove(broadcastReceiver);
            if (remove != null) {
                for (int size = remove.size() - 1; size >= 0; size--) {
                    C2244 r4 = remove.get(size);
                    r4.f7742 = true;
                    for (int i = 0; i < r4.f7741.countActions(); i++) {
                        String action = r4.f7741.getAction(i);
                        ArrayList<C2244> arrayList = this.f7734.get(action);
                        if (arrayList != null) {
                            for (int size2 = arrayList.size() - 1; size2 >= 0; size2--) {
                                C2244 r9 = arrayList.get(size2);
                                if (r9.f7740 == broadcastReceiver) {
                                    r9.f7742 = true;
                                    arrayList.remove(size2);
                                }
                            }
                            if (arrayList.size() <= 0) {
                                this.f7734.remove(action);
                            }
                        }
                    }
                }
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m5870(Intent intent) {
        String str;
        ArrayList<C2244> arrayList;
        int i;
        String str2;
        ArrayList arrayList2;
        synchronized (this.f7736) {
            String action = intent.getAction();
            String resolveTypeIfNeeded = intent.resolveTypeIfNeeded(this.f7737.getContentResolver());
            Uri data = intent.getData();
            String scheme = intent.getScheme();
            Set<String> categories = intent.getCategories();
            boolean z = (intent.getFlags() & 8) != 0;
            if (z) {
                Log.v("LocalBroadcastManager", "Resolving type " + resolveTypeIfNeeded + " scheme " + scheme + " of intent " + intent);
            }
            ArrayList<C2244> arrayList3 = this.f7734.get(intent.getAction());
            if (arrayList3 != null) {
                if (z) {
                    Log.v("LocalBroadcastManager", "Action list: " + arrayList3);
                }
                ArrayList arrayList4 = null;
                int i2 = 0;
                while (i2 < arrayList3.size()) {
                    C2244 r5 = arrayList3.get(i2);
                    if (z) {
                        Log.v("LocalBroadcastManager", "Matching against filter " + r5.f7741);
                    }
                    if (r5.f7739) {
                        if (z) {
                            Log.v("LocalBroadcastManager", "  Filter's target already added");
                        }
                        i = i2;
                        arrayList = arrayList3;
                        str2 = action;
                        str = resolveTypeIfNeeded;
                        arrayList2 = arrayList4;
                    } else {
                        str2 = action;
                        arrayList2 = arrayList4;
                        i = i2;
                        arrayList = arrayList3;
                        str = resolveTypeIfNeeded;
                        int match = r5.f7741.match(action, resolveTypeIfNeeded, scheme, data, categories, "LocalBroadcastManager");
                        if (match >= 0) {
                            if (z) {
                                Log.v("LocalBroadcastManager", "  Filter matched!  match=0x" + Integer.toHexString(match));
                            }
                            arrayList4 = arrayList2 == null ? new ArrayList() : arrayList2;
                            arrayList4.add(r5);
                            r5.f7739 = true;
                            i2 = i + 1;
                            action = str2;
                            arrayList3 = arrayList;
                            resolveTypeIfNeeded = str;
                        } else if (z) {
                            Log.v("LocalBroadcastManager", "  Filter did not match: " + (match != -4 ? match != -3 ? match != -2 ? match != -1 ? "unknown reason" : "type" : "data" : NativeProtocol.WEB_DIALOG_ACTION : "category"));
                        }
                    }
                    arrayList4 = arrayList2;
                    i2 = i + 1;
                    action = str2;
                    arrayList3 = arrayList;
                    resolveTypeIfNeeded = str;
                }
                if (arrayList4 != null) {
                    for (int i3 = 0; i3 < arrayList4.size(); i3++) {
                        ((C2244) arrayList4.get(i3)).f7739 = false;
                    }
                    this.f7738.add(new C2245(intent, arrayList4));
                    if (!this.f7735.hasMessages(1)) {
                        this.f7735.sendEmptyMessage(1);
                    }
                    return true;
                }
            }
            return false;
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:11:0x001d, code lost:
        if (r2 >= r1.length) goto L_0x0000;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:12:0x001f, code lost:
        r3 = r1[r2];
        r4 = r3.f7743.size();
        r5 = 0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0028, code lost:
        if (r5 >= r4) goto L_0x0042;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:14:0x002a, code lost:
        r6 = r3.f7743.get(r5);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:15:0x0034, code lost:
        if (r6.f7742 != false) goto L_0x003f;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:16:0x0036, code lost:
        r6.f7740.onReceive(r9.f7737, r3.f7744);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:17:0x003f, code lost:
        r5 = r5 + 1;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:18:0x0042, code lost:
        r2 = r2 + 1;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:9:0x001a, code lost:
        r2 = 0;
     */
    /* renamed from: K  reason: contains not printable characters */
    public void m5867() {
        while (true) {
            synchronized (this.f7736) {
                int size = this.f7738.size();
                if (size > 0) {
                    C2245[] r1 = new C2245[size];
                    this.f7738.toArray(r1);
                    this.f7738.clear();
                } else {
                    return;
                }
            }
        }
    }
}
