From 87a892e974cede644ec63873ec60ff0a7ba37101 Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Tue, 24 Aug 2021 20:35:37 +0800 Subject: [PATCH] =?UTF-8?q?Cronet=20=E6=94=AF=E6=8C=81okhttp=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E8=B6=85=E6=97=B6,=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E5=8F=96=E6=B6=88=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/cronetlib/cronet_api.jar | Bin 69333 -> 69333 bytes app/cronetlib/cronet_impl_common_java.jar | Bin 97267 -> 97267 bytes app/cronetlib/src/cronet_api-src.jar | Bin 44068 -> 44069 bytes .../src/cronet_impl_common_java-src.jar | Bin 22299 -> 22300 bytes .../app/help/http/cronet/CronetInterceptor.kt | 2 +- .../app/help/http/cronet/CronetLoader.kt | 2 +- .../http/cronet/CronetUrlRequestCallback.kt | 22 +++++++++++++----- .../io/legado/app/ui/dict/DictViewModel.kt | 2 +- gradle.properties | 2 ++ 9 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/cronetlib/cronet_api.jar b/app/cronetlib/cronet_api.jar index 5f322b8f80cba518ec8d548355cbe462d7dfa517..464e8f6bf2940607462d25115148a4927471826d 100644 GIT binary patch delta 134 zcmcaQm*whQ7Ks3FW)=|!2vF3zWGxY0$HKr+$1*wotN3ICCa$RtjBFe2Ihl-2Egg6m z3>XX<8QcvFEliUv5)CbrEi95vQ_@n5Q_YeMQWDL~EX-2OEiF?mlah^-OpPX2GfA-+ f82}kGnPiwuEhjG&6y1D=$@(t~$eyj-jHmbjhlV2E delta 133 zcmcaQm*whQ7Ks3FW)=|!2vF2ovCwHv9SZ|P9n0kSui}#pn7F1oFtTm5=VUTAHgw=& zFkmobWN$^oADGM0NAD^!2kdN diff --git a/app/cronetlib/cronet_impl_common_java.jar b/app/cronetlib/cronet_impl_common_java.jar index 4d627c1f24a3fc5608063fca90b11876c5f2738d..b54f81b5b41458ebda4fc58973a3155be5147ad4 100644 GIT binary patch delta 164 zcmezTo%Qo~)(yhJykFRg*NL()Fo3Z7uPEmJL%l8uv0jdY7r(~9+ziW2jZGjuaj6H|)y zO-v0<9jcX$3`~t`*%|bC7z`K;c^Hfsq!}4_EsgXH^gs&q3{5SYCx&jH7|JLo&H{4J K_RTqr4*UQ*wJk0H delta 164 zcmezTo%Qo~)(yhJyz0L%r;4&LFo3Z7sJiYL)+Am zY$wjz$Sx4oD|8JwP7r6aM}v}Ri?BorBxTnK{NHy-N{*Z+*mRyq?>`4Hwg*dPUxDk?WL^}Qf~zZC_s1f4MjN>nnT zkcgB5{#}WG4V9dx5buD%*ZH4kO7C(CIZG(VG@TI*3E>b^gR~SCPl0hfr!bw2quD%y zCCjPrc_m5KWQCRF%1`Rvd`|V1=LM&y9-P7>m5K?(A_^uI zFxQgt6^!q1XVJr=t_pv^$*Avl{fj|w;P(cjldHE8un7q7CW~qG7)>#=cj1EV1D75S~4g$%NuoW25F~l{nV=0gxn`C>jb=^GiM@ghMZEpqt zs7?0TbysJ-dYi*xQ{vFD!Y^f`xT~`vc}0D^nn}Zg%O+)l7&VvvifUwbY5+cchTmH> zAHTBKa-w{-y#~9KV#89SfmRhGZ!R<{+zG9J=76^6^PKqH!WA}c;&z6_rh-M#0=qLa z-w??}rJ&;Udr1?G?;PGwWOBx)DI|z94TVv&H!K z<}Q4ge4R#%wm#3_(Q>^F({TQ<82=T{zC~sgy1n5b9+KWD84i;{x=hdMWztQ_<>l~y zGW~5dqN6xDj|crTNtY^!CE-bSmQj+bz%0=9(}#X{(BI<{yahxs$)Me60--4ubsaMdq&C< zySKVE`@!rsnimE6-ndEw?7&`RS-(ahb^zbSq~!($5+Wrnhm+N-Ne1ks00000afs7z delta 959 zcmV;w13>(x*aD>30>k1T_bn2m?kHnj>%( zBhcT4TA_cI7(=uH24AP&PK@282&v#GDa|I#0%sB;bVzem$QXpAbA<6|Fq}+>Fc&EX zjYiJ+k}ar`UIe`AEs$t08;$VzxBaepP`ZJ_g$rq^Qx37C>@@X#*db1$3>RYSwv%B3!8YJC^guJq-)weymcaY0+Cir zq;Y@p<(lcZOxmG|RM<@bBMFMg(y&$((R9Ssumi1#o-(QIrL61cNk4L?t!sO&&4sb4(k%Th7En0GD`Y7E0z`*(A8WT6`a>8Bf_Y-3>IjK*|7uo@DV=m(R}!- zyp|W`i|y6exmGI?I}Pkraq^bRlES^vDh_{ee?Cu%Pc2+h(=Kk~NUSTA2v$*dZssed zg(?gb5`W~#Exj9RO}pBp1taGAk+GU_drjdgE?+evV;i@=MQUpSgl`M-dNi30Zmw_p z_oJ`l;cQ=@oj0^xZNs=fy`K&K=}-P1x>Y!f&f_!QJLA}HVdtEEYR^CMZiGDQv50@S z=B(H1bm#4h6OD5dMw&^UoFvF%6S@VudVJTq=ybNUM9&xFwrYZtT&ym*RoYuthFL@- z-C2~Eph;Ab#*P)=^~=L}qJsqTxb;OVYp8Bp-IFNsgjVt2iRLja)qo_qK$qr(NBB()79@vKy&B^PGaSOkW24xsyt(PPTiNf zb^9U8ZFDa(_M>){8rXw9%PRevgxCanD=U>A1Q4Juq*poviEGm8;l@0h_Q61%=4hJN zzMcMxiIkCf?QQB$qugoowF&(Xu2~P={&CMg?)kEW-;(TWu6m&0-*TE?d&>=PVZLov hd#+TYZ5#gqv+Shh1_jno?~jI))~iVd>!bhx001S;;MxEH diff --git a/app/cronetlib/src/cronet_impl_common_java-src.jar b/app/cronetlib/src/cronet_impl_common_java-src.jar index d4e43c622d08a631bd64e038779cc3550ffa0d0c..6e9402d8010a9c3b813abdd1e636de1c0d8ddaaf 100644 GIT binary patch delta 641 zcmV-{0)G9Qt^u5`0kCdG4VnFf6zBl}0MP>g049@x0U47&RS;yY_$78+-QH3kLV^Gcc|pe4cNT zcpWDOIi6k_?&Xqjx!OdJ;o^JTYPnR1!|hQHdl|PV4aD@L}S5lcRCjDm%mB$-oevdka)>rDa34kX_GP+@>a**Iv8G zR4JOulzD&lY)K?NRtO2v1M{ErRnf-(m=#vmtX#$K#lhIWe zlfOq2lciNE0e+LvRa*i@N|Vu57?XHP4wI!-5RT^ydKp0MP>g049@x0U47(RSB3c#39+BhRB-Vl**$xsy{P#H|RIF;*{1C;-JsXK*kSUm)YtXV%41vi6!Co`D zLnSbQcn=i5F28^EwAmL31!pKM%;eMnqXJ^AnNnGa1h}x@5u$kzE|wvryg=eOC1t;9 zW|dS%SnG`lG=y)<;=!rmYgC#`OGdSov@fSQbl2g_a{ja+PFclP8CXHJhPlO^5eEnC zDHY#QgP;vHb}Z$B7O*smiwuI7r$xBhv{di~I-jl#adOC>_jt z3RCUIiVBwZa-@lNYln}APu^@eJX)8vvfJ&R40PeSwZNp%Mpev6)%3i@ZEUl7?X`(a z=dvnnnP+Lwq@i*DTIV9yn_D;>o#t;7eY?AYf;Ttru~KGEOw?_he{Wc{v-x)^K0FL{JJEZ)<5?d=N92h051{(o^^ z&*Nh8GuzSmvx`T84F$J=*YxL;5mjjdi${}TN*I&CM-r2!RVo2}lhIXM0z^uaVM->G zrd1G=w@VNV0000000000qyeZ)lVM5|lh{ibldD!L0%c8;VM-H|>Q*cUTTlQ1003@m BC20Tv 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