package com.bytedance.router.util;

import X.AnonymousClass9EH;
import X.C30738n2;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.RoutesConfig;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public final class Util {
    static {
        Covode.recordClassIndex(37262);
    }

    public static boolean isLegalUrl(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return Uri.parse(str).isHierarchical();
    }

    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:9:0x0020 */
    /* JADX WARNING: Removed duplicated region for block: B:12:0x002b A[Catch:{ NameNotFoundException -> 0x002e }] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static int getAppVersionCode(android.content.Context r4) {
        /*
            android.content.pm.PackageManager r3 = r4.getPackageManager()
            r2 = -1
            java.lang.String r1 = r4.getPackageName()     // Catch:{ NameNotFoundException -> 0x0020 }
            r0 = 128(0x80, float:1.794E-43)
            android.content.pm.ApplicationInfo r1 = INVOKEVIRTUAL_com_bytedance_router_util_Util_com_ss_android_ugc_aweme_lancet_process_AwemeMetaDataLancet_getApplicationInfo(r3, r1, r0)     // Catch:{ NameNotFoundException -> 0x0020 }
            if (r1 == 0) goto L_0x0020
            android.os.Bundle r0 = r1.metaData     // Catch:{ NameNotFoundException -> 0x0020 }
            if (r0 == 0) goto L_0x0020
            android.os.Bundle r1 = r1.metaData     // Catch:{ NameNotFoundException -> 0x0020 }
            java.lang.String r0 = "UPDATE_VERSION_CODE"
            int r2 = r1.getInt(r0, r2)     // Catch:{ NameNotFoundException -> 0x0020 }
            if (r2 <= 0) goto L_0x0020
            return r2
        L_0x0020:
            java.lang.String r1 = r4.getPackageName()     // Catch:{ NameNotFoundException -> 0x002e }
            r0 = 0
            android.content.pm.PackageInfo r0 = INVOKEVIRTUAL_com_bytedance_router_util_Util_com_ss_android_ugc_aweme_lancet_process_AwemeMetaDataLancet_getPackageInfo(r3, r1, r0)     // Catch:{ NameNotFoundException -> 0x002e }
            if (r0 == 0) goto L_0x002e
            int r0 = r0.versionCode     // Catch:{ NameNotFoundException -> 0x002e }
            return r0
        L_0x002e:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.router.util.Util.getAppVersionCode(android.content.Context):int");
    }

    public static String getRealRouteUrl(String str) {
        Uri parse = Uri.parse(str);
        if (!parse.isHierarchical()) {
            return null;
        }
        if (TextUtils.isEmpty(parse.getScheme())) {
            return str;
        }
        return "//" + parse.getAuthority() + parse.getPath();
    }

    public static String getRouteUrl(String str) {
        Uri parse = Uri.parse(str);
        if (!parse.isHierarchical()) {
            return null;
        }
        if (!TextUtils.isEmpty(parse.getScheme())) {
            return parse.getScheme() + "://" + parse.getAuthority() + parse.getPath();
        }
        return "//" + parse.getAuthority() + parse.getPath();
    }

    public static Map<String, String> sliceUrlParams(String str) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("Slice url params but the url is null!!!");
            return Collections.EMPTY_MAP;
        }
        Uri parse = Uri.parse(str);
        if (!parse.isHierarchical()) {
            return Collections.EMPTY_MAP;
        }
        HashMap hashMap = new HashMap();
        for (String next : parse.getQueryParameterNames()) {
            if (!TextUtils.isEmpty(next)) {
                String queryParameter = parse.getQueryParameter(next);
                if (queryParameter == null) {
                    queryParameter = "";
                }
                hashMap.put(next, queryParameter);
            }
        }
        return hashMap;
    }

    public static String completeUrl(String str, String str2) {
        if (!TextUtils.isEmpty(Uri.parse(str2).getScheme())) {
            return str2;
        }
        if (str2.startsWith("//")) {
            return str + ':' + str2;
        }
        return str + "://" + str2;
    }

    public static boolean isLegalUrl(String str, RoutesConfig routesConfig) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        Uri parse = Uri.parse(str);
        if (!parse.isHierarchical()) {
            return false;
        }
        String scheme = parse.getScheme();
        if (TextUtils.isEmpty(scheme) || scheme.equals(routesConfig.getScheme())) {
            return true;
        }
        String[] otherSchemes = routesConfig.getOtherSchemes();
        if (otherSchemes != null && otherSchemes.length > 0) {
            for (String equals : otherSchemes) {
                if (scheme.equals(equals)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static ApplicationInfo INVOKEVIRTUAL_com_bytedance_router_util_Util_com_ss_android_ugc_aweme_lancet_process_AwemeMetaDataLancet_getApplicationInfo(PackageManager packageManager, String str, int i) {
        Context LIZ = AnonymousClass9EH.LJJIFFI.LIZ();
        if (C30738n2.LJIIIZ && TextUtils.equals(str, LIZ.getPackageName()) && i == 128) {
            if (C30738n2.LIZ == null) {
                C30738n2.LIZ = packageManager.getApplicationInfo(str, i);
            }
            return C30738n2.LIZ;
        } else if (!C30738n2.LJIIIZ || !TextUtils.equals(str, LIZ.getPackageName()) || i != 0) {
            return packageManager.getApplicationInfo(str, i);
        } else {
            if (C30738n2.LIZJ == null) {
                C30738n2.LIZJ = packageManager.getApplicationInfo(str, i);
            }
            return C30738n2.LIZJ;
        }
    }

    public static PackageInfo INVOKEVIRTUAL_com_bytedance_router_util_Util_com_ss_android_ugc_aweme_lancet_process_AwemeMetaDataLancet_getPackageInfo(PackageManager packageManager, String str, int i) {
        Context LIZ = AnonymousClass9EH.LJJIFFI.LIZ();
        if (C30738n2.LJIIIZ && TextUtils.equals(str, LIZ.getPackageName()) && i == 128) {
            if (C30738n2.LIZIZ == null) {
                C30738n2.LIZIZ = packageManager.getPackageInfo(str, i);
            }
            return C30738n2.LIZIZ;
        } else if (C30738n2.LJIIIZ && TextUtils.equals(str, LIZ.getPackageName()) && i == 0) {
            if (C30738n2.LIZLLL == null) {
                C30738n2.LIZLLL = packageManager.getPackageInfo(str, i);
            }
            return C30738n2.LIZLLL;
        } else if (C30738n2.LJIIIZ && TextUtils.equals(str, LIZ.getPackageName()) && i == 64) {
            if (C30738n2.LJ == null) {
                C30738n2.LJ = packageManager.getPackageInfo(str, i);
            }
            return C30738n2.LJ;
        } else if (!C30738n2.LJIIIZ || !TextUtils.equals(str, LIZ.getPackageName()) || i != 8) {
            return packageManager.getPackageInfo(str, i);
        } else {
            if (C30738n2.LJFF == null) {
                C30738n2.LJFF = packageManager.getPackageInfo(str, i);
            }
            return C30738n2.LJFF;
        }
    }
}
