Bug fixes for 233012255 and 232995024
Refactor bluetooth_adapter setname and getname to remove logic errors, array overruns, and leaking memory.
Refactor bluetooth discovery callbacks to prevent getting updates before we have cached the device found.
Refactor the dart code interfaces to more closely align between the dll and the dart UI, and move from using the device name (which can be easily duplicated) as the primary key to using endpoint_id as the primary key for all calls into the dll.

PiperOrigin-RevId: 451248048
diff --git a/connections/clients/ios/Internal/GNCPayloadListener.mm b/connections/clients/ios/Internal/GNCPayloadListener.mm
index 128375b..037e071 100644
--- a/connections/clients/ios/Internal/GNCPayloadListener.mm
+++ b/connections/clients/ios/Internal/GNCPayloadListener.mm
@@ -147,7 +147,8 @@
     case PayloadType::kFile:
       if (handlers.filePayloadHandler) {
         InputFile *payloadInputFile = payload.AsFile();
-        NSString *fileString = ObjCStringFromCppString(payloadInputFile->GetFilePath());
+        NSString *fileString =
+            ObjCStringFromCppString(std::string(payloadInputFile->GetFilePath()));
         NSURL *fileURL = [NSURL fileURLWithPath:fileString];
         int64_t fileSize = payloadInputFile->GetTotalSize();
         NSProgress *progress = [NSProgress progressWithTotalUnitCount:fileSize];
diff --git a/connections/clients/windows/dart/core_adapter_dart.h b/connections/clients/windows/dart/core_adapter_dart.h
index 084ffb0..5c83c8b 100644
--- a/connections/clients/windows/dart/core_adapter_dart.h
+++ b/connections/clients/windows/dart/core_adapter_dart.h
@@ -42,6 +42,9 @@
   int64_t ble;
   int64_t wifi_lan;
   int64_t wifi_hotspot;
+  int64_t nfc;
+  int64_t wifi_aware;
+  int64_t wifi_direct;
   int64_t web_rtc;
   // LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/mediums.dart)
 };
@@ -53,6 +56,7 @@
   StrategyDart strategy;
   int64_t auto_upgrade_bandwidth;
   int64_t enforce_topology_constraints;
+  int64_t use_fast_advertisements;
   int64_t low_power;
 
   // Whether this is intended to be used in conjunction with InjectEndpoint().
@@ -73,11 +77,13 @@
 
   // Whether this is intended to be used in conjunction with InjectEndpoint().
   int64_t is_out_of_band_connection = false;
-  char *remote_bluetooth_mac_address;
-  char *fast_advertisement_service_uuid;
+
   int64_t keep_alive_interval_millis;
   int64_t keep_alive_timeout_millis;
 
+  char *remote_bluetooth_mac_address;
+  char *fast_advertisement_service_uuid;
+
   Mediums mediums;
   // LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/connection_options.dart)
 };
@@ -87,11 +93,14 @@
   StrategyDart strategy;
   int64_t auto_upgrade_bandwidth;
   int64_t enforce_topology_constraints;
-  int64_t keep_alive_interval_millis = 0;
-  int64_t keep_alive_timeout_millis = 0;
+  int64_t discover_fast_advertisements;
 
   // Whether this is intended to be used in conjunction with InjectEndpoint().
   int64_t is_out_of_band_connection = false;
+
+  int64_t keep_alive_interval_millis = 0;
+  int64_t keep_alive_timeout_millis = 0;
+
   const char *fast_advertisement_service_uuid;
   const char *remote_bluetooth_mac_address;
 
