From 373d123e085ff2d33a34109acdb33c064e9f2299 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 22 May 2024 11:33:59 +0800 Subject: [PATCH] Revert "fix: proxy utils network callback" This reverts commit c2769d94bfc49789349049e4bfd81d1745926286. --- .../java/org/telegram/ui/LaunchActivity.java | 1 - .../tw/nekomimi/nekogram/utils/ProxyUtil.kt | 24 ++++--------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index aaf8d54231..018684a7d2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -6193,7 +6193,6 @@ protected void onPause() { if (ApplicationLoader.applicationLoaderInstance != null) { doNotPause = ApplicationLoader.applicationLoaderInstance.onPause(); } - ProxyUtil.unregisterNetworkCallback(); ConnectionsManager.getInstance(currentAccount).setAppPaused(!doNotPause, false); if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) { PhotoViewer.getInstance().onPause(); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/ProxyUtil.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/ProxyUtil.kt index e725ca9fcf..9ab4ad33ea 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/ProxyUtil.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/ProxyUtil.kt @@ -49,8 +49,6 @@ import java.io.File object ProxyUtil { - private var networkCallback: ConnectivityManager.NetworkCallback? = null - private var networkCallbackStatus = false @JvmStatic fun isVPNEnabled(): Boolean { @@ -68,11 +66,8 @@ object ProxyUtil { @JvmStatic fun registerNetworkCallback() { - if (networkCallbackStatus) { - return - } val connectivityManager = ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - networkCallback = + val networkCallback: ConnectivityManager.NetworkCallback = object : ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { val networkCapabilities = @@ -99,24 +94,13 @@ object ProxyUtil { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - connectivityManager.registerDefaultNetworkCallback(networkCallback!!) + connectivityManager.registerDefaultNetworkCallback(networkCallback) } else { val request: NetworkRequest = NetworkRequest.Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build() - connectivityManager.registerNetworkCallback(request, networkCallback!!) + connectivityManager.registerNetworkCallback(request, networkCallback) } - networkCallbackStatus = true - } catch (_: Exception) {} - } - - @JvmStatic - fun unregisterNetworkCallback() { - if (networkCallbackStatus && networkCallback != null) { - val connectivityManager = ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - try { - connectivityManager.unregisterNetworkCallback(networkCallback!!) - } catch (_: Exception) {} - } + } catch (ignored: Exception) {} } @JvmStatic