From 53bbabab756eec13ca238f67cb378c943e22feda Mon Sep 17 00:00:00 2001 From: tarsin Date: Mon, 5 Jun 2023 15:32:51 +0800 Subject: [PATCH] [DO NOT USE] Drop in-app proxy support --- .../java/com/hippo/ehviewer/EhApplication.kt | 7 +- .../com/hippo/ehviewer/EhProxySelector.kt | 90 ------------------- .../main/java/com/hippo/ehviewer/Settings.kt | 3 - .../ehviewer/ui/settings/AdvancedScreen.kt | 3 - 4 files changed, 1 insertion(+), 102 deletions(-) delete mode 100644 app/src/main/java/com/hippo/ehviewer/EhProxySelector.kt diff --git a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt index 90497037a..322091973 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt +++ b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt @@ -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) } } diff --git a/app/src/main/java/com/hippo/ehviewer/EhProxySelector.kt b/app/src/main/java/com/hippo/ehviewer/EhProxySelector.kt deleted file mode 100644 index 1e2ad7610..000000000 --- a/app/src/main/java/com/hippo/ehviewer/EhProxySelector.kt +++ /dev/null @@ -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 { - 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 { - 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 -} diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt index f5b551f28..d4cc14aac 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt @@ -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() } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt b/app/src/main/java/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt index e7222febe..54fcce96f 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt @@ -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,