package c.j.a;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.inputmethod.EditorInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/* JADX INFO: compiled from: EmojiCompat.java */
/* JADX INFO: loaded from: classes.dex */
public class i {
    public static final Object a = new Object();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static volatile i f1519b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Set<e> f1521d;

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

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

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

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

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

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

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

    /* JADX INFO: compiled from: EmojiCompat.java */
    public static final class a extends b {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public volatile l f1529b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public volatile o f1530c;

        /* JADX INFO: renamed from: c.j.a.i$a$a, reason: collision with other inner class name */
        /* JADX INFO: compiled from: EmojiCompat.java */
        public class C0013a extends h {
            public C0013a() {
            }

            @Override // c.j.a.i.h
            public void a(Throwable th) {
                a.this.a.f(th);
            }

            @Override // c.j.a.i.h
            public void b(o oVar) {
                a aVar = a.this;
                if (oVar == null) {
                    aVar.a.f(new IllegalArgumentException("metadataRepo cannot be null"));
                    return;
                }
                aVar.f1530c = oVar;
                o oVar2 = aVar.f1530c;
                C0014i c0014i = new C0014i();
                i iVar = aVar.a;
                d dVar = iVar.f1528k;
                Objects.requireNonNull(iVar);
                aVar.f1529b = new l(oVar2, c0014i, dVar, false, null);
                aVar.a.g();
            }
        }

        public a(i iVar) {
            super(iVar);
        }

        @Override // c.j.a.i.b
        public void a() {
            try {
                this.a.f1525h.a(new C0013a());
            } catch (Throwable th) {
                this.a.f(th);
            }
        }

        /* JADX WARN: Removed duplicated region for block: B:88:0x015e A[DONT_GENERATE] */
        @Override // c.j.a.i.b
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public java.lang.CharSequence b(java.lang.CharSequence r17, int r18, int r19, int r20, boolean r21) {
            /*
                Method dump skipped, instruction units count: 367
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.i.a.b(java.lang.CharSequence, int, int, int, boolean):java.lang.CharSequence");
        }

        @Override // c.j.a.i.b
        public void c(EditorInfo editorInfo) {
            Bundle bundle = editorInfo.extras;
            c.j.a.s.b bVar = this.f1530c.a;
            int iA = bVar.a(4);
            bundle.putInt("android.support.text.emoji.emojiCompat_metadataVersion", iA != 0 ? bVar.f1571b.getInt(iA + bVar.a) : 0);
            Bundle bundle2 = editorInfo.extras;
            Objects.requireNonNull(this.a);
            bundle2.putBoolean("android.support.text.emoji.emojiCompat_replaceAll", false);
        }
    }

    /* JADX INFO: compiled from: EmojiCompat.java */
    public static class b {
        public final i a;

        public b(i iVar) {
            this.a = iVar;
        }

        public void a() {
            throw null;
        }

        public CharSequence b(CharSequence charSequence, int i2, int i3, int i4, boolean z) {
            throw null;
        }

        public void c(EditorInfo editorInfo) {
            throw null;
        }
    }

    /* JADX INFO: compiled from: EmojiCompat.java */
    public static abstract class c {
        public final g a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public int f1531b = 0;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public d f1532c = new c.j.a.h();

        public c(g gVar) {
            c.f.b.h.f(gVar, "metadataLoader cannot be null.");
            this.a = gVar;
        }
    }

    /* JADX INFO: compiled from: EmojiCompat.java */
    public interface d {
    }

    /* JADX INFO: compiled from: EmojiCompat.java */
    public static abstract class e {
        public void a() {
        }
    }

    /* JADX INFO: compiled from: EmojiCompat.java */
    public static class f implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final List<e> f1533b;

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

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

        public f(Collection<e> collection, int i2, Throwable th) {
            c.f.b.h.f(collection, "initCallbacks cannot be null");
            this.f1533b = new ArrayList(collection);
            this.f1535f = i2;
            this.f1534e = th;
        }

        @Override // java.lang.Runnable
        public void run() {
            int size = this.f1533b.size();
            int i2 = 0;
            if (this.f1535f != 1) {
                while (i2 < size) {
                    Objects.requireNonNull(this.f1533b.get(i2));
                    i2++;
                }
            } else {
                while (i2 < size) {
                    this.f1533b.get(i2).a();
                    i2++;
                }
            }
        }
    }

    /* JADX INFO: compiled from: EmojiCompat.java */
    public interface g {
        void a(h hVar);
    }

    /* JADX INFO: compiled from: EmojiCompat.java */
    public static abstract class h {
        public abstract void a(Throwable th);

