package androidx.emoji2.text;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.os.Build;
import android.util.Log;
import androidx.emoji2.text.C0229g;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import p014e0.C0648e;
import p020g0.C0737f;

/* renamed from: androidx.emoji2.text.c */
/* loaded from: classes.dex */
public final class C0221c {

    /* renamed from: androidx.emoji2.text.c$a */
    /* loaded from: classes.dex */
    public static class C0222a {

        /* renamed from: a */
        public final C0223b f1063a;

        public C0222a(C0223b c0223b) {
            this.f1063a = c0223b == null ? m4414e() : c0223b;
        }

        /* renamed from: e */
        public static C0223b m4414e() {
            int i = Build.VERSION.SDK_INT;
            return i >= 28 ? new C0225d() : i >= 19 ? new C0224c() : new C0223b();
        }

        /* renamed from: a */
        public final C0229g.AbstractC0233c m4418a(Context context, C0648e c0648e) {
            if (c0648e == null) {
                return null;
            }
            return new C0247m(context, c0648e);
        }

        /* renamed from: b */
        public final List<List<byte[]>> m4417b(Signature[] signatureArr) {
            ArrayList arrayList = new ArrayList();
            for (Signature signature : signatureArr) {
                arrayList.add(signature.toByteArray());
            }
            return Collections.singletonList(arrayList);
        }

        /* renamed from: c */
        public C0229g.AbstractC0233c m4416c(Context context) {
            return m4418a(context, m4411h(context));
        }

        /* renamed from: d */
        public final C0648e m4415d(ProviderInfo providerInfo, PackageManager packageManager) {
            String str = providerInfo.authority;
            String str2 = providerInfo.packageName;
            return new C0648e(str, str2, "emojicompat-emoji-font", m4417b(this.f1063a.mo4408b(packageManager, str2)));
        }

        /* renamed from: f */
        public final boolean m4413f(ProviderInfo providerInfo) {
            ApplicationInfo applicationInfo;
            return (providerInfo == null || (applicationInfo = providerInfo.applicationInfo) == null || (applicationInfo.flags & 1) != 1) ? false : true;
        }

        /* renamed from: g */
        public final ProviderInfo m4412g(PackageManager packageManager) {
            for (ResolveInfo resolveInfo : this.f1063a.mo4409c(packageManager, new Intent("androidx.content.action.LOAD_EMOJI_FONT"), 0)) {
                ProviderInfo mo4410a = this.f1063a.mo4410a(resolveInfo);
                if (m4413f(mo4410a)) {
                    return mo4410a;
                }
            }
            return null;
        }

        /* renamed from: h */
        public C0648e m4411h(Context context) {
            PackageManager packageManager = context.getPackageManager();
            C0737f.m3032g(packageManager, "Package manager required to locate emoji font provider");
            ProviderInfo m4412g = m4412g(packageManager);
            if (m4412g == null) {
                return null;
            }
            try {
                return m4415d(m4412g, packageManager);
            } catch (PackageManager.NameNotFoundException e) {
                Log.wtf("emoji2.text.DefaultEmojiConfig", e);
                return null;
            }
        }
    }

    /* renamed from: androidx.emoji2.text.c$b */
    /* loaded from: classes.dex */
    public static class C0223b {
        /* renamed from: a */
        public ProviderInfo mo4410a(ResolveInfo resolveInfo) {
            throw new IllegalStateException("Unable to get provider info prior to API 19");
        }

        /* renamed from: b */
        public Signature[] mo4408b(PackageManager packageManager, String str) {
            return packageManager.getPackageInfo(str, 64).signatures;
        }

        /* renamed from: c */
        public List<ResolveInfo> mo4409c(PackageManager packageManager, Intent intent, int i) {
            return Collections.emptyList();
        }
    }

    /* renamed from: androidx.emoji2.text.c$c */
    /* loaded from: classes.dex */
    public static class C0224c extends C0223b {
        @Override // androidx.emoji2.text.C0221c.C0223b
        /* renamed from: a */
        public ProviderInfo mo4410a(ResolveInfo resolveInfo) {
            ProviderInfo providerInfo;
            providerInfo = resolveInfo.providerInfo;
            return providerInfo;
        }

        @Override // androidx.emoji2.text.C0221c.C0223b
        /* renamed from: c */
        public List<ResolveInfo> mo4409c(PackageManager packageManager, Intent intent, int i) {
            List<ResolveInfo> queryIntentContentProviders;
            queryIntentContentProviders = packageManager.queryIntentContentProviders(intent, i);
            return queryIntentContentProviders;
        }
    }

    /* renamed from: androidx.emoji2.text.c$d */
    /* loaded from: classes.dex */
    public static class C0225d extends C0224c {
        @Override // androidx.emoji2.text.C0221c.C0223b
        /* renamed from: b */
        public Signature[] mo4408b(PackageManager packageManager, String str) {
            return packageManager.getPackageInfo(str, 64).signatures;
        }
    }

    /* renamed from: a */
    public static C0247m m4419a(Context context) {
        return (C0247m) new C0222a(null).m4416c(context);
    }
}