Merge pull request #28 from hai007/cl-348050035

Roll forward to Cl/348050035
diff --git a/cpp/core/internal/mediums/webrtc/peer_connection_observer_impl.cc b/cpp/core/internal/mediums/webrtc/peer_connection_observer_impl.cc
index ec21286..8fb6c8e 100644
--- a/cpp/core/internal/mediums/webrtc/peer_connection_observer_impl.cc
+++ b/cpp/core/internal/mediums/webrtc/peer_connection_observer_impl.cc
@@ -30,7 +30,6 @@
 
 void PeerConnectionObserverImpl::OnIceCandidate(
     const webrtc::IceCandidateInterface* candidate) {
-  NEARBY_LOG(INFO, "OnIceCandidate");
   local_ice_candidate_listener_.local_ice_candidate_found_cb(candidate);
 }
 
diff --git a/cpp/core/internal/p2p_cluster_pcp_handler.cc b/cpp/core/internal/p2p_cluster_pcp_handler.cc
index 6f16791..90da296 100644
--- a/cpp/core/internal/p2p_cluster_pcp_handler.cc
+++ b/cpp/core/internal/p2p_cluster_pcp_handler.cc
@@ -151,12 +151,14 @@
 Status P2pClusterPcpHandler::StopAdvertisingImpl(ClientProxy* client) {
   if (client->GetClientId() == bluetooth_classic_advertiser_client_id_) {
     bluetooth_medium_.TurnOffDiscoverability();
+    bluetooth_classic_advertiser_client_id_ = 0;
   } else {
     NEARBY_LOG(INFO,
                "Skipped BT TurnOffDiscoverability for client %d, client that "
                "turned on discoverability is %d",
                client->GetClientId(), bluetooth_classic_advertiser_client_id_);
   }
+
   bluetooth_medium_.StopAcceptingConnections(client->GetAdvertisingServiceId());
 
   ble_medium_.StopAdvertising(client->GetAdvertisingServiceId());
@@ -635,12 +637,14 @@
   wifi_lan_medium_.StopDiscovery(client->GetDiscoveryServiceId());
   if (client->GetClientId() == bluetooth_classic_discoverer_client_id_) {
     bluetooth_medium_.StopDiscovery();
+    bluetooth_classic_discoverer_client_id_ = 0;
   } else {
     NEARBY_LOG(INFO,
                "Skipped BT stopDiscovery for client %d, client that started "
                "discovery is %d",
                client->GetClientId(), bluetooth_classic_discoverer_client_id_);
   }
+
   ble_medium_.StopScanning(client->GetDiscoveryServiceId());
   return {Status::kSuccess};
 }
diff --git a/cpp/core/internal/p2p_cluster_pcp_handler.h b/cpp/core/internal/p2p_cluster_pcp_handler.h
index 43c58b6..4c25b6d 100644
--- a/cpp/core/internal/p2p_cluster_pcp_handler.h
+++ b/cpp/core/internal/p2p_cluster_pcp_handler.h
@@ -200,8 +200,8 @@
   WifiLan& wifi_lan_medium_;
   mediums::WebRtc& webrtc_medium_;
   InjectedBluetoothDeviceStore& injected_bluetooth_device_store_;
-  std::int64_t bluetooth_classic_discoverer_client_id_;
-  std::int64_t bluetooth_classic_advertiser_client_id_;
+  std::int64_t bluetooth_classic_discoverer_client_id_{0};
+  std::int64_t bluetooth_classic_advertiser_client_id_{0};
 };
 
 }  // namespace connections
diff --git a/cpp/core/internal/payload_manager.cc b/cpp/core/internal/payload_manager.cc
index a471c29..1874a2a 100644
--- a/cpp/core/internal/payload_manager.cc
+++ b/cpp/core/internal/payload_manager.cc
@@ -48,13 +48,6 @@
       EndpointsToEndpointIds(pair.first);
   const Endpoints& unavailable_endpoints = pair.second;
 
