Merge pull request #1327 from ag2s20150909/master

一些修复
pull/1329/head
kunfei 3 years ago committed by GitHub
commit d7b4f059f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      app/cronetlib/cronet_api.jar
  2. BIN
      app/cronetlib/cronet_impl_common_java.jar
  3. 2
      app/src/main/assets/cronet.json
  4. 1
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  5. 52
      app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt
  6. 4
      app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt
  7. 25
      app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt
  8. 34
      app/src/main/java/io/legado/app/help/http/cronet/CronetRequestCallback.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  10. 2
      gradle.properties

Binary file not shown.

@ -1 +1 @@
{"arm64-v8a":"18441011d4a2e3751b8152ad05ab24da","armeabi-v7a":"701930e54c2cfa3d6d0df37168ecc4a6","x86":"3d4ebb7f23b910a8b50a2966eb39bbe7","x86_64":"9be68a8e03867c8f844e8eec88fe09ed","version":"93.0.4577.62"}
{"arm64-v8a":"9717593e18b283ac23a0be548c5aeea6","armeabi-v7a":"44c83d10c4a32ff20466bd7ef363c264","x86":"ce4ad637ead52aa3761e4ce3083f6453","x86_64":"a9924d9d2a31510d7335f6c6af32abc0","version":"93.0.4577.82"}

@ -29,6 +29,7 @@ val okHttpClient: OkHttpClient by lazy {
.connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.callTimeout(60,TimeUnit.SECONDS)
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory, SSLHelper.unsafeTrustManager)
.retryOnConnectionFailure(true)
.hostnameVerifier(SSLHelper.unsafeHostnameVerifier)

