package X6FRs_4.IMuAHx_6.Nm6q_10;

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;
/* compiled from: ICUCompat.java */
/* loaded from: classes.dex */
public final class QxJ9d_1 {
    public static Method KQgRr5e_0;
    public static Method QxJ9d_1;

    static {
        int i = Build.VERSION.SDK_INT;
        if (i >= 21) {
            if (i < 24) {
                try {
                    QxJ9d_1 = 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");
            if (cls != null) {
                KQgRr5e_0 = cls.getMethod("getScript", String.class);
                QxJ9d_1 = cls.getMethod("addLikelySubtags", String.class);
            }
        } catch (Exception e2) {
            KQgRr5e_0 = null;
            QxJ9d_1 = null;
            Log.w("ICUCompat", e2);
        }
    }

    public static String KQgRr5e_0(String str) {
        try {
            if (KQgRr5e_0 != null) {
                return (String) KQgRr5e_0.invoke(null, str);
            }
        } catch (IllegalAccessException e) {
            Log.w("ICUCompat", e);
        } catch (InvocationTargetException e2) {
            Log.w("ICUCompat", e2);
        }
        return null;
    }

    public static String QxJ9d_1(Locale locale) {
        int i = Build.VERSION.SDK_INT;
        if (i >= 24) {
            return ULocale.addLikelySubtags(ULocale.forLocale(locale)).getScript();
        }
        if (i >= 21) {
            try {
                return ((Locale) QxJ9d_1.invoke(null, locale)).getScript();
            } catch (IllegalAccessException e) {
                Log.w("ICUCompat", e);
                return locale.getScript();
            } catch (InvocationTargetException e2) {
                Log.w("ICUCompat", e2);
                return locale.getScript();
            }
        }
        String KQgRr5e_02 = KQgRr5e_0(locale);
        if (KQgRr5e_02 != null) {
            return KQgRr5e_0(KQgRr5e_02);
        }
        return null;
    }

    public static String KQgRr5e_0(Locale locale) {
        String locale2 = locale.toString();
        try {
            if (QxJ9d_1 != null) {
                return (String) QxJ9d_1.invoke(null, locale2);
            }
        } catch (IllegalAccessException e) {
            Log.w("ICUCompat", e);
        } catch (InvocationTargetException e2) {
            Log.w("ICUCompat", e2);
        }
        return locale2;
    }
}