        public abstract void b(o oVar);
    }

    /* JADX INFO: renamed from: c.j.a.i$i, reason: collision with other inner class name */
    /* JADX INFO: compiled from: EmojiCompat.java */
    public static class C0014i {
    }

    public i(c cVar) {
        ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
        this.f1520c = reentrantReadWriteLock;
        this.f1522e = 3;
        Objects.requireNonNull(cVar);
        this.f1526i = -16711936;
        this.f1525h = cVar.a;
        int i2 = cVar.f1531b;
        this.f1527j = i2;
        this.f1528k = cVar.f1532c;
        this.f1523f = new Handler(Looper.getMainLooper());
        this.f1521d = new c.d.c();
        a aVar = new a(this);
        this.f1524g = aVar;
        reentrantReadWriteLock.writeLock().lock();
        if (i2 == 0) {
            try {
                this.f1522e = 0;
            } catch (Throwable th) {
                this.f1520c.writeLock().unlock();
                throw th;
            }
        }
        reentrantReadWriteLock.writeLock().unlock();
        if (b() == 0) {
            aVar.a();
        }
    }

    public static i a() {
        i iVar;
        synchronized (a) {
            iVar = f1519b;
            c.f.b.h.h(iVar != null, "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.");
        }
        return iVar;
    }

    public static boolean c() {
        return f1519b != null;
    }

    public int b() {
        this.f1520c.readLock().lock();
        try {
            return this.f1522e;
        } finally {
            this.f1520c.readLock().unlock();
        }
    }

    public final boolean d() {
        return b() == 1;
    }

    public void e() {
        c.f.b.h.h(this.f1527j == 1, "Set metadataLoadStrategy to LOAD_STRATEGY_MANUAL to execute manual loading");
        if (d()) {
            return;
        }
        this.f1520c.writeLock().lock();
        try {
            if (this.f1522e == 0) {
                return;
            }
            this.f1522e = 0;
            this.f1520c.writeLock().unlock();
            this.f1524g.a();
        } finally {
            this.f1520c.writeLock().unlock();
        }
    }

    public void f(Throwable th) {
        ArrayList arrayList = new ArrayList();
        this.f1520c.writeLock().lock();
        try {
            this.f1522e = 2;
            arrayList.addAll(this.f1521d);
            this.f1521d.clear();
            this.f1520c.writeLock().unlock();
            this.f1523f.post(new f(arrayList, this.f1522e, th));
        } catch (Throwable th2) {
            this.f1520c.writeLock().unlock();
            throw th2;
        }
    }

    public void g() {
        ArrayList arrayList = new ArrayList();
        this.f1520c.writeLock().lock();
        try {
            this.f1522e = 1;
            arrayList.addAll(this.f1521d);
            this.f1521d.clear();
            this.f1520c.writeLock().unlock();
            this.f1523f.post(new f(arrayList, this.f1522e, null));
        } catch (Throwable th) {
            this.f1520c.writeLock().unlock();
            throw th;
        }
    }

    public CharSequence h(CharSequence charSequence) {
        return i(charSequence, 0, charSequence == null ? 0 : charSequence.length(), Integer.MAX_VALUE, 0);
    }

    public CharSequence i(CharSequence charSequence, int i2, int i3, int i4, int i5) {
        c.f.b.h.h(d(), "Not initialized yet");
        c.f.b.h.e(i2, "start cannot be negative");
        c.f.b.h.e(i3, "end cannot be negative");
        c.f.b.h.e(i4, "maxEmojiCount cannot be negative");
        c.f.b.h.c(i2 <= i3, "start should be <= than end");
        if (charSequence == null) {
            return null;
        }
        c.f.b.h.c(i2 <= charSequence.length(), "start should be < than charSequence length");
        c.f.b.h.c(i3 <= charSequence.length(), "end should be < than charSequence length");
        if (charSequence.length() == 0 || i2 == i3) {
            return charSequence;
        }
        return this.f1524g.b(charSequence, i2, i3, i4, i5 == 1);
    }

    public void j(e eVar) {
        c.f.b.h.f(eVar, "initCallback cannot be null");
        this.f1520c.writeLock().lock();
        try {
            if (this.f1522e == 1 || this.f1522e == 2) {
                Handler handler = this.f1523f;
                int i2 = this.f1522e;
                c.f.b.h.f(eVar, "initCallback cannot be null");
                handler.post(new f(Arrays.asList(eVar), i2, null));
            } else {
                this.f1521d.add(eVar);
            }
        } finally {
            this.f1520c.writeLock().unlock();
        }
    }
}
