package io.netty.util.internal;

import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class SystemPropertyUtil {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance((Class<?>) SystemPropertyUtil.class);

    private SystemPropertyUtil() {
    }

    public static boolean contains(String str) {
        return get(str) != null;
    }

    public static String get(String str) {
        return get(str, null);
    }

    public static String get(final String str, String str2) {
        Objects.requireNonNull(str, "key");
        if (str.isEmpty()) {
            throw new IllegalArgumentException("key must not be empty.");
        }
        String str3 = null;
        try {
            if (System.getSecurityManager() == null) {
                str = System.getProperty(str);
                str3 = str;
            } else {
                str3 = (String) AccessController.doPrivileged(new PrivilegedAction<String>() { // from class: io.netty.util.internal.SystemPropertyUtil.1
                    @Override // java.security.PrivilegedAction
                    public String run() {
                        return System.getProperty(str);
                    }
                });
            }
        } catch (SecurityException e2) {
            logger.warn("Unable to retrieve a system property '{}'; default values will be used.", str, e2);
        }
        return str3 == null ? str2 : str3;
    }

    public static boolean getBoolean(String str, boolean z2) {
        String str2 = get(str);
        if (str2 == null) {
            return z2;
        }
        String lowerCase = str2.trim().toLowerCase();
        if (lowerCase.isEmpty()) {
            return z2;
        }
        if ("true".equals(lowerCase) || "yes".equals(lowerCase) || "1".equals(lowerCase)) {
            return true;
        }
        if ("false".equals(lowerCase) || "no".equals(lowerCase) || "0".equals(lowerCase)) {
            return false;
        }
        logger.warn("Unable to parse the boolean system property '{}':{} - using the default value: {}", str, lowerCase, Boolean.valueOf(z2));
        return z2;
    }

    public static int getInt(String str, int i2) {
        String str2 = get(str);
        if (str2 == null) {
            return i2;
        }
        String strTrim = str2.trim();
        try {
            return Integer.parseInt(strTrim);
        } catch (Exception unused) {
            logger.warn("Unable to parse the integer system property '{}':{} - using the default value: {}", str, strTrim, Integer.valueOf(i2));
            return i2;
        }
    }

    public static long getLong(String str, long j2) {
        String str2 = get(str);
        if (str2 == null) {
            return j2;
        }
        String strTrim = str2.trim();
        try {
            return Long.parseLong(strTrim);
        } catch (Exception unused) {
            logger.warn("Unable to parse the long integer system property '{}':{} - using the default value: {}", str, strTrim, Long.valueOf(j2));
            return j2;
        }
    }
}
