update utils

androidx
Ztiany 5 years ago
parent 115715f2f5
commit ccb54e1814
  1. 25
      lib_base/src/main/java/com/android/base/utils/android/NetUtils.kt
  2. 2
      lib_base/src/main/java/com/android/base/utils/common/Strings.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
}

@ -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*)*(\\??(.+=.*)?(&.+=.*)?)?"

Loading…
Cancel
Save