Revert "[devfs][camera] Converting camera to services"

This reverts commit ebb2d9a15e32a90958d9495264a2fb527749b55e.

Reason for revert: Camera device is not available which causes e2e tests to fail. The tests were not run on this CL in presubmit.

Original change's description:
> [devfs][camera] Converting camera to services
>
> Functionality remains the same, but now cameras
> use services to communicate instead of the devfs
> system.
>
> Bug: 324273348
>
> Change-Id: I71b19adf6f40153a65c133831306a57778f117cb
> Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1216524
> Reviewed-by: Suraj Malhotra <surajmalhotra@google.com>
> Fuchsia-Auto-Submit: Garratt Gallagher <garratt@google.com>
> Reviewed-by: Matt Thiffault <mthiffault@google.com>
> Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>

Bug: 324273348
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I74b5396a8ba44bc59323bf3a796a3c9af216cdf9
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1222696
Reviewed-by: RubberStamper 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Garratt Gallagher <garratt@google.com>
diff --git a/src/camera/bin/device/BUILD.gn b/src/camera/bin/device/BUILD.gn
index 51d0150..36b79b4 100644
--- a/src/camera/bin/device/BUILD.gn
+++ b/src/camera/bin/device/BUILD.gn
@@ -44,7 +44,6 @@
   public_deps = [
     "//sdk/fidl/fuchsia.camera2.hal:fuchsia.camera2.hal_hlcpp",
     "//sdk/fidl/fuchsia.camera3:fuchsia.camera3_hlcpp",
-    "//sdk/fidl/fuchsia.hardware.camera:fuchsia.hardware.camera_cpp",
     "//sdk/fidl/fuchsia.hardware.camera:fuchsia.hardware.camera_hlcpp",
     "//sdk/fidl/fuchsia.sysmem:fuchsia.sysmem_cpp_hlcpp_conversion",
     "//sdk/fidl/fuchsia.sysmem:fuchsia.sysmem_hlcpp",
diff --git a/src/camera/bin/device/main.cc b/src/camera/bin/device/main.cc
index 06bbd462..5490172 100644
--- a/src/camera/bin/device/main.cc
+++ b/src/camera/bin/device/main.cc
@@ -2,7 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include <fidl/fuchsia.hardware.camera/cpp/wire.h>
 #include <fuchsia/camera2/hal/cpp/fidl.h>
 #include <fuchsia/hardware/camera/cpp/fidl.h>
 #include <fuchsia/ui/policy/cpp/fidl.h>
@@ -10,7 +9,6 @@
 #include <lib/async-loop/default.h>
 #include <lib/async/cpp/executor.h>
 #include <lib/async/cpp/wait.h>
-#include <lib/component/incoming/cpp/service_member_watcher.h>
 #include <lib/fdio/directory.h>
 #include <lib/fdio/fdio.h>
 #include <lib/sys/cpp/component_context.h>
@@ -27,18 +25,18 @@
 
 namespace camera {
 
+constexpr auto kCameraPath = "/dev/class/camera";
+
 using DeviceHandle = fuchsia::hardware::camera::DeviceHandle;
 
 static zx::result<DeviceHandle> GetCameraHandle() {
-  component::SyncServiceMemberWatcher<fuchsia_hardware_camera::Service::Device> watcher;
-  auto client_end = watcher.GetNextInstance(true);
-  if (client_end.is_error()) {
-    if (client_end.error_value() == ZX_ERR_STOP) {
-      return zx::error(ZX_ERR_NOT_FOUND);
-    }
-    return client_end.take_error();
+  for (auto const& dir_entry : std::filesystem::directory_iterator{kCameraPath}) {
+    DeviceHandle camera;
+    zx_status_t status =
+        fdio_service_connect(dir_entry.path().c_str(), camera.NewRequest().TakeChannel().release());
+    return zx::make_result(status, std::move(camera));
   }
-  return zx::ok(DeviceHandle(client_end.value().TakeChannel()));
+  return zx::error(ZX_ERR_NOT_FOUND);
 }
 
 }  // namespace camera
diff --git a/src/camera/bin/device/meta/camera_device.cml b/src/camera/bin/device/meta/camera_device.cml
index bb98d10..91ed70f 100644
--- a/src/camera/bin/device/meta/camera_device.cml
+++ b/src/camera/bin/device/meta/camera_device.cml
@@ -20,7 +20,11 @@
         },
     ],
     use: [
-        { service: "fuchsia.hardware.camera.Service" },
+        {
+            directory: "dev-camera",
+            rights: [ "r*" ],
+            path: "/dev/class/camera",
+        },
         {
             protocol: [
                 //"fuchsia.camera2.hal.Controller",
diff --git a/src/camera/bin/device_watcher/device_watcher_impl.h b/src/camera/bin/device_watcher/device_watcher_impl.h
index 02bcbae..c3deea6 100644
--- a/src/camera/bin/device_watcher/device_watcher_impl.h
+++ b/src/camera/bin/device_watcher/device_watcher_impl.h
@@ -25,7 +25,7 @@
 
 namespace camera {
 
-constexpr auto kCameraPath = "/svc/fuchsia.hardware.camera.Service";
+constexpr auto kCameraPath = "/dev/class/camera";
 
 constexpr std::string_view kMipiCsiDeviceInstanceCollectionName{"csi_camera_devices"};
 constexpr std::string_view kMipiCsiDeviceInstanceNamePrefix{"csi_camera_device_"};
diff --git a/src/camera/bin/device_watcher/main.cc b/src/camera/bin/device_watcher/main.cc
index 25376f8..1fae287 100644
--- a/src/camera/bin/device_watcher/main.cc
+++ b/src/camera/bin/device_watcher/main.cc
@@ -94,7 +94,7 @@
   auto watcher = fsl::DeviceWatcher::CreateWithIdleCallback(
       camera::kCameraPath,
       [&](const fidl::ClientEnd<fuchsia_io::Directory>& dir, const std::string& path) {
-        server->AddDeviceByPath(path + "/device");
+        server->AddDeviceByPath(path);
       },
       [&]() { server->UpdateClients(); });
   if (!watcher) {
diff --git a/src/camera/bin/device_watcher/meta/camera_device_watcher.cml b/src/camera/bin/device_watcher/meta/camera_device_watcher.cml
index 9b61cd9..24a8fb0 100644
--- a/src/camera/bin/device_watcher/meta/camera_device_watcher.cml
+++ b/src/camera/bin/device_watcher/meta/camera_device_watcher.cml
@@ -30,7 +30,11 @@
         },
     ],
     use: [
-        { service: "fuchsia.hardware.camera.Service" },
+        {
+            directory: "dev-camera",
+            rights: [ "r*" ],
+            path: "/dev/class/camera",
+        },
         {
             protocol: [ "fuchsia.component.Realm" ],
             from: "framework",
@@ -60,7 +64,7 @@
             ],
         },
         {
-            service: "fuchsia.hardware.camera.Service",
+            directory: "dev-camera",
             from: "parent",
             to: [
                 "#csi_camera_devices",
diff --git a/src/camera/bin/device_watcher/meta/camera_device_watcher_unittest.cml b/src/camera/bin/device_watcher/meta/camera_device_watcher_unittest.cml
index 66ef408..dca9142 100644
--- a/src/camera/bin/device_watcher/meta/camera_device_watcher_unittest.cml
+++ b/src/camera/bin/device_watcher/meta/camera_device_watcher_unittest.cml
@@ -17,7 +17,11 @@
         },
     ],
     use: [
-        { service: "fuchsia.hardware.camera.Service" },
+        {
+            directory: "dev-camera",
+            rights: [ "r*" ],
+            path: "/dev/class/camera",
+        },
         {
             protocol: [
                 "fuchsia.camera.test.DeviceWatcherTester",
@@ -32,7 +36,7 @@
     ],
     offer: [
         {
-            service: "fuchsia.hardware.camera.Service",
+            directory: "dev-camera",
             from: "parent",
             to: "#camera_device_watcher",
         },
diff --git a/src/camera/bin/sensor_cli/BUILD.gn b/src/camera/bin/sensor_cli/BUILD.gn
index 3f150f4..4816790 100644
--- a/src/camera/bin/sensor_cli/BUILD.gn
+++ b/src/camera/bin/sensor_cli/BUILD.gn
@@ -18,7 +18,6 @@
   deps = [
     "//sdk/lib/async-loop:async-loop-cpp",
     "//sdk/lib/async-loop:async-loop-default",
-    "//sdk/lib/component/incoming/cpp:cpp",
     "//sdk/lib/fidl/hlcpp",
     "//sdk/lib/sys/cpp",
     "//sdk/lib/syslog/cpp",
@@ -28,7 +27,6 @@
   public_deps = [
     "//sdk/fidl/fuchsia.camera2.debug:fuchsia.camera2.debug_hlcpp",
     "//sdk/fidl/fuchsia.camera2.hal:fuchsia.camera2.hal_hlcpp",
-    "//sdk/fidl/fuchsia.hardware.camera:fuchsia.hardware.camera_cpp",
     "//sdk/fidl/fuchsia.hardware.camera:fuchsia.hardware.camera_hlcpp",
   ]
 }
diff --git a/src/camera/bin/sensor_cli/debug_client.cc b/src/camera/bin/sensor_cli/debug_client.cc
index 4b002d2..35b6027 100644
--- a/src/camera/bin/sensor_cli/debug_client.cc
+++ b/src/camera/bin/sensor_cli/debug_client.cc
@@ -4,10 +4,8 @@
 
 #include "debug_client.h"
 
-#include <fidl/fuchsia.hardware.camera/cpp/wire.h>
 #include <lib/async-loop/default.h>
 #include <lib/async/cpp/task.h>
-#include <lib/component/incoming/cpp/service_member_watcher.h>
 #include <lib/fdio/directory.h>
 #include <lib/sys/cpp/component_context.h>
 #include <lib/syslog/cpp/log_settings.h>
@@ -28,15 +26,22 @@
 
 bool DebugClient::ConnectToServer() {
   fuchsia::hardware::camera::DeviceHandle device_handle;
-  component::SyncServiceMemberWatcher<fuchsia_hardware_camera::Service::Device> watcher;
-  auto result = watcher.GetNextInstance(/*stop_at_idle=*/true);
-  if (result.is_error()) {
-    FX_PLOGS(ERROR, result.status_value()) << "Failed to connect to controller device";
+  for (auto const& dir_entry : std::filesystem::directory_iterator{"/dev/class/camera"}) {
+    if (zx_status_t status = fdio_service_connect(
+            dir_entry.path().c_str(), device_handle.NewRequest().TakeChannel().release());
+        status != ZX_OK) {
+      FX_PLOGS(ERROR, status) << "Failed to connect to controller device";
+      Quit();
+    }
+    break;
+  }
+  if (!device_handle.is_valid()) {
+    FX_LOGS(ERROR) << "Failed to discover controller device";
     Quit();
   }
 
   fuchsia::hardware::camera::DeviceSyncPtr device_sync_ptr;
-  device_sync_ptr.Bind(result.value().TakeChannel());
+  device_sync_ptr.Bind(std::move(device_handle));
 
   if (zx_status_t status =
           device_sync_ptr->GetDebugChannel(debug_ptr_.NewRequest(loop_.dispatcher()));
diff --git a/src/camera/bin/usb_device/meta/usb_camera_device.cml b/src/camera/bin/usb_device/meta/usb_camera_device.cml
index 69255e0..3b25766 100644
--- a/src/camera/bin/usb_device/meta/usb_camera_device.cml
+++ b/src/camera/bin/usb_device/meta/usb_camera_device.cml
@@ -19,7 +19,11 @@
         },
     ],
     use: [
-        { service: "fuchsia.hardware.camera.Service" },
+        {
+            directory: "dev-camera",
+            rights: [ "r*" ],
+            path: "/dev/class/camera",
+        },
         {
             protocol: [
                 "fuchsia.sysmem.Allocator",
diff --git a/src/camera/drivers/controller/controller_device.cc b/src/camera/drivers/controller/controller_device.cc
index 673ba29..b1d3e44 100644
--- a/src/camera/drivers/controller/controller_device.cc
+++ b/src/camera/drivers/controller/controller_device.cc
@@ -43,16 +43,6 @@
   if (status != ZX_OK) {
     return fpromise::error(status);
   }
-  fuchsia_hardware_camera::Service::InstanceHandler handler({
-      .device = device->bindings_.CreateHandler(device.get(), device->loop_.dispatcher(),
-                                                fidl::kIgnoreBindingClosure),
-  });
-  zx::result add_result =
-      device->DdkAddService<fuchsia_hardware_camera::Service>(std::move(handler));
-  if (add_result.is_error()) {
-    zxlogf(ERROR, "Failed to advertise camera service");
-    return fpromise::error(add_result.error_value());
-  }
 
   return fpromise::ok(std::move(device));
 }
diff --git a/src/camera/drivers/controller/controller_device.h b/src/camera/drivers/controller/controller_device.h
index 487847b..b4fc97a 100644
--- a/src/camera/drivers/controller/controller_device.h
+++ b/src/camera/drivers/controller/controller_device.h
@@ -25,9 +25,10 @@
 namespace camera {
 
 class ControllerDevice;
-using ControllerDeviceType = ddk::Device<ControllerDevice, ddk::Unbindable>;
+using ControllerDeviceType = ddk::Device<ControllerDevice, ddk::Unbindable,
+                                         ddk::Messageable<fuchsia_hardware_camera::Device>::Mixin>;
 class ControllerDevice : public ControllerDeviceType,
-                         public fidl::WireServer<fuchsia_hardware_camera::Device> {
+                         public ddk::EmptyProtocol<ZX_PROTOCOL_CAMERA> {
  public:
   ~ControllerDevice() override;
 
@@ -66,7 +67,6 @@
 
   // Serves the fuchsia.camera2.debug.Debug protocol
   std::unique_ptr<DebugImpl> debug_;
-  fidl::ServerBindingGroup<fuchsia_hardware_camera::Device> bindings_;
 };
 
 }  // namespace camera
diff --git a/src/camera/drivers/usb_video/usb_video_stream.cc b/src/camera/drivers/usb_video/usb_video_stream.cc
index 00b93fc..d1c0168 100644
--- a/src/camera/drivers/usb_video/usb_video_stream.cc
+++ b/src/camera/drivers/usb_video/usb_video_stream.cc
@@ -81,17 +81,8 @@
     return streams_or.error_value();
   }
   // Parsed all descriptors successfully.
-  auto dev = std::make_unique<UsbVideoStream>(device, usb, std::move(*streams_or));
 
-  fuchsia_hardware_camera::Service::InstanceHandler handler({
-      .device = dev->bindings_.CreateHandler(dev.get(), dev->fidl_dispatch_loop_->dispatcher(),
-                                             fidl::kIgnoreBindingClosure),
-  });
-  zx::result add_result = dev->DdkAddService<fuchsia_hardware_camera::Service>(std::move(handler));
-  if (add_result.is_error()) {
-    zxlogf(ERROR, "Failed to advertise camera service");
-    return add_result.error_value();
-  }
+  auto dev = std::make_unique<UsbVideoStream>(device, usb, std::move(*streams_or));
 
   zxlogf(INFO, "Adding UsbVideoStream");
   status = dev->DdkAdd("usb-video-source");
diff --git a/src/camera/drivers/usb_video/usb_video_stream.h b/src/camera/drivers/usb_video/usb_video_stream.h
index b8764d8..ea1f0a9 100644
--- a/src/camera/drivers/usb_video/usb_video_stream.h
+++ b/src/camera/drivers/usb_video/usb_video_stream.h
@@ -96,12 +96,14 @@
 // Unless specified otherwise, all methods of this class are assumed to be called
 // on the single threaded dispatcher owned by this class.
 class UsbVideoStream;
-using UsbVideoStreamBase = ::ddk::Device<UsbVideoStream, ::ddk::Unbindable>;
+using UsbVideoStreamBase =
+    ::ddk::Device<UsbVideoStream, ::ddk::Unbindable,
+                  ::ddk::Messageable<fuchsia_hardware_camera::Device>::Mixin>;
 
 class UsbVideoStream : public UsbVideoStreamBase,
                        public fuchsia::camera::Control,
                        public fuchsia::camera::Stream,
-                       public fidl::WireServer<fuchsia_hardware_camera::Device> {
+                       public ::ddk::EmptyProtocol<ZX_PROTOCOL_CAMERA> {
  public:
   // Constructor is assumed to be called only through Bind, or suitable testing rig.
   // This method will not be called on the fidl_dispatch_loop_.
@@ -268,7 +270,6 @@
 
   zx::eventpair stream_token_;
   fidl::Binding<Stream> stream_binding_;
-  fidl::ServerBindingGroup<fuchsia_hardware_camera::Device> bindings_;
 };
 
 }  // namespace camera::usb_video
diff --git a/src/camera/drivers/usb_video/uvc-tester/main.cc b/src/camera/drivers/usb_video/uvc-tester/main.cc
index 7cba54a..e8558b8 100644
--- a/src/camera/drivers/usb_video/uvc-tester/main.cc
+++ b/src/camera/drivers/usb_video/uvc-tester/main.cc
@@ -66,30 +66,34 @@
 }
 
 zx::result<CamControl> OpenCamera() {
-  component::SyncServiceMemberWatcher<fuchsia_hardware_camera::Service::Device> watcher;
-  auto client_end = watcher.GetNextInstance(true);
-  if (client_end.is_error()) {
-    FX_PLOGS(ERROR, client_end.error_value()) << "Failed to open sensor ";
-    return client_end.take_error();
-  }
-  FX_LOGS(INFO) << "opened camera";
+  for (auto const& dir_entry : std::filesystem::directory_iterator{"/dev/class/camera"}) {
+    const char* path = dir_entry.path().c_str();
+    zx::result client_end = component::Connect<fuchsia_hardware_camera::Device>(path);
+    if (client_end.is_error()) {
+      FX_PLOGS(ERROR, client_end.error_value()) << "Failed to open sensor at " << path;
+      return client_end.take_error();
+    }
+    FX_LOGS(INFO) << "opened " << path;
 
-  fuchsia::camera::ControlSyncPtr ctrl;
-  const fidl::OneWayStatus status =
-      fidl::WireCall(client_end.value())->GetChannel(ctrl.NewRequest().TakeChannel());
-  if (!status.ok()) {
-    FX_PLOGS(INFO, status.status()) << "Couldn't GetChannel from camera";
-    return zx::error(status.status());
-  }
+    fuchsia::camera::ControlSyncPtr ctrl;
+    const fidl::OneWayStatus status =
+        fidl::WireCall(client_end.value())->GetChannel(ctrl.NewRequest().TakeChannel());
+    if (!status.ok()) {
+      FX_PLOGS(INFO, status.status()) << "Couldn't GetChannel from " << path;
+      return zx::error(status.status());
+    }
 
-  fuchsia::camera::DeviceInfo info_return;
-  if (zx_status_t status = ctrl->GetDeviceInfo(&info_return); status != ZX_OK) {
-    FX_PLOGS(ERROR, status) << "Could not get Device Info";
-    return zx::error(status);
+    fuchsia::camera::DeviceInfo info_return;
+    if (zx_status_t status = ctrl->GetDeviceInfo(&info_return); status != ZX_OK) {
+      FX_PLOGS(ERROR, status) << "Could not get Device Info";
+      return zx::error(status);
+    }
+    FX_LOGS(INFO) << "Got Device Info:\n"
+                  << "  Vendor: " << info_return.vendor_name << " (" << info_return.vendor_id
+                  << ")";
+    return zx::ok(std::move(ctrl));
   }
-  FX_LOGS(INFO) << "Got Device Info:\n"
-                << "  Vendor: " << info_return.vendor_name << " (" << info_return.vendor_id << ")";
-  return zx::ok(std::move(ctrl));
+  return zx::error(ZX_ERR_NOT_FOUND);
 }
 
 zx::result<std::vector<fuchsia::camera::VideoFormat>> GetFormats(CamControl& ctrl) {
diff --git a/src/camera/meta/camera.core_shard.cml b/src/camera/meta/camera.core_shard.cml
index 9609411..9d8143b 100644
--- a/src/camera/meta/camera.core_shard.cml
+++ b/src/camera/meta/camera.core_shard.cml
@@ -30,9 +30,11 @@
             dependency: "weak",
         },
         {
-            service: "fuchsia.hardware.camera.Service",
+            directory: "dev-class",
             from: "parent",
+            as: "dev-camera",
             to: "#camera_device_watcher",
+            subdir: "camera",
         },
     ],
 }
diff --git a/src/devices/bin/driver_manager/devfs/class_names.h b/src/devices/bin/driver_manager/devfs/class_names.h
index fcc9194..6433140 100644
--- a/src/devices/bin/driver_manager/devfs/class_names.h
+++ b/src/devices/bin/driver_manager/devfs/class_names.h
@@ -67,6 +67,7 @@
     {"bt-emulator",
      {ServiceEntry::kDevfsAndService, "fuchsia.hardware.bluetooth.EmulatorService", "device"}},
     {"bt-hci", {ServiceEntry::kDevfsAndService, "fuchsia.hardware.bluetooth.Service", "vendor"}},
+    {"camera", {ServiceEntry::kDevfsAndService, "fuchsia.hardware.camera.Service", "device"}},
     {"clock-impl",
      {ServiceEntry::kDevfsAndService, "fuchsia.hardware.clock.measure.Service", "measurer"}},
     {"codec",
diff --git a/src/devices/bin/driver_manager/devfs/meta/devfs-driver.cml b/src/devices/bin/driver_manager/devfs/meta/devfs-driver.cml
index 225c70c..b9d8485 100644
--- a/src/devices/bin/driver_manager/devfs/meta/devfs-driver.cml
+++ b/src/devices/bin/driver_manager/devfs/meta/devfs-driver.cml
@@ -24,6 +24,7 @@
                 "fuchsia.hardware.backlight.Service",
                 "fuchsia.hardware.bluetooth.EmulatorService",
                 "fuchsia.hardware.bluetooth.Service",
+                "fuchsia.hardware.camera.Service",
                 "fuchsia.hardware.clock.measure.Service",
                 "fuchsia.hardware.cpu.ctrl.Service",
                 "fuchsia.hardware.display.service",
@@ -84,6 +85,7 @@
                 "fuchsia.hardware.backlight.Service",
                 "fuchsia.hardware.bluetooth.EmulatorService",
                 "fuchsia.hardware.bluetooth.Service",
+                "fuchsia.hardware.camera.Service",
                 "fuchsia.hardware.clock.measure.Service",
                 "fuchsia.hardware.cpu.ctrl.Service",
                 "fuchsia.hardware.display.service",