package com.google.firebase.perf.util;

import android.content.Context;
import android.content.pm.PackageManager;
import com.google.android.gms.common.api.Api;
import com.google.firebase.perf.logging.AndroidLogger;
import uq.v;

/* loaded from: classes3.dex */
public class Utils {
    private static Boolean isDebugLoggingEnabled;

    public static int bufferToInt(byte[] bArr) {
        int i10 = 0;
        for (int i11 = 0; i11 < 4 && i11 < bArr.length; i11++) {
            i10 |= (bArr[i11] & 255) << (i11 * 8);
        }
        return i10;
    }

    public static void checkArgument(boolean z10, String str) {
        if (!z10) {
            throw new IllegalArgumentException(str);
        }
    }

    public static boolean isDebugLoggingEnabled(Context context) {
        Boolean bool = isDebugLoggingEnabled;
        if (bool != null) {
            return bool.booleanValue();
        }
        try {
            Boolean valueOf = Boolean.valueOf(context.getPackageManager().getApplicationInfo(context.getPackageName(), 128).metaData.getBoolean("firebase_performance_logcat_enabled", false));
            isDebugLoggingEnabled = valueOf;
            return valueOf.booleanValue();
        } catch (PackageManager.NameNotFoundException | NullPointerException e10) {
            AndroidLogger.getInstance().debug("No perf logcat meta data found " + e10.getMessage());
            return false;
        }
    }

    public static int saturatedIntCast(long j10) {
        if (j10 > 2147483647L) {
            return Api.BaseClientBuilder.API_PRIORITY_OTHER;
        }
        if (j10 < -2147483648L) {
            return Integer.MIN_VALUE;
        }
        return (int) j10;
    }

    public static String stripSensitiveInfo(String str) {
        v m10 = v.m(str);
        return m10 != null ? m10.k().C("").o("").s(null).i(null).toString() : str;
    }

    public static String truncateURL(String str, int i10) {
        v m10;
        int lastIndexOf;
        if (str.length() <= i10) {
            return str;
        }
        if (str.charAt(i10) != '/' && (m10 = v.m(str)) != null) {
            return (m10.d().lastIndexOf(47) < 0 || (lastIndexOf = str.lastIndexOf(47, i10 + (-1))) < 0) ? str.substring(0, i10) : str.substring(0, lastIndexOf);
        }
        return str.substring(0, i10);
    }
}
