Files
external_libcamera/src
Mattijs Korpershoek 66b0bcbbee android: hal: Add AIDL camera HAL
This is a combination of 31 commits.

android: hal: provider: Import legacy provider 2.4 HAL from AOSP

AOSP does not ship an up-to-date (libhardware) camera provider HAL.

In order to write an AIDL HAL compatible with libcamera, we need
some reference codebase to start from.

Import the 2.4 legacy HAL from AOSP from tag android-15.0.0_r12.
Folder path: //hardware/interfaces/camera/provider/2.4/default/
commit ad2ba1b851b6 ("[DON'T BLOCK] Test ownership migration rules")

Note: only the "legacy" part has been imported since external cameras are
supported via android.hardware.camera.provider-V1-external-service.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: device: Import helpers from camera.device-external-impl

The ExternalCameraDevice AIDL HAL provides some convience functions to
convert between libhardware structures and AIDL classes.
It also provides a wrapper to convert common::Status to ScopedAStatus.

We need those convience functions for our HAL implementation as well.

Since they are not in a separate library, we can't simply link against it.

Make a local copy for our own usage here.

Import from android-15.0.0_r12 tag
Folder path: //hardware/interfaces/camera/device/default/
commit ad2ba1b851b6 ("[DON'T BLOCK] Test ownership migration rules")

Note: this only imports the conversion code.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: device: Rename device-external-impl -> device-libcamera-impl

For now camera.device-libcamera-impl only supports conversion functions.

This is already useful for the provider implementation in order to
convert from common::Status to AScopedStatus.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: Use Android-Apache-2.0 instead of hardware_interfaces_license

hardware_interfaces_license is only available for projects in:
//hardware/interfaces//

Since our HAL is not located in that folder, we cannot use it.

  variant "android_common": depends on
  //hardware/interfaces:hardware_interfaces_license which is
  not visible to this module

Switch to Android-Apache-2.0 which is the same license and is
available in all Android projects.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Remove 32-bits build targets

Recent Android versions (with kernel version 6.2+) require 64-bits userspace.

Therefore, there is no point in keeping unused 32-bits build targets.
Remove them.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Rename 2.4 -> 2.5 to prepare HIDL update

The most recent libbhardware (legacy) based camera provider HAL in AOSP
is the 2.5 version located in //hardware/interfaces/camera/provider/2.5/default/
LegacyCameraProviderImpl_2_5 is implemented as a subclass of
LegacyCameraProviderImpl_2_4.

We don't want this subclassing to be done because it makes converting to AIDL
more difficult.
Instead, we want the new 2.5 function (notifyDeviceStateChange()) to
be part of our class.

In order to prepare for importing the 2.5 codebase, rename all mentions
from 2.4 -> 2.5.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Import HIDL v2.5 provider HAL from AOSP

The most recent libbhardware (legacy) based camera provider HAL in AOSP
is the 2.5 version located in //hardware/interfaces/camera/provider/2.5/default/
LegacyCameraProviderImpl_2_5 is implemented as a subclass of
LegacyCameraProviderImpl_2_4.

We don't want tho subclass because it makes converting to AIDL more difficult.
Instead, we want the new 2.5 function (notifyDeviceStateChange()) to
be part of our class.

Import the 2.5 code from tag android-15.0.0_r12.
Folder path: //hardware/interfaces/camera/provider/2.5/default/
commit ad2ba1b851b6 ("[DON'T BLOCK] Test ownership migration rules")