diff --git a/connections/clients/windows/medium_selector_w.h b/connections/clients/windows/medium_selector_w.h
index 9cf056c..4669d98 100644
--- a/connections/clients/windows/medium_selector_w.h
+++ b/connections/clients/windows/medium_selector_w.h
@@ -25,21 +25,26 @@
 struct MediumSelectorW {
   T bluetooth;
   T ble;
-  T web_rtc;
   T wifi_lan;
   T wifi_hotspot;
+  T nfc;
+  T wifi_aware;
+  T wifi_direct;
+  T web_rtc;
 
   constexpr MediumSelectorW() = default;
   constexpr MediumSelectorW(const MediumSelectorW&) = default;
   constexpr MediumSelectorW& operator=(const MediumSelectorW&) = default;
   constexpr bool Any(const T& value) const {
-    return bluetooth == value || ble == value || web_rtc == value ||
-           wifi_lan == value || wifi_hotspot == value;
+    return bluetooth == value || ble == value || wifi_lan == value ||
+           wifi_hotspot == value || nfc == value || wifi_aware == value ||
+           wifi_direct == value || web_rtc == value;
   }
 
   constexpr bool All(const T& value) const {
-    return bluetooth == value && ble == value && web_rtc == value &&
-           wifi_lan == value && wifi_hotspot == value;
+    return bluetooth == value && ble == value && wifi_lan == value &&
+           wifi_hotspot == value && nfc == value && wifi_aware == value &&
+           wifi_direct == value && web_rtc == value;
   }
 
   constexpr int Count(const T& value) const {
@@ -48,6 +53,9 @@
     if (ble == value) ++count;
     if (wifi_lan == value) ++count;
     if (wifi_hotspot == value) ++count;
+    if (nfc == value) ++count;
+    if (wifi_aware == value) ++count;
+    if (wifi_direct == value) ++count;
     if (web_rtc == value) ++count;
     return count;
   }
@@ -55,9 +63,12 @@
   constexpr MediumSelectorW& SetAll(const T& value) {
     bluetooth = value;
     ble = value;
-    web_rtc = value;
     wifi_lan = value;
     wifi_hotspot = value;
+    nfc = value;
+    wifi_aware = value;
+    wifi_direct = value;
+    web_rtc = value;
     return *this;
   }
 
@@ -69,6 +80,9 @@
     if (web_rtc == value) mediums.push_back(MediumW::WEB_RTC);
     if (bluetooth == value) mediums.push_back(MediumW::BLUETOOTH);
     if (ble == value) mediums.push_back(MediumW::BLE);
+    if (nfc == value) mediums.push_back(MediumW::NFC);
+    if (wifi_aware == value) mediums.push_back(MediumW::WIFI_AWARE);
+    if (wifi_direct == value) mediums.push_back(MediumW::WIFI_DIRECT);
     return mediums;
   }
 };
