From cf7468d0094035708d1d338a261a817e518e6eb4 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 15 Jul 2020 17:30:11 +0200 Subject: [PATCH] Reload on transitioning from metered to unmetered network --- .../eu/faircode/email/ServiceSynchronize.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 2323310f8e..214c017c47 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1701,7 +1701,31 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences try { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getNetworkInfo(network); - EntityLog.log(ServiceSynchronize.this, "Available network=" + network + " info=" + ni); + NetworkCapabilities caps = cm.getNetworkCapabilities(network); + + // Transition from metered to unmetered? + boolean transition = false; + if (caps != null && + caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN) && + caps.hasCapability((NetworkCapabilities.NET_CAPABILITY_NOT_METERED))) { + Network[] networks = cm.getAllNetworks(); + for (Network other : networks) + if (!network.equals(other)) { + NetworkCapabilities c = cm.getNetworkCapabilities(other); + if (c != null && + c.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN) && + !c.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)) { + transition = true; + break; + } + } + } + + EntityLog.log(ServiceSynchronize.this, + "Available network=" + network + " info=" + ni + " caps=" + caps + " transition=" + transition); + + if (transition) + reload(ServiceSynchronize.this, -1L, false, "unmetered"); } catch (Throwable ex) { Log.w(ex); }