Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68137fc4 authored by Biswarup Pal's avatar Biswarup Pal
Browse files

Add method to get id of virtual camera

Also, add CtsVirtualDevicesCameraTestCases to virtualcamera
service postsubmit.

Test: atest CtsVirtualDevicesCameraTestCases
Bug: 310857519
Change-Id: I9f2e070a49bbf94694e996e4793a7997fbcb7b9e
parent 7c7244bf
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2,6 +2,14 @@
  "postsubmit": [
    {
      "name": "virtual_camera_tests"
    },
    {
      "name": "CtsVirtualDevicesCameraTestCases",
      "options": [
        {
          "exclude-annotation": "androidx.test.filters.FlakyTest"
        }
      ]
    }
  ]
}
+2 −0
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@ class VirtualCameraDevice
  // "device@{major}.{minor}/virtual/{numerical_id}"
  std::string getCameraName() const;

  uint32_t getCameraId() const { return mCameraId; }

 private:
  const uint32_t mCameraId;
  const std::shared_ptr<
+21 −0
Original line number Diff line number Diff line
@@ -109,6 +109,27 @@ ndk::ScopedAStatus VirtualCameraService::unregisterCamera(
  return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus VirtualCameraService::getCameraId(
        const ::ndk::SpAIBinder& token, int32_t* _aidl_return) {
  if (_aidl_return == nullptr) {
    return ndk::ScopedAStatus::fromServiceSpecificError(
            Status::EX_ILLEGAL_ARGUMENT);
  }

  auto camera = getCamera(token);
  if (camera == nullptr) {
    ALOGE(
        "Attempt to get camera id corresponding to unknown binder token: "
        "0x%" PRIxPTR,
        reinterpret_cast<uintptr_t>(token.get()));
    return ndk::ScopedAStatus::ok();
  }

  *_aidl_return = camera->getCameraId();

  return ndk::ScopedAStatus::ok();
}

std::shared_ptr<VirtualCameraDevice> VirtualCameraService::getCamera(
    const ::ndk::SpAIBinder& token) {
  if (token == nullptr) {
+4 −0
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ class VirtualCameraService
  ndk::ScopedAStatus unregisterCamera(const ::ndk::SpAIBinder& token) override
      EXCLUDES(mLock);

  // Returns the camera id corresponding to the binder token.
  ndk::ScopedAStatus getCameraId(
      const ::ndk::SpAIBinder& token, int32_t* _aidl_return) override EXCLUDES(mLock);

  // Returns VirtualCameraDevice corresponding to binder token or nullptr if
  // there's no camera asociated with the token.
  std::shared_ptr<VirtualCameraDevice> getCamera(const ::ndk::SpAIBinder& token)
+6 −0
Original line number Diff line number Diff line
@@ -35,4 +35,10 @@ interface IVirtualCameraService {
     * be visible to the camera framework anymore.
     */
    void unregisterCamera(in IBinder token);

    /**
     * Returns the camera id for a given binder token. Note that this id corresponds to the id of
     * the camera device in the camera framework.
     */
    int getCameraId(in IBinder token);
}