Fail-safe

This commit is contained in:
M66B 2020-03-23 19:48:43 +01:00
parent 7710722b0a
commit bc811325ab
1 changed files with 19 additions and 16 deletions

View File

@ -343,23 +343,26 @@ class ImageHelper {
lld.setLevel(1); lld.setLevel(1);
boolean slow = true; boolean slow = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
// 2G GSM ~14.4 Kbps try {
// G GPRS ~26.8 Kbps // 2G GSM ~14.4 Kbps
// E EDGE ~108.8 Kbps // G GPRS ~26.8 Kbps
// 3G UMTS ~128 Kbps // E EDGE ~108.8 Kbps
// H HSPA ~3.6 Mbps // 3G UMTS ~128 Kbps
// H+ HSPA+ ~14.4 Mbps-23.0 Mbps // H HSPA ~3.6 Mbps
// 4G LTE ~50 Mbps // H+ HSPA+ ~14.4 Mbps-23.0 Mbps
// 4G LTE-A ~500 Mbps // 4G LTE ~50 Mbps
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // 4G LTE-A ~500 Mbps
Network active = (cm == null ? null : cm.getActiveNetwork()); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkCapabilities caps = (active == null ? null : cm.getNetworkCapabilities(active)); Network active = (cm == null ? null : cm.getActiveNetwork());
if (caps != null) { NetworkCapabilities caps = (active == null ? null : cm.getNetworkCapabilities(active));
int kbps = caps.getLinkDownstreamBandwidthKbps(); if (caps != null) {
slow = (kbps < SLOW_CONNECTION); int kbps = caps.getLinkDownstreamBandwidthKbps();
slow = (kbps < SLOW_CONNECTION);
}
} catch (Throwable ex) {
Log.e(ex);
} }
}
ExecutorService executor = (slow ? executor_1 : executor_n); ExecutorService executor = (slow ? executor_1 : executor_n);