diff options
-rw-r--r-- | camera/EmulatedFakeCamera2.cpp | 8 | ||||
-rw-r--r-- | camera/EmulatedFakeCamera3.cpp | 2 | ||||
-rw-r--r-- | camera/fake-pipeline2/Sensor.cpp | 2 | ||||
-rw-r--r-- | fingerprint/Android.mk | 33 | ||||
-rw-r--r-- | fingerprint/fingerprint.c | 223 | ||||
-rw-r--r-- | opengl/system/gralloc/gralloc.cpp | 2 |
6 files changed, 263 insertions, 7 deletions
diff --git a/camera/EmulatedFakeCamera2.cpp b/camera/EmulatedFakeCamera2.cpp index 844a71e..cbc67ed 100644 --- a/camera/EmulatedFakeCamera2.cpp +++ b/camera/EmulatedFakeCamera2.cpp @@ -42,7 +42,7 @@ const int64_t MSEC = USEC * 1000LL; const int64_t SEC = MSEC * 1000LL; const uint32_t EmulatedFakeCamera2::kAvailableFormats[4] = { - HAL_PIXEL_FORMAT_RAW_SENSOR, + HAL_PIXEL_FORMAT_RAW16, HAL_PIXEL_FORMAT_BLOB, HAL_PIXEL_FORMAT_RGBA_8888, // HAL_PIXEL_FORMAT_YV12, @@ -374,7 +374,7 @@ int EmulatedFakeCamera2::allocateStream( const uint32_t *availableSizes; size_t availableSizeCount; switch (format) { - case HAL_PIXEL_FORMAT_RAW_SENSOR: + case HAL_PIXEL_FORMAT_RAW16: availableSizes = kAvailableRawSizes; availableSizeCount = sizeof(kAvailableRawSizes)/sizeof(uint32_t); break; @@ -412,7 +412,7 @@ int EmulatedFakeCamera2::allocateStream( } switch (format) { - case HAL_PIXEL_FORMAT_RAW_SENSOR: + case HAL_PIXEL_FORMAT_RAW16: if (mRawStreamCount >= kMaxRawStreamCount) { ALOGE("%s: Cannot allocate another raw stream (%d already allocated)", __FUNCTION__, mRawStreamCount); @@ -523,7 +523,7 @@ int EmulatedFakeCamera2::releaseStream(uint32_t stream_id) { } switch(mStreams.valueAt(streamIndex).format) { - case HAL_PIXEL_FORMAT_RAW_SENSOR: + case HAL_PIXEL_FORMAT_RAW16: mRawStreamCount--; break; case HAL_PIXEL_FORMAT_BLOB: diff --git a/camera/EmulatedFakeCamera3.cpp b/camera/EmulatedFakeCamera3.cpp index fe07a25..8302da4 100644 --- a/camera/EmulatedFakeCamera3.cpp +++ b/camera/EmulatedFakeCamera3.cpp @@ -54,7 +54,7 @@ const int64_t MSEC = USEC * 1000LL; const int64_t SEC = MSEC * 1000LL; const int32_t EmulatedFakeCamera3::kAvailableFormats[5] = { - HAL_PIXEL_FORMAT_RAW_SENSOR, + HAL_PIXEL_FORMAT_RAW16, HAL_PIXEL_FORMAT_BLOB, HAL_PIXEL_FORMAT_RGBA_8888, HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, diff --git a/camera/fake-pipeline2/Sensor.cpp b/camera/fake-pipeline2/Sensor.cpp index aa54ef4..594a060 100644 --- a/camera/fake-pipeline2/Sensor.cpp +++ b/camera/fake-pipeline2/Sensor.cpp @@ -323,7 +323,7 @@ bool Sensor::threadLoop() { i, b.streamId, b.width, b.height, b.format, b.stride, b.buffer, b.img); switch(b.format) { - case HAL_PIXEL_FORMAT_RAW_SENSOR: + case HAL_PIXEL_FORMAT_RAW16: captureRaw(b.img, gain, b.stride); break; case HAL_PIXEL_FORMAT_RGB_888: diff --git a/fingerprint/Android.mk b/fingerprint/Android.mk new file mode 100644 index 0000000..f4b76c9 --- /dev/null +++ b/fingerprint/Android.mk @@ -0,0 +1,33 @@ +# Copyright (C) 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := fingerprint.goldfish +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := fingerprint.c +LOCAL_SHARED_LIBRARIES := liblog + +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_MODULE := fingerprint.ranchu +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := fingerprint.c +LOCAL_SHARED_LIBRARIES := liblog + +include $(BUILD_SHARED_LIBRARY) diff --git a/fingerprint/fingerprint.c b/fingerprint/fingerprint.c new file mode 100644 index 0000000..48cddd8 --- /dev/null +++ b/fingerprint/fingerprint.c @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define FINGERPRINT_LISTEN_SERVICE_NAME "fingerprintlisten" + +#define LOG_TAG "FingerprintHal" + +#include <errno.h> +#include <malloc.h> +#include <string.h> +#include <cutils/log.h> +#include <hardware/hardware.h> +#include <hardware/fingerprint.h> +#include <hardware/qemud.h> + +typedef enum worker_state_t { + STATE_ENROLL = 1, + STATE_SCAN = 2, + STATE_EXIT = 3 +} worker_state_t; + +typedef struct worker_thread_t { + pthread_t thread; + pthread_mutex_t mutex; + int request; + worker_state_t state; + int fingerid; + int finger_is_on; +} worker_thread_t; + +typedef struct emu_fingerprint_hal_device_t { + fingerprint_device_t device; //inheritance + worker_thread_t listener; + pthread_mutex_t lock; +} emu_fingerprint_hal_device_t; + + +static void destroyListenerThread(emu_fingerprint_hal_device_t* dev) +{ + pthread_join(dev->listener.thread, NULL); + pthread_mutex_destroy(&dev->listener.mutex); +} + +static void listener_send_notice(emu_fingerprint_hal_device_t* dev) +{ + fingerprint_msg_t message; + pthread_mutex_lock(&dev->listener.mutex); + if (dev->listener.state == STATE_ENROLL) { + message.type = FINGERPRINT_TEMPLATE_ENROLLING; + message.data.enroll.finger.fid = dev->listener.fingerid; + message.data.enroll.samples_remaining = 0; + dev->listener.state = STATE_SCAN; + } else { + message.type = FINGERPRINT_PROCESSED; + message.data.processed.finger.gid = 0; + message.data.processed.finger.fid = dev->listener.fingerid; + } + pthread_mutex_unlock(&dev->listener.mutex); + + pthread_mutex_lock(&dev->lock); + dev->device.notify(message); + pthread_mutex_unlock(&dev->lock); +} + +static void* listenerFunction(void* data) +{ + emu_fingerprint_hal_device_t* dev = (emu_fingerprint_hal_device_t*) data; + + int fd = qemud_channel_open(FINGERPRINT_LISTEN_SERVICE_NAME); + if (fd < 0) { + ALOGE("listener cannot open fingerprint listener service exit"); + return NULL; + } + + const char* cmd = "listen"; + if (qemud_channel_send(fd, cmd, strlen(cmd)) < 0) { + ALOGE("cannot write fingerprint 'listen' to host"); + return NULL; + } + + char buffer[128]; + int fingerid=-1; + int size; + while (1) { + //simply listen in blocking mode + if ((size = qemud_channel_recv(fd, buffer, sizeof buffer - 1)) >0) { + buffer[size] = '\0'; + if (sscanf(buffer, "on:%d", &fingerid) == 1) { + dev->listener.fingerid = fingerid; + dev->listener.finger_is_on = 1; + ALOGD("got finger %d", fingerid); + listener_send_notice(dev); + ALOGD("send notice finger %d", fingerid); + } else if (strncmp("off", buffer, 3) == 0) { + dev->listener.finger_is_on = 0; + ALOGD("finger off", fingerid); + } else { + ALOGE("error: '%s'", buffer); + } + } else { + ALOGE("receive failure"); + // return NULL; + } + //TODO: check for request to exit thread + } + + ALOGD("listener exit"); + return NULL; +} + +static void createListenerThread(emu_fingerprint_hal_device_t* dev) +{ + pthread_mutex_init(&dev->listener.mutex, NULL); + pthread_create(&dev->listener.thread, NULL, listenerFunction, dev); +} + +static int fingerprint_close(hw_device_t *dev) +{ + if (dev) { + free(dev); + destroyListenerThread(dev); + return 0; + } else { + return -1; + } +} + +static void setListenerState(emu_fingerprint_hal_device_t* dev, worker_state_t state) { + pthread_mutex_lock(&dev->listener.mutex); + dev->listener.state = state; + pthread_mutex_unlock(&dev->listener.mutex); +} + +static int fingerprint_enroll(struct fingerprint_device __unused *device, + uint32_t __unused timeout_sec) { + ALOGE("fingerpring_enroll"); + emu_fingerprint_hal_device_t* dev = (emu_fingerprint_hal_device_t*) device; + setListenerState(dev, STATE_ENROLL); + return 0; + +} + +static int fingerprint_enroll_cancel(struct fingerprint_device __unused *device, + uint32_t __unused timeout_sec) { + ALOGE("fingerpring_enroll_cancel"); + emu_fingerprint_hal_device_t* dev = (emu_fingerprint_hal_device_t*) device; + setListenerState(dev, STATE_SCAN); + return 0; +} + +static int fingerprint_remove(struct fingerprint_device __unused *dev, + uint32_t __unused fingerprint_id) { + return FINGERPRINT_ERROR; +} + +static int set_notify_callback(struct fingerprint_device *device, + fingerprint_notify_t notify) { + ALOGD("set_notify"); + emu_fingerprint_hal_device_t* dev =(emu_fingerprint_hal_device_t*) device; + pthread_mutex_lock(&dev->lock); + device->notify = notify; + pthread_mutex_unlock(&dev->lock); + return 0; +} + +static int fingerprint_open(const hw_module_t* module, const char __unused *id, + hw_device_t** device) +{ + if (device == NULL) { + ALOGE("NULL device on open"); + return -EINVAL; + } else { + ALOGE("fingerprint open\n"); + } + + emu_fingerprint_hal_device_t *dev = malloc(sizeof(emu_fingerprint_hal_device_t)); + memset(dev, 0, sizeof(emu_fingerprint_hal_device_t)); + + dev->device.common.tag = HARDWARE_DEVICE_TAG; + dev->device.common.version = HARDWARE_MODULE_API_VERSION(2, 0); + dev->device.common.module = (struct hw_module_t*) module; + dev->device.common.close = fingerprint_close; + + dev->device.enroll = fingerprint_enroll; + dev->device.enroll_cancel = fingerprint_enroll_cancel; + dev->device.remove = fingerprint_remove; + dev->device.set_notify = set_notify_callback; + dev->device.notify = NULL; + + pthread_mutex_init(&dev->lock, NULL); + createListenerThread(dev); + *device = (hw_device_t*) dev; + return 0; +} + +static struct hw_module_methods_t fingerprint_module_methods = { + .open = fingerprint_open, +}; + +fingerprint_module_t HAL_MODULE_INFO_SYM = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .module_api_version = FINGERPRINT_MODULE_API_VERSION_1_0, + .hal_api_version = HARDWARE_HAL_API_VERSION, + .id = FINGERPRINT_HARDWARE_MODULE_ID, + .name = "Emulator Fingerprint HAL", + .author = "The Android Open Source Project", + .methods = &fingerprint_module_methods, + }, +}; diff --git a/opengl/system/gralloc/gralloc.cpp b/opengl/system/gralloc/gralloc.cpp index 059bf12..9659e3d 100644 --- a/opengl/system/gralloc/gralloc.cpp +++ b/opengl/system/gralloc/gralloc.cpp @@ -211,7 +211,7 @@ static int gralloc_alloc(alloc_device_t* dev, glFormat = GL_RGB; glType = GL_UNSIGNED_SHORT_5_6_5; break; - case HAL_PIXEL_FORMAT_RAW_SENSOR: + case HAL_PIXEL_FORMAT_RAW16: bpp = 2; align = 16*bpp; if (! ((sw_read || hw_cam_read) && (sw_write || hw_cam_write) ) ) { |