-  NEARBY_LOG(INFO,
-             "SendPayloadLoop: Available: { %s }; Unavailable: { %s }; "
-             "payload_id=%" PRIX64 "; self=%p",
-             ToString(available_endpoint_ids).c_str(),
-             ToString(unavailable_endpoints).c_str(),
-             static_cast<Payload::Id>(payload_header.id()), this);
-
   // First, handle any non-available endpoints.
   for (const auto& endpoint : unavailable_endpoints) {
     HandleFinishedOutgoingPayload(
@@ -157,8 +150,6 @@
   Endpoints available;
   Endpoints unavailable;
   for (auto* endpoint_info : pending_payload.GetEndpoints()) {
-    NEARBY_LOG(INFO, "EndpointInfo: %p; id=%s; status=%d", endpoint_info,
-               endpoint_info->id.c_str(), endpoint_info->status.Get());
     if (endpoint_info->status.Get() ==
         PayloadManager::EndpointInfo::Status::kAvailable) {
       available.push_back(endpoint_info);
@@ -387,19 +378,15 @@
       ProcessControlPacket(to_client, from_endpoint_id, frame);
       break;
     case PayloadTransferFrame::DATA:
-      NEARBY_LOG(INFO, "PayloadManager::OnIncomingFrame [DATA]: self=%p; id=%s",
-                 this, from_endpoint_id.c_str());
       ProcessDataPacket(to_client, from_endpoint_id, frame);
       break;
     default:
       NEARBY_LOG(
-          INFO,
+          WARNING,
           "PayloadManager: invalid frame; remote endpoint: self=%p; id=%s",
           this, from_endpoint_id.c_str());
       break;
   }
-  NEARBY_LOG(INFO, "PayloadManager::OnIncomingFrame [DONE]: self=%p; id=%s",
-             this, from_endpoint_id.c_str());
 }
 
 void PayloadManager::OnEndpointDisconnect(ClientProxy* client,
@@ -815,7 +802,7 @@
   } else {
     pending_payload = GetPayload(payload_header.id());
     if (!pending_payload) {
-      NEARBY_LOG(INFO,
+      NEARBY_LOG(WARNING,
                  "ProcessDataPacket: [missing] id=%s; payload_id=%" PRIX64,
                  from_endpoint_id.c_str(),
                  static_cast<std::int64_t>(payload_header.id()));
@@ -847,7 +834,7 @@
   if (pending_payload->GetInternalPayload()
           ->AttachNextChunk(ByteArray(std::move(*payload_chunk.mutable_body())))
           .Raised()) {
-    NEARBY_LOG(INFO,
+    NEARBY_LOG(WARNING,
                "ProcessDataPacket: [data: error] id=%s; payload_id=%" PRIX64,
                from_endpoint_id.c_str(), pending_payload->GetId());
     HandleFinishedIncomingPayload(
@@ -856,8 +843,6 @@
     return;
   }
 
-  NEARBY_LOG(INFO, "ProcessDataPacket: [data: ok] id=%s; payload_id=%" PRIX64,
-             from_endpoint_id.c_str(), pending_payload->GetId());
   HandleSuccessfulIncomingChunk(to_client, from_endpoint_id, payload_header,
                                 payload_chunk.flags(), payload_chunk.offset(),
                                 payload_body_size);
diff --git a/cpp/platform/public/ble.cc b/cpp/platform/public/ble.cc
index 3f0bf92..4e5670d 100644
--- a/cpp/platform/public/ble.cc
+++ b/cpp/platform/public/ble.cc
@@ -51,18 +51,10 @@
                 auto pair = peripherals_.emplace(
                     &peripheral, absl::make_unique<ScanningInfo>());
                 auto& context = *pair.first->second;
-                if (!pair.second) {
-                  NEARBY_LOG(INFO,
-                             "Discovering (again) peripheral=%p, impl=%p, "
-                             "peripheral name=%s",
-                             &context.peripheral, &peripheral,
-                             peripheral.GetName().c_str());
-                } else {
+                if (pair.second) {
                   context.peripheral = BlePeripheral(&peripheral);
                   NEARBY_LOG(INFO,
-                             "Discovering peripheral=%p, impl=%p, "
-                             "peripheral name=%s",
-                             &context.peripheral, &peripheral,
+                             "Discovered peripheral '%s'",
                              peripheral.GetName().c_str());
                   discovered_peripheral_callback_.peripheral_discovered_cb(
                       context.peripheral, service_id,
diff --git a/proto/connections/offline_wire_formats.proto b/proto/connections/offline_wire_formats.proto
index 0a3de54..f5ddfbb 100644
--- a/proto/connections/offline_wire_formats.proto
+++ b/proto/connections/offline_wire_formats.proto
@@ -280,6 +280,8 @@
   optional bytes ip_address = 3;
   // True if local device supports 6GHz.
   optional bool supports_6_ghz = 4;
+  // True if local device has mobile radio.
+  optional bool mobile_radio = 5;
 }
 
 // LocationHint is used to specify a location as well as format.