From b2d1b3cf206f15f17932109193bec3f09c050267 Mon Sep 17 00:00:00 2001 From: bjutapp Date: Sun, 15 Dec 2024 20:51:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=BB=9C=E7=8E=AF=E5=A2=83=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=B9=B6=E5=8F=91=E4=BC=98=E5=8C=96=EF=BC=8C=E4=B8=80?= =?UTF-8?q?=E5=8D=A1=E9=80=9A=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2=E6=9A=97?= =?UTF-8?q?=E8=89=B2=E4=B8=BB=E9=A2=98=E4=BF=AE=E5=A4=8D=EF=BC=8C=E7=94=9F?= =?UTF-8?q?=E7=89=A9=E9=AA=8C=E8=AF=81=E8=A7=A3=E9=94=81=E5=BE=AE=E8=B0=83?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- app/build.gradle.kts | 4 +- .../java/com/hlwdy/bjut/BiometricHelper.kt | 2 +- .../java/com/hlwdy/bjut/RouterActivity.kt | 2 +- .../java/com/hlwdy/bjut/ui/LoginActivity.kt | 2 +- .../com/hlwdy/bjut/ui/card/CardFragment.kt | 2 +- .../hlwdy/bjut/ui/network/NetworkFragment.kt | 131 +++++++++++------- 7 files changed, 86 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 966d402..f23fb3e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ * [x] 桌面APP长按快捷菜单 * [x] 图书馆相关功能 * [x] 校内WiFi一键登录 +* [x] 生物验证解锁 * [ ] 校内邮箱浏览 * [ ] 办事大厅 * [ ] 重要消息提示 @@ -30,7 +31,7 @@ ## 应用兼容性说明 -本app完全支持armeabi-v7a, arm64-v8a, x86和x86_64安卓架构,理论上较好支持Android 7.1+版本 (Android API level 25)。 +本app完全支持armeabi-v7a, arm64-v8a, x86和x86_64安卓架构,理论上较好支持Android 7.1+版本 (Android API level 25),生物验证仅支持Android 9.0+版本。 ## 应用内部分截图 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ee8f03d..2a43d0f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,8 +11,8 @@ android { applicationId = "com.hlwdy.bjut" minSdk = 24 targetSdk = 34 - versionCode = 2 - versionName = "1.1.0" + versionCode = 3 + versionName = "1.1.1" /* ndk { abiFilters += listOf("armeabi-v7a", "arm64-v8a","x86","x86_64") diff --git a/app/src/main/java/com/hlwdy/bjut/BiometricHelper.kt b/app/src/main/java/com/hlwdy/bjut/BiometricHelper.kt index fb1967c..d7ce933 100644 --- a/app/src/main/java/com/hlwdy/bjut/BiometricHelper.kt +++ b/app/src/main/java/com/hlwdy/bjut/BiometricHelper.kt @@ -32,7 +32,7 @@ class BiometricHelper(private val activity: AppCompatActivity) { override fun onAuthenticationFailed() { super.onAuthenticationFailed() - Toast.makeText(activity, "认证尝试失败", Toast.LENGTH_SHORT).show() + Toast.makeText(activity, "尝试验证失败", Toast.LENGTH_SHORT).show() //pendingAction = null //允许继续尝试 } diff --git a/app/src/main/java/com/hlwdy/bjut/RouterActivity.kt b/app/src/main/java/com/hlwdy/bjut/RouterActivity.kt index 13f1ccb..ee6edb9 100644 --- a/app/src/main/java/com/hlwdy/bjut/RouterActivity.kt +++ b/app/src/main/java/com/hlwdy/bjut/RouterActivity.kt @@ -58,7 +58,7 @@ class RouterActivity : AppCompatActivity() { .commit() } - }) + },{finish()}) } } \ No newline at end of file diff --git a/app/src/main/java/com/hlwdy/bjut/ui/LoginActivity.kt b/app/src/main/java/com/hlwdy/bjut/ui/LoginActivity.kt index 719779b..50f8ce3 100644 --- a/app/src/main/java/com/hlwdy/bjut/ui/LoginActivity.kt +++ b/app/src/main/java/com/hlwdy/bjut/ui/LoginActivity.kt @@ -152,7 +152,7 @@ class LoginActivity : BaseActivity() { if(account_session_util(context).isLoggedIn()){ BiometricHelper(context).authenticate({//跳转生物验证 jumpToMain() - }) + },{finish()}) } else { rootLayout.removeView(overlayView) diff --git a/app/src/main/java/com/hlwdy/bjut/ui/card/CardFragment.kt b/app/src/main/java/com/hlwdy/bjut/ui/card/CardFragment.kt index f6e4909..6cd9fb6 100644 --- a/app/src/main/java/com/hlwdy/bjut/ui/card/CardFragment.kt +++ b/app/src/main/java/com/hlwdy/bjut/ui/card/CardFragment.kt @@ -130,7 +130,7 @@ class EnhancedCachingWebViewClient(private val context: Context,private val frag isNeedNewID=false } // 注入CSS - val css = "@media (prefers-color-scheme: dark) { body,uni-page-body,.bdbg1,.code-bg,.news-w-bg,.bdbg,.ticket-nav,.tap2{ background: #121212 !important; }uni-navigator,.menu-list,.news-w,.payment-method,.condition, .condition-checkbox,.amtbutton,.v-tabs__container,.v-tabs__container-item,.tr,.nowcode,.tap-box,.uni-picker-select,.uni-picker-header,.newsCol,.text-w,.txt,.itemArea_li,#popup_content{background:#313131 !important;color:white !important;}uni-text{color:white !important}.code-w{box-shadow:none !important;}.news-w,.newsli{border-bottom:none !important;}.bdbg1,uni-view{color:white !important}.bdt{border-top: 1px solid #555555 !important;}.per-details,.bor-bottom{border-bottom: 1px solid #555555 !important;}}" + val css = "@media (prefers-color-scheme: dark) { body,uni-page-body,.bdbg1,.code-bg,.news-w-bg,.bdbg,.ticket-nav,.tap2,.alert-page>uni-view,.pages_water-water-virtualcard-mywaterorder-mywaterorder uni-view{ background: #121212 !important; }uni-navigator,.menu-list,.news-w,.payment-method,.condition, .condition-checkbox,.amtbutton,.v-tabs__container,.v-tabs__container-item,.tr,.nowcode,.tap-box,.uni-picker-select,.uni-picker-header,.newsCol,.text-w,.txt,.itemArea_li,#popup_content{background:#313131 !important;color:white !important;}uni-text{color:white !important}.code-w{box-shadow:none !important;}.news-w,.newsli{border-bottom:none !important;}.bdbg1,uni-view{color:white !important}.bdt{border-top: 1px solid #555555 !important;}.per-details,.bor-bottom{border-bottom: 1px solid #555555 !important;}}" view.evaluateJavascript( """ (function() { diff --git a/app/src/main/java/com/hlwdy/bjut/ui/network/NetworkFragment.kt b/app/src/main/java/com/hlwdy/bjut/ui/network/NetworkFragment.kt index 08b9323..c2eb37a 100644 --- a/app/src/main/java/com/hlwdy/bjut/ui/network/NetworkFragment.kt +++ b/app/src/main/java/com/hlwdy/bjut/ui/network/NetworkFragment.kt @@ -26,6 +26,9 @@ import com.hlwdy.bjut.databinding.FragmentNetworkBinding import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.async +import kotlinx.coroutines.selects.select import java.net.InetAddress import org.json.JSONObject import com.hlwdy.bjut.network_account_util @@ -34,13 +37,13 @@ import java.util.Locale import kotlin.math.ln import kotlin.math.pow -fun isInternalIp(ip: String): Boolean { +fun isInternalIp(ip: String?): Boolean { val privateIpPatterns = listOf( "^10\\..*".toRegex(), "^172\\.(1[6-9]|2[0-9]|3[0-1])\\..*".toRegex(), "^192\\.168\\..*".toRegex() ) - return privateIpPatterns.any { it.matches(ip) } + return ip!=null&&privateIpPatterns.any { it.matches(ip) } } fun checkWebsiteAccessibility(urlString: String): Boolean { return try { @@ -116,23 +119,42 @@ fun postUrl(urlString: String, params: Set): String? { return null } } -private fun checkBjutLocation():String{ - //测试是否为宿舍光猫 - val bres= checkWebsiteAccessibility("http://10.21.221.98") - if(bres){ - return "dorm" - } - //测试是否为bjut_wifi - val wres= checkWebsiteAccessibility("http://wlgn.bjut.edu.cn") - if(wres){ - return "wifi" - } - //测试是否为其他情况(例如有线网) - val res= checkWebsiteAccessibility("http://172.30.201.2") - if(res){ - return "bjut" +suspend fun checkBjutLocation():String{ + return coroutineScope { + //测试是否为宿舍光猫 + val bPingDeferred = async(Dispatchers.IO){checkWebsiteAccessibility("http://10.21.221.98")} + //测试是否为bjut_wifi + val wPingDeferred = async(Dispatchers.IO){checkWebsiteAccessibility("http://wlgn.bjut.edu.cn")} + //测试是否为其他情况(例如有线网) + val lPingDeferred = async(Dispatchers.IO){checkWebsiteAccessibility("http://172.30.201.2")} + + val bwPingRes=select { + bPingDeferred.onAwait{ + if(it){ + "dorm" + }else if(wPingDeferred.await()){ + "wifi" + }else{""} + } + wPingDeferred.onAwait{ + if(it){ + "wifi" + }else if(bPingDeferred.await()){ + "dorm" + }else{""} + } + } + if(bwPingRes!=""){ + bwPingRes + }else { + val lres = lPingDeferred.await() + if (lres) { + "bjut" + }else { + "unknownType" + } + } } - return "unknownType" } fun checkLoginStatusBjut():Pair { val urlString="https://lgn.bjut.edu.cn" @@ -262,6 +284,18 @@ fun formatFlowSize(sizeInBytes: Long): String { val pre = "KMGTPE"[exp - 1] + "i" return String.format(Locale("zh", "CN"),"%.2f %sB", sizeInBytes / unit.toDouble().pow(exp.toDouble()), pre) } +fun checkInBjut():Int{ + return try { + val addresses = InetAddress.getAllByName("www.bjut.edu.cn") + if(addresses.any { isInternalIp(it.hostAddress) }) { + 1 + }else { + 0 + } + }catch (e: Exception) { + -1 + } +} class NetworkFragment : BaseFragment() { private var _binding: FragmentNetworkBinding? = null @@ -317,49 +351,40 @@ class NetworkFragment : BaseFragment() { } - private fun checkNetworkStates(networkAccount: network_account_util,showToast: Boolean) { + private fun checkNetworkStates(networkAccount: network_account_util,showToastFlag: Boolean) { showLoading() lifecycleScope.launch { - val success = withContext(Dispatchers.IO) { - try { - val addresses = InetAddress.getAllByName("www.bjut.edu.cn") - //有一个是内网地址即可 - if (addresses.any { isInternalIp(it.hostAddress!!) }) { - networkStates=checkBjutLocation() - val pair=checkLoginStatus(networkStates) - networkLoginipv4States=pair.first - networkLoginipv6States=pair.second - if(networkLoginipv4States) { - networkFlow=checkNetworkFlow() - }else{ - networkFlow=-1 - if (lastRequireLoginTime != 0L) { - if (System.currentTimeMillis() - lastRequireLoginTime < 5000) { - loginNetwork(networkAccount) - } - lastRequireLoginTime = 0L - } - + val inBjut = withContext(Dispatchers.IO) { checkInBjut() } + if (inBjut == 1) { + networkStates=withContext(Dispatchers.IO) { checkBjutLocation() } + val pair=withContext(Dispatchers.IO) { checkLoginStatus(networkStates) } + networkLoginipv4States=pair.first + networkLoginipv6States=pair.second + if(networkLoginipv4States) { + networkFlow=withContext(Dispatchers.IO) { checkNetworkFlow() } + }else{ + networkFlow=-1 + if (lastRequireLoginTime != 0L) { + if (System.currentTimeMillis() - lastRequireLoginTime < 5000) { + loginNetwork(networkAccount) } - }else { - networkStates = "outBJUT" - networkLoginipv4States=false - networkLoginipv6States=false - networkFlow=-1 + lastRequireLoginTime = 0L } - true - } catch (e: Exception) { - false + } - } - if(!success) { + } else if (inBjut == 0) { + networkStates = "outBJUT" + networkLoginipv4States = false + networkLoginipv6States = false + networkFlow = -1 + } else if (inBjut == -1) { networkStates = "noNetwork" - networkLoginipv4States=false - networkLoginipv6States=false - networkFlow=-1 + networkLoginipv4States = false + networkLoginipv6States = false + networkFlow = -1 } hideLoading() - if(showToast) { + if(showToastFlag) { showToast("刷新完成") } updateShow()