Skip to content

Commit

Permalink
Revert "fix: proxy utils network callback"
Browse files Browse the repository at this point in the history
This reverts commit c2769d9.
  • Loading branch information
omg-xtao committed May 22, 2024
1 parent 88ec504 commit 373d123
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ import java.io.File


object ProxyUtil {
private var networkCallback: ConnectivityManager.NetworkCallback? = null
private var networkCallbackStatus = false

@JvmStatic
fun isVPNEnabled(): Boolean {
Expand All @@ -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 =
Expand All @@ -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
Expand Down

0 comments on commit 373d123

Please sign in to comment.