power: Modify and rename SarWatcher to UserProximityWatcher

Modify and rename the SarWatcher to UserProximityWatcher, so then we
could enable it to detect the activity sensor for the body
detection in the next commit.

BUG=b:123434029
TEST=FEATURES="test" emerge-octopus power_manager

Change-Id: I918dd79e1d62de7c0008f4c64a534b7c6f23d60e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2432145
Commit-Queue: Ching-Kang Yen <chingkang@chromium.org>
Tested-by: Ching-Kang Yen <chingkang@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Puthikorn Voravootivat <puthik@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
diff --git a/power_manager/BUILD.gn b/power_manager/BUILD.gn
index 49a7a97..85424c9 100644
--- a/power_manager/BUILD.gn
+++ b/power_manager/BUILD.gn
@@ -141,7 +141,6 @@
     "powerd/system/pluggable_internal_backlight.cc",
     "powerd/system/power_supply.cc",
     "powerd/system/rolling_average.cc",
-    "powerd/system/sar_watcher.cc",
     "powerd/system/smart_discharge_configurator.cc",
     "powerd/system/suspend_configurator.cc",
     "powerd/system/tagged_device.cc",
@@ -150,6 +149,7 @@
     "powerd/system/thermal/thermal_device.cc",
     "powerd/system/thermal/thermal_device_factory.cc",
     "powerd/system/udev.cc",
+    "powerd/system/user_proximity_watcher.cc",
     "powerd/system/wake_on_dp_configurator.cc",
     "powerd/system/wakeup_device.cc",
     "powerd/system/wakeup_source_identifier.cc",
@@ -424,11 +424,11 @@
       "powerd/system/pluggable_internal_backlight_test.cc",
       "powerd/system/power_supply_test.cc",
       "powerd/system/rolling_average_test.cc",
-      "powerd/system/sar_watcher_test.cc",
       "powerd/system/suspend_configurator_test.cc",
       "powerd/system/tagged_device_test.cc",
       "powerd/system/thermal/cooling_device_test.cc",
       "powerd/system/thermal/thermal_device_factory_test.cc",
+      "powerd/system/user_proximity_watcher_test.cc",
       "powerd/system/wakeup_device_test.cc",
       "powerd/system/wakeup_source_identifier_test.cc",
     ]
diff --git a/power_manager/powerd/daemon_test.cc b/power_manager/powerd/daemon_test.cc
index 726b47d..0c099d6 100644
--- a/power_manager/powerd/daemon_test.cc
+++ b/power_manager/powerd/daemon_test.cc
@@ -75,7 +75,7 @@
         passed_acpi_wakeup_helper_(new system::AcpiWakeupHelperStub()),
         passed_ec_helper_(new system::CrosEcHelperStub()),
         passed_power_supply_(new system::PowerSupplyStub()),
-        passed_sar_watcher_(new system::UserProximityWatcherStub()),
+        passed_user_proximity_watcher_(new system::UserProximityWatcherStub()),
         passed_dark_resume_(new system::DarkResumeStub()),
         passed_audio_client_(new system::AudioClientStub()),
         passed_lockfile_checker_(new system::LockfileCheckerStub()),
@@ -102,7 +102,7 @@
         acpi_wakeup_helper_(passed_acpi_wakeup_helper_.get()),
         ec_helper_(passed_ec_helper_.get()),
         power_supply_(passed_power_supply_.get()),
-        sar_watcher_(passed_sar_watcher_.get()),
+        user_proximity_watcher_(passed_user_proximity_watcher_.get()),
         dark_resume_(passed_dark_resume_.get()),
         audio_client_(passed_audio_client_.get()),
         lockfile_checker_(passed_lockfile_checker_.get()),
