package p017f0;

import android.icu.util.ULocale;
import android.os.Build;
import android.util.Log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;

/* renamed from: f0.b */
/* loaded from: classes.dex */
public final class C0687b {

    /* renamed from: a */
    public static Method f2281a;

    /* renamed from: b */
    public static Method f2282b;

    /* renamed from: f0.b$a */
    /* loaded from: classes.dex */
    public static class C0688a {
        /* renamed from: a */
        public static String m3105a(Locale locale) {
            String script;
            script = locale.getScript();
            return script;
        }
    }

    /* renamed from: f0.b$b */
    /* loaded from: classes.dex */
    public static class C0689b {
        /* renamed from: a */
        public static ULocale m3104a(Object obj) {
            ULocale addLikelySubtags;
            addLikelySubtags = ULocale.addLikelySubtags((ULocale) obj);
            return addLikelySubtags;
        }

        /* renamed from: b */
        public static ULocale m3103b(Locale locale) {
            ULocale forLocale;
            forLocale = ULocale.forLocale(locale);
            return forLocale;
        }

        /* renamed from: c */
        public static String m3102c(Object obj) {
            String script;
            script = ((ULocale) obj).getScript();
            return script;
        }
    }

    static {
        int i = Build.VERSION.SDK_INT;
        if (i >= 21) {
            if (i < 24) {
                try {
                    f2282b = Class.forName("libcore.icu.ICU").getMethod("addLikelySubtags", Locale.class);
                    return;
                } catch (Exception e) {
                    throw new IllegalStateException(e);
                }
            }
            return;
        }
        try {
            Class<?> cls = Class.forName("libcore.icu.ICU");
            f2281a = cls.getMethod("getScript", String.class);
            f2282b = cls.getMethod("addLikelySubtags", String.class);
        } catch (Exception e2) {
            f2281a = null;
            f2282b = null;
            Log.w("ICUCompat", e2);
        }
    }

    /* renamed from: a */
    public static String m3108a(Locale locale) {
        String locale2 = locale.toString();
        try {
            Method method = f2282b;
            if (method != null) {
                return (String) method.invoke(null, locale2);
            }
        } catch (IllegalAccessException | InvocationTargetException e) {
            Log.w("ICUCompat", e);
        }
        return locale2;
    }

    /* renamed from: b */
    public static String m3107b(String str) {
        try {
            Method method = f2281a;
            if (method != null) {
                return (String) method.invoke(null, str);
            }
        } catch (IllegalAccessException | InvocationTargetException e) {
            Log.w("ICUCompat", e);
        }
        return null;
    }

    /* renamed from: c */
    public static String m3106c(Locale locale) {
        int i = Build.VERSION.SDK_INT;
        if (i >= 24) {
            return C0689b.m3102c(C0689b.m3104a(C0689b.m3103b(locale)));
        }
        if (i >= 21) {
            try {
                return C0688a.m3105a((Locale) f2282b.invoke(null, locale));
            } catch (IllegalAccessException | InvocationTargetException e) {
                Log.w("ICUCompat", e);
                return C0688a.m3105a(locale);
            }
        }
        String m3108a = m3108a(locale);
        if (m3108a != null) {
            return m3107b(m3108a);
        }
        return null;
    }
}