├── Android.mk ├── CleanSpec.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE ├── hardware.c ├── include └── hardware │ ├── activity_recognition.h │ ├── audio.h │ ├── audio_alsaops.h │ ├── audio_amplifier.h │ ├── audio_effect.h │ ├── audio_policy.h │ ├── bluetooth.h │ ├── boot_control.h │ ├── bt_av.h │ ├── bt_common_types.h │ ├── bt_gatt.h │ ├── bt_gatt_client.h │ ├── bt_gatt_server.h │ ├── bt_gatt_types.h │ ├── bt_hf.h │ ├── bt_hf_client.h │ ├── bt_hh.h │ ├── bt_hl.h │ ├── bt_mce.h │ ├── bt_pan.h │ ├── bt_rc.h │ ├── bt_sdp.h │ ├── bt_sock.h │ ├── camera.h │ ├── camera2.h │ ├── camera3.h │ ├── camera_common.h │ ├── consumerir.h │ ├── context_hub.h │ ├── display_defs.h │ ├── fb.h │ ├── fingerprint.h │ ├── fused_location.h │ ├── gatekeeper.h │ ├── gps.h │ ├── gps_internal.h │ ├── gralloc.h │ ├── gralloc1.h │ ├── hardware.h │ ├── hdmi_cec.h │ ├── hw_auth_token.h │ ├── hwcomposer.h │ ├── hwcomposer2.h │ ├── hwcomposer_defs.h │ ├── input.h │ ├── keymaster0.h │ ├── keymaster1.h │ ├── keymaster2.h │ ├── keymaster_common.h │ ├── keymaster_defs.h │ ├── lights.h │ ├── local_time_hal.h │ ├── memtrack.h │ ├── nfc.h │ ├── nfc_tag.h │ ├── nvram.h │ ├── power.h │ ├── qemu_pipe.h │ ├── qemud.h │ ├── radio.h │ ├── sensors.h │ ├── sound_trigger.h │ ├── thermal.h │ ├── tv_input.h │ ├── vehicle.h │ ├── vehicle_camera.h │ ├── vibrator.h │ └── vr.h ├── modules ├── Android.mk ├── README.android ├── audio │ ├── Android.mk │ ├── audio_amplifier.c │ ├── audio_hw.c │ └── audio_policy.c ├── audio_remote_submix │ ├── Android.mk │ └── audio_hw.cpp ├── camera │ ├── Android.mk │ ├── Camera.cpp │ ├── Camera.h │ ├── CameraHAL.cpp │ ├── CameraHAL.h │ ├── ExampleCamera.cpp │ ├── ExampleCamera.h │ ├── Metadata.cpp │ ├── Metadata.h │ ├── Stream.cpp │ ├── Stream.h │ ├── VendorTags.cpp │ └── VendorTags.h ├── consumerir │ ├── Android.mk │ └── consumerir.c ├── fingerprint │ ├── Android.mk │ └── fingerprint.c ├── gralloc │ ├── Android.mk │ ├── framebuffer.cpp │ ├── gr.h │ ├── gralloc.cpp │ ├── gralloc_priv.h │ └── mapper.cpp ├── hwcomposer │ ├── Android.mk │ ├── README.android │ └── hwcomposer.cpp ├── input │ ├── Android.mk │ └── evdev │ │ ├── Android.mk │ │ ├── BitUtils.cpp │ │ ├── BitUtils.h │ │ ├── EvdevModule.cpp │ │ ├── InputDevice.cpp │ │ ├── InputDevice.h │ │ ├── InputDeviceManager.cpp │ │ ├── InputDeviceManager.h │ │ ├── InputHost.cpp │ │ ├── InputHost.h │ │ ├── InputHub.cpp │ │ ├── InputHub.h │ │ ├── InputMapper.cpp │ │ ├── InputMapper.h │ │ ├── MouseInputMapper.cpp │ │ ├── MouseInputMapper.h │ │ ├── SwitchInputMapper.cpp │ │ └── SwitchInputMapper.h ├── local_time │ ├── Android.mk │ └── local_time_hw.c ├── nfc-nci │ ├── Android.mk │ └── nfc_nci_example.c ├── nfc │ ├── Android.mk │ └── nfc_pn544_example.c ├── power │ ├── Android.mk │ └── power.c ├── radio │ ├── Android.mk │ ├── radio_hal_tool.c │ └── radio_hw.c ├── sensors │ ├── Android.mk │ ├── SensorEventQueue.cpp │ ├── SensorEventQueue.h │ ├── multihal.cpp │ └── tests │ │ ├── Android.mk │ │ └── SensorEventQueue_test.cpp ├── soundtrigger │ ├── Android.mk │ └── sound_trigger_hw.c ├── thermal │ ├── Android.mk │ └── thermal.c ├── tv_input │ ├── Android.mk │ └── tv_input.cpp ├── usbaudio │ ├── Android.mk │ └── audio_hal.c ├── usbcamera │ ├── Android.mk │ ├── Camera.cpp │ ├── Camera.h │ ├── CameraHAL.cpp │ ├── CameraHAL.h │ ├── HotplugThread.cpp │ ├── HotplugThread.h │ ├── Metadata.cpp │ ├── Metadata.h │ ├── Stream.cpp │ ├── Stream.h │ ├── UsbCamera.cpp │ └── UsbCamera.h ├── vehicle │ ├── Android.mk │ ├── timeUtil.cpp │ └── vehicle.c ├── vibrator │ ├── Android.mk │ └── vibrator.c └── vr │ ├── Android.mk │ └── vr.c └── tests ├── Android.mk ├── camera2 ├── Android.mk ├── CameraBurstTests.cpp ├── CameraFrameTests.cpp ├── CameraMetadataTests.cpp ├── CameraModuleFixture.h ├── CameraModuleTests.cpp ├── CameraMultiStreamTests.cpp ├── CameraStreamFixture.h ├── CameraStreamTests.cpp ├── ForkedTests.cpp ├── TestExtensions.h ├── TestForkerEventListener.cpp ├── TestForkerEventListener.h ├── TestSettings.cpp ├── TestSettings.h ├── camera2_utils.cpp ├── camera2_utils.h └── main.cpp ├── camera3 ├── Android.mk ├── camera3test_fixtures.h └── camera3tests.cpp ├── fingerprint ├── Android.mk ├── fingerprint_test_fixtures.h └── fingerprint_tests.cpp ├── hardware ├── Android.mk ├── struct-last.cpp ├── struct-offset.cpp └── struct-size.cpp ├── hwc ├── Android.mk ├── cnativewindow.c ├── test-arrows.c ├── util.c └── util.h ├── input ├── Android.mk └── evdev │ ├── Android.mk │ ├── BitUtils_test.cpp │ ├── InputDevice_test.cpp │ ├── InputHub_test.cpp │ ├── InputMocks.cpp │ ├── InputMocks.h │ ├── MockInputHost.h │ ├── MouseInputMapper_test.cpp │ ├── SwitchInputMapper_test.cpp │ ├── TestHelpers.cpp │ └── TestHelpers.h ├── keymaster ├── Android.mk └── keymaster_test.cpp ├── nusensors ├── Android.mk └── nusensors.cpp └── vehicle ├── Android.mk ├── README ├── vehicle-hal-tool.c ├── vehicle_test_fixtures.h └── vehicle_tests.cpp /Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2006 The Android Open Source Project 2 | 3 | # Setting LOCAL_PATH will mess up all-subdir-makefiles, so do it beforehand. 4 | SUBDIR_MAKEFILES := $(call all-named-subdir-makefiles,modules tests) 5 | 6 | LOCAL_PATH:= $(call my-dir) 7 | include $(CLEAR_VARS) 8 | 9 | LOCAL_SHARED_LIBRARIES := libcutils liblog 10 | 11 | LOCAL_INCLUDES += $(LOCAL_PATH) 12 | 13 | LOCAL_CFLAGS += -DQEMU_HARDWARE 14 | QEMU_HARDWARE := true 15 | 16 | LOCAL_SHARED_LIBRARIES += libdl 17 | 18 | LOCAL_SRC_FILES += hardware.c 19 | 20 | LOCAL_MODULE:= libhardware 21 | 22 | include $(BUILD_SHARED_LIBRARY) 23 | 24 | include $(SUBDIR_MAKEFILES) 25 | -------------------------------------------------------------------------------- /CleanSpec.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # If you don't need to do a full clean build but would like to touch 17 | # a file or delete some intermediate files, add a clean step to the end 18 | # of the list. These steps will only be run once, if they haven't been 19 | # run before. 20 | # 21 | # E.g.: 22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h) 23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) 24 | # 25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with 26 | # files that are missing or have been moved. 27 | # 28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. 29 | # Use $(OUT_DIR) to refer to the "out" directory. 30 | # 31 | # If you need to re-do something that's already mentioned, just copy 32 | # the command and add it to the bottom of the list. E.g., if a change 33 | # that you made last week required touching a file and a change you 34 | # made today requires touching the same file, just copy the old 35 | # touch step and add it to the end of the list. 36 | # 37 | # ************************************************ 38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 39 | # ************************************************ 40 | 41 | # For example: 42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) 43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) 44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) 45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) 46 | 47 | # ************************************************ 48 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 49 | # ************************************************ 50 | -------------------------------------------------------------------------------- /MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_libhardware/f1aeb1fb33a7fd1cca7a55e5f83a0c5fb19b74a4/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /include/hardware/audio_alsaops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* This file contains shared utility functions to handle the tinyalsa 18 | * implementation for Android internal audio, generally in the hardware layer. 19 | * Some routines may log a fatal error on failure, as noted. 20 | */ 21 | 22 | #ifndef ANDROID_AUDIO_ALSAOPS_H 23 | #define ANDROID_AUDIO_ALSAOPS_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | __BEGIN_DECLS 30 | 31 | /* Converts audio_format to pcm_format. 32 | * Parameters: 33 | * format the audio_format_t to convert 34 | * 35 | * Logs a fatal error if format is not a valid convertible audio_format_t. 36 | */ 37 | static inline enum pcm_format pcm_format_from_audio_format(audio_format_t format) 38 | { 39 | switch (format) { 40 | #ifdef HAVE_BIG_ENDIAN 41 | case AUDIO_FORMAT_PCM_16_BIT: 42 | return PCM_FORMAT_S16_BE; 43 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: 44 | return PCM_FORMAT_S24_3BE; 45 | case AUDIO_FORMAT_PCM_32_BIT: 46 | return PCM_FORMAT_S32_BE; 47 | case AUDIO_FORMAT_PCM_8_24_BIT: 48 | return PCM_FORMAT_S24_BE; 49 | #else 50 | case AUDIO_FORMAT_PCM_16_BIT: 51 | return PCM_FORMAT_S16_LE; 52 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: 53 | return PCM_FORMAT_S24_3LE; 54 | case AUDIO_FORMAT_PCM_32_BIT: 55 | return PCM_FORMAT_S32_LE; 56 | case AUDIO_FORMAT_PCM_8_24_BIT: 57 | return PCM_FORMAT_S24_LE; 58 | #endif 59 | case AUDIO_FORMAT_PCM_FLOAT: /* there is no equivalent for float */ 60 | default: 61 | LOG_ALWAYS_FATAL("pcm_format_from_audio_format: invalid audio format %#x", format); 62 | return 0; 63 | } 64 | } 65 | 66 | /* Converts pcm_format to audio_format. 67 | * Parameters: 68 | * format the pcm_format to convert 69 | * 70 | * Logs a fatal error if format is not a valid convertible pcm_format. 71 | */ 72 | static inline audio_format_t audio_format_from_pcm_format(enum pcm_format format) 73 | { 74 | switch (format) { 75 | #ifdef HAVE_BIG_ENDIAN 76 | case PCM_FORMAT_S16_BE: 77 | return AUDIO_FORMAT_PCM_16_BIT; 78 | case PCM_FORMAT_S24_3BE: 79 | return AUDIO_FORMAT_PCM_24_BIT_PACKED; 80 | case PCM_FORMAT_S24_BE: 81 | return AUDIO_FORMAT_PCM_8_24_BIT; 82 | case PCM_FORMAT_S32_BE: 83 | return AUDIO_FORMAT_PCM_32_BIT; 84 | #else 85 | case PCM_FORMAT_S16_LE: 86 | return AUDIO_FORMAT_PCM_16_BIT; 87 | case PCM_FORMAT_S24_3LE: 88 | return AUDIO_FORMAT_PCM_24_BIT_PACKED; 89 | case PCM_FORMAT_S24_LE: 90 | return AUDIO_FORMAT_PCM_8_24_BIT; 91 | case PCM_FORMAT_S32_LE: 92 | return AUDIO_FORMAT_PCM_32_BIT; 93 | #endif 94 | default: 95 | LOG_ALWAYS_FATAL("audio_format_from_pcm_format: invalid pcm format %#x", format); 96 | return 0; 97 | } 98 | } 99 | 100 | __END_DECLS 101 | 102 | #endif /* ANDROID_AUDIO_ALSAOPS_H */ 103 | -------------------------------------------------------------------------------- /include/hardware/bt_common_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /****************************************************************************** 18 | * 19 | * This file contains constants and definitions that can be used commonly between JNI and stack layer 20 | * 21 | ******************************************************************************/ 22 | #ifndef ANDROID_INCLUDE_BT_COMMON_TYPES_H 23 | #define ANDROID_INCLUDE_BT_COMMON_TYPES_H 24 | 25 | #include "bluetooth.h" 26 | 27 | typedef struct 28 | { 29 | uint8_t client_if; 30 | uint8_t filt_index; 31 | uint8_t advertiser_state; 32 | uint8_t advertiser_info_present; 33 | uint8_t addr_type; 34 | uint8_t tx_power; 35 | int8_t rssi_value; 36 | uint16_t time_stamp; 37 | bt_bdaddr_t bd_addr; 38 | uint8_t adv_pkt_len; 39 | uint8_t *p_adv_pkt_data; 40 | uint8_t scan_rsp_len; 41 | uint8_t *p_scan_rsp_data; 42 | } btgatt_track_adv_info_t; 43 | 44 | typedef enum 45 | { 46 | BTGATT_DB_PRIMARY_SERVICE, 47 | BTGATT_DB_SECONDARY_SERVICE, 48 | BTGATT_DB_INCLUDED_SERVICE, 49 | BTGATT_DB_CHARACTERISTIC, 50 | BTGATT_DB_DESCRIPTOR, 51 | } bt_gatt_db_attribute_type_t; 52 | 53 | typedef struct 54 | { 55 | uint16_t id; 56 | bt_uuid_t uuid; 57 | bt_gatt_db_attribute_type_t type; 58 | uint16_t attribute_handle; 59 | 60 | /* 61 | * If |type| is |BTGATT_DB_PRIMARY_SERVICE|, or 62 | * |BTGATT_DB_SECONDARY_SERVICE|, this contains the start and end attribute 63 | * handles. 64 | */ 65 | uint16_t start_handle; 66 | uint16_t end_handle; 67 | 68 | /* 69 | * If |type| is |BTGATT_DB_CHARACTERISTIC|, this contains the properties of 70 | * the characteristic. 71 | */ 72 | uint8_t properties; 73 | } btgatt_db_element_t; 74 | 75 | #endif /* ANDROID_INCLUDE_BT_COMMON_TYPES_H */ 76 | -------------------------------------------------------------------------------- /include/hardware/bt_gatt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #ifndef ANDROID_INCLUDE_BT_GATT_H 19 | #define ANDROID_INCLUDE_BT_GATT_H 20 | 21 | #include 22 | #include "bt_gatt_client.h" 23 | #include "bt_gatt_server.h" 24 | 25 | __BEGIN_DECLS 26 | 27 | /** BT-GATT callbacks */ 28 | typedef struct { 29 | /** Set to sizeof(btgatt_callbacks_t) */ 30 | size_t size; 31 | 32 | /** GATT Client callbacks */ 33 | const btgatt_client_callbacks_t* client; 34 | 35 | /** GATT Server callbacks */ 36 | const btgatt_server_callbacks_t* server; 37 | } btgatt_callbacks_t; 38 | 39 | /** Represents the standard Bluetooth GATT interface. */ 40 | typedef struct { 41 | /** Set to sizeof(btgatt_interface_t) */ 42 | size_t size; 43 | 44 | /** 45 | * Initializes the interface and provides callback routines 46 | */ 47 | bt_status_t (*init)( const btgatt_callbacks_t* callbacks ); 48 | 49 | /** Closes the interface */ 50 | void (*cleanup)( void ); 51 | 52 | /** Pointer to the GATT client interface methods.*/ 53 | const btgatt_client_interface_t* client; 54 | 55 | /** Pointer to the GATT server interface methods.*/ 56 | const btgatt_server_interface_t* server; 57 | } btgatt_interface_t; 58 | 59 | __END_DECLS 60 | 61 | #endif /* ANDROID_INCLUDE_BT_GATT_H */ 62 | -------------------------------------------------------------------------------- /include/hardware/bt_gatt_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #ifndef ANDROID_INCLUDE_BT_GATT_TYPES_H 19 | #define ANDROID_INCLUDE_BT_GATT_TYPES_H 20 | 21 | #include 22 | #include 23 | 24 | __BEGIN_DECLS 25 | 26 | /** 27 | * GATT Service types 28 | */ 29 | #define BTGATT_SERVICE_TYPE_PRIMARY 0 30 | #define BTGATT_SERVICE_TYPE_SECONDARY 1 31 | 32 | /** GATT ID adding instance id tracking to the UUID */ 33 | typedef struct 34 | { 35 | bt_uuid_t uuid; 36 | uint8_t inst_id; 37 | } btgatt_gatt_id_t; 38 | 39 | /** GATT Service ID also identifies the service type (primary/secondary) */ 40 | typedef struct 41 | { 42 | btgatt_gatt_id_t id; 43 | uint8_t is_primary; 44 | } btgatt_srvc_id_t; 45 | 46 | /** Preferred physical Transport for GATT connection */ 47 | typedef enum 48 | { 49 | GATT_TRANSPORT_AUTO, 50 | GATT_TRANSPORT_BREDR, 51 | GATT_TRANSPORT_LE 52 | } btgatt_transport_t; 53 | 54 | __END_DECLS 55 | 56 | #endif /* ANDROID_INCLUDE_BT_GATT_TYPES_H */ 57 | -------------------------------------------------------------------------------- /include/hardware/bt_hl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_INCLUDE_BT_HL_H 18 | #define ANDROID_INCLUDE_BT_HL_H 19 | 20 | __BEGIN_DECLS 21 | 22 | /* HL connection states */ 23 | 24 | typedef enum 25 | { 26 | BTHL_MDEP_ROLE_SOURCE, 27 | BTHL_MDEP_ROLE_SINK 28 | } bthl_mdep_role_t; 29 | 30 | typedef enum { 31 | BTHL_APP_REG_STATE_REG_SUCCESS, 32 | BTHL_APP_REG_STATE_REG_FAILED, 33 | BTHL_APP_REG_STATE_DEREG_SUCCESS, 34 | BTHL_APP_REG_STATE_DEREG_FAILED 35 | } bthl_app_reg_state_t; 36 | 37 | typedef enum 38 | { 39 | BTHL_CHANNEL_TYPE_RELIABLE, 40 | BTHL_CHANNEL_TYPE_STREAMING, 41 | BTHL_CHANNEL_TYPE_ANY 42 | } bthl_channel_type_t; 43 | 44 | 45 | /* HL connection states */ 46 | typedef enum { 47 | BTHL_CONN_STATE_CONNECTING, 48 | BTHL_CONN_STATE_CONNECTED, 49 | BTHL_CONN_STATE_DISCONNECTING, 50 | BTHL_CONN_STATE_DISCONNECTED, 51 | BTHL_CONN_STATE_DESTROYED 52 | } bthl_channel_state_t; 53 | 54 | typedef struct 55 | { 56 | bthl_mdep_role_t mdep_role; 57 | int data_type; 58 | bthl_channel_type_t channel_type; 59 | const char *mdep_description; /* MDEP description to be used in the SDP (optional); null terminated */ 60 | } bthl_mdep_cfg_t; 61 | 62 | typedef struct 63 | { 64 | const char *application_name; 65 | const char *provider_name; /* provider name to be used in the SDP (optional); null terminated */ 66 | const char *srv_name; /* service name to be used in the SDP (optional); null terminated*/ 67 | const char *srv_desp; /* service description to be used in the SDP (optional); null terminated */ 68 | int number_of_mdeps; 69 | bthl_mdep_cfg_t *mdep_cfg; /* Dynamic array */ 70 | } bthl_reg_param_t; 71 | 72 | /** Callback for application registration status. 73 | * state will have one of the values from bthl_app_reg_state_t 74 | */ 75 | typedef void (* bthl_app_reg_state_callback)(int app_id, bthl_app_reg_state_t state); 76 | 77 | /** Callback for channel connection state change. 78 | * state will have one of the values from 79 | * bthl_connection_state_t and fd (file descriptor) 80 | */ 81 | typedef void (* bthl_channel_state_callback)(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int channel_id, bthl_channel_state_t state, int fd); 82 | 83 | /** BT-HL callback structure. */ 84 | typedef struct { 85 | /** set to sizeof(bthl_callbacks_t) */ 86 | size_t size; 87 | bthl_app_reg_state_callback app_reg_state_cb; 88 | bthl_channel_state_callback channel_state_cb; 89 | } bthl_callbacks_t; 90 | 91 | 92 | /** Represents the standard BT-HL interface. */ 93 | typedef struct { 94 | 95 | /** set to sizeof(bthl_interface_t) */ 96 | size_t size; 97 | 98 | /** 99 | * Register the Bthl callbacks 100 | */ 101 | bt_status_t (*init)( bthl_callbacks_t* callbacks ); 102 | 103 | /** Register HL application */ 104 | bt_status_t (*register_application) ( bthl_reg_param_t *p_reg_param, int *app_id); 105 | 106 | /** Unregister HL application */ 107 | bt_status_t (*unregister_application) (int app_id); 108 | 109 | /** connect channel */ 110 | bt_status_t (*connect_channel)(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int *channel_id); 111 | 112 | /** destroy channel */ 113 | bt_status_t (*destroy_channel)(int channel_id); 114 | 115 | /** Close the Bthl callback **/ 116 | void (*cleanup)(void); 117 | 118 | } bthl_interface_t; 119 | __END_DECLS 120 | 121 | #endif /* ANDROID_INCLUDE_BT_HL_H */ 122 | 123 | 124 | -------------------------------------------------------------------------------- /include/hardware/bt_mce.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_INCLUDE_BT_MCE_H 18 | #define ANDROID_INCLUDE_BT_MCE_H 19 | 20 | __BEGIN_DECLS 21 | 22 | /** MAS instance description */ 23 | typedef struct 24 | { 25 | int id; 26 | int scn; 27 | int msg_types; 28 | char *p_name; 29 | } btmce_mas_instance_t; 30 | 31 | /** callback for get_remote_mas_instances */ 32 | typedef void (*btmce_remote_mas_instances_callback)(bt_status_t status, bt_bdaddr_t *bd_addr, 33 | int num_instances, btmce_mas_instance_t *instances); 34 | 35 | typedef struct { 36 | /** set to sizeof(btmce_callbacks_t) */ 37 | size_t size; 38 | btmce_remote_mas_instances_callback remote_mas_instances_cb; 39 | } btmce_callbacks_t; 40 | 41 | typedef struct { 42 | /** set to size of this struct */ 43 | size_t size; 44 | 45 | /** register BT MCE callbacks */ 46 | bt_status_t (*init)(btmce_callbacks_t *callbacks); 47 | 48 | /** search for MAS instances on remote device */ 49 | bt_status_t (*get_remote_mas_instances)(bt_bdaddr_t *bd_addr); 50 | } btmce_interface_t; 51 | 52 | __END_DECLS 53 | 54 | #endif /* ANDROID_INCLUDE_BT_MCE_H */ 55 | -------------------------------------------------------------------------------- /include/hardware/bt_pan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_INCLUDE_BT_PAN_H 18 | #define ANDROID_INCLUDE_BT_PAN_H 19 | 20 | __BEGIN_DECLS 21 | 22 | #define BTPAN_ROLE_NONE 0 23 | #define BTPAN_ROLE_PANNAP 1 24 | #define BTPAN_ROLE_PANU 2 25 | 26 | typedef enum { 27 | BTPAN_STATE_CONNECTED = 0, 28 | BTPAN_STATE_CONNECTING = 1, 29 | BTPAN_STATE_DISCONNECTED = 2, 30 | BTPAN_STATE_DISCONNECTING = 3 31 | } btpan_connection_state_t; 32 | 33 | typedef enum { 34 | BTPAN_STATE_ENABLED = 0, 35 | BTPAN_STATE_DISABLED = 1 36 | } btpan_control_state_t; 37 | 38 | /** 39 | * Callback for pan connection state 40 | */ 41 | typedef void (*btpan_connection_state_callback)(btpan_connection_state_t state, bt_status_t error, 42 | const bt_bdaddr_t *bd_addr, int local_role, int remote_role); 43 | typedef void (*btpan_control_state_callback)(btpan_control_state_t state, int local_role, 44 | bt_status_t error, const char* ifname); 45 | 46 | typedef struct { 47 | size_t size; 48 | btpan_control_state_callback control_state_cb; 49 | btpan_connection_state_callback connection_state_cb; 50 | } btpan_callbacks_t; 51 | typedef struct { 52 | /** set to size of this struct*/ 53 | size_t size; 54 | /** 55 | * Initialize the pan interface and register the btpan callbacks 56 | */ 57 | bt_status_t (*init)(const btpan_callbacks_t* callbacks); 58 | /* 59 | * enable the pan service by specified role. The result state of 60 | * enabl will be returned by btpan_control_state_callback. when pan-nap is enabled, 61 | * the state of connecting panu device will be notified by btpan_connection_state_callback 62 | */ 63 | bt_status_t (*enable)(int local_role); 64 | /* 65 | * get current pan local role 66 | */ 67 | int (*get_local_role)(void); 68 | /** 69 | * start bluetooth pan connection to the remote device by specified pan role. The result state will be 70 | * returned by btpan_connection_state_callback 71 | */ 72 | bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, int local_role, int remote_role); 73 | /** 74 | * stop bluetooth pan connection. The result state will be returned by btpan_connection_state_callback 75 | */ 76 | bt_status_t (*disconnect)(const bt_bdaddr_t *bd_addr); 77 | 78 | /** 79 | * Cleanup the pan interface 80 | */ 81 | void (*cleanup)(void); 82 | 83 | } btpan_interface_t; 84 | 85 | __END_DECLS 86 | 87 | #endif /* ANDROID_INCLUDE_BT_PAN_H */ 88 | -------------------------------------------------------------------------------- /include/hardware/bt_sock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | __BEGIN_DECLS 20 | 21 | #define BTSOCK_FLAG_ENCRYPT 1 22 | #define BTSOCK_FLAG_AUTH (1 << 1) 23 | #define BTSOCK_FLAG_NO_SDP (1 << 2) 24 | #define BTSOCK_FLAG_AUTH_MITM (1 << 3) 25 | #define BTSOCK_FLAG_AUTH_16_DIGIT (1 << 4) 26 | 27 | typedef enum { 28 | BTSOCK_RFCOMM = 1, 29 | BTSOCK_SCO = 2, 30 | BTSOCK_L2CAP = 3 31 | } btsock_type_t; 32 | 33 | typedef enum { 34 | BTSOCK_OPT_GET_MODEM_BITS = 1, 35 | BTSOCK_OPT_SET_MODEM_BITS = 2, 36 | BTSOCK_OPT_CLR_MODEM_BITS = 3, 37 | } btsock_option_type_t; 38 | 39 | /** Represents the standard BT SOCKET interface. */ 40 | typedef struct { 41 | short size; 42 | bt_bdaddr_t bd_addr; 43 | int channel; 44 | int status; 45 | 46 | // The writer must make writes using a buffer of this maximum size 47 | // to avoid loosing data. (L2CAP only) 48 | unsigned short max_tx_packet_size; 49 | 50 | // The reader must read using a buffer of at least this size to avoid 51 | // loosing data. (L2CAP only) 52 | unsigned short max_rx_packet_size; 53 | } __attribute__((packed)) sock_connect_signal_t; 54 | 55 | typedef struct { 56 | /** set to size of this struct*/ 57 | size_t size; 58 | 59 | /** 60 | * Listen to a RFCOMM UUID or channel. It returns the socket fd from which 61 | * btsock_connect_signal can be read out when a remote device connected. 62 | * If neither a UUID nor a channel is provided, a channel will be allocated 63 | * and a service record can be created providing the channel number to 64 | * create_sdp_record(...) in bt_sdp. 65 | * The callingUid is the UID of the application which is requesting the socket. This is 66 | * used for traffic accounting purposes. 67 | */ 68 | bt_status_t (*listen)(btsock_type_t type, const char* service_name, 69 | const uint8_t* service_uuid, int channel, int* sock_fd, int flags, int callingUid); 70 | 71 | /** 72 | * Connect to a RFCOMM UUID channel of remote device, It returns the socket fd from which 73 | * the btsock_connect_signal and a new socket fd to be accepted can be read out when connected. 74 | * The callingUid is the UID of the application which is requesting the socket. This is 75 | * used for traffic accounting purposes. 76 | */ 77 | bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t* uuid, 78 | int channel, int* sock_fd, int flags, int callingUid); 79 | 80 | /* 81 | * get socket option of rfcomm channel socket. 82 | */ 83 | bt_status_t (*get_sock_opt)(btsock_type_t type, int channel, btsock_option_type_t option_name, 84 | void *option_value, int *option_len); 85 | /* 86 | 87 | * set socket option of rfcomm channel socket. 88 | */ 89 | bt_status_t (*set_sock_opt)(btsock_type_t type, int channel, btsock_option_type_t option_name, 90 | void *option_value, int option_len); 91 | 92 | } btsock_interface_t; 93 | 94 | __END_DECLS 95 | 96 | -------------------------------------------------------------------------------- /include/hardware/consumerir.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_INCLUDE_HARDWARE_CONSUMERIR_H 18 | #define ANDROID_INCLUDE_HARDWARE_CONSUMERIR_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define CONSUMERIR_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0) 26 | #define CONSUMERIR_HARDWARE_MODULE_ID "consumerir" 27 | #define CONSUMERIR_TRANSMITTER "transmitter" 28 | 29 | typedef struct consumerir_freq_range { 30 | int min; 31 | int max; 32 | } consumerir_freq_range_t; 33 | 34 | typedef struct consumerir_module { 35 | /** 36 | * Common methods of the consumer IR module. This *must* be the first member of 37 | * consumerir_module as users of this structure will cast a hw_module_t to 38 | * consumerir_module pointer in contexts where it's known the hw_module_t references a 39 | * consumerir_module. 40 | */ 41 | struct hw_module_t common; 42 | } consumerir_module_t; 43 | 44 | typedef struct consumerir_device { 45 | /** 46 | * Common methods of the consumer IR device. This *must* be the first member of 47 | * consumerir_device as users of this structure will cast a hw_device_t to 48 | * consumerir_device pointer in contexts where it's known the hw_device_t references a 49 | * consumerir_device. 50 | */ 51 | struct hw_device_t common; 52 | 53 | /* 54 | * (*transmit)() is called to by the ConsumerIrService to send an IR pattern 55 | * at a given carrier_freq. 56 | * 57 | * The pattern is alternating series of carrier on and off periods measured in 58 | * microseconds. The carrier should be turned off at the end of a transmit 59 | * even if there are and odd number of entries in the pattern array. 60 | * 61 | * This call should return when the transmit is complete or encounters an error. 62 | * 63 | * returns: 0 on success. A negative error code on error. 64 | */ 65 | int (*transmit)(struct consumerir_device *dev, int carrier_freq, 66 | const int pattern[], int pattern_len); 67 | 68 | /* 69 | * (*get_num_carrier_freqs)() is called by the ConsumerIrService to get the 70 | * number of carrier freqs to allocate space for, which is then filled by 71 | * a subsequent call to (*get_carrier_freqs)(). 72 | * 73 | * returns: the number of ranges on success. A negative error code on error. 74 | */ 75 | int (*get_num_carrier_freqs)(struct consumerir_device *dev); 76 | 77 | /* 78 | * (*get_carrier_freqs)() is called by the ConsumerIrService to enumerate 79 | * which frequencies the IR transmitter supports. The HAL implementation 80 | * should fill an array of consumerir_freq_range structs with the 81 | * appropriate values for the transmitter, up to len elements. 82 | * 83 | * returns: the number of ranges on success. A negative error code on error. 84 | */ 85 | int (*get_carrier_freqs)(struct consumerir_device *dev, 86 | size_t len, consumerir_freq_range_t *ranges); 87 | 88 | /* Reserved for future use. Must be NULL. */ 89 | void* reserved[8 - 3]; 90 | } consumerir_device_t; 91 | 92 | #endif /* ANDROID_INCLUDE_HARDWARE_CONSUMERIR_H */ 93 | -------------------------------------------------------------------------------- /include/hardware/display_defs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. 2 | * 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions are 5 | * met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above 9 | * copyright notice, this list of conditions and the following 10 | * disclaimer in the documentation and/or other materials provided 11 | * with the distribution. 12 | * * Neither the name of The Linux Foundation nor the names of its 13 | * contributors may be used to endorse or promote products derived 14 | * from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef ANDROID_INCLUDE_DISPLAY_DEFS_H 30 | #define ANDROID_INCLUDE_DISPLAY_DEFS_H 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | __BEGIN_DECLS 38 | 39 | /* Will need to update below enums if hwcomposer_defs.h is updated */ 40 | 41 | /* Extended events for hwc_methods::eventControl() */ 42 | enum { 43 | HWC_EVENT_ORIENTATION = HWC_EVENT_VSYNC + 1 44 | }; 45 | 46 | 47 | /* Extended hwc_layer_t::compositionType values */ 48 | enum { 49 | /* this layer will be handled in the HWC, using a blit engine */ 50 | HWC_BLIT = 0xFF 51 | }; 52 | 53 | /* Extended hwc_layer_t::flags values 54 | * Flags are set by SurfaceFlinger and read by the HAL 55 | */ 56 | enum { 57 | /* 58 | * HWC_SCREENSHOT_ANIMATOR_LAYER is set by surfaceflinger to indicate 59 | * that this layer is a screenshot animating layer. HWC uses this 60 | * info to disable rotation animation on External Display 61 | */ 62 | HWC_SCREENSHOT_ANIMATOR_LAYER = 0x00000004 63 | }; 64 | 65 | /* This enum represents different types of 3D mode supported. This definition 66 | * is maintained by HWC and exposed to its clients. 67 | */ 68 | enum { 69 | HWC_S3DMODE_NONE = 0, 70 | HWC_S3DMODE_LR, 71 | HWC_S3DMODE_RL, 72 | HWC_S3DMODE_TB, 73 | HWC_S3DMODE_FP, 74 | HWC_S3DMODE_MAX, 75 | }; 76 | 77 | __END_DECLS 78 | 79 | #endif /* ANDROID_INCLUDE_DISPLAY_DEFS_H*/ 80 | -------------------------------------------------------------------------------- /include/hardware/gps_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_INCLUDE_HARDWARE_GPS_INTERNAL_H 18 | #define ANDROID_INCLUDE_HARDWARE_GPS_INTERNAL_H 19 | 20 | #include "hardware/gps.h" 21 | 22 | /**************************************************************************** 23 | * This file contains legacy structs that are deprecated/retired from gps.h * 24 | ****************************************************************************/ 25 | 26 | __BEGIN_DECLS 27 | 28 | /** 29 | * Legacy GPS callback structure. 30 | * Deprecated, to be removed in the next Android release. 31 | * Use GpsCallbacks instead. 32 | */ 33 | typedef struct { 34 | /** set to sizeof(GpsCallbacks_v1) */ 35 | size_t size; 36 | gps_location_callback location_cb; 37 | gps_status_callback status_cb; 38 | gps_sv_status_callback sv_status_cb; 39 | gps_nmea_callback nmea_cb; 40 | gps_set_capabilities set_capabilities_cb; 41 | gps_acquire_wakelock acquire_wakelock_cb; 42 | gps_release_wakelock release_wakelock_cb; 43 | gps_create_thread create_thread_cb; 44 | gps_request_utc_time request_utc_time_cb; 45 | } GpsCallbacks_v1; 46 | 47 | #pragma pack(push,4) 48 | // We need to keep the alignment of this data structure to 4-bytes, to ensure that in 64-bit 49 | // environments the size of this legacy definition does not collide with _v2. Implementations should 50 | // be using _v2 and _v3, so it's OK to pay the 'unaligned' penalty in 64-bit if an old 51 | // implementation is still in use. 52 | 53 | /** 54 | * Legacy struct to represent the status of AGPS. 55 | */ 56 | typedef struct { 57 | /** set to sizeof(AGpsStatus_v1) */ 58 | size_t size; 59 | AGpsType type; 60 | AGpsStatusValue status; 61 | } AGpsStatus_v1; 62 | 63 | #pragma pack(pop) 64 | 65 | /** 66 | * Legacy struct to represent the status of AGPS augmented with a IPv4 address 67 | * field. 68 | */ 69 | typedef struct { 70 | /** set to sizeof(AGpsStatus_v2) */ 71 | size_t size; 72 | AGpsType type; 73 | AGpsStatusValue status; 74 | 75 | /*-------------------- New fields in _v2 --------------------*/ 76 | 77 | uint32_t ipaddr; 78 | } AGpsStatus_v2; 79 | 80 | /** 81 | * Legacy extended interface for AGPS support. 82 | * See AGpsInterface_v2 for more information. 83 | */ 84 | typedef struct { 85 | /** set to sizeof(AGpsInterface_v1) */ 86 | size_t size; 87 | void (*init)( AGpsCallbacks* callbacks ); 88 | int (*data_conn_open)( const char* apn ); 89 | int (*data_conn_closed)(); 90 | int (*data_conn_failed)(); 91 | int (*set_server)( AGpsType type, const char* hostname, int port ); 92 | } AGpsInterface_v1; 93 | 94 | __END_DECLS 95 | 96 | #endif /* ANDROID_INCLUDE_HARDWARE_GPS_INTERNAL_H */ 97 | -------------------------------------------------------------------------------- /include/hardware/hw_auth_token.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #ifndef ANDROID_HARDWARE_HW_AUTH_TOKEN_H 20 | #define ANDROID_HARDWARE_HW_AUTH_TOKEN_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif // __cplusplus 25 | 26 | const uint8_t HW_AUTH_TOKEN_VERSION = 0; 27 | 28 | typedef enum { 29 | HW_AUTH_NONE = 0, 30 | HW_AUTH_PASSWORD = 1 << 0, 31 | HW_AUTH_FINGERPRINT = 1 << 1, 32 | // Additional entries should be powers of 2. 33 | HW_AUTH_ANY = UINT32_MAX, 34 | } hw_authenticator_type_t; 35 | 36 | /** 37 | * Data format for an authentication record used to prove successful authentication. 38 | */ 39 | typedef struct __attribute__((__packed__)) { 40 | uint8_t version; // Current version is 0 41 | uint64_t challenge; 42 | uint64_t user_id; // secure user ID, not Android user ID 43 | uint64_t authenticator_id; // secure authenticator ID 44 | uint32_t authenticator_type; // hw_authenticator_type_t, in network order 45 | uint64_t timestamp; // in network order 46 | uint8_t hmac[32]; 47 | } hw_auth_token_t; 48 | 49 | #ifdef __cplusplus 50 | } // extern "C" 51 | #endif // __cplusplus 52 | 53 | #endif // ANDROID_HARDWARE_HW_AUTH_TOKEN_H 54 | -------------------------------------------------------------------------------- /include/hardware/local_time_hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #ifndef ANDROID_LOCAL_TIME_HAL_INTERFACE_H 19 | #define ANDROID_LOCAL_TIME_HAL_INTERFACE_H 20 | 21 | #include 22 | 23 | #include 24 | 25 | __BEGIN_DECLS 26 | 27 | /** 28 | * The id of this module 29 | */ 30 | #define LOCAL_TIME_HARDWARE_MODULE_ID "local_time" 31 | 32 | /** 33 | * Name of the local time devices to open 34 | */ 35 | #define LOCAL_TIME_HARDWARE_INTERFACE "local_time_hw_if" 36 | 37 | /**********************************************************************/ 38 | 39 | /** 40 | * A structure used to collect low level sync data in a lab environment. Most 41 | * HAL implementations will never need this structure. 42 | */ 43 | struct local_time_debug_event { 44 | int64_t local_timesync_event_id; 45 | int64_t local_time; 46 | }; 47 | 48 | /** 49 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 50 | * and the fields of this data structure must begin with hw_module_t 51 | * followed by module specific information. 52 | */ 53 | struct local_time_module { 54 | struct hw_module_t common; 55 | }; 56 | 57 | struct local_time_hw_device { 58 | /** 59 | * Common methods of the local time hardware device. This *must* be the first member of 60 | * local_time_hw_device as users of this structure will cast a hw_device_t to 61 | * local_time_hw_device pointer in contexts where it's known the hw_device_t references a 62 | * local_time_hw_device. 63 | */ 64 | struct hw_device_t common; 65 | 66 | /** 67 | * 68 | * Returns the current value of the system wide local time counter 69 | */ 70 | int64_t (*get_local_time)(struct local_time_hw_device* dev); 71 | 72 | /** 73 | * 74 | * Returns the nominal frequency (in hertz) of the system wide local time 75 | * counter 76 | */ 77 | uint64_t (*get_local_freq)(struct local_time_hw_device* dev); 78 | 79 | /** 80 | * 81 | * Sets the HW slew rate of oscillator which drives the system wide local 82 | * time counter. On success, platforms should return 0. Platforms which 83 | * do not support HW slew should leave this method set to NULL. 84 | * 85 | * Valid values for rate range from MIN_INT16 to MAX_INT16. Platform 86 | * implementations should attempt map this range linearly to the min/max 87 | * slew rate of their hardware. 88 | */ 89 | int (*set_local_slew)(struct local_time_hw_device* dev, int16_t rate); 90 | 91 | /** 92 | * 93 | * A method used to collect low level sync data in a lab environments. 94 | * Most HAL implementations will simply set this member to NULL, or return 95 | * -EINVAL to indicate that this functionality is not supported. 96 | * Production HALs should never support this method. 97 | */ 98 | int (*get_debug_log)(struct local_time_hw_device* dev, 99 | struct local_time_debug_event* records, 100 | int max_records); 101 | }; 102 | 103 | typedef struct local_time_hw_device local_time_hw_device_t; 104 | 105 | /** convenience API for opening and closing a supported device */ 106 | 107 | static inline int local_time_hw_device_open( 108 | const struct hw_module_t* module, 109 | struct local_time_hw_device** device) 110 | { 111 | return module->methods->open(module, LOCAL_TIME_HARDWARE_INTERFACE, 112 | (struct hw_device_t**)device); 113 | } 114 | 115 | static inline int local_time_hw_device_close(struct local_time_hw_device* device) 116 | { 117 | return device->common.close(&device->common); 118 | } 119 | 120 | 121 | __END_DECLS 122 | 123 | #endif // ANDROID_LOCAL_TIME_INTERFACE_H 124 | -------------------------------------------------------------------------------- /include/hardware/nfc_tag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_NFC_TAG_HAL_INTERFACE_H 18 | #define ANDROID_NFC_TAG_HAL_INTERFACE_H 19 | 20 | #include 21 | 22 | #include 23 | 24 | __BEGIN_DECLS 25 | 26 | /* 27 | * HAL for programmable NFC tags. 28 | * 29 | */ 30 | 31 | #define NFC_TAG_HARDWARE_MODULE_ID "nfc_tag" 32 | #define NFC_TAG_ID "tag" 33 | 34 | typedef struct nfc_tag_module_t { 35 | /** 36 | * Common methods of the NFC tag module. This *must* be the first member of 37 | * nfc_tag_module_t as users of this structure will cast a hw_module_t to 38 | * nfc_tag_module_t pointer in contexts where it's known the hw_module_t references a 39 | * nfc_tag_module_t. 40 | */ 41 | struct hw_module_t common; 42 | } nfc_tag_module_t; 43 | 44 | typedef struct nfc_tag_device { 45 | /** 46 | * Common methods of the NFC tag device. This *must* be the first member of 47 | * nfc_tag_device_t as users of this structure will cast a hw_device_t to 48 | * nfc_tag_device_t pointer in contexts where it's known the hw_device_t references a 49 | * nfc_tag_device_t. 50 | */ 51 | struct hw_device_t common; 52 | 53 | /** 54 | * Initialize the NFC tag. 55 | * 56 | * The driver must: 57 | * * Set the static lock bytes to read only 58 | * * Configure the Capability Container to disable write acess 59 | * eg: 0xE1 0x10 0x0F 60 | * 61 | * This function is called once before any calls to setContent(). 62 | * 63 | * Return 0 on success or -errno on error. 64 | */ 65 | int (*init)(const struct nfc_tag_device *dev); 66 | 67 | /** 68 | * Set the NFC tag content. 69 | * 70 | * The driver must write in the data area of the tag starting at 71 | * byte 0 of block 4 and zero the rest of the data area. 72 | * 73 | * Returns 0 on success or -errno on error. 74 | */ 75 | int (*setContent)(const struct nfc_tag_device *dev, const uint8_t *data, size_t len); 76 | 77 | /** 78 | * Returns the memory size of the data area. 79 | */ 80 | int (*getMemorySize)(const struct nfc_tag_device *dev); 81 | } nfc_tag_device_t; 82 | 83 | static inline int nfc_tag_open(const struct hw_module_t* module, 84 | nfc_tag_device_t** dev) { 85 | return module->methods->open(module, NFC_TAG_ID, 86 | (struct hw_device_t**)dev); 87 | } 88 | 89 | static inline int nfc_tag_close(nfc_tag_device_t* dev) { 90 | return dev->common.close(&dev->common); 91 | } 92 | 93 | __END_DECLS 94 | 95 | #endif // ANDROID_NFC_TAG_HAL_INTERFACE_H 96 | -------------------------------------------------------------------------------- /include/hardware/qemu_pipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H 17 | #define ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include /* for pthread_once() */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #ifndef D 30 | # define D(...) do{}while(0) 31 | #endif 32 | 33 | /* Try to open a new Qemu fast-pipe. This function returns a file descriptor 34 | * that can be used to communicate with a named service managed by the 35 | * emulator. 36 | * 37 | * This file descriptor can be used as a standard pipe/socket descriptor. 38 | * 39 | * 'pipeName' is the name of the emulator service you want to connect to. 40 | * E.g. 'opengles' or 'camera'. 41 | * 42 | * On success, return a valid file descriptor 43 | * Returns -1 on error, and errno gives the error code, e.g.: 44 | * 45 | * EINVAL -> unknown/unsupported pipeName 46 | * ENOSYS -> fast pipes not available in this system. 47 | * 48 | * ENOSYS should never happen, except if you're trying to run within a 49 | * misconfigured emulator. 50 | * 51 | * You should be able to open several pipes to the same pipe service, 52 | * except for a few special cases (e.g. GSM modem), where EBUSY will be 53 | * returned if more than one client tries to connect to it. 54 | */ 55 | static __inline__ int 56 | qemu_pipe_open(const char* pipeName) 57 | { 58 | char buff[256]; 59 | int buffLen; 60 | int fd, ret; 61 | 62 | if (pipeName == NULL || pipeName[0] == '\0') { 63 | errno = EINVAL; 64 | return -1; 65 | } 66 | 67 | snprintf(buff, sizeof buff, "pipe:%s", pipeName); 68 | 69 | fd = open("/dev/qemu_pipe", O_RDWR); 70 | if (fd < 0 && errno == ENOENT) 71 | fd = open("/dev/goldfish_pipe", O_RDWR); 72 | if (fd < 0) { 73 | D("%s: Could not open /dev/qemu_pipe: %s", __FUNCTION__, strerror(errno)); 74 | //errno = ENOSYS; 75 | return -1; 76 | } 77 | 78 | buffLen = strlen(buff); 79 | 80 | ret = TEMP_FAILURE_RETRY(write(fd, buff, buffLen+1)); 81 | if (ret != buffLen+1) { 82 | D("%s: Could not connect to %s pipe service: %s", __FUNCTION__, pipeName, strerror(errno)); 83 | if (ret == 0) { 84 | errno = ECONNRESET; 85 | } else if (ret > 0) { 86 | errno = EINVAL; 87 | } 88 | return -1; 89 | } 90 | 91 | return fd; 92 | } 93 | 94 | #endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_PIPE_H */ 95 | -------------------------------------------------------------------------------- /include/hardware/vibrator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _HARDWARE_VIBRATOR_H 18 | #define _HARDWARE_VIBRATOR_H 19 | 20 | #include 21 | 22 | __BEGIN_DECLS 23 | 24 | #define VIBRATOR_API_VERSION HARDWARE_MODULE_API_VERSION(1,0) 25 | 26 | /** 27 | * The id of this module 28 | */ 29 | #define VIBRATOR_HARDWARE_MODULE_ID "vibrator" 30 | 31 | /** 32 | * The id of the main vibrator device 33 | */ 34 | #define VIBRATOR_DEVICE_ID_MAIN "main_vibrator" 35 | 36 | struct vibrator_device; 37 | typedef struct vibrator_device { 38 | /** 39 | * Common methods of the vibrator device. This *must* be the first member of 40 | * vibrator_device as users of this structure will cast a hw_device_t to 41 | * vibrator_device pointer in contexts where it's known the hw_device_t references a 42 | * vibrator_device. 43 | */ 44 | struct hw_device_t common; 45 | 46 | /** Turn on vibrator 47 | * 48 | * This function must only be called after the previous timeout has expired or 49 | * was canceled (through vibrator_off()). 50 | * 51 | * @param timeout_ms number of milliseconds to vibrate 52 | * 53 | * @return 0 in case of success, negative errno code else 54 | */ 55 | int (*vibrator_on)(struct vibrator_device* vibradev, unsigned int timeout_ms); 56 | 57 | /** Turn off vibrator 58 | * 59 | * Cancel a previously-started vibration, if any. 60 | * 61 | * @return 0 in case of success, negative errno code else 62 | */ 63 | int (*vibrator_off)(struct vibrator_device* vibradev); 64 | } vibrator_device_t; 65 | 66 | static inline int vibrator_open(const struct hw_module_t* module, vibrator_device_t** device) 67 | { 68 | return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, (struct hw_device_t**)device); 69 | } 70 | 71 | __END_DECLS 72 | 73 | #endif // _HARDWARE_VIBRATOR_H 74 | -------------------------------------------------------------------------------- /modules/Android.mk: -------------------------------------------------------------------------------- 1 | hardware_modules := gralloc hwcomposer audio nfc nfc-nci local_time \ 2 | power usbaudio audio_remote_submix camera usbcamera consumerir sensors vibrator \ 3 | tv_input fingerprint input vehicle thermal vr 4 | include $(call all-named-subdir-makefiles,$(hardware_modules)) 5 | -------------------------------------------------------------------------------- /modules/README.android: -------------------------------------------------------------------------------- 1 | Default (and possibly architecture dependents) HAL modules go here. 2 | 3 | 4 | libhardware.so eventually should contain *just* the HAL hub 5 | (hardware.c), everything in it should be rewritten as modules. 6 | 7 | Modules are .so in /system/libs/hw/ and have a well defined naming 8 | convention: 9 | 10 | /system/libs/hw/<*_HARDWARE_MODULE_ID>..so 11 | /system/libs/hw/<*_HARDWARE_MODULE_ID>..so 12 | /system/libs/hw/<*_HARDWARE_MODULE_ID>..so 13 | /system/libs/hw/<*_HARDWARE_MODULE_ID>.default.so 14 | 15 | They also have a well defined interface which lives in include/hardware/. 16 | 17 | A module can have several variants: "default", "arch" and "board", and they're 18 | loaded in the "board", "arch" and "default" order. 19 | The source code for the "board" variant, usually lives under partners/... 20 | 21 | The source code for "default" and "arch" would usually 22 | live under hardware/modules/. 23 | 24 | -------------------------------------------------------------------------------- /modules/audio/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2011 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | # The default audio HAL module, which is a stub, that is loaded if no other 18 | # device specific modules are present. The exact load order can be seen in 19 | # libhardware/hardware.c 20 | # 21 | # The format of the name is audio...so where the only 22 | # required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc. 23 | include $(CLEAR_VARS) 24 | 25 | LOCAL_MODULE := audio.primary.default 26 | LOCAL_MODULE_RELATIVE_PATH := hw 27 | LOCAL_SRC_FILES := audio_hw.c 28 | LOCAL_SHARED_LIBRARIES := liblog libcutils 29 | LOCAL_MODULE_TAGS := optional 30 | LOCAL_CFLAGS := -Wno-unused-parameter 31 | 32 | include $(BUILD_SHARED_LIBRARY) 33 | 34 | # The stub audio HAL module, identical to the default audio hal, but with 35 | # different name to be loaded concurrently with other audio HALs if necessary. 36 | # This can also be used as skeleton for new implementations 37 | # 38 | # The format of the name is audio...so where the only 39 | # required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc. 40 | include $(CLEAR_VARS) 41 | 42 | LOCAL_MODULE := audio.stub.default 43 | LOCAL_MODULE_RELATIVE_PATH := hw 44 | LOCAL_SRC_FILES := audio_hw.c 45 | LOCAL_SHARED_LIBRARIES := liblog libcutils 46 | LOCAL_MODULE_TAGS := optional 47 | LOCAL_CFLAGS := -Wno-unused-parameter 48 | 49 | include $(BUILD_SHARED_LIBRARY) 50 | 51 | # The stub audio policy HAL module that can be used as a skeleton for 52 | # new implementations. 53 | include $(CLEAR_VARS) 54 | 55 | LOCAL_MODULE := audio_policy.stub 56 | LOCAL_MODULE_RELATIVE_PATH := hw 57 | LOCAL_SRC_FILES := audio_policy.c 58 | LOCAL_SHARED_LIBRARIES := liblog libcutils 59 | LOCAL_MODULE_TAGS := optional 60 | LOCAL_CFLAGS := -Wno-unused-parameter 61 | 62 | include $(BUILD_SHARED_LIBRARY) 63 | 64 | # The stub audio amplifier HAL module that can be used as a skeleton for 65 | # new implementations. 66 | include $(CLEAR_VARS) 67 | 68 | LOCAL_MODULE := audio_amplifier.default 69 | LOCAL_MODULE_RELATIVE_PATH := hw 70 | LOCAL_SRC_FILES := audio_amplifier.c 71 | LOCAL_SHARED_LIBRARIES := liblog libcutils 72 | LOCAL_MODULE_TAGS := optional 73 | LOCAL_CFLAGS := -Wno-unused-parameter 74 | 75 | include $(BUILD_SHARED_LIBRARY) 76 | -------------------------------------------------------------------------------- /modules/audio_remote_submix/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := audio.r_submix.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := \ 22 | audio_hw.cpp 23 | LOCAL_C_INCLUDES += \ 24 | frameworks/av/include/ \ 25 | frameworks/native/include/ 26 | LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libnbaio 27 | LOCAL_STATIC_LIBRARIES := libmedia_helper 28 | LOCAL_MODULE_TAGS := optional 29 | LOCAL_CFLAGS := -Wno-unused-parameter 30 | 31 | include $(BUILD_SHARED_LIBRARY) 32 | 33 | -------------------------------------------------------------------------------- /modules/camera/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := camera.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | 22 | LOCAL_C_INCLUDES += \ 23 | system/core/include \ 24 | system/media/camera/include \ 25 | 26 | LOCAL_SRC_FILES := \ 27 | CameraHAL.cpp \ 28 | Camera.cpp \ 29 | ExampleCamera.cpp \ 30 | Metadata.cpp \ 31 | Stream.cpp \ 32 | VendorTags.cpp \ 33 | 34 | LOCAL_SHARED_LIBRARIES := \ 35 | libcamera_metadata \ 36 | libcutils \ 37 | liblog \ 38 | libsync \ 39 | libutils \ 40 | 41 | LOCAL_CFLAGS += -Wall -Wextra -fvisibility=hidden 42 | 43 | LOCAL_MODULE_TAGS := optional 44 | 45 | include $(BUILD_SHARED_LIBRARY) 46 | -------------------------------------------------------------------------------- /modules/camera/CameraHAL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef CAMERA_HAL_H_ 18 | #define CAMERA_HAL_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "Camera.h" 25 | #include "VendorTags.h" 26 | 27 | namespace default_camera_hal { 28 | // CameraHAL contains all module state that isn't specific to an individual 29 | // camera device. 30 | class CameraHAL { 31 | public: 32 | CameraHAL(int num_cameras); 33 | ~CameraHAL(); 34 | 35 | // Camera Module Interface (see ) 36 | int getNumberOfCameras(); 37 | int getCameraInfo(int camera_id, struct camera_info *info); 38 | int setCallbacks(const camera_module_callbacks_t *callbacks); 39 | void getVendorTagOps(vendor_tag_ops_t* ops); 40 | 41 | // Hardware Module Interface (see ) 42 | int open(const hw_module_t* mod, const char* name, hw_device_t** dev); 43 | 44 | private: 45 | // Number of cameras 46 | const int mNumberOfCameras; 47 | // Callback handle 48 | const camera_module_callbacks_t *mCallbacks; 49 | // Array of camera devices, contains mNumberOfCameras device pointers 50 | Camera **mCameras; 51 | }; 52 | } // namespace default_camera_hal 53 | 54 | #endif // CAMERA_HAL_H_ 55 | -------------------------------------------------------------------------------- /modules/camera/ExampleCamera.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef EXAMPLE_CAMERA_H_ 18 | #define EXAMPLE_CAMERA_H_ 19 | 20 | #include 21 | #include "Camera.h" 22 | 23 | namespace default_camera_hal { 24 | // ExampleCamera is an example for a specific camera device. The Camera object 25 | // contains all logic common between all cameras (e.g. front and back cameras), 26 | // while a specific camera device (e.g. ExampleCamera) holds all specific 27 | // metadata and logic about that device. 28 | class ExampleCamera : public Camera { 29 | public: 30 | ExampleCamera(int id); 31 | ~ExampleCamera(); 32 | 33 | private: 34 | // Initialize static camera characteristics for individual device 35 | camera_metadata_t *initStaticInfo(); 36 | // Initialize whole device (templates/etc) when opened 37 | int initDevice(); 38 | // Initialize each template metadata controls 39 | int setPreviewTemplate(Metadata m); 40 | int setStillTemplate(Metadata m); 41 | int setRecordTemplate(Metadata m); 42 | int setSnapshotTemplate(Metadata m); 43 | int setZslTemplate(Metadata m); 44 | // Verify settings are valid for a capture with this device 45 | bool isValidCaptureSettings(const camera_metadata_t* settings); 46 | }; 47 | } // namespace default_camera_hal 48 | 49 | #endif // CAMERA_H_ 50 | -------------------------------------------------------------------------------- /modules/camera/Metadata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef METADATA_H_ 18 | #define METADATA_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace default_camera_hal { 25 | // Metadata is a convenience class for dealing with libcamera_metadata 26 | class Metadata { 27 | public: 28 | Metadata(); 29 | ~Metadata(); 30 | // Initialize with framework metadata 31 | int init(const camera_metadata_t *metadata); 32 | 33 | // Parse and add an entry. Allocates and copies new storage for *data. 34 | int addUInt8(uint32_t tag, int count, const uint8_t *data); 35 | int add1UInt8(uint32_t tag, const uint8_t data); 36 | int addInt32(uint32_t tag, int count, const int32_t *data); 37 | int addFloat(uint32_t tag, int count, const float *data); 38 | int addInt64(uint32_t tag, int count, const int64_t *data); 39 | int addDouble(uint32_t tag, int count, const double *data); 40 | int addRational(uint32_t tag, int count, 41 | const camera_metadata_rational_t *data); 42 | 43 | // Get a handle to the current metadata 44 | // This is not a durable handle, and may be destroyed by add*/init 45 | camera_metadata_t* get(); 46 | 47 | private: 48 | // Actual internal storage 49 | camera_metadata_t* mData; 50 | // Destroy old metadata and replace with new 51 | void replace(camera_metadata_t *m); 52 | // Validate the tag, type and count for a metadata entry 53 | bool validate(uint32_t tag, int tag_type, int count); 54 | // Add a verified tag with data 55 | int add(uint32_t tag, int count, const void *tag_data); 56 | }; 57 | } // namespace default_camera_hal 58 | 59 | #endif // METADATA_H_ 60 | -------------------------------------------------------------------------------- /modules/camera/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef STREAM_H_ 18 | #define STREAM_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace default_camera_hal { 26 | // Stream represents a single input or output stream for a camera device. 27 | class Stream { 28 | public: 29 | Stream(int id, camera3_stream_t *s); 30 | ~Stream(); 31 | 32 | // validate that astream's parameters match this stream's parameters 33 | bool isValidReuseStream(int id, camera3_stream_t *s); 34 | 35 | // Register buffers with hardware 36 | int registerBuffers(const camera3_stream_buffer_set_t *buf_set); 37 | 38 | void setUsage(uint32_t usage); 39 | void setMaxBuffers(uint32_t max_buffers); 40 | 41 | int getType(); 42 | bool isInputType(); 43 | bool isOutputType(); 44 | bool isRegistered(); 45 | const char* typeToString(int type); 46 | const char* formatToString(int format); 47 | void dump(int fd); 48 | 49 | // This stream is being reused. Used in stream configuration passes 50 | bool mReuse; 51 | 52 | private: 53 | // Clean up buffer state. must be called with mLock held. 54 | void unregisterBuffers_L(); 55 | 56 | // The camera device id this stream belongs to 57 | const int mId; 58 | // Handle to framework's stream, used as a cookie for buffers 59 | camera3_stream_t *mStream; 60 | // Stream type: CAMERA3_STREAM_* (see ) 61 | const int mType; 62 | // Width in pixels of the buffers in this stream 63 | const uint32_t mWidth; 64 | // Height in pixels of the buffers in this stream 65 | const uint32_t mHeight; 66 | // Gralloc format: HAL_PIXEL_FORMAT_* (see ) 67 | const int mFormat; 68 | // Gralloc usage mask : GRALLOC_USAGE_* (see ) 69 | uint32_t mUsage; 70 | // Max simultaneous in-flight buffers for this stream 71 | uint32_t mMaxBuffers; 72 | // Buffers have been registered for this stream and are ready 73 | bool mRegistered; 74 | // Array of handles to buffers currently in use by the stream 75 | buffer_handle_t **mBuffers; 76 | // Number of buffers in mBuffers 77 | unsigned int mNumBuffers; 78 | // Lock protecting the Stream object for modifications 79 | android::Mutex mLock; 80 | }; 81 | } // namespace default_camera_hal 82 | 83 | #endif // STREAM_H_ 84 | -------------------------------------------------------------------------------- /modules/camera/VendorTags.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef VENDOR_TAGS_H_ 18 | #define VENDOR_TAGS_H_ 19 | 20 | #include 21 | #include 22 | 23 | namespace default_camera_hal { 24 | 25 | // VendorTags contains all vendor-specific metadata tag functionality 26 | class VendorTags { 27 | public: 28 | VendorTags(); 29 | ~VendorTags(); 30 | 31 | // Vendor Tags Operations (see ) 32 | int getTagCount(const vendor_tag_ops_t* ops); 33 | void getAllTags(const vendor_tag_ops_t* ops, uint32_t* tag_array); 34 | const char* getSectionName(const vendor_tag_ops_t* ops, uint32_t tag); 35 | const char* getTagName(const vendor_tag_ops_t* ops, uint32_t tag); 36 | int getTagType(const vendor_tag_ops_t* ops, uint32_t tag); 37 | 38 | private: 39 | // Total number of vendor tags 40 | int mTagCount; 41 | }; 42 | 43 | // Tag sections start at the beginning of vendor tags (0x8000_0000) 44 | // See 45 | enum { 46 | DEMO_WIZARDRY, 47 | DEMO_SORCERY, 48 | DEMO_MAGIC, 49 | DEMO_SECTION_COUNT 50 | }; 51 | 52 | const uint32_t vendor_section_start = VENDOR_SECTION_START; 53 | 54 | // Each section starts at increments of 0x1_0000 55 | const uint32_t demo_wizardry_start = (DEMO_WIZARDRY + VENDOR_SECTION) << 16; 56 | const uint32_t demo_sorcery_start = (DEMO_SORCERY + VENDOR_SECTION) << 16; 57 | const uint32_t demo_magic_start = (DEMO_MAGIC + VENDOR_SECTION) << 16; 58 | 59 | // Vendor Tag values, start value begins each section 60 | const uint32_t demo_wizardry_dimension_size = demo_wizardry_start; 61 | const uint32_t demo_wizardry_dimensions = demo_wizardry_start + 1; 62 | const uint32_t demo_wizardry_familiar = demo_wizardry_start + 2; 63 | const uint32_t demo_wizardry_fire = demo_wizardry_start + 3; 64 | const uint32_t demo_wizardry_end = demo_wizardry_start + 4; 65 | 66 | const uint32_t demo_sorcery_difficulty = demo_sorcery_start; 67 | const uint32_t demo_sorcery_light = demo_sorcery_start + 1; 68 | const uint32_t demo_sorcery_end = demo_sorcery_start + 2; 69 | 70 | const uint32_t demo_magic_card_trick = demo_magic_start; 71 | const uint32_t demo_magic_levitation = demo_magic_start + 1; 72 | const uint32_t demo_magic_end = demo_magic_start + 2; 73 | 74 | } // namespace default_camera_hal 75 | 76 | #endif // VENDOR_TAGS_H_ 77 | -------------------------------------------------------------------------------- /modules/consumerir/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2013 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := consumerir.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := consumerir.c 22 | LOCAL_SHARED_LIBRARIES := liblog libcutils 23 | LOCAL_MODULE_TAGS := optional 24 | 25 | include $(BUILD_SHARED_LIBRARY) 26 | -------------------------------------------------------------------------------- /modules/consumerir/consumerir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #define LOG_TAG "ConsumerIrHal" 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 26 | 27 | static const consumerir_freq_range_t consumerir_freqs[] = { 28 | {.min = 30000, .max = 30000}, 29 | {.min = 33000, .max = 33000}, 30 | {.min = 36000, .max = 36000}, 31 | {.min = 38000, .max = 38000}, 32 | {.min = 40000, .max = 40000}, 33 | {.min = 56000, .max = 56000}, 34 | }; 35 | 36 | static int consumerir_transmit(struct consumerir_device *dev __unused, 37 | int carrier_freq, const int pattern[], int pattern_len) 38 | { 39 | int total_time = 0; 40 | long i; 41 | 42 | for (i = 0; i < pattern_len; i++) 43 | total_time += pattern[i]; 44 | 45 | /* simulate the time spent transmitting by sleeping */ 46 | ALOGD("transmit for %d uS at %d Hz", total_time, carrier_freq); 47 | usleep(total_time); 48 | 49 | return 0; 50 | } 51 | 52 | static int consumerir_get_num_carrier_freqs(struct consumerir_device *dev __unused) 53 | { 54 | return ARRAY_SIZE(consumerir_freqs); 55 | } 56 | 57 | static int consumerir_get_carrier_freqs(struct consumerir_device *dev __unused, 58 | size_t len, consumerir_freq_range_t *ranges) 59 | { 60 | size_t to_copy = ARRAY_SIZE(consumerir_freqs); 61 | 62 | to_copy = len < to_copy ? len : to_copy; 63 | memcpy(ranges, consumerir_freqs, to_copy * sizeof(consumerir_freq_range_t)); 64 | return to_copy; 65 | } 66 | 67 | static int consumerir_close(hw_device_t *dev) 68 | { 69 | free(dev); 70 | return 0; 71 | } 72 | 73 | /* 74 | * Generic device handling 75 | */ 76 | static int consumerir_open(const hw_module_t* module, const char* name, 77 | hw_device_t** device) 78 | { 79 | if (strcmp(name, CONSUMERIR_TRANSMITTER) != 0) { 80 | return -EINVAL; 81 | } 82 | if (device == NULL) { 83 | ALOGE("NULL device on open"); 84 | return -EINVAL; 85 | } 86 | 87 | consumerir_device_t *dev = malloc(sizeof(consumerir_device_t)); 88 | memset(dev, 0, sizeof(consumerir_device_t)); 89 | 90 | dev->common.tag = HARDWARE_DEVICE_TAG; 91 | dev->common.version = 0; 92 | dev->common.module = (struct hw_module_t*) module; 93 | dev->common.close = consumerir_close; 94 | 95 | dev->transmit = consumerir_transmit; 96 | dev->get_num_carrier_freqs = consumerir_get_num_carrier_freqs; 97 | dev->get_carrier_freqs = consumerir_get_carrier_freqs; 98 | 99 | *device = (hw_device_t*) dev; 100 | return 0; 101 | } 102 | 103 | static struct hw_module_methods_t consumerir_module_methods = { 104 | .open = consumerir_open, 105 | }; 106 | 107 | consumerir_module_t HAL_MODULE_INFO_SYM = { 108 | .common = { 109 | .tag = HARDWARE_MODULE_TAG, 110 | .module_api_version = CONSUMERIR_MODULE_API_VERSION_1_0, 111 | .hal_api_version = HARDWARE_HAL_API_VERSION, 112 | .id = CONSUMERIR_HARDWARE_MODULE_ID, 113 | .name = "Demo IR HAL", 114 | .author = "The Android Open Source Project", 115 | .methods = &consumerir_module_methods, 116 | }, 117 | }; 118 | -------------------------------------------------------------------------------- /modules/fingerprint/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2013 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := fingerprint.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := fingerprint.c 22 | LOCAL_SHARED_LIBRARIES := liblog 23 | LOCAL_MODULE_TAGS := optional 24 | 25 | include $(BUILD_SHARED_LIBRARY) 26 | -------------------------------------------------------------------------------- /modules/gralloc/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | LOCAL_PATH := $(call my-dir) 17 | 18 | # HAL module implemenation stored in 19 | # hw/..so 20 | include $(CLEAR_VARS) 21 | 22 | LOCAL_MODULE_RELATIVE_PATH := hw 23 | LOCAL_SHARED_LIBRARIES := liblog libcutils 24 | 25 | LOCAL_SRC_FILES := \ 26 | gralloc.cpp \ 27 | framebuffer.cpp \ 28 | mapper.cpp 29 | 30 | LOCAL_MODULE := gralloc.default 31 | LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\" -Wno-missing-field-initializers 32 | ifeq ($(TARGET_USE_PAN_DISPLAY),true) 33 | LOCAL_CFLAGS += -DUSE_PAN_DISPLAY=1 34 | endif 35 | 36 | include $(BUILD_SHARED_LIBRARY) 37 | -------------------------------------------------------------------------------- /modules/gralloc/gr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef GR_H_ 18 | #define GR_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | /*****************************************************************************/ 31 | 32 | struct private_module_t; 33 | struct private_handle_t; 34 | 35 | inline size_t roundUpToPageSize(size_t x) { 36 | return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); 37 | } 38 | 39 | int mapFrameBufferLocked(struct private_module_t* module); 40 | int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd); 41 | int mapBuffer(gralloc_module_t const* module, private_handle_t* hnd); 42 | 43 | /*****************************************************************************/ 44 | 45 | class Locker { 46 | pthread_mutex_t mutex; 47 | public: 48 | class Autolock { 49 | Locker& locker; 50 | public: 51 | inline Autolock(Locker& locker) : locker(locker) { locker.lock(); } 52 | inline ~Autolock() { locker.unlock(); } 53 | }; 54 | inline Locker() { pthread_mutex_init(&mutex, 0); } 55 | inline ~Locker() { pthread_mutex_destroy(&mutex); } 56 | inline void lock() { pthread_mutex_lock(&mutex); } 57 | inline void unlock() { pthread_mutex_unlock(&mutex); } 58 | }; 59 | 60 | #endif /* GR_H_ */ 61 | -------------------------------------------------------------------------------- /modules/gralloc/gralloc_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef GRALLOC_PRIV_H_ 18 | #define GRALLOC_PRIV_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | /*****************************************************************************/ 33 | 34 | struct private_module_t; 35 | struct private_handle_t; 36 | 37 | struct private_module_t { 38 | gralloc_module_t base; 39 | 40 | private_handle_t* framebuffer; 41 | uint32_t flags; 42 | uint32_t numBuffers; 43 | uint32_t bufferMask; 44 | pthread_mutex_t lock; 45 | buffer_handle_t currentBuffer; 46 | int pmem_master; 47 | void* pmem_master_base; 48 | 49 | struct fb_var_screeninfo info; 50 | struct fb_fix_screeninfo finfo; 51 | float xdpi; 52 | float ydpi; 53 | float fps; 54 | }; 55 | 56 | /*****************************************************************************/ 57 | 58 | #ifdef __cplusplus 59 | struct private_handle_t : public native_handle { 60 | #else 61 | struct private_handle_t { 62 | struct native_handle nativeHandle; 63 | #endif 64 | 65 | enum { 66 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001 67 | }; 68 | 69 | // file-descriptors 70 | int fd; 71 | // ints 72 | int magic; 73 | int flags; 74 | int size; 75 | int offset; 76 | 77 | // FIXME: the attributes below should be out-of-line 78 | uint64_t base __attribute__((aligned(8))); 79 | int pid; 80 | 81 | #ifdef __cplusplus 82 | static inline int sNumInts() { 83 | return (((sizeof(private_handle_t) - sizeof(native_handle_t))/sizeof(int)) - sNumFds); 84 | } 85 | static const int sNumFds = 1; 86 | static const int sMagic = 0x3141592; 87 | 88 | private_handle_t(int fd, int size, int flags) : 89 | fd(fd), magic(sMagic), flags(flags), size(size), offset(0), 90 | base(0), pid(getpid()) 91 | { 92 | version = sizeof(native_handle); 93 | numInts = sNumInts(); 94 | numFds = sNumFds; 95 | } 96 | ~private_handle_t() { 97 | magic = 0; 98 | } 99 | 100 | static int validate(const native_handle* h) { 101 | const private_handle_t* hnd = (const private_handle_t*)h; 102 | if (!h || h->version != sizeof(native_handle) || 103 | h->numInts != sNumInts() || h->numFds != sNumFds || 104 | hnd->magic != sMagic) 105 | { 106 | ALOGE("invalid gralloc handle (at %p)", h); 107 | return -EINVAL; 108 | } 109 | return 0; 110 | } 111 | #endif 112 | }; 113 | 114 | #endif /* GRALLOC_PRIV_H_ */ 115 | -------------------------------------------------------------------------------- /modules/hwcomposer/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | LOCAL_PATH := $(call my-dir) 17 | 18 | # HAL module implemenation stored in 19 | # hw/..so 20 | include $(CLEAR_VARS) 21 | 22 | LOCAL_MODULE_RELATIVE_PATH := hw 23 | LOCAL_SHARED_LIBRARIES := liblog libEGL 24 | LOCAL_SRC_FILES := hwcomposer.cpp 25 | LOCAL_MODULE := hwcomposer.default 26 | LOCAL_CFLAGS:= -DLOG_TAG=\"hwcomposer\" 27 | LOCAL_MODULE_TAGS := optional 28 | include $(BUILD_SHARED_LIBRARY) 29 | -------------------------------------------------------------------------------- /modules/hwcomposer/README.android: -------------------------------------------------------------------------------- 1 | 2 | Skeleton for the "hwcomposer" HAL module. 3 | 4 | -------------------------------------------------------------------------------- /modules/input/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | include $(call all-makefiles-under,$(LOCAL_PATH)) 20 | -------------------------------------------------------------------------------- /modules/input/evdev/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | # Evdev module implementation 18 | include $(CLEAR_VARS) 19 | 20 | LOCAL_SRC_FILES := \ 21 | BitUtils.cpp \ 22 | InputHub.cpp \ 23 | InputDevice.cpp \ 24 | InputDeviceManager.cpp \ 25 | InputHost.cpp \ 26 | InputMapper.cpp \ 27 | MouseInputMapper.cpp \ 28 | SwitchInputMapper.cpp 29 | 30 | LOCAL_SHARED_LIBRARIES := \ 31 | libhardware_legacy \ 32 | liblog \ 33 | libutils 34 | 35 | LOCAL_CLANG := true 36 | LOCAL_CPPFLAGS += -std=c++14 -Wno-unused-parameter 37 | 38 | LOCAL_MODULE := libinput_evdev 39 | LOCAL_MODULE_TAGS := optional 40 | 41 | include $(BUILD_SHARED_LIBRARY) 42 | 43 | # HAL module 44 | include $(CLEAR_VARS) 45 | 46 | LOCAL_MODULE := input.evdev.default 47 | LOCAL_MODULE_RELATIVE_PATH := hw 48 | 49 | LOCAL_SRC_FILES := \ 50 | EvdevModule.cpp 51 | 52 | LOCAL_SHARED_LIBRARIES := \ 53 | libinput_evdev \ 54 | liblog 55 | 56 | LOCAL_CLANG := true 57 | LOCAL_CPPFLAGS += -std=c++14 -Wno-unused-parameter 58 | 59 | LOCAL_MODULE_TAGS := optional 60 | 61 | include $(BUILD_SHARED_LIBRARY) 62 | -------------------------------------------------------------------------------- /modules/input/evdev/BitUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "BitUtils" 18 | //#define LOG_NDEBUG 0 19 | 20 | #include "BitUtils.h" 21 | 22 | #include 23 | 24 | // Enables debug output for hasKeyInRange 25 | #define DEBUG_KEY_RANGE 0 26 | 27 | namespace android { 28 | 29 | #if DEBUG_KEY_RANGE 30 | static const char* bitstrings[16] = { 31 | "0000", "0001", "0010", "0011", 32 | "0100", "0101", "0110", "0111", 33 | "1000", "1001", "1010", "1011", 34 | "1100", "1101", "1110", "1111", 35 | }; 36 | #endif 37 | 38 | bool testBitInRange(const uint8_t arr[], size_t start, size_t end) { 39 | #if DEBUG_KEY_RANGE 40 | ALOGD("testBitInRange(%d, %d)", start, end); 41 | #endif 42 | // Invalid range! This is nonsense; just say no. 43 | if (end <= start) return false; 44 | 45 | // Find byte array indices. The end is not included in the range, nor is 46 | // endIndex. Round up for endIndex. 47 | size_t startIndex = start / 8; 48 | size_t endIndex = (end + 7) / 8; 49 | #if DEBUG_KEY_RANGE 50 | ALOGD("startIndex=%d, endIndex=%d", startIndex, endIndex); 51 | #endif 52 | for (size_t i = startIndex; i < endIndex; ++i) { 53 | uint8_t bits = arr[i]; 54 | uint8_t mask = 0xff; 55 | #if DEBUG_KEY_RANGE 56 | ALOGD("block %04d: %s%s", i, bitstrings[bits >> 4], bitstrings[bits & 0x0f]); 57 | #endif 58 | if (bits) { 59 | // Mask off bits before our start bit 60 | if (i == startIndex) { 61 | mask &= 0xff << (start % 8); 62 | } 63 | // Mask off bits after our end bit 64 | if (i == endIndex - 1 && (end % 8)) { 65 | mask &= 0xff >> (8 - (end % 8)); 66 | } 67 | #if DEBUG_KEY_RANGE 68 | ALOGD("mask: %s%s", bitstrings[mask >> 4], bitstrings[mask & 0x0f]); 69 | #endif 70 | // Test the index against the mask 71 | if (bits & mask) return true; 72 | } 73 | } 74 | return false; 75 | } 76 | } // namespace android 77 | -------------------------------------------------------------------------------- /modules/input/evdev/BitUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_BIT_UTILS_H_ 18 | #define ANDROID_BIT_UTILS_H_ 19 | 20 | #include 21 | 22 | namespace android { 23 | 24 | /** Test whether any bits in the interval [start, end) are set in the array. */ 25 | bool testBitInRange(const uint8_t arr[], size_t start, size_t end); 26 | 27 | } // namespace android 28 | 29 | #endif // ANDROID_BIT_UTILS_H_ 30 | -------------------------------------------------------------------------------- /modules/input/evdev/InputDeviceManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "InputDeviceManager" 18 | //#define LOG_NDEBUG 0 19 | 20 | #include "InputDeviceManager.h" 21 | 22 | #include 23 | 24 | #include "InputDevice.h" 25 | 26 | namespace android { 27 | 28 | void InputDeviceManager::onInputEvent(const std::shared_ptr& node, InputEvent& event, 29 | nsecs_t event_time) { 30 | if (mDevices[node] == nullptr) { 31 | ALOGE("got input event for unknown node %s", node->getPath().c_str()); 32 | return; 33 | } 34 | mDevices[node]->processInput(event, event_time); 35 | } 36 | 37 | void InputDeviceManager::onDeviceAdded(const std::shared_ptr& node) { 38 | mDevices[node] = std::make_shared(mHost, node); 39 | } 40 | 41 | void InputDeviceManager::onDeviceRemoved(const std::shared_ptr& node) { 42 | if (mDevices[node] == nullptr) { 43 | ALOGE("could not remove unknown node %s", node->getPath().c_str()); 44 | return; 45 | } 46 | // TODO: tell the InputDevice and InputDeviceNode that they are being 47 | // removed so they can run any cleanup, including unregistering from the 48 | // host. 49 | mDevices.erase(node); 50 | } 51 | 52 | } // namespace android 53 | -------------------------------------------------------------------------------- /modules/input/evdev/InputDeviceManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_INPUT_DEVICE_MANAGER_H_ 18 | #define ANDROID_INPUT_DEVICE_MANAGER_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "InputHub.h" 26 | 27 | namespace android { 28 | 29 | class InputDeviceInterface; 30 | class InputHostInterface; 31 | 32 | /** 33 | * InputDeviceManager keeps the mapping of InputDeviceNodes to 34 | * InputDeviceInterfaces and handles the callbacks from the InputHub, delegating 35 | * them to the appropriate InputDeviceInterface. 36 | */ 37 | class InputDeviceManager : public InputCallbackInterface { 38 | public: 39 | explicit InputDeviceManager(InputHostInterface* host) : 40 | mHost(host) {} 41 | virtual ~InputDeviceManager() override = default; 42 | 43 | virtual void onInputEvent(const std::shared_ptr& node, InputEvent& event, 44 | nsecs_t event_time) override; 45 | virtual void onDeviceAdded(const std::shared_ptr& node) override; 46 | virtual void onDeviceRemoved(const std::shared_ptr& node) override; 47 | 48 | private: 49 | InputHostInterface* mHost; 50 | 51 | template 52 | using DeviceMap = std::unordered_map, std::shared_ptr>; 53 | 54 | DeviceMap mDevices; 55 | }; 56 | 57 | } // namespace android 58 | 59 | #endif // ANDROID_INPUT_DEVICE_MANAGER_H_ 60 | -------------------------------------------------------------------------------- /modules/input/evdev/InputMapper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "InputMapper.h" 18 | 19 | #include "InputHost.h" 20 | 21 | namespace android { 22 | 23 | InputReport* InputMapper::getInputReport() { 24 | if (mReport) return mReport; 25 | if (mInputReportDef == nullptr) return nullptr; 26 | mReport = mInputReportDef->allocateReport(); 27 | return mReport; 28 | } 29 | 30 | } // namespace android 31 | -------------------------------------------------------------------------------- /modules/input/evdev/InputMapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_INPUT_MAPPER_H_ 18 | #define ANDROID_INPUT_MAPPER_H_ 19 | 20 | struct input_device_handle; 21 | 22 | namespace android { 23 | 24 | class InputDeviceNode; 25 | class InputReport; 26 | class InputReportDefinition; 27 | struct InputEvent; 28 | using InputDeviceHandle = struct input_device_handle; 29 | 30 | /** 31 | * An InputMapper processes raw evdev input events and combines them into 32 | * Android input HAL reports. A given InputMapper will focus on a particular 33 | * type of input, like key presses or touch events. A single InputDevice may 34 | * have multiple InputMappers, corresponding to the different types of inputs it 35 | * supports. 36 | */ 37 | class InputMapper { 38 | public: 39 | InputMapper() = default; 40 | virtual ~InputMapper() {} 41 | 42 | /** 43 | * If the mapper supports input events from the InputDevice, 44 | * configureInputReport will populate the InputReportDefinition and return 45 | * true. If input is not supported, false is returned, and the InputDevice 46 | * may free or re-use the InputReportDefinition. 47 | */ 48 | virtual bool configureInputReport(InputDeviceNode* devNode, InputReportDefinition* report) { 49 | return false; 50 | } 51 | 52 | /** 53 | * If the mapper supports output events from the InputDevice, 54 | * configureOutputReport will populate the InputReportDefinition and return 55 | * true. If output is not supported, false is returned, and the InputDevice 56 | * may free or re-use the InputReportDefinition. 57 | */ 58 | virtual bool configureOutputReport(InputDeviceNode* devNode, InputReportDefinition* report) { 59 | return false; 60 | } 61 | 62 | // Set the InputDeviceHandle after registering the device with the host. 63 | virtual void setDeviceHandle(InputDeviceHandle* handle) { mDeviceHandle = handle; } 64 | // Process the InputEvent. 65 | virtual void process(const InputEvent& event) = 0; 66 | 67 | protected: 68 | virtual void setInputReportDefinition(InputReportDefinition* reportDef) final { 69 | mInputReportDef = reportDef; 70 | } 71 | virtual void setOutputReportDefinition(InputReportDefinition* reportDef) final { 72 | mOutputReportDef = reportDef; 73 | } 74 | virtual InputReportDefinition* getInputReportDefinition() final { return mInputReportDef; } 75 | virtual InputReportDefinition* getOutputReportDefinition() final { return mOutputReportDef; } 76 | virtual InputDeviceHandle* getDeviceHandle() final { return mDeviceHandle; } 77 | virtual InputReport* getInputReport() final; 78 | 79 | private: 80 | InputReportDefinition* mInputReportDef = nullptr; 81 | InputReportDefinition* mOutputReportDef = nullptr; 82 | InputDeviceHandle* mDeviceHandle = nullptr; 83 | InputReport* mReport = nullptr; 84 | }; 85 | 86 | } // namespace android 87 | 88 | #endif // ANDROID_INPUT_MAPPER_H_ 89 | -------------------------------------------------------------------------------- /modules/input/evdev/MouseInputMapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_MOUSE_INPUT_MAPPER_H_ 18 | #define ANDROID_MOUSE_INPUT_MAPPER_H_ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include "InputMapper.h" 26 | 27 | namespace android { 28 | 29 | class MouseInputMapper : public InputMapper { 30 | public: 31 | virtual ~MouseInputMapper() = default; 32 | 33 | virtual bool configureInputReport(InputDeviceNode* devNode, 34 | InputReportDefinition* report) override; 35 | virtual void process(const InputEvent& event) override; 36 | 37 | private: 38 | void processMotion(int32_t code, int32_t value); 39 | void processButton(int32_t code, int32_t value); 40 | void sync(nsecs_t when); 41 | 42 | BitSet32 mButtonValues; 43 | BitSet32 mUpdatedButtonMask; 44 | 45 | int32_t mRelX = 0; 46 | int32_t mRelY = 0; 47 | 48 | bool mHaveRelWheel = false; 49 | bool mHaveRelHWheel = false; 50 | int32_t mRelWheel = 0; 51 | int32_t mRelHWheel = 0; 52 | }; 53 | 54 | } // namespace android 55 | 56 | #endif // ANDROID_MOUSE_INPUT_MAPPER_H_ 57 | -------------------------------------------------------------------------------- /modules/input/evdev/SwitchInputMapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_SWITCH_INPUT_MAPPER_H_ 18 | #define ANDROID_SWITCH_INPUT_MAPPER_H_ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include "InputMapper.h" 26 | 27 | namespace android { 28 | 29 | class SwitchInputMapper : public InputMapper { 30 | public: 31 | SwitchInputMapper(); 32 | virtual ~SwitchInputMapper() = default; 33 | 34 | virtual bool configureInputReport(InputDeviceNode* devNode, 35 | InputReportDefinition* report) override; 36 | virtual void process(const InputEvent& event) override; 37 | 38 | private: 39 | void processSwitch(int32_t switchCode, int32_t switchValue); 40 | void sync(nsecs_t when); 41 | 42 | BitSet32 mSwitchValues; 43 | BitSet32 mUpdatedSwitchMask; 44 | }; 45 | 46 | } // namespace android 47 | 48 | #endif // ANDROID_SWITCH_INPUT_MAPPER_H_ 49 | -------------------------------------------------------------------------------- /modules/local_time/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2011 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | # The default local time HAL module. The default module simply uses the 18 | # system's clock_gettime(CLOCK_MONOTONIC) and does not support HW slewing. 19 | # Devices which use the default implementation should take care to ensure that 20 | # the oscillator backing the CLOCK_MONOTONIC implementation is phase locked to 21 | # the audio and video output hardware. This default implementation is loaded 22 | # if no other device specific modules are present. The exact load order can be 23 | # seen in libhardware/hardware.c 24 | # 25 | # The format of the name is local_time..so 26 | include $(CLEAR_VARS) 27 | 28 | LOCAL_MODULE := local_time.default 29 | LOCAL_MODULE_RELATIVE_PATH := hw 30 | LOCAL_SRC_FILES := local_time_hw.c 31 | LOCAL_SHARED_LIBRARIES := liblog libcutils 32 | LOCAL_MODULE_TAGS := optional 33 | 34 | include $(BUILD_SHARED_LIBRARY) 35 | -------------------------------------------------------------------------------- /modules/local_time/local_time_hw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "local_time_hw_default" 18 | //#define LOG_NDEBUG 0 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | struct stub_local_time_device { 32 | struct local_time_hw_device device; 33 | }; 34 | 35 | static int64_t ltdev_get_local_time(struct local_time_hw_device* dev) 36 | { 37 | struct timespec ts; 38 | uint64_t now; 39 | int ret; 40 | 41 | ret = clock_gettime(CLOCK_MONOTONIC, &ts); 42 | if (ret < 0) { 43 | ALOGW("%s failed to fetch CLOCK_MONOTONIC value! (res = %d)", 44 | dev->common.module->name, ret); 45 | return 0; 46 | } 47 | 48 | now = (((uint64_t)ts.tv_sec) * 1000000000ull) + 49 | ((uint64_t)ts.tv_nsec); 50 | 51 | return (int64_t)now; 52 | } 53 | 54 | static uint64_t ltdev_get_local_freq(struct local_time_hw_device* dev) 55 | { 56 | // For better or worse, linux clock_gettime routines normalize all clock 57 | // frequencies to 1GHz 58 | return 1000000000ull; 59 | } 60 | 61 | static int ltdev_close(hw_device_t *device) 62 | { 63 | free(device); 64 | return 0; 65 | } 66 | 67 | static int ltdev_open(const hw_module_t* module, const char* name, 68 | hw_device_t** device) 69 | { 70 | struct stub_local_time_device *ltdev; 71 | struct timespec ts; 72 | int ret; 73 | 74 | if (strcmp(name, LOCAL_TIME_HARDWARE_INTERFACE) != 0) 75 | return -EINVAL; 76 | 77 | ltdev = calloc(1, sizeof(struct stub_local_time_device)); 78 | if (!ltdev) 79 | return -ENOMEM; 80 | 81 | ltdev->device.common.tag = HARDWARE_DEVICE_TAG; 82 | ltdev->device.common.version = 0; 83 | ltdev->device.common.module = (struct hw_module_t *) module; 84 | ltdev->device.common.close = ltdev_close; 85 | 86 | ltdev->device.get_local_time = ltdev_get_local_time; 87 | ltdev->device.get_local_freq = ltdev_get_local_freq; 88 | ltdev->device.set_local_slew = NULL; 89 | ltdev->device.get_debug_log = NULL; 90 | 91 | *device = <dev->device.common; 92 | 93 | return 0; 94 | } 95 | 96 | static struct hw_module_methods_t hal_module_methods = { 97 | .open = ltdev_open, 98 | }; 99 | 100 | struct local_time_module HAL_MODULE_INFO_SYM = { 101 | .common = { 102 | .tag = HARDWARE_MODULE_TAG, 103 | .version_major = 1, 104 | .version_minor = 0, 105 | .id = LOCAL_TIME_HARDWARE_MODULE_ID, 106 | .name = "Default local_time HW HAL", 107 | .author = "The Android Open Source Project", 108 | .methods = &hal_module_methods, 109 | }, 110 | }; 111 | -------------------------------------------------------------------------------- /modules/nfc-nci/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2011 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := nfc_nci.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := nfc_nci_example.c 22 | LOCAL_SHARED_LIBRARIES := liblog libcutils 23 | LOCAL_MODULE_TAGS := optional 24 | 25 | include $(BUILD_SHARED_LIBRARY) 26 | -------------------------------------------------------------------------------- /modules/nfc-nci/nfc_nci_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | /* 26 | * NCI HAL method implementations. These must be overriden 27 | */ 28 | static int hal_open(const struct nfc_nci_device *dev, 29 | nfc_stack_callback_t *p_cback, nfc_stack_data_callback_t *p_data_cback) { 30 | ALOGE("NFC-NCI HAL: %s", __FUNCTION__); 31 | return 0; 32 | } 33 | 34 | static int hal_write(const struct nfc_nci_device *dev, 35 | uint16_t data_len, const uint8_t *p_data) { 36 | ALOGE("NFC-NCI HAL: %s", __FUNCTION__); 37 | return 0; 38 | } 39 | 40 | static int hal_core_initialized(const struct nfc_nci_device *dev, 41 | uint8_t* p_core_init_rsp_params) { 42 | ALOGE("NFC-NCI HAL: %s", __FUNCTION__); 43 | return 0; 44 | } 45 | 46 | static int hal_pre_discover(const struct nfc_nci_device *dev) { 47 | ALOGE("NFC-NCI HAL: %s", __FUNCTION__); 48 | return 0; 49 | } 50 | 51 | static int hal_close(const struct nfc_nci_device *dev) { 52 | ALOGE("NFC-NCI HAL: %s", __FUNCTION__); 53 | return 0; 54 | } 55 | 56 | static int hal_control_granted (const struct nfc_nci_device *p_dev) 57 | { 58 | ALOGE("NFC-NCI HAL: %s", __FUNCTION__); 59 | return 0; 60 | } 61 | 62 | 63 | static int hal_power_cycle (const struct nfc_nci_device *p_dev) 64 | { 65 | ALOGE("NFC-NCI HAL: %s", __FUNCTION__); 66 | return 0; 67 | } 68 | 69 | /* 70 | * Generic device handling below - can generally be left unchanged. 71 | */ 72 | /* Close an opened nfc device instance */ 73 | static int nfc_close(hw_device_t *dev) { 74 | free(dev); 75 | return 0; 76 | } 77 | 78 | static int nfc_open(const hw_module_t* module, const char* name, 79 | hw_device_t** device) { 80 | if (strcmp(name, NFC_NCI_CONTROLLER) == 0) { 81 | nfc_nci_device_t *dev = calloc(1, sizeof(nfc_nci_device_t)); 82 | 83 | dev->common.tag = HARDWARE_DEVICE_TAG; 84 | dev->common.version = 0x00010000; // [31:16] major, [15:0] minor 85 | dev->common.module = (struct hw_module_t*) module; 86 | dev->common.close = nfc_close; 87 | 88 | // NCI HAL method pointers 89 | dev->open = hal_open; 90 | dev->write = hal_write; 91 | dev->core_initialized = hal_core_initialized; 92 | dev->pre_discover = hal_pre_discover; 93 | dev->close = hal_close; 94 | dev->control_granted = hal_control_granted; 95 | dev->power_cycle = hal_power_cycle; 96 | 97 | *device = (hw_device_t*) dev; 98 | 99 | return 0; 100 | } else { 101 | return -EINVAL; 102 | } 103 | } 104 | 105 | 106 | static struct hw_module_methods_t nfc_module_methods = { 107 | .open = nfc_open, 108 | }; 109 | 110 | struct nfc_nci_module_t HAL_MODULE_INFO_SYM = { 111 | .common = { 112 | .tag = HARDWARE_MODULE_TAG, 113 | .module_api_version = 0x0100, // [15:8] major, [7:0] minor (1.0) 114 | .hal_api_version = 0x00, // 0 is only valid value 115 | .id = NFC_NCI_HARDWARE_MODULE_ID, 116 | .name = "Default NFC NCI HW HAL", 117 | .author = "The Android Open Source Project", 118 | .methods = &nfc_module_methods, 119 | }, 120 | }; 121 | -------------------------------------------------------------------------------- /modules/nfc/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2011 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := nfc.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := nfc_pn544_example.c 22 | LOCAL_SHARED_LIBRARIES := liblog libcutils 23 | LOCAL_MODULE_TAGS := optional 24 | 25 | include $(BUILD_SHARED_LIBRARY) 26 | -------------------------------------------------------------------------------- /modules/nfc/nfc_pn544_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | /* Close an opened pn544 device instance */ 24 | static int pn544_close(hw_device_t *dev) { 25 | free(dev); 26 | return 0; 27 | } 28 | 29 | /* 30 | * Generic device handling 31 | */ 32 | static int nfc_open(const hw_module_t* module, const char* name, 33 | hw_device_t** device) { 34 | if (strcmp(name, NFC_PN544_CONTROLLER) == 0) { 35 | nfc_pn544_device_t *dev = calloc(1, sizeof(nfc_pn544_device_t)); 36 | 37 | dev->common.tag = HARDWARE_DEVICE_TAG; 38 | dev->common.version = 0; 39 | dev->common.module = (struct hw_module_t*) module; 40 | dev->common.close = pn544_close; 41 | 42 | /* Example settings */ 43 | dev->num_eeprom_settings = 0; 44 | dev->eeprom_settings = NULL; 45 | dev->linktype = PN544_LINK_TYPE_INVALID; 46 | dev->device_node = NULL; 47 | dev->enable_i2c_workaround = 0; 48 | dev->i2c_device_address = 0; 49 | 50 | *device = (hw_device_t*) dev; 51 | return 0; 52 | } else { 53 | return -EINVAL; 54 | } 55 | } 56 | 57 | 58 | static struct hw_module_methods_t nfc_module_methods = { 59 | .open = nfc_open, 60 | }; 61 | 62 | struct nfc_module_t HAL_MODULE_INFO_SYM = { 63 | .common = { 64 | .tag = HARDWARE_MODULE_TAG, 65 | .version_major = 1, 66 | .version_minor = 0, 67 | .id = NFC_HARDWARE_MODULE_ID, 68 | .name = "Default NFC HW HAL", 69 | .author = "The Android Open Source Project", 70 | .methods = &nfc_module_methods, 71 | }, 72 | }; 73 | -------------------------------------------------------------------------------- /modules/power/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2011 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := power.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := power.c 22 | LOCAL_SHARED_LIBRARIES := liblog 23 | LOCAL_MODULE_TAGS := optional 24 | 25 | include $(BUILD_SHARED_LIBRARY) 26 | -------------------------------------------------------------------------------- /modules/power/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define LOG_TAG "Legacy PowerHAL" 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | static void power_init(struct power_module *module) 29 | { 30 | } 31 | 32 | static void power_set_interactive(struct power_module *module, int on) 33 | { 34 | } 35 | 36 | static void power_hint(struct power_module *module, power_hint_t hint, 37 | void *data) { 38 | switch (hint) { 39 | default: 40 | break; 41 | } 42 | } 43 | 44 | static struct hw_module_methods_t power_module_methods = { 45 | .open = NULL, 46 | }; 47 | 48 | struct power_module HAL_MODULE_INFO_SYM = { 49 | .common = { 50 | .tag = HARDWARE_MODULE_TAG, 51 | .module_api_version = POWER_MODULE_API_VERSION_0_2, 52 | .hal_api_version = HARDWARE_HAL_API_VERSION, 53 | .id = POWER_HARDWARE_MODULE_ID, 54 | .name = "Default Power HAL", 55 | .author = "The Android Open Source Project", 56 | .methods = &power_module_methods, 57 | }, 58 | 59 | .init = power_init, 60 | .setInteractive = power_set_interactive, 61 | .powerHint = power_hint, 62 | }; 63 | -------------------------------------------------------------------------------- /modules/radio/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | # Stub radio HAL module, used for tests 18 | include $(CLEAR_VARS) 19 | 20 | LOCAL_MULTILIB := $(AUDIOSERVER_MULTILIB) 21 | 22 | LOCAL_MODULE := radio.fm.default 23 | LOCAL_MODULE_RELATIVE_PATH := hw 24 | LOCAL_SRC_FILES := radio_hw.c 25 | LOCAL_SHARED_LIBRARIES := liblog libcutils libradio_metadata 26 | LOCAL_MODULE_TAGS := optional 27 | 28 | include $(BUILD_SHARED_LIBRARY) 29 | 30 | # Stub radio tool that can be run in native. 31 | include $(CLEAR_VARS) 32 | 33 | LOCAL_MULTILIB := $(AUDIOSERVER_MULTILIB) 34 | 35 | LOCAL_MODULE := radio_hal_tool 36 | LOCAL_SRC_FILES := radio_hal_tool.c 37 | LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror 38 | LOCAL_SHARED_LIBRARIES := libcutils libhardware liblog libradio_metadata 39 | 40 | include $(BUILD_EXECUTABLE) 41 | -------------------------------------------------------------------------------- /modules/sensors/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 The Android Open-Source Project 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | LOCAL_PATH := $(call my-dir) 18 | 19 | ifeq ($(USE_SENSOR_MULTI_HAL),true) 20 | 21 | include $(CLEAR_VARS) 22 | 23 | LOCAL_MODULE := sensors.$(TARGET_BOARD_PLATFORM) 24 | 25 | LOCAL_MODULE_RELATIVE_PATH := hw 26 | 27 | LOCAL_CFLAGS := -DLOG_TAG=\"MultiHal\" 28 | 29 | LOCAL_SRC_FILES := \ 30 | multihal.cpp \ 31 | SensorEventQueue.cpp \ 32 | 33 | LOCAL_SHARED_LIBRARIES := \ 34 | libcutils \ 35 | libdl \ 36 | liblog \ 37 | libutils \ 38 | 39 | LOCAL_STRIP_MODULE := false 40 | 41 | include $(BUILD_SHARED_LIBRARY) 42 | 43 | endif # USE_SENSOR_MULTI_HAL 44 | 45 | include $(call all-makefiles-under, $(LOCAL_PATH)) 46 | -------------------------------------------------------------------------------- /modules/sensors/SensorEventQueue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "SensorEventQueue.h" 23 | 24 | SensorEventQueue::SensorEventQueue(int capacity) { 25 | mCapacity = capacity; 26 | 27 | mStart = 0; 28 | mSize = 0; 29 | mData = new sensors_event_t[mCapacity]; 30 | pthread_cond_init(&mSpaceAvailableCondition, NULL); 31 | } 32 | 33 | SensorEventQueue::~SensorEventQueue() { 34 | delete[] mData; 35 | mData = NULL; 36 | pthread_cond_destroy(&mSpaceAvailableCondition); 37 | } 38 | 39 | int SensorEventQueue::getWritableRegion(int requestedLength, sensors_event_t** out) { 40 | if (mSize == mCapacity || requestedLength <= 0) { 41 | *out = NULL; 42 | return 0; 43 | } 44 | // Start writing after the last readable record. 45 | int firstWritable = (mStart + mSize) % mCapacity; 46 | 47 | int lastWritable = firstWritable + requestedLength - 1; 48 | 49 | // Don't go past the end of the data array. 50 | if (lastWritable > mCapacity - 1) { 51 | lastWritable = mCapacity - 1; 52 | } 53 | // Don't go into the readable region. 54 | if (firstWritable < mStart && lastWritable >= mStart) { 55 | lastWritable = mStart - 1; 56 | } 57 | *out = &mData[firstWritable]; 58 | return lastWritable - firstWritable + 1; 59 | } 60 | 61 | void SensorEventQueue::markAsWritten(int count) { 62 | mSize += count; 63 | } 64 | 65 | int SensorEventQueue::getSize() { 66 | return mSize; 67 | } 68 | 69 | sensors_event_t* SensorEventQueue::peek() { 70 | if (mSize == 0) return NULL; 71 | return &mData[mStart]; 72 | } 73 | 74 | void SensorEventQueue::dequeue() { 75 | if (mSize == 0) return; 76 | if (mSize == mCapacity) { 77 | pthread_cond_broadcast(&mSpaceAvailableCondition); 78 | } 79 | mSize--; 80 | mStart = (mStart + 1) % mCapacity; 81 | } 82 | 83 | // returns true if it waited, or false if it was a no-op. 84 | bool SensorEventQueue::waitForSpace(pthread_mutex_t* mutex) { 85 | bool waited = false; 86 | while (mSize == mCapacity) { 87 | waited = true; 88 | pthread_cond_wait(&mSpaceAvailableCondition, mutex); 89 | } 90 | return waited; 91 | } 92 | -------------------------------------------------------------------------------- /modules/sensors/SensorEventQueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef SENSOREVENTQUEUE_H_ 18 | #define SENSOREVENTQUEUE_H_ 19 | 20 | #include 21 | #include 22 | 23 | /* 24 | * Fixed-size circular queue, with an API developed around the sensor HAL poll() method. 25 | * Poll() takes a pointer to a buffer, which is written by poll() before it returns. 26 | * This class can provide a pointer to a spot in its internal buffer for poll() to 27 | * write to, instead of using an intermediate buffer and a memcpy. 28 | * 29 | * Thread safety: 30 | * Reading can be done safely after grabbing the mutex lock, while poll() writing in a separate 31 | * thread without a mutex lock. But there can only be one writer at a time. 32 | */ 33 | class SensorEventQueue { 34 | int mCapacity; 35 | int mStart; // start of readable region 36 | int mSize; // number of readable items 37 | sensors_event_t* mData; 38 | pthread_cond_t mSpaceAvailableCondition; 39 | 40 | public: 41 | SensorEventQueue(int capacity); 42 | ~SensorEventQueue(); 43 | 44 | // Returns length of region, between zero and min(capacity, requestedLength). If there is any 45 | // writable space, it will return a region of at least one. Because it must return 46 | // a pointer to a contiguous region, it may return smaller regions as we approach the end of 47 | // the data array. 48 | // Only call while holding the lock. 49 | // The region is not marked internally in any way. Subsequent calls may return overlapping 50 | // regions. This class expects there to be exactly one writer at a time. 51 | int getWritableRegion(int requestedLength, sensors_event_t** out); 52 | 53 | // After writing to the region returned by getWritableRegion(), call this to indicate how 54 | // many records were actually written. 55 | // This increases size() by count. 56 | // Only call while holding the lock. 57 | void markAsWritten(int count); 58 | 59 | // Gets the number of readable records. 60 | // Only call while holding the lock. 61 | int getSize(); 62 | 63 | // Returns pointer to the first readable record, or NULL if size() is zero. 64 | // Only call this while holding the lock. 65 | sensors_event_t* peek(); 66 | 67 | // This will decrease the size by one, freeing up the oldest readable event's slot for writing. 68 | // Only call while holding the lock. 69 | void dequeue(); 70 | 71 | // Blocks until space is available. No-op if there is already space. 72 | // Returns true if it had to wait. 73 | bool waitForSpace(pthread_mutex_t* mutex); 74 | }; 75 | 76 | #endif // SENSOREVENTQUEUE_H_ 77 | -------------------------------------------------------------------------------- /modules/sensors/tests/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_SRC_FILES := \ 6 | SensorEventQueue_test.cpp 7 | 8 | #LOCAL_CFLAGS := -g 9 | LOCAL_MODULE := sensorstests 10 | 11 | LOCAL_STATIC_LIBRARIES := libcutils libutils 12 | 13 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. bionic 14 | 15 | LOCAL_LDLIBS += -lpthread 16 | 17 | include $(BUILD_HOST_EXECUTABLE) 18 | -------------------------------------------------------------------------------- /modules/soundtrigger/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2011 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | # Stub sound_trigger HAL module, used for tests 18 | include $(CLEAR_VARS) 19 | 20 | LOCAL_MODULE := sound_trigger.stub.default 21 | LOCAL_MODULE_RELATIVE_PATH := hw 22 | LOCAL_SRC_FILES := sound_trigger_hw.c 23 | LOCAL_SHARED_LIBRARIES := liblog libcutils 24 | LOCAL_MODULE_TAGS := optional 25 | 26 | include $(BUILD_SHARED_LIBRARY) 27 | -------------------------------------------------------------------------------- /modules/thermal/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := thermal.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := thermal.c 22 | LOCAL_SHARED_LIBRARIES := liblog libcutils 23 | LOCAL_MODULE_TAGS := optional 24 | LOCAL_CFLAGS := -Wno-unused-parameter 25 | 26 | include $(BUILD_SHARED_LIBRARY) 27 | -------------------------------------------------------------------------------- /modules/tv_input/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE_RELATIVE_PATH := hw 20 | LOCAL_SHARED_LIBRARIES := libcutils liblog 21 | LOCAL_SRC_FILES := tv_input.cpp 22 | LOCAL_MODULE := tv_input.default 23 | LOCAL_MODULE_TAGS := optional 24 | include $(BUILD_SHARED_LIBRARY) 25 | -------------------------------------------------------------------------------- /modules/usbaudio/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := audio.usb.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := \ 22 | audio_hal.c 23 | LOCAL_C_INCLUDES += \ 24 | external/tinyalsa/include \ 25 | $(call include-path-for, audio-utils) \ 26 | $(call include-path-for, alsa-utils) 27 | LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libalsautils 28 | LOCAL_MODULE_TAGS := optional 29 | LOCAL_CFLAGS := -Wno-unused-parameter 30 | 31 | include $(BUILD_SHARED_LIBRARY) 32 | 33 | -------------------------------------------------------------------------------- /modules/usbcamera/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := camera.usb.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | 22 | LOCAL_C_INCLUDES += \ 23 | system/core/include \ 24 | system/media/camera/include \ 25 | 26 | LOCAL_SRC_FILES := \ 27 | CameraHAL.cpp \ 28 | Camera.cpp \ 29 | UsbCamera.cpp \ 30 | Metadata.cpp \ 31 | Stream.cpp \ 32 | HotplugThread.cpp \ 33 | 34 | LOCAL_SHARED_LIBRARIES := \ 35 | libcamera_metadata \ 36 | libcutils \ 37 | liblog \ 38 | libsync \ 39 | libutils \ 40 | 41 | LOCAL_CFLAGS += -Wall -Wextra -fvisibility=hidden 42 | 43 | LOCAL_MODULE_TAGS := optional 44 | 45 | include $(BUILD_SHARED_LIBRARY) 46 | -------------------------------------------------------------------------------- /modules/usbcamera/CameraHAL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef CAMERA_HAL_H_ 18 | #define CAMERA_HAL_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "HotplugThread.h" 25 | #include "Camera.h" 26 | 27 | namespace usb_camera_hal { 28 | 29 | class HotplugThread; 30 | 31 | /** 32 | * CameraHAL contains all module state that isn't specific to an individual camera device 33 | */ 34 | class CameraHAL { 35 | public: 36 | CameraHAL(); 37 | ~CameraHAL(); 38 | 39 | // Camera Module Interface (see ) 40 | int getNumberOfCameras(); 41 | int getCameraInfo(int camera_id, struct camera_info *info); 42 | int setCallbacks(const camera_module_callbacks_t *callbacks); 43 | void getVendorTagOps(vendor_tag_ops_t* ops); 44 | 45 | // Hardware Module Interface (see ) 46 | int open(const hw_module_t* mod, const char* name, hw_device_t** dev); 47 | 48 | private: 49 | // Callback handle 50 | const camera_module_callbacks_t *mCallbacks; 51 | android::Vector mCameras; 52 | // Lock to protect the module method calls. 53 | android::Mutex mModuleLock; 54 | // Hot plug thread managing camera hot plug. 55 | HotplugThread *mHotplugThread; 56 | 57 | }; 58 | } // namespace usb_camera_hal 59 | 60 | #endif // CAMERA_HAL_H_ 61 | -------------------------------------------------------------------------------- /modules/usbcamera/HotplugThread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | //#define LOG_NDEBUG 0 18 | #define LOG_TAG "HotplugThread" 19 | #include 20 | 21 | #include "HotplugThread.h" 22 | 23 | namespace usb_camera_hal { 24 | 25 | HotplugThread::HotplugThread(CameraHAL *hal) 26 | : mModule(hal) { 27 | 28 | } 29 | 30 | HotplugThread::~HotplugThread() { 31 | 32 | } 33 | 34 | void HotplugThread::requestExit() { 35 | // Call parent to set up shutdown 36 | Thread::requestExit(); 37 | 38 | // Cleanup other states? 39 | } 40 | 41 | bool HotplugThread::threadLoop() { 42 | 43 | /** 44 | * Check camera connection status change, if connected, do below: 45 | * 1. Create camera device, add to mCameras. 46 | * 2. Init static info (mCameras[id]->initStaticInfo()) 47 | * 3. Notify on_status_change callback 48 | * 49 | * If unconnected, similarly, do below: 50 | * 1. Destroy camera device and remove it from mCameras. 51 | * 2. Notify on_status_change callback 52 | * 53 | * DO NOT have a tight polling loop here, to avoid excessive CPU utilization. 54 | */ 55 | 56 | return true; 57 | } 58 | 59 | } // namespace usb_camera_hal 60 | -------------------------------------------------------------------------------- /modules/usbcamera/HotplugThread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef HOTPLUG_THREAD_H_ 17 | #define HOTPLUG_THREAD_H_ 18 | 19 | #include 20 | #include "CameraHAL.h" 21 | 22 | namespace usb_camera_hal { 23 | /** 24 | * Thread for managing usb camera hotplug. It does below: 25 | * 1. Monitor camera hotplug status, and notify the status changes by calling 26 | * module callback methods. 27 | * 2. When camera is plugged, create camera device instance, initialize the camera 28 | * static info. When camera is unplugged, destroy the camera device instance and 29 | * static metadata. As an optimization option, the camera device instance (including 30 | * the static info) could be cached when the same camera plugged/unplugged multiple 31 | * times. 32 | */ 33 | 34 | class CameraHAL; 35 | 36 | class HotplugThread : public android::Thread { 37 | 38 | public: 39 | HotplugThread(CameraHAL *hal); 40 | ~HotplugThread(); 41 | 42 | // Override below two methods for proper cleanup. 43 | virtual bool threadLoop(); 44 | virtual void requestExit(); 45 | 46 | private: 47 | CameraHAL *mModule; 48 | }; 49 | 50 | } // namespace usb_camera_hal 51 | 52 | #endif // HOTPLUG_THREAD_H_ 53 | -------------------------------------------------------------------------------- /modules/usbcamera/Metadata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef METADATA_H_ 18 | #define METADATA_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace usb_camera_hal { 25 | // Metadata is a convenience class for dealing with libcamera_metadata 26 | class Metadata { 27 | public: 28 | Metadata(); 29 | ~Metadata(); 30 | // Initialize with framework metadata 31 | int init(const camera_metadata_t *metadata); 32 | 33 | // Parse and add an entry. Allocates and copies new storage for *data. 34 | int addUInt8(uint32_t tag, int count, const uint8_t *data); 35 | int add1UInt8(uint32_t tag, const uint8_t data); 36 | int addInt32(uint32_t tag, int count, const int32_t *data); 37 | int addFloat(uint32_t tag, int count, const float *data); 38 | int addInt64(uint32_t tag, int count, const int64_t *data); 39 | int addDouble(uint32_t tag, int count, const double *data); 40 | int addRational(uint32_t tag, int count, 41 | const camera_metadata_rational_t *data); 42 | 43 | // Get a handle to the current metadata 44 | // This is not a durable handle, and may be destroyed by add*/init 45 | camera_metadata_t* get(); 46 | 47 | private: 48 | // Actual internal storage 49 | camera_metadata_t* mData; 50 | // Destroy old metadata and replace with new 51 | void replace(camera_metadata_t *m); 52 | // Validate the tag, type and count for a metadata entry 53 | bool validate(uint32_t tag, int tag_type, int count); 54 | // Add a verified tag with data 55 | int add(uint32_t tag, int count, const void *tag_data); 56 | }; 57 | } // namespace usb_camera_hal 58 | 59 | #endif // METADATA_H_ 60 | -------------------------------------------------------------------------------- /modules/usbcamera/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef STREAM_H_ 18 | #define STREAM_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace usb_camera_hal { 27 | // Stream represents a single input or output stream for a camera device. 28 | class Stream { 29 | public: 30 | Stream(int id, camera3_stream_t *s); 31 | ~Stream(); 32 | 33 | // validate that a stream's parameters match this stream's parameters 34 | bool isValidReuseStream(int id, camera3_stream_t *s); 35 | 36 | void setUsage(uint32_t usage); 37 | void setMaxBuffers(uint32_t max_buffers); 38 | 39 | int getType(); 40 | bool isInputType(); 41 | bool isOutputType(); 42 | const char* typeToString(int type); 43 | const char* formatToString(int format); 44 | void dump(int fd); 45 | 46 | // This stream is being reused. Used in stream configuration passes 47 | bool mReuse; 48 | 49 | private: 50 | // The camera device id this stream belongs to 51 | const int mId; 52 | // Handle to framework's stream, used as a cookie for buffers 53 | camera3_stream_t *mStream; 54 | // Array of handles to buffers currently in use by the stream 55 | android::Vector mBuffers; 56 | // Lock protecting the Stream object for modifications 57 | android::Mutex mLock; 58 | }; 59 | } // namespace usb_camera_hal 60 | 61 | #endif // STREAM_H_ 62 | -------------------------------------------------------------------------------- /modules/usbcamera/UsbCamera.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef EXAMPLE_CAMERA_H_ 18 | #define EXAMPLE_CAMERA_H_ 19 | 20 | #include 21 | #include "Camera.h" 22 | 23 | namespace usb_camera_hal { 24 | /** 25 | * UsbCamera is an example for a specific camera device. The Camera instance contains 26 | * a specific camera device (e.g. UsbCamera) holds all specific metadata and logic about 27 | * that device. 28 | */ 29 | class UsbCamera : public Camera { 30 | public: 31 | UsbCamera(int id); 32 | ~UsbCamera(); 33 | 34 | private: 35 | // Initialize static camera characteristics for individual device 36 | int initStaticInfo(); 37 | int openDevice(); 38 | // Initialize whole device (templates/etc) when opened 39 | int initDevice(); 40 | int flushDevice(); 41 | int closeDevice(); 42 | int processCaptureBuffer(const camera3_stream_buffer_t *in, camera3_stream_buffer_t *out); 43 | // Initialize each template metadata controls 44 | int initPreviewTemplate(Metadata m); 45 | int initStillTemplate(Metadata m); 46 | int initRecordTemplate(Metadata m); 47 | int initSnapshotTemplate(Metadata m); 48 | int initZslTemplate(Metadata m); 49 | int initManualTemplate(Metadata m); 50 | // Verify settings are valid for a capture with this device 51 | bool isValidCaptureSettings(const camera_metadata_t* settings); 52 | }; 53 | } // namespace usb_camera_hal 54 | 55 | #endif // CAMERA_H_ 56 | -------------------------------------------------------------------------------- /modules/vehicle/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := vehicle.default 20 | 21 | LOCAL_MODULE_RELATIVE_PATH := hw 22 | LOCAL_C_INCLUDES := hardware/libhardware 23 | LOCAL_SRC_FILES := vehicle.c timeUtil.cpp 24 | LOCAL_SHARED_LIBRARIES := liblog libcutils libutils 25 | LOCAL_MODULE_TAGS := optional 26 | 27 | include $(BUILD_SHARED_LIBRARY) 28 | 29 | -------------------------------------------------------------------------------- /modules/vehicle/timeUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | int64_t elapsedRealtimeNano() { 22 | return android::elapsedRealtimeNano(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /modules/vibrator/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := vibrator.default 20 | 21 | # HAL module implementation stored in 22 | # hw/.default.so 23 | LOCAL_MODULE_RELATIVE_PATH := hw 24 | LOCAL_C_INCLUDES := hardware/libhardware 25 | LOCAL_SRC_FILES := vibrator.c 26 | LOCAL_SHARED_LIBRARIES := liblog 27 | LOCAL_MODULE_TAGS := optional 28 | 29 | include $(BUILD_SHARED_LIBRARY) 30 | 31 | -------------------------------------------------------------------------------- /modules/vibrator/vibrator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | static const char THE_DEVICE[] = "/sys/class/timed_output/vibrator/enable"; 30 | 31 | static int vibra_exists() { 32 | int fd; 33 | 34 | fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR)); 35 | if(fd < 0) { 36 | ALOGE("Vibrator file does not exist : %d", fd); 37 | return 0; 38 | } 39 | 40 | close(fd); 41 | return 1; 42 | } 43 | 44 | static int sendit(unsigned int timeout_ms) 45 | { 46 | int to_write, written, ret, fd; 47 | 48 | char value[20]; /* large enough for millions of years */ 49 | 50 | fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR)); 51 | if(fd < 0) { 52 | return -errno; 53 | } 54 | 55 | to_write = snprintf(value, sizeof(value), "%u\n", timeout_ms); 56 | written = TEMP_FAILURE_RETRY(write(fd, value, to_write)); 57 | 58 | if (written == -1) { 59 | ret = -errno; 60 | } else if (written != to_write) { 61 | /* even though EAGAIN is an errno value that could be set 62 | by write() in some cases, none of them apply here. So, this return 63 | value can be clearly identified when debugging and suggests the 64 | caller that it may try to call vibraror_on() again */ 65 | ret = -EAGAIN; 66 | } else { 67 | ret = 0; 68 | } 69 | 70 | errno = 0; 71 | close(fd); 72 | 73 | return ret; 74 | } 75 | 76 | static int vibra_on(vibrator_device_t* vibradev __unused, unsigned int timeout_ms) 77 | { 78 | /* constant on, up to maximum allowed time */ 79 | return sendit(timeout_ms); 80 | } 81 | 82 | static int vibra_off(vibrator_device_t* vibradev __unused) 83 | { 84 | return sendit(0); 85 | } 86 | 87 | static int vibra_close(hw_device_t *device) 88 | { 89 | free(device); 90 | return 0; 91 | } 92 | 93 | static int vibra_open(const hw_module_t* module, const char* id __unused, 94 | hw_device_t** device __unused) { 95 | if (!vibra_exists()) { 96 | ALOGE("Vibrator device does not exist. Cannot start vibrator"); 97 | return -ENODEV; 98 | } 99 | 100 | vibrator_device_t *vibradev = calloc(1, sizeof(vibrator_device_t)); 101 | 102 | if (!vibradev) { 103 | ALOGE("Can not allocate memory for the vibrator device"); 104 | return -ENOMEM; 105 | } 106 | 107 | vibradev->common.tag = HARDWARE_DEVICE_TAG; 108 | vibradev->common.module = (hw_module_t *) module; 109 | vibradev->common.version = HARDWARE_DEVICE_API_VERSION(1,0); 110 | vibradev->common.close = vibra_close; 111 | 112 | vibradev->vibrator_on = vibra_on; 113 | vibradev->vibrator_off = vibra_off; 114 | 115 | *device = (hw_device_t *) vibradev; 116 | 117 | return 0; 118 | } 119 | 120 | /*===========================================================================*/ 121 | /* Default vibrator HW module interface definition */ 122 | /*===========================================================================*/ 123 | 124 | static struct hw_module_methods_t vibrator_module_methods = { 125 | .open = vibra_open, 126 | }; 127 | 128 | struct hw_module_t HAL_MODULE_INFO_SYM = { 129 | .tag = HARDWARE_MODULE_TAG, 130 | .module_api_version = VIBRATOR_API_VERSION, 131 | .hal_api_version = HARDWARE_HAL_API_VERSION, 132 | .id = VIBRATOR_HARDWARE_MODULE_ID, 133 | .name = "Default vibrator HAL", 134 | .author = "The Android Open Source Project", 135 | .methods = &vibrator_module_methods, 136 | }; 137 | -------------------------------------------------------------------------------- /modules/vr/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := vr.default 20 | LOCAL_MODULE_RELATIVE_PATH := hw 21 | LOCAL_SRC_FILES := vr.c 22 | LOCAL_SHARED_LIBRARIES := libcutils 23 | LOCAL_MODULE_TAGS := optional 24 | LOCAL_CFLAGS += -Wno-unused-parameter 25 | 26 | include $(BUILD_SHARED_LIBRARY) 27 | -------------------------------------------------------------------------------- /modules/vr/vr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #define LOG_TAG "VrHal" 17 | 18 | #include 19 | #include 20 | 21 | static void vr_init(struct vr_module *module) { 22 | // NOOP 23 | } 24 | 25 | static void vr_set_vr_mode(struct vr_module *module, bool enabled) { 26 | // NOOP 27 | } 28 | 29 | static struct hw_module_methods_t vr_module_methods = { 30 | .open = NULL, 31 | }; 32 | 33 | 34 | vr_module_t HAL_MODULE_INFO_SYM = { 35 | .common = { 36 | .tag = HARDWARE_MODULE_TAG, 37 | .module_api_version = VR_MODULE_API_VERSION_1_0, 38 | .hal_api_version = HARDWARE_HAL_API_VERSION, 39 | .id = VR_HARDWARE_MODULE_ID, 40 | .name = "Demo VR HAL", 41 | .author = "The Android Open Source Project", 42 | .methods = &vr_module_methods, 43 | }, 44 | 45 | .init = vr_init, 46 | .set_vr_mode = vr_set_vr_mode, 47 | }; 48 | -------------------------------------------------------------------------------- /tests/Android.mk: -------------------------------------------------------------------------------- 1 | include $(call all-subdir-makefiles) 2 | -------------------------------------------------------------------------------- /tests/camera2/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES:= \ 5 | camera2_utils.cpp \ 6 | main.cpp \ 7 | CameraMetadataTests.cpp \ 8 | CameraModuleTests.cpp \ 9 | CameraStreamTests.cpp \ 10 | CameraFrameTests.cpp \ 11 | CameraBurstTests.cpp \ 12 | CameraMultiStreamTests.cpp\ 13 | ForkedTests.cpp \ 14 | TestForkerEventListener.cpp \ 15 | TestSettings.cpp \ 16 | 17 | LOCAL_SHARED_LIBRARIES := \ 18 | liblog \ 19 | libutils \ 20 | libcutils \ 21 | libhardware \ 22 | libcamera_metadata \ 23 | libcameraservice \ 24 | libcamera_client \ 25 | libgui \ 26 | libsync \ 27 | libui \ 28 | libdl 29 | 30 | LOCAL_C_INCLUDES += \ 31 | system/media/camera/include \ 32 | frameworks/av/include/ \ 33 | frameworks/av/services/camera/libcameraservice \ 34 | frameworks/native/include \ 35 | 36 | LOCAL_CFLAGS += -Wall -Wextra 37 | LOCAL_MODULE:= camera2_test 38 | LOCAL_MODULE_STEM_32 := camera2_test 39 | LOCAL_MODULE_STEM_64 := camera2_test64 40 | LOCAL_MULTILIB := both 41 | LOCAL_MODULE_TAGS := tests 42 | 43 | include $(BUILD_NATIVE_TEST) 44 | -------------------------------------------------------------------------------- /tests/camera2/ForkedTests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include "TestExtensions.h" 22 | 23 | namespace android { 24 | namespace camera2 { 25 | namespace tests { 26 | 27 | // Intentionally disabled since 2 of these tests are supposed to fail 28 | class DISABLED_ForkedTest : public ::testing::Test { 29 | 30 | virtual void SetUp() { 31 | TEST_EXTENSION_FORKING_SET_UP; 32 | } 33 | 34 | virtual void TearDown() { 35 | TEST_EXTENSION_FORKING_TEAR_DOWN; 36 | } 37 | }; 38 | 39 | // intentionally fail 40 | TEST_F(DISABLED_ForkedTest, FailCrash) { 41 | TEST_EXTENSION_FORKING_INIT; 42 | abort(); 43 | } 44 | 45 | TEST_F(DISABLED_ForkedTest, SucceedNormal) { 46 | TEST_EXTENSION_FORKING_INIT; 47 | 48 | EXPECT_TRUE(true); 49 | } 50 | 51 | // intentionally fail 52 | TEST_F(DISABLED_ForkedTest, FailNormal) { 53 | TEST_EXTENSION_FORKING_INIT; 54 | 55 | EXPECT_TRUE(false); 56 | } 57 | 58 | } 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /tests/camera2/TestExtensions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __ANDROID_HAL_CAMERA2_TESTS_EXTENSIONS__ 18 | #define __ANDROID_HAL_CAMERA2_TESTS_EXTENSIONS__ 19 | 20 | #include "TestForkerEventListener.h" 21 | #include "TestSettings.h" 22 | 23 | // Use at the beginning of each Test::SetUp() impl 24 | #define TEST_EXTENSION_FORKING_SET_UP \ 25 | do { \ 26 | if (TEST_EXTENSION_FORKING_ENABLED) { \ 27 | if (!TestForkerEventListener::mIsForked) { \ 28 | return; \ 29 | } \ 30 | } \ 31 | } while (false) \ 32 | 33 | // Use at the beginning of each Test::TearDown() impl 34 | #define TEST_EXTENSION_FORKING_TEAR_DOWN TEST_EXTENSION_FORKING_SET_UP 35 | 36 | // Use at the beginning of each Test::Test constructor 37 | #define TEST_EXTENSION_FORKING_CONSTRUCTOR TEST_EXTENSION_FORKING_SET_UP 38 | 39 | // Use at the beginning of each Test::~Test destructor 40 | #define TEST_EXTENSION_FORKING_DESTRUCTOR TEST_EXTENSION_FORKING_TEAR_DOWN 41 | 42 | // Use at the beginning of each test body, e.g. TEST(x,y), TEST_F(x,y), etc 43 | #define TEST_EXTENSION_FORKING_INIT \ 44 | do { \ 45 | TEST_EXTENSION_FORKING_SET_UP; \ 46 | if (HasFatalFailure()) return; \ 47 | } while(false) \ 48 | 49 | // Are we running each test by forking it? 50 | #define TEST_EXTENSION_FORKING_ENABLED \ 51 | (android::camera2::tests::TestSettings::ForkingEnabled()) 52 | 53 | 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /tests/camera2/TestForkerEventListener.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include "TestForkerEventListener.h" 25 | #include "TestExtensions.h" 26 | 27 | #define DEBUG_TEST_FORKER_EVENT_LISTENER 0 28 | 29 | #define RETURN_CODE_PASSED 0 30 | #define RETURN_CODE_FAILED 1 31 | 32 | namespace android { 33 | namespace camera2 { 34 | namespace tests { 35 | 36 | bool TestForkerEventListener::mIsForked = false; 37 | 38 | TestForkerEventListener::TestForkerEventListener() { 39 | mIsForked = false; 40 | mHasSucceeded = true; 41 | mTermSignal = 0; 42 | } 43 | 44 | // Called before a test starts. 45 | void TestForkerEventListener::OnTestStart(const ::testing::TestInfo&) { 46 | 47 | if (!TEST_EXTENSION_FORKING_ENABLED) { 48 | return; 49 | } 50 | 51 | pid_t childPid = fork(); 52 | if (childPid != 0) { 53 | int status; 54 | waitpid(childPid, &status, /*options*/0); 55 | 56 | // terminated normally? 57 | mHasSucceeded = WIFEXITED(status); 58 | // terminate with return code 0 = test passed, 1 = test failed 59 | if (mHasSucceeded) { 60 | mHasSucceeded = WEXITSTATUS(status) == RETURN_CODE_PASSED; 61 | } else if (WIFSIGNALED(status)) { 62 | mTermSignal = WTERMSIG(status); 63 | } 64 | 65 | /* the test is then skipped by inserting the various 66 | TEST_EXTENSION_ macros in TestExtensions.h */ 67 | 68 | } else { 69 | mIsForked = true; 70 | } 71 | } 72 | 73 | // Called after a failed assertion or a SUCCEED() invocation. 74 | void TestForkerEventListener::OnTestPartResult( 75 | const ::testing::TestPartResult& test_part_result) { 76 | 77 | if (DEBUG_TEST_FORKER_EVENT_LISTENER) { 78 | printf("%s in %s:%d\n%s\n", 79 | test_part_result.failed() ? "*** Failure" : "Success", 80 | test_part_result.file_name(), 81 | test_part_result.line_number(), 82 | test_part_result.summary()); 83 | } 84 | } 85 | 86 | // Called after a test ends. 87 | void TestForkerEventListener::OnTestEnd(const ::testing::TestInfo& test_info) { 88 | 89 | if (!TEST_EXTENSION_FORKING_ENABLED) { 90 | return; 91 | } 92 | 93 | if (mIsForked) { 94 | exit(test_info.result()->Passed() 95 | ? RETURN_CODE_PASSED : RETURN_CODE_FAILED); 96 | } else if (!mHasSucceeded && mTermSignal != 0) { 97 | 98 | printf("*** Test %s.%s crashed with signal = %s\n", 99 | test_info.test_case_name(), test_info.name(), 100 | strsignal(mTermSignal)); 101 | } 102 | 103 | //TODO: overload the default event listener to suppress this message 104 | // dynamically (e.g. by skipping OnTestPartResult after OnTestEnd ) 105 | 106 | // trigger a test failure if the child has failed 107 | if (!mHasSucceeded) { 108 | ADD_FAILURE(); 109 | } 110 | mTermSignal = 0; 111 | } 112 | 113 | 114 | } 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /tests/camera2/TestForkerEventListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __ANDROID_HAL_CAMERA2_TESTS_FORKER_EVENT_LISTENER__ 18 | #define __ANDROID_HAL_CAMERA2_TESTS_FORKER_EVENT_LISTENER__ 19 | 20 | #include 21 | 22 | namespace android { 23 | namespace camera2 { 24 | namespace tests { 25 | 26 | // Fork before each test runs. 27 | class TestForkerEventListener : public ::testing::EmptyTestEventListener { 28 | 29 | public: 30 | 31 | TestForkerEventListener(); 32 | 33 | private: 34 | 35 | // Called before a test starts. 36 | virtual void OnTestStart(const ::testing::TestInfo& test_info); 37 | 38 | // Called after a failed assertion or a SUCCEED() invocation. 39 | virtual void OnTestPartResult( 40 | const ::testing::TestPartResult& test_part_result); 41 | 42 | // Called after a test ends. 43 | virtual void OnTestEnd(const ::testing::TestInfo& test_info); 44 | 45 | bool mHasSucceeded; 46 | int mTermSignal; 47 | 48 | public: 49 | // do not read directly. use TEST_EXTENSION macros instead 50 | static bool mIsForked; 51 | }; 52 | 53 | } 54 | } 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /tests/camera2/TestSettings.h: -------------------------------------------------------------------------------- 1 | /* 2 | :qa 3 | * Copyright (C) 2012 The Android Open Source Project 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef __ANDROID_HAL_CAMERA2_TESTS_SETTINGS__ 19 | #define __ANDROID_HAL_CAMERA2_TESTS_SETTINGS__ 20 | 21 | namespace android { 22 | namespace camera2 { 23 | namespace tests { 24 | 25 | class TestSettings { 26 | 27 | public: 28 | // --forking-disabled, false by default 29 | static bool ForkingDisabled(); 30 | 31 | // reverse of --forking-disabled (not a flag), true by default 32 | static bool ForkingEnabled(); 33 | 34 | // --device-id, 0 by default 35 | static int DeviceId(); 36 | 37 | // returns false if usage should be printed and we should exit early 38 | static bool ParseArgs(int argc, char* const argv[]); 39 | 40 | // print usage/help list of commands (non-gtest) 41 | static void PrintUsage(); 42 | 43 | private: 44 | TestSettings(); 45 | ~TestSettings(); 46 | 47 | static bool mForkingDisabled; 48 | static int mDeviceId; 49 | static char* const* mArgv; 50 | }; 51 | 52 | } 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /tests/camera2/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include "TestForkerEventListener.h" 19 | #include "TestSettings.h" 20 | 21 | using android::camera2::tests::TestForkerEventListener; 22 | using android::camera2::tests::TestSettings; 23 | 24 | int main(int argc, char **argv) { 25 | 26 | bool printUsage = !TestSettings::ParseArgs(argc, argv); 27 | 28 | ::testing::InitGoogleTest(&argc, argv); 29 | 30 | if (printUsage) { 31 | TestSettings::PrintUsage(); 32 | return 0; 33 | } 34 | 35 | // Gets hold of the event listener list. 36 | ::testing::TestEventListeners& listeners = 37 | ::testing::UnitTest::GetInstance()->listeners(); 38 | // Adds a listener to the end. Google Test takes the ownership. 39 | listeners.Append(new TestForkerEventListener()); 40 | 41 | int ret = RUN_ALL_TESTS(); 42 | 43 | return ret; 44 | } 45 | -------------------------------------------------------------------------------- /tests/camera3/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES:= \ 5 | camera3tests.cpp \ 6 | 7 | LOCAL_SHARED_LIBRARIES := \ 8 | liblog \ 9 | libhardware \ 10 | libcamera_metadata \ 11 | 12 | LOCAL_C_INCLUDES += \ 13 | system/media/camera/include \ 14 | 15 | LOCAL_CFLAGS += -Wall -Wextra 16 | 17 | LOCAL_MODULE:= camera3_tests 18 | LOCAL_MODULE_TAGS := tests 19 | 20 | include $(BUILD_NATIVE_TEST) 21 | -------------------------------------------------------------------------------- /tests/camera3/camera3test_fixtures.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __ANDROID_HAL_CAMERA3_TEST_COMMON__ 18 | #define __ANDROID_HAL_CAMERA3_TEST_COMMON__ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace tests { 25 | 26 | static const int kMmaxCams = 2; 27 | static const uint16_t kVersion3_0 = HARDWARE_MODULE_API_VERSION(3, 0); 28 | 29 | class Camera3Module : public testing::Test { 30 | public: 31 | Camera3Module() : 32 | num_cams_(0), 33 | cam_module_(NULL) {} 34 | ~Camera3Module() {} 35 | protected: 36 | virtual void SetUp() { 37 | const hw_module_t *hw_module = NULL; 38 | ASSERT_EQ(0, hw_get_module(CAMERA_HARDWARE_MODULE_ID, &hw_module)) 39 | << "Can't get camera module"; 40 | ASSERT_TRUE(NULL != hw_module) 41 | << "hw_get_module didn't return a valid camera module"; 42 | 43 | cam_module_ = reinterpret_cast(hw_module); 44 | ASSERT_TRUE(NULL != cam_module_->get_number_of_cameras) 45 | << "get_number_of_cameras is not implemented"; 46 | num_cams_ = cam_module_->get_number_of_cameras(); 47 | } 48 | int num_cams() { return num_cams_; } 49 | const camera_module_t * cam_module() { return cam_module_; } 50 | private: 51 | int num_cams_; 52 | const camera_module_t *cam_module_; 53 | }; 54 | 55 | class Camera3Device : public Camera3Module { 56 | public: 57 | Camera3Device() : 58 | cam_device_(NULL) {} 59 | ~Camera3Device() {} 60 | protected: 61 | virtual void SetUp() { 62 | Camera3Module::SetUp(); 63 | hw_device_t *device = NULL; 64 | ASSERT_TRUE(NULL != cam_module()->common.methods->open) 65 | << "Camera open() is unimplemented"; 66 | ASSERT_EQ(0, cam_module()->common.methods->open( 67 | (const hw_module_t*)cam_module(), "0", &device)) 68 | << "Can't open camera device"; 69 | ASSERT_TRUE(NULL != device) 70 | << "Camera open() returned a NULL device"; 71 | ASSERT_LE(kVersion3_0, device->version) 72 | << "The device does not support HAL3"; 73 | cam_device_ = reinterpret_cast(device); 74 | } 75 | camera3_device_t* cam_device() { return cam_device_; } 76 | private: 77 | camera3_device *cam_device_; 78 | }; 79 | 80 | } // namespace tests 81 | 82 | #endif // __ANDROID_HAL_CAMERA3_TEST_COMMON__ 83 | -------------------------------------------------------------------------------- /tests/camera3/camera3tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include "camera3test_fixtures.h" 19 | 20 | namespace tests { 21 | 22 | TEST_F(Camera3Module, NumberOfCameras) { 23 | ASSERT_LT(0, num_cams()) << "No cameras found"; 24 | ASSERT_GE(kMmaxCams, num_cams()) << "Too many cameras found"; 25 | } 26 | 27 | TEST_F(Camera3Module, IsActiveArraySizeSubsetPixelArraySize) { 28 | for (int i = 0; i < num_cams(); ++i) { 29 | ASSERT_TRUE(NULL != cam_module()->get_camera_info) 30 | << "get_camera_info is not implemented"; 31 | 32 | camera_info info; 33 | ASSERT_EQ(0, cam_module()->get_camera_info(i, &info)) 34 | << "Can't get camera info for" << i; 35 | 36 | camera_metadata_entry entry; 37 | ASSERT_EQ(0, find_camera_metadata_entry( 38 | const_cast( 39 | info.static_camera_characteristics), 40 | ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, &entry)) 41 | << "Can't find the sensor pixel array size."; 42 | int pixel_array_w = entry.data.i32[0]; 43 | int pixel_array_h = entry.data.i32[1]; 44 | 45 | ASSERT_EQ(0, find_camera_metadata_entry( 46 | const_cast( 47 | info.static_camera_characteristics), 48 | ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, &entry)) 49 | << "Can't find the sensor active array size."; 50 | int active_array_w = entry.data.i32[0]; 51 | int active_array_h = entry.data.i32[1]; 52 | 53 | EXPECT_LE(active_array_h, pixel_array_h); 54 | EXPECT_LE(active_array_w, pixel_array_w); 55 | } 56 | } 57 | 58 | TEST_F(Camera3Device, DefaultSettingsStillCaptureHasAndroidControlMode) { 59 | ASSERT_TRUE(NULL != cam_device()->ops) << "Camera device ops are NULL"; 60 | const camera_metadata_t *default_settings = 61 | cam_device()->ops->construct_default_request_settings(cam_device(), 62 | CAMERA3_TEMPLATE_STILL_CAPTURE); 63 | ASSERT_TRUE(NULL != default_settings) << "Camera default settings are NULL"; 64 | camera_metadata_entry entry; 65 | ASSERT_EQ(0, find_camera_metadata_entry( 66 | const_cast(default_settings), 67 | ANDROID_CONTROL_MODE, &entry)) 68 | << "Can't find ANDROID_CONTROL_MODE in default settings."; 69 | } 70 | 71 | } // namespace tests 72 | -------------------------------------------------------------------------------- /tests/fingerprint/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES:= \ 5 | fingerprint_tests.cpp \ 6 | 7 | LOCAL_SHARED_LIBRARIES := \ 8 | liblog \ 9 | libhardware \ 10 | 11 | #LOCAL_C_INCLUDES += \ 12 | # system/media/camera/include \ 13 | 14 | LOCAL_CFLAGS += -Wall -Wextra 15 | 16 | LOCAL_MODULE:= fingerprint_tests 17 | LOCAL_MODULE_TAGS := tests 18 | 19 | include $(BUILD_NATIVE_TEST) 20 | -------------------------------------------------------------------------------- /tests/fingerprint/fingerprint_test_fixtures.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __ANDROID_HAL_FINGERPRINT_TEST_COMMON__ 18 | #define __ANDROID_HAL_FINGERPRINT_TEST_COMMON__ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace tests { 25 | 26 | static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(1, 0); 27 | 28 | class FingerprintModule : public testing::Test { 29 | public: 30 | FingerprintModule() : 31 | fp_module_(NULL) {} 32 | ~FingerprintModule() {} 33 | protected: 34 | virtual void SetUp() { 35 | const hw_module_t *hw_module = NULL; 36 | ASSERT_EQ(0, hw_get_module(FINGERPRINT_HARDWARE_MODULE_ID, &hw_module)) 37 | << "Can't get fingerprint module"; 38 | ASSERT_TRUE(NULL != hw_module) 39 | << "hw_get_module didn't return a valid fingerprint module"; 40 | 41 | fp_module_ = reinterpret_cast(hw_module); 42 | } 43 | const fingerprint_module_t* fp_module() { return fp_module_; } 44 | private: 45 | const fingerprint_module_t *fp_module_; 46 | }; 47 | 48 | class FingerprintDevice : public FingerprintModule { 49 | public: 50 | FingerprintDevice() : 51 | fp_device_(NULL) {} 52 | ~FingerprintDevice() {} 53 | protected: 54 | virtual void SetUp() { 55 | FingerprintModule::SetUp(); 56 | hw_device_t *device = NULL; 57 | ASSERT_TRUE(NULL != fp_module()->common.methods->open) 58 | << "Fingerprint open() is unimplemented"; 59 | ASSERT_EQ(0, fp_module()->common.methods->open( 60 | (const hw_module_t*)fp_module(), NULL, &device)) 61 | << "Can't open fingerprint device"; 62 | ASSERT_TRUE(NULL != device) 63 | << "Fingerprint open() returned a NULL device"; 64 | ASSERT_EQ(kVersion, device->version) 65 | << "Unsupported version"; 66 | fp_device_ = reinterpret_cast(device); 67 | } 68 | fingerprint_device_t* fp_device() { return fp_device_; } 69 | private: 70 | fingerprint_device_t *fp_device_; 71 | }; 72 | 73 | } // namespace tests 74 | 75 | #endif // __ANDROID_HAL_FINGERPRINT_TEST_COMMON__ 76 | -------------------------------------------------------------------------------- /tests/fingerprint/fingerprint_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include "fingerprint_test_fixtures.h" 19 | 20 | namespace tests { 21 | 22 | TEST_F(FingerprintDevice, isThereEnroll) { 23 | ASSERT_TRUE(NULL != fp_device()->enroll) 24 | << "enroll() function is not implemented"; 25 | } 26 | 27 | TEST_F(FingerprintDevice, isTherePreEnroll) { 28 | ASSERT_TRUE(NULL != fp_device()->pre_enroll) 29 | << "pre_enroll() function is not implemented"; 30 | } 31 | 32 | TEST_F(FingerprintDevice, isThereGetAuthenticatorId) { 33 | ASSERT_TRUE(NULL != fp_device()->get_authenticator_id) 34 | << "get_authenticator_id() function is not implemented"; 35 | } 36 | 37 | TEST_F(FingerprintDevice, isThereCancel) { 38 | ASSERT_TRUE(NULL != fp_device()->cancel) 39 | << "cancel() function is not implemented"; 40 | } 41 | 42 | TEST_F(FingerprintDevice, isThereRemove) { 43 | ASSERT_TRUE(NULL != fp_device()->remove) 44 | << "remove() function is not implemented"; 45 | } 46 | 47 | TEST_F(FingerprintDevice, isThereAuthenticate) { 48 | ASSERT_TRUE(NULL != fp_device()->authenticate) 49 | << "authenticate() function is not implemented"; 50 | } 51 | 52 | TEST_F(FingerprintDevice, isThereSetActiveGroup) { 53 | ASSERT_TRUE(NULL != fp_device()->set_active_group) 54 | << "set_active_group() function is not implemented"; 55 | } 56 | 57 | TEST_F(FingerprintDevice, isThereSetNotify) { 58 | ASSERT_TRUE(NULL != fp_device()->set_notify) 59 | << "set_notify() function is not implemented"; 60 | } 61 | 62 | } // namespace tests 63 | -------------------------------------------------------------------------------- /tests/hardware/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_MODULE := static-hal-check 5 | LOCAL_SRC_FILES := struct-size.cpp struct-offset.cpp struct-last.cpp 6 | LOCAL_SHARED_LIBRARIES := libhardware 7 | LOCAL_CFLAGS := -std=gnu++11 -O0 8 | 9 | LOCAL_C_INCLUDES += \ 10 | system/media/camera/include 11 | 12 | include $(BUILD_STATIC_LIBRARY) 13 | -------------------------------------------------------------------------------- /tests/hardware/struct-last.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define GET_PADDING(align, size) (((align) - ((size) % (align))) % (align)) 29 | 30 | #define CHECK_LAST_MEMBER(type, member) \ 31 | do { \ 32 | static constexpr size_t calc_size = offsetof(type, member) + sizeof(((type *)0)->member); \ 33 | static_assert(sizeof(type) == calc_size + GET_PADDING(alignof(type), calc_size), \ 34 | "" #member " is not the last element of " #type); \ 35 | } while (0) 36 | 37 | void CheckSizes(void) { 38 | //Types defined in hardware.h 39 | CHECK_LAST_MEMBER(hw_module_t, reserved); 40 | CHECK_LAST_MEMBER(hw_device_t, close); 41 | 42 | //Types defined in sensors.h 43 | CHECK_LAST_MEMBER(sensors_vec_t, reserved); 44 | CHECK_LAST_MEMBER(sensors_event_t, reserved1); 45 | CHECK_LAST_MEMBER(struct sensor_t, reserved); 46 | CHECK_LAST_MEMBER(sensors_poll_device_1_t, reserved_procs); 47 | 48 | //Types defined in fb.h 49 | CHECK_LAST_MEMBER(framebuffer_device_t, reserved_proc); 50 | 51 | //Types defined in hwcomposer.h 52 | CHECK_LAST_MEMBER(hwc_layer_1_t, reserved); 53 | CHECK_LAST_MEMBER(hwc_composer_device_1_t, reserved_proc); 54 | 55 | //Types defined in gralloc.h 56 | CHECK_LAST_MEMBER(gralloc_module_t, reserved_proc); 57 | CHECK_LAST_MEMBER(alloc_device_t, reserved_proc); 58 | 59 | //Types defined in consumerir.h 60 | CHECK_LAST_MEMBER(consumerir_device_t, reserved); 61 | 62 | //Types defined in camera_common.h 63 | CHECK_LAST_MEMBER(vendor_tag_ops_t, reserved); 64 | CHECK_LAST_MEMBER(camera_module_t, reserved); 65 | 66 | //Types defined in camera3.h 67 | CHECK_LAST_MEMBER(camera3_device_ops_t, reserved); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /tests/hardware/struct-size.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | template static constexpr size_t CheckSizeHelper(size_t, size_t); 29 | 30 | template<> constexpr size_t CheckSizeHelper<4>(size_t size32, size_t /* size64 */) { 31 | return size32; 32 | } 33 | 34 | template<> constexpr size_t CheckSizeHelper<8>(size_t /* size32 */, size_t size64) { 35 | return size64; 36 | } 37 | 38 | template static void CheckTypeSize() { 39 | const size_t mySize = CheckSizeHelper(size32, size64); 40 | 41 | static_assert(sizeof(T) == mySize, "struct is the wrong size"); 42 | } 43 | 44 | void CheckSizes(void) { 45 | //Types defined in hardware.h 46 | CheckTypeSize(); 47 | CheckTypeSize(); 48 | 49 | //Types defined in sensors.h 50 | CheckTypeSize(); 51 | CheckTypeSize(); 52 | CheckTypeSize(); 53 | CheckTypeSize(); 54 | 55 | //Types defined in fb.h 56 | CheckTypeSize(); 57 | 58 | //Types defined in hwcomposer.h 59 | CheckTypeSize(); 60 | CheckTypeSize(); 61 | 62 | //Types defined in gralloc.h 63 | CheckTypeSize(); 64 | CheckTypeSize(); 65 | 66 | //Types defined in consumerir.h 67 | CheckTypeSize(); 68 | 69 | //Types defined in camera_common.h 70 | CheckTypeSize(); 71 | CheckTypeSize(); 72 | 73 | //Types defined in camera3.h 74 | CheckTypeSize(); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /tests/hwc/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := libcnativewindow 5 | LOCAL_SRC_FILES := cnativewindow.c util.c 6 | LOCAL_CFLAGS := -Wno-unused-parameter 7 | include $(BUILD_STATIC_LIBRARY) 8 | 9 | include $(CLEAR_VARS) 10 | LOCAL_MODULE := hwc-test-arrows 11 | LOCAL_SRC_FILES := test-arrows.c 12 | LOCAL_STATIC_LIBRARIES := libcnativewindow 13 | LOCAL_SHARED_LIBRARIES := libEGL libGLESv2 libdl libhardware 14 | LOCAL_CFLAGS := -DGL_GLEXT_PROTOTYPES 15 | include $(BUILD_EXECUTABLE) 16 | -------------------------------------------------------------------------------- /tests/hwc/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _GL_UTIL_H_ 18 | #define _GL_UTIL_H_ 19 | 20 | /* convenience */ 21 | 22 | GLuint load_program(const char *vert_src, const char *frag_src); 23 | void matrix_init_ortho(GLfloat *m, float w, float h); 24 | 25 | /* context setup / teardown */ 26 | 27 | int egl_create(EGLDisplay *_display, EGLSurface *_surface, int *_w, int *_h); 28 | void egl_destroy(EGLDisplay display, EGLSurface surface); 29 | 30 | /* internals needed by util.c */ 31 | 32 | struct CNativeWindow; 33 | struct CNativeWindow *cnw_create(void); 34 | void cnw_destroy(struct CNativeWindow *win); 35 | void cnw_info(struct CNativeWindow *win, 36 | unsigned *w, unsigned *h, unsigned *fmt); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /tests/input/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | include $(call all-makefiles-under,$(LOCAL_PATH)) 20 | -------------------------------------------------------------------------------- /tests/input/evdev/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_C_INCLUDES += hardware/libhardware/modules/input/evdev 5 | LOCAL_C_INCLUDES += $(TOP)/external/gmock/include 6 | 7 | LOCAL_SRC_FILES:= \ 8 | BitUtils_test.cpp \ 9 | InputDevice_test.cpp \ 10 | InputHub_test.cpp \ 11 | InputMocks.cpp \ 12 | MouseInputMapper_test.cpp \ 13 | SwitchInputMapper_test.cpp \ 14 | TestHelpers.cpp 15 | 16 | LOCAL_STATIC_LIBRARIES := libgmock 17 | 18 | LOCAL_SHARED_LIBRARIES := \ 19 | libinput_evdev \ 20 | liblog \ 21 | libutils 22 | 23 | LOCAL_CLANG := true 24 | LOCAL_CFLAGS += -Wall -Wextra -Wno-unused-parameter 25 | LOCAL_CPPFLAGS += -std=c++14 26 | 27 | # TestHelpers uses mktemp. As the path is given to TempFile, we can't do too much 28 | # here (e.g., use mkdtemp first). At least races will lead to an early failure, as 29 | # mkfifo fails on existing files. 30 | LOCAL_CFLAGS += -Wno-deprecated-declarations 31 | 32 | LOCAL_MODULE := libinput_evdevtests 33 | LOCAL_MODULE_TAGS := tests 34 | 35 | include $(BUILD_NATIVE_TEST) 36 | -------------------------------------------------------------------------------- /tests/input/evdev/BitUtils_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "BitUtils.h" 18 | 19 | #include 20 | 21 | namespace android { 22 | namespace tests { 23 | 24 | TEST(BitInRange, testInvalidRange) { 25 | uint8_t arr[2] = { 0xff, 0xff }; 26 | EXPECT_FALSE(testBitInRange(arr, 0, 0)); 27 | EXPECT_FALSE(testBitInRange(arr, 1, 0)); 28 | } 29 | 30 | TEST(BitInRange, testNoBits) { 31 | uint8_t arr[1]; 32 | arr[0] = 0; 33 | EXPECT_FALSE(testBitInRange(arr, 0, 8)); 34 | } 35 | 36 | TEST(BitInRange, testOneBit) { 37 | uint8_t arr[1]; 38 | for (int i = 0; i < 8; ++i) { 39 | arr[0] = 1 << i; 40 | EXPECT_TRUE(testBitInRange(arr, 0, 8)); 41 | } 42 | } 43 | 44 | TEST(BitInRange, testZeroStart) { 45 | uint8_t arr[1] = { 0x10 }; 46 | for (int i = 0; i < 5; ++i) { 47 | EXPECT_FALSE(testBitInRange(arr, 0, i)); 48 | } 49 | for (int i = 5; i <= 8; ++i) { 50 | EXPECT_TRUE(testBitInRange(arr, 0, i)); 51 | } 52 | } 53 | 54 | TEST(BitInRange, testByteBoundaryEnd) { 55 | uint8_t arr[1] = { 0x10 }; 56 | for (int i = 0; i < 5; ++i) { 57 | EXPECT_TRUE(testBitInRange(arr, i, 8)); 58 | } 59 | for (int i = 5; i <= 8; ++i) { 60 | EXPECT_FALSE(testBitInRange(arr, i, 8)); 61 | } 62 | } 63 | 64 | TEST(BitInRange, testMultiByteArray) { 65 | // bits set: 11 and 16 66 | uint8_t arr[3] = { 0x00, 0x08, 0x01 }; 67 | for (int start = 0; start < 24; ++start) { 68 | for (int end = start + 1; end <= 24; ++end) { 69 | if (start > 16 || end <= 11 || (start > 11 && end <= 16)) { 70 | EXPECT_FALSE(testBitInRange(arr, start, end)) 71 | << "range = (" << start << ", " << end << ")"; 72 | } else { 73 | EXPECT_TRUE(testBitInRange(arr, start, end)) 74 | << "range = (" << start << ", " << end << ")"; 75 | } 76 | } 77 | } 78 | } 79 | 80 | } // namespace tests 81 | } // namespace android 82 | -------------------------------------------------------------------------------- /tests/input/evdev/MockInputHost.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_MOCK_INPUT_HOST_H_ 18 | #define ANDROID_MOCK_INPUT_HOST_H_ 19 | 20 | #include "InputHost.h" 21 | 22 | #include "gmock/gmock.h" 23 | 24 | 25 | namespace android { 26 | namespace tests { 27 | 28 | class MockInputReport : public InputReport { 29 | public: 30 | MockInputReport() : InputReport(nullptr, {}, nullptr) {} 31 | MOCK_METHOD4(setIntUsage, void(InputCollectionId id, InputUsage usage, int32_t value, 32 | int32_t arityIndex)); 33 | MOCK_METHOD4(setBoolUsage, void(InputCollectionId id, InputUsage usage, bool value, 34 | int32_t arityIndex)); 35 | MOCK_METHOD1(reportEvent, void(InputDeviceHandle* d)); 36 | }; 37 | 38 | class MockInputReportDefinition : public InputReportDefinition { 39 | public: 40 | MockInputReportDefinition() : InputReportDefinition(nullptr, {}, nullptr) {} 41 | MOCK_METHOD2(addCollection, void(InputCollectionId id, int32_t arity)); 42 | MOCK_METHOD5(declareUsage, void(InputCollectionId id, InputUsage usage, int32_t min, 43 | int32_t max, float resolution)); 44 | MOCK_METHOD3(declareUsages, void(InputCollectionId id, InputUsage* usage, size_t usageCount)); 45 | MOCK_METHOD0(allocateReport, InputReport*()); 46 | }; 47 | 48 | class MockInputDeviceDefinition : public InputDeviceDefinition { 49 | public: 50 | MockInputDeviceDefinition() : InputDeviceDefinition(nullptr, {}, nullptr) {} 51 | MOCK_METHOD1(addReport, void(InputReportDefinition* r)); 52 | }; 53 | 54 | class MockInputProperty : public InputProperty { 55 | public: 56 | MockInputProperty() : InputProperty(nullptr, {}, nullptr) {} 57 | virtual ~MockInputProperty() {} 58 | MOCK_CONST_METHOD0(getKey, const char*()); 59 | MOCK_CONST_METHOD0(getValue, const char*()); 60 | }; 61 | 62 | class MockInputPropertyMap : public InputPropertyMap { 63 | public: 64 | MockInputPropertyMap() : InputPropertyMap(nullptr, {}, nullptr) {} 65 | virtual ~MockInputPropertyMap() {} 66 | MOCK_CONST_METHOD1(getDeviceProperty, InputProperty*(const char* key)); 67 | MOCK_CONST_METHOD1(freeDeviceProperty, void(InputProperty* property)); 68 | }; 69 | 70 | class MockInputHost : public InputHostInterface { 71 | public: 72 | MOCK_METHOD5(createDeviceIdentifier, InputDeviceIdentifier*( 73 | const char* name, int32_t productId, int32_t vendorId, InputBus bus, 74 | const char* uniqueId)); 75 | MOCK_METHOD0(createDeviceDefinition, InputDeviceDefinition*()); 76 | MOCK_METHOD0(createInputReportDefinition, InputReportDefinition*()); 77 | MOCK_METHOD0(createOutputReportDefinition, InputReportDefinition*()); 78 | MOCK_METHOD1(freeReportDefinition, void(InputReportDefinition* reportDef)); 79 | MOCK_METHOD2(registerDevice, InputDeviceHandle*(InputDeviceIdentifier* id, 80 | InputDeviceDefinition* d)); 81 | MOCK_METHOD1(unregisterDevice, void(InputDeviceHandle* handle)); 82 | MOCK_METHOD1(getDevicePropertyMap, InputPropertyMap*(InputDeviceIdentifier* id)); 83 | MOCK_METHOD1(freeDevicePropertyMap, void(InputPropertyMap* propertyMap)); 84 | }; 85 | 86 | } // namespace tests 87 | } // namespace android 88 | 89 | #endif // ANDROID_MOCK_INPUT_HOST_H_ 90 | -------------------------------------------------------------------------------- /tests/input/evdev/SwitchInputMapper_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "InputMocks.h" 24 | #include "MockInputHost.h" 25 | #include "SwitchInputMapper.h" 26 | 27 | using ::testing::_; 28 | using ::testing::Args; 29 | using ::testing::InSequence; 30 | using ::testing::Return; 31 | using ::testing::UnorderedElementsAre; 32 | 33 | namespace android { 34 | namespace tests { 35 | 36 | class SwitchInputMapperTest : public ::testing::Test { 37 | protected: 38 | virtual void SetUp() override { 39 | mMapper = std::make_unique(); 40 | } 41 | 42 | MockInputHost mHost; 43 | std::unique_ptr mMapper; 44 | }; 45 | 46 | TEST_F(SwitchInputMapperTest, testConfigureDevice) { 47 | MockInputReportDefinition reportDef; 48 | MockInputDeviceNode deviceNode; 49 | deviceNode.addSwitch(SW_LID); 50 | deviceNode.addSwitch(SW_CAMERA_LENS_COVER); 51 | 52 | EXPECT_CALL(reportDef, addCollection(INPUT_COLLECTION_ID_SWITCH, 1)); 53 | EXPECT_CALL(reportDef, declareUsages(INPUT_COLLECTION_ID_SWITCH, _, 2)) 54 | .With(Args<1,2>(UnorderedElementsAre(INPUT_USAGE_SWITCH_LID, 55 | INPUT_USAGE_SWITCH_CAMERA_LENS_COVER))); 56 | 57 | EXPECT_TRUE(mMapper->configureInputReport(&deviceNode, &reportDef)); 58 | } 59 | 60 | TEST_F(SwitchInputMapperTest, testConfigureDevice_noSwitches) { 61 | MockInputReportDefinition reportDef; 62 | MockInputDeviceNode deviceNode; 63 | 64 | EXPECT_CALL(reportDef, addCollection(_, _)).Times(0); 65 | EXPECT_CALL(reportDef, declareUsages(_, _, _)).Times(0); 66 | 67 | EXPECT_FALSE(mMapper->configureInputReport(&deviceNode, &reportDef)); 68 | } 69 | 70 | TEST_F(SwitchInputMapperTest, testProcessInput) { 71 | MockInputReportDefinition reportDef; 72 | MockInputDeviceNode deviceNode; 73 | deviceNode.addSwitch(SW_LID); 74 | 75 | EXPECT_CALL(reportDef, addCollection(_, _)); 76 | EXPECT_CALL(reportDef, declareUsages(_, _, _)); 77 | 78 | mMapper->configureInputReport(&deviceNode, &reportDef); 79 | 80 | MockInputReport report; 81 | EXPECT_CALL(reportDef, allocateReport()) 82 | .WillOnce(Return(&report)); 83 | 84 | { 85 | // Test two switch events in order 86 | InSequence s; 87 | EXPECT_CALL(report, setBoolUsage(INPUT_COLLECTION_ID_SWITCH, INPUT_USAGE_SWITCH_LID, 1, 0)); 88 | EXPECT_CALL(report, reportEvent(_)); 89 | EXPECT_CALL(report, setBoolUsage(INPUT_COLLECTION_ID_SWITCH, INPUT_USAGE_SWITCH_LID, 0, 0)); 90 | EXPECT_CALL(report, reportEvent(_)); 91 | } 92 | 93 | InputEvent events[] = { 94 | {0, EV_SW, SW_LID, 1}, 95 | {1, EV_SYN, SYN_REPORT, 0}, 96 | {2, EV_SW, SW_LID, 0}, 97 | {3, EV_SYN, SYN_REPORT, 0}, 98 | }; 99 | for (auto e : events) { 100 | mMapper->process(e); 101 | } 102 | } 103 | 104 | } // namespace tests 105 | } // namespace android 106 | 107 | -------------------------------------------------------------------------------- /tests/input/evdev/TestHelpers.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "TestHelpers" 18 | #define LOG_NDEBUG 0 19 | 20 | #include "TestHelpers.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | namespace android { 32 | 33 | static const char kTmpDirTemplate[] = "/data/local/tmp/XXXXXX"; 34 | 35 | TempFile::TempFile(const char* path) { 36 | bool needTrailingSlash = path[strlen(path) - 1] != '/'; 37 | // name = path + XXXXXX + \0 38 | size_t nameLen = strlen(path) + 6 + 1; 39 | if (needTrailingSlash) nameLen++; 40 | 41 | mName = new char[nameLen]; 42 | strcpy(mName, path); 43 | if (needTrailingSlash) { 44 | strcat(mName, "/"); 45 | } 46 | strcat(mName, "XXXXXX"); 47 | mName = mktemp(mName); 48 | LOG_FATAL_IF(mName == nullptr, "could not create temp filename %s. errno=%d", mName, errno); 49 | 50 | int result = TEMP_FAILURE_RETRY(mkfifo(mName, S_IRWXU)); 51 | LOG_FATAL_IF(result < 0, "could not create fifo %s. errno=%d", mName, errno); 52 | 53 | mFd = TEMP_FAILURE_RETRY(open(mName, O_RDWR | O_NONBLOCK)); 54 | LOG_FATAL_IF(mFd < 0, "could not open fifo %s. errno=%d", mName, errno); 55 | } 56 | 57 | TempFile::~TempFile() { 58 | if (unlink(mName) < 0) { 59 | ALOGE("could not unlink %s. errno=%d", mName, errno); 60 | } 61 | if (close(mFd) < 0) { 62 | ALOGE("could not close %d. errno=%d", mFd, errno); 63 | } 64 | delete[] mName; 65 | } 66 | 67 | TempDir::TempDir() { 68 | mName = new char[sizeof(kTmpDirTemplate)]; 69 | strcpy(mName, kTmpDirTemplate); 70 | mName = mkdtemp(mName); 71 | LOG_FATAL_IF(mName == nullptr, "could not allocate tempdir %s", mName); 72 | } 73 | 74 | TempDir::~TempDir() { 75 | auto tmpDir = opendir(mName); 76 | while (auto entry = readdir(tmpDir)) { 77 | if (strcmp(entry->d_name, ".") == 0 || 78 | strcmp(entry->d_name, "..") == 0) { 79 | continue; 80 | } 81 | ALOGD("stale file %s, removing", entry->d_name); 82 | unlink(entry->d_name); 83 | } 84 | closedir(tmpDir); 85 | rmdir(mName); 86 | delete mName; 87 | } 88 | 89 | TempFile* TempDir::newTempFile() { 90 | return new TempFile(mName); 91 | } 92 | 93 | } // namespace android 94 | -------------------------------------------------------------------------------- /tests/input/evdev/TestHelpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_TEST_HELPERS_H_ 18 | #define ANDROID_TEST_HELPERS_H_ 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | 25 | /** 26 | * Runs the given function after the specified delay. 27 | * NOTE: if the std::future returned from std::async is not bound, this function 28 | * will block until the task completes. This is almost certainly NOT what you 29 | * want, so save the return value from delay_async into a variable: 30 | * 31 | * auto f = delay_async(100ms, []{ ALOGD("Hello world"); }); 32 | */ 33 | template 34 | decltype(auto) delay_async(Duration&& delay, Function&& task) 35 | { 36 | return std::async(std::launch::async, [=]{ std::this_thread::sleep_for(delay); task(); }); 37 | } 38 | 39 | /** 40 | * Creates and opens a temporary file at the given path. The file is unlinked 41 | * and closed in the destructor. 42 | */ 43 | class TempFile { 44 | public: 45 | TempFile(const char* path); 46 | ~TempFile(); 47 | 48 | // No copy or assign 49 | TempFile(const TempFile&) = delete; 50 | TempFile& operator=(const TempFile&) = delete; 51 | 52 | const char* getName() const { return mName; } 53 | int getFd() const { return mFd; } 54 | 55 | private: 56 | char* mName; 57 | int mFd; 58 | }; 59 | 60 | /** 61 | * Creates a temporary directory that can create temporary files. The directory 62 | * is emptied and deleted in the destructor. 63 | */ 64 | class TempDir { 65 | public: 66 | TempDir(); 67 | ~TempDir(); 68 | 69 | // No copy or assign 70 | TempDir(const TempDir&) = delete; 71 | TempDir& operator=(const TempDir&) = delete; 72 | 73 | const char* getName() const { return mName; } 74 | 75 | TempFile* newTempFile(); 76 | 77 | private: 78 | char* mName; 79 | }; 80 | 81 | } // namespace android 82 | 83 | #endif // ANDROID_TEST_HELPERS_H_ 84 | -------------------------------------------------------------------------------- /tests/keymaster/Android.mk: -------------------------------------------------------------------------------- 1 | # Build the keymaster unit tests 2 | 3 | LOCAL_PATH:= $(call my-dir) 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_SRC_FILES:= \ 7 | keymaster_test.cpp 8 | 9 | LOCAL_SHARED_LIBRARIES := \ 10 | liblog \ 11 | libutils \ 12 | libcrypto \ 13 | libhardware \ 14 | 15 | LOCAL_MODULE := keymaster_test 16 | 17 | LOCAL_MODULE_TAGS := tests 18 | 19 | include $(BUILD_NATIVE_TEST) 20 | -------------------------------------------------------------------------------- /tests/nusensors/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES:= \ 5 | nusensors.cpp 6 | 7 | LOCAL_SHARED_LIBRARIES := \ 8 | libcutils libhardware 9 | 10 | LOCAL_MODULE:= test-nusensors 11 | 12 | LOCAL_MODULE_TAGS := optional 13 | 14 | include $(BUILD_EXECUTABLE) 15 | -------------------------------------------------------------------------------- /tests/vehicle/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 The Android Open Source Project 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | LOCAL_PATH:= $(call my-dir) 17 | 18 | # Build native tests. 19 | include $(CLEAR_VARS) 20 | 21 | LOCAL_SRC_FILES:= \ 22 | vehicle_tests.cpp \ 23 | 24 | LOCAL_SHARED_LIBRARIES := \ 25 | liblog \ 26 | libhardware \ 27 | 28 | LOCAL_CFLAGS += -Wall -Wextra 29 | 30 | LOCAL_MODULE:= vehicle_tests 31 | LOCAL_MODULE_TAGS := tests 32 | 33 | include $(BUILD_NATIVE_TEST) 34 | 35 | # Build HAL command line utility. 36 | include $(CLEAR_VARS) 37 | 38 | LOCAL_SRC_FILES := vehicle-hal-tool.c 39 | LOCAL_MODULE := vehicle-hal-tool 40 | LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror 41 | LOCAL_MODULE_TAGS := tests 42 | 43 | LOCAL_SHARED_LIBRARIES := libcutils libhardware liblog 44 | 45 | include $(BUILD_EXECUTABLE) 46 | -------------------------------------------------------------------------------- /tests/vehicle/README: -------------------------------------------------------------------------------- 1 | What does this document tell? 2 | 3 | This document details how to use the vehicle service if you are implementhing 4 | HAL. It lists the various places to look for code and how to build and test the 5 | code on your own dev device. 6 | 7 | This code also provides a simple command line utility for the target to test the 8 | vehicle HAL. 9 | 10 | What is the code? 11 | 12 | The code is split into folowing logical components: 13 | a) hardware/libhardware/include/hardware/vehicle.h - this is the main HAL 14 | interface that will be required to be implemented by the OEMs. It includes all 15 | documentation necessary to understand what vehicle subsystems are exposed, 16 | various units, capabilities and any other relevant details about the HAL design 17 | itself. 18 | 19 | b) hardware/libhardware/modules/vehicle/vehicle.c 20 | This is a reference implementation for the OEMs to have a peek into getting 21 | started with a barebones structure. There are implementation for each of the 22 | critical HAL functions such as, get(), set() and subscribe(). 23 | 24 | c) hardware/libhardware/tests/vehicle/vehicle_test.cpp & vehicle_test_fixtures.h 25 | These are native tests that can be run on the target to validate basic 26 | features of HAL implementation. Things such as loading of HAL and 27 | basic functions are implemented (by check if the returned functions are not NULL 28 | pointers) can be asserted. It also checks if the subscribe function is doing its 29 | job by spitting out data at continuous intervals and printed on the stdout. 30 | 31 | d) hardware/libhardware/tests/vehicle/vehicle-hal-tool.c 32 | This tool will provide you with a simple utility which can set commands to the 33 | HAL such as: 34 | i) Getting a property (and printing its value). 35 | ii) Setting a property (and the HAL will take some setting action). 36 | iii) Subscribe to a property (and the HAL should send you values at some certain 37 | intevals). 38 | 39 | See the usage() function in vehicle-hal-tool.c for details on how to use the 40 | binary. 41 | 42 | How to build and run? 43 | 44 | You can build everything by issuing the following from the top of directory. It 45 | is assumed that you have done a first run of make from the top level so that 46 | intermediates are generated. 47 | 48 | $ croot 49 | $ mmm hardware/libhardware 50 | 51 | This will generate the following binaries that we care about: 52 | i) out/target/product/XXX/system/lib/hw/vehicle.default.so 53 | ii) out/target/product/XXX/data/nativetest/vehicle_tests 54 | iii) out/target/product/XXX/system/bin/vehicle-hal-tool 55 | 56 | The location for the first shared library would be: 57 | $ adb push out/target/product/XXX/system/lib/hw/vehicle.default.so 58 | /system/lib/hw 59 | You can also use 'adb sync' if you like, although this is the easiest least 60 | hassle way of putting it in place. 61 | 62 | The second binary is a native test - which is nothing but an executable for the 63 | target device. You can load it anywhere in your /data directory and run it as: 64 | $ adb push out/target/product/XXX/data/nativetest/vehicle_tests 65 | /data/tmp/vehicle_tests 66 | $ adb shell 67 | $ ./data/tmp/vehicle_tests 68 | <...output should be spitted with passing tests for atleast the reference 69 | implementation ...> 70 | 71 | The last binary is the command line tool, to push the binary on your target do: 72 | $ adb push out/target/product/XXX/system/bin/vehicle-hal-tool 73 | /data/tmp/vehicle-hal-tool 74 | -------------------------------------------------------------------------------- /tests/vehicle/vehicle_test_fixtures.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __ANDROID_HAL_VEHICLE_TEST_ 18 | #define __ANDROID_HAL_VEHICLE_TEST_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace tests { 25 | 26 | static const uint64_t kVersion = HARDWARE_DEVICE_API_VERSION_2(1, 0, 1); 27 | 28 | class VehicleModule : public testing::Test { 29 | public: 30 | VehicleModule() : 31 | vehicle_module_(NULL) {} 32 | ~VehicleModule() {} 33 | protected: 34 | virtual void SetUp() { 35 | const hw_module_t *hw_module = NULL; 36 | ASSERT_EQ(0, hw_get_module(VEHICLE_HARDWARE_MODULE_ID, &hw_module)) 37 | << "Can't get vehicle module"; 38 | ASSERT_TRUE(NULL != hw_module) 39 | << "hw_get_module didn't return a valid hardware module"; 40 | 41 | vehicle_module_ = reinterpret_cast(hw_module); 42 | } 43 | const vehicle_module_t* vehicle_module() { return vehicle_module_; } 44 | private: 45 | const vehicle_module_t* vehicle_module_; 46 | }; 47 | 48 | 49 | int VehicleEventCallback(const vehicle_prop_value_t* event_data) { 50 | // Print what we got. 51 | std::cout << "got some value from callback: " 52 | << event_data->prop 53 | << " uint32 value: " 54 | << event_data->value.int32_value << "\n"; 55 | return 0; 56 | } 57 | 58 | int VehicleErrorCallback(int32_t /*error_code*/, int32_t /*property*/, int32_t /*operation*/) { 59 | // Do nothing. 60 | return 0; 61 | } 62 | 63 | class VehicleDevice : public VehicleModule { 64 | public: 65 | VehicleDevice() : 66 | vehicle_device_(NULL) {} 67 | ~VehicleDevice() {} 68 | protected: 69 | virtual void SetUp() { 70 | VehicleModule::SetUp(); 71 | hw_device_t *device = NULL; 72 | ASSERT_TRUE(NULL != vehicle_module()->common.methods->open) 73 | << "Vehicle open() is unimplemented"; 74 | ASSERT_EQ(0, vehicle_module()->common.methods->open( 75 | (const hw_module_t*)vehicle_module(), NULL, &device)) 76 | << "Can't open vehicle device"; 77 | ASSERT_TRUE(NULL != device) 78 | << "Vehicle open() returned a NULL device"; 79 | ASSERT_EQ(kVersion, device->version) 80 | << "Unsupported version"; 81 | vehicle_device_ = reinterpret_cast(device); 82 | } 83 | vehicle_hw_device_t* vehicle_device() { return vehicle_device_; } 84 | vehicle_event_callback_fn callback_fn() { 85 | return VehicleEventCallback; 86 | } 87 | vehicle_error_callback_fn error_fn() { 88 | return VehicleErrorCallback; 89 | } 90 | 91 | private: 92 | vehicle_hw_device_t* vehicle_device_; 93 | }; 94 | 95 | } // namespace tests 96 | 97 | #endif // __ANDROID_HAL_VEHICLE_TEST_ 98 | --------------------------------------------------------------------------------