From ccb54e18141c40057d74dac84a9ef17a81c4f73a Mon Sep 17 00:00:00 2001 From: Ztiany Date: Fri, 13 Dec 2019 11:25:08 +0800 Subject: [PATCH] update utils --- .../android/base/utils/android/NetUtils.kt | 25 +++++++++++++++++++ .../com/android/base/utils/common/Strings.kt | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 lib_base/src/main/java/com/android/base/utils/android/NetUtils.kt diff --git a/lib_base/src/main/java/com/android/base/utils/android/NetUtils.kt b/lib_base/src/main/java/com/android/base/utils/android/NetUtils.kt new file mode 100644 index 0000000..a5c2008 --- /dev/null +++ b/lib_base/src/main/java/com/android/base/utils/android/NetUtils.kt @@ -0,0 +1,25 @@ +package com.android.base.utils.android + +import android.content.Context +import android.os.Build +import android.text.TextUtils +import timber.log.Timber + +/** + * 获取当前系统是否设置代理,参考 [App 防止 Fiddler 抓包小技巧](https://cloud.tencent.com/developer/article/1445715)。 + */ +fun checkWifiProxy(context: Context): Boolean { + val isIcsOrLater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH + val proxyAddress: String? + val proxyPort: Int? + if (isIcsOrLater) { + proxyAddress = System.getProperty("http.proxyHost") + val portStr = System.getProperty("http.proxyPort") + proxyPort = Integer.parseInt(portStr ?: "-1") + } else { + proxyAddress = android.net.Proxy.getHost(context) + proxyPort = android.net.Proxy.getPort(context) + } + Timber.d("proxyAddress : ${proxyAddress}, port : $proxyPort") + return !TextUtils.isEmpty(proxyAddress) && proxyPort != -1 +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/utils/common/Strings.kt b/lib_base/src/main/java/com/android/base/utils/common/Strings.kt index 2a8c14c..f5492a5 100644 --- a/lib_base/src/main/java/com/android/base/utils/common/Strings.kt +++ b/lib_base/src/main/java/com/android/base/utils/common/Strings.kt @@ -6,7 +6,7 @@ package com.android.base.utils.common import java.util.regex.Pattern private const val CHINA_PHONE_REG = "^1\\d{10}$" -private const val ID_CARD_REG = "(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)" +private const val ID_CARD_REG = "(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9X]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)" private const val EMAIL_REG = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*" private const val DIGIT_REG = "-?[1-9]\\d+\"" private const val URL_REG = "(https?://(w{3}\\.)?)?\\w+\\.\\w+(\\.[a-zA-Z]+)*(:\\d{1,5})?(/\\w*)*(\\??(.+=.*)?(&.+=.*)?)?"