diff --git a/connections/payload.cc b/connections/payload.cc
index 9b05384..b30e9d5 100644
--- a/connections/payload.cc
+++ b/connections/payload.cc
@@ -21,14 +21,14 @@
 namespace connections {
 
 namespace {
-std::string SepFinder(std::string s, size_t index) {
-  std::string filename = s.substr(index + 1, s.length() - index);
+std::string_view SepFinder(std::string_view s, size_t index) {
+  std::string_view filename = s.substr(index + 1, s.length() - index);
   size_t lastindex = filename.find_last_of('.');
-  std::string rawname = filename.substr(0, lastindex);
+  std::string_view rawname = filename.substr(0, lastindex);
   return rawname;
 }
 
-std::string getFileName(const std::string& s) {
+std::string_view getFileName(const std::string_view s) {
   char forwardSep = '/';
   char backwardSep = '\\';
 
@@ -46,20 +46,20 @@
     // and if backward sep doesn't exist
     if (lastBackwardSepIndex == std::string::npos) {
       // Construct filename from forward sep
-      std::string rawname = SepFinder(s, lastForwardSepIndex);
+      std::string_view rawname = SepFinder(s, lastForwardSepIndex);
       return (rawname);
     }
     // backward sep also exists
     if (lastForwardSepIndex > lastBackwardSepIndex) {
       // the forward sep is the last
-      std::string rawname = SepFinder(s, lastForwardSepIndex);
+      std::string_view rawname = SepFinder(s, lastForwardSepIndex);
       return (rawname);
     }
     // The backward sep is the last
-    std::string rawname = SepFinder(s, lastBackwardSepIndex);
+    std::string_view rawname = SepFinder(s, lastBackwardSepIndex);
     return (rawname);
   }
-  std::string rawname = SepFinder(s, lastBackwardSepIndex);
+  std::string_view rawname = SepFinder(s, lastBackwardSepIndex);
   return (rawname);
 }
 
@@ -84,7 +84,7 @@
     : type_(PayloadType::kBytes), content_(bytes) {}
 
 Payload::Payload(InputFile input_file)
-    : id_(std::hash<std::string>()(input_file.GetFilePath())),
+    : id_(std::hash<std::string_view>()(input_file.GetFilePath())),
       file_name_(getFileName(input_file.GetFilePath())),
       type_(PayloadType::kFile),
       content_(std::move(input_file)) {}
@@ -97,7 +97,7 @@
 
 Payload::Payload(std::string parent_folder, std::string file_name,
                  InputFile input_file)
-    : id_(std::hash<std::string>()(input_file.GetFilePath())),
+    : id_(std::hash<std::string_view>()(input_file.GetFilePath())),
       parent_folder_(parent_folder),
       file_name_(file_name),
       type_(PayloadType::kFile),
diff --git a/internal/platform/file.cc b/internal/platform/file.cc
index c151646..9aabab6 100644
--- a/internal/platform/file.cc
+++ b/internal/platform/file.cc
@@ -33,7 +33,7 @@
 }
 
 // Returns a string that uniqely identifies this file.
-std::string InputFile::GetFilePath() const { return impl_->GetFilePath(); }
+std::string_view InputFile::GetFilePath() const { return impl_->GetFilePath(); }
 
 // Returns total size of this file in bytes.
 std::int64_t InputFile::GetTotalSize() const { return impl_->GetTotalSize(); }
diff --git a/internal/platform/file.h b/internal/platform/file.h
index 93be7af..b08e8ee 100644
--- a/internal/platform/file.h
+++ b/internal/platform/file.h
@@ -50,7 +50,7 @@
   ExceptionOr<ByteArray> Read(std::int64_t size);
 
   // Returns a string that uniqely identifies this file.
-  std::string GetFilePath() const;
+  std::string_view GetFilePath() const;
 
   // Returns total size of this file in bytes.
   std::int64_t GetTotalSize() const;
diff --git a/internal/platform/implementation/input_file.h b/internal/platform/implementation/input_file.h
index 4129b52..437fdd7 100644
--- a/internal/platform/implementation/input_file.h
+++ b/internal/platform/implementation/input_file.h
@@ -29,7 +29,7 @@
 class InputFile : public InputStream {
  public:
   ~InputFile() override = default;
-  virtual std::string GetFilePath() const = 0;
+  virtual std::string_view GetFilePath() const = 0;
   virtual std::int64_t GetTotalSize() const = 0;
 };
 
diff --git a/internal/platform/implementation/shared/file.h b/internal/platform/implementation/shared/file.h
index 2efcc6d..663eb13 100644
--- a/internal/platform/implementation/shared/file.h
+++ b/internal/platform/implementation/shared/file.h
@@ -35,9 +35,7 @@
   static std::unique_ptr<IOFile> CreateOutputFile(const absl::string_view path);
 
   ExceptionOr<ByteArray> Read(std::int64_t size) override;
-  std::string GetFilePath() const override {
-    return std::string(path_.data(), path_.size());
-  }
+  std::string_view GetFilePath() const override { return path_; }
   std::int64_t GetTotalSize() const override { return total_size_; }
   Exception Close() override;
 
diff --git a/internal/platform/implementation/windows/bluetooth_adapter.cc b/internal/platform/implementation/windows/bluetooth_adapter.cc
index 21cf270..ab56181 100644
--- a/internal/platform/implementation/windows/bluetooth_adapter.cc
+++ b/internal/platform/implementation/windows/bluetooth_adapter.cc
@@ -52,8 +52,7 @@
       winrt::Windows::Devices::Bluetooth::BluetoothAdapter::GetDefaultAsync()
           .get();
   if (windows_bluetooth_adapter_ == nullptr) {
-    NEARBY_LOGS(ERROR)
-        << __func__ << ": No Bluetooth adapter on this device.";
+    NEARBY_LOGS(ERROR) << __func__ << ": No Bluetooth adapter on this device.";
   } else {
     // Gets the radio represented by this Bluetooth adapter.
     // https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothadapter.getradioasync?view=winrt-20348
@@ -65,8 +64,7 @@
 // returns true if the operation was a success.
 bool BluetoothAdapter::SetStatus(Status status) {
   if (windows_bluetooth_radio_ == nullptr) {
-    NEARBY_LOGS(ERROR)
-        << __func__ << ": No Bluetooth radio on this device.";
+    NEARBY_LOGS(ERROR) << __func__ << ": No Bluetooth radio on this device.";
     return false;
   }
   if (status == Status::kDisabled) {
@@ -84,8 +82,7 @@
 // Status::Value::kEnabled.
 bool BluetoothAdapter::IsEnabled() const {
   if (windows_bluetooth_radio_ == nullptr) {
-    NEARBY_LOGS(ERROR)
-        << __func__ << ": No Bluetooth radio on this device.";
+    NEARBY_LOGS(ERROR) << __func__ << ": No Bluetooth radio on this device.";
     return false;
   }
   // Gets the current state of the radio represented by this object.
@@ -154,7 +151,7 @@
                // key
 
   if (status == ERROR_SUCCESS) {
-    DWORD local_name_size;
+    DWORD local_name_size = 0;
     DWORD value_type;
 
     // Retrieves the size of the data for the specified value name associated
@@ -173,42 +170,42 @@
         &local_name_size);  // A pointer to a variable that specifies the
                             // size of the buffer pointed to by the lpData
                             // parameter, in bytes.
-    if (status != ERROR_SUCCESS) {
+    if (status == ERROR_SUCCESS) {
+      unsigned char *local_name = new unsigned char[local_name_size];
+      memset(local_name, '\0', local_name_size);
+
+      status = RegQueryValueExA(
+          hKey,  // A handle to an open registry key.
+          BLUETOOTH_RADIO_REGISTRY_NAME_KEY,  // The name of the registry
+                                              // value.
+          nullptr,            // This parameter is reserved and must be NULL.
+          &value_type,        // A pointer to a variable that receives a code
+                              // indicating the type of data stored in the
+                              // specified value.
+          local_name,         // A pointer to a buffer that
+                              // receives the value's data.
+          &local_name_size);  // A pointer to a variable that specifies the
+                              // size of the buffer pointed to by the lpData
+                              // parameter, in bytes.
+
+      // Closes a handle to the specified registry key.
+      // https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
+      RegCloseKey(hKey);
+
+      if (status == ERROR_SUCCESS) {
+        std::string local_name_return = std::string(
+            local_name, local_name + local_name_size / sizeof local_name[0]);
+
+        delete[] local_name;
+
+        return local_name_return;
+      }
+      delete[] local_name;
+    } else {
       NEARBY_LOGS(ERROR)
           << __func__
           << ": Failed to get the required size of the local name buffer";
-      return {};
     }
-    unsigned char *local_name = new unsigned char[local_name_size];
-    memset(local_name, '\0', local_name_size);
-
-    status = RegQueryValueExA(
-        hKey,                               // A handle to an open registry key.
-        BLUETOOTH_RADIO_REGISTRY_NAME_KEY,  // The name of the registry
-                                            // value.
-        nullptr,            // This parameter is reserved and must be NULL.
-        &value_type,        // A pointer to a variable that receives a code
-                            // indicating the type of data stored in the
-                            // specified value.
-        local_name,         // A pointer to a buffer that
-                            // receives the value's data.
-        &local_name_size);  // A pointer to a variable that specifies the
-                            // size of the buffer pointed to by the lpData
-                            // parameter, in bytes.
-
-    // Closes a handle to the specified registry key.
-    // https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
-    RegCloseKey(hKey);
-
-    if (status == ERROR_SUCCESS) {
-      std::string local_name_return = std::string(
-          local_name, local_name + local_name_size / sizeof local_name[0]);
-
-      delete[] local_name;
-
-      return local_name_return;
-    }
-    delete[] local_name;
   }
 
   // The local name is not in the registry, return the machine name
@@ -222,7 +219,7 @@
     return {};
   }
 
-  local_name.reserve(name_size);
+  local_name.resize(name_size);
 
   // Retrieves the NetBIOS name of the local computer.
   // https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcomputernamea
@@ -398,9 +395,8 @@
         0,           // This parameter is reserved and must be zero.
         REG_BINARY,  // The type of data pointed to by the lpData parameter.
         (LPBYTE)std::string(name).c_str(),  // The data to be stored.
-        strlen(std::string(name)
-                   .c_str()));  // The size of the information pointed
-                                // to by the lpData parameter, in bytes.
+        std::string(name).size());  // The size of the information pointed
+                                    // to by the lpData parameter, in bytes.
   } else {
     // If we are told to set the key to "", we treat this as a reset
     // If we delete the key value the OS will default to the system
@@ -551,8 +547,7 @@
 // Returns BT MAC address assigned to this adapter.
 std::string BluetoothAdapter::GetMacAddress() const {
   if (windows_bluetooth_adapter_ == nullptr) {
-    NEARBY_LOGS(ERROR)
-        << __func__ << ": No Bluetooth adapter on this device.";
+    NEARBY_LOGS(ERROR) << __func__ << ": No Bluetooth adapter on this device.";
     return "";
   }
   return uint64_to_mac_address_string(
diff --git a/internal/platform/implementation/windows/bluetooth_classic_medium.cc b/internal/platform/implementation/windows/bluetooth_classic_medium.cc
index d93d88a..fd672aa 100644
--- a/internal/platform/implementation/windows/bluetooth_classic_medium.cc
+++ b/internal/platform/implementation/windows/bluetooth_classic_medium.cc
@@ -68,6 +68,7 @@
 bool BluetoothClassicMedium::StartDiscovery(
     BluetoothClassicMedium::DiscoveryCallback discovery_callback) {
   EnterCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "StartDisovery entered critical section.";
 
   bool result = false;
   discovery_callback_ = discovery_callback;
@@ -77,13 +78,14 @@
   }
 
   LeaveCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "StartDisovery left critical section.";
 
   return result;
 }
 
 bool BluetoothClassicMedium::StopDiscovery() {
   EnterCriticalSection(&critical_section_);
-
+  NEARBY_LOGS(INFO) << "StopDiscovery entered critical section.";
   bool result = false;
 
   if (IsWatcherStarted()) {
@@ -91,6 +93,7 @@
   }
 
   LeaveCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "StopDiscovery left critical section.";
 
   return result;
 }
@@ -182,6 +185,7 @@
   }
 
   EnterCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "ConnectToService entered critical section.";
 
   std::unique_ptr<BluetoothSocket> rfcommSocket =
       std::make_unique<BluetoothSocket>();
@@ -200,11 +204,13 @@
                        << exception.what();
 
     LeaveCriticalSection(&critical_section_);
+    NEARBY_LOGS(INFO) << "ConnectToService left critical section.";
 
     return nullptr;
   }
 
   LeaveCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "ConnectToService left critical section.";
 
   return rfcommSocket;
 }
@@ -366,6 +372,9 @@
 
 winrt::fire_and_forget BluetoothClassicMedium::DeviceWatcher_Added(
     DeviceWatcher sender, DeviceInformation deviceInfo) {
+  EnterCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "DeviceWatcher_Added entered critical section.";
+  NEARBY_LOGS(INFO) << "Device added " << winrt::to_string(deviceInfo.Id());
   if (IsWatcherStarted()) {
     // Represents a Bluetooth device.
     // https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothdevice?view=winrt-20348
@@ -378,45 +387,52 @@
 
     // Add to our internal list if necessary
     if (it != discovered_devices_by_id_.end()) {
-      // We're already tracking this one
+      // We're already tracking this one  NEARBY_LOGS(INFO) <<
+      // "DeviceWatcher_Added entered critical section.";
+
+      LeaveCriticalSection(&critical_section_);
+      NEARBY_LOGS(INFO) << "DeviceWatcher_Added left critical section.";
+
       return winrt::fire_and_forget();
     }
 
     // Create a bluetooth device out of this id
-    winrt::Windows::Devices::Bluetooth::BluetoothDevice::FromIdAsync(
-        deviceInfo.Id())
-        .Completed([this, deviceInfo](
-                       winrt::Windows::Foundation::IAsyncOperation<
-                           winrt::Windows::Devices::Bluetooth::BluetoothDevice>
-                           bluetoothDevice,
-                       winrt::Windows::Foundation::AsyncStatus status) {
-          EnterCriticalSection(&critical_section_);
+    auto bluetoothDevice =
+        winrt::Windows::Devices::Bluetooth::BluetoothDevice::FromIdAsync(
+            deviceInfo.Id())
+            .get();
 
-          auto bluetoothDeviceP =
-              absl::WrapUnique(new BluetoothDevice(bluetoothDevice.get()));
+    auto bluetoothDeviceP =
+        absl::WrapUnique(new BluetoothDevice(bluetoothDevice));
 
-          discovered_devices_by_id_[deviceInfo.Id()] =
-              std::move(bluetoothDeviceP);
+    discovered_devices_by_id_[deviceInfo.Id()] = std::move(bluetoothDeviceP);
 
-          if (discovery_callback_.device_discovered_cb != nullptr) {
-            discovery_callback_.device_discovered_cb(
-                *discovered_devices_by_id_[deviceInfo.Id()]);
-          }
-
-          LeaveCriticalSection(&critical_section_);
-        });
+    if (discovery_callback_.device_discovered_cb != nullptr) {
+      discovery_callback_.device_discovered_cb(
+          *discovered_devices_by_id_[deviceInfo.Id()]);
+    }
   }
 
+  LeaveCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "DeviceWatcher_Added left critical section.";
+
   return winrt::fire_and_forget();
 }
 
 winrt::fire_and_forget BluetoothClassicMedium::DeviceWatcher_Updated(
     DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate) {
   EnterCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "DeviceWatcher_Updated entered critical section.";
+
+  NEARBY_LOGS(INFO)
+      << "Device updated "
+      << discovered_devices_by_id_[deviceInfoUpdate.Id()]->GetName() << " ("
+      << winrt::to_string(deviceInfoUpdate.Id()) << ")";
 
   if (!IsWatcherStarted()) {
     // Spurious call, watcher has stopped or wasn't started
     LeaveCriticalSection(&critical_section_);
+    NEARBY_LOGS(INFO) << "DeviceWatcher_Updated left critical section.";
     return winrt::fire_and_forget();
   }
 
@@ -424,6 +440,7 @@
 
   if (it == discovered_devices_by_id_.end()) {
     LeaveCriticalSection(&critical_section_);
+    NEARBY_LOGS(INFO) << "DeviceWatcher_Updated left critical section.";
     // Not tracking this device
     return winrt::fire_and_forget();
   }
@@ -435,6 +452,7 @@
   }
 
   LeaveCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "DeviceWatcher_Updated left critical section.";
 
   return winrt::fire_and_forget();
 }
