mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
68eddefb94
commit
9c50621895
6
app/proguard-rules.pro
vendored
6
app/proguard-rules.pro
vendored
|
@ -255,6 +255,12 @@
|
|||
# 繁简转换
|
||||
-keep class com.github.liuyueyi.quick.transfer.** {*;}
|
||||
|
||||
# Cronet
|
||||
-keep class org.chromium.net.X509Util {
|
||||
private static sDefaultTrustManager;
|
||||
private static sTestTrustManager;
|
||||
}
|
||||
|
||||
# Class.forName调用
|
||||
-keep class io.legado.app.lib.cronet.CronetInterceptor{*;}
|
||||
-keep class io.legado.app.lib.cronet.CronetLoader{*;}
|
||||
|
|
|
@ -4,7 +4,6 @@ import io.legado.app.constant.AppConst
|
|||
import io.legado.app.help.CacheManager
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.http.CookieManager.cookieJarHeader
|
||||
import io.legado.app.utils.GzipSourceCompat
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
import okhttp3.ConnectionSpec
|
||||
import okhttp3.Cookie
|
||||
|
@ -16,12 +15,14 @@ import okhttp3.OkHttpClient
|
|||
import okhttp3.internal.http.RealResponseBody
|
||||
import okhttp3.internal.http.promisesBody
|
||||
import okio.buffer
|
||||
import okio.source
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.Proxy
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.ThreadFactory
|
||||
import java.util.concurrent.ThreadPoolExecutor
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.zip.GZIPInputStream
|
||||
|
||||
private val proxyClientCache: ConcurrentHashMap<String, OkHttpClient> by lazy {
|
||||
ConcurrentHashMap()
|
||||
|
@ -123,7 +124,7 @@ val okHttpClient: OkHttpClient by lazy {
|
|||
&& response.promisesBody() && responseBody != null
|
||||
) {
|
||||
val responseBuilder = response.newBuilder()
|
||||
val gzipSource = GzipSourceCompat(responseBody.source())
|
||||
val gzipSource = GZIPInputStream(responseBody.byteStream()).source()
|
||||
val strippedHeaders = response.headers.newBuilder()
|
||||
.removeAll("Content-Encoding")
|
||||
.removeAll("Content-Length")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.legado.app.help.http
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.net.http.X509TrustManagerExtensions
|
||||
import io.legado.app.utils.printOnDebug
|
||||
|
||||
|
||||
|
@ -38,11 +39,19 @@ object SSLHelper {
|
|||
//do nothing,接受任意客户端证书
|
||||
}
|
||||
|
||||
fun checkServerTrusted(chain: Array<X509Certificate>, authType: String, host: String): List<X509Certificate> {
|
||||
return chain.toList()
|
||||
}
|
||||
|
||||
override fun getAcceptedIssuers(): Array<X509Certificate> {
|
||||
return arrayOf()
|
||||
}
|
||||
}
|
||||
|
||||
val unsafeTrustManagerExtensions by lazy {
|
||||
X509TrustManagerExtensions(unsafeTrustManager)
|
||||
}
|
||||
|
||||
val unsafeSSLSocketFactory: SSLSocketFactory by lazy {
|
||||
try {
|
||||
val sslContext = SSLContext.getInstance("SSL")
|
||||
|
|
|
@ -6,6 +6,7 @@ package io.legado.app.lib.cronet
|
|||
import androidx.annotation.Keep
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.help.http.CookieManager.cookieJarHeader
|
||||
import io.legado.app.help.http.SSLHelper
|
||||
import io.legado.app.help.http.okHttpClient
|
||||
import io.legado.app.utils.DebugLog
|
||||
import okhttp3.Headers
|
||||
|
@ -15,6 +16,7 @@ import org.chromium.net.CronetEngine.Builder.HTTP_CACHE_DISK
|
|||
import org.chromium.net.ExperimentalCronetEngine
|
||||
import org.chromium.net.UploadDataProvider
|
||||
import org.chromium.net.UrlRequest
|
||||
import org.chromium.net.X509Util
|
||||
import org.json.JSONObject
|
||||
import splitties.init.appCtx
|
||||
|
||||
|
@ -22,6 +24,7 @@ internal const val BUFFER_SIZE = 32 * 1024
|
|||
|
||||
val cronetEngine: ExperimentalCronetEngine? by lazy {
|
||||
CronetLoader.preDownload()
|
||||
disableCertificateVerify()
|
||||
val builder = ExperimentalCronetEngine.Builder(appCtx).apply {
|
||||
if (CronetLoader.install()) {
|
||||
setLibraryLoader(CronetLoader)//设置自定义so库加载
|
||||
|
@ -103,3 +106,15 @@ fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest? {
|
|||
|
||||
}
|
||||
|
||||
private fun disableCertificateVerify() {
|
||||
runCatching {
|
||||
val sDefaultTrustManager = X509Util::class.java.getDeclaredField("sTestTrustManager")
|
||||
sDefaultTrustManager.isAccessible = true
|
||||
sDefaultTrustManager.set(null, SSLHelper.unsafeTrustManagerExtensions)
|
||||
}
|
||||
runCatching {
|
||||
val sTestTrustManager = X509Util::class.java.getDeclaredField("sTestTrustManager")
|
||||
sTestTrustManager.isAccessible = true
|
||||
sTestTrustManager.set(null, SSLHelper.unsafeTrustManagerExtensions)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -368,6 +368,7 @@ class TextChapterLayout(
|
|||
}
|
||||
}
|
||||
val textLine = TextLine(isImage = true)
|
||||
textLine.text = " "
|
||||
textLine.lineTop = durY + paddingTop
|
||||
durY += height
|
||||
textLine.lineBottom = durY + paddingTop
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package io.legado.app.utils
|
||||
|
||||
import okio.Buffer
|
||||
import okio.EOFException
|
||||
import okio.GzipSource
|
||||
import okio.Source
|
||||
|
||||
class GzipSourceCompat(source: Source) : Source {
|
||||
private val delegate = GzipSource(source)
|
||||
|
||||
override fun close() = delegate.close()
|
||||
|
||||
override fun read(sink: Buffer, byteCount: Long): Long {
|
||||
try {
|
||||
return delegate.read(sink, byteCount)
|
||||
} catch (e: EOFException) {
|
||||
if (e.message == "source exhausted prematurely") {
|
||||
return -1
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
override fun timeout() = delegate.timeout()
|
||||
|
||||
}
|
|
@ -4,17 +4,16 @@ import android.annotation.SuppressLint
|
|||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkCapabilities
|
||||
import android.os.Build
|
||||
import cn.hutool.core.lang.Validator
|
||||
import io.legado.app.constant.AppLog
|
||||
import okhttp3.internal.publicsuffix.PublicSuffixDatabase
|
||||
import splitties.systemservices.connectivityManager
|
||||
|
||||
import java.net.InetAddress
|
||||
import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
|
||||
import cn.hutool.core.lang.Validator
|
||||
import java.util.BitSet
|
||||
import java.util.Enumeration
|
||||
|
||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
object NetworkUtils {
|
||||
|
@ -190,28 +189,32 @@ object NetworkUtils {
|
|||
* Get local Ip address.
|
||||
*/
|
||||
fun getLocalIPAddress(): InetAddress? {
|
||||
var enumeration: Enumeration<NetworkInterface>? = null
|
||||
val enumeration: Enumeration<NetworkInterface>
|
||||
try {
|
||||
enumeration = NetworkInterface.getNetworkInterfaces()
|
||||
} catch (e: SocketException) {
|
||||
e.printOnDebug()
|
||||
return null
|
||||
}
|
||||
|
||||
if (enumeration != null) {
|
||||
while (enumeration.hasMoreElements()) {
|
||||
val nif = enumeration.nextElement()
|
||||
val addresses = nif.inetAddresses
|
||||
if (addresses != null) {
|
||||
while (addresses.hasMoreElements()) {
|
||||
val address = addresses.nextElement()
|
||||
if (!address.isLoopbackAddress && isIPv4Address(address.hostAddress)) {
|
||||
return address
|
||||
}
|
||||
var fallbackAddress: InetAddress? = null
|
||||
|
||||
while (enumeration.hasMoreElements()) {
|
||||
val nif = enumeration.nextElement()
|
||||
val addresses = nif.inetAddresses ?: continue
|
||||
while (addresses.hasMoreElements()) {
|
||||
val address = addresses.nextElement()
|
||||
if (!address.isLoopbackAddress && isIPv4Address(address.hostAddress)) {
|
||||
if (nif.name?.startsWith("wl") == true) {
|
||||
return address
|
||||
}
|
||||
if (fallbackAddress == null) {
|
||||
fallbackAddress = address
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
return fallbackAddress
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user