[DO NOT USE] Drop in-app proxy support
This commit is contained in:
1 parent
b1671eacb7
commit
53bbabab75
4 files changed
+1
-102
No files matched your search
@@ -51,7 +51,6 @@ import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import okio.Path.Companion.toOkioPath
|
||||
import splitties.arch.room.roomDb
|
||||
import splitties.init.appCtx
|
||||
import java.net.Proxy
|
||||
|
||||
class EhApplication : Application(), ImageLoaderFactory {
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@@ -146,11 +145,7 @@ class EhApplication : Application(), ImageLoaderFactory {
|
||||
httpClient {
|
||||
cookieJar(EhCookieStore)
|
||||
dns(EhDns)
|
||||
proxySelector(EhProxySelector)
|
||||
if (Settings.dF) {
|
||||
install(EhSSLSocketFactory)
|
||||
proxy(Proxy.NO_PROXY)
|
||||
}
|
||||
if (Settings.dF) install(EhSSLSocketFactory)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer
|
||||
|
||||
import android.text.TextUtils
|
||||
import com.hippo.ehviewer.Settings.proxyIp
|
||||
import com.hippo.ehviewer.Settings.proxyPort
|
||||
import com.hippo.ehviewer.Settings.proxyType
|
||||
import com.hippo.ehviewer.network.InetValidator.isValidInetPort
|
||||
import com.hippo.ehviewer.util.ExceptionUtils
|
||||
import java.io.IOException
|
||||
import java.net.InetAddress
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.Proxy
|
||||
import java.net.ProxySelector
|
||||
import java.net.SocketAddress
|
||||
import java.net.URI
|
||||
|
||||
object EhProxySelector : ProxySelector() {
|
||||
private var delegation: ProxySelector? = null
|
||||
private var alternative: ProxySelector?
|
||||
|
||||
init {
|
||||
alternative = getDefault() ?: NullProxySelector()
|
||||
updateProxy()
|
||||
}
|
||||
|
||||
fun updateProxy() {
|
||||
delegation = when (proxyType) {
|
||||
TYPE_DIRECT -> NullProxySelector()
|
||||
TYPE_SYSTEM -> alternative
|
||||
TYPE_HTTP, TYPE_SOCKS -> null
|
||||
else -> alternative
|
||||
}
|
||||
}
|
||||
|
||||
override fun select(uri: URI): List<Proxy> {
|
||||
val type = proxyType
|
||||
if (type == TYPE_HTTP || type == TYPE_SOCKS) {
|
||||
runCatching {
|
||||
val ip = proxyIp
|
||||
val port = proxyPort
|
||||
if (!TextUtils.isEmpty(ip) && isValidInetPort(port)) {
|
||||
val inetAddress = InetAddress.getByName(ip)
|
||||
val socketAddress = InetSocketAddress(inetAddress, port)
|
||||
return listOf(
|
||||
Proxy(
|
||||
if (type == TYPE_HTTP) Proxy.Type.HTTP else Proxy.Type.SOCKS,
|
||||
socketAddress,
|
||||
),
|
||||
)
|
||||
}
|
||||
}.onFailure {
|
||||
ExceptionUtils.throwIfFatal(it)
|
||||
it.printStackTrace()
|
||||
}
|
||||
}
|
||||
return delegation?.select(uri) ?: alternative!!.select(uri)
|
||||
}
|
||||
|
||||
override fun connectFailed(uri: URI, sa: SocketAddress, ioe: IOException) {
|
||||
delegation?.select(uri)
|
||||
}
|
||||
|
||||
private class NullProxySelector : ProxySelector() {
|
||||
override fun select(uri: URI): List<Proxy> {
|
||||
return listOf(Proxy.NO_PROXY)
|
||||
}
|
||||
|
||||
override fun connectFailed(uri: URI, sa: SocketAddress, ioe: IOException) {}
|
||||
}
|
||||
|
||||
const val TYPE_DIRECT = 0
|
||||
const val TYPE_SYSTEM = 1
|
||||
const val TYPE_HTTP = 2
|
||||
const val TYPE_SOCKS = 3
|
||||
}
|
||||
@@ -98,8 +98,6 @@ object Settings : DataStorePreferences(null) {
|
||||
var recentFavCat by intPref("recent_fav_cat", FavListUrlBuilder.FAV_CAT_ALL)
|
||||
var defaultFavSlot by intPref("default_favorite_2", INVALID_DEFAULT_FAV_SLOT) // -1 for local, 0 - 9 for cloud favorite, other for no default fav slot
|
||||
var securityDelay by intPref("require_unlock_delay", 0)
|
||||
var proxyType by intPref("proxy_type", EhProxySelector.TYPE_SYSTEM)
|
||||
var proxyPort by intPref("proxy_port", -1)
|
||||
var clipboardTextHashCode by intPref("clipboard_text_hash_code", 0)
|
||||
val listThumbSize by intPref(KEY_LIST_THUMB_SIZE, 40)
|
||||
var requestNewsTimerHour by intPref("request_news_timer_hour", -1)
|
||||
@@ -110,7 +108,6 @@ object Settings : DataStorePreferences(null) {
|
||||
var defaultDownloadLabel by stringOrNullPref("default_download_label", null)
|
||||
var displayName by stringOrNullPref("display_name", null)
|
||||
var avatar by stringOrNullPref("avatar", null)
|
||||
var proxyIp by stringOrNullPref("proxy_ip", null)
|
||||
|
||||
var dohUrl by stringPref("doh_url", "")
|
||||
var language by stringPref("app_language", "system").observed { updateWhenLocaleChanges() }
|
||||
|
||||
@@ -135,9 +135,6 @@ fun AdvancedScreen() {
|
||||
entryValueRes = R.array.app_language_entry_values,
|
||||
value = Settings::language,
|
||||
)
|
||||
Preference(
|
||||
title = stringResource(id = R.string.settings_advanced_proxy),
|
||||
)
|
||||
SwitchPreference(
|
||||
title = stringResource(id = R.string.settings_advanced_built_in_hosts_title),
|
||||
summary = null,
|
||||
|
||||
Reference in new issue
Block a user