@@ -442,8 +460,15 @@
 winrt::fire_and_forget BluetoothClassicMedium::DeviceWatcher_Removed(
     DeviceWatcher sender, DeviceInformationUpdate deviceInfo) {
   EnterCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "DeviceWatcher_Removed entered critical section.";
+  NEARBY_LOGS(INFO) << "Device removed "
+                    << discovered_devices_by_id_[deviceInfo.Id()]->GetName()
+                    << " (" << winrt::to_string(deviceInfo.Id()) << ")";
 
   if (!IsWatcherStarted()) {
+    LeaveCriticalSection(&critical_section_);
+    NEARBY_LOGS(INFO) << "DeviceWatcher_Removed left critical section.";
+
     return winrt::fire_and_forget();
   }
 
@@ -455,6 +480,7 @@
   discovered_devices_by_id_.erase(deviceInfo.Id());
 
   LeaveCriticalSection(&critical_section_);
+  NEARBY_LOGS(INFO) << "DeviceWatcher_Removed left critical section.";
 
   return winrt::fire_and_forget();
 }
diff --git a/internal/platform/implementation/windows/bluetooth_classic_server_socket.h b/internal/platform/implementation/windows/bluetooth_classic_server_socket.h
index 6e9811e..f144886 100644
--- a/internal/platform/implementation/windows/bluetooth_classic_server_socket.h
+++ b/internal/platform/implementation/windows/bluetooth_classic_server_socket.h
@@ -96,7 +96,9 @@
   void SetScanMode(bool radioDiscoverable) {
     StopAdvertising();
     radio_discoverable_ = radioDiscoverable;
-    StartAdvertising();
+    if (radio_discoverable_) {
+      StartAdvertising();
+    }
   }
 
  private:
diff --git a/internal/platform/implementation/windows/input_file.h b/internal/platform/implementation/windows/input_file.h
index c9ac879..aa74e5e 100644
--- a/internal/platform/implementation/windows/input_file.h
+++ b/internal/platform/implementation/windows/input_file.h
@@ -29,7 +29,7 @@
   // TODO(b/184975123): replace with real implementation.
   ~InputFile() override = default;
   // TODO(b/184975123): replace with real implementation.
-  std::string GetFilePath() const override { return "Un-implemented"; }
+  std::string_view GetFilePath() const override { return "Un-implemented"; }
   // TODO(b/184975123): replace with real implementation.
   std::int64_t GetTotalSize() const override { return 0; }