Created
December 4, 2012 16:56
-
-
Save yoavweiss/4206150 to your computer and use it in GitHub Desktop.
Firefox on Android BW detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static private final double kDefaultBandwidth = -1.0; | |
static private final boolean kDefaultCanBeMetered = false; | |
static private final double kMaxBandwidth = 20.0; | |
static private final double kNetworkSpeedEthernet = 20.0; // 20 Mb/s | |
static private final double kNetworkSpeedWifi = 20.0; // 20 Mb/s | |
static private final double kNetworkSpeedWiMax = 40.0; // 40 Mb/s | |
static private final double kNetworkSpeed_2_G = 15.0 / 1024.0; // 15 kb/s | |
static private final double kNetworkSpeed_2_5_G = 60.0 / 1024.0; // 60 kb/s | |
static private final double kNetworkSpeed_2_75_G = 200.0 / 1024.0; // 200 kb/s | |
static private final double kNetworkSpeed_3_G = 300.0 / 1024.0; // 300 kb/s | |
static private final double kNetworkSpeed_3_5_G = 7.0; // 7 Mb/s | |
static private final double kNetworkSpeed_3_75_G = 20.0; // 20 Mb/s | |
static private final double kNetworkSpeed_3_9_G = 50.0; // 50 Mb/s | |
private static NetworkType getNetworkType() { | |
ConnectivityManager cm = | |
(ConnectivityManager)GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE); | |
if (cm == null) { | |
Log.w("GeckoNetworkManager", "Could not access Connectivity service"); | |
return NetworkType.NETWORK_NONE; | |
} | |
NetworkInfo ni = cm.getActiveNetworkInfo(); | |
if (ni == null) { | |
return NetworkType.NETWORK_NONE; | |
} | |
... | |
switch (tm.getNetworkType()) { | |
case TelephonyManager.NETWORK_TYPE_IDEN: | |
case TelephonyManager.NETWORK_TYPE_CDMA: | |
return NetworkType.NETWORK_2_G; | |
case TelephonyManager.NETWORK_TYPE_GPRS: | |
case TelephonyManager.NETWORK_TYPE_1xRTT: | |
return NetworkType.NETWORK_2_5_G; | |
case TelephonyManager.NETWORK_TYPE_EDGE: | |
return NetworkType.NETWORK_2_75_G; | |
case TelephonyManager.NETWORK_TYPE_UMTS: | |
case TelephonyManager.NETWORK_TYPE_EVDO_0: | |
return NetworkType.NETWORK_3_G; | |
case TelephonyManager.NETWORK_TYPE_HSPA: | |
case TelephonyManager.NETWORK_TYPE_HSDPA: | |
case TelephonyManager.NETWORK_TYPE_HSUPA: | |
case TelephonyManager.NETWORK_TYPE_EVDO_A: | |
case TelephonyManager.NETWORK_TYPE_EVDO_B: | |
case TelephonyManager.NETWORK_TYPE_EHRPD: | |
return NetworkType.NETWORK_3_5_G; | |
case TelephonyManager.NETWORK_TYPE_HSPAP: | |
return NetworkType.NETWORK_3_75_G; | |
case TelephonyManager.NETWORK_TYPE_LTE: | |
return NetworkType.NETWORK_3_9_G; | |
case TelephonyManager.NETWORK_TYPE_UNKNOWN: | |
default: | |
Log.w("GeckoNetworkManager", "Connected to an unknown mobile network!"); | |
return NetworkType.NETWORK_UNKNOWN; | |
} | |
} | |
private static double getNetworkSpeed(NetworkType aType) { | |
switch (aType) { | |
case NETWORK_NONE: | |
return 0.0; | |
case NETWORK_ETHERNET: | |
return kNetworkSpeedEthernet; | |
case NETWORK_WIFI: | |
return kNetworkSpeedWifi; | |
case NETWORK_WIMAX: | |
return kNetworkSpeedWiMax; | |
case NETWORK_2_G: | |
return kNetworkSpeed_2_G; | |
case NETWORK_2_5_G: | |
return kNetworkSpeed_2_5_G; | |
case NETWORK_2_75_G: | |
return kNetworkSpeed_2_75_G; | |
case NETWORK_3_G: | |
return kNetworkSpeed_3_G; | |
case NETWORK_3_5_G: | |
return kNetworkSpeed_3_5_G; | |
case NETWORK_3_75_G: | |
return kNetworkSpeed_3_75_G; | |
case NETWORK_3_9_G: | |
return kNetworkSpeed_3_9_G; | |
case NETWORK_UNKNOWN: | |
default: | |
return kDefaultBandwidth; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment