Extend rtc::AdapterType with 2g, 3G, 4G & 5G enum values.

This patch adds new enum values for different types of cellular
connections.

The new costs are currently blocked when sending to remote,
(so that arbitrary network switches does not starts occurring).

The end-game for this series to be able to distinguish between
different type of cellular connections in the ice-layer (e.g when
selecting/switching connections).

BUG: webrtc:11473
Change-Id: I587ac8fdff4f6cdd0f8905f327232f58818db4f6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/172582
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30970}
diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc
index 0e3a228..a9d5706 100644
--- a/p2p/base/connection.cc
+++ b/p2p/base/connection.cc
@@ -106,18 +106,24 @@
 }
 
 webrtc::IceCandidateNetworkType ConvertNetworkType(rtc::AdapterType type) {
-  if (type == rtc::ADAPTER_TYPE_ETHERNET) {
-    return webrtc::IceCandidateNetworkType::kEthernet;
-  } else if (type == rtc::ADAPTER_TYPE_LOOPBACK) {
-    return webrtc::IceCandidateNetworkType::kLoopback;
-  } else if (type == rtc::ADAPTER_TYPE_WIFI) {
-    return webrtc::IceCandidateNetworkType::kWifi;
-  } else if (type == rtc::ADAPTER_TYPE_VPN) {
-    return webrtc::IceCandidateNetworkType::kVpn;
-  } else if (type == rtc::ADAPTER_TYPE_CELLULAR) {
-    return webrtc::IceCandidateNetworkType::kCellular;
+  switch (type) {
+    case rtc::ADAPTER_TYPE_ETHERNET:
+      return webrtc::IceCandidateNetworkType::kEthernet;
+    case rtc::ADAPTER_TYPE_LOOPBACK:
+      return webrtc::IceCandidateNetworkType::kLoopback;
+    case rtc::ADAPTER_TYPE_WIFI:
+      return webrtc::IceCandidateNetworkType::kWifi;
+    case rtc::ADAPTER_TYPE_VPN:
+      return webrtc::IceCandidateNetworkType::kVpn;
+    case rtc::ADAPTER_TYPE_CELLULAR:
+    case rtc::ADAPTER_TYPE_CELLULAR_2G:
+    case rtc::ADAPTER_TYPE_CELLULAR_3G:
+    case rtc::ADAPTER_TYPE_CELLULAR_4G:
+    case rtc::ADAPTER_TYPE_CELLULAR_5G:
+      return webrtc::IceCandidateNetworkType::kCellular;
+    default:
+      return webrtc::IceCandidateNetworkType::kUnknown;
   }
-  return webrtc::IceCandidateNetworkType::kUnknown;
 }
 
 // When we don't have any RTT data, we have to pick something reasonable.  We
diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc
index 6a132a2..e3e6194 100644
--- a/p2p/base/p2p_transport_channel.cc
+++ b/p2p/base/p2p_transport_channel.cc
@@ -66,8 +66,16 @@
       return rtc::ADAPTER_TYPE_ETHERNET;
     case rtc::kNetworkCostLow:
       return rtc::ADAPTER_TYPE_WIFI;
-    case rtc::kNetworkCostHigh:
+    case rtc::kNetworkCostCellular:
       return rtc::ADAPTER_TYPE_CELLULAR;
+    case rtc::kNetworkCostCellular2G:
+      return rtc::ADAPTER_TYPE_CELLULAR_2G;
+    case rtc::kNetworkCostCellular3G:
+      return rtc::ADAPTER_TYPE_CELLULAR_3G;
+    case rtc::kNetworkCostCellular4G:
+      return rtc::ADAPTER_TYPE_CELLULAR_4G;
+    case rtc::kNetworkCostCellular5G:
+      return rtc::ADAPTER_TYPE_CELLULAR_5G;
     case rtc::kNetworkCostUnknown:
       return rtc::ADAPTER_TYPE_UNKNOWN;
     case rtc::kNetworkCostMax:
diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc
index 29c7d09..01799b4 100644
--- a/pc/rtc_stats_collector.cc
+++ b/pc/rtc_stats_collector.cc
@@ -184,6 +184,10 @@
 const char* NetworkAdapterTypeToStatsType(rtc::AdapterType type) {
   switch (type) {
     case rtc::ADAPTER_TYPE_CELLULAR:
+    case rtc::ADAPTER_TYPE_CELLULAR_2G:
+    case rtc::ADAPTER_TYPE_CELLULAR_3G:
+    case rtc::ADAPTER_TYPE_CELLULAR_4G:
+    case rtc::ADAPTER_TYPE_CELLULAR_5G:
       return RTCNetworkType::kCellular;
     case rtc::ADAPTER_TYPE_ETHERNET:
       return RTCNetworkType::kEthernet;
diff --git a/pc/stats_collector.cc b/pc/stats_collector.cc
index c5999da..b447b8f 100644
--- a/pc/stats_collector.cc
+++ b/pc/stats_collector.cc
@@ -483,6 +483,10 @@
     case rtc::ADAPTER_TYPE_WIFI:
       return STATSREPORT_ADAPTER_TYPE_WIFI;
     case rtc::ADAPTER_TYPE_CELLULAR:
+    case rtc::ADAPTER_TYPE_CELLULAR_2G:
+    case rtc::ADAPTER_TYPE_CELLULAR_3G:
+    case rtc::ADAPTER_TYPE_CELLULAR_4G:
+    case rtc::ADAPTER_TYPE_CELLULAR_5G:
       return STATSREPORT_ADAPTER_TYPE_WWAN;
     case rtc::ADAPTER_TYPE_VPN:
       return STATSREPORT_ADAPTER_TYPE_VPN;
diff --git a/rtc_base/network.cc b/rtc_base/network.cc
index 07b121b..ffa8f94 100644
--- a/rtc_base/network.cc
+++ b/rtc_base/network.cc
@@ -86,6 +86,8 @@
 }
 
 uint16_t ComputeNetworkCostByType(int type) {
+  // TODO(jonaso) : Rollout support for cellular network cost using A/B
+  // experiment to make sure it does not introduce regressions.
   switch (type) {
     case rtc::ADAPTER_TYPE_ETHERNET:
     case rtc::ADAPTER_TYPE_LOOPBACK:
@@ -93,7 +95,11 @@
     case rtc::ADAPTER_TYPE_WIFI:
       return kNetworkCostLow;
     case rtc::ADAPTER_TYPE_CELLULAR:
-      return kNetworkCostHigh;
+    case rtc::ADAPTER_TYPE_CELLULAR_2G:
+    case rtc::ADAPTER_TYPE_CELLULAR_3G:
+    case rtc::ADAPTER_TYPE_CELLULAR_4G:
+    case rtc::ADAPTER_TYPE_CELLULAR_5G:
+      return kNetworkCostCellular;
     case rtc::ADAPTER_TYPE_ANY:
       // Candidates gathered from the any-address/wildcard ports, as backups,
       // are given the maximum cost so that if there are other candidates with
diff --git a/rtc_base/network.h b/rtc_base/network.h
index fb40166..ed601a5 100644
--- a/rtc_base/network.h
+++ b/rtc_base/network.h
@@ -409,6 +409,19 @@
 
   bool IsVpn() const { return type_ == ADAPTER_TYPE_VPN; }
 
+  bool IsCellular() const {
+    switch (type_) {
+      case ADAPTER_TYPE_CELLULAR:
+      case ADAPTER_TYPE_CELLULAR_2G:
+      case ADAPTER_TYPE_CELLULAR_3G:
+      case ADAPTER_TYPE_CELLULAR_4G:
+      case ADAPTER_TYPE_CELLULAR_5G:
+        return true;
+      default:
+        return false;
+    }
+  }
+
   uint16_t GetCost() const;
   // A unique id assigned by the network manager, which may be signaled
   // to the remote side in the candidate.
diff --git a/rtc_base/network_constants.cc b/rtc_base/network_constants.cc
index 2cb5233..905aa36 100644
--- a/rtc_base/network_constants.cc
+++ b/rtc_base/network_constants.cc
@@ -26,6 +26,14 @@
       return "Wifi";
     case ADAPTER_TYPE_CELLULAR:
       return "Cellular";
+    case ADAPTER_TYPE_CELLULAR_2G:
+      return "Cellular2G";
+    case ADAPTER_TYPE_CELLULAR_3G:
+      return "Cellular3G";
+    case ADAPTER_TYPE_CELLULAR_4G:
+      return "Cellular4G";
+    case ADAPTER_TYPE_CELLULAR_5G:
+      return "Cellular5G";
     case ADAPTER_TYPE_VPN:
       return "VPN";
     case ADAPTER_TYPE_LOOPBACK:
diff --git a/rtc_base/network_constants.h b/rtc_base/network_constants.h
index 1b43243..cdb505f 100644
--- a/rtc_base/network_constants.h
+++ b/rtc_base/network_constants.h
@@ -17,18 +17,25 @@
 
 namespace rtc {
 
-static const uint16_t kNetworkCostMax = 999;
-static const uint16_t kNetworkCostHigh = 900;
-static const uint16_t kNetworkCostUnknown = 50;
-static const uint16_t kNetworkCostLow = 10;
-static const uint16_t kNetworkCostMin = 0;
+constexpr uint16_t kNetworkCostMax = 999;
+constexpr uint16_t kNetworkCostCellular2G = 980;
+constexpr uint16_t kNetworkCostCellular3G = 910;
+constexpr uint16_t kNetworkCostCellular = 900;
+constexpr uint16_t kNetworkCostCellular4G = 500;
+constexpr uint16_t kNetworkCostCellular5G = 250;
+constexpr uint16_t kNetworkCostUnknown = 50;
+constexpr uint16_t kNetworkCostLow = 10;
+constexpr uint16_t kNetworkCostMin = 0;
+
+// alias
+constexpr uint16_t kNetworkCostHigh = kNetworkCostCellular;
 
 enum AdapterType {
   // This enum resembles the one in Chromium net::ConnectionType.
   ADAPTER_TYPE_UNKNOWN = 0,
   ADAPTER_TYPE_ETHERNET = 1 << 0,
   ADAPTER_TYPE_WIFI = 1 << 1,
-  ADAPTER_TYPE_CELLULAR = 1 << 2,
+  ADAPTER_TYPE_CELLULAR = 1 << 2,  // This is CELLULAR of unknown type.
   ADAPTER_TYPE_VPN = 1 << 3,
   ADAPTER_TYPE_LOOPBACK = 1 << 4,
   // ADAPTER_TYPE_ANY is used for a network, which only contains a single "any
@@ -37,6 +44,10 @@
   // when the network uses a specific interface/IP, but its interface type can
   // not be determined or not fit in this enum.
   ADAPTER_TYPE_ANY = 1 << 5,
+  ADAPTER_TYPE_CELLULAR_2G = 1 << 6,
+  ADAPTER_TYPE_CELLULAR_3G = 1 << 7,
+  ADAPTER_TYPE_CELLULAR_4G = 1 << 8,
+  ADAPTER_TYPE_CELLULAR_5G = 1 << 9
 };
 
 std::string AdapterTypeToString(AdapterType type);