diff --git a/app/cronetlib/cronet_api.jar b/app/cronetlib/cronet_api.jar index 5f322b8f8..464e8f6bf 100644 Binary files a/app/cronetlib/cronet_api.jar and b/app/cronetlib/cronet_api.jar differ diff --git a/app/cronetlib/cronet_impl_common_java.jar b/app/cronetlib/cronet_impl_common_java.jar index 4d627c1f2..b54f81b5b 100644 Binary files a/app/cronetlib/cronet_impl_common_java.jar and b/app/cronetlib/cronet_impl_common_java.jar differ diff --git a/app/cronetlib/src/cronet_api-src.jar b/app/cronetlib/src/cronet_api-src.jar index 6c11000c0..c175fb4e0 100644 Binary files a/app/cronetlib/src/cronet_api-src.jar and b/app/cronetlib/src/cronet_api-src.jar differ diff --git a/app/cronetlib/src/cronet_impl_common_java-src.jar b/app/cronetlib/src/cronet_impl_common_java-src.jar index d4e43c622..6e9402d80 100644 Binary files a/app/cronetlib/src/cronet_impl_common_java-src.jar and b/app/cronetlib/src/cronet_impl_common_java-src.jar differ diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt index 3bc10e838..2038e461a 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt @@ -44,7 +44,7 @@ class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor { val callback = CronetUrlRequestCallback(request, call) val urlRequest = buildRequest(request, callback) urlRequest.start() - return callback.waitForDone() + return callback.waitForDone(urlRequest) } private fun getCookie(url: HttpUrl): String { diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt index e7ea61ec1..544c0fb28 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt @@ -40,7 +40,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { md5Url = ("https://cdn.jsdelivr.net/gh/ag2s20150909/cronet-repo@" + ImplVersion.getCronetVersion() + "/cronet/" + ImplVersion.getCronetVersion() + "/" + getCpuAbi(appCtx) + "/" + soName + ".js") - val dir = appCtx.getDir("lib", Context.MODE_PRIVATE) + val dir = appCtx.getDir("cronet", Context.MODE_PRIVATE) soFile = File(dir.toString() + "/" + getCpuAbi(appCtx), soName) downloadFile = File(appCtx.cacheDir.toString() + "/so_download", soName) Log.e(TAG, "soName+:$soName") diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt index 9517f6e66..04c4d7066 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetUrlRequestCallback.kt @@ -31,8 +31,20 @@ class CronetUrlRequestCallback @JvmOverloads internal constructor( private val mBuffer = Buffer() @Throws(IOException::class) - fun waitForDone(): Response { - mResponseCondition.block() + fun waitForDone(urlRequest: UrlRequest): Response { + //获取okhttp call的完整请求的超时时间 + val timeOutMs: Long = mCall.timeout().timeoutNanos() / 1000000 + if (timeOutMs > 0) { + mResponseCondition.block(timeOutMs) + } else { + mResponseCondition.block() + } + //ConditionVariable 正常open或者超时open后,检查urlRequest是否完成 + if (!urlRequest.isDone) { + urlRequest.cancel() + mException = IOException("Cronet timeout after wait " + timeOutMs + "ms") + } + if (mException != null) { throw mException as IOException } @@ -74,7 +86,7 @@ class CronetUrlRequestCallback @JvmOverloads internal constructor( // } // Log.e("Cronet", sb.toString()) //打印协议,用于调试 - Log.e("Cronet", info.negotiatedProtocol) + Log.i("Cronet", info.negotiatedProtocol) if (eventListener != null) { eventListener.responseHeadersEnd(mCall, this.mResponse) eventListener.responseBodyStart(mCall) @@ -89,8 +101,8 @@ class CronetUrlRequestCallback @JvmOverloads internal constructor( byteBuffer: ByteBuffer ) { byteBuffer.flip() + try { - //mReceiveChannel.write(byteBuffer) mBuffer.write(byteBuffer) } catch (e: IOException) { Log.i(TAG, "IOException during ByteBuffer read. Details: ", e) @@ -104,8 +116,6 @@ class CronetUrlRequestCallback @JvmOverloads internal constructor( eventListener?.responseBodyEnd(mCall, info.receivedByteCount) val contentType: MediaType? = (this.mResponse.header("content-type") ?: "text/plain; charset=\"utf-8\"").toMediaTypeOrNull() -// val responseBody: ResponseBody = -// mBytesReceived.toByteArray().toResponseBody(contentType) val responseBody: ResponseBody = mBuffer.asResponseBody(contentType) val newRequest = originalRequest.newBuilder().url(info.url).build() diff --git a/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt b/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt index 96e10d0d4..41d56d03b 100644 --- a/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt @@ -74,7 +74,7 @@ class DictViewModel(application: Application) : BaseViewModel(application) { * @return */ - fun isChinese(str: String): Boolean { + private fun isChinese(str: String): Boolean { val p = Pattern.compile("[\u4e00-\u9fa5]") val m = p.matcher(str) return m.find() diff --git a/gradle.properties b/gradle.properties index 667087ef0..7934fd0e7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,3 +19,5 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official + +android.enableResourceOptimizations=true