@ -12,11 +12,11 @@ import org.chromium.net.ExperimentalCronetEngine
import org.chromium.net.UploadDataProviders
import org.chromium.net.UrlRequest
import splitties.init.appCtx
import java.util.concurrent.Executor
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
val executor: Executor by lazy { Executors.newCachedThreadPool() }
val executor: ExecutorService by lazy { Executors.newCachedThreadPool() }
val cronetEngine: ExperimentalCronetEngine by lazy {
if (AppConfig.isGooglePlay) {
@ -27,16 +27,17 @@ val cronetEngine: ExperimentalCronetEngine by lazy {
val builder = ExperimentalCronetEngine.Builder(appCtx).apply {
if (!AppConfig.isGooglePlay&&CronetLoader.install()) {
if (!AppConfig.isGooglePlay && CronetLoader.install()) {
setLibraryLoader(CronetLoader)//设置自定义so库加载
}
setStoragePath(appCtx.externalCacheDir?.absolutePath)//设置缓存路径
enableHttpCache(HTTP_CACHE_DISK, (1024 * 1024 * 50).toLong())//设置缓存模式
enableHttpCache(HTTP_CACHE_DISK, (1024 * 1024 * 50).toLong())//设置50M的磁盘缓存
enableQuic(true)//设置支持http/3
enableHttp2(true) //设置支持http/2
enablePublicKeyPinningBypassForLocalTrustAnchors(true)
enableBrotli(true)//Brotli压缩
}
val engine = builder.build()
Log.d("Cronet", "Cronet Version:" + engine.versionString)
@ -49,31 +50,32 @@ val cronetEngine: ExperimentalCronetEngine by lazy {
fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest {
val url = request.url.toString()
val requestBuilder = cronetEngine.newUrlRequestBuilder(url, callback, executor)
requestBuilder.setHttpMethod(request.method)
val headers: Headers = request.headers
headers.forEachIndexed { index, _ ->
requestBuilder.addHeader(headers.name(index), headers.value(index))
}
val requestBody = request.body
if (requestBody != null) {
val contentType: MediaType? = requestBody.contentType()
if (contentType != null) {
requestBuilder.addHeader("Content-Type", contentType.toString())
} else {
requestBuilder.addHeader("Content-Type", "text/plain")
return cronetEngine.newUrlRequestBuilder(url, callback, executor).apply {
setHttpMethod(request.method)//设置
allowDirectExecutor()
headers.forEachIndexed { index, _ ->
addHeader(headers.name(index), headers.value(index))
}
val buffer = Buffer()
requestBody.writeTo(buffer)
requestBuilder.setUploadDataProvider(
UploadDataProviders.create(buffer.readByteArray()),
executor
)
if (requestBody != null) {
val contentType: MediaType? = requestBody.contentType()
if (contentType != null) {
addHeader("Content-Type", contentType.toString())
} else {
addHeader("Content-Type", "text/plain")
}
val buffer = Buffer()
requestBody.writeTo(buffer)
setUploadDataProvider(
UploadDataProviders.create(buffer.readByteArray()),
executor
)
}
}.build()
}
return requestBuilder.build()
}

@ -42,7 +42,7 @@ class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor {
@Throws(IOException::class)
private fun proceedWithCronet(request: Request, call: Call): Response {
val callback = CronetUrlRequestCallback(request, call)
val callback = CronetRequestCallback(request, call)
val urlRequest = buildRequest(request, callback)
urlRequest.start()
return callback.waitForDone(urlRequest)
@ -50,7 +50,7 @@ class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor {
private fun getCookie(url: HttpUrl): String {
val sb = StringBuilder()
//处理从 Cookjar 获取到的Cookies
//处理从 Cookiejar 获取到的Cookies
if (cookieJar != null) {
val cookies = cookieJar.loadForRequest(url)
for (cookie in cookies) {

@ -24,8 +24,8 @@ import java.util.*
object CronetLoader : CronetEngine.Builder.LibraryLoader() {
//https://storage.googleapis.com/chromium-cronet/android/92.0.4515.159/Release/cronet/libs/arm64-v8a/libcronet.92.0.4515.159.so
//https://cdn.jsdelivr.net/gh/ag2s20150909/cronet-repo@92.0.4515.159/cronet/92.0.4515.127/arm64-v8a/libcronet.92.0.4515.159.so.js
private const val TAG = "CronetLoader"
private const val soVersion = BuildConfig.Cronet_Version
private const val soName = "libcronet.$soVersion.so"
private val soUrl: String
@ -34,6 +34,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
private var cpuAbi: String? = null
private var md5: String
var download = false
private var cacheInstall = false
init {
soUrl = ("https://storage.googleapis.com/chromium-cronet/android/"
@ -49,18 +50,33 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
Log.e(TAG, "soUrl:$soUrl")
}
/**
* 判断Cronet是否安装完成
* @return
*/
fun install(): Boolean {
if (cacheInstall) {
return true
}
if (AppConfig.isGooglePlay) {
//检查GMS的Cronet服务是否安装
return CronetProviderInstaller.isInstalled()
cacheInstall = CronetProviderInstaller.isInstalled()
return cacheInstall
}
if (md5.length != 32 || !soFile.exists() || md5 != getFileMD5(soFile)) {
return false
cacheInstall = false
return cacheInstall
}
return soFile.exists()
cacheInstall = soFile.exists()
return cacheInstall
}
/**
* 预加载Cronet
*/
fun preDownload() {
if (AppConfig.isGooglePlay) {
CronetProviderInstaller.installProvider(appCtx)
@ -269,6 +285,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
Log.e(TAG, "download success, copy to $destSuccessFile")
//下载成功拷贝文件
copyFile(downloadTempFile, destSuccessFile)
cacheInstall=false
val parentFile = downloadTempFile.parentFile
@Suppress("SameParameterValue")
deleteHistoryFile(parentFile!!, null)

@ -15,7 +15,7 @@ import java.io.IOException
import java.nio.ByteBuffer
import java.util.*
class CronetUrlRequestCallback @JvmOverloads internal constructor(
class CronetRequestCallback @JvmOverloads internal constructor(
private val originalRequest: Request,
private val mCall: Call,
eventListener: EventListener? = null,
@ -100,6 +100,8 @@ class CronetUrlRequestCallback @JvmOverloads internal constructor(
info: UrlResponseInfo,
byteBuffer: ByteBuffer
) {
byteBuffer.flip()
try {
@ -143,9 +145,8 @@ class CronetUrlRequestCallback @JvmOverloads internal constructor(
responseCallback?.onFailure(mCall, e)
}
override fun onCanceled(request: UrlRequest, info: UrlResponseInfo) {
override fun onCanceled(request: UrlRequest, info: UrlResponseInfo?) {
mResponseCondition.open()
this.eventListener?.callEnd(mCall)
@ -184,20 +185,23 @@ class CronetUrlRequestCallback @JvmOverloads internal constructor(
private fun headersFromResponse(responseInfo: UrlResponseInfo): Headers {
val headers = responseInfo.allHeadersAsList
val headerBuilder = Headers.Builder()
for ((key, value) in headers) {
try {
if (key.equals("content-encoding", ignoreCase = true)) {
// Strip all content encoding headers as decoding is done handled by cronet
continue
return Headers.Builder().apply {
for ((key, value) in headers) {
try {
if (key.equals("content-encoding", ignoreCase = true)) {
// Strip all content encoding headers as decoding is done handled by cronet
continue
}
add(key, value)
} catch (e: Exception) {
Log.w(TAG, "Invalid HTTP header/value: $key$value")
// Ignore that header
}
headerBuilder.add(key, value)
} catch (e: Exception) {
Log.w(TAG, "Invalid HTTP header/value: $key$value")
// Ignore that header
}
}
return headerBuilder.build()
}.build()
}
private fun responseFromResponse(

@ -118,6 +118,8 @@ class ReadAloudDialog : BaseDialogFragment() {
seekTtsSpeechRate.isEnabled = !isChecked
upTtsSpeechRate()
}
//设置保存的默认值
seekTtsSpeechRate.progress=AppConfig.ttsSpeechRate
seekTtsSpeechRate.setOnSeekBarChangeListener(object : SeekBarChangeListener {
override fun onStopTrackingTouch(seekBar: SeekBar) {
AppConfig.ttsSpeechRate = seekBar.progress

@ -22,4 +22,4 @@ kotlin.code.style=official
android.enableResourceOptimizations=true
CronetVersion=93.0.4577.62
CronetVersion=93.0.4577.82

Loading…
Cancel
Save