@@ -276,7 +276,7 @@
                              system::UdevInterface* udev) override {
     EXPECT_EQ(prefs_, prefs);
     EXPECT_EQ(udev_, udev);
-    return std::move(passed_sar_watcher_);
+    return std::move(passed_user_proximity_watcher_);
   }
   std::unique_ptr<system::DarkResumeInterface> CreateDarkResume(
       PrefsInterface* prefs,
@@ -371,7 +371,8 @@
   std::unique_ptr<system::AcpiWakeupHelperStub> passed_acpi_wakeup_helper_;
   std::unique_ptr<system::CrosEcHelperStub> passed_ec_helper_;
   std::unique_ptr<system::PowerSupplyStub> passed_power_supply_;
-  std::unique_ptr<system::UserProximityWatcherStub> passed_sar_watcher_;
+  std::unique_ptr<system::UserProximityWatcherStub>
+      passed_user_proximity_watcher_;
   std::unique_ptr<system::DarkResumeStub> passed_dark_resume_;
   std::unique_ptr<system::AudioClientStub> passed_audio_client_;
   std::unique_ptr<system::LockfileCheckerStub> passed_lockfile_checker_;
@@ -399,7 +400,7 @@
   system::AcpiWakeupHelperStub* acpi_wakeup_helper_;
   system::CrosEcHelperStub* ec_helper_;
   system::PowerSupplyStub* power_supply_;
-  system::UserProximityWatcherStub* sar_watcher_;
+  system::UserProximityWatcherStub* user_proximity_watcher_;
   system::DarkResumeStub* dark_resume_;
   system::AudioClientStub* audio_client_;
   system::LockfileCheckerStub* lockfile_checker_;
diff --git a/power_manager/powerd/main.cc b/power_manager/powerd/main.cc
index a631daa..03d2a64 100644
--- a/power_manager/powerd/main.cc
+++ b/power_manager/powerd/main.cc
@@ -53,11 +53,11 @@
 #include "power_manager/powerd/system/peripheral_battery_watcher.h"
 #include "power_manager/powerd/system/pluggable_internal_backlight.h"
 #include "power_manager/powerd/system/power_supply.h"
-#include "power_manager/powerd/system/sar_watcher.h"
 #include "power_manager/powerd/system/suspend_configurator.h"
 #include "power_manager/powerd/system/thermal/thermal_device.h"
 #include "power_manager/powerd/system/thermal/thermal_device_factory.h"
 #include "power_manager/powerd/system/udev.h"
+#include "power_manager/powerd/system/user_proximity_watcher.h"
 #include "power_manager/powerd/system/wilco_charge_controller_helper.h"
 
 #ifndef VCSID
@@ -215,7 +215,7 @@
   std::unique_ptr<system::UserProximityWatcherInterface>
   CreateUserProximityWatcher(PrefsInterface* prefs,
                              system::UdevInterface* udev) override {
-    auto watcher = std::make_unique<system::SarWatcher>();
+    auto watcher = std::make_unique<system::UserProximityWatcher>();
     watcher->Init(prefs, udev);
     return watcher;
   }
diff --git a/power_manager/powerd/policy/user_proximity_handler.h b/power_manager/powerd/policy/user_proximity_handler.h
index cbc79bd..d60de78 100644
--- a/power_manager/powerd/policy/user_proximity_handler.h
+++ b/power_manager/powerd/policy/user_proximity_handler.h
@@ -11,8 +11,8 @@
 #include <base/macros.h>
 
 #include "power_manager/powerd/policy/user_proximity_voting.h"
-#include "power_manager/powerd/system/sar_watcher.h"
 #include "power_manager/powerd/system/user_proximity_observer.h"
+#include "power_manager/powerd/system/user_proximity_watcher.h"
 
 namespace power_manager {
 
@@ -25,9 +25,9 @@
 class WifiController;
 
 // UserProximityHandler responds to events from SAR (Specific Absorption Rate)
-// sensors, and routes them to controllers responsible for adjusting radio
-// transmit power in response to the physical proximity of the user to their
-// Chromebook.
+// and other proximity sensors, and routes them to controllers responsible
+// for adjusting radio transmit power in response to the physical proximity of
+// the user to their Chromebook.
 class UserProximityHandler : public system::UserProximityObserver {
  public:
   class Delegate {
diff --git a/power_manager/powerd/policy/user_proximity_handler_test.cc b/power_manager/powerd/policy/user_proximity_handler_test.cc
index d42a664..e585dc9 100644
--- a/power_manager/powerd/policy/user_proximity_handler_test.cc
+++ b/power_manager/powerd/policy/user_proximity_handler_test.cc
@@ -62,12 +62,12 @@
 class UserProximityHandlerTest : public ::testing::Test {
  public:
   UserProximityHandlerTest() {
-    user_proximity_handler_.Init(&sar_watcher_, &wifi_delegate_,
+    user_proximity_handler_.Init(&user_proximity_watcher_, &wifi_delegate_,
                                  &lte_delegate_);
   }
 
  protected:
-  system::UserProximityWatcherStub sar_watcher_;
+  system::UserProximityWatcherStub user_proximity_watcher_;
   WifiDelegate wifi_delegate_;
   LteDelegate lte_delegate_;
   UserProximityHandler user_proximity_handler_;
@@ -76,33 +76,33 @@
 }  // namespace
 
 TEST_F(UserProximityHandlerTest, DetectSensor) {
-  sar_watcher_.AddSensor(
+  user_proximity_watcher_.AddSensor(
       1, system::UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
   CHECK_EQ(JoinActions(kWifiSensorDetected, nullptr),
            wifi_delegate_.GetActions());
 
-  sar_watcher_.AddSensor(
+  user_proximity_watcher_.AddSensor(
       1, system::UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
   CHECK_EQ(JoinActions(kLteSensorDetected, nullptr),
            lte_delegate_.GetActions());
 }
 
 TEST_F(UserProximityHandlerTest, ProximityChange) {
-  sar_watcher_.AddSensor(
+  user_proximity_watcher_.AddSensor(
       1, system::UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
-  sar_watcher_.AddSensor(
+  user_proximity_watcher_.AddSensor(
       2, system::UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
   wifi_delegate_.GetActions();  //  consume the detection events
 
-  sar_watcher_.SendEvent(1, UserProximity::FAR);
+  user_proximity_watcher_.SendEvent(1, UserProximity::FAR);
   CHECK_EQ(JoinActions(nullptr), wifi_delegate_.GetActions());
 
-  sar_watcher_.SendEvent(2, UserProximity::FAR);
+  user_proximity_watcher_.SendEvent(2, UserProximity::FAR);
   CHECK_EQ(JoinActions(kWifiChangeFar, nullptr), wifi_delegate_.GetActions());
 
-  sar_watcher_.SendEvent(1, UserProximity::NEAR);
+  user_proximity_watcher_.SendEvent(1, UserProximity::NEAR);
   CHECK_EQ(JoinActions(kWifiChangeNear, nullptr), wifi_delegate_.GetActions());
-  sar_watcher_.SendEvent(2, UserProximity::NEAR);
+  user_proximity_watcher_.SendEvent(2, UserProximity::NEAR);
   CHECK_EQ(JoinActions(nullptr), wifi_delegate_.GetActions());
 }
 
diff --git a/power_manager/powerd/system/sar_watcher.cc b/power_manager/powerd/system/user_proximity_watcher.cc
similarity index 75%
rename from power_manager/powerd/system/sar_watcher.cc
rename to power_manager/powerd/system/user_proximity_watcher.cc
index f4c7f54..0075e20 100644
--- a/power_manager/powerd/system/sar_watcher.cc
+++ b/power_manager/powerd/system/user_proximity_watcher.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "power_manager/powerd/system/sar_watcher.h"
+#include "power_manager/powerd/system/user_proximity_watcher.h"
 
 #include <fcntl.h>
 #include <linux/iio/events.h>
@@ -13,7 +13,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <memory>
 #include <utility>
 #include <vector>
 
@@ -57,25 +56,26 @@
 
 }  // namespace
 
-const char SarWatcher::kIioUdevSubsystem[] = "iio";
+const char UserProximityWatcher::kIioUdevSubsystem[] = "iio";
 
-const char SarWatcher::kIioUdevDevice[] = "iio_device";
+const char UserProximityWatcher::kIioUdevDevice[] = "iio_device";
 
-void SarWatcher::set_open_iio_events_func_for_testing(OpenIioEventsFunc f) {
+void UserProximityWatcher::set_open_iio_events_func_for_testing(
+    OpenIioEventsFunc f) {
   open_iio_events_func_ = f;
 }
 
-SarWatcher::SarWatcher() : open_iio_events_func_(base::Bind(&OpenIioFd)) {}
+UserProximityWatcher::UserProximityWatcher()
+    : open_iio_events_func_(base::Bind(&OpenIioFd)) {}
 
-SarWatcher::~SarWatcher() {
+UserProximityWatcher::~UserProximityWatcher() {
   if (udev_)
     udev_->RemoveSubsystemObserver(kIioUdevSubsystem, this);
 }
 
-bool SarWatcher::Init(PrefsInterface* prefs, UdevInterface* udev) {
+bool UserProximityWatcher::Init(PrefsInterface* prefs, UdevInterface* udev) {
   prefs->GetBool(kSetCellularTransmitPowerForProximityPref,
                  &use_proximity_for_cellular_);
-
   prefs->GetBool(kSetWifiTransmitPowerForProximityPref,
                  &use_proximity_for_wifi_);
 
@@ -93,7 +93,7 @@
   return true;
 }
 
-void SarWatcher::AddObserver(UserProximityObserver* observer) {
+void UserProximityWatcher::AddObserver(UserProximityObserver* observer) {
   DCHECK(observer);
   observers_.AddObserver(observer);
 #if USE_TROGDOR_SAR_HACK
@@ -104,18 +104,18 @@
 #endif  // USE_TROGDOR_SAR_HACK
 }
 
-void SarWatcher::RemoveObserver(UserProximityObserver* observer) {
+void UserProximityWatcher::RemoveObserver(UserProximityObserver* observer) {
   DCHECK(observer);
   observers_.RemoveObserver(observer);
 }
 
-void SarWatcher::OnUdevEvent(const UdevEvent& event) {
+void UserProximityWatcher::OnUdevEvent(const UdevEvent& event) {
   if (event.action != UdevEvent::Action::ADD)
     return;
   OnNewUdevDevice(event.device_info);
 }
 
-void SarWatcher::OnFileCanReadWithoutBlocking(int fd) {
+void UserProximityWatcher::OnFileCanReadWithoutBlocking(int fd) {
   if (sensors_.find(fd) == sensors_.end()) {
     LOG(WARNING) << "Notified about FD " << fd << "which is not a sensor";
     return;
@@ -140,15 +140,13 @@
       return;
   }
 
-  for (auto& observer : observers_) {
+  for (auto& observer : observers_)
     observer.OnProximityEvent(fd, proximity);
-  }
 }
 
-bool SarWatcher::IsIioProximitySensor(const UdevDeviceInfo& dev,
-                                      std::string* devlink_out) {
+bool UserProximityWatcher::IsIioSarSensor(const UdevDeviceInfo& dev,
+                                          std::string* devlink_out) {
   DCHECK(udev_);
-
   if (dev.subsystem != kIioUdevSubsystem || dev.devtype != kIioUdevDevice)
     return false;
 
@@ -169,30 +167,34 @@
   return false;
 }
 
-uint32_t SarWatcher::GetUsableSensorRoles(const std::string& path) {
+uint32_t UserProximityWatcher::GetUsableSensorRoles(const SensorType type,
+                                                    const std::string& path) {
   uint32_t responsibility = UserProximityObserver::SensorRole::SENSOR_ROLE_NONE;
 
-  const auto proximity_index = path.find("proximity-");
-  if (proximity_index == std::string::npos)
-    return responsibility;
+  if (type == SensorType::SAR) {
+    const auto proximity_index = path.find("proximity-");
+    if (proximity_index == std::string::npos)
+      return responsibility;
 
-  if (use_proximity_for_cellular_ &&
-      path.find("-lte", proximity_index) != std::string::npos)
-    responsibility |= UserProximityObserver::SensorRole::SENSOR_ROLE_LTE;
+    if (use_proximity_for_cellular_ &&
+        path.find("-lte", proximity_index) != std::string::npos)
+      responsibility |= UserProximityObserver::SensorRole::SENSOR_ROLE_LTE;
 
-  if (use_proximity_for_wifi_ &&
-      path.find("-wifi", proximity_index) != std::string::npos)
-    responsibility |= UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI;
+    if (use_proximity_for_wifi_ &&
+        path.find("-wifi", proximity_index) != std::string::npos)
+      responsibility |= UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI;
+  }
 
   return responsibility;
 }
 
-bool SarWatcher::SetIioRisingFallingValue(const std::string& syspath,
-                                          brillo::CrosConfigInterface* config,
-                                          const std::string& config_path,
-                                          const std::string& config_name,
-                                          const std::string& path_prefix,
-                                          const std::string& postfix) {
+bool UserProximityWatcher::SetIioRisingFallingValue(
+    const std::string& syspath,
+    brillo::CrosConfigInterface* config,
+    const std::string& config_path,
+    const std::string& config_name,
+    const std::string& path_prefix,
+    const std::string& postfix) {
   std::string rising_value, falling_value;
   std::string rising_config = "thresh-rising" + config_name;
   std::string falling_config = "thresh-falling" + config_name;
@@ -231,7 +233,8 @@
   return true;
 }
 
-bool SarWatcher::ConfigureSensor(const std::string& syspath, uint32_t role) {
+bool UserProximityWatcher::ConfigureSarSensor(const std::string& syspath,
+                                              uint32_t role) {
   auto config = std::make_unique<brillo::CrosConfig>();
   if (!config->Init()) {
     /* Ignore on non-unibuild boards */
@@ -313,17 +316,19 @@
   return true;
 }
 
-bool SarWatcher::OnSensorDetected(const std::string& syspath,
-                                  const std::string& devlink) {
-  uint32_t role = GetUsableSensorRoles(devlink);
+bool UserProximityWatcher::OnSensorDetected(const SensorType type,
+                                            const std::string& syspath,
+                                            const std::string& devlink) {
+  DCHECK(type != SensorType::UNKNOWN);
+  uint32_t role = GetUsableSensorRoles(type, devlink);
 
   if (role == UserProximityObserver::SensorRole::SENSOR_ROLE_NONE) {
     LOG(INFO) << "Sensor at " << devlink << " not usable for any subsystem";
     return true;
   }
 
-  if (!ConfigureSensor(syspath, role)) {
-    LOG(WARNING) << "Unable to configure sensor at " << devlink;
+  if (type == SensorType::SAR && !ConfigureSarSensor(syspath, role)) {
+    LOG(WARNING) << "Unable to configure sar sensor at " << devlink;
     return false;
   }
 
@@ -334,13 +339,15 @@
   }
 
   SensorInfo info;
+  info.type = type;
   info.syspath = syspath;
   info.devlink = devlink;
   info.event_fd = event_fd;
   info.role = role;
   info.controller = base::FileDescriptorWatcher::WatchReadable(
-      event_fd, base::BindRepeating(&SarWatcher::OnFileCanReadWithoutBlocking,
-                                    base::Unretained(this), event_fd));
+      event_fd,
+      base::BindRepeating(&UserProximityWatcher::OnFileCanReadWithoutBlocking,
+                          base::Unretained(this), event_fd));
   sensors_.emplace(event_fd, std::move(info));
 
   for (auto& observer : observers_) {
@@ -350,11 +357,15 @@
   return true;
 }
 
-void SarWatcher::OnNewUdevDevice(const UdevDeviceInfo& device_info) {
+void UserProximityWatcher::OnNewUdevDevice(const UdevDeviceInfo& device_info) {
   std::string devlink;
-  if (!IsIioProximitySensor(device_info, &devlink))
+  SensorType type = SensorType::UNKNOWN;
+  if (IsIioSarSensor(device_info, &devlink))
+    type = SensorType::SAR;
+  else
     return;
-  if (!OnSensorDetected(device_info.syspath, devlink))
+
+  if (!OnSensorDetected(type, device_info.syspath, devlink))
     LOG(ERROR) << "Unable to setup proximity sensor " << device_info.syspath;
 }
 
diff --git a/power_manager/powerd/system/sar_watcher.h b/power_manager/powerd/system/user_proximity_watcher.h
similarity index 78%
rename from power_manager/powerd/system/sar_watcher.h
rename to power_manager/powerd/system/user_proximity_watcher.h
index b9d231c..d6cfd93 100644
--- a/power_manager/powerd/system/sar_watcher.h
+++ b/power_manager/powerd/system/user_proximity_watcher.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef POWER_MANAGER_POWERD_SYSTEM_SAR_WATCHER_H_
-#define POWER_MANAGER_POWERD_SYSTEM_SAR_WATCHER_H_
+#ifndef POWER_MANAGER_POWERD_SYSTEM_USER_PROXIMITY_WATCHER_H_
+#define POWER_MANAGER_POWERD_SYSTEM_USER_PROXIMITY_WATCHER_H_
 
 #include <memory>
 #include <string>
@@ -17,6 +17,7 @@
 #include <cros_config/cros_config.h>
 
 #include "power_manager/common/power_constants.h"
+#include "power_manager/powerd/system/udev.h"
 #include "power_manager/powerd/system/udev_subsystem_observer.h"
 #include "power_manager/powerd/system/user_proximity_watcher_interface.h"
 
@@ -32,9 +33,12 @@
 
 // Concrete implementation of UserProximityWatcherInterface: detects proximity
 // sensors and reports proximity events.
-class SarWatcher : public UserProximityWatcherInterface,
-                   public UdevSubsystemObserver {
+class UserProximityWatcher : public UserProximityWatcherInterface,
+                             public UdevSubsystemObserver {
  public:
+  // Sensor type for proximity detection.
+  enum class SensorType { UNKNOWN, SAR };
+
   // udev subsystem to watch.
   static const char kIioUdevSubsystem[];
 
@@ -46,11 +50,11 @@
 
   void set_open_iio_events_func_for_testing(OpenIioEventsFunc f);
 
-  SarWatcher();
-  SarWatcher(const SarWatcher&) = delete;
-  SarWatcher& operator=(const SarWatcher&) = delete;
+  UserProximityWatcher();
+  UserProximityWatcher(const UserProximityWatcher&) = delete;
+  UserProximityWatcher& operator=(const UserProximityWatcher&) = delete;
 
-  ~SarWatcher() override;
+  ~UserProximityWatcher() override;
 
   // Returns true on success.
   bool Init(PrefsInterface* prefs, UdevInterface* udev);
@@ -67,6 +71,7 @@
 
  private:
   struct SensorInfo {
+    SensorType type;
     std::string syspath;
     std::string devlink;
     int event_fd;
@@ -79,13 +84,12 @@
   // data for. The allowed roles are filtered based on whether the preferences
   // allow using proximity sensor as an input for a given subsystem. The
   // return value is a bitwise combination of SensorRole values.
-  uint32_t GetUsableSensorRoles(const std::string& path);
+  uint32_t GetUsableSensorRoles(const SensorType type, const std::string& path);
 
   // Determines whether |dev| represents a proximity sensor connected via
   // the IIO subsystem. If so, |devlink_out| is the path to the file to be used
   // to read proximity events from this device.
-  bool IsIioProximitySensor(const UdevDeviceInfo& dev,
-                            std::string* devlink_out);
+  bool IsIioSarSensor(const UdevDeviceInfo& dev, std::string* devlink_out);
 
   // Sets proximity IIO attributes for rising, falling, or either direction
   bool SetIioRisingFallingValue(const std::string& syspath,
@@ -97,12 +101,14 @@
 
   // Configures the proximity sensor for usage based on values read from
   // cros_config
-  bool ConfigureSensor(const std::string& syspath, uint32_t role);
+  bool ConfigureSarSensor(const std::string& syspath, uint32_t role);
 
   // Opens a file descriptor suitable for listening to proximity events for
   // the sensor at |devlink|, and notifies registered observers that a new
   // valid proximity sensor exists.
-  bool OnSensorDetected(const std::string& syspath, const std::string& devlink);
+  bool OnSensorDetected(const SensorType type,
+                        const std::string& syspath,
+                        const std::string& devlink);
 
   // Check new udev device. If the device of |device_info| is a proximity
   // sensor, start listening to proximity events for it.
@@ -123,4 +129,4 @@
 }  // namespace system
 }  // namespace power_manager
 
-#endif  // POWER_MANAGER_POWERD_SYSTEM_SAR_WATCHER_H_
+#endif  // POWER_MANAGER_POWERD_SYSTEM_USER_PROXIMITY_WATCHER_H_
diff --git a/power_manager/powerd/system/sar_watcher_test.cc b/power_manager/powerd/system/user_proximity_watcher_test.cc
similarity index 64%
rename from power_manager/powerd/system/sar_watcher_test.cc
rename to power_manager/powerd/system/user_proximity_watcher_test.cc
index 15a0f01..15ec43c 100644
--- a/power_manager/powerd/system/sar_watcher_test.cc
+++ b/power_manager/powerd/system/user_proximity_watcher_test.cc
@@ -23,9 +23,9 @@
 #include "power_manager/common/action_recorder.h"
 #include "power_manager/common/fake_prefs.h"
 #include "power_manager/common/test_main_loop_runner.h"
-#include "power_manager/powerd/system/sar_watcher.h"
 #include "power_manager/powerd/system/udev_stub.h"
 #include "power_manager/powerd/system/user_proximity_observer.h"
+#include "power_manager/powerd/system/user_proximity_watcher.h"
 
 namespace power_manager {
 namespace system {
@@ -34,7 +34,8 @@
 
 class TestObserver : public UserProximityObserver, public ActionRecorder {
  public:
-  explicit TestObserver(SarWatcher* watcher, TestMainLoopRunner* runner)
+  explicit TestObserver(UserProximityWatcher* watcher,
+                        TestMainLoopRunner* runner)
       : watcher_(watcher), loop_runner_(runner) {
     watcher_->AddObserver(this);
   }
@@ -56,29 +57,33 @@
   }
 
  private:
-  SarWatcher* watcher_;              // Not owned.
+  UserProximityWatcher* watcher_;    // Not owned.
   TestMainLoopRunner* loop_runner_;  // Not owned.
 };
 
-class SarWatcherTest : public testing::Test {
+class UserProximityWatcherTest : public testing::Test {
  public:
-  SarWatcherTest() : sar_watcher_(std::make_unique<SarWatcher>()) {
-    sar_watcher_->set_open_iio_events_func_for_testing(
-        base::Bind(&SarWatcherTest::OpenTestIioFd, base::Unretained(this)));
+  UserProximityWatcherTest()
+      : user_proximity_watcher_(std::make_unique<UserProximityWatcher>()) {
+    user_proximity_watcher_->set_open_iio_events_func_for_testing(base::Bind(
+        &UserProximityWatcherTest::OpenTestIioFd, base::Unretained(this)));
   }
 
-  void Init(uint32_t roles) {
-    prefs_.SetInt64(kSetCellularTransmitPowerForProximityPref,
-                    roles & UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
-    prefs_.SetInt64(
-        kSetWifiTransmitPowerForProximityPref,
-        roles & UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
-
-    CHECK(sar_watcher_->Init(&prefs_, &udev_));
-    observer_.reset(new TestObserver(sar_watcher_.get(), &loop_runner_));
+  void Init(UserProximityWatcher::SensorType type, uint32_t roles) {
+    if (type == UserProximityWatcher::SensorType::SAR) {
+      prefs_.SetInt64(
+          kSetCellularTransmitPowerForProximityPref,
+          roles & UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
+      prefs_.SetInt64(
+          kSetWifiTransmitPowerForProximityPref,
+          roles & UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
+    }
+    CHECK(user_proximity_watcher_->Init(&prefs_, &udev_));
+    observer_.reset(
+        new TestObserver(user_proximity_watcher_.get(), &loop_runner_));
   }
 
-  ~SarWatcherTest() override {
+  ~UserProximityWatcherTest() override {
     for (const auto& fd : fds_) {
       close(fd.second.first);
       close(fd.second.second);
@@ -113,8 +118,8 @@
   void AddDevice(const std::string& syspath, const std::string& devlink) {
     UdevEvent iio_event;
     iio_event.action = UdevEvent::Action::ADD;
-    iio_event.device_info.subsystem = SarWatcher::kIioUdevSubsystem;
-    iio_event.device_info.devtype = SarWatcher::kIioUdevDevice;
+    iio_event.device_info.subsystem = UserProximityWatcher::kIioUdevSubsystem;
+    iio_event.device_info.devtype = UserProximityWatcher::kIioUdevDevice;
     iio_event.device_info.sysname = "MOCKSENSOR";
     iio_event.device_info.syspath = syspath;
     udev_.AddSubsystemDevice(iio_event.device_info.subsystem,
@@ -138,14 +143,15 @@
   std::unordered_map<std::string, std::pair<int, int>> fds_;
   FakePrefs prefs_;
   UdevStub udev_;
-  std::unique_ptr<SarWatcher> sar_watcher_;
+  std::unique_ptr<UserProximityWatcher> user_proximity_watcher_;
   TestMainLoopRunner loop_runner_;
   std::unique_ptr<TestObserver> observer_;
   int open_sensor_count_ = 0;
 };
 
-TEST_F(SarWatcherTest, DetectUsableWifiDevice) {
-  Init(UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
+TEST_F(UserProximityWatcherTest, DetectUsableWifiDevice) {
+  Init(UserProximityWatcher::SensorType::SAR,
+       UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
 
   AddDevice("/sys/mockproximity", "/dev/proximity-wifi-right");
   EXPECT_EQ(JoinActions("OnNewSensor(roles=0x1)", nullptr),
@@ -153,8 +159,9 @@
   EXPECT_EQ(1, GetNumOpenedSensors());
 }
 
-TEST_F(SarWatcherTest, DetectUsableLteDevice) {
-  Init(UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
+TEST_F(UserProximityWatcherTest, DetectUsableLteDevice) {
+  Init(UserProximityWatcher::SensorType::SAR,
+       UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
 
   AddDevice("/sys/mockproximity", "/dev/proximity-lte");
   EXPECT_EQ(JoinActions("OnNewSensor(roles=0x2)", nullptr),
@@ -162,24 +169,27 @@
   EXPECT_EQ(1, GetNumOpenedSensors());
 }
 
-TEST_F(SarWatcherTest, DetectNotUsableWifiDevice) {
-  Init(UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
+TEST_F(UserProximityWatcherTest, DetectNotUsableWifiDevice) {
+  Init(UserProximityWatcher::SensorType::SAR,
+       UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
 
   AddDevice("/sys/mockproximity", "/dev/proximity-wifi-right");
   EXPECT_EQ(JoinActions(nullptr), observer_->GetActions());
   EXPECT_EQ(0, GetNumOpenedSensors());
 }
 
-TEST_F(SarWatcherTest, DetectNotUsableLteDevice) {
-  Init(UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
+TEST_F(UserProximityWatcherTest, DetectNotUsableLteDevice) {
+  Init(UserProximityWatcher::SensorType::SAR,
+       UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
 
   AddDevice("/sys/mockproximity", "/dev/proximity-lte");
   EXPECT_EQ(JoinActions(nullptr), observer_->GetActions());
   EXPECT_EQ(0, GetNumOpenedSensors());
 }
 
-TEST_F(SarWatcherTest, DetectUsableMixDevice) {
-  Init(UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
+TEST_F(UserProximityWatcherTest, DetectUsableMixDevice) {
+  Init(UserProximityWatcher::SensorType::SAR,
+       UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
 
   AddDevice("/sys/mockproximity", "/dev/proximity-wifi-lte");
   EXPECT_EQ(JoinActions("OnNewSensor(roles=0x1)", nullptr),
@@ -187,8 +197,9 @@
   EXPECT_EQ(1, GetNumOpenedSensors());
 }
 
-TEST_F(SarWatcherTest, ReceiveProximityInfo) {
-  Init(UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
+TEST_F(UserProximityWatcherTest, ReceiveProximityInfo) {
+  Init(UserProximityWatcher::SensorType::SAR,
+       UserProximityObserver::SensorRole::SENSOR_ROLE_LTE);
 
   AddDevice("/sys/mockproximity", "/dev/proximity-lte");
   observer_->GetActions();  // consume OnNewSensor
@@ -197,6 +208,15 @@
             observer_->GetActions());
 }
 
+TEST_F(UserProximityWatcherTest, UnknownDevice) {
+  Init(UserProximityWatcher::SensorType::SAR,
+       UserProximityObserver::SensorRole::SENSOR_ROLE_WIFI);
+
+  AddDevice("/sys/mockunknown", "/dev/unknown-wifi-right");
+  EXPECT_EQ(JoinActions(nullptr), observer_->GetActions());
+  EXPECT_EQ(0, GetNumOpenedSensors());
+}
+
 }  // namespace
 
 }  // namespace system