package defpackage;

import android.os.Handler;
import android.os.Looper;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/* JADX INFO: renamed from: ᵪˉᵨ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3880 {

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public static final Object f14797 = new Object();

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public static volatile C3880 f14798;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final C0513 f14799;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final int f14800;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public volatile int f14801;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final C5519 f14802;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final ReentrantReadWriteLock f14803;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final C3664 f14804;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final Handler f14805;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final C1513 f14806;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final InterfaceC3885 f14807;

    public C3880(C2764 c2764) {
        ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
        this.f14803 = reentrantReadWriteLock;
        this.f14801 = 3;
        InterfaceC3885 interfaceC3885 = (InterfaceC3885) c2764.f11596;
        this.f14807 = interfaceC3885;
        int i = c2764.f11598;
        this.f14800 = i;
        this.f14806 = (C1513) c2764.f11597;
        this.f14805 = new Handler(Looper.getMainLooper());
        this.f14799 = new C0513(0);
        this.f14804 = new C3664(20);
        C5519 c5519 = new C5519(this);
        this.f14802 = c5519;
        reentrantReadWriteLock.writeLock().lock();
        if (i == 0) {
            try {
                this.f14801 = 0;
            } catch (Throwable th) {
                this.f14803.writeLock().unlock();
                throw th;
            }
        }
        reentrantReadWriteLock.writeLock().unlock();
        if (m8583() == 0) {
            try {
                interfaceC3885.mo4754(new C1784(c5519));
            } catch (Throwable th2) {
                m8586(th2);
            }
        }
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static C3880 m8582() {
        C3880 c3880;
        synchronized (f14797) {
            try {
                c3880 = f14798;
                if (!(c3880 != null)) {
                    throw new IllegalStateException("EmojiCompat is not initialized.\n\nYou must initialize EmojiCompat prior to referencing the EmojiCompat instance.\n\nThe most likely cause of this error is disabling the EmojiCompatInitializer\neither explicitly in AndroidManifest.xml, or by including\nandroidx.emoji2:emoji2-bundled.\n\nAutomatic initialization is typically performed by EmojiCompatInitializer. If\nyou are not expecting to initialize EmojiCompat manually in your application,\nplease check to ensure it has not been removed from your APK's manifest. You can\ndo this in Android Studio using Build > Analyze APK.\n\nIn the APK Analyzer, ensure that the startup entry for\nEmojiCompatInitializer and InitializationProvider is present in\n AndroidManifest.xml. If it is missing or contains tools:node=\"remove\", and you\nintend to use automatic configuration, verify:\n\n  1. Your application does not include emoji2-bundled\n  2. All modules do not contain an exclusion manifest rule for\n     EmojiCompatInitializer or InitializationProvider. For more information\n     about manifest exclusions see the documentation for the androidx startup\n     library.\n\nIf you intend to use emoji2-bundled, please call EmojiCompat.init. You can\nlearn more in the documentation for BundledEmojiCompatConfig.\n\nIf you intended to perform manual configuration, it is recommended that you call\nEmojiCompat.init immediately on application startup.\n\nIf you still cannot resolve this issue, please open a bug with your specific\nconfiguration to help improve error message.");
                }
            } finally {
            }
        }
        return c3880;
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final int m8583() {
        this.f14803.readLock().lock();
        try {
            return this.f14801;
        } finally {
            this.f14803.readLock().unlock();
        }
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final void m8584() {
        if (!(this.f14800 == 1)) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Set metadataLoadStrategy to LOAD_STRATEGY_MANUAL to execute manual loading");
            return;
        }
        if (m8583() == 1) {
            return;
        }
        this.f14803.writeLock().lock();
        try {
            if (this.f14801 == 0) {
                return;
            }
            this.f14801 = 0;
            this.f14803.writeLock().unlock();
            C5519 c5519 = this.f14802;
            C3880 c3880 = (C3880) c5519.f20843;
            try {
                c3880.f14807.mo4754(new C1784(c5519));
            } catch (Throwable th) {
                c3880.m8586(th);
            }
        } finally {
            this.f14803.writeLock().unlock();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:112:? A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:114:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:49:0x0089 A[Catch: all -> 0x007c, TRY_ENTER, TryCatch #3 {all -> 0x007c, blocks: (B:35:0x0054, B:38:0x0059, B:40:0x005d, B:42:0x006a, B:49:0x0089, B:51:0x0093, B:53:0x0096, B:55:0x009a, B:57:0x00aa, B:58:0x00ad), top: B:109:0x0054 }] */
    /* JADX WARN: Removed duplicated region for block: B:55:0x009a A[Catch: all -> 0x007c, TryCatch #3 {all -> 0x007c, blocks: (B:35:0x0054, B:38:0x0059, B:40:0x005d, B:42:0x006a, B:49:0x0089, B:51:0x0093, B:53:0x0096, B:55:0x009a, B:57:0x00aa, B:58:0x00ad), top: B:109:0x0054 }] */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00bc A[Catch: all -> 0x00f3, TRY_ENTER, TryCatch #0 {all -> 0x00f3, blocks: (B:62:0x00bc, B:65:0x00c4, B:68:0x00cc, B:47:0x007f), top: B:103:0x007f }] */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00c2  */
    /* JADX WARN: Removed duplicated region for block: B:88:0x0100  */
    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final CharSequence m8585(CharSequence charSequence, int i, int i2) throws Throwable {
        CharSequence charSequence2;
        Throwable th;
        int i3;
        int i4;
        C4677[] c4677Arr;
        C1127 c1127 = null;
        if (!(m8583() == 1)) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Not initialized yet");
            return null;
        }
        if (i < 0) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("start cannot be negative");
            return null;
        }
        if (i2 < 0) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("end cannot be negative");
            return null;
        }
        if (!(i <= i2)) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("start should be <= than end");
            return null;
        }
        if (charSequence == null) {
            return null;
        }
        if (!(i <= charSequence.length())) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("start should be < than charSequence length");
            return null;
        }
        if (!(i2 <= charSequence.length())) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("end should be < than charSequence length");
            return null;
        }
        if (charSequence.length() == 0 || i == i2) {
            return charSequence;
        }
        ᵯᵨᵲ r4 = (ᵯᵨᵲ) this.f14802.f20841;
        r4.getClass();
        boolean z = charSequence instanceof C5460;
        if (z) {
            ((C5460) charSequence).m11086();
        }
        if (z) {
            c1127 = new C1127((Spannable) charSequence);
            if (c1127 != null) {
            }
            i3 = i;
            i4 = i2;
            if (i3 == i4) {
            }
            ((C5460) charSequence2).m11083();
            return charSequence2;
        }
        try {
            if (!(charSequence instanceof Spannable)) {
                if ((charSequence instanceof Spanned) && ((Spanned) charSequence).nextSpanTransition(i - 1, i2 + 1, C4677.class) <= i2) {
                    c1127 = new C1127();
                    c1127.f4824 = false;
                    c1127.f4825 = new SpannableString(charSequence);
                }
                if (c1127 != null) {
                    while (i < r2) {
                    }
                }
                i3 = i;
                i4 = i2;
                if (i3 == i4) {
                    charSequence2 = charSequence;
                    if (!z) {
                    }
                }
                ((C5460) charSequence2).m11083();
                return charSequence2;
            }
            try {
                c1127 = new C1127((Spannable) charSequence);
                if (c1127 != null && (c4677Arr = (C4677[]) c1127.f4825.getSpans(i, i2, C4677.class)) != null && c4677Arr.length > 0) {
                    for (C4677 c4677 : c4677Arr) {
                        int spanStart = c1127.f4825.getSpanStart(c4677);
                        int spanEnd = c1127.f4825.getSpanEnd(c4677);
                        if (spanStart != i2) {
                            c1127.removeSpan(c4677);
                        }
                        i = Math.min(spanStart, i);
                        i2 = Math.max(spanEnd, i2);
                    }
                }
                i3 = i;
                i4 = i2;
                if (i3 == i4 || i3 >= charSequence.length()) {
                    charSequence2 = charSequence;
                    if (!z) {
                        return charSequence2;
                    }
                } else {
                    try {
                        charSequence2 = charSequence;
                    } catch (Throwable th2) {
                        charSequence2 = charSequence;
                        th = th2;
                    }
                    try {
                        C1127 c11272 = (C1127) r4.ˋʿᐧ(charSequence2, i3, i4, Integer.MAX_VALUE, false, new ˊˊᵞᵽ(20, c1127, (C3664) r4.ᵜᵪʾ, false));
                        if (c11272 != null) {
                            Spannable spannable = c11272.f4825;
                            if (z) {
                                ((C5460) charSequence2).m11083();
                            }
                            return spannable;
                        }
                        if (!z) {
                            return charSequence2;
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        th = th;
                        if (!z) {
                        }
                    }
                }
                ((C5460) charSequence2).m11083();
                return charSequence2;
            } catch (Throwable th4) {
                th = th4;
                charSequence2 = charSequence;
                th = th;
                if (!z) {
                }
            }
        } catch (Throwable th5) {
            th = th5;
            charSequence2 = charSequence;
        }
        if (!z) {
            throw th;
        }
        ((C5460) charSequence2).m11083();
        throw th;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m8586(Throwable th) {
        ArrayList arrayList = new ArrayList();
        this.f14803.writeLock().lock();
        try {
            this.f14801 = 2;
            arrayList.addAll(this.f14799);
            this.f14799.clear();
            this.f14803.writeLock().unlock();
            this.f14805.post(new RunnableC5577(arrayList, this.f14801, th));
        } catch (Throwable th2) {
            this.f14803.writeLock().unlock();
            throw th2;
        }
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final void m8587(AbstractC2212 abstractC2212) {
        ᵫﾞˌ.ᵷᵺʾᵖ(abstractC2212, "initCallback cannot be null");
        this.f14803.writeLock().lock();
        try {
            if (this.f14801 == 1 || this.f14801 == 2) {
                this.f14805.post(new RunnableC5577(Arrays.asList(abstractC2212), this.f14801, null));
            } else {
                this.f14799.add(abstractC2212);
            }
            this.f14803.writeLock().unlock();
        } catch (Throwable th) {
            this.f14803.writeLock().unlock();
            throw th;
        }
    }
}
