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

Commit feb76cc0 authored by Chien-Yu Chen's avatar Chien-Yu Chen Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'camera-hardening'

* changes:
  camera: Add support to pass native handles across binders
  Camera: Fix client permission check
  Add cameraserver process
parents dfb7c95a 6773d477
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_C_INCLUDES += \
	system/media/camera/include \
	system/media/private/camera/include \
	frameworks/native/include/media/openmax \

LOCAL_MODULE:= libcamera_client

+2 −2
Original line number Diff line number Diff line
@@ -72,9 +72,9 @@ Camera::~Camera()
}

sp<Camera> Camera::connect(int cameraId, const String16& clientPackageName,
        int clientUid)
        int clientUid, int clientPid)
{
    return CameraBaseT::connect(cameraId, clientPackageName, clientUid);
    return CameraBaseT::connect(cameraId, clientPackageName, clientUid, clientPid);
}

status_t Camera::connectLegacy(int cameraId, int halVersion,
+2 −2
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ const sp<ICameraService>& CameraBase<TCam, TCamTraits>::getCameraService()
template <typename TCam, typename TCamTraits>
sp<TCam> CameraBase<TCam, TCamTraits>::connect(int cameraId,
                                               const String16& clientPackageName,
                                               int clientUid)
                                               int clientUid, int clientPid)
{
    ALOGV("%s: connect", __FUNCTION__);
    sp<TCam> c = new TCam(cameraId);
@@ -103,7 +103,7 @@ sp<TCam> CameraBase<TCam, TCamTraits>::connect(int cameraId,
    if (cs != 0) {
        TCamConnectService fnConnectService = TCamTraits::fnConnectService;
        status = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
                                             /*out*/ c->mCamera);
                                               clientPid, /*out*/ c->mCamera);
    }
    if (status == OK && c->mCamera != 0) {
        IInterface::asBinder(c->mCamera)->linkToDeath(c);
+15 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
//#define LOG_NDEBUG 0

#include <camera/CameraUtils.h>
#include <media/hardware/HardwareAPI.h>

#include <system/window.h>
#include <system/graphics.h>
@@ -121,5 +122,19 @@ status_t CameraUtils::getRotationTransform(const CameraMetadata& staticInfo,
    return OK;
}

// Return whether the image data contains a native handle.
bool CameraUtils::isNativeHandleMetadata(const sp<IMemory>& imageData) {
    if (imageData == nullptr) {
        return false;
    }

    if (imageData->size() == sizeof(VideoNativeHandleMetadata)) {
        VideoNativeHandleMetadata *metadata =
                (VideoNativeHandleMetadata*)(imageData->pointer());
        return metadata->eType == kMetadataBufferTypeNativeHandleSource;
    }

    return false;
}

} /* namespace android */
+25 −0
Original line number Diff line number Diff line
@@ -21,9 +21,11 @@
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <camera/CameraUtils.h>
#include <camera/ICamera.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/Surface.h>
#include <media/hardware/HardwareAPI.h>

namespace android {

@@ -149,7 +151,22 @@ public:
        Parcel data, reply;
        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
        data.writeStrongBinder(IInterface::asBinder(mem));

        native_handle_t *nh = nullptr;
        if (CameraUtils::isNativeHandleMetadata(mem)) {
            VideoNativeHandleMetadata *metadata =
                        (VideoNativeHandleMetadata*)(mem->pointer());
            nh = metadata->pHandle;
            data.writeNativeHandle(nh);
        }

        remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);

        if (nh) {
            // Close the native handle because camera received a dup copy.
            native_handle_close(nh);
            native_handle_delete(nh);
        }
    }

    status_t setVideoBufferMode(int32_t videoBufferMode)
@@ -348,6 +365,14 @@ status_t BnCamera::onTransact(
            ALOGV("RELEASE_RECORDING_FRAME");
            CHECK_INTERFACE(ICamera, data, reply);
            sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder());

            if (CameraUtils::isNativeHandleMetadata(mem)) {
                VideoNativeHandleMetadata *metadata =
                        (VideoNativeHandleMetadata*)(mem->pointer());
                metadata->pHandle = data.readNativeHandle();
                // releaseRecordingFrame will be responsble to close the native handle.
            }

            releaseRecordingFrame(mem);
            return NO_ERROR;
        } break;
Loading