This:
- Removes the '-impl' library (it's a template-based header only)
- Add notifyDeviceStateChange() method
- Update copyright notice

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Remove templated CameraProvider struct

CameraProvider is implemented as a wrapper structure in order to
be backwards compatible with various HIDL versions.

Since this code is about to get upgraded to AIDL, we don't care about the
deprecated HIDL support.

Remove the HIDL interface layer and make LegacyCameraProviderImpl
implement the ICameraProvider interface.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Rename legacy -> libcamera

This provider HAL is libcamera specific. As a first step we will still rely on
libhardware as interface, but that can get plumbed in future reworks.

Rename from "legacy" to "libcamera" to make it clear that this provider HAL is
for supporting cameras using libcamera.

While at it, also update the LOG_TAGs to match the new naming.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Send libcamera logs to logcat

By default libcamera logs only warnings and errors to stdout.

Use LIBCAMERA_LOG_LEVELS and LIBCAMERA_LOG_FILE to ensure
that libcamera logs info+ logs are send to logcat.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Remove V2_5 namespace to prepare for AIDL

Most AIDL HALs don't use the AIDL version inside the C++ namespace.
Follow that practice and remove it here as well.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Don't hard-code the hwbinder thread count

Following example from //hardware/interfaces/camera/provider/default,
use a constant instead of hard-coding the thread count.

This will simplify AIDL migration to match what is done for the
ExternalCameraProvider.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Don't use intermediate variable for LAZY_SERVICE

The intermediate bool variable is not needed since we can use the pre-processor
for this.

Remove it as done in ExternalCameraProvider.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: device: Add a stub implementation for provider

In order to implement the provider HAL in AIDL, we need to
instantiate a ICameraDevice.
A ICameraDevice implementation must inherit from BnCameraDevice.

Add a minimal stub, named LibcameraDevice which builds.
This can be used by the provider HAL in getCameraDeviceInterface().

Note that we no longer depend on hidl_defaults so get rid of that as well.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Migrate from v3.5 HIDL to AIDL v1

This migrates the provider HAL from HIDL into AIDL.

This includes the following changes:
- Replace use std::string instead of hidl_string
- Use CameraDeviceStatus enum instead of CAMERA_DEVICE_STATUS
- Use std::shared_ptr<> instead of android::sp<>
- Use method argument naming from ExternalCameraProvider
- Return ndk::ScopedAStatus instead of camera::common::Status
- Remove support of vendor tags as it's un-implemented in libcamera

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: device: Implement BnCameraDevice interface

Implement all required operations of a BnCameraDevice with the exception
for session handling.

Session being a quite complex topic, it will be enabled after the
LibcameraDeviceSession class is implemented.

This is based on the both the legacy 3.2 HIDL HAL and
the External AIDL located in:

//hardware/interfaces/camera/device/3.2/default/CameraDevice
//hardware/interfaces/camera/device/default/ExternalCameraDevice

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: session: Import legacy 3.2 CameraDeviceSession from AOSP

In order to write an AIDL HAL compatible with libcamera, we need
some reference codebase to start from.

Import the 3.2 legacy HAL from AOSP from tag android-15.0.0_r12.
Folder path: //hardware/interfaces/camera/device/3.2/default/
commit ad2ba1b851b6 ("[DON'T BLOCK] Test ownership migration rules")

Note: only the "legacy" part has been imported since external cameras are
supported via android.hardware.camera.provider-V1-external-service.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: session: rename CameraDeviceSession -> LibcameraDeviceSession

This is going to be libcamera specific, so rename it accordingly.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: session: Remove V3_2 namespace to prepare for AIDL

Most AIDL HALs don't use the AIDL version inside the C++ namespace.
Follow that practice and remove it here as well.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: session: Remove HIDL trampoline code to prepare for AIDL

We don't need this, as it's HIDL specific.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: session: Migrate from v3.2 HIDL to AIDL v1

This migrates the DeviceSession class from HIDL into AIDL.

This includes the following changes:
- Use std::shared_ptr<> instead of android::sp<>
- Use std::string instead of hidl_string
- Use std::vector instead of hidl_vec
- Remove V1_0 namespace for camera::common::helper
- Use HandleImporter from camera::common::helper
- Use AIDLMessageQueues and change data type from uint8_t -> int8_t
- Use makeFromAidl() for fence handling
- Use std::move() instead of hand-cloning fences
- Use new NotifyMsg API with class enums
- Use NativeHandle instead off native_handle_t* when needed

Note: by switching to dupToAidl(), we must ensure that the original handle
is deleted.

Note: All AIDL specific operations are stubbed for now, as we are not sure that
those are implemented by libcamera's hw_module.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: device: Use LibcameraDeviceSession class

Now that LibcameraDeviceSession is implemented, we can use it in
LibcameraDevice.

With this change, we can see preview using com.android.camera2 app and
take pictures via libcamera.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: Rename outdated LOG_TAGs

These were leftovers from the code import from AOSP.

Update to use the new naming scheme so that it's easier to grep
for this HAL in logcat.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: Remove un-needed dependencies

While converting to AIDL, we failed to remove the HIDL
dependencies.

Cleanup the dependencies and also depend on common-helper instead of
the deprecated common@1.0-helper.

Note that for device, we cannot get rid of libhidlbase because of our
usage of HandleImporter.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: Remove lazy service support

We have never used the lazy implementation and don't even know how
to test it.

To simplify the codebase, get rid of it.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: add libcamera_aidl_defaults

Add a new libcamera_aidl_defaults which is used by the
camera library.

This allows us to remove lots of duplicated shared_libs since
they are defined in the new defaults.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: provider: Return ILLEGAL_ARGUMENT when callback is nullptr

When a user attempts to setCallback() using a nullptr, we should
return ILLEGAL_ARGUMENT, not OK.

Update the condition and while at it, drop the braces which are
not needed for a single statement.

Not: this is tested by VTS.

Test: atest PerInstance/CameraAidlTest#setCallback/1_android_hardware_camera_provider_ICameraProvider_libcamera_0
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: device: Fix openInjectSession() return code

The AIDL doc states that we should return OPERATION_NOT_SUPPORTED when
this is not implemented.

Fix the return code. This is tested with VTS.

Test: atest PerInstance/CameraAidlTest#configureInjectionStreamsAvailableOutputs/1_android_hardware_camera_provider_ICameraProvider_libcamera_0
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: device: Fix torch related return codes

When these operations are not supported, we should return
OPERATION_NOT_SUPPORTED instead of ILLEGAL_ARGUMENT.

Fix both return codes.

This is tested by VTS.

Test: atest PerInstance/CameraAidlTest#turnOnTorchWithStrengthLevel/1_android_hardware_camera_provider_ICameraProvider_libcamera_0
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: device: Return ILLEGAL_ARGUMENT on invalid output buffer

When we are importing an invalid output buffer, we should return
ILLEGAL_ARGUMENT, not INTERNAL_ERROR.

Fix this.

This is tested by VTS.

Test: atest PerInstance/CameraAidlTest#processCaptureRequestInvalidBuffer/1_android_hardware_camera_provider_ICameraProvider_libcamera_0
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

android: hal: Cleanup makefiles
2026-04-30 16:11:18 +03:00
..
2026-04-30 16:11:18 +03:00
2026-03-06 18:24:56 +01:00