Project import
diff --git a/libhardware/Android.bp b/libhardware/Android.bp
new file mode 100644
index 0000000..f093c56
--- /dev/null
+++ b/libhardware/Android.bp
@@ -0,0 +1,18 @@
+// Copyright 2006 The Android Open Source Project
+
+cc_library_shared {
+ name: "libhardware",
+
+ srcs: ["hardware.c"],
+ shared_libs: [
+ "libcutils",
+ "liblog",
+ "libdl",
+ ],
+ cflags: ["-DQEMU_HARDWARE"],
+}
+
+subdirs = [
+ "modules/*",
+ "tests/*",
+]
diff --git a/libhardware/Android.mk b/libhardware/Android.mk
new file mode 100644
index 0000000..8744f46
--- /dev/null
+++ b/libhardware/Android.mk
@@ -0,0 +1,3 @@
+# Copyright 2006 The Android Open Source Project
+
+include $(call all-named-subdir-makefiles,modules tests)
diff --git a/libhardware/CleanSpec.mk b/libhardware/CleanSpec.mk
new file mode 100644
index 0000000..b84e1b6
--- /dev/null
+++ b/libhardware/CleanSpec.mk
@@ -0,0 +1,49 @@
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list. These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list. E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
diff --git a/libhardware/MODULE_LICENSE_APACHE2 b/libhardware/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/libhardware/MODULE_LICENSE_APACHE2
diff --git a/libhardware/NOTICE b/libhardware/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/libhardware/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/libhardware/hardware.c b/libhardware/hardware.c
new file mode 100644
index 0000000..79d0a2f
--- /dev/null
+++ b/libhardware/hardware.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hardware/hardware.h>
+
+#include <cutils/properties.h>
+
+#include <dlfcn.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <limits.h>
+
+#define LOG_TAG "HAL"
+#include <utils/Log.h>
+
+/** Base path of the hal modules */
+#if defined(__LP64__)
+#define HAL_LIBRARY_PATH1 "/system/lib64/hw"
+#define HAL_LIBRARY_PATH2 "/vendor/lib64/hw"
+#else
+#define HAL_LIBRARY_PATH1 "/system/lib/hw"
+#define HAL_LIBRARY_PATH2 "/vendor/lib/hw"
+#endif
+
+/**
+ * There are a set of variant filename for modules. The form of the filename
+ * is "<MODULE_ID>.variant.so" so for the led module the Dream variants
+ * of base "ro.product.board", "ro.board.platform" and "ro.arch" would be:
+ *
+ * led.trout.so
+ * led.msm7k.so
+ * led.ARMV6.so
+ * led.default.so
+ */
+
+static const char *variant_keys[] = {
+ "ro.hardware", /* This goes first so that it can pick up a different
+ file on the emulator. */
+ "ro.product.board",
+ "ro.board.platform",
+ "ro.arch"
+};
+
+static const int HAL_VARIANT_KEYS_COUNT =
+ (sizeof(variant_keys)/sizeof(variant_keys[0]));
+
+/**
+ * Load the file defined by the variant and if successful
+ * return the dlopen handle and the hmi.
+ * @return 0 = success, !0 = failure.
+ */
+static int load(const char *id,
+ const char *path,
+ const struct hw_module_t **pHmi)
+{
+ int status = -EINVAL;
+ void *handle = NULL;
+ struct hw_module_t *hmi = NULL;
+
+ /*
+ * load the symbols resolving undefined symbols before
+ * dlopen returns. Since RTLD_GLOBAL is not or'd in with
+ * RTLD_NOW the external symbols will not be global
+ */
+ handle = dlopen(path, RTLD_NOW);
+ if (handle == NULL) {
+ char const *err_str = dlerror();
+ ALOGE("load: module=%s\n%s", path, err_str?err_str:"unknown");
+ status = -EINVAL;
+ goto done;
+ }
+
+ /* Get the address of the struct hal_module_info. */
+ const char *sym = HAL_MODULE_INFO_SYM_AS_STR;
+ hmi = (struct hw_module_t *)dlsym(handle, sym);
+ if (hmi == NULL) {
+ ALOGE("load: couldn't find symbol %s", sym);
+ status = -EINVAL;
+ goto done;
+ }
+
+ /* Check that the id matches */
+ if (strcmp(id, hmi->id) != 0) {
+ ALOGE("load: id=%s != hmi->id=%s", id, hmi->id);
+ status = -EINVAL;
+ goto done;
+ }
+
+ hmi->dso = handle;
+
+ /* success */
+ status = 0;
+
+ done:
+ if (status != 0) {
+ hmi = NULL;
+ if (handle != NULL) {
+ dlclose(handle);
+ handle = NULL;
+ }
+ } else {
+ ALOGV("loaded HAL id=%s path=%s hmi=%p handle=%p",
+ id, path, *pHmi, handle);
+ }
+
+ *pHmi = hmi;
+
+ return status;
+}
+
+/*
+ * Check if a HAL with given name and subname exists, if so return 0, otherwise
+ * otherwise return negative. On success path will contain the path to the HAL.
+ */
+static int hw_module_exists(char *path, size_t path_len, const char *name,
+ const char *subname)
+{
+ snprintf(path, path_len, "%s/%s.%s.so",
+ HAL_LIBRARY_PATH2, name, subname);
+ if (access(path, R_OK) == 0)
+ return 0;
+
+ snprintf(path, path_len, "%s/%s.%s.so",
+ HAL_LIBRARY_PATH1, name, subname);
+ if (access(path, R_OK) == 0)
+ return 0;
+
+ return -ENOENT;
+}
+
+int hw_get_module_by_class(const char *class_id, const char *inst,
+ const struct hw_module_t **module)
+{
+ int i = 0;
+ char prop[PATH_MAX] = {0};
+ char path[PATH_MAX] = {0};
+ char name[PATH_MAX] = {0};
+ char prop_name[PATH_MAX] = {0};
+
+
+ if (inst)
+ snprintf(name, PATH_MAX, "%s.%s", class_id, inst);
+ else
+ strlcpy(name, class_id, PATH_MAX);
+
+ /*
+ * Here we rely on the fact that calling dlopen multiple times on
+ * the same .so will simply increment a refcount (and not load
+ * a new copy of the library).
+ * We also assume that dlopen() is thread-safe.
+ */
+
+ /* First try a property specific to the class and possibly instance */
+ snprintf(prop_name, sizeof(prop_name), "ro.hardware.%s", name);
+ if (property_get(prop_name, prop, NULL) > 0) {
+ if (hw_module_exists(path, sizeof(path), name, prop) == 0) {
+ goto found;
+ }
+ }
+
+ /* Loop through the configuration variants looking for a module */
+ for (i=0 ; i<HAL_VARIANT_KEYS_COUNT; i++) {
+ if (property_get(variant_keys[i], prop, NULL) == 0) {
+ continue;
+ }
+ if (hw_module_exists(path, sizeof(path), name, prop) == 0) {
+ goto found;
+ }
+ }
+
+ /* Nothing found, try the default */
+ if (hw_module_exists(path, sizeof(path), name, "default") == 0) {
+ goto found;
+ }
+
+ return -ENOENT;
+
+found:
+ /* load the module, if this fails, we're doomed, and we should not try
+ * to load a different variant. */
+ return load(class_id, path, module);
+}
+
+int hw_get_module(const char *id, const struct hw_module_t **module)
+{
+ return hw_get_module_by_class(id, NULL, module);
+}
diff --git a/libhardware/include/hardware/activity_recognition.h b/libhardware/include/hardware/activity_recognition.h
new file mode 100644
index 0000000..8f99459
--- /dev/null
+++ b/libhardware/include/hardware/activity_recognition.h
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Activity Recognition HAL. The goal is to provide low power, low latency, always-on activity
+ * recognition implemented in hardware (i.e. these activity recognition algorithms/classifers
+ * should NOT be run on the AP). By low power we mean that this may be activated 24/7 without
+ * impacting the battery drain speed (goal in order of 1mW including the power for sensors).
+ * This HAL does not specify the input sources that are used towards detecting these activities.
+ * It has one monitor interface which can be used to batch activities for always-on
+ * activity_recognition and if the latency is zero, the same interface can be used for low latency
+ * detection.
+ */
+
+#ifndef ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
+#define ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define ACTIVITY_RECOGNITION_HEADER_VERSION 1
+#define ACTIVITY_RECOGNITION_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, ACTIVITY_RECOGNITION_HEADER_VERSION)
+
+#define ACTIVITY_RECOGNITION_HARDWARE_MODULE_ID "activity_recognition"
+#define ACTIVITY_RECOGNITION_HARDWARE_INTERFACE "activity_recognition_hw_if"
+
+/*
+ * Define types for various activities. Multiple activities may be active at the same time and
+ * sometimes none of these activities may be active.
+ *
+ * Each activity has a corresponding type. Only activities that are defined here should use
+ * android.activity_recognition.* prefix. OEM defined activities should not use this prefix.
+ * Activity type of OEM-defined activities should start with the reverse domain name of the entity
+ * defining the activity.
+ *
+ * When android introduces a new activity type that can potentially replace an OEM-defined activity
+ * type, the OEM must use the official activity type on versions of the HAL that support this new
+ * official activity type.
+ *
+ * Example (made up): Suppose Google's Glass team wants to detect nodding activity.
+ * - Such an activity is not officially supported in android L
+ * - Glass devices launching on L can implement a custom activity with
+ * type = "com.google.glass.nodding"
+ * - In M android release, if android decides to define ACITIVITY_TYPE_NODDING, those types
+ * should replace the Glass-team-specific types in all future launches.
+ * - When launching glass on the M release, Google should now use the official activity type
+ * - This way, other applications can use this activity.
+ */
+
+#define ACTIVITY_TYPE_IN_VEHICLE "android.activity_recognition.in_vehicle"
+
+#define ACTIVITY_TYPE_ON_BICYCLE "android.activity_recognition.on_bicycle"
+
+#define ACTIVITY_TYPE_WALKING "android.activity_recognition.walking"
+
+#define ACTIVITY_TYPE_RUNNING "android.activity_recognition.running"
+
+#define ACTIVITY_TYPE_STILL "android.activity_recognition.still"
+
+#define ACTIVITY_TYPE_TILTING "android.activity_recognition.tilting"
+
+/* Values for activity_event.event_types. */
+enum {
+ /*
+ * A flush_complete event which indicates that a flush() has been successfully completed. This
+ * does not correspond to any activity/event. An event of this type should be added to the end
+ * of a batch FIFO and it indicates that all the events in the batch FIFO have been successfully
+ * reported to the framework. An event of this type should be generated only if flush() has been
+ * explicitly called and if the FIFO is empty at the time flush() is called it should trivially
+ * return a flush_complete_event to indicate that the FIFO is empty.
+ *
+ * A flush complete event should have the following parameters set.
+ * activity_event_t.event_type = ACTIVITY_EVENT_FLUSH_COMPLETE
+ * activity_event_t.activity = 0
+ * activity_event_t.timestamp = 0
+ * activity_event_t.reserved = 0
+ * See (*flush)() for more details.
+ */
+ ACTIVITY_EVENT_FLUSH_COMPLETE = 0,
+
+ /* Signifies entering an activity. */
+ ACTIVITY_EVENT_ENTER = 1,
+
+ /* Signifies exiting an activity. */
+ ACTIVITY_EVENT_EXIT = 2
+};
+
+/*
+ * Each event is a separate activity with event_type indicating whether this activity has started
+ * or ended. Eg event: (event_type="enter", activity="ON_FOOT", timestamp)
+ */
+typedef struct activity_event {
+ /* One of the ACTIVITY_EVENT_* constants defined above. */
+ uint32_t event_type;
+
+ /*
+ * Index of the activity in the list returned by get_supported_activities_list. If this event
+ * is a flush complete event, this should be set to zero.
+ */
+ uint32_t activity;
+
+ /* Time at which the transition/event has occurred in nanoseconds using elapsedRealTimeNano. */
+ int64_t timestamp;
+
+ /* Set to zero. */
+ int32_t reserved[4];
+} activity_event_t;
+
+typedef struct activity_recognition_module {
+ /**
+ * Common methods of the activity recognition module. This *must* be the first member of
+ * activity_recognition_module as users of this structure will cast a hw_module_t to
+ * activity_recognition_module pointer in contexts where it's known the hw_module_t
+ * references an activity_recognition_module.
+ */
+ hw_module_t common;
+
+ /*
+ * List of all activities supported by this module including OEM defined activities. Each
+ * activity is represented using a string defined above. Each string should be null terminated.
+ * The index of the activity in this array is used as a "handle" for enabling/disabling and
+ * event delivery.
+ * Return value is the size of this list.
+ */
+ int (*get_supported_activities_list)(struct activity_recognition_module* module,
+ char const* const* *activity_list);
+} activity_recognition_module_t;
+
+struct activity_recognition_device;
+
+typedef struct activity_recognition_callback_procs {
+ // Callback for activity_data. This is guaranteed to not invoke any HAL methods.
+ // Memory allocated for the events can be reused after this method returns.
+ // events - Array of activity_event_t s that are reported.
+ // count - size of the array.
+ void (*activity_callback)(const struct activity_recognition_callback_procs* procs,
+ const activity_event_t* events, int count);
+} activity_recognition_callback_procs_t;
+
+typedef struct activity_recognition_device {
+ /**
+ * Common methods of the activity recognition device. This *must* be the first member of
+ * activity_recognition_device as users of this structure will cast a hw_device_t to
+ * activity_recognition_device pointer in contexts where it's known the hw_device_t
+ * references an activity_recognition_device.
+ */
+ hw_device_t common;
+
+ /*
+ * Sets the callback to invoke when there are events to report. This call overwrites the
+ * previously registered callback (if any).
+ */
+ void (*register_activity_callback)(const struct activity_recognition_device* dev,
+ const activity_recognition_callback_procs_t* callback);
+
+ /*
+ * Activates monitoring of activity transitions. Activities need not be reported as soon as they
+ * are detected. The detected activities are stored in a FIFO and reported in batches when the
+ * "max_batch_report_latency" expires or when the batch FIFO is full. The implementation should
+ * allow the AP to go into suspend mode while the activities are detected and stored in the
+ * batch FIFO. Whenever events need to be reported (like when the FIFO is full or when the
+ * max_batch_report_latency has expired for an activity, event pair), it should wake_up the AP
+ * so that no events are lost. Activities are stored as transitions and they are allowed to
+ * overlap with each other. Each (activity, event_type) pair can be activated or deactivated
+ * independently of the other. The HAL implementation needs to keep track of which pairs are
+ * currently active and needs to detect only those pairs.
+ *
+ * activity_handle - Index of the specific activity that needs to be detected in the list
+ * returned by get_supported_activities_list.
+ * event_type - Specific transition of the activity that needs to be detected.
+ * max_batch_report_latency_ns - a transition can be delayed by at most
+ * “max_batch_report_latency” nanoseconds.
+ * Return 0 on success, negative errno code otherwise.
+ */
+ int (*enable_activity_event)(const struct activity_recognition_device* dev,
+ uint32_t activity_handle, uint32_t event_type, int64_t max_batch_report_latency_ns);
+
+ /*
+ * Disables detection of a specific (activity, event_type) pair.
+ */
+ int (*disable_activity_event)(const struct activity_recognition_device* dev,
+ uint32_t activity_handle, uint32_t event_type);
+
+ /*
+ * Flush all the batch FIFOs. Report all the activities that were stored in the FIFO so far as
+ * if max_batch_report_latency had expired. This shouldn't change the latency in any way. Add
+ * a flush_complete_event to indicate the end of the FIFO after all events are delivered.
+ * See ACTIVITY_EVENT_FLUSH_COMPLETE for more details.
+ * Return 0 on success, negative errno code otherwise.
+ */
+ int (*flush)(const struct activity_recognition_device* dev);
+
+ // Must be set to NULL.
+ void (*reserved_procs[16 - 4])(void);
+} activity_recognition_device_t;
+
+static inline int activity_recognition_open(const hw_module_t* module,
+ activity_recognition_device_t** device) {
+ return module->methods->open(module,
+ ACTIVITY_RECOGNITION_HARDWARE_INTERFACE, (hw_device_t**)device);
+}
+
+static inline int activity_recognition_close(activity_recognition_device_t* device) {
+ return device->common.close(&device->common);
+}
+
+__END_DECLS
+
+#endif // ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
diff --git a/libhardware/include/hardware/audio.h b/libhardware/include/hardware/audio.h
new file mode 100644
index 0000000..2389c09
--- /dev/null
+++ b/libhardware/include/hardware/audio.h
@@ -0,0 +1,672 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_HAL_INTERFACE_H
+#define ANDROID_AUDIO_HAL_INTERFACE_H
+
+#include <stdint.h>
+#include <strings.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/bitops.h>
+
+#include <hardware/hardware.h>
+#include <system/audio.h>
+#include <hardware/audio_effect.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define AUDIO_HARDWARE_MODULE_ID "audio"
+
+/**
+ * Name of the audio devices to open
+ */
+#define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
+
+
+/* Use version 0.1 to be compatible with first generation of audio hw module with version_major
+ * hardcoded to 1. No audio module API change.
+ */
+#define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+#define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1
+
+/* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0
+ * will be considered of first generation API.
+ */
+#define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0)
+#define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
+#define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
+#define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
+#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0
+/* Minimal audio HAL version supported by the audio framework */
+#define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
+
+/**
+ * List of known audio HAL modules. This is the base name of the audio HAL
+ * library composed of the "audio." prefix, one of the base names below and
+ * a suffix specific to the device.
+ * e.g: audio.primary.goldfish.so or audio.a2dp.default.so
+ */
+
+#define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
+#define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
+#define AUDIO_HARDWARE_MODULE_ID_USB "usb"
+#define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix"
+#define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload"
+
+/**************************************/
+
+/**
+ * standard audio parameters that the HAL may need to handle
+ */
+
+/**
+ * audio device parameters
+ */
+
+/* BT SCO Noise Reduction + Echo Cancellation parameters */
+#define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
+#define AUDIO_PARAMETER_VALUE_ON "on"
+#define AUDIO_PARAMETER_VALUE_OFF "off"
+
+/* TTY mode selection */
+#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
+#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
+#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
+#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
+#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
+
+/* Hearing Aid Compatibility - Telecoil (HAC-T) mode on/off
+ Strings must be in sync with CallFeaturesSetting.java */
+#define AUDIO_PARAMETER_KEY_HAC "HACSetting"
+#define AUDIO_PARAMETER_VALUE_HAC_ON "ON"
+#define AUDIO_PARAMETER_VALUE_HAC_OFF "OFF"
+
+/* A2DP sink address set by framework */
+#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
+
+/* A2DP source address set by framework */
+#define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address"
+
+/* Screen state */
+#define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
+
+/* Bluetooth SCO wideband */
+#define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs"
+
+/* Get a new HW synchronization source identifier.
+ * Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs
+ * or no HW sync is available. */
+#define AUDIO_PARAMETER_HW_AV_SYNC "hw_av_sync"
+
+/**
+ * audio stream parameters
+ */
+
+#define AUDIO_PARAMETER_STREAM_ROUTING "routing" /* audio_devices_t */
+#define AUDIO_PARAMETER_STREAM_FORMAT "format" /* audio_format_t */
+#define AUDIO_PARAMETER_STREAM_CHANNELS "channels" /* audio_channel_mask_t */
+#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" /* size_t */
+#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" /* audio_source_t */
+#define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" /* uint32_t */
+
+#define AUDIO_PARAMETER_DEVICE_CONNECT "connect" /* audio_devices_t */
+#define AUDIO_PARAMETER_DEVICE_DISCONNECT "disconnect" /* audio_devices_t */
+
+/* Query supported formats. The response is a '|' separated list of strings from
+ * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
+#define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
+/* Query supported channel masks. The response is a '|' separated list of strings from
+ * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
+#define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
+/* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
+ * "sup_sampling_rates=44100|48000" */
+#define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
+
+/* Set the HW synchronization source for an output stream. */
+#define AUDIO_PARAMETER_STREAM_HW_AV_SYNC "hw_av_sync"
+
+/**
+ * audio codec parameters
+ */
+
+#define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param"
+#define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample"
+#define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate"
+#define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate"
+#define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id"
+#define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align"
+#define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate"
+#define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option"
+#define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels"
+#define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling"
+#define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples"
+#define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples"
+
+/**************************************/
+
+/* common audio stream parameters and operations */
+struct audio_stream {
+
+ /**
+ * Return the sampling rate in Hz - eg. 44100.
+ */
+ uint32_t (*get_sample_rate)(const struct audio_stream *stream);
+
+ /* currently unused - use set_parameters with key
+ * AUDIO_PARAMETER_STREAM_SAMPLING_RATE
+ */
+ int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
+
+ /**
+ * Return size of input/output buffer in bytes for this stream - eg. 4800.
+ * It should be a multiple of the frame size. See also get_input_buffer_size.
+ */
+ size_t (*get_buffer_size)(const struct audio_stream *stream);
+
+ /**
+ * Return the channel mask -
+ * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
+ */
+ audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
+
+ /**
+ * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
+ */
+ audio_format_t (*get_format)(const struct audio_stream *stream);
+
+ /* currently unused - use set_parameters with key
+ * AUDIO_PARAMETER_STREAM_FORMAT
+ */
+ int (*set_format)(struct audio_stream *stream, audio_format_t format);
+
+ /**
+ * Put the audio hardware input/output into standby mode.
+ * Driver should exit from standby mode at the next I/O operation.
+ * Returns 0 on success and <0 on failure.
+ */
+ int (*standby)(struct audio_stream *stream);
+
+ /** dump the state of the audio input/output device */
+ int (*dump)(const struct audio_stream *stream, int fd);
+
+ /** Return the set of device(s) which this stream is connected to */
+ audio_devices_t (*get_device)(const struct audio_stream *stream);
+
+ /**
+ * Currently unused - set_device() corresponds to set_parameters() with key
+ * AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
+ * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
+ * input streams only.
+ */
+ int (*set_device)(struct audio_stream *stream, audio_devices_t device);
+
+ /**
+ * set/get audio stream parameters. The function accepts a list of
+ * parameter key value pairs in the form: key1=value1;key2=value2;...
+ *
+ * Some keys are reserved for standard parameters (See AudioParameter class)
+ *
+ * If the implementation does not accept a parameter change while
+ * the output is active but the parameter is acceptable otherwise, it must
+ * return -ENOSYS.
+ *
+ * The audio flinger will put the stream in standby and then change the
+ * parameter value.
+ */
+ int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
+
+ /*
+ * Returns a pointer to a heap allocated string. The caller is responsible
+ * for freeing the memory for it using free().
+ */
+ char * (*get_parameters)(const struct audio_stream *stream,
+ const char *keys);
+ int (*add_audio_effect)(const struct audio_stream *stream,
+ effect_handle_t effect);
+ int (*remove_audio_effect)(const struct audio_stream *stream,
+ effect_handle_t effect);
+};
+typedef struct audio_stream audio_stream_t;
+
+/* type of asynchronous write callback events. Mutually exclusive */
+typedef enum {
+ STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */
+ STREAM_CBK_EVENT_DRAIN_READY /* drain completed */
+} stream_callback_event_t;
+
+typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie);
+
+/* type of drain requested to audio_stream_out->drain(). Mutually exclusive */
+typedef enum {
+ AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */
+ AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data
+ from the current track has been played to
+ give time for gapless track switch */
+} audio_drain_type_t;
+
+/**
+ * audio_stream_out is the abstraction interface for the audio output hardware.
+ *
+ * It provides information about various properties of the audio output
+ * hardware driver.
+ */
+
+struct audio_stream_out {
+ /**
+ * Common methods of the audio stream out. This *must* be the first member of audio_stream_out
+ * as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts
+ * where it's known the audio_stream references an audio_stream_out.
+ */
+ struct audio_stream common;
+
+ /**
+ * Return the audio hardware driver estimated latency in milliseconds.
+ */
+ uint32_t (*get_latency)(const struct audio_stream_out *stream);
+
+ /**
+ * Use this method in situations where audio mixing is done in the
+ * hardware. This method serves as a direct interface with hardware,
+ * allowing you to directly set the volume as apposed to via the framework.
+ * This method might produce multiple PCM outputs or hardware accelerated
+ * codecs, such as MP3 or AAC.
+ */
+ int (*set_volume)(struct audio_stream_out *stream, float left, float right);
+
+ /**
+ * Write audio buffer to driver. Returns number of bytes written, or a
+ * negative status_t. If at least one frame was written successfully prior to the error,
+ * it is suggested that the driver return that successful (short) byte count
+ * and then return an error in the subsequent call.
+ *
+ * If set_callback() has previously been called to enable non-blocking mode
+ * the write() is not allowed to block. It must write only the number of
+ * bytes that currently fit in the driver/hardware buffer and then return
+ * this byte count. If this is less than the requested write size the
+ * callback function must be called when more space is available in the
+ * driver/hardware buffer.
+ */
+ ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
+ size_t bytes);
+
+ /* return the number of audio frames written by the audio dsp to DAC since
+ * the output has exited standby
+ */
+ int (*get_render_position)(const struct audio_stream_out *stream,
+ uint32_t *dsp_frames);
+
+ /**
+ * get the local time at which the next write to the audio driver will be presented.
+ * The units are microseconds, where the epoch is decided by the local audio HAL.
+ */
+ int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
+ int64_t *timestamp);
+
+ /**
+ * set the callback function for notifying completion of non-blocking
+ * write and drain.
+ * Calling this function implies that all future write() and drain()
+ * must be non-blocking and use the callback to signal completion.
+ */
+ int (*set_callback)(struct audio_stream_out *stream,
+ stream_callback_t callback, void *cookie);
+
+ /**
+ * Notifies to the audio driver to stop playback however the queued buffers are
+ * retained by the hardware. Useful for implementing pause/resume. Empty implementation
+ * if not supported however should be implemented for hardware with non-trivial
+ * latency. In the pause state audio hardware could still be using power. User may
+ * consider calling suspend after a timeout.
+ *
+ * Implementation of this function is mandatory for offloaded playback.
+ */
+ int (*pause)(struct audio_stream_out* stream);
+
+ /**
+ * Notifies to the audio driver to resume playback following a pause.
+ * Returns error if called without matching pause.
+ *
+ * Implementation of this function is mandatory for offloaded playback.
+ */
+ int (*resume)(struct audio_stream_out* stream);
+
+ /**
+ * Requests notification when data buffered by the driver/hardware has
+ * been played. If set_callback() has previously been called to enable
+ * non-blocking mode, the drain() must not block, instead it should return
+ * quickly and completion of the drain is notified through the callback.
+ * If set_callback() has not been called, the drain() must block until
+ * completion.
+ * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
+ * data has been played.
+ * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
+ * data for the current track has played to allow time for the framework
+ * to perform a gapless track switch.
+ *
+ * Drain must return immediately on stop() and flush() call
+ *
+ * Implementation of this function is mandatory for offloaded playback.
+ */
+ int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type );
+
+ /**
+ * Notifies to the audio driver to flush the queued data. Stream must already
+ * be paused before calling flush().
+ *
+ * Implementation of this function is mandatory for offloaded playback.
+ */
+ int (*flush)(struct audio_stream_out* stream);
+
+ /**
+ * Return a recent count of the number of audio frames presented to an external observer.
+ * This excludes frames which have been written but are still in the pipeline.
+ * The count is not reset to zero when output enters standby.
+ * Also returns the value of CLOCK_MONOTONIC as of this presentation count.
+ * The returned count is expected to be 'recent',
+ * but does not need to be the most recent possible value.
+ * However, the associated time should correspond to whatever count is returned.
+ * Example: assume that N+M frames have been presented, where M is a 'small' number.
+ * Then it is permissible to return N instead of N+M,
+ * and the timestamp should correspond to N rather than N+M.
+ * The terms 'recent' and 'small' are not defined.
+ * They reflect the quality of the implementation.
+ *
+ * 3.0 and higher only.
+ */
+ int (*get_presentation_position)(const struct audio_stream_out *stream,
+ uint64_t *frames, struct timespec *timestamp);
+
+};
+typedef struct audio_stream_out audio_stream_out_t;
+
+struct audio_stream_in {
+ /**
+ * Common methods of the audio stream in. This *must* be the first member of audio_stream_in
+ * as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts
+ * where it's known the audio_stream references an audio_stream_in.
+ */
+ struct audio_stream common;
+
+ /** set the input gain for the audio driver. This method is for
+ * for future use */
+ int (*set_gain)(struct audio_stream_in *stream, float gain);
+
+ /** Read audio buffer in from audio driver. Returns number of bytes read, or a
+ * negative status_t. If at least one frame was read prior to the error,
+ * read should return that byte count and then return an error in the subsequent call.
+ */
+ ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
+ size_t bytes);
+
+ /**
+ * Return the amount of input frames lost in the audio driver since the
+ * last call of this function.
+ * Audio driver is expected to reset the value to 0 and restart counting
+ * upon returning the current value by this function call.
+ * Such loss typically occurs when the user space process is blocked
+ * longer than the capacity of audio driver buffers.
+ *
+ * Unit: the number of input audio frames
+ */
+ uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
+};
+typedef struct audio_stream_in audio_stream_in_t;
+
+/**
+ * return the frame size (number of bytes per sample).
+ *
+ * Deprecated: use audio_stream_out_frame_size() or audio_stream_in_frame_size() instead.
+ */
+__attribute__((__deprecated__))
+static inline size_t audio_stream_frame_size(const struct audio_stream *s)
+{
+ size_t chan_samp_sz;
+ audio_format_t format = s->get_format(s);
+
+ if (audio_is_linear_pcm(format)) {
+ chan_samp_sz = audio_bytes_per_sample(format);
+ return popcount(s->get_channels(s)) * chan_samp_sz;
+ }
+
+ return sizeof(int8_t);
+}
+
+/**
+ * return the frame size (number of bytes per sample) of an output stream.
+ */
+static inline size_t audio_stream_out_frame_size(const struct audio_stream_out *s)
+{
+ size_t chan_samp_sz;
+ audio_format_t format = s->common.get_format(&s->common);
+
+ if (audio_is_linear_pcm(format)) {
+ chan_samp_sz = audio_bytes_per_sample(format);
+ return audio_channel_count_from_out_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
+ }
+
+ return sizeof(int8_t);
+}
+
+/**
+ * return the frame size (number of bytes per sample) of an input stream.
+ */
+static inline size_t audio_stream_in_frame_size(const struct audio_stream_in *s)
+{
+ size_t chan_samp_sz;
+ audio_format_t format = s->common.get_format(&s->common);
+
+ if (audio_is_linear_pcm(format)) {
+ chan_samp_sz = audio_bytes_per_sample(format);
+ return audio_channel_count_from_in_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
+ }
+
+ return sizeof(int8_t);
+}
+
+/**********************************************************************/
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+struct audio_module {
+ struct hw_module_t common;
+};
+
+struct audio_hw_device {
+ /**
+ * Common methods of the audio device. This *must* be the first member of audio_hw_device
+ * as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts
+ * where it's known the hw_device_t references an audio_hw_device.
+ */
+ struct hw_device_t common;
+
+ /**
+ * used by audio flinger to enumerate what devices are supported by
+ * each audio_hw_device implementation.
+ *
+ * Return value is a bitmask of 1 or more values of audio_devices_t
+ *
+ * NOTE: audio HAL implementations starting with
+ * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function.
+ * All supported devices should be listed in audio_policy.conf
+ * file and the audio policy manager must choose the appropriate
+ * audio module based on information in this file.
+ */
+ uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
+
+ /**
+ * check to see if the audio hardware interface has been initialized.
+ * returns 0 on success, -ENODEV on failure.
+ */
+ int (*init_check)(const struct audio_hw_device *dev);
+
+ /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
+ int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
+
+ /**
+ * set the audio volume for all audio activities other than voice call.
+ * Range between 0.0 and 1.0. If any value other than 0 is returned,
+ * the software mixer will emulate this capability.
+ */
+ int (*set_master_volume)(struct audio_hw_device *dev, float volume);
+
+ /**
+ * Get the current master volume value for the HAL, if the HAL supports
+ * master volume control. AudioFlinger will query this value from the
+ * primary audio HAL when the service starts and use the value for setting
+ * the initial master volume across all HALs. HALs which do not support
+ * this method may leave it set to NULL.
+ */
+ int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
+
+ /**
+ * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
+ * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
+ * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
+ */
+ int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
+
+ /* mic mute */
+ int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
+ int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
+
+ /* set/get global audio parameters */
+ int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
+
+ /*
+ * Returns a pointer to a heap allocated string. The caller is responsible
+ * for freeing the memory for it using free().
+ */
+ char * (*get_parameters)(const struct audio_hw_device *dev,
+ const char *keys);
+
+ /* Returns audio input buffer size according to parameters passed or
+ * 0 if one of the parameters is not supported.
+ * See also get_buffer_size which is for a particular stream.
+ */
+ size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
+ const struct audio_config *config);
+
+ /** This method creates and opens the audio hardware output stream.
+ * The "address" parameter qualifies the "devices" audio device type if needed.
+ * The format format depends on the device type:
+ * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
+ * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
+ * - Other devices may use a number or any other string.
+ */
+
+ int (*open_output_stream)(struct audio_hw_device *dev,
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ audio_output_flags_t flags,
+ struct audio_config *config,
+ struct audio_stream_out **stream_out,
+ const char *address);
+
+ void (*close_output_stream)(struct audio_hw_device *dev,
+ struct audio_stream_out* stream_out);
+
+ /** This method creates and opens the audio hardware input stream */
+ int (*open_input_stream)(struct audio_hw_device *dev,
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ struct audio_config *config,
+ struct audio_stream_in **stream_in,
+ audio_input_flags_t flags,
+ const char *address,
+ audio_source_t source);
+
+ void (*close_input_stream)(struct audio_hw_device *dev,
+ struct audio_stream_in *stream_in);
+
+ /** This method dumps the state of the audio hardware */
+ int (*dump)(const struct audio_hw_device *dev, int fd);
+
+ /**
+ * set the audio mute status for all audio activities. If any value other
+ * than 0 is returned, the software mixer will emulate this capability.
+ */
+ int (*set_master_mute)(struct audio_hw_device *dev, bool mute);
+
+ /**
+ * Get the current master mute status for the HAL, if the HAL supports
+ * master mute control. AudioFlinger will query this value from the primary
+ * audio HAL when the service starts and use the value for setting the
+ * initial master mute across all HALs. HALs which do not support this
+ * method may leave it set to NULL.
+ */
+ int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);
+
+ /**
+ * Routing control
+ */
+
+ /* Creates an audio patch between several source and sink ports.
+ * The handle is allocated by the HAL and should be unique for this
+ * audio HAL module. */
+ int (*create_audio_patch)(struct audio_hw_device *dev,
+ unsigned int num_sources,
+ const struct audio_port_config *sources,
+ unsigned int num_sinks,
+ const struct audio_port_config *sinks,
+ audio_patch_handle_t *handle);
+
+ /* Release an audio patch */
+ int (*release_audio_patch)(struct audio_hw_device *dev,
+ audio_patch_handle_t handle);
+
+ /* Fills the list of supported attributes for a given audio port.
+ * As input, "port" contains the information (type, role, address etc...)
+ * needed by the HAL to identify the port.
+ * As output, "port" contains possible attributes (sampling rates, formats,
+ * channel masks, gain controllers...) for this port.
+ */
+ int (*get_audio_port)(struct audio_hw_device *dev,
+ struct audio_port *port);
+
+ /* Set audio port configuration */
+ int (*set_audio_port_config)(struct audio_hw_device *dev,
+ const struct audio_port_config *config);
+
+};
+typedef struct audio_hw_device audio_hw_device_t;
+
+/** convenience API for opening and closing a supported device */
+
+static inline int audio_hw_device_open(const struct hw_module_t* module,
+ struct audio_hw_device** device)
+{
+ return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
+ (struct hw_device_t**)device);
+}
+
+static inline int audio_hw_device_close(struct audio_hw_device* device)
+{
+ return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif // ANDROID_AUDIO_INTERFACE_H
diff --git a/libhardware/include/hardware/audio_alsaops.h b/libhardware/include/hardware/audio_alsaops.h
new file mode 100644
index 0000000..0d266ff
--- /dev/null
+++ b/libhardware/include/hardware/audio_alsaops.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* This file contains shared utility functions to handle the tinyalsa
+ * implementation for Android internal audio, generally in the hardware layer.
+ * Some routines may log a fatal error on failure, as noted.
+ */
+
+#ifndef ANDROID_AUDIO_ALSAOPS_H
+#define ANDROID_AUDIO_ALSAOPS_H
+
+#include <cutils/log.h>
+#include <system/audio.h>
+#include <tinyalsa/asoundlib.h>
+
+__BEGIN_DECLS
+
+/* Converts audio_format to pcm_format.
+ * Parameters:
+ * format the audio_format_t to convert
+ *
+ * Logs a fatal error if format is not a valid convertible audio_format_t.
+ */
+static inline enum pcm_format pcm_format_from_audio_format(audio_format_t format)
+{
+ switch (format) {
+#ifdef HAVE_BIG_ENDIAN
+ case AUDIO_FORMAT_PCM_16_BIT:
+ return PCM_FORMAT_S16_BE;
+ case AUDIO_FORMAT_PCM_24_BIT_PACKED:
+ return PCM_FORMAT_S24_3BE;
+ case AUDIO_FORMAT_PCM_32_BIT:
+ return PCM_FORMAT_S32_BE;
+ case AUDIO_FORMAT_PCM_8_24_BIT:
+ return PCM_FORMAT_S24_BE;
+#else
+ case AUDIO_FORMAT_PCM_16_BIT:
+ return PCM_FORMAT_S16_LE;
+ case AUDIO_FORMAT_PCM_24_BIT_PACKED:
+ return PCM_FORMAT_S24_3LE;
+ case AUDIO_FORMAT_PCM_32_BIT:
+ return PCM_FORMAT_S32_LE;
+ case AUDIO_FORMAT_PCM_8_24_BIT:
+ return PCM_FORMAT_S24_LE;
+#endif
+ case AUDIO_FORMAT_PCM_FLOAT: /* there is no equivalent for float */
+ default:
+ LOG_ALWAYS_FATAL("pcm_format_from_audio_format: invalid audio format %#x", format);
+ return 0;
+ }
+}
+
+/* Converts pcm_format to audio_format.
+ * Parameters:
+ * format the pcm_format to convert
+ *
+ * Logs a fatal error if format is not a valid convertible pcm_format.
+ */
+static inline audio_format_t audio_format_from_pcm_format(enum pcm_format format)
+{
+ switch (format) {
+#ifdef HAVE_BIG_ENDIAN
+ case PCM_FORMAT_S16_BE:
+ return AUDIO_FORMAT_PCM_16_BIT;
+ case PCM_FORMAT_S24_3BE:
+ return AUDIO_FORMAT_PCM_24_BIT_PACKED;
+ case PCM_FORMAT_S24_BE:
+ return AUDIO_FORMAT_PCM_8_24_BIT;
+ case PCM_FORMAT_S32_BE:
+ return AUDIO_FORMAT_PCM_32_BIT;
+#else
+ case PCM_FORMAT_S16_LE:
+ return AUDIO_FORMAT_PCM_16_BIT;
+ case PCM_FORMAT_S24_3LE:
+ return AUDIO_FORMAT_PCM_24_BIT_PACKED;
+ case PCM_FORMAT_S24_LE:
+ return AUDIO_FORMAT_PCM_8_24_BIT;
+ case PCM_FORMAT_S32_LE:
+ return AUDIO_FORMAT_PCM_32_BIT;
+#endif
+ default:
+ LOG_ALWAYS_FATAL("audio_format_from_pcm_format: invalid pcm format %#x", format);
+ return 0;
+ }
+}
+
+__END_DECLS
+
+#endif /* ANDROID_AUDIO_ALSAOPS_H */
diff --git a/libhardware/include/hardware/audio_effect.h b/libhardware/include/hardware/audio_effect.h
new file mode 100644
index 0000000..41cd2e6
--- /dev/null
+++ b/libhardware/include/hardware/audio_effect.h
@@ -0,0 +1,1014 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_EFFECT_H
+#define ANDROID_AUDIO_EFFECT_H
+
+#include <errno.h>
+#include <stdint.h>
+#include <strings.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/bitops.h>
+
+#include <system/audio.h>
+
+
+__BEGIN_DECLS
+
+
+/////////////////////////////////////////////////
+// Common Definitions
+/////////////////////////////////////////////////
+
+//
+//--- Effect descriptor structure effect_descriptor_t
+//
+
+// Unique effect ID (can be generated from the following site:
+// http://www.itu.int/ITU-T/asn1/uuid.html)
+// This format is used for both "type" and "uuid" fields of the effect descriptor structure.
+// - When used for effect type and the engine is implementing and effect corresponding to a standard
+// OpenSL ES interface, this ID must be the one defined in OpenSLES_IID.h for that interface.
+// - When used as uuid, it should be a unique UUID for this particular implementation.
+typedef struct effect_uuid_s {
+ uint32_t timeLow;
+ uint16_t timeMid;
+ uint16_t timeHiAndVersion;
+ uint16_t clockSeq;
+ uint8_t node[6];
+} effect_uuid_t;
+
+// Maximum length of character strings in structures defines by this API.
+#define EFFECT_STRING_LEN_MAX 64
+
+// NULL UUID definition (matches SL_IID_NULL_)
+#define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, \
+ { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } }
+static const effect_uuid_t EFFECT_UUID_NULL_ = EFFECT_UUID_INITIALIZER;
+static const effect_uuid_t * const EFFECT_UUID_NULL = &EFFECT_UUID_NULL_;
+static const char * const EFFECT_UUID_NULL_STR = "ec7178ec-e5e1-4432-a3f4-4657e6795210";
+
+
+// The effect descriptor contains necessary information to facilitate the enumeration of the effect
+// engines present in a library.
+typedef struct effect_descriptor_s {
+ effect_uuid_t type; // UUID of to the OpenSL ES interface implemented by this effect
+ effect_uuid_t uuid; // UUID for this particular implementation
+ uint32_t apiVersion; // Version of the effect control API implemented
+ uint32_t flags; // effect engine capabilities/requirements flags (see below)
+ uint16_t cpuLoad; // CPU load indication (see below)
+ uint16_t memoryUsage; // Data Memory usage (see below)
+ char name[EFFECT_STRING_LEN_MAX]; // human readable effect name
+ char implementor[EFFECT_STRING_LEN_MAX]; // human readable effect implementor name
+} effect_descriptor_t;
+
+// CPU load and memory usage indication: each effect implementation must provide an indication of
+// its CPU and memory usage for the audio effect framework to limit the number of effects
+// instantiated at a given time on a given platform.
+// The CPU load is expressed in 0.1 MIPS units as estimated on an ARM9E core (ARMv5TE) with 0 WS.
+// The memory usage is expressed in KB and includes only dynamically allocated memory
+
+// Definitions for flags field of effect descriptor.
+// +---------------------------+-----------+-----------------------------------
+// | description | bits | values
+// +---------------------------+-----------+-----------------------------------
+// | connection mode | 0..2 | 0 insert: after track process
+// | | | 1 auxiliary: connect to track auxiliary
+// | | | output and use send level
+// | | | 2 replace: replaces track process function;
+// | | | must implement SRC, volume and mono to stereo.
+// | | | 3 pre processing: applied below audio HAL on input
+// | | | 4 post processing: applied below audio HAL on output
+// | | | 5 - 7 reserved
+// +---------------------------+-----------+-----------------------------------
+// | insertion preference | 3..5 | 0 none
+// | | | 1 first of the chain
+// | | | 2 last of the chain
+// | | | 3 exclusive (only effect in the insert chain)
+// | | | 4..7 reserved
+// +---------------------------+-----------+-----------------------------------
+// | Volume management | 6..8 | 0 none
+// | | | 1 implements volume control
+// | | | 2 requires volume indication
+// | | | 4 reserved
+// +---------------------------+-----------+-----------------------------------
+// | Device indication | 9..11 | 0 none
+// | | | 1 requires device updates
+// | | | 2, 4 reserved
+// +---------------------------+-----------+-----------------------------------
+// | Sample input mode | 12..13 | 1 direct: process() function or EFFECT_CMD_SET_CONFIG
+// | | | command must specify a buffer descriptor
+// | | | 2 provider: process() function uses the
+// | | | bufferProvider indicated by the
+// | | | EFFECT_CMD_SET_CONFIG command to request input.
+// | | | buffers.
+// | | | 3 both: both input modes are supported
+// +---------------------------+-----------+-----------------------------------
+// | Sample output mode | 14..15 | 1 direct: process() function or EFFECT_CMD_SET_CONFIG
+// | | | command must specify a buffer descriptor
+// | | | 2 provider: process() function uses the
+// | | | bufferProvider indicated by the
+// | | | EFFECT_CMD_SET_CONFIG command to request output
+// | | | buffers.
+// | | | 3 both: both output modes are supported
+// +---------------------------+-----------+-----------------------------------
+// | Hardware acceleration | 16..17 | 0 No hardware acceleration
+// | | | 1 non tunneled hw acceleration: the process() function
+// | | | reads the samples, send them to HW accelerated
+// | | | effect processor, reads back the processed samples
+// | | | and returns them to the output buffer.
+// | | | 2 tunneled hw acceleration: the process() function is
+// | | | transparent. The effect interface is only used to
+// | | | control the effect engine. This mode is relevant for
+// | | | global effects actually applied by the audio
+// | | | hardware on the output stream.
+// +---------------------------+-----------+-----------------------------------
+// | Audio Mode indication | 18..19 | 0 none
+// | | | 1 requires audio mode updates
+// | | | 2..3 reserved
+// +---------------------------+-----------+-----------------------------------
+// | Audio source indication | 20..21 | 0 none
+// | | | 1 requires audio source updates
+// | | | 2..3 reserved
+// +---------------------------+-----------+-----------------------------------
+// | Effect offload supported | 22 | 0 The effect cannot be offloaded to an audio DSP
+// | | | 1 The effect can be offloaded to an audio DSP
+// +---------------------------+-----------+-----------------------------------
+
+// Insert mode
+#define EFFECT_FLAG_TYPE_SHIFT 0
+#define EFFECT_FLAG_TYPE_SIZE 3
+#define EFFECT_FLAG_TYPE_MASK (((1 << EFFECT_FLAG_TYPE_SIZE) -1) \
+ << EFFECT_FLAG_TYPE_SHIFT)
+#define EFFECT_FLAG_TYPE_INSERT (0 << EFFECT_FLAG_TYPE_SHIFT)
+#define EFFECT_FLAG_TYPE_AUXILIARY (1 << EFFECT_FLAG_TYPE_SHIFT)
+#define EFFECT_FLAG_TYPE_REPLACE (2 << EFFECT_FLAG_TYPE_SHIFT)
+#define EFFECT_FLAG_TYPE_PRE_PROC (3 << EFFECT_FLAG_TYPE_SHIFT)
+#define EFFECT_FLAG_TYPE_POST_PROC (4 << EFFECT_FLAG_TYPE_SHIFT)
+
+// Insert preference
+#define EFFECT_FLAG_INSERT_SHIFT (EFFECT_FLAG_TYPE_SHIFT + EFFECT_FLAG_TYPE_SIZE)
+#define EFFECT_FLAG_INSERT_SIZE 3
+#define EFFECT_FLAG_INSERT_MASK (((1 << EFFECT_FLAG_INSERT_SIZE) -1) \
+ << EFFECT_FLAG_INSERT_SHIFT)
+#define EFFECT_FLAG_INSERT_ANY (0 << EFFECT_FLAG_INSERT_SHIFT)
+#define EFFECT_FLAG_INSERT_FIRST (1 << EFFECT_FLAG_INSERT_SHIFT)
+#define EFFECT_FLAG_INSERT_LAST (2 << EFFECT_FLAG_INSERT_SHIFT)
+#define EFFECT_FLAG_INSERT_EXCLUSIVE (3 << EFFECT_FLAG_INSERT_SHIFT)
+
+
+// Volume control
+#define EFFECT_FLAG_VOLUME_SHIFT (EFFECT_FLAG_INSERT_SHIFT + EFFECT_FLAG_INSERT_SIZE)
+#define EFFECT_FLAG_VOLUME_SIZE 3
+#define EFFECT_FLAG_VOLUME_MASK (((1 << EFFECT_FLAG_VOLUME_SIZE) -1) \
+ << EFFECT_FLAG_VOLUME_SHIFT)
+#define EFFECT_FLAG_VOLUME_CTRL (1 << EFFECT_FLAG_VOLUME_SHIFT)
+#define EFFECT_FLAG_VOLUME_IND (2 << EFFECT_FLAG_VOLUME_SHIFT)
+#define EFFECT_FLAG_VOLUME_NONE (0 << EFFECT_FLAG_VOLUME_SHIFT)
+
+// Device indication
+#define EFFECT_FLAG_DEVICE_SHIFT (EFFECT_FLAG_VOLUME_SHIFT + EFFECT_FLAG_VOLUME_SIZE)
+#define EFFECT_FLAG_DEVICE_SIZE 3
+#define EFFECT_FLAG_DEVICE_MASK (((1 << EFFECT_FLAG_DEVICE_SIZE) -1) \
+ << EFFECT_FLAG_DEVICE_SHIFT)
+#define EFFECT_FLAG_DEVICE_IND (1 << EFFECT_FLAG_DEVICE_SHIFT)
+#define EFFECT_FLAG_DEVICE_NONE (0 << EFFECT_FLAG_DEVICE_SHIFT)
+
+// Sample input modes
+#define EFFECT_FLAG_INPUT_SHIFT (EFFECT_FLAG_DEVICE_SHIFT + EFFECT_FLAG_DEVICE_SIZE)
+#define EFFECT_FLAG_INPUT_SIZE 2
+#define EFFECT_FLAG_INPUT_MASK (((1 << EFFECT_FLAG_INPUT_SIZE) -1) \
+ << EFFECT_FLAG_INPUT_SHIFT)
+#define EFFECT_FLAG_INPUT_DIRECT (1 << EFFECT_FLAG_INPUT_SHIFT)
+#define EFFECT_FLAG_INPUT_PROVIDER (2 << EFFECT_FLAG_INPUT_SHIFT)
+#define EFFECT_FLAG_INPUT_BOTH (3 << EFFECT_FLAG_INPUT_SHIFT)
+
+// Sample output modes
+#define EFFECT_FLAG_OUTPUT_SHIFT (EFFECT_FLAG_INPUT_SHIFT + EFFECT_FLAG_INPUT_SIZE)
+#define EFFECT_FLAG_OUTPUT_SIZE 2
+#define EFFECT_FLAG_OUTPUT_MASK (((1 << EFFECT_FLAG_OUTPUT_SIZE) -1) \
+ << EFFECT_FLAG_OUTPUT_SHIFT)
+#define EFFECT_FLAG_OUTPUT_DIRECT (1 << EFFECT_FLAG_OUTPUT_SHIFT)
+#define EFFECT_FLAG_OUTPUT_PROVIDER (2 << EFFECT_FLAG_OUTPUT_SHIFT)
+#define EFFECT_FLAG_OUTPUT_BOTH (3 << EFFECT_FLAG_OUTPUT_SHIFT)
+
+// Hardware acceleration mode
+#define EFFECT_FLAG_HW_ACC_SHIFT (EFFECT_FLAG_OUTPUT_SHIFT + EFFECT_FLAG_OUTPUT_SIZE)
+#define EFFECT_FLAG_HW_ACC_SIZE 2
+#define EFFECT_FLAG_HW_ACC_MASK (((1 << EFFECT_FLAG_HW_ACC_SIZE) -1) \
+ << EFFECT_FLAG_HW_ACC_SHIFT)
+#define EFFECT_FLAG_HW_ACC_SIMPLE (1 << EFFECT_FLAG_HW_ACC_SHIFT)
+#define EFFECT_FLAG_HW_ACC_TUNNEL (2 << EFFECT_FLAG_HW_ACC_SHIFT)
+
+// Audio mode indication
+#define EFFECT_FLAG_AUDIO_MODE_SHIFT (EFFECT_FLAG_HW_ACC_SHIFT + EFFECT_FLAG_HW_ACC_SIZE)
+#define EFFECT_FLAG_AUDIO_MODE_SIZE 2
+#define EFFECT_FLAG_AUDIO_MODE_MASK (((1 << EFFECT_FLAG_AUDIO_MODE_SIZE) -1) \
+ << EFFECT_FLAG_AUDIO_MODE_SHIFT)
+#define EFFECT_FLAG_AUDIO_MODE_IND (1 << EFFECT_FLAG_AUDIO_MODE_SHIFT)
+#define EFFECT_FLAG_AUDIO_MODE_NONE (0 << EFFECT_FLAG_AUDIO_MODE_SHIFT)
+
+// Audio source indication
+#define EFFECT_FLAG_AUDIO_SOURCE_SHIFT (EFFECT_FLAG_AUDIO_MODE_SHIFT + EFFECT_FLAG_AUDIO_MODE_SIZE)
+#define EFFECT_FLAG_AUDIO_SOURCE_SIZE 2
+#define EFFECT_FLAG_AUDIO_SOURCE_MASK (((1 << EFFECT_FLAG_AUDIO_SOURCE_SIZE) -1) \
+ << EFFECT_FLAG_AUDIO_SOURCE_SHIFT)
+#define EFFECT_FLAG_AUDIO_SOURCE_IND (1 << EFFECT_FLAG_AUDIO_SOURCE_SHIFT)
+#define EFFECT_FLAG_AUDIO_SOURCE_NONE (0 << EFFECT_FLAG_AUDIO_SOURCE_SHIFT)
+
+// Effect offload indication
+#define EFFECT_FLAG_OFFLOAD_SHIFT (EFFECT_FLAG_AUDIO_SOURCE_SHIFT + \
+ EFFECT_FLAG_AUDIO_SOURCE_SIZE)
+#define EFFECT_FLAG_OFFLOAD_SIZE 1
+#define EFFECT_FLAG_OFFLOAD_MASK (((1 << EFFECT_FLAG_OFFLOAD_SIZE) -1) \
+ << EFFECT_FLAG_OFFLOAD_SHIFT)
+#define EFFECT_FLAG_OFFLOAD_SUPPORTED (1 << EFFECT_FLAG_OFFLOAD_SHIFT)
+
+#define EFFECT_MAKE_API_VERSION(M, m) (((M)<<16) | ((m) & 0xFFFF))
+#define EFFECT_API_VERSION_MAJOR(v) ((v)>>16)
+#define EFFECT_API_VERSION_MINOR(v) ((m) & 0xFFFF)
+
+
+
+/////////////////////////////////////////////////
+// Effect control interface
+/////////////////////////////////////////////////
+
+// Effect control interface version 2.0
+#define EFFECT_CONTROL_API_VERSION EFFECT_MAKE_API_VERSION(2,0)
+
+// Effect control interface structure: effect_interface_s
+// The effect control interface is exposed by each effect engine implementation. It consists of
+// a set of functions controlling the configuration, activation and process of the engine.
+// The functions are grouped in a structure of type effect_interface_s.
+//
+// Effect control interface handle: effect_handle_t
+// The effect_handle_t serves two purposes regarding the implementation of the effect engine:
+// - 1 it is the address of a pointer to an effect_interface_s structure where the functions
+// of the effect control API for a particular effect are located.
+// - 2 it is the address of the context of a particular effect instance.
+// A typical implementation in the effect library would define a structure as follows:
+// struct effect_module_s {
+// const struct effect_interface_s *itfe;
+// effect_config_t config;
+// effect_context_t context;
+// }
+// The implementation of EffectCreate() function would then allocate a structure of this
+// type and return its address as effect_handle_t
+typedef struct effect_interface_s **effect_handle_t;
+
+
+// Forward definition of type audio_buffer_t
+typedef struct audio_buffer_s audio_buffer_t;
+
+
+
+
+
+
+// Effect control interface definition
+struct effect_interface_s {
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // Function: process
+ //
+ // Description: Effect process function. Takes input samples as specified
+ // (count and location) in input buffer descriptor and output processed
+ // samples as specified in output buffer descriptor. If the buffer descriptor
+ // is not specified the function must use either the buffer or the
+ // buffer provider function installed by the EFFECT_CMD_SET_CONFIG command.
+ // The effect framework will call the process() function after the EFFECT_CMD_ENABLE
+ // command is received and until the EFFECT_CMD_DISABLE is received. When the engine
+ // receives the EFFECT_CMD_DISABLE command it should turn off the effect gracefully
+ // and when done indicate that it is OK to stop calling the process() function by
+ // returning the -ENODATA status.
+ //
+ // NOTE: the process() function implementation should be "real-time safe" that is
+ // it should not perform blocking calls: malloc/free, sleep, read/write/open/close,
+ // pthread_cond_wait/pthread_mutex_lock...
+ //
+ // Input:
+ // self: handle to the effect interface this function
+ // is called on.
+ // inBuffer: buffer descriptor indicating where to read samples to process.
+ // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command.
+ //
+ // outBuffer: buffer descriptor indicating where to write processed samples.
+ // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command.
+ //
+ // Output:
+ // returned value: 0 successful operation
+ // -ENODATA the engine has finished the disable phase and the framework
+ // can stop calling process()
+ // -EINVAL invalid interface handle or
+ // invalid input/output buffer description
+ ////////////////////////////////////////////////////////////////////////////////
+ int32_t (*process)(effect_handle_t self,
+ audio_buffer_t *inBuffer,
+ audio_buffer_t *outBuffer);
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // Function: command
+ //
+ // Description: Send a command and receive a response to/from effect engine.
+ //
+ // Input:
+ // self: handle to the effect interface this function
+ // is called on.
+ // cmdCode: command code: the command can be a standardized command defined in
+ // effect_command_e (see below) or a proprietary command.
+ // cmdSize: size of command in bytes
+ // pCmdData: pointer to command data
+ // pReplyData: pointer to reply data
+ //
+ // Input/Output:
+ // replySize: maximum size of reply data as input
+ // actual size of reply data as output
+ //
+ // Output:
+ // returned value: 0 successful operation
+ // -EINVAL invalid interface handle or
+ // invalid command/reply size or format according to
+ // command code
+ // The return code should be restricted to indicate problems related to this API
+ // specification. Status related to the execution of a particular command should be
+ // indicated as part of the reply field.
+ //
+ // *pReplyData updated with command response
+ //
+ ////////////////////////////////////////////////////////////////////////////////
+ int32_t (*command)(effect_handle_t self,
+ uint32_t cmdCode,
+ uint32_t cmdSize,
+ void *pCmdData,
+ uint32_t *replySize,
+ void *pReplyData);
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // Function: get_descriptor
+ //
+ // Description: Returns the effect descriptor
+ //
+ // Input:
+ // self: handle to the effect interface this function
+ // is called on.
+ //
+ // Input/Output:
+ // pDescriptor: address where to return the effect descriptor.
+ //
+ // Output:
+ // returned value: 0 successful operation.
+ // -EINVAL invalid interface handle or invalid pDescriptor
+ // *pDescriptor: updated with the effect descriptor.
+ //
+ ////////////////////////////////////////////////////////////////////////////////
+ int32_t (*get_descriptor)(effect_handle_t self,
+ effect_descriptor_t *pDescriptor);
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // Function: process_reverse
+ //
+ // Description: Process reverse stream function. This function is used to pass
+ // a reference stream to the effect engine. If the engine does not need a reference
+ // stream, this function pointer can be set to NULL.
+ // This function would typically implemented by an Echo Canceler.
+ //
+ // Input:
+ // self: handle to the effect interface this function
+ // is called on.
+ // inBuffer: buffer descriptor indicating where to read samples to process.
+ // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command.
+ //
+ // outBuffer: buffer descriptor indicating where to write processed samples.
+ // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command.
+ // If the buffer and buffer provider in the configuration received by
+ // EFFECT_CMD_SET_CONFIG_REVERSE are also NULL, do not return modified reverse
+ // stream data
+ //
+ // Output:
+ // returned value: 0 successful operation
+ // -ENODATA the engine has finished the disable phase and the framework
+ // can stop calling process_reverse()
+ // -EINVAL invalid interface handle or
+ // invalid input/output buffer description
+ ////////////////////////////////////////////////////////////////////////////////
+ int32_t (*process_reverse)(effect_handle_t self,
+ audio_buffer_t *inBuffer,
+ audio_buffer_t *outBuffer);
+};
+
+
+//
+//--- Standardized command codes for command() function
+//
+enum effect_command_e {
+ EFFECT_CMD_INIT, // initialize effect engine
+ EFFECT_CMD_SET_CONFIG, // configure effect engine (see effect_config_t)
+ EFFECT_CMD_RESET, // reset effect engine
+ EFFECT_CMD_ENABLE, // enable effect process
+ EFFECT_CMD_DISABLE, // disable effect process
+ EFFECT_CMD_SET_PARAM, // set parameter immediately (see effect_param_t)
+ EFFECT_CMD_SET_PARAM_DEFERRED, // set parameter deferred
+ EFFECT_CMD_SET_PARAM_COMMIT, // commit previous set parameter deferred
+ EFFECT_CMD_GET_PARAM, // get parameter
+ EFFECT_CMD_SET_DEVICE, // set audio device (see audio.h, audio_devices_t)
+ EFFECT_CMD_SET_VOLUME, // set volume
+ EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...)
+ EFFECT_CMD_SET_CONFIG_REVERSE, // configure effect engine reverse stream(see effect_config_t)
+ EFFECT_CMD_SET_INPUT_DEVICE, // set capture device (see audio.h, audio_devices_t)
+ EFFECT_CMD_GET_CONFIG, // read effect engine configuration
+ EFFECT_CMD_GET_CONFIG_REVERSE, // read configure effect engine reverse stream configuration
+ EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS,// get all supported configurations for a feature.
+ EFFECT_CMD_GET_FEATURE_CONFIG, // get current feature configuration
+ EFFECT_CMD_SET_FEATURE_CONFIG, // set current feature configuration
+ EFFECT_CMD_SET_AUDIO_SOURCE, // set the audio source (see audio.h, audio_source_t)
+ EFFECT_CMD_OFFLOAD, // set if effect thread is an offload one,
+ // send the ioHandle of the effect thread
+ EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code
+};
+
+//==================================================================================================
+// command: EFFECT_CMD_INIT
+//--------------------------------------------------------------------------------------------------
+// description:
+// Initialize effect engine: All configurations return to default
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: 0
+// data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(int)
+// data: status
+//==================================================================================================
+// command: EFFECT_CMD_SET_CONFIG
+//--------------------------------------------------------------------------------------------------
+// description:
+// Apply new audio parameters configurations for input and output buffers
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(effect_config_t)
+// data: effect_config_t
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(int)
+// data: status
+//==================================================================================================
+// command: EFFECT_CMD_RESET
+//--------------------------------------------------------------------------------------------------
+// description:
+// Reset the effect engine. Keep configuration but resets state and buffer content
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: 0
+// data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: 0
+// data: N/A
+//==================================================================================================
+// command: EFFECT_CMD_ENABLE
+//--------------------------------------------------------------------------------------------------
+// description:
+// Enable the process. Called by the framework before the first call to process()
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: 0
+// data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(int)
+// data: status
+//==================================================================================================
+// command: EFFECT_CMD_DISABLE
+//--------------------------------------------------------------------------------------------------
+// description:
+// Disable the process. Called by the framework after the last call to process()
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: 0
+// data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(int)
+// data: status
+//==================================================================================================
+// command: EFFECT_CMD_SET_PARAM
+//--------------------------------------------------------------------------------------------------
+// description:
+// Set a parameter and apply it immediately
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(effect_param_t) + size of param and value
+// data: effect_param_t + param + value. See effect_param_t definition below for value offset
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(int)
+// data: status
+//==================================================================================================
+// command: EFFECT_CMD_SET_PARAM_DEFERRED
+//--------------------------------------------------------------------------------------------------
+// description:
+// Set a parameter but apply it only when receiving EFFECT_CMD_SET_PARAM_COMMIT command
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(effect_param_t) + size of param and value
+// data: effect_param_t + param + value. See effect_param_t definition below for value offset
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: 0
+// data: N/A
+//==================================================================================================
+// command: EFFECT_CMD_SET_PARAM_COMMIT
+//--------------------------------------------------------------------------------------------------
+// description:
+// Apply all previously received EFFECT_CMD_SET_PARAM_DEFERRED commands
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: 0
+// data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(int)
+// data: status
+//==================================================================================================
+// command: EFFECT_CMD_GET_PARAM
+//--------------------------------------------------------------------------------------------------
+// description:
+// Get a parameter value
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(effect_param_t) + size of param
+// data: effect_param_t + param
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(effect_param_t) + size of param and value
+// data: effect_param_t + param + value. See effect_param_t definition below for value offset
+//==================================================================================================
+// command: EFFECT_CMD_SET_DEVICE
+//--------------------------------------------------------------------------------------------------
+// description:
+// Set the rendering device the audio output path is connected to. See audio.h, audio_devices_t
+// for device values.
+// The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this
+// command when the device changes
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(uint32_t)
+// data: uint32_t
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: 0
+// data: N/A
+//==================================================================================================
+// command: EFFECT_CMD_SET_VOLUME
+//--------------------------------------------------------------------------------------------------
+// description:
+// Set and get volume. Used by audio framework to delegate volume control to effect engine.
+// The effect implementation must set EFFECT_FLAG_VOLUME_IND or EFFECT_FLAG_VOLUME_CTRL flag in
+// its descriptor to receive this command before every call to process() function
+// If EFFECT_FLAG_VOLUME_CTRL flag is set in the effect descriptor, the effect engine must return
+// the volume that should be applied before the effect is processed. The overall volume (the volume
+// actually applied by the effect engine multiplied by the returned value) should match the value
+// indicated in the command.
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: n * sizeof(uint32_t)
+// data: volume for each channel defined in effect_config_t for output buffer expressed in
+// 8.24 fixed point format
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: n * sizeof(uint32_t) / 0
+// data: - if EFFECT_FLAG_VOLUME_CTRL is set in effect descriptor:
+// volume for each channel defined in effect_config_t for output buffer expressed in
+// 8.24 fixed point format
+// - if EFFECT_FLAG_VOLUME_CTRL is not set in effect descriptor:
+// N/A
+// It is legal to receive a null pointer as pReplyData in which case the effect framework has
+// delegated volume control to another effect
+//==================================================================================================
+// command: EFFECT_CMD_SET_AUDIO_MODE
+//--------------------------------------------------------------------------------------------------
+// description:
+// Set the audio mode. The effect implementation must set EFFECT_FLAG_AUDIO_MODE_IND flag in its
+// descriptor to receive this command when the audio mode changes.
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(uint32_t)
+// data: audio_mode_t
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: 0
+// data: N/A
+//==================================================================================================
+// command: EFFECT_CMD_SET_CONFIG_REVERSE
+//--------------------------------------------------------------------------------------------------
+// description:
+// Apply new audio parameters configurations for input and output buffers of reverse stream.
+// An example of reverse stream is the echo reference supplied to an Acoustic Echo Canceler.
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(effect_config_t)
+// data: effect_config_t
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(int)
+// data: status
+//==================================================================================================
+// command: EFFECT_CMD_SET_INPUT_DEVICE
+//--------------------------------------------------------------------------------------------------
+// description:
+// Set the capture device the audio input path is connected to. See audio.h, audio_devices_t
+// for device values.
+// The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this
+// command when the device changes
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(uint32_t)
+// data: uint32_t
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: 0
+// data: N/A
+//==================================================================================================
+// command: EFFECT_CMD_GET_CONFIG
+//--------------------------------------------------------------------------------------------------
+// description:
+// Read audio parameters configurations for input and output buffers
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: 0
+// data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(effect_config_t)
+// data: effect_config_t
+//==================================================================================================
+// command: EFFECT_CMD_GET_CONFIG_REVERSE
+//--------------------------------------------------------------------------------------------------
+// description:
+// Read audio parameters configurations for input and output buffers of reverse stream
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: 0
+// data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(effect_config_t)
+// data: effect_config_t
+//==================================================================================================
+// command: EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS
+//--------------------------------------------------------------------------------------------------
+// description:
+// Queries for supported configurations for a particular feature (e.g. get the supported
+// combinations of main and auxiliary channels for a noise suppressor).
+// The command parameter is the feature identifier (See effect_feature_e for a list of defined
+// features) followed by the maximum number of configuration descriptor to return.
+// The reply is composed of:
+// - status (uint32_t):
+// - 0 if feature is supported
+// - -ENOSYS if the feature is not supported,
+// - -ENOMEM if the feature is supported but the total number of supported configurations
+// exceeds the maximum number indicated by the caller.
+// - total number of supported configurations (uint32_t)
+// - an array of configuration descriptors.
+// The actual number of descriptors returned must not exceed the maximum number indicated by
+// the caller.
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: 2 x sizeof(uint32_t)
+// data: effect_feature_e + maximum number of configurations to return
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: 2 x sizeof(uint32_t) + n x sizeof (<config descriptor>)
+// data: status + total number of configurations supported + array of n config descriptors
+//==================================================================================================
+// command: EFFECT_CMD_GET_FEATURE_CONFIG
+//--------------------------------------------------------------------------------------------------
+// description:
+// Retrieves current configuration for a given feature.
+// The reply status is:
+// - 0 if feature is supported
+// - -ENOSYS if the feature is not supported,
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(uint32_t)
+// data: effect_feature_e
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(uint32_t) + sizeof (<config descriptor>)
+// data: status + config descriptor
+//==================================================================================================
+// command: EFFECT_CMD_SET_FEATURE_CONFIG
+//--------------------------------------------------------------------------------------------------
+// description:
+// Sets current configuration for a given feature.
+// The reply status is:
+// - 0 if feature is supported
+// - -ENOSYS if the feature is not supported,
+// - -EINVAL if the configuration is invalid
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(uint32_t) + sizeof (<config descriptor>)
+// data: effect_feature_e + config descriptor
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(uint32_t)
+// data: status
+//==================================================================================================
+// command: EFFECT_CMD_SET_AUDIO_SOURCE
+//--------------------------------------------------------------------------------------------------
+// description:
+// Set the audio source the capture path is configured for (Camcorder, voice recognition...).
+// See audio.h, audio_source_t for values.
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(uint32_t)
+// data: uint32_t
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: 0
+// data: N/A
+//==================================================================================================
+// command: EFFECT_CMD_OFFLOAD
+//--------------------------------------------------------------------------------------------------
+// description:
+// 1.indicate if the playback thread the effect is attached to is offloaded or not
+// 2.update the io handle of the playback thread the effect is attached to
+//--------------------------------------------------------------------------------------------------
+// command format:
+// size: sizeof(effect_offload_param_t)
+// data: effect_offload_param_t
+//--------------------------------------------------------------------------------------------------
+// reply format:
+// size: sizeof(uint32_t)
+// data: uint32_t
+//--------------------------------------------------------------------------------------------------
+// command: EFFECT_CMD_FIRST_PROPRIETARY
+//--------------------------------------------------------------------------------------------------
+// description:
+// All proprietary effect commands must use command codes above this value. The size and format of
+// command and response fields is free in this case
+//==================================================================================================
+
+
+// Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t
+// structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with
+// regard to the channel mask definition in audio.h, audio_channel_mask_t e.g :
+// Stereo: left, right
+// 5 point 1: front left, front right, front center, low frequency, back left, back right
+// The buffer size is expressed in frame count, a frame being composed of samples for all
+// channels at a given time. Frame size for unspecified format (AUDIO_FORMAT_OTHER) is 8 bit by
+// definition
+struct audio_buffer_s {
+ size_t frameCount; // number of frames in buffer
+ union {
+ void* raw; // raw pointer to start of buffer
+ int32_t* s32; // pointer to signed 32 bit data at start of buffer
+ int16_t* s16; // pointer to signed 16 bit data at start of buffer
+ uint8_t* u8; // pointer to unsigned 8 bit data at start of buffer
+ };
+};
+
+// The buffer_provider_s structure contains functions that can be used
+// by the effect engine process() function to query and release input
+// or output audio buffer.
+// The getBuffer() function is called to retrieve a buffer where data
+// should read from or written to by process() function.
+// The releaseBuffer() function MUST be called when the buffer retrieved
+// with getBuffer() is not needed anymore.
+// The process function should use the buffer provider mechanism to retrieve
+// input or output buffer if the inBuffer or outBuffer passed as argument is NULL
+// and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_SET_CONFIG
+// command did not specify an audio buffer.
+
+typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer);
+
+typedef struct buffer_provider_s {
+ buffer_function_t getBuffer; // retrieve next buffer
+ buffer_function_t releaseBuffer; // release used buffer
+ void *cookie; // for use by client of buffer provider functions
+} buffer_provider_t;
+
+
+// The buffer_config_s structure specifies the input or output audio format
+// to be used by the effect engine. It is part of the effect_config_t
+// structure that defines both input and output buffer configurations and is
+// passed by the EFFECT_CMD_SET_CONFIG or EFFECT_CMD_SET_CONFIG_REVERSE command.
+typedef struct buffer_config_s {
+ audio_buffer_t buffer; // buffer for use by process() function if not passed explicitly
+ uint32_t samplingRate; // sampling rate
+ uint32_t channels; // channel mask (see audio_channel_mask_t in audio.h)
+ buffer_provider_t bufferProvider; // buffer provider
+ uint8_t format; // Audio format (see audio_format_t in audio.h)
+ uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e)
+ uint16_t mask; // indicates which of the above fields is valid
+} buffer_config_t;
+
+// Values for "accessMode" field of buffer_config_t:
+// overwrite, read only, accumulate (read/modify/write)
+enum effect_buffer_access_e {
+ EFFECT_BUFFER_ACCESS_WRITE,
+ EFFECT_BUFFER_ACCESS_READ,
+ EFFECT_BUFFER_ACCESS_ACCUMULATE
+
+};
+
+// feature identifiers for EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS command
+enum effect_feature_e {
+ EFFECT_FEATURE_AUX_CHANNELS, // supports auxiliary channels (e.g. dual mic noise suppressor)
+ EFFECT_FEATURE_CNT
+};
+
+// EFFECT_FEATURE_AUX_CHANNELS feature configuration descriptor. Describe a combination
+// of main and auxiliary channels supported
+typedef struct channel_config_s {
+ audio_channel_mask_t main_channels; // channel mask for main channels
+ audio_channel_mask_t aux_channels; // channel mask for auxiliary channels
+} channel_config_t;
+
+
+// Values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field
+// in buffer_config_t must be taken into account when executing the EFFECT_CMD_SET_CONFIG command
+#define EFFECT_CONFIG_BUFFER 0x0001 // buffer field must be taken into account
+#define EFFECT_CONFIG_SMP_RATE 0x0002 // samplingRate field must be taken into account
+#define EFFECT_CONFIG_CHANNELS 0x0004 // channels field must be taken into account
+#define EFFECT_CONFIG_FORMAT 0x0008 // format field must be taken into account
+#define EFFECT_CONFIG_ACC_MODE 0x0010 // accessMode field must be taken into account
+#define EFFECT_CONFIG_PROVIDER 0x0020 // bufferProvider field must be taken into account
+#define EFFECT_CONFIG_ALL (EFFECT_CONFIG_BUFFER | EFFECT_CONFIG_SMP_RATE | \
+ EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | \
+ EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER)
+
+
+// effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_CONFIG
+// command to configure audio parameters and buffers for effect engine input and output.
+typedef struct effect_config_s {
+ buffer_config_t inputCfg;
+ buffer_config_t outputCfg;
+} effect_config_t;
+
+
+// effect_param_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_PARAM
+// command and pCmdData and pReplyData of EFFECT_CMD_GET_PARAM command.
+// psize and vsize represent the actual size of parameter and value.
+//
+// NOTE: the start of value field inside the data field is always on a 32 bit boundary:
+//
+// +-----------+
+// | status | sizeof(int)
+// +-----------+
+// | psize | sizeof(int)
+// +-----------+
+// | vsize | sizeof(int)
+// +-----------+
+// | | | |
+// ~ parameter ~ > psize |
+// | | | > ((psize - 1)/sizeof(int) + 1) * sizeof(int)
+// +-----------+ |
+// | padding | |
+// +-----------+
+// | | |
+// ~ value ~ > vsize
+// | | |
+// +-----------+
+
+typedef struct effect_param_s {
+ int32_t status; // Transaction status (unused for command, used for reply)
+ uint32_t psize; // Parameter size
+ uint32_t vsize; // Value size
+ char data[]; // Start of Parameter + Value data
+} effect_param_t;
+
+// structure used by EFFECT_CMD_OFFLOAD command
+typedef struct effect_offload_param_s {
+ bool isOffload; // true if the playback thread the effect is attached to is offloaded
+ int ioHandle; // io handle of the playback thread the effect is attached to
+} effect_offload_param_t;
+
+
+/////////////////////////////////////////////////
+// Effect library interface
+/////////////////////////////////////////////////
+
+// Effect library interface version 3.0
+// Note that EffectsFactory.c only checks the major version component, so changes to the minor
+// number can only be used for fully backwards compatible changes
+#define EFFECT_LIBRARY_API_VERSION EFFECT_MAKE_API_VERSION(3,0)
+
+#define AUDIO_EFFECT_LIBRARY_TAG ((('A') << 24) | (('E') << 16) | (('L') << 8) | ('T'))
+
+// Every effect library must have a data structure named AUDIO_EFFECT_LIBRARY_INFO_SYM
+// and the fields of this data structure must begin with audio_effect_library_t
+
+typedef struct audio_effect_library_s {
+ // tag must be initialized to AUDIO_EFFECT_LIBRARY_TAG
+ uint32_t tag;
+ // Version of the effect library API : 0xMMMMmmmm MMMM: Major, mmmm: minor
+ uint32_t version;
+ // Name of this library
+ const char *name;
+ // Author/owner/implementor of the library
+ const char *implementor;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // Function: create_effect
+ //
+ // Description: Creates an effect engine of the specified implementation uuid and
+ // returns an effect control interface on this engine. The function will allocate the
+ // resources for an instance of the requested effect engine and return
+ // a handle on the effect control interface.
+ //
+ // Input:
+ // uuid: pointer to the effect uuid.
+ // sessionId: audio session to which this effect instance will be attached.
+ // All effects created with the same session ID are connected in series and process
+ // the same signal stream. Knowing that two effects are part of the same effect
+ // chain can help the library implement some kind of optimizations.
+ // ioId: identifies the output or input stream this effect is directed to in
+ // audio HAL.
+ // For future use especially with tunneled HW accelerated effects
+ //
+ // Input/Output:
+ // pHandle: address where to return the effect interface handle.
+ //
+ // Output:
+ // returned value: 0 successful operation.
+ // -ENODEV library failed to initialize
+ // -EINVAL invalid pEffectUuid or pHandle
+ // -ENOENT no effect with this uuid found
+ // *pHandle: updated with the effect interface handle.
+ //
+ ////////////////////////////////////////////////////////////////////////////////
+ int32_t (*create_effect)(const effect_uuid_t *uuid,
+ int32_t sessionId,
+ int32_t ioId,
+ effect_handle_t *pHandle);
+
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // Function: release_effect
+ //
+ // Description: Releases the effect engine whose handle is given as argument.
+ // All resources allocated to this particular instance of the effect are
+ // released.
+ //
+ // Input:
+ // handle: handle on the effect interface to be released.
+ //
+ // Output:
+ // returned value: 0 successful operation.
+ // -ENODEV library failed to initialize
+ // -EINVAL invalid interface handle
+ //
+ ////////////////////////////////////////////////////////////////////////////////
+ int32_t (*release_effect)(effect_handle_t handle);
+
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // Function: get_descriptor
+ //
+ // Description: Returns the descriptor of the effect engine which implementation UUID is
+ // given as argument.
+ //
+ // Input/Output:
+ // uuid: pointer to the effect uuid.
+ // pDescriptor: address where to return the effect descriptor.
+ //
+ // Output:
+ // returned value: 0 successful operation.
+ // -ENODEV library failed to initialize
+ // -EINVAL invalid pDescriptor or uuid
+ // *pDescriptor: updated with the effect descriptor.
+ //
+ ////////////////////////////////////////////////////////////////////////////////
+ int32_t (*get_descriptor)(const effect_uuid_t *uuid,
+ effect_descriptor_t *pDescriptor);
+} audio_effect_library_t;
+
+// Name of the hal_module_info
+#define AUDIO_EFFECT_LIBRARY_INFO_SYM AELI
+
+// Name of the hal_module_info as a string
+#define AUDIO_EFFECT_LIBRARY_INFO_SYM_AS_STR "AELI"
+
+__END_DECLS
+
+#endif // ANDROID_AUDIO_EFFECT_H
diff --git a/libhardware/include/hardware/audio_policy.h b/libhardware/include/hardware/audio_policy.h
new file mode 100644
index 0000000..99cb044
--- /dev/null
+++ b/libhardware/include/hardware/audio_policy.h
@@ -0,0 +1,457 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_POLICY_INTERFACE_H
+#define ANDROID_AUDIO_POLICY_INTERFACE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+#include <system/audio.h>
+#include <system/audio_policy.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define AUDIO_POLICY_HARDWARE_MODULE_ID "audio_policy"
+
+/**
+ * Name of the audio devices to open
+ */
+#define AUDIO_POLICY_INTERFACE "policy"
+
+/* ---------------------------------------------------------------------------- */
+
+/*
+ * The audio_policy and audio_policy_service_ops structs define the
+ * communication interfaces between the platform specific audio policy manager
+ * and Android generic audio policy manager.
+ * The platform specific audio policy manager must implement methods of the
+ * audio_policy struct.
+ * This implementation makes use of the audio_policy_service_ops to control
+ * the activity and configuration of audio input and output streams.
+ *
+ * The platform specific audio policy manager is in charge of the audio
+ * routing and volume control policies for a given platform.
+ * The main roles of this module are:
+ * - keep track of current system state (removable device connections, phone
+ * state, user requests...).
+ * System state changes and user actions are notified to audio policy
+ * manager with methods of the audio_policy.
+ *
+ * - process get_output() queries received when AudioTrack objects are
+ * created: Those queries return a handler on an output that has been
+ * selected, configured and opened by the audio policy manager and that
+ * must be used by the AudioTrack when registering to the AudioFlinger
+ * with the createTrack() method.
+ * When the AudioTrack object is released, a release_output() query
+ * is received and the audio policy manager can decide to close or
+ * reconfigure the output depending on other streams using this output and
+ * current system state.
+ *
+ * - similarly process get_input() and release_input() queries received from
+ * AudioRecord objects and configure audio inputs.
+ * - process volume control requests: the stream volume is converted from
+ * an index value (received from UI) to a float value applicable to each
+ * output as a function of platform specific settings and current output
+ * route (destination device). It also make sure that streams are not
+ * muted if not allowed (e.g. camera shutter sound in some countries).
+ */
+
+/* XXX: this should be defined OUTSIDE of frameworks/base */
+struct effect_descriptor_s;
+
+struct audio_policy {
+ /*
+ * configuration functions
+ */
+
+ /* indicate a change in device connection status */
+ int (*set_device_connection_state)(struct audio_policy *pol,
+ audio_devices_t device,
+ audio_policy_dev_state_t state,
+ const char *device_address);
+
+ /* retrieve a device connection status */
+ audio_policy_dev_state_t (*get_device_connection_state)(
+ const struct audio_policy *pol,
+ audio_devices_t device,
+ const char *device_address);
+
+ /* indicate a change in phone state. Valid phones states are defined
+ * by audio_mode_t */
+ void (*set_phone_state)(struct audio_policy *pol, audio_mode_t state);
+
+ /* deprecated, never called (was "indicate a change in ringer mode") */
+ void (*set_ringer_mode)(struct audio_policy *pol, uint32_t mode,
+ uint32_t mask);
+
+ /* force using a specific device category for the specified usage */
+ void (*set_force_use)(struct audio_policy *pol,
+ audio_policy_force_use_t usage,
+ audio_policy_forced_cfg_t config);
+
+ /* retrieve current device category forced for a given usage */
+ audio_policy_forced_cfg_t (*get_force_use)(const struct audio_policy *pol,
+ audio_policy_force_use_t usage);
+
+ /* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
+ * can still be muted. */
+ void (*set_can_mute_enforced_audible)(struct audio_policy *pol,
+ bool can_mute);
+
+ /* check proper initialization */
+ int (*init_check)(const struct audio_policy *pol);
+
+ /*
+ * Audio routing query functions
+ */
+
+ /* request an output appropriate for playback of the supplied stream type and
+ * parameters */
+ audio_io_handle_t (*get_output)(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ uint32_t samplingRate,
+ audio_format_t format,
+ audio_channel_mask_t channelMask,
+ audio_output_flags_t flags,
+ const audio_offload_info_t *offloadInfo);
+
+ /* indicates to the audio policy manager that the output starts being used
+ * by corresponding stream. */
+ int (*start_output)(struct audio_policy *pol,
+ audio_io_handle_t output,
+ audio_stream_type_t stream,
+ int session);
+
+ /* indicates to the audio policy manager that the output stops being used
+ * by corresponding stream. */
+ int (*stop_output)(struct audio_policy *pol,
+ audio_io_handle_t output,
+ audio_stream_type_t stream,
+ int session);
+
+ /* releases the output. */
+ void (*release_output)(struct audio_policy *pol, audio_io_handle_t output);
+
+ /* request an input appropriate for record from the supplied device with
+ * supplied parameters. */
+ audio_io_handle_t (*get_input)(struct audio_policy *pol, audio_source_t inputSource,
+ uint32_t samplingRate,
+ audio_format_t format,
+ audio_channel_mask_t channelMask,
+ audio_in_acoustics_t acoustics);
+
+ /* indicates to the audio policy manager that the input starts being used */
+ int (*start_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+ /* indicates to the audio policy manager that the input stops being used. */
+ int (*stop_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+ /* releases the input. */
+ void (*release_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+ /*
+ * volume control functions
+ */
+
+ /* initialises stream volume conversion parameters by specifying volume
+ * index range. The index range for each stream is defined by AudioService. */
+ void (*init_stream_volume)(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int index_min,
+ int index_max);
+
+ /* sets the new stream volume at a level corresponding to the supplied
+ * index. The index is within the range specified by init_stream_volume() */
+ int (*set_stream_volume_index)(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int index);
+
+ /* retrieve current volume index for the specified stream */
+ int (*get_stream_volume_index)(const struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int *index);
+
+ /* sets the new stream volume at a level corresponding to the supplied
+ * index for the specified device.
+ * The index is within the range specified by init_stream_volume() */
+ int (*set_stream_volume_index_for_device)(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int index,
+ audio_devices_t device);
+
+ /* retrieve current volume index for the specified stream for the specified device */
+ int (*get_stream_volume_index_for_device)(const struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int *index,
+ audio_devices_t device);
+
+ /* return the strategy corresponding to a given stream type */
+ uint32_t (*get_strategy_for_stream)(const struct audio_policy *pol,
+ audio_stream_type_t stream);
+
+ /* return the enabled output devices for the given stream type */
+ audio_devices_t (*get_devices_for_stream)(const struct audio_policy *pol,
+ audio_stream_type_t stream);
+
+ /* Audio effect management */
+ audio_io_handle_t (*get_output_for_effect)(struct audio_policy *pol,
+ const struct effect_descriptor_s *desc);
+
+ int (*register_effect)(struct audio_policy *pol,
+ const struct effect_descriptor_s *desc,
+ audio_io_handle_t output,
+ uint32_t strategy,
+ int session,
+ int id);
+
+ int (*unregister_effect)(struct audio_policy *pol, int id);
+
+ int (*set_effect_enabled)(struct audio_policy *pol, int id, bool enabled);
+
+ bool (*is_stream_active)(const struct audio_policy *pol,
+ audio_stream_type_t stream,
+ uint32_t in_past_ms);
+
+ bool (*is_stream_active_remotely)(const struct audio_policy *pol,
+ audio_stream_type_t stream,
+ uint32_t in_past_ms);
+
+ bool (*is_source_active)(const struct audio_policy *pol,
+ audio_source_t source);
+
+ /* dump state */
+ int (*dump)(const struct audio_policy *pol, int fd);
+
+ /* check if offload is possible for given sample rate, bitrate, duration, ... */
+ bool (*is_offload_supported)(const struct audio_policy *pol,
+ const audio_offload_info_t *info);
+};
+
+
+struct audio_policy_service_ops {
+ /*
+ * Audio output Control functions
+ */
+
+ /* Opens an audio output with the requested parameters.
+ *
+ * The parameter values can indicate to use the default values in case the
+ * audio policy manager has no specific requirements for the output being
+ * opened.
+ *
+ * When the function returns, the parameter values reflect the actual
+ * values used by the audio hardware output stream.
+ *
+ * The audio policy manager can check if the proposed parameters are
+ * suitable or not and act accordingly.
+ */
+ audio_io_handle_t (*open_output)(void *service,
+ audio_devices_t *pDevices,
+ uint32_t *pSamplingRate,
+ audio_format_t *pFormat,
+ audio_channel_mask_t *pChannelMask,
+ uint32_t *pLatencyMs,
+ audio_output_flags_t flags);
+
+ /* creates a special output that is duplicated to the two outputs passed as
+ * arguments. The duplication is performed by
+ * a special mixer thread in the AudioFlinger.
+ */
+ audio_io_handle_t (*open_duplicate_output)(void *service,
+ audio_io_handle_t output1,
+ audio_io_handle_t output2);
+
+ /* closes the output stream */
+ int (*close_output)(void *service, audio_io_handle_t output);
+
+ /* suspends the output.
+ *
+ * When an output is suspended, the corresponding audio hardware output
+ * stream is placed in standby and the AudioTracks attached to the mixer
+ * thread are still processed but the output mix is discarded.
+ */
+ int (*suspend_output)(void *service, audio_io_handle_t output);
+
+ /* restores a suspended output. */
+ int (*restore_output)(void *service, audio_io_handle_t output);
+
+ /* */
+ /* Audio input Control functions */
+ /* */
+
+ /* opens an audio input
+ * deprecated - new implementations should use open_input_on_module,
+ * and the acoustics parameter is ignored
+ */
+ audio_io_handle_t (*open_input)(void *service,
+ audio_devices_t *pDevices,
+ uint32_t *pSamplingRate,
+ audio_format_t *pFormat,
+ audio_channel_mask_t *pChannelMask,
+ audio_in_acoustics_t acoustics);
+
+ /* closes an audio input */
+ int (*close_input)(void *service, audio_io_handle_t input);
+
+ /* */
+ /* misc control functions */
+ /* */
+
+ /* set a stream volume for a particular output.
+ *
+ * For the same user setting, a given stream type can have different
+ * volumes for each output (destination device) it is attached to.
+ */
+ int (*set_stream_volume)(void *service,
+ audio_stream_type_t stream,
+ float volume,
+ audio_io_handle_t output,
+ int delay_ms);
+
+ /* invalidate a stream type, causing a reroute to an unspecified new output */
+ int (*invalidate_stream)(void *service,
+ audio_stream_type_t stream);
+
+ /* function enabling to send proprietary informations directly from audio
+ * policy manager to audio hardware interface. */
+ void (*set_parameters)(void *service,
+ audio_io_handle_t io_handle,
+ const char *kv_pairs,
+ int delay_ms);
+
+ /* function enabling to receive proprietary informations directly from
+ * audio hardware interface to audio policy manager.
+ *
+ * Returns a pointer to a heap allocated string. The caller is responsible
+ * for freeing the memory for it using free().
+ */
+
+ char * (*get_parameters)(void *service, audio_io_handle_t io_handle,
+ const char *keys);
+
+ /* request the playback of a tone on the specified stream.
+ * used for instance to replace notification sounds when playing over a
+ * telephony device during a phone call.
+ */
+ int (*start_tone)(void *service,
+ audio_policy_tone_t tone,
+ audio_stream_type_t stream);
+
+ int (*stop_tone)(void *service);
+
+ /* set down link audio volume. */
+ int (*set_voice_volume)(void *service,
+ float volume,
+ int delay_ms);
+
+ /* move effect to the specified output */
+ int (*move_effects)(void *service,
+ int session,
+ audio_io_handle_t src_output,
+ audio_io_handle_t dst_output);
+
+ /* loads an audio hw module.
+ *
+ * The module name passed is the base name of the HW module library, e.g "primary" or "a2dp".
+ * The function returns a handle on the module that will be used to specify a particular
+ * module when calling open_output_on_module() or open_input_on_module()
+ */
+ audio_module_handle_t (*load_hw_module)(void *service,
+ const char *name);
+
+ /* Opens an audio output on a particular HW module.
+ *
+ * Same as open_output() but specifying a specific HW module on which the output must be opened.
+ */
+ audio_io_handle_t (*open_output_on_module)(void *service,
+ audio_module_handle_t module,
+ audio_devices_t *pDevices,
+ uint32_t *pSamplingRate,
+ audio_format_t *pFormat,
+ audio_channel_mask_t *pChannelMask,
+ uint32_t *pLatencyMs,
+ audio_output_flags_t flags,
+ const audio_offload_info_t *offloadInfo);
+
+ /* Opens an audio input on a particular HW module.
+ *
+ * Same as open_input() but specifying a specific HW module on which the input must be opened.
+ * Also removed deprecated acoustics parameter
+ */
+ audio_io_handle_t (*open_input_on_module)(void *service,
+ audio_module_handle_t module,
+ audio_devices_t *pDevices,
+ uint32_t *pSamplingRate,
+ audio_format_t *pFormat,
+ audio_channel_mask_t *pChannelMask);
+
+};
+
+/**********************************************************************/
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+typedef struct audio_policy_module {
+ struct hw_module_t common;
+} audio_policy_module_t;
+
+struct audio_policy_device {
+ /**
+ * Common methods of the audio policy device. This *must* be the first member of
+ * audio_policy_device as users of this structure will cast a hw_device_t to
+ * audio_policy_device pointer in contexts where it's known the hw_device_t references an
+ * audio_policy_device.
+ */
+ struct hw_device_t common;
+
+ int (*create_audio_policy)(const struct audio_policy_device *device,
+ struct audio_policy_service_ops *aps_ops,
+ void *service,
+ struct audio_policy **ap);
+
+ int (*destroy_audio_policy)(const struct audio_policy_device *device,
+ struct audio_policy *ap);
+};
+
+/** convenience API for opening and closing a supported device */
+
+static inline int audio_policy_dev_open(const hw_module_t* module,
+ struct audio_policy_device** device)
+{
+ return module->methods->open(module, AUDIO_POLICY_INTERFACE,
+ (hw_device_t**)device);
+}
+
+static inline int audio_policy_dev_close(struct audio_policy_device* device)
+{
+ return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif // ANDROID_AUDIO_POLICY_INTERFACE_H
diff --git a/libhardware/include/hardware/ble_advertiser.h b/libhardware/include/hardware/ble_advertiser.h
new file mode 100644
index 0000000..f486ed8
--- /dev/null
+++ b/libhardware/include/hardware/ble_advertiser.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BLE_ADVERTISER_H
+#define ANDROID_INCLUDE_BLE_ADVERTISER_H
+
+#include <base/callback_forward.h>
+#include <stdint.h>
+#include <vector>
+#include "bt_common_types.h"
+#include "bt_gatt_types.h"
+
+using std::vector;
+
+/** Callback invoked when multi-adv operation has completed */
+using BleAdvertiserCb = base::Callback<void(uint8_t /* status */)>;
+
+class BleAdvertiserInterface {
+ public:
+ virtual ~BleAdvertiserInterface() = default;
+
+ /** Registers an advertiser with the stack */
+ virtual void RegisterAdvertiser(
+ base::Callback<void(uint8_t /* advertiser_id */, uint8_t /* status */)>) = 0;
+
+ /* This function disable a Multi-ADV instance */
+ virtual void Unregister(uint8_t advertiser_id) = 0;
+
+ /** Set the advertising data or scan response data */
+ virtual void SetData(bool set_scan_rsp, vector<uint8_t> data) = 0;
+
+ /** Start or stop advertising */
+ virtual void Enable(bool start, BleAdvertiserCb cb) = 0;
+
+ /* Set the parameters as per spec, user manual specified values */
+ virtual void MultiAdvSetParameters(int advertiser_id, int min_interval,
+ int max_interval, int adv_type,
+ int chnl_map, int tx_power,
+ BleAdvertiserCb cb) = 0;
+
+ /* Setup the data for the specified instance */
+ virtual void MultiAdvSetInstData(int advertiser_id, bool set_scan_rsp,
+ vector<uint8_t> data,
+ BleAdvertiserCb cb) = 0;
+
+ /* Enable the advertising instance as per spec */
+ virtual void MultiAdvEnable(uint8_t advertiser_id, bool enable,
+ BleAdvertiserCb cb, int timeout_s,
+ BleAdvertiserCb timeout_cb) = 0;
+};
+
+#endif /* ANDROID_INCLUDE_BLE_ADVERTISER_H */
diff --git a/libhardware/include/hardware/ble_scanner.h b/libhardware/include/hardware/ble_scanner.h
new file mode 100644
index 0000000..dca7e43
--- /dev/null
+++ b/libhardware/include/hardware/ble_scanner.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BLE_SCANNER_H
+#define ANDROID_INCLUDE_BLE_SCANNER_H
+
+#include <stdint.h>
+#include <vector>
+#include "bt_gatt_types.h"
+#include "bt_common_types.h"
+#include "bt_gatt_client.h"
+
+/** Callback invoked in response to register_scanner */
+typedef void (*register_scanner_callback)(int status, int scanner_id,
+ bt_uuid_t *app_uuid);
+
+/** Callback invoked when batchscan storage config operation has completed */
+typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
+
+/** Callback invoked when batchscan enable / disable operation has completed */
+typedef void (*batchscan_enable_disable_callback)(int action, int client_if, int status);
+
+/** Callback invoked when batchscan reports are obtained */
+typedef void (*batchscan_reports_callback)(int client_if, int status, int report_format,
+ int num_records, std::vector<uint8_t> data);
+
+/** Callback invoked when batchscan storage threshold limit is crossed */
+typedef void (*batchscan_threshold_callback)(int client_if);
+
+/** Track ADV VSE callback invoked when tracked device is found or lost */
+typedef void (*track_adv_event_callback)(btgatt_track_adv_info_t *p_track_adv_info);
+
+/** Callback invoked when scan parameter setup has completed */
+typedef void (*scan_parameter_setup_completed_callback)(int client_if,
+ btgattc_error_t status);
+
+/** Callback for scan results */
+typedef void (*scan_result_callback)(bt_bdaddr_t* bda, int rssi, std::vector<uint8_t> adv_data);
+
+/** Callback invoked when a scan filter configuration command has completed */
+typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status, int filt_type,
+ int avbl_space);
+
+/** Callback invoked when scan param has been added, cleared, or deleted */
+typedef void (*scan_filter_param_callback)(int action, int client_if, int status,
+ int avbl_space);
+
+/** Callback invoked when a scan filter configuration command has completed */
+typedef void (*scan_filter_status_callback)(int enable, int client_if, int status);
+
+typedef struct {
+ register_scanner_callback register_scanner_cb;
+ scan_result_callback scan_result_cb;
+ batchscan_cfg_storage_callback batchscan_cfg_storage_cb;
+ batchscan_enable_disable_callback batchscan_enb_disable_cb;
+ batchscan_reports_callback batchscan_reports_cb;
+ batchscan_threshold_callback batchscan_threshold_cb;
+ track_adv_event_callback track_adv_event_cb;
+ scan_parameter_setup_completed_callback scan_parameter_setup_completed_cb;
+ scan_filter_cfg_callback scan_filter_cfg_cb;
+ scan_filter_param_callback scan_filter_param_cb;
+ scan_filter_status_callback scan_filter_status_cb;
+} btgatt_scanner_callbacks_t;
+
+typedef struct {
+ /** Registers a scanner with the stack */
+ bt_status_t (*register_scanner)( bt_uuid_t *uuid );
+
+ /** Unregister a scanner from the stack */
+ bt_status_t (*unregister_scanner)(int scanner_id );
+
+ /** Start or stop LE device scanning */
+ bt_status_t (*scan)( bool start );
+
+ /** Setup scan filter params */
+ bt_status_t (*scan_filter_param_setup)(btgatt_filt_param_setup_t filt_param);
+
+
+ /** Configure a scan filter condition */
+ bt_status_t (*scan_filter_add_remove)(int client_if, int action, int filt_type,
+ int filt_index, int company_id,
+ int company_id_mask, const bt_uuid_t *p_uuid,
+ const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr,
+ char addr_type, std::vector<uint8_t> data,
+ std::vector<uint8_t> p_mask);
+
+ /** Clear all scan filter conditions for specific filter index*/
+ bt_status_t (*scan_filter_clear)(int client_if, int filt_index);
+
+ /** Enable / disable scan filter feature*/
+ bt_status_t (*scan_filter_enable)(int client_if, bool enable);
+
+ /** Sets the LE scan interval and window in units of N*0.625 msec */
+ bt_status_t (*set_scan_parameters)(int client_if, int scan_interval, int scan_window);
+
+ /* Configure the batchscan storage */
+ bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
+ int batch_scan_trunc_max, int batch_scan_notify_threshold);
+
+ /* Enable batchscan */
+ bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
+ int scan_interval, int scan_window, int addr_type, int discard_rule);
+
+ /* Disable batchscan */
+ bt_status_t (*batchscan_dis_batch_scan)(int client_if);
+
+ /* Read out batchscan reports */
+ bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
+
+} btgatt_scanner_interface_t;
+
+#endif /* ANDROID_INCLUDE_BLE_SCANNER_H */
\ No newline at end of file
diff --git a/libhardware/include/hardware/bluetooth.h b/libhardware/include/hardware/bluetooth.h
new file mode 100644
index 0000000..125a95b
--- /dev/null
+++ b/libhardware/include/hardware/bluetooth.h
@@ -0,0 +1,610 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BLUETOOTH_H
+#define ANDROID_INCLUDE_BLUETOOTH_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+/**
+ * The Bluetooth Hardware Module ID
+ */
+
+#define BT_HARDWARE_MODULE_ID "bluetooth"
+#define BT_STACK_MODULE_ID "bluetooth"
+#define BT_STACK_TEST_MODULE_ID "bluetooth_test"
+
+
+/* Bluetooth profile interface IDs */
+
+#define BT_PROFILE_HANDSFREE_ID "handsfree"
+#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
+#define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
+#define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
+#define BT_PROFILE_HEALTH_ID "health"
+#define BT_PROFILE_SOCKETS_ID "socket"
+#define BT_PROFILE_HIDHOST_ID "hidhost"
+#define BT_PROFILE_PAN_ID "pan"
+#define BT_PROFILE_MAP_CLIENT_ID "map_client"
+#define BT_PROFILE_SDP_CLIENT_ID "sdp"
+#define BT_PROFILE_GATT_ID "gatt"
+#define BT_PROFILE_AV_RC_ID "avrcp"
+#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
+
+/** Bluetooth Address */
+typedef struct {
+ uint8_t address[6];
+} __attribute__((packed))bt_bdaddr_t;
+
+/** Bluetooth Device Name */
+typedef struct {
+ uint8_t name[249];
+} __attribute__((packed))bt_bdname_t;
+
+/** Bluetooth Adapter Visibility Modes*/
+typedef enum {
+ BT_SCAN_MODE_NONE,
+ BT_SCAN_MODE_CONNECTABLE,
+ BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
+} bt_scan_mode_t;
+
+/** Bluetooth Adapter State */
+typedef enum {
+ BT_STATE_OFF,
+ BT_STATE_ON
+} bt_state_t;
+
+/** Bluetooth Error Status */
+/** We need to build on this */
+
+typedef enum {
+ BT_STATUS_SUCCESS,
+ BT_STATUS_FAIL,
+ BT_STATUS_NOT_READY,
+ BT_STATUS_NOMEM,
+ BT_STATUS_BUSY,
+ BT_STATUS_DONE, /* request already completed */
+ BT_STATUS_UNSUPPORTED,
+ BT_STATUS_PARM_INVALID,
+ BT_STATUS_UNHANDLED,
+ BT_STATUS_AUTH_FAILURE,
+ BT_STATUS_RMT_DEV_DOWN,
+ BT_STATUS_AUTH_REJECTED,
+ BT_STATUS_JNI_ENVIRONMENT_ERROR,
+ BT_STATUS_JNI_THREAD_ATTACH_ERROR,
+ BT_STATUS_WAKELOCK_ERROR
+} bt_status_t;
+
+/** Bluetooth PinKey Code */
+typedef struct {
+ uint8_t pin[16];
+} __attribute__((packed))bt_pin_code_t;
+
+typedef struct {
+ uint8_t status;
+ uint8_t ctrl_state; /* stack reported state */
+ uint64_t tx_time; /* in ms */
+ uint64_t rx_time; /* in ms */
+ uint64_t idle_time; /* in ms */
+ uint64_t energy_used; /* a product of mA, V and ms */
+} __attribute__((packed))bt_activity_energy_info;
+
+typedef struct {
+ int32_t app_uid;
+ uint64_t tx_bytes;
+ uint64_t rx_bytes;
+} __attribute__((packed))bt_uid_traffic_t;
+
+/** Bluetooth Adapter Discovery state */
+typedef enum {
+ BT_DISCOVERY_STOPPED,
+ BT_DISCOVERY_STARTED
+} bt_discovery_state_t;
+
+/** Bluetooth ACL connection state */
+typedef enum {
+ BT_ACL_STATE_CONNECTED,
+ BT_ACL_STATE_DISCONNECTED
+} bt_acl_state_t;
+
+/** Bluetooth 128-bit UUID */
+typedef struct {
+ uint8_t uu[16];
+} bt_uuid_t;
+
+/** Bluetooth SDP service record */
+typedef struct
+{
+ bt_uuid_t uuid;
+ uint16_t channel;
+ char name[256]; // what's the maximum length
+} bt_service_record_t;
+
+
+/** Bluetooth Remote Version info */
+typedef struct
+{
+ int version;
+ int sub_ver;
+ int manufacturer;
+} bt_remote_version_t;
+
+typedef struct
+{
+ uint16_t version_supported;
+ uint8_t local_privacy_enabled;
+ uint8_t max_adv_instance;
+ uint8_t rpa_offload_supported;
+ uint8_t max_irk_list_size;
+ uint8_t max_adv_filter_supported;
+ uint8_t activity_energy_info_supported;
+ uint16_t scan_result_storage_size;
+ uint16_t total_trackable_advertisers;
+ bool extended_scan_support;
+ bool debug_logging_supported;
+}bt_local_le_features_t;
+
+/* Bluetooth Adapter and Remote Device property types */
+typedef enum {
+ /* Properties common to both adapter and remote device */
+ /**
+ * Description - Bluetooth Device Name
+ * Access mode - Adapter name can be GET/SET. Remote device can be GET
+ * Data type - bt_bdname_t
+ */
+ BT_PROPERTY_BDNAME = 0x1,
+ /**
+ * Description - Bluetooth Device Address
+ * Access mode - Only GET.
+ * Data type - bt_bdaddr_t
+ */
+ BT_PROPERTY_BDADDR,
+ /**
+ * Description - Bluetooth Service 128-bit UUIDs
+ * Access mode - Only GET.
+ * Data type - Array of bt_uuid_t (Array size inferred from property length).
+ */
+ BT_PROPERTY_UUIDS,
+ /**
+ * Description - Bluetooth Class of Device as found in Assigned Numbers
+ * Access mode - Only GET.
+ * Data type - uint32_t.
+ */
+ BT_PROPERTY_CLASS_OF_DEVICE,
+ /**
+ * Description - Device Type - BREDR, BLE or DUAL Mode
+ * Access mode - Only GET.
+ * Data type - bt_device_type_t
+ */
+ BT_PROPERTY_TYPE_OF_DEVICE,
+ /**
+ * Description - Bluetooth Service Record
+ * Access mode - Only GET.
+ * Data type - bt_service_record_t
+ */
+ BT_PROPERTY_SERVICE_RECORD,
+
+ /* Properties unique to adapter */
+ /**
+ * Description - Bluetooth Adapter scan mode
+ * Access mode - GET and SET
+ * Data type - bt_scan_mode_t.
+ */
+ BT_PROPERTY_ADAPTER_SCAN_MODE,
+ /**
+ * Description - List of bonded devices
+ * Access mode - Only GET.
+ * Data type - Array of bt_bdaddr_t of the bonded remote devices
+ * (Array size inferred from property length).
+ */
+ BT_PROPERTY_ADAPTER_BONDED_DEVICES,
+ /**
+ * Description - Bluetooth Adapter Discovery timeout (in seconds)
+ * Access mode - GET and SET
+ * Data type - uint32_t
+ */
+ BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
+
+ /* Properties unique to remote device */
+ /**
+ * Description - User defined friendly name of the remote device
+ * Access mode - GET and SET
+ * Data type - bt_bdname_t.
+ */
+ BT_PROPERTY_REMOTE_FRIENDLY_NAME,
+ /**
+ * Description - RSSI value of the inquired remote device
+ * Access mode - Only GET.
+ * Data type - int32_t.
+ */
+ BT_PROPERTY_REMOTE_RSSI,
+ /**
+ * Description - Remote version info
+ * Access mode - SET/GET.
+ * Data type - bt_remote_version_t.
+ */
+
+ BT_PROPERTY_REMOTE_VERSION_INFO,
+
+ /**
+ * Description - Local LE features
+ * Access mode - GET.
+ * Data type - bt_local_le_features_t.
+ */
+ BT_PROPERTY_LOCAL_LE_FEATURES,
+
+ BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
+} bt_property_type_t;
+
+/** Bluetooth Adapter Property data structure */
+typedef struct
+{
+ bt_property_type_t type;
+ int len;
+ void *val;
+} bt_property_t;
+
+/** Bluetooth Out Of Band data for bonding */
+typedef struct
+{
+ uint8_t le_bt_dev_addr[7]; /* LE Bluetooth Device Address */
+ uint8_t c192[16]; /* Simple Pairing Hash C-192 */
+ uint8_t r192[16]; /* Simple Pairing Randomizer R-192 */
+ uint8_t c256[16]; /* Simple Pairing Hash C-256 */
+ uint8_t r256[16]; /* Simple Pairing Randomizer R-256 */
+ uint8_t sm_tk[16]; /* Security Manager TK Value */
+ uint8_t le_sc_c[16]; /* LE Secure Connections Confirmation Value */
+ uint8_t le_sc_r[16]; /* LE Secure Connections Random Value */
+} bt_out_of_band_data_t;
+
+
+
+/** Bluetooth Device Type */
+typedef enum {
+ BT_DEVICE_DEVTYPE_BREDR = 0x1,
+ BT_DEVICE_DEVTYPE_BLE,
+ BT_DEVICE_DEVTYPE_DUAL
+} bt_device_type_t;
+/** Bluetooth Bond state */
+typedef enum {
+ BT_BOND_STATE_NONE,
+ BT_BOND_STATE_BONDING,
+ BT_BOND_STATE_BONDED
+} bt_bond_state_t;
+
+/** Bluetooth SSP Bonding Variant */
+typedef enum {
+ BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
+ BT_SSP_VARIANT_PASSKEY_ENTRY,
+ BT_SSP_VARIANT_CONSENT,
+ BT_SSP_VARIANT_PASSKEY_NOTIFICATION
+} bt_ssp_variant_t;
+
+#define BT_MAX_NUM_UUIDS 32
+
+/** Bluetooth Interface callbacks */
+
+/** Bluetooth Enable/Disable Callback. */
+typedef void (*adapter_state_changed_callback)(bt_state_t state);
+
+/** GET/SET Adapter Properties callback */
+/* TODO: For the GET/SET property APIs/callbacks, we may need a session
+ * identifier to associate the call with the callback. This would be needed
+ * whenever more than one simultaneous instance of the same adapter_type
+ * is get/set.
+ *
+ * If this is going to be handled in the Java framework, then we do not need
+ * to manage sessions here.
+ */
+typedef void (*adapter_properties_callback)(bt_status_t status,
+ int num_properties,
+ bt_property_t *properties);
+
+/** GET/SET Remote Device Properties callback */
+/** TODO: For remote device properties, do not see a need to get/set
+ * multiple properties - num_properties shall be 1
+ */
+typedef void (*remote_device_properties_callback)(bt_status_t status,
+ bt_bdaddr_t *bd_addr,
+ int num_properties,
+ bt_property_t *properties);
+
+/** New device discovered callback */
+/** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
+ * respectively */
+typedef void (*device_found_callback)(int num_properties,
+ bt_property_t *properties);
+
+/** Discovery state changed callback */
+typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
+
+/** Bluetooth Legacy PinKey Request callback */
+typedef void (*pin_request_callback)(bt_bdaddr_t *remote_bd_addr,
+ bt_bdname_t *bd_name, uint32_t cod, bool min_16_digit);
+
+/** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
+/** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
+ * BT_SSP_PAIRING_PASSKEY_ENTRY */
+/* TODO: Passkey request callback shall not be needed for devices with display
+ * capability. We still need support this in the stack for completeness */
+typedef void (*ssp_request_callback)(bt_bdaddr_t *remote_bd_addr,
+ bt_bdname_t *bd_name,
+ uint32_t cod,
+ bt_ssp_variant_t pairing_variant,
+ uint32_t pass_key);
+
+/** Bluetooth Bond state changed callback */
+/* Invoked in response to create_bond, cancel_bond or remove_bond */
+typedef void (*bond_state_changed_callback)(bt_status_t status,
+ bt_bdaddr_t *remote_bd_addr,
+ bt_bond_state_t state);
+
+/** Bluetooth ACL connection state changed callback */
+typedef void (*acl_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
+ bt_acl_state_t state);
+
+typedef enum {
+ ASSOCIATE_JVM,
+ DISASSOCIATE_JVM
+} bt_cb_thread_evt;
+
+/** Thread Associate/Disassociate JVM Callback */
+/* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from
+ * the JVM */
+typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
+
+/** Bluetooth Test Mode Callback */
+/* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */
+typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t len);
+
+/* LE Test mode callbacks
+* This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked
+* The num_packets is valid only for le_test_end command */
+typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
+
+/** Callback invoked when energy details are obtained */
+/* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as defined by HCI spec.
+ * If the ctrl_state value is 0, it means the API call failed
+ * Time values-In milliseconds as returned by the controller
+ * Energy used-Value as returned by the controller
+ * Status-Provides the status of the read_energy_info API call
+ * uid_data provides an array of bt_uid_traffic_t, where the array is terminated by an element with
+ * app_uid set to -1.
+ */
+typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info,
+ bt_uid_traffic_t *uid_data);
+
+/** TODO: Add callbacks for Link Up/Down and other generic
+ * notifications/callbacks */
+
+/** Bluetooth DM callback structure. */
+typedef struct {
+ /** set to sizeof(bt_callbacks_t) */
+ size_t size;
+ adapter_state_changed_callback adapter_state_changed_cb;
+ adapter_properties_callback adapter_properties_cb;
+ remote_device_properties_callback remote_device_properties_cb;
+ device_found_callback device_found_cb;
+ discovery_state_changed_callback discovery_state_changed_cb;
+ pin_request_callback pin_request_cb;
+ ssp_request_callback ssp_request_cb;
+ bond_state_changed_callback bond_state_changed_cb;
+ acl_state_changed_callback acl_state_changed_cb;
+ callback_thread_event thread_evt_cb;
+ dut_mode_recv_callback dut_mode_recv_cb;
+ le_test_mode_callback le_test_mode_cb;
+ energy_info_callback energy_info_cb;
+} bt_callbacks_t;
+
+typedef void (*alarm_cb)(void *data);
+typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
+typedef int (*acquire_wake_lock_callout)(const char *lock_name);
+typedef int (*release_wake_lock_callout)(const char *lock_name);
+
+/** The set of functions required by bluedroid to set wake alarms and
+ * grab wake locks. This struct is passed into the stack through the
+ * |set_os_callouts| function on |bt_interface_t|.
+ */
+typedef struct {
+ /* set to sizeof(bt_os_callouts_t) */
+ size_t size;
+
+ set_wake_alarm_callout set_wake_alarm;
+ acquire_wake_lock_callout acquire_wake_lock;
+ release_wake_lock_callout release_wake_lock;
+} bt_os_callouts_t;
+
+/** NOTE: By default, no profiles are initialized at the time of init/enable.
+ * Whenever the application invokes the 'init' API of a profile, then one of
+ * the following shall occur:
+ *
+ * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
+ * profile as enabled. Subsequently, when the application invokes the
+ * Bluetooth 'enable', as part of the enable sequence the profile that were
+ * marked shall be enabled by calling appropriate stack APIs. The
+ * 'adapter_properties_cb' shall return the list of UUIDs of the
+ * enabled profiles.
+ *
+ * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
+ * profile API to initialize the profile and trigger a
+ * 'adapter_properties_cb' with the current list of UUIDs including the
+ * newly added profile's UUID.
+ *
+ * The reverse shall occur whenever the profile 'cleanup' APIs are invoked
+ */
+
+/** Represents the standard Bluetooth DM interface. */
+typedef struct {
+ /** set to sizeof(bt_interface_t) */
+ size_t size;
+ /**
+ * Opens the interface and provides the callback routines
+ * to the implemenation of this interface.
+ */
+ int (*init)(bt_callbacks_t* callbacks );
+
+ /** Enable Bluetooth. */
+ int (*enable)(bool guest_mode);
+
+ /** Disable Bluetooth. */
+ int (*disable)(void);
+
+ /** Closes the interface. */
+ void (*cleanup)(void);
+
+ /** Get all Bluetooth Adapter properties at init */
+ int (*get_adapter_properties)(void);
+
+ /** Get Bluetooth Adapter property of 'type' */
+ int (*get_adapter_property)(bt_property_type_t type);
+
+ /** Set Bluetooth Adapter property of 'type' */
+ /* Based on the type, val shall be one of
+ * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
+ */
+ int (*set_adapter_property)(const bt_property_t *property);
+
+ /** Get all Remote Device properties */
+ int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
+
+ /** Get Remote Device property of 'type' */
+ int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
+ bt_property_type_t type);
+
+ /** Set Remote Device property of 'type' */
+ int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
+ const bt_property_t *property);
+
+ /** Get Remote Device's service record for the given UUID */
+ int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
+ bt_uuid_t *uuid);
+
+ /** Start SDP to get remote services */
+ int (*get_remote_services)(bt_bdaddr_t *remote_addr);
+
+ /** Start Discovery */
+ int (*start_discovery)(void);
+
+ /** Cancel Discovery */
+ int (*cancel_discovery)(void);
+
+ /** Create Bluetooth Bonding */
+ int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
+
+ /** Create Bluetooth Bond using out of band data */
+ int (*create_bond_out_of_band)(const bt_bdaddr_t *bd_addr, int transport,
+ const bt_out_of_band_data_t *oob_data);
+
+ /** Remove Bond */
+ int (*remove_bond)(const bt_bdaddr_t *bd_addr);
+
+ /** Cancel Bond */
+ int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
+
+ /**
+ * Get the connection status for a given remote device.
+ * return value of 0 means the device is not connected,
+ * non-zero return status indicates an active connection.
+ */
+ int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
+
+ /** BT Legacy PinKey Reply */
+ /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
+ int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
+ uint8_t pin_len, bt_pin_code_t *pin_code);
+
+ /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
+ * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
+ * BT_SSP_VARIANT_CONSENT
+ * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
+ * shall be zero */
+ int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
+ uint8_t accept, uint32_t passkey);
+
+ /** Get Bluetooth profile interface */
+ const void* (*get_profile_interface) (const char *profile_id);
+
+ /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
+ /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
+ int (*dut_mode_configure)(uint8_t enable);
+
+ /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
+ int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
+ /** BLE Test Mode APIs */
+ /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
+ int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
+
+ /* enable or disable bluetooth HCI snoop log */
+ int (*config_hci_snoop_log)(uint8_t enable);
+
+ /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
+ * This should be called immediately after a successful |init|.
+ */
+ int (*set_os_callouts)(bt_os_callouts_t *callouts);
+
+ /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY
+ * Success indicates that the VSC command was sent to controller
+ */
+ int (*read_energy_info)();
+
+ /**
+ * Native support for dumpsys function
+ * Function is synchronous and |fd| is owned by caller.
+ * |arguments| are arguments which may affect the output, encoded as
+ * UTF-8 strings.
+ */
+ void (*dump)(int fd, const char **arguments);
+
+ /**
+ * Clear /data/misc/bt_config.conf and erase all stored connections
+ */
+ int (*config_clear)(void);
+
+ /**
+ * Clear (reset) the dynamic portion of the device interoperability database.
+ */
+ void (*interop_database_clear)(void);
+
+ /**
+ * Add a new device interoperability workaround for a remote device whose
+ * first |len| bytes of the its device address match |addr|.
+ * NOTE: |feature| has to match an item defined in interop_feature_t (interop.h).
+ */
+ void (*interop_database_add)(uint16_t feature, const bt_bdaddr_t *addr, size_t len);
+} bt_interface_t;
+
+/** TODO: Need to add APIs for Service Discovery, Service authorization and
+ * connection management. Also need to add APIs for configuring
+ * properties of remote bonded devices such as name, UUID etc. */
+
+typedef struct {
+ struct hw_device_t common;
+ const bt_interface_t* (*get_bluetooth_interface)();
+} bluetooth_device_t;
+
+typedef bluetooth_device_t bluetooth_module_t;
+
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BLUETOOTH_H */
diff --git a/libhardware/include/hardware/boot_control.h b/libhardware/include/hardware/boot_control.h
new file mode 100644
index 0000000..36a867d
--- /dev/null
+++ b/libhardware/include/hardware/boot_control.h
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_HARDWARE_BOOT_CONTROL_H
+#define ANDROID_INCLUDE_HARDWARE_BOOT_CONTROL_H
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define BOOT_CONTROL_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+
+/**
+ * The id of this module
+ */
+#define BOOT_CONTROL_HARDWARE_MODULE_ID "bootctrl"
+
+/*
+ * The Boot Control HAL is designed to allow for managing sets of redundant
+ * partitions, called slots, that can be booted from independantly. Slots
+ * are sets of partitions whose names differ only by a given suffix.
+ * They are identified here by a 0 indexed number, and associated with their
+ * suffix, which can be appended to the base name for any particular partition
+ * to find the one associated with that slot. The bootloader must pass the suffix
+ * of the currently active slot either through a kernel command line property at
+ * androidboot.slot_suffix, or the device tree at /firmware/android/slot_suffix.
+ * The primary use of this set up is to allow for background updates while the
+ * device is running, and to provide a fallback in the event that the update fails.
+ */
+
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+typedef struct boot_control_module {
+ struct hw_module_t common;
+
+ /*
+ * (*init)() perform any initialization tasks needed for the HAL.
+ * This is called only once.
+ */
+ void (*init)(struct boot_control_module *module);
+
+ /*
+ * (*getNumberSlots)() returns the number of available slots.
+ * For instance, a system with a single set of partitions would return
+ * 1, a system with A/B would return 2, A/B/C -> 3...
+ */
+ unsigned (*getNumberSlots)(struct boot_control_module *module);
+
+ /*
+ * (*getCurrentSlot)() returns the value letting the system know
+ * whether the current slot is A or B. The meaning of A and B is
+ * left up to the implementer. It is assumed that if the current slot
+ * is A, then the block devices underlying B can be accessed directly
+ * without any risk of corruption.
+ * The returned value is always guaranteed to be strictly less than the
+ * value returned by getNumberSlots. Slots start at 0 and
+ * finish at getNumberSlots() - 1
+ */
+ unsigned (*getCurrentSlot)(struct boot_control_module *module);
+
+ /*
+ * (*markBootSuccessful)() marks the current slot
+ * as having booted successfully
+ *
+ * Returns 0 on success, -errno on error.
+ */
+ int (*markBootSuccessful)(struct boot_control_module *module);
+
+ /*
+ * (*setActiveBootSlot)() marks the slot passed in parameter as
+ * the active boot slot (see getCurrentSlot for an explanation
+ * of the "slot" parameter). This overrides any previous call to
+ * setSlotAsUnbootable.
+ * Returns 0 on success, -errno on error.
+ */
+ int (*setActiveBootSlot)(struct boot_control_module *module, unsigned slot);
+
+ /*
+ * (*setSlotAsUnbootable)() marks the slot passed in parameter as
+ * an unbootable. This can be used while updating the contents of the slot's
+ * partitions, so that the system will not attempt to boot a known bad set up.
+ * Returns 0 on success, -errno on error.
+ */
+ int (*setSlotAsUnbootable)(struct boot_control_module *module, unsigned slot);
+
+ /*
+ * (*isSlotBootable)() returns if the slot passed in parameter is
+ * bootable. Note that slots can be made unbootable by both the
+ * bootloader and by the OS using setSlotAsUnbootable.
+ * Returns 1 if the slot is bootable, 0 if it's not, and -errno on
+ * error.
+ */
+ int (*isSlotBootable)(struct boot_control_module *module, unsigned slot);
+
+ /*
+ * (*getSuffix)() returns the string suffix used by partitions that
+ * correspond to the slot number passed in parameter. The returned string
+ * is expected to be statically allocated and not need to be freed.
+ * Returns NULL if slot does not match an existing slot.
+ */
+ const char* (*getSuffix)(struct boot_control_module *module, unsigned slot);
+
+ /*
+ * (*isSlotMarkedSucessful)() returns if the slot passed in parameter has
+ * been marked as successful using markBootSuccessful.
+ * Returns 1 if the slot has been marked as successful, 0 if it's
+ * not the case, and -errno on error.
+ */
+ int (*isSlotMarkedSuccessful)(struct boot_control_module *module, unsigned slot);
+
+ void* reserved[31];
+} boot_control_module_t;
+
+
+__END_DECLS
+
+#endif // ANDROID_INCLUDE_HARDWARE_BOOT_CONTROL_H
diff --git a/libhardware/include/hardware/bt_av.h b/libhardware/include/hardware/bt_av.h
new file mode 100644
index 0000000..9b32216
--- /dev/null
+++ b/libhardware/include/hardware/bt_av.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_AV_H
+#define ANDROID_INCLUDE_BT_AV_H
+
+__BEGIN_DECLS
+
+/* Bluetooth AV connection states */
+typedef enum {
+ BTAV_CONNECTION_STATE_DISCONNECTED = 0,
+ BTAV_CONNECTION_STATE_CONNECTING,
+ BTAV_CONNECTION_STATE_CONNECTED,
+ BTAV_CONNECTION_STATE_DISCONNECTING
+} btav_connection_state_t;
+
+/* Bluetooth AV datapath states */
+typedef enum {
+ BTAV_AUDIO_STATE_REMOTE_SUSPEND = 0,
+ BTAV_AUDIO_STATE_STOPPED,
+ BTAV_AUDIO_STATE_STARTED,
+} btav_audio_state_t;
+
+
+/** Callback for connection state change.
+ * state will have one of the values from btav_connection_state_t
+ */
+typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
+ bt_bdaddr_t *bd_addr);
+
+/** Callback for audiopath state change.
+ * state will have one of the values from btav_audio_state_t
+ */
+typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
+ bt_bdaddr_t *bd_addr);
+
+/** Callback for audio configuration change.
+ * Used only for the A2DP sink interface.
+ * state will have one of the values from btav_audio_state_t
+ * sample_rate: sample rate in Hz
+ * channel_count: number of channels (1 for mono, 2 for stereo)
+ */
+typedef void (* btav_audio_config_callback)(bt_bdaddr_t *bd_addr,
+ uint32_t sample_rate,
+ uint8_t channel_count);
+
+/** BT-AV callback structure. */
+typedef struct {
+ /** set to sizeof(btav_callbacks_t) */
+ size_t size;
+ btav_connection_state_callback connection_state_cb;
+ btav_audio_state_callback audio_state_cb;
+ btav_audio_config_callback audio_config_cb;
+} btav_callbacks_t;
+
+/**
+ * NOTE:
+ *
+ * 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands
+ * shall be handled internally via uinput
+ *
+ * 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger
+ * android_audio_hw library and the Bluetooth stack.
+ *
+ */
+/** Represents the standard BT-AV interface.
+ * Used for both the A2DP source and sink interfaces.
+ */
+typedef struct {
+
+ /** set to sizeof(btav_interface_t) */
+ size_t size;
+ /**
+ * Register the BtAv callbacks
+ */
+ bt_status_t (*init)( btav_callbacks_t* callbacks );
+
+ /** connect to headset */
+ bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
+
+ /** dis-connect from headset */
+ bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
+
+ /** Closes the interface. */
+ void (*cleanup)( void );
+
+ /** Sends Audio Focus State. */
+ void (*set_audio_focus_state)( int focus_state );
+
+ /** Sets the audio track gain. */
+ void (*set_audio_track_gain)( float gain );
+} btav_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_AV_H */
diff --git a/libhardware/include/hardware/bt_common_types.h b/libhardware/include/hardware/bt_common_types.h
new file mode 100644
index 0000000..1e6be6b
--- /dev/null
+++ b/libhardware/include/hardware/bt_common_types.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/******************************************************************************
+ *
+ * This file contains constants and definitions that can be used commonly between JNI and stack layer
+ *
+ ******************************************************************************/
+#ifndef ANDROID_INCLUDE_BT_COMMON_TYPES_H
+#define ANDROID_INCLUDE_BT_COMMON_TYPES_H
+
+#include "bluetooth.h"
+
+typedef struct
+{
+ uint8_t client_if;
+ uint8_t filt_index;
+ uint8_t advertiser_state;
+ uint8_t advertiser_info_present;
+ uint8_t addr_type;
+ uint8_t tx_power;
+ int8_t rssi_value;
+ uint16_t time_stamp;
+ bt_bdaddr_t bd_addr;
+ uint8_t adv_pkt_len;
+ uint8_t *p_adv_pkt_data;
+ uint8_t scan_rsp_len;
+ uint8_t *p_scan_rsp_data;
+} btgatt_track_adv_info_t;
+
+typedef enum
+{
+ BTGATT_DB_PRIMARY_SERVICE,
+ BTGATT_DB_SECONDARY_SERVICE,
+ BTGATT_DB_INCLUDED_SERVICE,
+ BTGATT_DB_CHARACTERISTIC,
+ BTGATT_DB_DESCRIPTOR,
+} bt_gatt_db_attribute_type_t;
+
+typedef struct
+{
+ uint16_t id;
+ bt_uuid_t uuid;
+ bt_gatt_db_attribute_type_t type;
+ uint16_t attribute_handle;
+
+ /*
+ * If |type| is |BTGATT_DB_PRIMARY_SERVICE|, or
+ * |BTGATT_DB_SECONDARY_SERVICE|, this contains the start and end attribute
+ * handles.
+ */
+ uint16_t start_handle;
+ uint16_t end_handle;
+
+ /*
+ * If |type| is |BTGATT_DB_CHARACTERISTIC|, this contains the properties of
+ * the characteristic.
+ */
+ uint8_t properties;
+ uint16_t permissions;
+} btgatt_db_element_t;
+
+#endif /* ANDROID_INCLUDE_BT_COMMON_TYPES_H */
diff --git a/libhardware/include/hardware/bt_gatt.h b/libhardware/include/hardware/bt_gatt.h
new file mode 100644
index 0000000..414d3e4
--- /dev/null
+++ b/libhardware/include/hardware/bt_gatt.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_INCLUDE_BT_GATT_H
+#define ANDROID_INCLUDE_BT_GATT_H
+
+#include <stdint.h>
+#include "ble_advertiser.h"
+#include "ble_scanner.h"
+#include "bt_gatt_client.h"
+#include "bt_gatt_server.h"
+
+__BEGIN_DECLS
+
+/** BT-GATT callbacks */
+typedef struct {
+ /** Set to sizeof(btgatt_callbacks_t) */
+ size_t size;
+
+ /** GATT Client callbacks */
+ const btgatt_client_callbacks_t* client;
+
+ /** GATT Server callbacks */
+ const btgatt_server_callbacks_t* server;
+
+ /** LE scanner callbacks */
+ const btgatt_scanner_callbacks_t* scanner;
+} btgatt_callbacks_t;
+
+/** Represents the standard Bluetooth GATT interface. */
+typedef struct {
+ /** Set to sizeof(btgatt_interface_t) */
+ size_t size;
+
+ /**
+ * Initializes the interface and provides callback routines
+ */
+ bt_status_t (*init)( const btgatt_callbacks_t* callbacks );
+
+ /** Closes the interface */
+ void (*cleanup)( void );
+
+ /** Pointer to the GATT client interface methods.*/
+ const btgatt_client_interface_t* client;
+
+ /** Pointer to the GATT server interface methods.*/
+ const btgatt_server_interface_t* server;
+
+ /** Pointer to the LE scanner interface methods.*/
+ const btgatt_scanner_interface_t* scanner;
+
+ /** Pointer to the advertiser interface methods.*/
+ BleAdvertiserInterface* advertiser;
+} btgatt_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_GATT_H */
diff --git a/libhardware/include/hardware/bt_gatt_client.h b/libhardware/include/hardware/bt_gatt_client.h
new file mode 100644
index 0000000..6c5a85e
--- /dev/null
+++ b/libhardware/include/hardware/bt_gatt_client.h
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_INCLUDE_BT_GATT_CLIENT_H
+#define ANDROID_INCLUDE_BT_GATT_CLIENT_H
+
+#include <stdint.h>
+#include <vector>
+#include "bt_gatt_types.h"
+#include "bt_common_types.h"
+
+using std::vector;
+
+__BEGIN_DECLS
+
+/**
+ * Buffer sizes for maximum attribute length and maximum read/write
+ * operation buffer size.
+ */
+#define BTGATT_MAX_ATTR_LEN 600
+
+/** Buffer type for unformatted reads/writes */
+typedef struct
+{
+ uint8_t value[BTGATT_MAX_ATTR_LEN];
+ uint16_t len;
+} btgatt_unformatted_value_t;
+
+/** Parameters for GATT read operations */
+typedef struct
+{
+ uint16_t handle;
+ btgatt_unformatted_value_t value;
+ uint16_t value_type;
+ uint8_t status;
+} btgatt_read_params_t;
+
+/** Parameters for GATT write operations */
+typedef struct
+{
+ btgatt_srvc_id_t srvc_id;
+ btgatt_gatt_id_t char_id;
+ btgatt_gatt_id_t descr_id;
+ uint8_t status;
+} btgatt_write_params_t;
+
+/** Attribute change notification parameters */
+typedef struct
+{
+ uint8_t value[BTGATT_MAX_ATTR_LEN];
+ bt_bdaddr_t bda;
+ uint16_t handle;
+ uint16_t len;
+ uint8_t is_notify;
+} btgatt_notify_params_t;
+
+typedef struct
+{
+ uint8_t client_if;
+ uint8_t action;
+ uint8_t filt_index;
+ uint16_t feat_seln;
+ uint16_t list_logic_type;
+ uint8_t filt_logic_type;
+ uint8_t rssi_high_thres;
+ uint8_t rssi_low_thres;
+ uint8_t dely_mode;
+ uint16_t found_timeout;
+ uint16_t lost_timeout;
+ uint8_t found_timeout_cnt;
+ uint16_t num_of_tracking_entries;
+} btgatt_filt_param_setup_t;
+
+typedef struct
+{
+ bt_bdaddr_t *bda1;
+ bt_uuid_t *uuid1;
+ uint16_t u1;
+ uint16_t u2;
+ uint16_t u3;
+ uint16_t u4;
+ uint16_t u5;
+} btgatt_test_params_t;
+
+/* BT GATT client error codes */
+typedef enum
+{
+ BT_GATTC_COMMAND_SUCCESS = 0, /* 0 Command succeeded */
+ BT_GATTC_COMMAND_STARTED, /* 1 Command started OK. */
+ BT_GATTC_COMMAND_BUSY, /* 2 Device busy with another command */
+ BT_GATTC_COMMAND_STORED, /* 3 request is stored in control block */
+ BT_GATTC_NO_RESOURCES, /* 4 No resources to issue command */
+ BT_GATTC_MODE_UNSUPPORTED, /* 5 Request for 1 or more unsupported modes */
+ BT_GATTC_ILLEGAL_VALUE, /* 6 Illegal command /parameter value */
+ BT_GATTC_INCORRECT_STATE, /* 7 Device in wrong state for request */
+ BT_GATTC_UNKNOWN_ADDR, /* 8 Unknown remote BD address */
+ BT_GATTC_DEVICE_TIMEOUT, /* 9 Device timeout */
+ BT_GATTC_INVALID_CONTROLLER_OUTPUT,/* 10 An incorrect value was received from HCI */
+ BT_GATTC_SECURITY_ERROR, /* 11 Authorization or security failure or not authorized */
+ BT_GATTC_DELAYED_ENCRYPTION_CHECK, /*12 Delayed encryption check */
+ BT_GATTC_ERR_PROCESSING /* 12 Generic error */
+} btgattc_error_t;
+
+/** BT-GATT Client callback structure. */
+
+/** Callback invoked in response to register_client */
+typedef void (*register_client_callback)(int status, int client_if,
+ bt_uuid_t *app_uuid);
+
+/** GATT open callback invoked in response to open */
+typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
+
+/** Callback invoked in response to close */
+typedef void (*disconnect_callback)(int conn_id, int status,
+ int client_if, bt_bdaddr_t* bda);
+
+/**
+ * Invoked in response to search_service when the GATT service search
+ * has been completed.
+ */
+typedef void (*search_complete_callback)(int conn_id, int status);
+
+/** Callback invoked in response to [de]register_for_notification */
+typedef void (*register_for_notification_callback)(int conn_id,
+ int registered, int status, uint16_t handle);
+
+/**
+ * Remote device notification callback, invoked when a remote device sends
+ * a notification or indication that a client has registered for.
+ */
+typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
+
+/** Reports result of a GATT read operation */
+typedef void (*read_characteristic_callback)(int conn_id, int status,
+ btgatt_read_params_t *p_data);
+
+/** GATT write characteristic operation callback */
+typedef void (*write_characteristic_callback)(int conn_id, int status, uint16_t handle);
+
+/** GATT execute prepared write callback */
+typedef void (*execute_write_callback)(int conn_id, int status);
+
+/** Callback invoked in response to read_descriptor */
+typedef void (*read_descriptor_callback)(int conn_id, int status,
+ btgatt_read_params_t *p_data);
+
+/** Callback invoked in response to write_descriptor */
+typedef void (*write_descriptor_callback)(int conn_id, int status, uint16_t handle);
+
+/** Callback triggered in response to read_remote_rssi */
+typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
+ int rssi, int status);
+
+/** Callback invoked when the MTU for a given connection changes */
+typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
+
+
+/**
+ * Callback notifying an application that a remote device connection is currently congested
+ * and cannot receive any more data. An application should avoid sending more data until
+ * a further callback is received indicating the congestion status has been cleared.
+ */
+typedef void (*congestion_callback)(int conn_id, bool congested);
+
+/** GATT get database callback */
+typedef void (*get_gatt_db_callback)(int conn_id, btgatt_db_element_t *db, int count);
+
+/** GATT services between start_handle and end_handle were removed */
+typedef void (*services_removed_callback)(int conn_id, uint16_t start_handle, uint16_t end_handle);
+
+/** GATT services were added */
+typedef void (*services_added_callback)(int conn_id, btgatt_db_element_t *added, int added_count);
+
+typedef struct {
+ register_client_callback register_client_cb;
+ connect_callback open_cb;
+ disconnect_callback close_cb;
+ search_complete_callback search_complete_cb;
+ register_for_notification_callback register_for_notification_cb;
+ notify_callback notify_cb;
+ read_characteristic_callback read_characteristic_cb;
+ write_characteristic_callback write_characteristic_cb;
+ read_descriptor_callback read_descriptor_cb;
+ write_descriptor_callback write_descriptor_cb;
+ execute_write_callback execute_write_cb;
+ read_remote_rssi_callback read_remote_rssi_cb;
+ configure_mtu_callback configure_mtu_cb;
+ congestion_callback congestion_cb;
+ get_gatt_db_callback get_gatt_db_cb;
+ services_removed_callback services_removed_cb;
+ services_added_callback services_added_cb;
+} btgatt_client_callbacks_t;
+
+/** Represents the standard BT-GATT client interface. */
+
+typedef struct {
+ /** Registers a GATT client application with the stack */
+ bt_status_t (*register_client)( bt_uuid_t *uuid );
+
+ /** Unregister a client application from the stack */
+ bt_status_t (*unregister_client)(int client_if );
+
+ /** Create a connection to a remote LE or dual-mode device */
+ bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,
+ bool is_direct, int transport );
+
+ /** Disconnect a remote device or cancel a pending connection */
+ bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
+ int conn_id);
+
+ /** Clear the attribute cache for a given device */
+ bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
+
+ /**
+ * Enumerate all GATT services on a connected device.
+ * Optionally, the results can be filtered for a given UUID.
+ */
+ bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );
+
+ /** Read a characteristic on a remote device */
+ bt_status_t (*read_characteristic)( int conn_id, uint16_t handle,
+ int auth_req );
+
+ /** Write a remote characteristic */
+ bt_status_t (*write_characteristic)(int conn_id, uint16_t handle,
+ int write_type, int auth_req,
+ vector<uint8_t> value);
+
+ /** Read the descriptor for a given characteristic */
+ bt_status_t (*read_descriptor)(int conn_id, uint16_t handle, int auth_req);
+
+ /** Write a remote descriptor for a given characteristic */
+ bt_status_t (*write_descriptor)( int conn_id, uint16_t handle,
+ int auth_req, vector<uint8_t> value);
+
+ /** Execute a prepared write operation */
+ bt_status_t (*execute_write)(int conn_id, int execute);
+
+ /**
+ * Register to receive notifications or indications for a given
+ * characteristic
+ */
+ bt_status_t (*register_for_notification)( int client_if,
+ const bt_bdaddr_t *bd_addr, uint16_t handle);
+
+ /** Deregister a previous request for notifications/indications */
+ bt_status_t (*deregister_for_notification)( int client_if,
+ const bt_bdaddr_t *bd_addr, uint16_t handle);
+
+ /** Request RSSI for a given remote device */
+ bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
+
+ /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
+ int (*get_device_type)( const bt_bdaddr_t *bd_addr );
+
+ /** Configure the MTU for a given connection */
+ bt_status_t (*configure_mtu)(int conn_id, int mtu);
+
+ /** Request a connection parameter update */
+ bt_status_t (*conn_parameter_update)(const bt_bdaddr_t *bd_addr, int min_interval,
+ int max_interval, int latency, int timeout);
+
+ /** Test mode interface */
+ bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
+
+ /** Get gatt db content */
+ bt_status_t (*get_gatt_db)( int conn_id);
+
+} btgatt_client_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */
diff --git a/libhardware/include/hardware/bt_gatt_server.h b/libhardware/include/hardware/bt_gatt_server.h
new file mode 100644
index 0000000..92af285
--- /dev/null
+++ b/libhardware/include/hardware/bt_gatt_server.h
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_INCLUDE_BT_GATT_SERVER_H
+#define ANDROID_INCLUDE_BT_GATT_SERVER_H
+
+#include <stdint.h>
+#include <vector>
+
+#include "bt_gatt_types.h"
+
+using std::vector;
+
+__BEGIN_DECLS
+
+/** GATT value type used in response to remote read requests */
+typedef struct
+{
+ uint8_t value[BTGATT_MAX_ATTR_LEN];
+ uint16_t handle;
+ uint16_t offset;
+ uint16_t len;
+ uint8_t auth_req;
+} btgatt_value_t;
+
+/** GATT remote read request response type */
+typedef union
+{
+ btgatt_value_t attr_value;
+ uint16_t handle;
+} btgatt_response_t;
+
+/** BT-GATT Server callback structure. */
+
+/** Callback invoked in response to register_server */
+typedef void (*register_server_callback)(int status, int server_if,
+ bt_uuid_t *app_uuid);
+
+/** Callback indicating that a remote device has connected or been disconnected */
+typedef void (*connection_callback)(int conn_id, int server_if, int connected,
+ bt_bdaddr_t *bda);
+
+/** Callback invoked in response to create_service */
+typedef void (*service_added_callback)(int status, int server_if,
+ vector<btgatt_db_element_t> service);
+
+/** Callback invoked in response to stop_service */
+typedef void (*service_stopped_callback)(int status, int server_if,
+ int srvc_handle);
+
+/** Callback triggered when a service has been deleted */
+typedef void (*service_deleted_callback)(int status, int server_if,
+ int srvc_handle);
+
+/**
+ * Callback invoked when a remote device has requested to read a characteristic
+ * or descriptor. The application must respond by calling send_response
+ */
+typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
+ int attr_handle, int offset, bool is_long);
+
+/**
+ * Callback invoked when a remote device has requested to write to a
+ * characteristic or descriptor.
+ */
+typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
+ int attr_handle, int offset, bool need_rsp,
+ bool is_prep, vector<uint8_t> value);
+
+/** Callback invoked when a previously prepared write is to be executed */
+typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
+ bt_bdaddr_t *bda, int exec_write);
+
+/**
+ * Callback triggered in response to send_response if the remote device
+ * sends a confirmation.
+ */
+typedef void (*response_confirmation_callback)(int status, int handle);
+
+/**
+ * Callback confirming that a notification or indication has been sent
+ * to a remote device.
+ */
+typedef void (*indication_sent_callback)(int conn_id, int status);
+
+/**
+ * Callback notifying an application that a remote device connection is currently congested
+ * and cannot receive any more data. An application should avoid sending more data until
+ * a further callback is received indicating the congestion status has been cleared.
+ */
+typedef void (*congestion_callback)(int conn_id, bool congested);
+
+/** Callback invoked when the MTU for a given connection changes */
+typedef void (*mtu_changed_callback)(int conn_id, int mtu);
+
+typedef struct {
+ register_server_callback register_server_cb;
+ connection_callback connection_cb;
+ service_added_callback service_added_cb;
+ service_stopped_callback service_stopped_cb;
+ service_deleted_callback service_deleted_cb;
+ request_read_callback request_read_characteristic_cb;
+ request_read_callback request_read_descriptor_cb;
+ request_write_callback request_write_characteristic_cb;
+ request_write_callback request_write_descriptor_cb;
+ request_exec_write_callback request_exec_write_cb;
+ response_confirmation_callback response_confirmation_cb;
+ indication_sent_callback indication_sent_cb;
+ congestion_callback congestion_cb;
+ mtu_changed_callback mtu_changed_cb;
+} btgatt_server_callbacks_t;
+
+/** Represents the standard BT-GATT server interface. */
+typedef struct {
+ /** Registers a GATT server application with the stack */
+ bt_status_t (*register_server)( bt_uuid_t *uuid );
+
+ /** Unregister a server application from the stack */
+ bt_status_t (*unregister_server)(int server_if );
+
+ /** Create a connection to a remote peripheral */
+ bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
+ bool is_direct, int transport);
+
+ /** Disconnect an established connection or cancel a pending one */
+ bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,
+ int conn_id );
+
+ /** Create a new service */
+ bt_status_t (*add_service)(int server_if, vector<btgatt_db_element_t> service);
+
+ /** Stops a local service */
+ bt_status_t (*stop_service)(int server_if, int service_handle);
+
+ /** Delete a local service */
+ bt_status_t (*delete_service)(int server_if, int service_handle);
+
+ /** Send value indication to a remote device */
+ bt_status_t (*send_indication)(int server_if, int attribute_handle,
+ int conn_id, int confirm,
+ vector<uint8_t> value);
+
+ /** Send a response to a read/write operation */
+ bt_status_t (*send_response)(int conn_id, int trans_id,
+ int status, btgatt_response_t *response);
+
+} btgatt_server_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */
diff --git a/libhardware/include/hardware/bt_gatt_types.h b/libhardware/include/hardware/bt_gatt_types.h
new file mode 100644
index 0000000..e037ddc
--- /dev/null
+++ b/libhardware/include/hardware/bt_gatt_types.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_INCLUDE_BT_GATT_TYPES_H
+#define ANDROID_INCLUDE_BT_GATT_TYPES_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+__BEGIN_DECLS
+
+/**
+ * GATT Service types
+ */
+#define BTGATT_SERVICE_TYPE_PRIMARY 0
+#define BTGATT_SERVICE_TYPE_SECONDARY 1
+
+/** GATT ID adding instance id tracking to the UUID */
+typedef struct
+{
+ bt_uuid_t uuid;
+ uint8_t inst_id;
+} btgatt_gatt_id_t;
+
+/** GATT Service ID also identifies the service type (primary/secondary) */
+typedef struct
+{
+ btgatt_gatt_id_t id;
+ uint8_t is_primary;
+} btgatt_srvc_id_t;
+
+/** Preferred physical Transport for GATT connection */
+typedef enum
+{
+ GATT_TRANSPORT_AUTO,
+ GATT_TRANSPORT_BREDR,
+ GATT_TRANSPORT_LE
+} btgatt_transport_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_GATT_TYPES_H */
diff --git a/libhardware/include/hardware/bt_hf.h b/libhardware/include/hardware/bt_hf.h
new file mode 100644
index 0000000..0a77675
--- /dev/null
+++ b/libhardware/include/hardware/bt_hf.h
@@ -0,0 +1,330 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_HF_H
+#define ANDROID_INCLUDE_BT_HF_H
+
+__BEGIN_DECLS
+
+/* AT response code - OK/Error */
+typedef enum {
+ BTHF_AT_RESPONSE_ERROR = 0,
+ BTHF_AT_RESPONSE_OK
+} bthf_at_response_t;
+
+typedef enum {
+ BTHF_CONNECTION_STATE_DISCONNECTED = 0,
+ BTHF_CONNECTION_STATE_CONNECTING,
+ BTHF_CONNECTION_STATE_CONNECTED,
+ BTHF_CONNECTION_STATE_SLC_CONNECTED,
+ BTHF_CONNECTION_STATE_DISCONNECTING
+} bthf_connection_state_t;
+
+typedef enum {
+ BTHF_AUDIO_STATE_DISCONNECTED = 0,
+ BTHF_AUDIO_STATE_CONNECTING,
+ BTHF_AUDIO_STATE_CONNECTED,
+ BTHF_AUDIO_STATE_DISCONNECTING
+} bthf_audio_state_t;
+
+typedef enum {
+ BTHF_VR_STATE_STOPPED = 0,
+ BTHF_VR_STATE_STARTED
+} bthf_vr_state_t;
+
+typedef enum {
+ BTHF_VOLUME_TYPE_SPK = 0,
+ BTHF_VOLUME_TYPE_MIC
+} bthf_volume_type_t;
+
+/* Noise Reduction and Echo Cancellation */
+typedef enum
+{
+ BTHF_NREC_STOP,
+ BTHF_NREC_START
+} bthf_nrec_t;
+
+/* WBS codec setting */
+typedef enum
+{
+ BTHF_WBS_NONE,
+ BTHF_WBS_NO,
+ BTHF_WBS_YES
+}bthf_wbs_config_t;
+
+/* CHLD - Call held handling */
+typedef enum
+{
+ BTHF_CHLD_TYPE_RELEASEHELD, // Terminate all held or set UDUB("busy") to a waiting call
+ BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD, // Terminate all active calls and accepts a waiting/held call
+ BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD, // Hold all active calls and accepts a waiting/held call
+ BTHF_CHLD_TYPE_ADDHELDTOCONF, // Add all held calls to a conference
+} bthf_chld_type_t;
+
+
+/* HF Indicators HFP 1.7 */
+typedef enum
+{
+ BTHF_HF_IND_ENHANCED_DRIVER_SAFETY = 1,
+ BTHF_HF_IND_BATTERY_LEVEL_STATUS = 2,
+} bthf_hf_ind_type_t;
+
+typedef enum
+{
+ BTHF_HF_IND_DISABLED = 0,
+ BTHF_HF_IND_ENABLED,
+} bthf_hf_ind_status_t;
+
+/** Callback for connection state change.
+ * state will have one of the values from BtHfConnectionState
+ */
+typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr);
+
+/** Callback for audio connection state change.
+ * state will have one of the values from BtHfAudioState
+ */
+typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr);
+
+/** Callback for VR connection state change.
+ * state will have one of the values from BtHfVRState
+ */
+typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state, bt_bdaddr_t *bd_addr);
+
+/** Callback for answer incoming call (ATA)
+ */
+typedef void (* bthf_answer_call_cmd_callback)(bt_bdaddr_t *bd_addr);
+
+/** Callback for disconnect call (AT+CHUP)
+ */
+typedef void (* bthf_hangup_call_cmd_callback)(bt_bdaddr_t *bd_addr);
+
+/** Callback for disconnect call (AT+CHUP)
+ * type will denote Speaker/Mic gain (BtHfVolumeControl).
+ */
+typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr);
+
+/** Callback for dialing an outgoing call
+ * If number is NULL, redial
+ */
+typedef void (* bthf_dial_call_cmd_callback)(char *number, bt_bdaddr_t *bd_addr);
+
+/** Callback for sending DTMF tones
+ * tone contains the dtmf character to be sent
+ */
+typedef void (* bthf_dtmf_cmd_callback)(char tone, bt_bdaddr_t *bd_addr);
+
+/** Callback for enabling/disabling noise reduction/echo cancellation
+ * value will be 1 to enable, 0 to disable
+ */
+typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr);
+
+/** Callback for AT+BCS and event from BAC
+ * WBS enable, WBS disable
+ */
+typedef void (* bthf_wbs_callback)(bthf_wbs_config_t wbs, bt_bdaddr_t *bd_addr);
+
+/** Callback for call hold handling (AT+CHLD)
+ * value will contain the call hold command (0, 1, 2, 3)
+ */
+typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr);
+
+/** Callback for CNUM (subscriber number)
+ */
+typedef void (* bthf_cnum_cmd_callback)(bt_bdaddr_t *bd_addr);
+
+/** Callback for indicators (CIND)
+ */
+typedef void (* bthf_cind_cmd_callback)(bt_bdaddr_t *bd_addr);
+
+/** Callback for operator selection (COPS)
+ */
+typedef void (* bthf_cops_cmd_callback)(bt_bdaddr_t *bd_addr);
+
+/** Callback for call list (AT+CLCC)
+ */
+typedef void (* bthf_clcc_cmd_callback) (bt_bdaddr_t *bd_addr);
+
+/** Callback for unknown AT command recd from HF
+ * at_string will contain the unparsed AT string
+ */
+typedef void (* bthf_unknown_at_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
+
+/** Callback for keypressed (HSP) event.
+ */
+typedef void (* bthf_key_pressed_cmd_callback)(bt_bdaddr_t *bd_addr);
+
+/** Callback for BIND. Pass the remote HF Indicators supported.
+ */
+typedef void (* bthf_bind_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
+
+/** Callback for BIEV. Pass the change in the Remote HF indicator values
+ */
+typedef void (* bthf_biev_cmd_callback)(bthf_hf_ind_type_t ind_id, int ind_value,
+ bt_bdaddr_t *bd_addr);
+
+/** BT-HF callback structure. */
+typedef struct {
+ /** set to sizeof(BtHfCallbacks) */
+ size_t size;
+ bthf_connection_state_callback connection_state_cb;
+ bthf_audio_state_callback audio_state_cb;
+ bthf_vr_cmd_callback vr_cmd_cb;
+ bthf_answer_call_cmd_callback answer_call_cmd_cb;
+ bthf_hangup_call_cmd_callback hangup_call_cmd_cb;
+ bthf_volume_cmd_callback volume_cmd_cb;
+ bthf_dial_call_cmd_callback dial_call_cmd_cb;
+ bthf_dtmf_cmd_callback dtmf_cmd_cb;
+ bthf_nrec_cmd_callback nrec_cmd_cb;
+ bthf_wbs_callback wbs_cb;
+ bthf_chld_cmd_callback chld_cmd_cb;
+ bthf_cnum_cmd_callback cnum_cmd_cb;
+ bthf_cind_cmd_callback cind_cmd_cb;
+ bthf_cops_cmd_callback cops_cmd_cb;
+ bthf_clcc_cmd_callback clcc_cmd_cb;
+ bthf_unknown_at_cmd_callback unknown_at_cmd_cb;
+ bthf_bind_cmd_callback bind_cb;
+ bthf_biev_cmd_callback biev_cb;
+ bthf_key_pressed_cmd_callback key_pressed_cmd_cb;
+} bthf_callbacks_t;
+
+/** Network Status */
+typedef enum
+{
+ BTHF_NETWORK_STATE_NOT_AVAILABLE = 0,
+ BTHF_NETWORK_STATE_AVAILABLE
+} bthf_network_state_t;
+
+/** Service type */
+typedef enum
+{
+ BTHF_SERVICE_TYPE_HOME = 0,
+ BTHF_SERVICE_TYPE_ROAMING
+} bthf_service_type_t;
+
+typedef enum {
+ BTHF_CALL_STATE_ACTIVE = 0,
+ BTHF_CALL_STATE_HELD,
+ BTHF_CALL_STATE_DIALING,
+ BTHF_CALL_STATE_ALERTING,
+ BTHF_CALL_STATE_INCOMING,
+ BTHF_CALL_STATE_WAITING,
+ BTHF_CALL_STATE_IDLE
+} bthf_call_state_t;
+
+typedef enum {
+ BTHF_CALL_DIRECTION_OUTGOING = 0,
+ BTHF_CALL_DIRECTION_INCOMING
+} bthf_call_direction_t;
+
+typedef enum {
+ BTHF_CALL_TYPE_VOICE = 0,
+ BTHF_CALL_TYPE_DATA,
+ BTHF_CALL_TYPE_FAX
+} bthf_call_mode_t;
+
+typedef enum {
+ BTHF_CALL_MPTY_TYPE_SINGLE = 0,
+ BTHF_CALL_MPTY_TYPE_MULTI
+} bthf_call_mpty_type_t;
+
+typedef enum {
+ BTHF_CALL_ADDRTYPE_UNKNOWN = 0x81,
+ BTHF_CALL_ADDRTYPE_INTERNATIONAL = 0x91
+} bthf_call_addrtype_t;
+/** Represents the standard BT-HF interface. */
+typedef struct {
+
+ /** set to sizeof(BtHfInterface) */
+ size_t size;
+ /**
+ * Register the BtHf callbacks
+ */
+ bt_status_t (*init)( bthf_callbacks_t* callbacks, int max_hf_clients);
+
+ /** connect to headset */
+ bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
+
+ /** dis-connect from headset */
+ bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
+
+ /** create an audio connection */
+ bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr );
+
+ /** close the audio connection */
+ bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr );
+
+ /** start voice recognition */
+ bt_status_t (*start_voice_recognition)( bt_bdaddr_t *bd_addr );
+
+ /** stop voice recognition */
+ bt_status_t (*stop_voice_recognition)( bt_bdaddr_t *bd_addr );
+
+ /** volume control */
+ bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr );
+
+ /** Combined device status change notification */
+ bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal,
+ int batt_chg);
+
+ /** Response for COPS command */
+ bt_status_t (*cops_response)(const char *cops, bt_bdaddr_t *bd_addr );
+
+ /** Response for CIND command */
+ bt_status_t (*cind_response)(int svc, int num_active, int num_held, bthf_call_state_t call_setup_state,
+ int signal, int roam, int batt_chg, bt_bdaddr_t *bd_addr );
+
+ /** Pre-formatted AT response, typically in response to unknown AT cmd */
+ bt_status_t (*formatted_at_response)(const char *rsp, bt_bdaddr_t *bd_addr );
+
+ /** ok/error response
+ * ERROR (0)
+ * OK (1)
+ */
+ bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code, bt_bdaddr_t *bd_addr );
+
+ /** response for CLCC command
+ * Can be iteratively called for each call index
+ * Call index of 0 will be treated as NULL termination (Completes response)
+ */
+ bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir,
+ bthf_call_state_t state, bthf_call_mode_t mode,
+ bthf_call_mpty_type_t mpty, const char *number,
+ bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr );
+
+ /** notify of a call state change
+ * Each update notifies
+ * 1. Number of active/held/ringing calls
+ * 2. call_state: This denotes the state change that triggered this msg
+ * This will take one of the values from BtHfCallState
+ * 3. number & type: valid only for incoming & waiting call
+ */
+ bt_status_t (*phone_state_change) (int num_active, int num_held, bthf_call_state_t call_setup_state,
+ const char *number, bthf_call_addrtype_t type);
+
+ /** Closes the interface. */
+ void (*cleanup)( void );
+
+ /** configureation for the SCO codec */
+ bt_status_t (*configure_wbs)( bt_bdaddr_t *bd_addr ,bthf_wbs_config_t config );
+
+ /** Response for HF Indicator change (+BIND) */
+ bt_status_t (*bind_response)(bthf_hf_ind_type_t ind_id, bthf_hf_ind_status_t ind_status,
+ bt_bdaddr_t *bd_addr);
+} bthf_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_HF_H */
diff --git a/libhardware/include/hardware/bt_hf_client.h b/libhardware/include/hardware/bt_hf_client.h
new file mode 100644
index 0000000..8acf1b2
--- /dev/null
+++ b/libhardware/include/hardware/bt_hf_client.h
@@ -0,0 +1,363 @@
+/*
+ * Copyright (C) 2012-2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_HF_CLIENT_H
+#define ANDROID_INCLUDE_BT_HF_CLIENT_H
+
+__BEGIN_DECLS
+
+typedef enum {
+ BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED = 0,
+ BTHF_CLIENT_CONNECTION_STATE_CONNECTING,
+ BTHF_CLIENT_CONNECTION_STATE_CONNECTED,
+ BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED,
+ BTHF_CLIENT_CONNECTION_STATE_DISCONNECTING
+} bthf_client_connection_state_t;
+
+typedef enum {
+ BTHF_CLIENT_AUDIO_STATE_DISCONNECTED = 0,
+ BTHF_CLIENT_AUDIO_STATE_CONNECTING,
+ BTHF_CLIENT_AUDIO_STATE_CONNECTED,
+ BTHF_CLIENT_AUDIO_STATE_CONNECTED_MSBC,
+} bthf_client_audio_state_t;
+
+typedef enum {
+ BTHF_CLIENT_VR_STATE_STOPPED = 0,
+ BTHF_CLIENT_VR_STATE_STARTED
+} bthf_client_vr_state_t;
+
+typedef enum {
+ BTHF_CLIENT_VOLUME_TYPE_SPK = 0,
+ BTHF_CLIENT_VOLUME_TYPE_MIC
+} bthf_client_volume_type_t;
+
+typedef enum
+{
+ BTHF_CLIENT_NETWORK_STATE_NOT_AVAILABLE = 0,
+ BTHF_CLIENT_NETWORK_STATE_AVAILABLE
+} bthf_client_network_state_t;
+
+typedef enum
+{
+ BTHF_CLIENT_SERVICE_TYPE_HOME = 0,
+ BTHF_CLIENT_SERVICE_TYPE_ROAMING
+} bthf_client_service_type_t;
+
+typedef enum {
+ BTHF_CLIENT_CALL_STATE_ACTIVE = 0,
+ BTHF_CLIENT_CALL_STATE_HELD,
+ BTHF_CLIENT_CALL_STATE_DIALING,
+ BTHF_CLIENT_CALL_STATE_ALERTING,
+ BTHF_CLIENT_CALL_STATE_INCOMING,
+ BTHF_CLIENT_CALL_STATE_WAITING,
+ BTHF_CLIENT_CALL_STATE_HELD_BY_RESP_HOLD,
+} bthf_client_call_state_t;
+
+typedef enum {
+ BTHF_CLIENT_CALL_NO_CALLS_IN_PROGRESS = 0,
+ BTHF_CLIENT_CALL_CALLS_IN_PROGRESS
+} bthf_client_call_t;
+
+typedef enum {
+ BTHF_CLIENT_CALLSETUP_NONE = 0,
+ BTHF_CLIENT_CALLSETUP_INCOMING,
+ BTHF_CLIENT_CALLSETUP_OUTGOING,
+ BTHF_CLIENT_CALLSETUP_ALERTING
+
+} bthf_client_callsetup_t;
+
+typedef enum {
+ BTHF_CLIENT_CALLHELD_NONE = 0,
+ BTHF_CLIENT_CALLHELD_HOLD_AND_ACTIVE,
+ BTHF_CLIENT_CALLHELD_HOLD,
+} bthf_client_callheld_t;
+
+typedef enum {
+ BTHF_CLIENT_RESP_AND_HOLD_HELD = 0,
+ BTRH_CLIENT_RESP_AND_HOLD_ACCEPT,
+ BTRH_CLIENT_RESP_AND_HOLD_REJECT,
+} bthf_client_resp_and_hold_t;
+
+typedef enum {
+ BTHF_CLIENT_CALL_DIRECTION_OUTGOING = 0,
+ BTHF_CLIENT_CALL_DIRECTION_INCOMING
+} bthf_client_call_direction_t;
+
+typedef enum {
+ BTHF_CLIENT_CALL_MPTY_TYPE_SINGLE = 0,
+ BTHF_CLIENT_CALL_MPTY_TYPE_MULTI
+} bthf_client_call_mpty_type_t;
+
+typedef enum {
+ BTHF_CLIENT_CMD_COMPLETE_OK = 0,
+ BTHF_CLIENT_CMD_COMPLETE_ERROR,
+ BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_CARRIER,
+ BTHF_CLIENT_CMD_COMPLETE_ERROR_BUSY,
+ BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_ANSWER,
+ BTHF_CLIENT_CMD_COMPLETE_ERROR_DELAYED,
+ BTHF_CLIENT_CMD_COMPLETE_ERROR_BLACKLISTED,
+ BTHF_CLIENT_CMD_COMPLETE_ERROR_CME
+} bthf_client_cmd_complete_t;
+
+typedef enum {
+ BTHF_CLIENT_CALL_ACTION_CHLD_0 = 0,
+ BTHF_CLIENT_CALL_ACTION_CHLD_1,
+ BTHF_CLIENT_CALL_ACTION_CHLD_2,
+ BTHF_CLIENT_CALL_ACTION_CHLD_3,
+ BTHF_CLIENT_CALL_ACTION_CHLD_4,
+ BTHF_CLIENT_CALL_ACTION_CHLD_1x,
+ BTHF_CLIENT_CALL_ACTION_CHLD_2x,
+ BTHF_CLIENT_CALL_ACTION_ATA,
+ BTHF_CLIENT_CALL_ACTION_CHUP,
+ BTHF_CLIENT_CALL_ACTION_BTRH_0,
+ BTHF_CLIENT_CALL_ACTION_BTRH_1,
+ BTHF_CLIENT_CALL_ACTION_BTRH_2,
+} bthf_client_call_action_t;
+
+typedef enum {
+ BTHF_CLIENT_SERVICE_UNKNOWN = 0,
+ BTHF_CLIENT_SERVICE_VOICE,
+ BTHF_CLIENT_SERVICE_FAX
+} bthf_client_subscriber_service_type_t;
+
+typedef enum {
+ BTHF_CLIENT_IN_BAND_RINGTONE_NOT_PROVIDED = 0,
+ BTHF_CLIENT_IN_BAND_RINGTONE_PROVIDED,
+} bthf_client_in_band_ring_state_t;
+
+/* Peer features masks */
+#define BTHF_CLIENT_PEER_FEAT_3WAY 0x00000001 /* Three-way calling */
+#define BTHF_CLIENT_PEER_FEAT_ECNR 0x00000002 /* Echo cancellation and/or noise reduction */
+#define BTHF_CLIENT_PEER_FEAT_VREC 0x00000004 /* Voice recognition */
+#define BTHF_CLIENT_PEER_FEAT_INBAND 0x00000008 /* In-band ring tone */
+#define BTHF_CLIENT_PEER_FEAT_VTAG 0x00000010 /* Attach a phone number to a voice tag */
+#define BTHF_CLIENT_PEER_FEAT_REJECT 0x00000020 /* Ability to reject incoming call */
+#define BTHF_CLIENT_PEER_FEAT_ECS 0x00000040 /* Enhanced Call Status */
+#define BTHF_CLIENT_PEER_FEAT_ECC 0x00000080 /* Enhanced Call Control */
+#define BTHF_CLIENT_PEER_FEAT_EXTERR 0x00000100 /* Extended error codes */
+#define BTHF_CLIENT_PEER_FEAT_CODEC 0x00000200 /* Codec Negotiation */
+
+/* Peer call handling features masks */
+#define BTHF_CLIENT_CHLD_FEAT_REL 0x00000001 /* 0 Release waiting call or held calls */
+#define BTHF_CLIENT_CHLD_FEAT_REL_ACC 0x00000002 /* 1 Release active calls and accept other
+ (waiting or held) cal */
+#define BTHF_CLIENT_CHLD_FEAT_REL_X 0x00000004 /* 1x Release specified active call only */
+#define BTHF_CLIENT_CHLD_FEAT_HOLD_ACC 0x00000008 /* 2 Active calls on hold and accept other
+ (waiting or held) call */
+#define BTHF_CLIENT_CHLD_FEAT_PRIV_X 0x00000010 /* 2x Request private mode with specified
+ call (put the rest on hold) */
+#define BTHF_CLIENT_CHLD_FEAT_MERGE 0x00000020 /* 3 Add held call to multiparty */
+#define BTHF_CLIENT_CHLD_FEAT_MERGE_DETACH 0x00000040 /* 4 Connect two calls and leave
+ (disconnect from) multiparty */
+
+/** Callback for connection state change.
+ * state will have one of the values from BtHfConnectionState
+ * peer/chld_features are valid only for BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED state
+ */
+typedef void (* bthf_client_connection_state_callback)(bthf_client_connection_state_t state,
+ unsigned int peer_feat,
+ unsigned int chld_feat,
+ bt_bdaddr_t *bd_addr);
+
+/** Callback for audio connection state change.
+ * state will have one of the values from BtHfAudioState
+ */
+typedef void (* bthf_client_audio_state_callback)(bthf_client_audio_state_t state,
+ bt_bdaddr_t *bd_addr);
+
+/** Callback for VR connection state change.
+ * state will have one of the values from BtHfVRState
+ */
+typedef void (* bthf_client_vr_cmd_callback)(bthf_client_vr_state_t state);
+
+/** Callback for network state change
+ */
+typedef void (* bthf_client_network_state_callback) (bthf_client_network_state_t state);
+
+/** Callback for network roaming status change
+ */
+typedef void (* bthf_client_network_roaming_callback) (bthf_client_service_type_t type);
+
+/** Callback for signal strength indication
+ */
+typedef void (* bthf_client_network_signal_callback) (int signal_strength);
+
+/** Callback for battery level indication
+ */
+typedef void (* bthf_client_battery_level_callback) (int battery_level);
+
+/** Callback for current operator name
+ */
+typedef void (* bthf_client_current_operator_callback) (const char *name);
+
+/** Callback for call indicator
+ */
+typedef void (* bthf_client_call_callback) (bthf_client_call_t call);
+
+/** Callback for callsetup indicator
+ */
+typedef void (* bthf_client_callsetup_callback) (bthf_client_callsetup_t callsetup);
+
+/** Callback for callheld indicator
+ */
+typedef void (* bthf_client_callheld_callback) (bthf_client_callheld_t callheld);
+
+/** Callback for response and hold
+ */
+typedef void (* bthf_client_resp_and_hold_callback) (bthf_client_resp_and_hold_t resp_and_hold);
+
+/** Callback for Calling Line Identification notification
+ * Will be called only when there is an incoming call and number is provided.
+ */
+typedef void (* bthf_client_clip_callback) (const char *number);
+
+/**
+ * Callback for Call Waiting notification
+ */
+typedef void (* bthf_client_call_waiting_callback) (const char *number);
+
+/**
+ * Callback for listing current calls. Can be called multiple time.
+ * If number is unknown NULL is passed.
+ */
+typedef void (*bthf_client_current_calls) (int index, bthf_client_call_direction_t dir,
+ bthf_client_call_state_t state,
+ bthf_client_call_mpty_type_t mpty,
+ const char *number);
+
+/** Callback for audio volume change
+ */
+typedef void (*bthf_client_volume_change_callback) (bthf_client_volume_type_t type, int volume);
+
+/** Callback for command complete event
+ * cme is valid only for BTHF_CLIENT_CMD_COMPLETE_ERROR_CME type
+ */
+typedef void (*bthf_client_cmd_complete_callback) (bthf_client_cmd_complete_t type, int cme);
+
+/** Callback for subscriber information
+ */
+typedef void (* bthf_client_subscriber_info_callback) (const char *name,
+ bthf_client_subscriber_service_type_t type);
+
+/** Callback for in-band ring tone settings
+ */
+typedef void (* bthf_client_in_band_ring_tone_callback) (bthf_client_in_band_ring_state_t state);
+
+/**
+ * Callback for requested number from AG
+ */
+typedef void (* bthf_client_last_voice_tag_number_callback) (const char *number);
+
+/**
+ * Callback for sending ring indication to app
+ */
+typedef void (* bthf_client_ring_indication_callback) (void);
+
+/** BT-HF callback structure. */
+typedef struct {
+ /** set to sizeof(BtHfClientCallbacks) */
+ size_t size;
+ bthf_client_connection_state_callback connection_state_cb;
+ bthf_client_audio_state_callback audio_state_cb;
+ bthf_client_vr_cmd_callback vr_cmd_cb;
+ bthf_client_network_state_callback network_state_cb;
+ bthf_client_network_roaming_callback network_roaming_cb;
+ bthf_client_network_signal_callback network_signal_cb;
+ bthf_client_battery_level_callback battery_level_cb;
+ bthf_client_current_operator_callback current_operator_cb;
+ bthf_client_call_callback call_cb;
+ bthf_client_callsetup_callback callsetup_cb;
+ bthf_client_callheld_callback callheld_cb;
+ bthf_client_resp_and_hold_callback resp_and_hold_cb;
+ bthf_client_clip_callback clip_cb;
+ bthf_client_call_waiting_callback call_waiting_cb;
+ bthf_client_current_calls current_calls_cb;
+ bthf_client_volume_change_callback volume_change_cb;
+ bthf_client_cmd_complete_callback cmd_complete_cb;
+ bthf_client_subscriber_info_callback subscriber_info_cb;
+ bthf_client_in_band_ring_tone_callback in_band_ring_tone_cb;
+ bthf_client_last_voice_tag_number_callback last_voice_tag_number_callback;
+ bthf_client_ring_indication_callback ring_indication_cb;
+} bthf_client_callbacks_t;
+
+/** Represents the standard BT-HF interface. */
+typedef struct {
+
+ /** set to sizeof(BtHfClientInterface) */
+ size_t size;
+ /**
+ * Register the BtHf callbacks
+ */
+ bt_status_t (*init)(bthf_client_callbacks_t* callbacks);
+
+ /** connect to audio gateway */
+ bt_status_t (*connect)(bt_bdaddr_t *bd_addr);
+
+ /** disconnect from audio gateway */
+ bt_status_t (*disconnect)(bt_bdaddr_t *bd_addr);
+
+ /** create an audio connection */
+ bt_status_t (*connect_audio)(bt_bdaddr_t *bd_addr);
+
+ /** close the audio connection */
+ bt_status_t (*disconnect_audio)(bt_bdaddr_t *bd_addr);
+
+ /** start voice recognition */
+ bt_status_t (*start_voice_recognition)(void);
+
+ /** stop voice recognition */
+ bt_status_t (*stop_voice_recognition)(void);
+
+ /** volume control */
+ bt_status_t (*volume_control) (bthf_client_volume_type_t type, int volume);
+
+ /** place a call with number a number
+ * if number is NULL last called number is called (aka re-dial)*/
+ bt_status_t (*dial) (const char *number);
+
+ /** place a call with number specified by location (speed dial) */
+ bt_status_t (*dial_memory) (int location);
+
+ /** perform specified call related action
+ * idx is limited only for enhanced call control related action
+ */
+ bt_status_t (*handle_call_action) (bthf_client_call_action_t action, int idx);
+
+ /** query list of current calls */
+ bt_status_t (*query_current_calls) (void);
+
+ /** query name of current selected operator */
+ bt_status_t (*query_current_operator_name) (void);
+
+ /** Retrieve subscriber information */
+ bt_status_t (*retrieve_subscriber_info) (void);
+
+ /** Send DTMF code*/
+ bt_status_t (*send_dtmf) (char code);
+
+ /** Request a phone number from AG corresponding to last voice tag recorded */
+ bt_status_t (*request_last_voice_tag_number) (void);
+
+ /** Closes the interface. */
+ void (*cleanup)(void);
+
+ /** Send AT Command. */
+ bt_status_t (*send_at_cmd) (int cmd, int val1, int val2, const char *arg);
+} bthf_client_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_HF_CLIENT_H */
diff --git a/libhardware/include/hardware/bt_hh.h b/libhardware/include/hardware/bt_hh.h
new file mode 100644
index 0000000..dad9586
--- /dev/null
+++ b/libhardware/include/hardware/bt_hh.h
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_HH_H
+#define ANDROID_INCLUDE_BT_HH_H
+
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+#define BTHH_MAX_DSC_LEN 884
+
+/* HH connection states */
+typedef enum
+{
+ BTHH_CONN_STATE_CONNECTED = 0,
+ BTHH_CONN_STATE_CONNECTING,
+ BTHH_CONN_STATE_DISCONNECTED,
+ BTHH_CONN_STATE_DISCONNECTING,
+ BTHH_CONN_STATE_FAILED_MOUSE_FROM_HOST,
+ BTHH_CONN_STATE_FAILED_KBD_FROM_HOST,
+ BTHH_CONN_STATE_FAILED_TOO_MANY_DEVICES,
+ BTHH_CONN_STATE_FAILED_NO_BTHID_DRIVER,
+ BTHH_CONN_STATE_FAILED_GENERIC,
+ BTHH_CONN_STATE_UNKNOWN
+} bthh_connection_state_t;
+
+typedef enum
+{
+ BTHH_OK = 0,
+ BTHH_HS_HID_NOT_READY, /* handshake error : device not ready */
+ BTHH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */
+ BTHH_HS_TRANS_NOT_SPT, /* handshake error : transaction not spt */
+ BTHH_HS_INVALID_PARAM, /* handshake error : invalid paremter */
+ BTHH_HS_ERROR, /* handshake error : unspecified HS error */
+ BTHH_ERR, /* general BTA HH error */
+ BTHH_ERR_SDP, /* SDP error */
+ BTHH_ERR_PROTO, /* SET_Protocol error,
+ only used in BTA_HH_OPEN_EVT callback */
+ BTHH_ERR_DB_FULL, /* device database full error, used */
+ BTHH_ERR_TOD_UNSPT, /* type of device not supported */
+ BTHH_ERR_NO_RES, /* out of system resources */
+ BTHH_ERR_AUTH_FAILED, /* authentication fail */
+ BTHH_ERR_HDL
+}bthh_status_t;
+
+/* Protocol modes */
+typedef enum {
+ BTHH_REPORT_MODE = 0x00,
+ BTHH_BOOT_MODE = 0x01,
+ BTHH_UNSUPPORTED_MODE = 0xff
+}bthh_protocol_mode_t;
+
+/* Report types */
+typedef enum {
+ BTHH_INPUT_REPORT = 1,
+ BTHH_OUTPUT_REPORT,
+ BTHH_FEATURE_REPORT
+}bthh_report_type_t;
+
+typedef struct
+{
+ int attr_mask;
+ uint8_t sub_class;
+ uint8_t app_id;
+ int vendor_id;
+ int product_id;
+ int version;
+ uint8_t ctry_code;
+ int dl_len;
+ uint8_t dsc_list[BTHH_MAX_DSC_LEN];
+} bthh_hid_info_t;
+
+/** Callback for connection state change.
+ * state will have one of the values from bthh_connection_state_t
+ */
+typedef void (* bthh_connection_state_callback)(bt_bdaddr_t *bd_addr, bthh_connection_state_t state);
+
+/** Callback for vitual unplug api.
+ * the status of the vitual unplug
+ */
+typedef void (* bthh_virtual_unplug_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
+
+/** Callback for get hid info
+ * hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, version, ctry_code, len
+ */
+typedef void (* bthh_hid_info_callback)(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info);
+
+/** Callback for get protocol api.
+ * the protocol mode is one of the value from bthh_protocol_mode_t
+ */
+typedef void (* bthh_protocol_mode_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, bthh_protocol_mode_t mode);
+
+/** Callback for get/set_idle_time api.
+ */
+typedef void (* bthh_idle_time_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, int idle_rate);
+
+
+/** Callback for get report api.
+ * if staus is ok rpt_data contains the report data
+ */
+typedef void (* bthh_get_report_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t* rpt_data, int rpt_size);
+
+/** Callback for set_report/set_protocol api and if error
+ * occurs for get_report/get_protocol api.
+ */
+typedef void (* bthh_handshake_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
+
+
+/** BT-HH callback structure. */
+typedef struct {
+ /** set to sizeof(BtHfCallbacks) */
+ size_t size;
+ bthh_connection_state_callback connection_state_cb;
+ bthh_hid_info_callback hid_info_cb;
+ bthh_protocol_mode_callback protocol_mode_cb;
+ bthh_idle_time_callback idle_time_cb;
+ bthh_get_report_callback get_report_cb;
+ bthh_virtual_unplug_callback virtual_unplug_cb;
+ bthh_handshake_callback handshake_cb;
+
+} bthh_callbacks_t;
+
+
+
+/** Represents the standard BT-HH interface. */
+typedef struct {
+
+ /** set to sizeof(BtHhInterface) */
+ size_t size;
+
+ /**
+ * Register the BtHh callbacks
+ */
+ bt_status_t (*init)( bthh_callbacks_t* callbacks );
+
+ /** connect to hid device */
+ bt_status_t (*connect)( bt_bdaddr_t *bd_addr);
+
+ /** dis-connect from hid device */
+ bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
+
+ /** Virtual UnPlug (VUP) the specified HID device */
+ bt_status_t (*virtual_unplug)(bt_bdaddr_t *bd_addr);
+
+ /** Set the HID device descriptor for the specified HID device. */
+ bt_status_t (*set_info)(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info );
+
+ /** Get the HID proto mode. */
+ bt_status_t (*get_protocol) (bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
+
+ /** Set the HID proto mode. */
+ bt_status_t (*set_protocol)(bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
+
+ /** Send a GET_REPORT to HID device. */
+ bt_status_t (*get_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, uint8_t reportId, int bufferSize);
+
+ /** Send a SET_REPORT to HID device. */
+ bt_status_t (*set_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, char* report);
+
+ /** Send data to HID device. */
+ bt_status_t (*send_data)(bt_bdaddr_t *bd_addr, char* data);
+
+ /** Closes the interface. */
+ void (*cleanup)( void );
+
+} bthh_interface_t;
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_HH_H */
+
+
diff --git a/libhardware/include/hardware/bt_hl.h b/libhardware/include/hardware/bt_hl.h
new file mode 100644
index 0000000..bd29e3a
--- /dev/null
+++ b/libhardware/include/hardware/bt_hl.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_HL_H
+#define ANDROID_INCLUDE_BT_HL_H
+
+__BEGIN_DECLS
+
+/* HL connection states */
+
+typedef enum
+{
+ BTHL_MDEP_ROLE_SOURCE,
+ BTHL_MDEP_ROLE_SINK
+} bthl_mdep_role_t;
+
+typedef enum {
+ BTHL_APP_REG_STATE_REG_SUCCESS,
+ BTHL_APP_REG_STATE_REG_FAILED,
+ BTHL_APP_REG_STATE_DEREG_SUCCESS,
+ BTHL_APP_REG_STATE_DEREG_FAILED
+} bthl_app_reg_state_t;
+
+typedef enum
+{
+ BTHL_CHANNEL_TYPE_RELIABLE,
+ BTHL_CHANNEL_TYPE_STREAMING,
+ BTHL_CHANNEL_TYPE_ANY
+} bthl_channel_type_t;
+
+
+/* HL connection states */
+typedef enum {
+ BTHL_CONN_STATE_CONNECTING,
+ BTHL_CONN_STATE_CONNECTED,
+ BTHL_CONN_STATE_DISCONNECTING,
+ BTHL_CONN_STATE_DISCONNECTED,
+ BTHL_CONN_STATE_DESTROYED
+} bthl_channel_state_t;
+
+typedef struct
+{
+ bthl_mdep_role_t mdep_role;
+ int data_type;
+ bthl_channel_type_t channel_type;
+ const char *mdep_description; /* MDEP description to be used in the SDP (optional); null terminated */
+} bthl_mdep_cfg_t;
+
+typedef struct
+{
+ const char *application_name;
+ const char *provider_name; /* provider name to be used in the SDP (optional); null terminated */
+ const char *srv_name; /* service name to be used in the SDP (optional); null terminated*/
+ const char *srv_desp; /* service description to be used in the SDP (optional); null terminated */
+ int number_of_mdeps;
+ bthl_mdep_cfg_t *mdep_cfg; /* Dynamic array */
+} bthl_reg_param_t;
+
+/** Callback for application registration status.
+ * state will have one of the values from bthl_app_reg_state_t
+ */
+typedef void (* bthl_app_reg_state_callback)(int app_id, bthl_app_reg_state_t state);
+
+/** Callback for channel connection state change.
+ * state will have one of the values from
+ * bthl_connection_state_t and fd (file descriptor)
+ */
+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);
+
+/** BT-HL callback structure. */
+typedef struct {
+ /** set to sizeof(bthl_callbacks_t) */
+ size_t size;
+ bthl_app_reg_state_callback app_reg_state_cb;
+ bthl_channel_state_callback channel_state_cb;
+} bthl_callbacks_t;
+
+
+/** Represents the standard BT-HL interface. */
+typedef struct {
+
+ /** set to sizeof(bthl_interface_t) */
+ size_t size;
+
+ /**
+ * Register the Bthl callbacks
+ */
+ bt_status_t (*init)( bthl_callbacks_t* callbacks );
+
+ /** Register HL application */
+ bt_status_t (*register_application) ( bthl_reg_param_t *p_reg_param, int *app_id);
+
+ /** Unregister HL application */
+ bt_status_t (*unregister_application) (int app_id);
+
+ /** connect channel */
+ bt_status_t (*connect_channel)(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int *channel_id);
+
+ /** destroy channel */
+ bt_status_t (*destroy_channel)(int channel_id);
+
+ /** Close the Bthl callback **/
+ void (*cleanup)(void);
+
+} bthl_interface_t;
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_HL_H */
+
+
diff --git a/libhardware/include/hardware/bt_mce.h b/libhardware/include/hardware/bt_mce.h
new file mode 100644
index 0000000..5d159b3
--- /dev/null
+++ b/libhardware/include/hardware/bt_mce.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_MCE_H
+#define ANDROID_INCLUDE_BT_MCE_H
+
+__BEGIN_DECLS
+
+/** MAS instance description */
+typedef struct
+{
+ int id;
+ int scn;
+ int msg_types;
+ char *p_name;
+} btmce_mas_instance_t;
+
+/** callback for get_remote_mas_instances */
+typedef void (*btmce_remote_mas_instances_callback)(bt_status_t status, bt_bdaddr_t *bd_addr,
+ int num_instances, btmce_mas_instance_t *instances);
+
+typedef struct {
+ /** set to sizeof(btmce_callbacks_t) */
+ size_t size;
+ btmce_remote_mas_instances_callback remote_mas_instances_cb;
+} btmce_callbacks_t;
+
+typedef struct {
+ /** set to size of this struct */
+ size_t size;
+
+ /** register BT MCE callbacks */
+ bt_status_t (*init)(btmce_callbacks_t *callbacks);
+
+ /** search for MAS instances on remote device */
+ bt_status_t (*get_remote_mas_instances)(bt_bdaddr_t *bd_addr);
+} btmce_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_MCE_H */
diff --git a/libhardware/include/hardware/bt_pan.h b/libhardware/include/hardware/bt_pan.h
new file mode 100644
index 0000000..83e7949
--- /dev/null
+++ b/libhardware/include/hardware/bt_pan.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_PAN_H
+#define ANDROID_INCLUDE_BT_PAN_H
+
+__BEGIN_DECLS
+
+#define BTPAN_ROLE_NONE 0
+#define BTPAN_ROLE_PANNAP 1
+#define BTPAN_ROLE_PANU 2
+
+typedef enum {
+ BTPAN_STATE_CONNECTED = 0,
+ BTPAN_STATE_CONNECTING = 1,
+ BTPAN_STATE_DISCONNECTED = 2,
+ BTPAN_STATE_DISCONNECTING = 3
+} btpan_connection_state_t;
+
+typedef enum {
+ BTPAN_STATE_ENABLED = 0,
+ BTPAN_STATE_DISABLED = 1
+} btpan_control_state_t;
+
+/**
+* Callback for pan connection state
+*/
+typedef void (*btpan_connection_state_callback)(btpan_connection_state_t state, bt_status_t error,
+ const bt_bdaddr_t *bd_addr, int local_role, int remote_role);
+typedef void (*btpan_control_state_callback)(btpan_control_state_t state, int local_role,
+ bt_status_t error, const char* ifname);
+
+typedef struct {
+ size_t size;
+ btpan_control_state_callback control_state_cb;
+ btpan_connection_state_callback connection_state_cb;
+} btpan_callbacks_t;
+typedef struct {
+ /** set to size of this struct*/
+ size_t size;
+ /**
+ * Initialize the pan interface and register the btpan callbacks
+ */
+ bt_status_t (*init)(const btpan_callbacks_t* callbacks);
+ /*
+ * enable the pan service by specified role. The result state of
+ * enabl will be returned by btpan_control_state_callback. when pan-nap is enabled,
+ * the state of connecting panu device will be notified by btpan_connection_state_callback
+ */
+ bt_status_t (*enable)(int local_role);
+ /*
+ * get current pan local role
+ */
+ int (*get_local_role)(void);
+ /**
+ * start bluetooth pan connection to the remote device by specified pan role. The result state will be
+ * returned by btpan_connection_state_callback
+ */
+ bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, int local_role, int remote_role);
+ /**
+ * stop bluetooth pan connection. The result state will be returned by btpan_connection_state_callback
+ */
+ bt_status_t (*disconnect)(const bt_bdaddr_t *bd_addr);
+
+ /**
+ * Cleanup the pan interface
+ */
+ void (*cleanup)(void);
+
+} btpan_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_PAN_H */
diff --git a/libhardware/include/hardware/bt_rc.h b/libhardware/include/hardware/bt_rc.h
new file mode 100644
index 0000000..71a8901
--- /dev/null
+++ b/libhardware/include/hardware/bt_rc.h
@@ -0,0 +1,723 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_RC_H
+#define ANDROID_INCLUDE_BT_RC_H
+
+__BEGIN_DECLS
+
+/* Change this macro to use multiple RC */
+#define BT_RC_NUM_APP 1
+
+/* Macros */
+#define BTRC_MAX_ATTR_STR_LEN (1 << 16)
+#define BTRC_UID_SIZE 8
+#define BTRC_MAX_APP_SETTINGS 8
+#define BTRC_MAX_FOLDER_DEPTH 4
+#define BTRC_MAX_APP_ATTR_SIZE 16
+#define BTRC_MAX_ELEM_ATTR_SIZE 8
+#define BTRC_FEATURE_BIT_MASK_SIZE 16
+
+/* Macros for valid scopes in get_folder_items */
+#define BTRC_SCOPE_PLAYER_LIST 0x00 /* Media Player List */
+#define BTRC_SCOPE_FILE_SYSTEM 0x01 /* Virtual File System */
+#define BTRC_SCOPE_SEARCH 0x02 /* Search */
+#define BTRC_SCOPE_NOW_PLAYING 0x03 /* Now Playing */
+
+/* Macros for supported character encoding */
+#define BTRC_CHARSET_ID_UTF8 0x006A
+
+/* Macros for item types */
+#define BTRC_ITEM_PLAYER 0x01 /* Media Player */
+#define BTRC_ITEM_FOLDER 0x02 /* Folder */
+#define BTRC_ITEM_MEDIA 0x03 /* Media File */
+
+/* Macros for media attribute IDs */
+#define BTRC_MEDIA_ATTR_ID_INVALID -1
+#define BTRC_MEDIA_ATTR_ID_TITLE 0x00000001
+#define BTRC_MEDIA_ATTR_ID_ARTIST 0x00000002
+#define BTRC_MEDIA_ATTR_ID_ALBUM 0x00000003
+#define BTRC_MEDIA_ATTR_ID_TRACK_NUM 0x00000004
+#define BTRC_MEDIA_ATTR_ID_NUM_TRACKS 0x00000005
+#define BTRC_MEDIA_ATTR_ID_GENRE 0x00000006
+#define BTRC_MEDIA_ATTR_ID_PLAYING_TIME 0x00000007 /* in miliseconds */
+
+/* Macros for folder types */
+#define BTRC_FOLDER_TYPE_MIXED 0x00
+#define BTRC_FOLDER_TYPE_TITLES 0x01
+#define BTRC_FOLDER_TYPE_ALBUMS 0x02
+#define BTRC_FOLDER_TYPE_ARTISTS 0x03
+#define BTRC_FOLDER_TYPE_GENRES 0x04
+#define BTRC_FOLDER_TYPE_PLAYLISTS 0x05
+#define BTRC_FOLDER_TYPE_YEARS 0x06
+
+/* Macros for media types */
+#define BTRC_MEDIA_TYPE_AUDIO 0x00 /* audio */
+#define BTRC_MEDIA_TYPE_VIDEO 0x01 /* video */
+
+/* Macros for num attributes */
+#define BTRC_NUM_ATTR_NONE 0xFF /* No attributes required */
+#define BTRC_NUM_ATTR_ALL 0X00 /* All attributes required */
+
+#define BTRC_HANDLE_NONE 0xFF
+
+typedef uint8_t btrc_uid_t[BTRC_UID_SIZE];
+
+typedef enum {
+ BTRC_CONNECTION_STATE_DISCONNECTED = 0,
+ BTRC_CONNECTION_STATE_CONNECTED
+} btrc_connection_state_t;
+
+typedef enum {
+ BTRC_FEAT_NONE = 0x00, /* AVRCP 1.0 */
+ BTRC_FEAT_METADATA = 0x01, /* AVRCP 1.3 */
+ BTRC_FEAT_ABSOLUTE_VOLUME = 0x02, /* Supports TG role and volume sync */
+ BTRC_FEAT_BROWSE = 0x04, /* AVRCP 1.4 and up, with Browsing support */
+} btrc_remote_features_t;
+
+typedef enum {
+ BTRC_PLAYSTATE_STOPPED = 0x00, /* Stopped */
+ BTRC_PLAYSTATE_PLAYING = 0x01, /* Playing */
+ BTRC_PLAYSTATE_PAUSED = 0x02, /* Paused */
+ BTRC_PLAYSTATE_FWD_SEEK = 0x03, /* Fwd Seek*/
+ BTRC_PLAYSTATE_REV_SEEK = 0x04, /* Rev Seek*/
+ BTRC_PLAYSTATE_ERROR = 0xFF, /* Error */
+} btrc_play_status_t;
+
+typedef enum {
+ BTRC_EVT_PLAY_STATUS_CHANGED = 0x01,
+ BTRC_EVT_TRACK_CHANGE = 0x02,
+ BTRC_EVT_TRACK_REACHED_END = 0x03,
+ BTRC_EVT_TRACK_REACHED_START = 0x04,
+ BTRC_EVT_PLAY_POS_CHANGED = 0x05,
+ BTRC_EVT_APP_SETTINGS_CHANGED = 0x08,
+ BTRC_EVT_NOW_PLAYING_CONTENT_CHANGED = 0x09,
+ BTRC_EVT_AVAL_PLAYER_CHANGE = 0x0a,
+ BTRC_EVT_ADDR_PLAYER_CHANGE = 0x0b,
+ BTRC_EVT_UIDS_CHANGED = 0x0c,
+ BTRC_EVT_VOL_CHANGED = 0x0d,
+} btrc_event_id_t;
+
+typedef enum {
+ BTRC_NOTIFICATION_TYPE_INTERIM = 0,
+ BTRC_NOTIFICATION_TYPE_CHANGED = 1,
+} btrc_notification_type_t;
+
+typedef enum {
+ BTRC_PLAYER_ATTR_EQUALIZER = 0x01,
+ BTRC_PLAYER_ATTR_REPEAT = 0x02,
+ BTRC_PLAYER_ATTR_SHUFFLE = 0x03,
+ BTRC_PLAYER_ATTR_SCAN = 0x04,
+} btrc_player_attr_t;
+
+typedef enum {
+ BTRC_MEDIA_ATTR_TITLE = 0x01,
+ BTRC_MEDIA_ATTR_ARTIST = 0x02,
+ BTRC_MEDIA_ATTR_ALBUM = 0x03,
+ BTRC_MEDIA_ATTR_TRACK_NUM = 0x04,
+ BTRC_MEDIA_ATTR_NUM_TRACKS = 0x05,
+ BTRC_MEDIA_ATTR_GENRE = 0x06,
+ BTRC_MEDIA_ATTR_PLAYING_TIME = 0x07,
+} btrc_media_attr_t;
+
+typedef enum {
+ BTRC_PLAYER_VAL_OFF_REPEAT = 0x01,
+ BTRC_PLAYER_VAL_SINGLE_REPEAT = 0x02,
+ BTRC_PLAYER_VAL_ALL_REPEAT = 0x03,
+ BTRC_PLAYER_VAL_GROUP_REPEAT = 0x04
+} btrc_player_repeat_val_t;
+
+typedef enum {
+ BTRC_PLAYER_VAL_OFF_SHUFFLE = 0x01,
+ BTRC_PLAYER_VAL_ALL_SHUFFLE = 0x02,
+ BTRC_PLAYER_VAL_GROUP_SHUFFLE = 0x03
+} btrc_player_shuffle_val_t;
+
+typedef enum {
+ BTRC_STS_BAD_CMD = 0x00, /* Invalid command */
+ BTRC_STS_BAD_PARAM = 0x01, /* Invalid parameter */
+ BTRC_STS_NOT_FOUND = 0x02, /* Specified parameter is wrong or not found */
+ BTRC_STS_INTERNAL_ERR = 0x03, /* Internal Error */
+ BTRC_STS_NO_ERROR = 0x04, /* Operation Success */
+ BTRC_STS_UID_CHANGED = 0x05, /* UIDs changed */
+ BTRC_STS_RESERVED = 0x06, /* Reserved */
+ BTRC_STS_INV_DIRN = 0x07, /* Invalid direction */
+ BTRC_STS_INV_DIRECTORY = 0x08, /* Invalid directory */
+ BTRC_STS_INV_ITEM = 0x09, /* Invalid Item */
+ BTRC_STS_INV_SCOPE = 0x0a, /* Invalid scope */
+ BTRC_STS_INV_RANGE = 0x0b, /* Invalid range */
+ BTRC_STS_DIRECTORY = 0x0c, /* UID is a directory */
+ BTRC_STS_MEDIA_IN_USE = 0x0d, /* Media in use */
+ BTRC_STS_PLAY_LIST_FULL = 0x0e, /* Playing list full */
+ BTRC_STS_SRCH_NOT_SPRTD = 0x0f, /* Search not supported */
+ BTRC_STS_SRCH_IN_PROG = 0x10, /* Search in progress */
+ BTRC_STS_INV_PLAYER = 0x11, /* Invalid player */
+ BTRC_STS_PLAY_NOT_BROW = 0x12, /* Player not browsable */
+ BTRC_STS_PLAY_NOT_ADDR = 0x13, /* Player not addressed */
+ BTRC_STS_INV_RESULTS = 0x14, /* Invalid results */
+ BTRC_STS_NO_AVBL_PLAY = 0x15, /* No available players */
+ BTRC_STS_ADDR_PLAY_CHGD = 0x16, /* Addressed player changed */
+} btrc_status_t;
+
+typedef struct {
+ uint16_t player_id;
+ uint16_t uid_counter;
+} btrc_addr_player_changed_t;
+
+typedef struct {
+ uint8_t num_attr;
+ uint8_t attr_ids[BTRC_MAX_APP_SETTINGS];
+ uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
+} btrc_player_settings_t;
+
+typedef struct {
+ uint8_t val;
+ uint16_t charset_id;
+ uint16_t str_len;
+ uint8_t *p_str;
+} btrc_player_app_ext_attr_val_t;
+
+typedef struct {
+ uint8_t attr_id;
+ uint16_t charset_id;
+ uint16_t str_len;
+ uint8_t *p_str;
+ uint8_t num_val;
+ btrc_player_app_ext_attr_val_t ext_attr_val[BTRC_MAX_APP_ATTR_SIZE];
+} btrc_player_app_ext_attr_t;
+
+typedef struct {
+ uint8_t attr_id;
+ uint8_t num_val;
+ uint8_t attr_val[BTRC_MAX_APP_ATTR_SIZE];
+} btrc_player_app_attr_t;
+
+typedef struct {
+ uint32_t start_item;
+ uint32_t end_item;
+ uint32_t size;
+ uint32_t attrs[BTRC_MAX_ELEM_ATTR_SIZE];
+ uint8_t attr_count;
+} btrc_getfolderitem_t;
+
+typedef struct {
+ uint16_t type;
+ uint16_t uid_counter;
+} btrc_uids_changed_t;
+
+typedef struct {
+ uint16_t type;
+} btrc_now_playing_changed_t;
+
+typedef union
+{
+ btrc_play_status_t play_status;
+ btrc_uid_t track; /* queue position in NowPlaying */
+ uint32_t song_pos;
+ uint16_t uid_counter;
+ btrc_player_settings_t player_setting;
+ btrc_addr_player_changed_t addr_player_changed;
+ btrc_uids_changed_t uids_changed;
+ btrc_now_playing_changed_t now_playing_changed;
+} btrc_register_notification_t;
+
+typedef struct {
+ uint8_t id; /* can be attr_id or value_id */
+ uint8_t text[BTRC_MAX_ATTR_STR_LEN];
+} btrc_player_setting_text_t;
+
+typedef struct {
+ uint32_t attr_id;
+ uint8_t text[BTRC_MAX_ATTR_STR_LEN];
+} btrc_element_attr_val_t;
+
+typedef struct {
+ uint16_t player_id;
+ uint8_t major_type;
+ uint32_t sub_type;
+ uint8_t play_status;
+ uint8_t features[BTRC_FEATURE_BIT_MASK_SIZE];
+ uint16_t charset_id;
+ uint8_t name[BTRC_MAX_ATTR_STR_LEN];
+} btrc_item_player_t;
+
+typedef struct {
+ uint8_t uid[BTRC_UID_SIZE];
+ uint8_t type;
+ uint8_t playable;
+ uint16_t charset_id;
+ uint8_t name[BTRC_MAX_ATTR_STR_LEN];
+} btrc_item_folder_t;
+
+typedef struct {
+ uint8_t uid[BTRC_UID_SIZE];
+ uint8_t type;
+ uint16_t charset_id;
+ uint8_t name[BTRC_MAX_ATTR_STR_LEN];
+ int num_attrs;
+ btrc_element_attr_val_t* p_attrs;
+} btrc_item_media_t;
+
+typedef struct {
+ uint8_t item_type;
+ union
+ {
+ btrc_item_player_t player;
+ btrc_item_folder_t folder;
+ btrc_item_media_t media;
+ };
+} btrc_folder_items_t;
+
+typedef struct {
+ uint16_t str_len;
+ uint8_t p_str[BTRC_MAX_ATTR_STR_LEN];
+} btrc_br_folder_name_t;
+
+/** Callback for the controller's supported feautres */
+typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
+ btrc_remote_features_t features);
+
+/** Callback for play status request */
+typedef void (* btrc_get_play_status_callback)(bt_bdaddr_t *bd_addr);
+
+/** Callback for list player application attributes (Shuffle, Repeat,...) */
+typedef void (* btrc_list_player_app_attr_callback)(bt_bdaddr_t *bd_addr);
+
+/** Callback for list player application attributes (Shuffle, Repeat,...) */
+typedef void (* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id,
+ bt_bdaddr_t *bd_addr);
+
+/** Callback for getting the current player application settings value
+** num_attr: specifies the number of attribute ids contained in p_attrs
+*/
+typedef void (* btrc_get_player_app_value_callback) (uint8_t num_attr,
+ btrc_player_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
+
+/** Callback for getting the player application settings attributes' text
+** num_attr: specifies the number of attribute ids contained in p_attrs
+*/
+typedef void (* btrc_get_player_app_attrs_text_callback) (uint8_t num_attr,
+ btrc_player_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
+
+/** Callback for getting the player application settings values' text
+** num_attr: specifies the number of value ids contained in p_vals
+*/
+typedef void (* btrc_get_player_app_values_text_callback) (uint8_t attr_id, uint8_t num_val,
+ uint8_t *p_vals, bt_bdaddr_t *bd_addr);
+
+/** Callback for setting the player application settings values */
+typedef void (* btrc_set_player_app_value_callback) (btrc_player_settings_t *p_vals,
+ bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch the get element attributes of the current song
+** num_attr: specifies the number of attributes requested in p_attrs
+*/
+typedef void (* btrc_get_element_attr_callback) (uint8_t num_attr, btrc_media_attr_t *p_attrs,
+ bt_bdaddr_t *bd_addr);
+
+/** Callback for register notification (Play state change/track change/...)
+** param: Is only valid if event_id is BTRC_EVT_PLAY_POS_CHANGED
+*/
+typedef void (* btrc_register_notification_callback) (btrc_event_id_t event_id, uint32_t param,
+ bt_bdaddr_t *bd_addr);
+
+/* AVRCP 1.4 Enhancements */
+/** Callback for volume change on CT
+** volume: Current volume setting on the CT (0-127)
+*/
+typedef void (* btrc_volume_change_callback) (uint8_t volume, uint8_t ctype, bt_bdaddr_t *bd_addr);
+
+/** Callback for passthrough commands */
+typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state, bt_bdaddr_t *bd_addr);
+
+/** Callback for set addressed player response on TG **/
+typedef void (* btrc_set_addressed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for set browsed player response on TG **/
+typedef void (* btrc_set_browsed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for get folder items on TG
+** num_attr: specifies the number of attributes requested in p_attr_ids
+*/
+typedef void (* btrc_get_folder_items_callback) (uint8_t scope, uint32_t start_item,
+ uint32_t end_item, uint8_t num_attr, uint32_t *p_attr_ids, bt_bdaddr_t *bd_addr);
+
+/** Callback for changing browsed path on TG **/
+typedef void (* btrc_change_path_callback) (uint8_t direction,
+ uint8_t* folder_uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch the get item attributes of the media item
+** num_attr: specifies the number of attributes requested in p_attrs
+*/
+typedef void (* btrc_get_item_attr_callback) (uint8_t scope, uint8_t* uid, uint16_t uid_counter,
+ uint8_t num_attr, btrc_media_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
+
+/** Callback for play request for the media item indicated by an identifier */
+typedef void (* btrc_play_item_callback) (uint8_t scope,
+ uint16_t uid_counter, uint8_t* uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch total number of items from a folder **/
+typedef void (* btrc_get_total_num_of_items_callback) (uint8_t scope, bt_bdaddr_t *bd_addr);
+
+/** Callback for conducting recursive search on a current browsed path for a specified string */
+typedef void (* btrc_search_callback) (uint16_t charset_id,
+ uint16_t str_len, uint8_t* p_str, bt_bdaddr_t *bd_addr);
+
+/** Callback to add a specified media item indicated by an identifier to now playing queue. */
+typedef void (* btrc_add_to_now_playing_callback) (uint8_t scope,
+ uint8_t* uid, uint16_t uid_counter, bt_bdaddr_t *bd_addr);
+
+/** Callback for set addressed player response on TG **/
+typedef void (* btrc_set_addressed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for set browsed player response on TG **/
+typedef void (* btrc_set_browsed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for get folder items on TG
+** num_attr: specifies the number of attributes requested in p_attr_ids
+*/
+typedef void (* btrc_get_folder_items_callback) (uint8_t scope, uint32_t start_item,
+ uint32_t end_item, uint8_t num_attr, uint32_t *p_attr_ids, bt_bdaddr_t *bd_addr);
+
+/** Callback for changing browsed path on TG **/
+typedef void (* btrc_change_path_callback) (uint8_t direction,
+ uint8_t* folder_uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch the get item attributes of the media item
+** num_attr: specifies the number of attributes requested in p_attrs
+*/
+typedef void (* btrc_get_item_attr_callback) (uint8_t scope, uint8_t* uid, uint16_t uid_counter,
+ uint8_t num_attr, btrc_media_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
+
+/** Callback for play request for the media item indicated by an identifier */
+typedef void (* btrc_play_item_callback) (uint8_t scope,
+ uint16_t uid_counter, uint8_t* uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch total number of items from a folder **/
+typedef void (* btrc_get_total_num_of_items_callback) (uint8_t scope, bt_bdaddr_t *bd_addr);
+
+/** Callback for conducting recursive search on a current browsed path for a specified string */
+typedef void (* btrc_search_callback) (uint16_t charset_id,
+ uint16_t str_len, uint8_t* p_str, bt_bdaddr_t *bd_addr);
+
+/** Callback to add a specified media item indicated by an identifier to now playing queue. */
+typedef void (* btrc_add_to_now_playing_callback) (uint8_t scope,
+ uint8_t* uid, uint16_t uid_counter, bt_bdaddr_t *bd_addr);
+
+/** Callback for set addressed player response on TG **/
+typedef void (* btrc_set_addressed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for set browsed player response on TG **/
+typedef void (* btrc_set_browsed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for get folder items on TG
+** num_attr: specifies the number of attributes requested in p_attr_ids
+*/
+typedef void (* btrc_get_folder_items_callback) (uint8_t scope, uint32_t start_item,
+ uint32_t end_item, uint8_t num_attr, uint32_t *p_attr_ids, bt_bdaddr_t *bd_addr);
+
+/** Callback for changing browsed path on TG **/
+typedef void (* btrc_change_path_callback) (uint8_t direction,
+ uint8_t* folder_uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch the get item attributes of the media item
+** num_attr: specifies the number of attributes requested in p_attrs
+*/
+typedef void (* btrc_get_item_attr_callback) (uint8_t scope, uint8_t* uid, uint16_t uid_counter,
+ uint8_t num_attr, btrc_media_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
+
+/** Callback for play request for the media item indicated by an identifier */
+typedef void (* btrc_play_item_callback) (uint8_t scope,
+ uint16_t uid_counter, uint8_t* uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch total number of items from a folder **/
+typedef void (* btrc_get_total_num_of_items_callback) (uint8_t scope, bt_bdaddr_t *bd_addr);
+
+/** Callback for conducting recursive search on a current browsed path for a specified string */
+typedef void (* btrc_search_callback) (uint16_t charset_id,
+ uint16_t str_len, uint8_t* p_str, bt_bdaddr_t *bd_addr);
+
+/** Callback to add a specified media item indicated by an identifier to now playing queue. */
+typedef void (* btrc_add_to_now_playing_callback) (uint8_t scope,
+ uint8_t* uid, uint16_t uid_counter, bt_bdaddr_t *bd_addr);
+
+/** BT-RC Target callback structure. */
+typedef struct {
+ /** set to sizeof(BtRcCallbacks) */
+ size_t size;
+ btrc_remote_features_callback remote_features_cb;
+ btrc_get_play_status_callback get_play_status_cb;
+ btrc_list_player_app_attr_callback list_player_app_attr_cb;
+ btrc_list_player_app_values_callback list_player_app_values_cb;
+ btrc_get_player_app_value_callback get_player_app_value_cb;
+ btrc_get_player_app_attrs_text_callback get_player_app_attrs_text_cb;
+ btrc_get_player_app_values_text_callback get_player_app_values_text_cb;
+ btrc_set_player_app_value_callback set_player_app_value_cb;
+ btrc_get_element_attr_callback get_element_attr_cb;
+ btrc_register_notification_callback register_notification_cb;
+ btrc_volume_change_callback volume_change_cb;
+ btrc_passthrough_cmd_callback passthrough_cmd_cb;
+ btrc_set_addressed_player_callback set_addressed_player_cb;
+ btrc_set_browsed_player_callback set_browsed_player_cb;
+ btrc_get_folder_items_callback get_folder_items_cb;
+ btrc_change_path_callback change_path_cb;
+ btrc_get_item_attr_callback get_item_attr_cb;
+ btrc_play_item_callback play_item_cb;
+ btrc_get_total_num_of_items_callback get_total_num_of_items_cb;
+ btrc_search_callback search_cb;
+ btrc_add_to_now_playing_callback add_to_now_playing_cb;
+} btrc_callbacks_t;
+
+/** Represents the standard BT-RC AVRCP Target interface. */
+typedef struct {
+
+ /** set to sizeof(BtRcInterface) */
+ size_t size;
+ /**
+ * Register the BtRc callbacks
+ */
+ bt_status_t (*init)( btrc_callbacks_t* callbacks );
+
+ /** Respose to GetPlayStatus request. Contains the current
+ ** 1. Play status
+ ** 2. Song duration/length
+ ** 3. Song position
+ */
+ bt_status_t (*get_play_status_rsp)( bt_bdaddr_t *bd_addr, btrc_play_status_t play_status,
+ uint32_t song_len, uint32_t song_pos);
+
+ /** Lists the support player application attributes (Shuffle/Repeat/...)
+ ** num_attr: Specifies the number of attributes contained in the pointer p_attrs
+ */
+ bt_status_t (*list_player_app_attr_rsp)( bt_bdaddr_t *bd_addr, int num_attr,
+ btrc_player_attr_t *p_attrs);
+
+ /** Lists the support player application attributes (Shuffle Off/On/Group)
+ ** num_val: Specifies the number of values contained in the pointer p_vals
+ */
+ bt_status_t (*list_player_app_value_rsp)( bt_bdaddr_t *bd_addr, int num_val, uint8_t *p_vals);
+
+ /** Returns the current application attribute values for each of the specified attr_id */
+ bt_status_t (*get_player_app_value_rsp)( bt_bdaddr_t *bd_addr, btrc_player_settings_t *p_vals);
+
+ /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
+ ** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
+ */
+ bt_status_t (*get_player_app_attr_text_rsp)( bt_bdaddr_t *bd_addr, int num_attr,
+ btrc_player_setting_text_t *p_attrs);
+
+ /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
+ ** num_attr: Specifies the number of attribute values' text contained in the pointer p_vals
+ */
+ bt_status_t (*get_player_app_value_text_rsp)( bt_bdaddr_t *bd_addr, int num_val,
+ btrc_player_setting_text_t *p_vals);
+
+ /** Returns the current songs' element attributes text ("Title"/"Album"/"Artist")
+ ** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
+ */
+ bt_status_t (*get_element_attr_rsp)( bt_bdaddr_t *bd_addr, uint8_t num_attr,
+ btrc_element_attr_val_t *p_attrs);
+
+ /** Response to set player attribute request ("Shuffle"/"Repeat")
+ ** rsp_status: Status of setting the player attributes for the current media player
+ */
+ bt_status_t (*set_player_app_value_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
+
+ /* Response to the register notification request (Play state change/track change/...).
+ ** event_id: Refers to the event_id this notification change corresponds too
+ ** type: Response type - interim/changed
+ ** p_params: Based on the event_id, this parameter should be populated
+ */
+ bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,
+ btrc_notification_type_t type,
+ btrc_register_notification_t *p_param);
+
+ /* AVRCP 1.4 enhancements */
+
+ /**Send current volume setting to remote side. Support limited to SetAbsoluteVolume
+ ** This can be enhanced to support Relative Volume (AVRCP 1.0).
+ ** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN opposed to absolute volume level
+ ** volume: Should be in the range 0-127. bit7 is reseved and cannot be set
+ */
+ bt_status_t (*set_volume)(uint8_t volume);
+
+ /* Set addressed player response from TG to CT */
+ bt_status_t (*set_addressed_player_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
+
+ /* Set browsed player response from TG to CT */
+ bt_status_t (*set_browsed_player_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+ uint32_t num_items, uint16_t charset_id, uint8_t folder_depth,
+ btrc_br_folder_name_t *p_folders);
+
+ /* Get folder item list response from TG to CT */
+ bt_status_t (*get_folder_items_list_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+ uint16_t uid_counter, uint8_t num_items, btrc_folder_items_t *p_items);
+
+ /* Change path response from TG to CT */
+ bt_status_t (*change_path_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+ uint32_t num_items);
+
+ /** Returns the element's attributes num_attr: Specifies the number of attributes' text
+ * contained in the pointer p_attrs
+ */
+ bt_status_t (*get_item_attr_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+ uint8_t num_attr, btrc_element_attr_val_t *p_attrs);
+
+ /* play media item response from TG to CT */
+ bt_status_t (*play_item_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
+
+ /* get total number of items response from TG to CT*/
+ bt_status_t (*get_total_num_of_items_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+ uint32_t uid_counter, uint32_t num_items);
+
+ /* Search VFS response from TG to CT */
+ bt_status_t (*search_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status, uint32_t uid_counter,
+ uint32_t num_items);
+
+ /* add_to_now playing list response from TG to CT */
+ bt_status_t (*add_to_now_playing_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
+
+ /** Closes the interface. */
+ void (*cleanup)( void );
+} btrc_interface_t;
+
+typedef void (* btrc_passthrough_rsp_callback) (bt_bdaddr_t *bd_addr, int id, int key_state);
+
+typedef void (* btrc_groupnavigation_rsp_callback) (int id, int key_state);
+
+typedef void (* btrc_connection_state_callback) (
+ bool rc_connect, bool bt_connect, bt_bdaddr_t *bd_addr);
+
+typedef void (* btrc_ctrl_getrcfeatures_callback) (bt_bdaddr_t *bd_addr, int features);
+
+typedef void (* btrc_ctrl_setabsvol_cmd_callback) (bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label);
+
+typedef void (* btrc_ctrl_registernotification_abs_vol_callback) (bt_bdaddr_t *bd_addr, uint8_t label);
+
+typedef void (* btrc_ctrl_setplayerapplicationsetting_rsp_callback) (bt_bdaddr_t *bd_addr,
+ uint8_t accepted);
+
+typedef void (* btrc_ctrl_playerapplicationsetting_callback)(bt_bdaddr_t *bd_addr,
+ uint8_t num_attr,
+ btrc_player_app_attr_t *app_attrs,
+ uint8_t num_ext_attr,
+ btrc_player_app_ext_attr_t *ext_attrs);
+
+typedef void (* btrc_ctrl_playerapplicationsetting_changed_callback)(bt_bdaddr_t *bd_addr,
+ btrc_player_settings_t *p_vals);
+
+typedef void (* btrc_ctrl_track_changed_callback)(bt_bdaddr_t *bd_addr, uint8_t num_attr,
+ btrc_element_attr_val_t *p_attrs);
+
+typedef void (* btrc_ctrl_play_position_changed_callback)(bt_bdaddr_t *bd_addr,
+ uint32_t song_len, uint32_t song_pos);
+
+typedef void (* btrc_ctrl_play_status_changed_callback)(bt_bdaddr_t *bd_addr,
+ btrc_play_status_t play_status);
+
+typedef void (* btrc_ctrl_get_folder_items_callback )(bt_bdaddr_t *bd_addr,
+ btrc_status_t status,
+ const btrc_folder_items_t *folder_items,
+ uint8_t count);
+
+typedef void (* btrc_ctrl_change_path_callback)(bt_bdaddr_t *bd_addr, uint8_t count);
+
+typedef void (* btrc_ctrl_set_browsed_player_callback )(
+ bt_bdaddr_t *bd_addr, uint8_t num_items, uint8_t depth);
+typedef void (* btrc_ctrl_set_addressed_player_callback)(bt_bdaddr_t *bd_addr, uint8_t status);
+/** BT-RC Controller callback structure. */
+typedef struct {
+ /** set to sizeof(BtRcCallbacks) */
+ size_t size;
+ btrc_passthrough_rsp_callback passthrough_rsp_cb;
+ btrc_groupnavigation_rsp_callback groupnavigation_rsp_cb;
+ btrc_connection_state_callback connection_state_cb;
+ btrc_ctrl_getrcfeatures_callback getrcfeatures_cb;
+ btrc_ctrl_setplayerapplicationsetting_rsp_callback setplayerappsetting_rsp_cb;
+ btrc_ctrl_playerapplicationsetting_callback playerapplicationsetting_cb;
+ btrc_ctrl_playerapplicationsetting_changed_callback playerapplicationsetting_changed_cb;
+ btrc_ctrl_setabsvol_cmd_callback setabsvol_cmd_cb;
+ btrc_ctrl_registernotification_abs_vol_callback registernotification_absvol_cb;
+ btrc_ctrl_track_changed_callback track_changed_cb;
+ btrc_ctrl_play_position_changed_callback play_position_changed_cb;
+ btrc_ctrl_play_status_changed_callback play_status_changed_cb;
+ btrc_ctrl_get_folder_items_callback get_folder_items_cb;
+ btrc_ctrl_change_path_callback change_folder_path_cb;
+ btrc_ctrl_set_browsed_player_callback set_browsed_player_cb;
+ btrc_ctrl_set_addressed_player_callback set_addressed_player_cb;
+} btrc_ctrl_callbacks_t;
+
+/** Represents the standard BT-RC AVRCP Controller interface. */
+typedef struct {
+
+ /** set to sizeof(BtRcInterface) */
+ size_t size;
+ /**
+ * Register the BtRc callbacks
+ */
+ bt_status_t (*init)( btrc_ctrl_callbacks_t* callbacks );
+
+ /** send pass through command to target */
+ bt_status_t (*send_pass_through_cmd) (bt_bdaddr_t *bd_addr, uint8_t key_code,
+ uint8_t key_state );
+
+ /** send group navigation command to target */
+ bt_status_t (*send_group_navigation_cmd) (bt_bdaddr_t *bd_addr, uint8_t key_code,
+ uint8_t key_state );
+
+ /** send command to set player applicaiton setting attributes to target */
+ bt_status_t (*set_player_app_setting_cmd) (bt_bdaddr_t *bd_addr, uint8_t num_attrib,
+ uint8_t* attrib_ids, uint8_t* attrib_vals);
+
+ /** send command to play a particular item */
+ bt_status_t (*play_item_cmd) (
+ bt_bdaddr_t *bd_addr, uint8_t scope, uint8_t *uid, uint16_t uid_counter);
+
+ /** get the playback state */
+ bt_status_t (*get_playback_state_cmd) (bt_bdaddr_t *bd_addr);
+
+ /** get the now playing list */
+ bt_status_t (*get_now_playing_list_cmd) (bt_bdaddr_t *bd_addr, uint8_t start, uint8_t items);
+
+ /** get the folder list */
+ bt_status_t (*get_folder_list_cmd) (bt_bdaddr_t *bd_addr, uint8_t start, uint8_t items);
+
+ /** get the folder list */
+ bt_status_t (*get_player_list_cmd) (bt_bdaddr_t *bd_addr, uint8_t start, uint8_t items);
+
+ /** get the folder list */
+ bt_status_t (*change_folder_path_cmd) (bt_bdaddr_t *bd_addr, uint8_t direction, uint8_t * uid);
+
+ /** set browsed player */
+ bt_status_t (*set_browsed_player_cmd) (bt_bdaddr_t *bd_addr, uint16_t player_id);
+
+ /** set addressed player */
+ bt_status_t (*set_addressed_player_cmd) (bt_bdaddr_t *bd_addr, uint16_t player_id);
+
+ /** send rsp to set_abs_vol received from target */
+ bt_status_t (*set_volume_rsp) (bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label);
+
+ /** send notificaiton rsp for abs vol to target */
+ bt_status_t (*register_abs_vol_rsp) (bt_bdaddr_t *bd_addr, btrc_notification_type_t rsp_type,
+ uint8_t abs_vol, uint8_t label);
+
+ /** Closes the interface. */
+ void (*cleanup)( void );
+} btrc_ctrl_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_RC_H */
diff --git a/libhardware/include/hardware/bt_sdp.h b/libhardware/include/hardware/bt_sdp.h
new file mode 100644
index 0000000..8f39bc5
--- /dev/null
+++ b/libhardware/include/hardware/bt_sdp.h
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "bluetooth.h"
+
+#define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15
+
+__BEGIN_DECLS
+
+/**
+ * These events are handled by the state machine
+ */
+typedef enum {
+ SDP_TYPE_RAW, // Used to carry raw SDP search data for unknown UUIDs
+ SDP_TYPE_MAP_MAS, // Message Access Profile - Server
+ SDP_TYPE_MAP_MNS, // Message Access Profile - Client (Notification Server)
+ SDP_TYPE_PBAP_PSE, // Phone Book Profile - Server
+ SDP_TYPE_PBAP_PCE, // Phone Book Profile - Client
+ SDP_TYPE_OPP_SERVER, // Object Push Profile
+ SDP_TYPE_SAP_SERVER // SIM Access Profile
+} bluetooth_sdp_types;
+
+typedef struct _bluetooth_sdp_hdr {
+ bluetooth_sdp_types type;
+ bt_uuid_t uuid;
+ uint32_t service_name_length;
+ char *service_name;
+ int32_t rfcomm_channel_number;
+ int32_t l2cap_psm;
+ int32_t profile_version;
+} bluetooth_sdp_hdr;
+
+/**
+ * Some signals need additional pointers, hence we introduce a
+ * generic way to handle these pointers.
+ */
+typedef struct _bluetooth_sdp_hdr_overlay {
+ bluetooth_sdp_types type;
+ bt_uuid_t uuid;
+ uint32_t service_name_length;
+ char *service_name;
+ int32_t rfcomm_channel_number;
+ int32_t l2cap_psm;
+ int32_t profile_version;
+
+ // User pointers, only used for some signals - see bluetooth_sdp_ops_record
+ int user1_ptr_len;
+ uint8_t *user1_ptr;
+ int user2_ptr_len;
+ uint8_t *user2_ptr;
+} bluetooth_sdp_hdr_overlay;
+
+typedef struct _bluetooth_sdp_mas_record {
+ bluetooth_sdp_hdr_overlay hdr;
+ uint32_t mas_instance_id;
+ uint32_t supported_features;
+ uint32_t supported_message_types;
+} bluetooth_sdp_mas_record;
+
+typedef struct _bluetooth_sdp_mns_record {
+ bluetooth_sdp_hdr_overlay hdr;
+ uint32_t supported_features;
+} bluetooth_sdp_mns_record;
+
+typedef struct _bluetooth_sdp_pse_record {
+ bluetooth_sdp_hdr_overlay hdr;
+ uint32_t supported_features;
+ uint32_t supported_repositories;
+} bluetooth_sdp_pse_record;
+
+typedef struct _bluetooth_sdp_pce_record {
+ bluetooth_sdp_hdr_overlay hdr;
+} bluetooth_sdp_pce_record;
+
+typedef struct _bluetooth_sdp_ops_record {
+ bluetooth_sdp_hdr_overlay hdr;
+ int supported_formats_list_len;
+ uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH];
+} bluetooth_sdp_ops_record;
+
+typedef struct _bluetooth_sdp_sap_record {
+ bluetooth_sdp_hdr_overlay hdr;
+} bluetooth_sdp_sap_record;
+
+typedef union {
+ bluetooth_sdp_hdr_overlay hdr;
+ bluetooth_sdp_mas_record mas;
+ bluetooth_sdp_mns_record mns;
+ bluetooth_sdp_pse_record pse;
+ bluetooth_sdp_pce_record pce;
+ bluetooth_sdp_ops_record ops;
+ bluetooth_sdp_sap_record sap;
+} bluetooth_sdp_record;
+
+
+/** Callback for SDP search */
+typedef void (*btsdp_search_callback)(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
+
+typedef struct {
+ /** Set to sizeof(btsdp_callbacks_t) */
+ size_t size;
+ btsdp_search_callback sdp_search_cb;
+} btsdp_callbacks_t;
+
+typedef struct {
+ /** Set to size of this struct */
+ size_t size;
+
+ /** Register BT SDP search callbacks */
+ bt_status_t (*init)(btsdp_callbacks_t *callbacks);
+
+ /** Unregister BT SDP */
+ bt_status_t (*deinit)();
+
+ /** Search for SDP records with specific uuid on remote device */
+ bt_status_t (*sdp_search)(bt_bdaddr_t *bd_addr, const uint8_t* uuid);
+
+ /**
+ * Use listen in the socket interface to create rfcomm and/or l2cap PSM channels,
+ * (without UUID and service_name and set the BTSOCK_FLAG_NO_SDP flag in flags).
+ * Then use createSdpRecord to create the SDP record associated with the rfcomm/l2cap channels.
+ *
+ * Returns a handle to the SDP record, which can be parsed to remove_sdp_record.
+ *
+ * record (in) The SDP record to create
+ * record_handle (out)The corresponding record handle will be written to this pointer.
+ */
+ bt_status_t (*create_sdp_record)(bluetooth_sdp_record *record, int* record_handle);
+
+ /** Remove a SDP record created by createSdpRecord */
+ bt_status_t (*remove_sdp_record)(int sdp_handle);
+} btsdp_interface_t;
+
+__END_DECLS
+
diff --git a/libhardware/include/hardware/bt_sock.h b/libhardware/include/hardware/bt_sock.h
new file mode 100644
index 0000000..8d1a9e0
--- /dev/null
+++ b/libhardware/include/hardware/bt_sock.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+__BEGIN_DECLS
+
+#define BTSOCK_FLAG_ENCRYPT 1
+#define BTSOCK_FLAG_AUTH (1 << 1)
+#define BTSOCK_FLAG_NO_SDP (1 << 2)
+#define BTSOCK_FLAG_AUTH_MITM (1 << 3)
+#define BTSOCK_FLAG_AUTH_16_DIGIT (1 << 4)
+
+typedef enum {
+ BTSOCK_RFCOMM = 1,
+ BTSOCK_SCO = 2,
+ BTSOCK_L2CAP = 3
+} btsock_type_t;
+
+/** Represents the standard BT SOCKET interface. */
+typedef struct {
+ short size;
+ bt_bdaddr_t bd_addr;
+ int channel;
+ int status;
+
+ // The writer must make writes using a buffer of this maximum size
+ // to avoid loosing data. (L2CAP only)
+ unsigned short max_tx_packet_size;
+
+ // The reader must read using a buffer of at least this size to avoid
+ // loosing data. (L2CAP only)
+ unsigned short max_rx_packet_size;
+} __attribute__((packed)) sock_connect_signal_t;
+
+typedef struct {
+ /** set to size of this struct*/
+ size_t size;
+
+ /**
+ * Listen to a RFCOMM UUID or channel. It returns the socket fd from which
+ * btsock_connect_signal can be read out when a remote device connected.
+ * If neither a UUID nor a channel is provided, a channel will be allocated
+ * and a service record can be created providing the channel number to
+ * create_sdp_record(...) in bt_sdp.
+ * The callingUid is the UID of the application which is requesting the socket. This is
+ * used for traffic accounting purposes.
+ */
+ bt_status_t (*listen)(btsock_type_t type, const char* service_name,
+ const uint8_t* service_uuid, int channel, int* sock_fd, int flags, int callingUid);
+
+ /**
+ * Connect to a RFCOMM UUID channel of remote device, It returns the socket fd from which
+ * the btsock_connect_signal and a new socket fd to be accepted can be read out when connected.
+ * The callingUid is the UID of the application which is requesting the socket. This is
+ * used for traffic accounting purposes.
+ */
+ bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t* uuid,
+ int channel, int* sock_fd, int flags, int callingUid);
+} btsock_interface_t;
+
+__END_DECLS
+
diff --git a/libhardware/include/hardware/camera.h b/libhardware/include/hardware/camera.h
new file mode 100644
index 0000000..b1f18ff
--- /dev/null
+++ b/libhardware/include/hardware/camera.h
@@ -0,0 +1,298 @@
+/*
+ * Copyright (C) 2010-2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_CAMERA_H
+#define ANDROID_INCLUDE_CAMERA_H
+
+#include "camera_common.h"
+
+/**
+ * Camera device HAL, initial version [ CAMERA_DEVICE_API_VERSION_1_0 ]
+ *
+ * DEPRECATED. New devices should use Camera HAL v3.2 or newer.
+ *
+ * Supports the android.hardware.Camera API, and the android.hardware.camera2
+ * API in legacy mode only.
+ *
+ * Camera devices that support this version of the HAL must return a value in
+ * the range HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF) in
+ * camera_device_t.common.version. CAMERA_DEVICE_API_VERSION_1_0 is the
+ * recommended value.
+ *
+ * Camera modules that implement version 2.0 or higher of camera_module_t must
+ * also return the value of camera_device_t.common.version in
+ * camera_info_t.device_version.
+ *
+ * See camera_common.h for more details.
+ */
+
+__BEGIN_DECLS
+
+struct camera_memory;
+typedef void (*camera_release_memory)(struct camera_memory *mem);
+
+typedef struct camera_memory {
+ void *data;
+ size_t size;
+ void *handle;
+ camera_release_memory release;
+} camera_memory_t;
+
+typedef camera_memory_t* (*camera_request_memory)(int fd, size_t buf_size, unsigned int num_bufs,
+ void *user);
+
+typedef void (*camera_notify_callback)(int32_t msg_type,
+ int32_t ext1,
+ int32_t ext2,
+ void *user);
+
+typedef void (*camera_data_callback)(int32_t msg_type,
+ const camera_memory_t *data, unsigned int index,
+ camera_frame_metadata_t *metadata, void *user);
+
+typedef void (*camera_data_timestamp_callback)(int64_t timestamp,
+ int32_t msg_type,
+ const camera_memory_t *data, unsigned int index,
+ void *user);
+
+#define HAL_CAMERA_PREVIEW_WINDOW_TAG 0xcafed00d
+
+typedef struct preview_stream_ops {
+ int (*dequeue_buffer)(struct preview_stream_ops* w,
+ buffer_handle_t** buffer, int *stride);
+ int (*enqueue_buffer)(struct preview_stream_ops* w,
+ buffer_handle_t* buffer);
+ int (*cancel_buffer)(struct preview_stream_ops* w,
+ buffer_handle_t* buffer);
+ int (*set_buffer_count)(struct preview_stream_ops* w, int count);
+ int (*set_buffers_geometry)(struct preview_stream_ops* pw,
+ int w, int h, int format);
+ int (*set_crop)(struct preview_stream_ops *w,
+ int left, int top, int right, int bottom);
+ int (*set_usage)(struct preview_stream_ops* w, int usage);
+ int (*set_swap_interval)(struct preview_stream_ops *w, int interval);
+ int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w,
+ int *count);
+ int (*lock_buffer)(struct preview_stream_ops* w,
+ buffer_handle_t* buffer);
+ // Timestamps are measured in nanoseconds, and must be comparable
+ // and monotonically increasing between two frames in the same
+ // preview stream. They do not need to be comparable between
+ // consecutive or parallel preview streams, cameras, or app runs.
+ int (*set_timestamp)(struct preview_stream_ops *w, int64_t timestamp);
+} preview_stream_ops_t;
+
+struct camera_device;
+typedef struct camera_device_ops {
+ /** Set the ANativeWindow to which preview frames are sent */
+ int (*set_preview_window)(struct camera_device *,
+ struct preview_stream_ops *window);
+
+ /** Set the notification and data callbacks */
+ void (*set_callbacks)(struct camera_device *,
+ camera_notify_callback notify_cb,
+ camera_data_callback data_cb,
+ camera_data_timestamp_callback data_cb_timestamp,
+ camera_request_memory get_memory,
+ void *user);
+
+ /**
+ * The following three functions all take a msg_type, which is a bitmask of
+ * the messages defined in include/ui/Camera.h
+ */
+
+ /**
+ * Enable a message, or set of messages.
+ */
+ void (*enable_msg_type)(struct camera_device *, int32_t msg_type);
+
+ /**
+ * Disable a message, or a set of messages.
+ *
+ * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera
+ * HAL should not rely on its client to call releaseRecordingFrame() to
+ * release video recording frames sent out by the cameral HAL before and
+ * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL
+ * clients must not modify/access any video recording frame after calling
+ * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
+ */
+ void (*disable_msg_type)(struct camera_device *, int32_t msg_type);
+
+ /**
+ * Query whether a message, or a set of messages, is enabled. Note that
+ * this is operates as an AND, if any of the messages queried are off, this
+ * will return false.
+ */
+ int (*msg_type_enabled)(struct camera_device *, int32_t msg_type);
+
+ /**
+ * Start preview mode.
+ */
+ int (*start_preview)(struct camera_device *);
+
+ /**
+ * Stop a previously started preview.
+ */
+ void (*stop_preview)(struct camera_device *);
+
+ /**
+ * Returns true if preview is enabled.
+ */
+ int (*preview_enabled)(struct camera_device *);
+
+ /**
+ * Request the camera HAL to store meta data or real YUV data in the video
+ * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If
+ * it is not called, the default camera HAL behavior is to store real YUV
+ * data in the video buffers.
+ *
+ * This method should be called before startRecording() in order to be
+ * effective.
+ *
+ * If meta data is stored in the video buffers, it is up to the receiver of
+ * the video buffers to interpret the contents and to find the actual frame
+ * data with the help of the meta data in the buffer. How this is done is
+ * outside of the scope of this method.
+ *
+ * Some camera HALs may not support storing meta data in the video buffers,
+ * but all camera HALs should support storing real YUV data in the video
+ * buffers. If the camera HAL does not support storing the meta data in the
+ * video buffers when it is requested to do do, INVALID_OPERATION must be
+ * returned. It is very useful for the camera HAL to pass meta data rather
+ * than the actual frame data directly to the video encoder, since the
+ * amount of the uncompressed frame data can be very large if video size is
+ * large.
+ *
+ * @param enable if true to instruct the camera HAL to store
+ * meta data in the video buffers; false to instruct
+ * the camera HAL to store real YUV data in the video
+ * buffers.
+ *
+ * @return OK on success.
+ */
+ int (*store_meta_data_in_buffers)(struct camera_device *, int enable);
+
+ /**
+ * Start record mode. When a record image is available, a
+ * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding
+ * frame. Every record frame must be released by a camera HAL client via
+ * releaseRecordingFrame() before the client calls
+ * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
+ * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
+ * responsibility to manage the life-cycle of the video recording frames,
+ * and the client must not modify/access any video recording frames.
+ */
+ int (*start_recording)(struct camera_device *);
+
+ /**
+ * Stop a previously started recording.
+ */
+ void (*stop_recording)(struct camera_device *);
+
+ /**
+ * Returns true if recording is enabled.
+ */
+ int (*recording_enabled)(struct camera_device *);
+
+ /**
+ * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
+ *
+ * It is camera HAL client's responsibility to release video recording
+ * frames sent out by the camera HAL before the camera HAL receives a call
+ * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to
+ * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
+ * responsibility to manage the life-cycle of the video recording frames.
+ */
+ void (*release_recording_frame)(struct camera_device *,
+ const void *opaque);
+
+ /**
+ * Start auto focus, the notification callback routine is called with
+ * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be
+ * called again if another auto focus is needed.
+ */
+ int (*auto_focus)(struct camera_device *);
+
+ /**
+ * Cancels auto-focus function. If the auto-focus is still in progress,
+ * this function will cancel it. Whether the auto-focus is in progress or
+ * not, this function will return the focus position to the default. If
+ * the camera does not support auto-focus, this is a no-op.
+ */
+ int (*cancel_auto_focus)(struct camera_device *);
+
+ /**
+ * Take a picture.
+ */
+ int (*take_picture)(struct camera_device *);
+
+ /**
+ * Cancel a picture that was started with takePicture. Calling this method
+ * when no picture is being taken is a no-op.
+ */
+ int (*cancel_picture)(struct camera_device *);
+
+ /**
+ * Set the camera parameters. This returns BAD_VALUE if any parameter is
+ * invalid or not supported.
+ */
+ int (*set_parameters)(struct camera_device *, const char *parms);
+
+ /** Retrieve the camera parameters. The buffer returned by the camera HAL
+ must be returned back to it with put_parameters, if put_parameters
+ is not NULL.
+ */
+ char *(*get_parameters)(struct camera_device *);
+
+ /** The camera HAL uses its own memory to pass us the parameters when we
+ call get_parameters. Use this function to return the memory back to
+ the camera HAL, if put_parameters is not NULL. If put_parameters
+ is NULL, then you have to use free() to release the memory.
+ */
+ void (*put_parameters)(struct camera_device *, char *);
+
+ /**
+ * Send command to camera driver.
+ */
+ int (*send_command)(struct camera_device *,
+ int32_t cmd, int32_t arg1, int32_t arg2);
+
+ /**
+ * Release the hardware resources owned by this object. Note that this is
+ * *not* done in the destructor.
+ */
+ void (*release)(struct camera_device *);
+
+ /**
+ * Dump state of the camera hardware
+ */
+ int (*dump)(struct camera_device *, int fd);
+} camera_device_ops_t;
+
+typedef struct camera_device {
+ /**
+ * camera_device.common.version must be in the range
+ * HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF). CAMERA_DEVICE_API_VERSION_1_0 is
+ * recommended.
+ */
+ hw_device_t common;
+ camera_device_ops_t *ops;
+ void *priv;
+} camera_device_t;
+
+__END_DECLS
+
+#endif /* #ifdef ANDROID_INCLUDE_CAMERA_H */
diff --git a/libhardware/include/hardware/camera2.h b/libhardware/include/hardware/camera2.h
new file mode 100644
index 0000000..d920d4b
--- /dev/null
+++ b/libhardware/include/hardware/camera2.h
@@ -0,0 +1,839 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_CAMERA2_H
+#define ANDROID_INCLUDE_CAMERA2_H
+
+#include "camera_common.h"
+#include "system/camera_metadata.h"
+
+/**
+ * Camera device HAL 2.1 [ CAMERA_DEVICE_API_VERSION_2_0, CAMERA_DEVICE_API_VERSION_2_1 ]
+ *
+ * DEPRECATED. New devices should use Camera HAL v3.2 or newer.
+ *
+ * Supports the android.hardware.Camera API, and the android.hardware.camera2
+ * API in legacy mode only.
+ *
+ * Camera devices that support this version of the HAL must return
+ * CAMERA_DEVICE_API_VERSION_2_1 in camera_device_t.common.version and in
+ * camera_info_t.device_version (from camera_module_t.get_camera_info).
+ *
+ * Camera modules that may contain version 2.x devices must implement at least
+ * version 2.0 of the camera module interface (as defined by
+ * camera_module_t.common.module_api_version).
+ *
+ * See camera_common.h for more versioning details.
+ *
+ * Version history:
+ *
+ * 2.0: CAMERA_DEVICE_API_VERSION_2_0. Initial release (Android 4.2):
+ * - Sufficient for implementing existing android.hardware.Camera API.
+ * - Allows for ZSL queue in camera service layer
+ * - Not tested for any new features such manual capture control,
+ * Bayer RAW capture, reprocessing of RAW data.
+ *
+ * 2.1: CAMERA_DEVICE_API_VERSION_2_1. Support per-device static metadata:
+ * - Add get_instance_metadata() method to retrieve metadata that is fixed
+ * after device open, but may be variable between open() calls.
+ */
+
+__BEGIN_DECLS
+
+struct camera2_device;
+
+/**********************************************************************
+ *
+ * Input/output stream buffer queue interface definitions
+ *
+ */
+
+/**
+ * Output image stream queue interface. A set of these methods is provided to
+ * the HAL device in allocate_stream(), and are used to interact with the
+ * gralloc buffer queue for that stream. They may not be called until after
+ * allocate_stream returns.
+ */
+typedef struct camera2_stream_ops {
+ /**
+ * Get a buffer to fill from the queue. The size and format of the buffer
+ * are fixed for a given stream (defined in allocate_stream), and the stride
+ * should be queried from the platform gralloc module. The gralloc buffer
+ * will have been allocated based on the usage flags provided by
+ * allocate_stream, and will be locked for use.
+ */
+ int (*dequeue_buffer)(const struct camera2_stream_ops* w,
+ buffer_handle_t** buffer);
+
+ /**
+ * Push a filled buffer to the stream to be used by the consumer.
+ *
+ * The timestamp represents the time at start of exposure of the first row
+ * of the image; it must be from a monotonic clock, and is measured in
+ * nanoseconds. The timestamps do not need to be comparable between
+ * different cameras, or consecutive instances of the same camera. However,
+ * they must be comparable between streams from the same camera. If one
+ * capture produces buffers for multiple streams, each stream must have the
+ * same timestamp for that buffer, and that timestamp must match the
+ * timestamp in the output frame metadata.
+ */
+ int (*enqueue_buffer)(const struct camera2_stream_ops* w,
+ int64_t timestamp,
+ buffer_handle_t* buffer);
+ /**
+ * Return a buffer to the queue without marking it as filled.
+ */
+ int (*cancel_buffer)(const struct camera2_stream_ops* w,
+ buffer_handle_t* buffer);
+ /**
+ * Set the crop window for subsequently enqueued buffers. The parameters are
+ * measured in pixels relative to the buffer width and height.
+ */
+ int (*set_crop)(const struct camera2_stream_ops *w,
+ int left, int top, int right, int bottom);
+
+} camera2_stream_ops_t;
+
+/**
+ * Temporary definition during transition.
+ *
+ * These formats will be removed and replaced with
+ * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED. To maximize forward compatibility,
+ * HAL implementations are strongly recommended to treat FORMAT_OPAQUE and
+ * FORMAT_ZSL as equivalent to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, and
+ * return HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED in the format_actual output
+ * parameter of allocate_stream, allowing the gralloc module to select the
+ * specific format based on the usage flags from the camera and the stream
+ * consumer.
+ */
+enum {
+ CAMERA2_HAL_PIXEL_FORMAT_OPAQUE = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
+ CAMERA2_HAL_PIXEL_FORMAT_ZSL = -1
+};
+
+/**
+ * Transport header for compressed JPEG buffers in output streams.
+ *
+ * To capture JPEG images, a stream is created using the pixel format
+ * HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
+ * used as the buffer size. Since compressed JPEG images are of variable size,
+ * the HAL needs to include the final size of the compressed image using this
+ * structure inside the output stream buffer. The JPEG blob ID field must be set
+ * to CAMERA2_JPEG_BLOB_ID.
+ *
+ * Transport header should be at the end of the JPEG output stream buffer. That
+ * means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
+ * sizeof(camera2_jpeg_blob)]. Any HAL using this transport header must
+ * account for it in android.jpeg.maxSize. The JPEG data itself starts at
+ * byte[0] and should be jpeg_size bytes long.
+ */
+typedef struct camera2_jpeg_blob {
+ uint16_t jpeg_blob_id;
+ uint32_t jpeg_size;
+};
+
+enum {
+ CAMERA2_JPEG_BLOB_ID = 0x00FF
+};
+
+/**
+ * Input reprocess stream queue management. A set of these methods is provided
+ * to the HAL device in allocate_reprocess_stream(); they are used to interact
+ * with the reprocess stream's input gralloc buffer queue.
+ */
+typedef struct camera2_stream_in_ops {
+ /**
+ * Get the next buffer of image data to reprocess. The width, height, and
+ * format of the buffer is fixed in allocate_reprocess_stream(), and the
+ * stride and other details should be queried from the platform gralloc
+ * module as needed. The buffer will already be locked for use.
+ */
+ int (*acquire_buffer)(const struct camera2_stream_in_ops *w,
+ buffer_handle_t** buffer);
+ /**
+ * Return a used buffer to the buffer queue for reuse.
+ */
+ int (*release_buffer)(const struct camera2_stream_in_ops *w,
+ buffer_handle_t* buffer);
+
+} camera2_stream_in_ops_t;
+
+/**********************************************************************
+ *
+ * Metadata queue management, used for requests sent to HAL module, and for
+ * frames produced by the HAL.
+ *
+ */
+
+enum {
+ CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS = -1
+};
+
+/**
+ * Request input queue protocol:
+ *
+ * The framework holds the queue and its contents. At start, the queue is empty.
+ *
+ * 1. When the first metadata buffer is placed into the queue, the framework
+ * signals the device by calling notify_request_queue_not_empty().
+ *
+ * 2. After receiving notify_request_queue_not_empty, the device must call
+ * dequeue() once it's ready to handle the next buffer.
+ *
+ * 3. Once the device has processed a buffer, and is ready for the next buffer,
+ * it must call dequeue() again instead of waiting for a notification. If
+ * there are no more buffers available, dequeue() will return NULL. After
+ * this point, when a buffer becomes available, the framework must call
+ * notify_request_queue_not_empty() again. If the device receives a NULL
+ * return from dequeue, it does not need to query the queue again until a
+ * notify_request_queue_not_empty() call is received from the source.
+ *
+ * 4. If the device calls buffer_count() and receives 0, this does not mean that
+ * the framework will provide a notify_request_queue_not_empty() call. The
+ * framework will only provide such a notification after the device has
+ * received a NULL from dequeue, or on initial startup.
+ *
+ * 5. The dequeue() call in response to notify_request_queue_not_empty() may be
+ * on the same thread as the notify_request_queue_not_empty() call, and may
+ * be performed from within the notify call.
+ *
+ * 6. All dequeued request buffers must be returned to the framework by calling
+ * free_request, including when errors occur, a device flush is requested, or
+ * when the device is shutting down.
+ */
+typedef struct camera2_request_queue_src_ops {
+ /**
+ * Get the count of request buffers pending in the queue. May return
+ * CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS if a repeating request (stream
+ * request) is currently configured. Calling this method has no effect on
+ * whether the notify_request_queue_not_empty() method will be called by the
+ * framework.
+ */
+ int (*request_count)(const struct camera2_request_queue_src_ops *q);
+
+ /**
+ * Get a metadata buffer from the framework. Returns OK if there is no
+ * error. If the queue is empty, returns NULL in buffer. In that case, the
+ * device must wait for a notify_request_queue_not_empty() message before
+ * attempting to dequeue again. Buffers obtained in this way must be
+ * returned to the framework with free_request().
+ */
+ int (*dequeue_request)(const struct camera2_request_queue_src_ops *q,
+ camera_metadata_t **buffer);
+ /**
+ * Return a metadata buffer to the framework once it has been used, or if
+ * an error or shutdown occurs.
+ */
+ int (*free_request)(const struct camera2_request_queue_src_ops *q,
+ camera_metadata_t *old_buffer);
+
+} camera2_request_queue_src_ops_t;
+
+/**
+ * Frame output queue protocol:
+ *
+ * The framework holds the queue and its contents. At start, the queue is empty.
+ *
+ * 1. When the device is ready to fill an output metadata frame, it must dequeue
+ * a metadata buffer of the required size.
+ *
+ * 2. It should then fill the metadata buffer, and place it on the frame queue
+ * using enqueue_frame. The framework takes ownership of the frame.
+ *
+ * 3. In case of an error, a request to flush the pipeline, or shutdown, the
+ * device must return any affected dequeued frames to the framework by
+ * calling cancel_frame.
+ */
+typedef struct camera2_frame_queue_dst_ops {
+ /**
+ * Get an empty metadata buffer to fill from the framework. The new metadata
+ * buffer will have room for entries number of metadata entries, plus
+ * data_bytes worth of extra storage. Frames dequeued here must be returned
+ * to the framework with either cancel_frame or enqueue_frame.
+ */
+ int (*dequeue_frame)(const struct camera2_frame_queue_dst_ops *q,
+ size_t entries, size_t data_bytes,
+ camera_metadata_t **buffer);
+
+ /**
+ * Return a dequeued metadata buffer to the framework for reuse; do not mark it as
+ * filled. Use when encountering errors, or flushing the internal request queue.
+ */
+ int (*cancel_frame)(const struct camera2_frame_queue_dst_ops *q,
+ camera_metadata_t *buffer);
+
+ /**
+ * Place a completed metadata frame on the frame output queue.
+ */
+ int (*enqueue_frame)(const struct camera2_frame_queue_dst_ops *q,
+ camera_metadata_t *buffer);
+
+} camera2_frame_queue_dst_ops_t;
+
+/**********************************************************************
+ *
+ * Notification callback and message definition, and trigger definitions
+ *
+ */
+
+/**
+ * Asynchronous notification callback from the HAL, fired for various
+ * reasons. Only for information independent of frame capture, or that require
+ * specific timing. The user pointer must be the same one that was passed to the
+ * device in set_notify_callback().
+ */
+typedef void (*camera2_notify_callback)(int32_t msg_type,
+ int32_t ext1,
+ int32_t ext2,
+ int32_t ext3,
+ void *user);
+
+/**
+ * Possible message types for camera2_notify_callback
+ */
+enum {
+ /**
+ * An error has occurred. Argument ext1 contains the error code, and
+ * ext2 and ext3 contain any error-specific information.
+ */
+ CAMERA2_MSG_ERROR = 0x0001,
+ /**
+ * The exposure of a given request has begun. Argument ext1 contains the
+ * frame number, and ext2 and ext3 contain the low-order and high-order
+ * bytes of the timestamp for when exposure began.
+ * (timestamp = (ext3 << 32 | ext2))
+ */
+ CAMERA2_MSG_SHUTTER = 0x0010,
+ /**
+ * The autofocus routine has changed state. Argument ext1 contains the new
+ * state; the values are the same as those for the metadata field
+ * android.control.afState. Ext2 contains the latest trigger ID passed to
+ * trigger_action(CAMERA2_TRIGGER_AUTOFOCUS) or
+ * trigger_action(CAMERA2_TRIGGER_CANCEL_AUTOFOCUS), or 0 if trigger has not
+ * been called with either of those actions.
+ */
+ CAMERA2_MSG_AUTOFOCUS = 0x0020,
+ /**
+ * The autoexposure routine has changed state. Argument ext1 contains the
+ * new state; the values are the same as those for the metadata field
+ * android.control.aeState. Ext2 contains the latest trigger ID value passed to
+ * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
+ * has not been called.
+ */
+ CAMERA2_MSG_AUTOEXPOSURE = 0x0021,
+ /**
+ * The auto-whitebalance routine has changed state. Argument ext1 contains
+ * the new state; the values are the same as those for the metadata field
+ * android.control.awbState. Ext2 contains the latest trigger ID passed to
+ * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
+ * has not been called.
+ */
+ CAMERA2_MSG_AUTOWB = 0x0022
+};
+
+/**
+ * Error codes for CAMERA_MSG_ERROR
+ */
+enum {
+ /**
+ * A serious failure occured. Camera device may not work without reboot, and
+ * no further frames or buffer streams will be produced by the
+ * device. Device should be treated as closed.
+ */
+ CAMERA2_MSG_ERROR_HARDWARE = 0x0001,
+ /**
+ * A serious failure occured. No further frames or buffer streams will be
+ * produced by the device. Device should be treated as closed. The client
+ * must reopen the device to use it again.
+ */
+ CAMERA2_MSG_ERROR_DEVICE,
+ /**
+ * An error has occurred in processing a request. No output (metadata or
+ * buffers) will be produced for this request. ext2 contains the frame
+ * number of the request. Subsequent requests are unaffected, and the device
+ * remains operational.
+ */
+ CAMERA2_MSG_ERROR_REQUEST,
+ /**
+ * An error has occurred in producing an output frame metadata buffer for a
+ * request, but image buffers for it will still be available. Subsequent
+ * requests are unaffected, and the device remains operational. ext2
+ * contains the frame number of the request.
+ */
+ CAMERA2_MSG_ERROR_FRAME,
+ /**
+ * An error has occurred in placing an output buffer into a stream for a
+ * request. The frame metadata and other buffers may still be
+ * available. Subsequent requests are unaffected, and the device remains
+ * operational. ext2 contains the frame number of the request, and ext3
+ * contains the stream id.
+ */
+ CAMERA2_MSG_ERROR_STREAM,
+ /**
+ * Number of error types
+ */
+ CAMERA2_MSG_NUM_ERRORS
+};
+
+/**
+ * Possible trigger ids for trigger_action()
+ */
+enum {
+ /**
+ * Trigger an autofocus cycle. The effect of the trigger depends on the
+ * autofocus mode in effect when the trigger is received, which is the mode
+ * listed in the latest capture request to be dequeued by the HAL. If the
+ * mode is OFF, EDOF, or FIXED, the trigger has no effect. In AUTO, MACRO,
+ * or CONTINUOUS_* modes, see below for the expected behavior. The state of
+ * the autofocus cycle can be tracked in android.control.afMode and the
+ * corresponding notifications.
+ *
+ **
+ * In AUTO or MACRO mode, the AF state transitions (and notifications)
+ * when calling with trigger ID = N with the previous ID being K are:
+ *
+ * Initial state Transitions
+ * INACTIVE (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * AF_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * AF_NOT_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * ACTIVE_SCAN (K) -> AF_FOCUSED(N) or AF_NOT_FOCUSED(N)
+ * PASSIVE_SCAN (K) Not used in AUTO/MACRO mode
+ * PASSIVE_FOCUSED (K) Not used in AUTO/MACRO mode
+ *
+ **
+ * In CONTINUOUS_PICTURE mode, triggering AF must lock the AF to the current
+ * lens position and transition the AF state to either AF_FOCUSED or
+ * NOT_FOCUSED. If a passive scan is underway, that scan must complete and
+ * then lock the lens position and change AF state. TRIGGER_CANCEL_AUTOFOCUS
+ * will allow the AF to restart its operation.
+ *
+ * Initial state Transitions
+ * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * PASSIVE_SCAN (K) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * AF_FOCUSED (K) no effect except to change next notification ID to N
+ * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
+ *
+ **
+ * In CONTINUOUS_VIDEO mode, triggering AF must lock the AF to the current
+ * lens position and transition the AF state to either AF_FOCUSED or
+ * NOT_FOCUSED. If a passive scan is underway, it must immediately halt, in
+ * contrast with CONTINUOUS_PICTURE mode. TRIGGER_CANCEL_AUTOFOCUS will
+ * allow the AF to restart its operation.
+ *
+ * Initial state Transitions
+ * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * PASSIVE_SCAN (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
+ * AF_FOCUSED (K) no effect except to change next notification ID to N
+ * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
+ *
+ * Ext1 is an ID that must be returned in subsequent auto-focus state change
+ * notifications through camera2_notify_callback() and stored in
+ * android.control.afTriggerId.
+ */
+ CAMERA2_TRIGGER_AUTOFOCUS = 0x0001,
+ /**
+ * Send a cancel message to the autofocus algorithm. The effect of the
+ * cancellation depends on the autofocus mode in effect when the trigger is
+ * received, which is the mode listed in the latest capture request to be
+ * dequeued by the HAL. If the AF mode is OFF or EDOF, the cancel has no
+ * effect. For other modes, the lens should return to its default position,
+ * any current autofocus scan must be canceled, and the AF state should be
+ * set to INACTIVE.
+ *
+ * The state of the autofocus cycle can be tracked in android.control.afMode
+ * and the corresponding notification. Continuous autofocus modes may resume
+ * focusing operations thereafter exactly as if the camera had just been set
+ * to a continuous AF mode.
+ *
+ * Ext1 is an ID that must be returned in subsequent auto-focus state change
+ * notifications through camera2_notify_callback() and stored in
+ * android.control.afTriggerId.
+ */
+ CAMERA2_TRIGGER_CANCEL_AUTOFOCUS,
+ /**
+ * Trigger a pre-capture metering cycle, which may include firing the flash
+ * to determine proper capture parameters. Typically, this trigger would be
+ * fired for a half-depress of a camera shutter key, or before a snapshot
+ * capture in general. The state of the metering cycle can be tracked in
+ * android.control.aeMode and the corresponding notification. If the
+ * auto-exposure mode is OFF, the trigger does nothing.
+ *
+ * Ext1 is an ID that must be returned in subsequent
+ * auto-exposure/auto-white balance state change notifications through
+ * camera2_notify_callback() and stored in android.control.aePrecaptureId.
+ */
+ CAMERA2_TRIGGER_PRECAPTURE_METERING
+};
+
+/**
+ * Possible template types for construct_default_request()
+ */
+enum {
+ /**
+ * Standard camera preview operation with 3A on auto.
+ */
+ CAMERA2_TEMPLATE_PREVIEW = 1,
+ /**
+ * Standard camera high-quality still capture with 3A and flash on auto.
+ */
+ CAMERA2_TEMPLATE_STILL_CAPTURE,
+ /**
+ * Standard video recording plus preview with 3A on auto, torch off.
+ */
+ CAMERA2_TEMPLATE_VIDEO_RECORD,
+ /**
+ * High-quality still capture while recording video. Application will
+ * include preview, video record, and full-resolution YUV or JPEG streams in
+ * request. Must not cause stuttering on video stream. 3A on auto.
+ */
+ CAMERA2_TEMPLATE_VIDEO_SNAPSHOT,
+ /**
+ * Zero-shutter-lag mode. Application will request preview and
+ * full-resolution data for each frame, and reprocess it to JPEG when a
+ * still image is requested by user. Settings should provide highest-quality
+ * full-resolution images without compromising preview frame rate. 3A on
+ * auto.
+ */
+ CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG,
+
+ /* Total number of templates */
+ CAMERA2_TEMPLATE_COUNT
+};
+
+
+/**********************************************************************
+ *
+ * Camera device operations
+ *
+ */
+typedef struct camera2_device_ops {
+
+ /**********************************************************************
+ * Request and frame queue setup and management methods
+ */
+
+ /**
+ * Pass in input request queue interface methods.
+ */
+ int (*set_request_queue_src_ops)(const struct camera2_device *,
+ const camera2_request_queue_src_ops_t *request_src_ops);
+
+ /**
+ * Notify device that the request queue is no longer empty. Must only be
+ * called when the first buffer is added a new queue, or after the source
+ * has returned NULL in response to a dequeue call.
+ */
+ int (*notify_request_queue_not_empty)(const struct camera2_device *);
+
+ /**
+ * Pass in output frame queue interface methods
+ */
+ int (*set_frame_queue_dst_ops)(const struct camera2_device *,
+ const camera2_frame_queue_dst_ops_t *frame_dst_ops);
+
+ /**
+ * Number of camera requests being processed by the device at the moment
+ * (captures/reprocesses that have had their request dequeued, but have not
+ * yet been enqueued onto output pipeline(s) ). No streams may be released
+ * by the framework until the in-progress count is 0.
+ */
+ int (*get_in_progress_count)(const struct camera2_device *);
+
+ /**
+ * Flush all in-progress captures. This includes all dequeued requests
+ * (regular or reprocessing) that have not yet placed any outputs into a
+ * stream or the frame queue. Partially completed captures must be completed
+ * normally. No new requests may be dequeued from the request queue until
+ * the flush completes.
+ */
+ int (*flush_captures_in_progress)(const struct camera2_device *);
+
+ /**
+ * Create a filled-in default request for standard camera use cases.
+ *
+ * The device must return a complete request that is configured to meet the
+ * requested use case, which must be one of the CAMERA2_TEMPLATE_*
+ * enums. All request control fields must be included, except for
+ * android.request.outputStreams.
+ *
+ * The metadata buffer returned must be allocated with
+ * allocate_camera_metadata. The framework takes ownership of the buffer.
+ */
+ int (*construct_default_request)(const struct camera2_device *,
+ int request_template,
+ camera_metadata_t **request);
+
+ /**********************************************************************
+ * Stream management
+ */
+
+ /**
+ * allocate_stream:
+ *
+ * Allocate a new output stream for use, defined by the output buffer width,
+ * height, target, and possibly the pixel format. Returns the new stream's
+ * ID, gralloc usage flags, minimum queue buffer count, and possibly the
+ * pixel format, on success. Error conditions:
+ *
+ * - Requesting a width/height/format combination not listed as
+ * supported by the sensor's static characteristics
+ *
+ * - Asking for too many streams of a given format type (2 bayer raw
+ * streams, for example).
+ *
+ * Input parameters:
+ *
+ * - width, height, format: Specification for the buffers to be sent through
+ * this stream. Format is a value from the HAL_PIXEL_FORMAT_* list. If
+ * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
+ * gralloc module will select a format based on the usage flags provided
+ * by the camera HAL and the consumer of the stream. The camera HAL should
+ * inspect the buffers handed to it in the register_stream_buffers call to
+ * obtain the implementation-specific format if necessary.
+ *
+ * - stream_ops: A structure of function pointers for obtaining and queuing
+ * up buffers for this stream. The underlying stream will be configured
+ * based on the usage and max_buffers outputs. The methods in this
+ * structure may not be called until after allocate_stream returns.
+ *
+ * Output parameters:
+ *
+ * - stream_id: An unsigned integer identifying this stream. This value is
+ * used in incoming requests to identify the stream, and in releasing the
+ * stream.
+ *
+ * - usage: The gralloc usage mask needed by the HAL device for producing
+ * the requested type of data. This is used in allocating new gralloc
+ * buffers for the stream buffer queue.
+ *
+ * - max_buffers: The maximum number of buffers the HAL device may need to
+ * have dequeued at the same time. The device may not dequeue more buffers
+ * than this value at the same time.
+ *
+ */
+ int (*allocate_stream)(
+ const struct camera2_device *,
+ // inputs
+ uint32_t width,
+ uint32_t height,
+ int format,
+ const camera2_stream_ops_t *stream_ops,
+ // outputs
+ uint32_t *stream_id,
+ uint32_t *format_actual, // IGNORED, will be removed
+ uint32_t *usage,
+ uint32_t *max_buffers);
+
+ /**
+ * Register buffers for a given stream. This is called after a successful
+ * allocate_stream call, and before the first request referencing the stream
+ * is enqueued. This method is intended to allow the HAL device to map or
+ * otherwise prepare the buffers for later use. num_buffers is guaranteed to
+ * be at least max_buffers (from allocate_stream), but may be larger. The
+ * buffers will already be locked for use. At the end of the call, all the
+ * buffers must be ready to be returned to the queue. If the stream format
+ * was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL should
+ * inspect the passed-in buffers here to determine any platform-private
+ * pixel format information.
+ */
+ int (*register_stream_buffers)(
+ const struct camera2_device *,
+ uint32_t stream_id,
+ int num_buffers,
+ buffer_handle_t *buffers);
+
+ /**
+ * Release a stream. Returns an error if called when get_in_progress_count
+ * is non-zero, or if the stream id is invalid.
+ */
+ int (*release_stream)(
+ const struct camera2_device *,
+ uint32_t stream_id);
+
+ /**
+ * allocate_reprocess_stream:
+ *
+ * Allocate a new input stream for use, defined by the output buffer width,
+ * height, and the pixel format. Returns the new stream's ID, gralloc usage
+ * flags, and required simultaneously acquirable buffer count, on
+ * success. Error conditions:
+ *
+ * - Requesting a width/height/format combination not listed as
+ * supported by the sensor's static characteristics
+ *
+ * - Asking for too many reprocessing streams to be configured at once.
+ *
+ * Input parameters:
+ *
+ * - width, height, format: Specification for the buffers to be sent through
+ * this stream. Format must be a value from the HAL_PIXEL_FORMAT_* list.
+ *
+ * - reprocess_stream_ops: A structure of function pointers for acquiring
+ * and releasing buffers for this stream. The underlying stream will be
+ * configured based on the usage and max_buffers outputs.
+ *
+ * Output parameters:
+ *
+ * - stream_id: An unsigned integer identifying this stream. This value is
+ * used in incoming requests to identify the stream, and in releasing the
+ * stream. These ids are numbered separately from the input stream ids.
+ *
+ * - consumer_usage: The gralloc usage mask needed by the HAL device for
+ * consuming the requested type of data. This is used in allocating new
+ * gralloc buffers for the stream buffer queue.
+ *
+ * - max_buffers: The maximum number of buffers the HAL device may need to
+ * have acquired at the same time. The device may not have more buffers
+ * acquired at the same time than this value.
+ *
+ */
+ int (*allocate_reprocess_stream)(const struct camera2_device *,
+ uint32_t width,
+ uint32_t height,
+ uint32_t format,
+ const camera2_stream_in_ops_t *reprocess_stream_ops,
+ // outputs
+ uint32_t *stream_id,
+ uint32_t *consumer_usage,
+ uint32_t *max_buffers);
+
+ /**
+ * allocate_reprocess_stream_from_stream:
+ *
+ * Allocate a new input stream for use, which will use the buffers allocated
+ * for an existing output stream. That is, after the HAL enqueues a buffer
+ * onto the output stream, it may see that same buffer handed to it from
+ * this input reprocessing stream. After the HAL releases the buffer back to
+ * the reprocessing stream, it will be returned to the output queue for
+ * reuse.
+ *
+ * Error conditions:
+ *
+ * - Using an output stream of unsuitable size/format for the basis of the
+ * reprocessing stream.
+ *
+ * - Attempting to allocatee too many reprocessing streams at once.
+ *
+ * Input parameters:
+ *
+ * - output_stream_id: The ID of an existing output stream which has
+ * a size and format suitable for reprocessing.
+ *
+ * - reprocess_stream_ops: A structure of function pointers for acquiring
+ * and releasing buffers for this stream. The underlying stream will use
+ * the same graphics buffer handles as the output stream uses.
+ *
+ * Output parameters:
+ *
+ * - stream_id: An unsigned integer identifying this stream. This value is
+ * used in incoming requests to identify the stream, and in releasing the
+ * stream. These ids are numbered separately from the input stream ids.
+ *
+ * The HAL client must always release the reprocessing stream before it
+ * releases the output stream it is based on.
+ *
+ */
+ int (*allocate_reprocess_stream_from_stream)(const struct camera2_device *,
+ uint32_t output_stream_id,
+ const camera2_stream_in_ops_t *reprocess_stream_ops,
+ // outputs
+ uint32_t *stream_id);
+
+ /**
+ * Release a reprocessing stream. Returns an error if called when
+ * get_in_progress_count is non-zero, or if the stream id is not
+ * valid.
+ */
+ int (*release_reprocess_stream)(
+ const struct camera2_device *,
+ uint32_t stream_id);
+
+ /**********************************************************************
+ * Miscellaneous methods
+ */
+
+ /**
+ * Trigger asynchronous activity. This is used for triggering special
+ * behaviors of the camera 3A routines when they are in use. See the
+ * documentation for CAMERA2_TRIGGER_* above for details of the trigger ids
+ * and their arguments.
+ */
+ int (*trigger_action)(const struct camera2_device *,
+ uint32_t trigger_id,
+ int32_t ext1,
+ int32_t ext2);
+
+ /**
+ * Notification callback setup
+ */
+ int (*set_notify_callback)(const struct camera2_device *,
+ camera2_notify_callback notify_cb,
+ void *user);
+
+ /**
+ * Get methods to query for vendor extension metadata tag infomation. May
+ * set ops to NULL if no vendor extension tags are defined.
+ */
+ int (*get_metadata_vendor_tag_ops)(const struct camera2_device*,
+ vendor_tag_query_ops_t **ops);
+
+ /**
+ * Dump state of the camera hardware
+ */
+ int (*dump)(const struct camera2_device *, int fd);
+
+ /**
+ * Get device-instance-specific metadata. This metadata must be constant for
+ * a single instance of the camera device, but may be different between
+ * open() calls. The returned camera_metadata pointer must be valid until
+ * the device close() method is called.
+ *
+ * Version information:
+ *
+ * CAMERA_DEVICE_API_VERSION_2_0:
+ *
+ * Not available. Framework may not access this function pointer.
+ *
+ * CAMERA_DEVICE_API_VERSION_2_1:
+ *
+ * Valid. Can be called by the framework.
+ *
+ */
+ int (*get_instance_metadata)(const struct camera2_device *,
+ camera_metadata **instance_metadata);
+
+} camera2_device_ops_t;
+
+/**********************************************************************
+ *
+ * Camera device definition
+ *
+ */
+typedef struct camera2_device {
+ /**
+ * common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
+ * this device as implementing version 2.0 of the camera device HAL.
+ */
+ hw_device_t common;
+ camera2_device_ops_t *ops;
+ void *priv;
+} camera2_device_t;
+
+__END_DECLS
+
+#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */
diff --git a/libhardware/include/hardware/camera3.h b/libhardware/include/hardware/camera3.h
new file mode 100644
index 0000000..3ef6d6f
--- /dev/null
+++ b/libhardware/include/hardware/camera3.h
@@ -0,0 +1,3077 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_CAMERA3_H
+#define ANDROID_INCLUDE_CAMERA3_H
+
+#include <system/camera_metadata.h>
+#include "camera_common.h"
+
+/**
+ * Camera device HAL 3.3 [ CAMERA_DEVICE_API_VERSION_3_3 ]
+ *
+ * This is the current recommended version of the camera device HAL.
+ *
+ * Supports the android.hardware.Camera API, and as of v3.2, the
+ * android.hardware.camera2 API in LIMITED or FULL modes.
+ *
+ * Camera devices that support this version of the HAL must return
+ * CAMERA_DEVICE_API_VERSION_3_3 in camera_device_t.common.version and in
+ * camera_info_t.device_version (from camera_module_t.get_camera_info).
+ *
+ * CAMERA_DEVICE_API_VERSION_3_3:
+ * Camera modules that may contain version 3.3 devices must implement at
+ * least version 2.2 of the camera module interface (as defined by
+ * camera_module_t.common.module_api_version).
+ *
+ * CAMERA_DEVICE_API_VERSION_3_2:
+ * Camera modules that may contain version 3.2 devices must implement at
+ * least version 2.2 of the camera module interface (as defined by
+ * camera_module_t.common.module_api_version).
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ * Camera modules that may contain version 3.1 (or 3.0) devices must
+ * implement at least version 2.0 of the camera module interface
+ * (as defined by camera_module_t.common.module_api_version).
+ *
+ * See camera_common.h for more versioning details.
+ *
+ * Documentation index:
+ * S1. Version history
+ * S2. Startup and operation sequencing
+ * S3. Operational modes
+ * S4. 3A modes and state machines
+ * S5. Cropping
+ * S6. Error management
+ * S7. Key Performance Indicator (KPI) glossary
+ * S8. Sample Use Cases
+ * S9. Notes on Controls and Metadata
+ * S10. Reprocessing flow and controls
+ */
+
+/**
+ * S1. Version history:
+ *
+ * 1.0: Initial Android camera HAL (Android 4.0) [camera.h]:
+ *
+ * - Converted from C++ CameraHardwareInterface abstraction layer.
+ *
+ * - Supports android.hardware.Camera API.
+ *
+ * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
+ *
+ * - Sufficient for implementing existing android.hardware.Camera API.
+ *
+ * - Allows for ZSL queue in camera service layer
+ *
+ * - Not tested for any new features such manual capture control, Bayer RAW
+ * capture, reprocessing of RAW data.
+ *
+ * 3.0: First revision of expanded-capability HAL:
+ *
+ * - Major version change since the ABI is completely different. No change to
+ * the required hardware capabilities or operational model from 2.0.
+ *
+ * - Reworked input request and stream queue interfaces: Framework calls into
+ * HAL with next request and stream buffers already dequeued. Sync framework
+ * support is included, necessary for efficient implementations.
+ *
+ * - Moved triggers into requests, most notifications into results.
+ *
+ * - Consolidated all callbacks into framework into one structure, and all
+ * setup methods into a single initialize() call.
+ *
+ * - Made stream configuration into a single call to simplify stream
+ * management. Bidirectional streams replace STREAM_FROM_STREAM construct.
+ *
+ * - Limited mode semantics for older/limited hardware devices.
+ *
+ * 3.1: Minor revision of expanded-capability HAL:
+ *
+ * - configure_streams passes consumer usage flags to the HAL.
+ *
+ * - flush call to drop all in-flight requests/buffers as fast as possible.
+ *
+ * 3.2: Minor revision of expanded-capability HAL:
+ *
+ * - Deprecates get_metadata_vendor_tag_ops. Please use get_vendor_tag_ops
+ * in camera_common.h instead.
+ *
+ * - register_stream_buffers deprecated. All gralloc buffers provided
+ * by framework to HAL in process_capture_request may be new at any time.
+ *
+ * - add partial result support. process_capture_result may be called
+ * multiple times with a subset of the available result before the full
+ * result is available.
+ *
+ * - add manual template to camera3_request_template. The applications may
+ * use this template to control the capture settings directly.
+ *
+ * - Rework the bidirectional and input stream specifications.
+ *
+ * - change the input buffer return path. The buffer is returned in
+ * process_capture_result instead of process_capture_request.
+ *
+ * 3.3: Minor revision of expanded-capability HAL:
+ *
+ * - OPAQUE and YUV reprocessing API updates.
+ *
+ * - Basic support for depth output buffers.
+ *
+ * - Addition of data_space field to camera3_stream_t.
+ *
+ * - Addition of rotation field to camera3_stream_t.
+ *
+ * - Addition of camera3 stream configuration operation mode to camera3_stream_configuration_t
+ *
+ */
+
+/**
+ * S2. Startup and general expected operation sequence:
+ *
+ * 1. Framework calls camera_module_t->common.open(), which returns a
+ * hardware_device_t structure.
+ *
+ * 2. Framework inspects the hardware_device_t->version field, and instantiates
+ * the appropriate handler for that version of the camera hardware device. In
+ * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
+ * a camera3_device_t.
+ *
+ * 3. Framework calls camera3_device_t->ops->initialize() with the framework
+ * callback function pointers. This will only be called this one time after
+ * open(), before any other functions in the ops structure are called.
+ *
+ * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
+ * of input/output streams to the HAL device.
+ *
+ * 5. <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * The framework allocates gralloc buffers and calls
+ * camera3_device_t->ops->register_stream_buffers() for at least one of the
+ * output streams listed in configure_streams. The same stream is registered
+ * only once.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * camera3_device_t->ops->register_stream_buffers() is not called and must
+ * be NULL.
+ *
+ * 6. The framework requests default settings for some number of use cases with
+ * calls to camera3_device_t->ops->construct_default_request_settings(). This
+ * may occur any time after step 3.
+ *
+ * 7. The framework constructs and sends the first capture request to the HAL,
+ * with settings based on one of the sets of default settings, and with at
+ * least one output stream, which has been registered earlier by the
+ * framework. This is sent to the HAL with
+ * camera3_device_t->ops->process_capture_request(). The HAL must block the
+ * return of this call until it is ready for the next request to be sent.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * The buffer_handle_t provided in the camera3_stream_buffer_t array
+ * in the camera3_capture_request_t may be new and never-before-seen
+ * by the HAL on any given new request.
+ *
+ * 8. The framework continues to submit requests, and call
+ * construct_default_request_settings to get default settings buffers for
+ * other use cases.
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * The framework may call register_stream_buffers() at this time for
+ * not-yet-registered streams.
+ *
+ * 9. When the capture of a request begins (sensor starts exposing for the
+ * capture) or processing a reprocess request begins, the HAL
+ * calls camera3_callback_ops_t->notify() with the SHUTTER event, including
+ * the frame number and the timestamp for start of exposure. For a reprocess
+ * request, the timestamp must be the start of exposure of the input image
+ * which can be looked up with android.sensor.timestamp from
+ * camera3_capture_request_t.settings when process_capture_request() is
+ * called.
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * This notify call must be made before the first call to
+ * process_capture_result() for that frame number.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * The camera3_callback_ops_t->notify() call with the SHUTTER event should
+ * be made as early as possible since the framework will be unable to
+ * deliver gralloc buffers to the application layer (for that frame) until
+ * it has a valid timestamp for the start of exposure (or the input image's
+ * start of exposure for a reprocess request).
+ *
+ * Both partial metadata results and the gralloc buffers may be sent to the
+ * framework at any time before or after the SHUTTER event.
+ *
+ * 10. After some pipeline delay, the HAL begins to return completed captures to
+ * the framework with camera3_callback_ops_t->process_capture_result(). These
+ * are returned in the same order as the requests were submitted. Multiple
+ * requests can be in flight at once, depending on the pipeline depth of the
+ * camera HAL device.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * Once a buffer is returned by process_capture_result as part of the
+ * camera3_stream_buffer_t array, and the fence specified by release_fence
+ * has been signaled (this is a no-op for -1 fences), the ownership of that
+ * buffer is considered to be transferred back to the framework. After that,
+ * the HAL must no longer retain that particular buffer, and the
+ * framework may clean up the memory for it immediately.
+ *
+ * process_capture_result may be called multiple times for a single frame,
+ * each time with a new disjoint piece of metadata and/or set of gralloc
+ * buffers. The framework will accumulate these partial metadata results
+ * into one result.
+ *
+ * In particular, it is legal for a process_capture_result to be called
+ * simultaneously for both a frame N and a frame N+1 as long as the
+ * above rule holds for gralloc buffers (both input and output).
+ *
+ * 11. After some time, the framework may stop submitting new requests, wait for
+ * the existing captures to complete (all buffers filled, all results
+ * returned), and then call configure_streams() again. This resets the camera
+ * hardware and pipeline for a new set of input/output streams. Some streams
+ * may be reused from the previous configuration; if these streams' buffers
+ * had already been registered with the HAL, they will not be registered
+ * again. The framework then continues from step 7, if at least one
+ * registered output stream remains (otherwise, step 5 is required first).
+ *
+ * 12. Alternatively, the framework may call camera3_device_t->common->close()
+ * to end the camera session. This may be called at any time when no other
+ * calls from the framework are active, although the call may block until all
+ * in-flight captures have completed (all results returned, all buffers
+ * filled). After the close call returns, no more calls to the
+ * camera3_callback_ops_t functions are allowed from the HAL. Once the
+ * close() call is underway, the framework may not call any other HAL device
+ * functions.
+ *
+ * 13. In case of an error or other asynchronous event, the HAL must call
+ * camera3_callback_ops_t->notify() with the appropriate error/event
+ * message. After returning from a fatal device-wide error notification, the
+ * HAL should act as if close() had been called on it. However, the HAL must
+ * either cancel or complete all outstanding captures before calling
+ * notify(), so that once notify() is called with a fatal error, the
+ * framework will not receive further callbacks from the device. Methods
+ * besides close() should return -ENODEV or NULL after the notify() method
+ * returns from a fatal error message.
+ */
+
+/**
+ * S3. Operational modes:
+ *
+ * The camera 3 HAL device can implement one of two possible operational modes;
+ * limited and full. Full support is expected from new higher-end
+ * devices. Limited mode has hardware requirements roughly in line with those
+ * for a camera HAL device v1 implementation, and is expected from older or
+ * inexpensive devices. Full is a strict superset of limited, and they share the
+ * same essential operational flow, as documented above.
+ *
+ * The HAL must indicate its level of support with the
+ * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
+ * limited mode, and 1 indicating full mode support.
+ *
+ * Roughly speaking, limited-mode devices do not allow for application control
+ * of capture settings (3A control only), high-rate capture of high-resolution
+ * images, raw sensor readout, or support for YUV output streams above maximum
+ * recording resolution (JPEG only for large images).
+ *
+ * ** Details of limited mode behavior:
+ *
+ * - Limited-mode devices do not need to implement accurate synchronization
+ * between capture request settings and the actual image data
+ * captured. Instead, changes to settings may take effect some time in the
+ * future, and possibly not for the same output frame for each settings
+ * entry. Rapid changes in settings may result in some settings never being
+ * used for a capture. However, captures that include high-resolution output
+ * buffers ( > 1080p ) have to use the settings as specified (but see below
+ * for processing rate).
+ *
+ * - Limited-mode devices do not need to support most of the
+ * settings/result/static info metadata. Specifically, only the following settings
+ * are expected to be consumed or produced by a limited-mode HAL device:
+ *
+ * android.control.aeAntibandingMode (controls and dynamic)
+ * android.control.aeExposureCompensation (controls and dynamic)
+ * android.control.aeLock (controls and dynamic)
+ * android.control.aeMode (controls and dynamic)
+ * android.control.aeRegions (controls and dynamic)
+ * android.control.aeTargetFpsRange (controls and dynamic)
+ * android.control.aePrecaptureTrigger (controls and dynamic)
+ * android.control.afMode (controls and dynamic)
+ * android.control.afRegions (controls and dynamic)
+ * android.control.awbLock (controls and dynamic)
+ * android.control.awbMode (controls and dynamic)
+ * android.control.awbRegions (controls and dynamic)
+ * android.control.captureIntent (controls and dynamic)
+ * android.control.effectMode (controls and dynamic)
+ * android.control.mode (controls and dynamic)
+ * android.control.sceneMode (controls and dynamic)
+ * android.control.videoStabilizationMode (controls and dynamic)
+ * android.control.aeAvailableAntibandingModes (static)
+ * android.control.aeAvailableModes (static)
+ * android.control.aeAvailableTargetFpsRanges (static)
+ * android.control.aeCompensationRange (static)
+ * android.control.aeCompensationStep (static)
+ * android.control.afAvailableModes (static)
+ * android.control.availableEffects (static)
+ * android.control.availableSceneModes (static)
+ * android.control.availableVideoStabilizationModes (static)
+ * android.control.awbAvailableModes (static)
+ * android.control.maxRegions (static)
+ * android.control.sceneModeOverrides (static)
+ * android.control.aeState (dynamic)
+ * android.control.afState (dynamic)
+ * android.control.awbState (dynamic)
+ *
+ * android.flash.mode (controls and dynamic)
+ * android.flash.info.available (static)
+ *
+ * android.info.supportedHardwareLevel (static)
+ *
+ * android.jpeg.gpsCoordinates (controls and dynamic)
+ * android.jpeg.gpsProcessingMethod (controls and dynamic)
+ * android.jpeg.gpsTimestamp (controls and dynamic)
+ * android.jpeg.orientation (controls and dynamic)
+ * android.jpeg.quality (controls and dynamic)
+ * android.jpeg.thumbnailQuality (controls and dynamic)
+ * android.jpeg.thumbnailSize (controls and dynamic)
+ * android.jpeg.availableThumbnailSizes (static)
+ * android.jpeg.maxSize (static)
+ *
+ * android.lens.info.minimumFocusDistance (static)
+ *
+ * android.request.id (controls and dynamic)
+ *
+ * android.scaler.cropRegion (controls and dynamic)
+ * android.scaler.availableStreamConfigurations (static)
+ * android.scaler.availableMinFrameDurations (static)
+ * android.scaler.availableStallDurations (static)
+ * android.scaler.availableMaxDigitalZoom (static)
+ * android.scaler.maxDigitalZoom (static)
+ * android.scaler.croppingType (static)
+ *
+ * android.sensor.orientation (static)
+ * android.sensor.timestamp (dynamic)
+ *
+ * android.statistics.faceDetectMode (controls and dynamic)
+ * android.statistics.info.availableFaceDetectModes (static)
+ * android.statistics.faceIds (dynamic)
+ * android.statistics.faceLandmarks (dynamic)
+ * android.statistics.faceRectangles (dynamic)
+ * android.statistics.faceScores (dynamic)
+ *
+ * android.sync.frameNumber (dynamic)
+ * android.sync.maxLatency (static)
+ *
+ * - Captures in limited mode that include high-resolution (> 1080p) output
+ * buffers may block in process_capture_request() until all the output buffers
+ * have been filled. A full-mode HAL device must process sequences of
+ * high-resolution requests at the rate indicated in the static metadata for
+ * that pixel format. The HAL must still call process_capture_result() to
+ * provide the output; the framework must simply be prepared for
+ * process_capture_request() to block until after process_capture_result() for
+ * that request completes for high-resolution captures for limited-mode
+ * devices.
+ *
+ * - Full-mode devices must support below additional capabilities:
+ * - 30fps at maximum resolution is preferred, more than 20fps is required.
+ * - Per frame control (android.sync.maxLatency == PER_FRAME_CONTROL).
+ * - Sensor manual control metadata. See MANUAL_SENSOR defined in
+ * android.request.availableCapabilities.
+ * - Post-processing manual control metadata. See MANUAL_POST_PROCESSING defined
+ * in android.request.availableCapabilities.
+ *
+ */
+
+/**
+ * S4. 3A modes and state machines:
+ *
+ * While the actual 3A algorithms are up to the HAL implementation, a high-level
+ * state machine description is defined by the HAL interface, to allow the HAL
+ * device and the framework to communicate about the current state of 3A, and to
+ * trigger 3A events.
+ *
+ * When the device is opened, all the individual 3A states must be
+ * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
+ * focus must be maintained across the configure() call.
+ *
+ * Triggering a 3A action involves simply setting the relevant trigger entry in
+ * the settings for the next request to indicate start of trigger. For example,
+ * the trigger for starting an autofocus scan is setting the entry
+ * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
+ * request, and cancelling an autofocus scan is triggered by setting
+ * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
+ * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
+ * request with a trigger entry set to a non-IDLE value will be treated as an
+ * independent triggering event.
+ *
+ * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
+ * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
+ * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
+ * (ANDROID_CONTROL_USE_SCENE_MODE).
+ *
+ * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
+ * and none of the capture controls may be overridden by the 3A routines.
+ *
+ * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
+ * their own independent algorithms, and have their own mode, state, and
+ * trigger metadata entries, as listed in the next section.
+ *
+ * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
+ * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
+ * FACE_PRIORITY, the HAL must override the values of
+ * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
+ * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
+ * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
+ * must be ignored for these scene modes.
+ *
+ * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
+ * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
+ * and focusing on any detected faces in the scene.
+ *
+ * S4.1. Auto-focus settings and result entries:
+ *
+ * Main metadata entries:
+ *
+ * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
+ * mode. Set by the framework in the request settings.
+ *
+ * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
+ * position.
+ *
+ * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
+ * triggered.
+ *
+ * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
+ * AF is triggered.
+ *
+ * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
+ * video. Triggering immediately locks focus in current
+ * position. Canceling resumes cotinuous focusing.
+ *
+ * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
+ * zero-shutter-lag still capture. Triggering locks focus once currently
+ * active sweep concludes. Canceling resumes continuous focusing.
+ *
+ * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
+ * autofocus scan, so triggering one or canceling one has no effect.
+ * Images are focused automatically by the HAL.
+ *
+ * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
+ * algorithm state, reported by the HAL in the result metadata.
+ *
+ * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
+ * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
+ * When the device is opened, it must start in this state.
+ *
+ * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
+ * for good focus. The lens is moving.
+ *
+ * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
+ * well focused. The lens is not moving. The HAL may spontaneously leave
+ * this state.
+ *
+ * AF_STATE_PASSIVE_UNFOCUSED: A continuous focus algorithm believes it is
+ * not well focused. The lens is not moving. The HAL may spontaneously
+ * leave this state.
+ *
+ * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
+ *
+ * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
+ * lens is not moving.
+ *
+ * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
+ * focus. The lens is not moving.
+ *
+ * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
+ * meaning of which is mode- and state- dependent. Set by the framework in
+ * the request settings.
+ *
+ * AF_TRIGGER_IDLE: No current trigger.
+ *
+ * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
+ * dependent.
+ *
+ * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
+ * default.
+ *
+ * Additional metadata entries:
+ *
+ * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
+ * that should be used to determine good focus. This applies to all AF
+ * modes that scan for focus. Set by the framework in the request
+ * settings.
+ *
+ * S4.2. Auto-exposure settings and result entries:
+ *
+ * Main metadata entries:
+ *
+ * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
+ * mode. Set by the framework in the request settings.
+ *
+ * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
+ * frame duration, and flash.
+ *
+ * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
+ * set flash to fire or to torch mode.
+ *
+ * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
+ * discretion for precapture and still capture. User control of flash
+ * disabled.
+ *
+ * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
+ * for capture, and at HAL's discretion for precapture.. User control of
+ * flash disabled.
+ *
+ * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
+ * HAL's discretion for precapture and still capture. Use a flash burst
+ * at end of precapture sequence to reduce redeye in the final
+ * picture. User control of flash disabled.
+ *
+ * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
+ * algorithm state, reported by the HAL in the result metadata.
+ *
+ * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
+ * opened, it must start in this state.
+ *
+ * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
+ * exposure parameters.
+ *
+ * AE_STATE_CONVERGED: AE has found good exposure values for the current
+ * scene, and the exposure parameters are not changing. HAL may
+ * spontaneously leave this state to search for better solution.
+ *
+ * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
+ * values are not changing.
+ *
+ * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
+ * flash is required for a sufficiently bright picture. Used for
+ * determining if a zero-shutter-lag frame can be used.
+ *
+ * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
+ * sequence. Depending on AE mode, this mode may involve firing the
+ * flash for metering, or a burst of flash pulses for redeye reduction.
+ *
+ * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
+ * sequence before capturing a high-quality image. Set by the framework in
+ * the request settings.
+ *
+ * PRECAPTURE_TRIGGER_IDLE: No current trigger.
+ *
+ * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
+ * use the subsequent requests to measure good exposure/white balance
+ * for an upcoming high-resolution capture.
+ *
+ * Additional metadata entries:
+ *
+ * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
+ * values
+ *
+ * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
+ * algorithm target brightness point.
+ *
+ * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
+ * rate range for the AE algorithm. The AE routine cannot change the frame
+ * rate to be outside these bounds.
+ *
+ * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
+ * that should be used to determine good exposure levels. This applies to
+ * all AE modes besides OFF.
+ *
+ * S4.3. Auto-whitebalance settings and result entries:
+ *
+ * Main metadata entries:
+ *
+ * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
+ * mode.
+ *
+ * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
+ *
+ * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
+ * transform, possibly using more complex transforms than a simple
+ * matrix.
+ *
+ * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
+ * incandescent (tungsten) lighting, roughly 2700K.
+ *
+ * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
+ * lighting, roughly 5000K.
+ *
+ * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
+ * fluorescent lighting, roughly 3000K.
+ *
+ * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
+ * roughly 5500K.
+ *
+ * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
+ * daylight, roughly 6500K.
+ *
+ * AWB_MODE_TWILIGHT: Fixed white balance settings good for
+ * near-sunset/sunrise, roughly 15000K.
+ *
+ * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
+ * lit by the sun, roughly 7500K.
+ *
+ * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
+ * algorithm state, reported by the HAL in the result metadata.
+ *
+ * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
+ * is opened, it must start in this state.
+ *
+ * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
+ * changing color adjustment parameters.
+ *
+ * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
+ * current scene, and the parameters are not changing. HAL may
+ * spontaneously leave this state to search for better solution.
+ *
+ * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
+ * adjustment values are not changing.
+ *
+ * Additional metadata entries:
+ *
+ * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
+ * their current values.
+ *
+ * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
+ * that should be used to determine good color balance. This applies only
+ * to auto-WB mode.
+ *
+ * S4.4. General state machine transition notes
+ *
+ * Switching between AF, AE, or AWB modes always resets the algorithm's state
+ * to INACTIVE. Similarly, switching between CONTROL_MODE or
+ * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
+ * algorithm states to INACTIVE.
+ *
+ * The tables below are per-mode.
+ *
+ * S4.5. AF state machines
+ *
+ * when enabling AF or changing AF mode
+ *| state | trans. cause | new state | notes |
+ *+--------------------+---------------+--------------------+------------------+
+ *| Any | AF mode change| INACTIVE | |
+ *+--------------------+---------------+--------------------+------------------+
+ *
+ * mode = AF_MODE_OFF or AF_MODE_EDOF
+ *| state | trans. cause | new state | notes |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | | INACTIVE | Never changes |
+ *+--------------------+---------------+--------------------+------------------+
+ *
+ * mode = AF_MODE_AUTO or AF_MODE_MACRO
+ *| state | trans. cause | new state | notes |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
+ *| | | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
+ *+--------------------+---------------+--------------------+------------------+
+ *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
+ *| | | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
+ *+--------------------+---------------+--------------------+------------------+
+ *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
+ *| | | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| All states | mode change | INACTIVE | |
+ *+--------------------+---------------+--------------------+------------------+
+ *
+ * mode = AF_MODE_CONTINUOUS_VIDEO
+ *| state | trans. cause | new state | notes |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
+ *| | new scan | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
+ *| | current scan | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
+ *| | current scan | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
+ *| | | | if focus is good |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
+ *| | | | if focus is bad |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
+ *| | | | position |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
+ *| | new scan | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
+ *| | new scan | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
+ *+--------------------+---------------+--------------------+------------------+
+ *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
+ *+--------------------+---------------+--------------------+------------------+
+ *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
+ *+--------------------+---------------+--------------------+------------------+
+ *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
+ *+--------------------+---------------+--------------------+------------------+
+ *
+ * mode = AF_MODE_CONTINUOUS_PICTURE
+ *| state | trans. cause | new state | notes |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
+ *| | new scan | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
+ *| | current scan | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
+ *| | current scan | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
+ *| | | | once focus good |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
+ *| | | | if cannot focus |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
+ *| | | | position |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
+ *| | new scan | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
+ *| | new scan | | Lens now moving |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
+ *| | | | Lens now locked |
+ *+--------------------+---------------+--------------------+------------------+
+ *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
+ *+--------------------+---------------+--------------------+------------------+
+ *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
+ *+--------------------+---------------+--------------------+------------------+
+ *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
+ *+--------------------+---------------+--------------------+------------------+
+ *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
+ *+--------------------+---------------+--------------------+------------------+
+ *
+ * S4.6. AE and AWB state machines
+ *
+ * The AE and AWB state machines are mostly identical. AE has additional
+ * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
+ * states should be ignored for the AWB state machine.
+ *
+ * when enabling AE/AWB or changing AE/AWB mode
+ *| state | trans. cause | new state | notes |
+ *+--------------------+---------------+--------------------+------------------+
+ *| Any | mode change | INACTIVE | |
+ *+--------------------+---------------+--------------------+------------------+
+ *
+ * mode = AE_MODE_OFF / AWB mode not AUTO
+ *| state | trans. cause | new state | notes |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | | INACTIVE | AE/AWB disabled |
+ *+--------------------+---------------+--------------------+------------------+
+ *
+ * mode = AE_MODE_ON_* / AWB_MODE_AUTO
+ *| state | trans. cause | new state | notes |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | HAL initiates | SEARCHING | |
+ *| | AE/AWB scan | | |
+ *+--------------------+---------------+--------------------+------------------+
+ *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
+ *| | on | | |
+ *+--------------------+---------------+--------------------+------------------+
+ *| SEARCHING | HAL finishes | CONVERGED | good values, not |
+ *| | AE/AWB scan | | changing |
+ *+--------------------+---------------+--------------------+------------------+
+ *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
+ *| | AE scan | | dark w/o flash |
+ *+--------------------+---------------+--------------------+------------------+
+ *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
+ *| | on | | |
+ *+--------------------+---------------+--------------------+------------------+
+ *| CONVERGED | HAL initiates | SEARCHING | values locked |
+ *| | AE/AWB scan | | |
+ *+--------------------+---------------+--------------------+------------------+
+ *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
+ *| | on | | |
+ *+--------------------+---------------+--------------------+------------------+
+ *| FLASH_REQUIRED | HAL initiates | SEARCHING | values locked |
+ *| | AE/AWB scan | | |
+ *+--------------------+---------------+--------------------+------------------+
+ *| FLASH_REQUIRED | AE/AWB_LOCK | LOCKED | values locked |
+ *| | on | | |
+ *+--------------------+---------------+--------------------+------------------+
+ *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
+ *| | off | | after unlock |
+ *+--------------------+---------------+--------------------+------------------+
+ *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
+ *| | off | | after unlock |
+ *+--------------------+---------------+--------------------+------------------+
+ *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
+ *| | off | | but too dark |
+ *+--------------------+---------------+--------------------+------------------+
+ *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
+ *| | START | | sequence |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
+ *| | AE_LOCK off | | quality capture |
+ *+--------------------+---------------+--------------------+------------------+
+ *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
+ *| | AE_LOCK on | | quality capture |
+ *+--------------------+---------------+--------------------+------------------+
+ *
+ */
+
+/**
+ * S5. Cropping:
+ *
+ * Cropping of the full pixel array (for digital zoom and other use cases where
+ * a smaller FOV is desirable) is communicated through the
+ * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
+ * change on a per-request basis, which is critical for implementing smooth
+ * digital zoom.
+ *
+ * The region is defined as a rectangle (x, y, width, height), with (x, y)
+ * describing the top-left corner of the rectangle. The rectangle is defined on
+ * the coordinate system of the sensor active pixel array, with (0,0) being the
+ * top-left pixel of the active pixel array. Therefore, the width and height
+ * cannot be larger than the dimensions reported in the
+ * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
+ * width and height are reported by the HAL through the
+ * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
+ * maximum supported zoom factor. Therefore, the minimum crop region width and
+ * height are:
+ *
+ * {width, height} =
+ * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
+ * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
+ * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
+ * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
+ *
+ * If the crop region needs to fulfill specific requirements (for example, it
+ * needs to start on even coordinates, and its width/height needs to be even),
+ * the HAL must do the necessary rounding and write out the final crop region
+ * used in the output result metadata. Similarly, if the HAL implements video
+ * stabilization, it must adjust the result crop region to describe the region
+ * actually included in the output after video stabilization is applied. In
+ * general, a camera-using application must be able to determine the field of
+ * view it is receiving based on the crop region, the dimensions of the image
+ * sensor, and the lens focal length.
+ *
+ * It is assumed that the cropping is applied after raw to other color space
+ * conversion. Raw streams (RAW16 and RAW_OPAQUE) don't have this conversion stage,
+ * and are not croppable. Therefore, the crop region must be ignored by the HAL
+ * for raw streams.
+ *
+ * Since the crop region applies to all non-raw streams, which may have different aspect
+ * ratios than the crop region, the exact sensor region used for each stream may
+ * be smaller than the crop region. Specifically, each stream should maintain
+ * square pixels and its aspect ratio by minimally further cropping the defined
+ * crop region. If the stream's aspect ratio is wider than the crop region, the
+ * stream should be further cropped vertically, and if the stream's aspect ratio
+ * is narrower than the crop region, the stream should be further cropped
+ * horizontally.
+ *
+ * In all cases, the stream crop must be centered within the full crop region,
+ * and each stream is only either cropped horizontally or vertical relative to
+ * the full crop region, never both.
+ *
+ * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
+ * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
+ * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
+ * 1500 pixel array) sensor.
+ *
+ * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
+ *
+ * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
+ * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
+ *
+ * 0 1000 2000
+ * +---------+---------+---------+----------+
+ * | Active pixel array |
+ * | |
+ * | |
+ * + +-------------------+ + 375
+ * | | | |
+ * | O===================O |
+ * | I 1280x720 stream I |
+ * + I I + 750
+ * | I I |
+ * | O===================O |
+ * | | | |
+ * + +-------------------+ + 1125
+ * | Crop region, 640x480 stream |
+ * | |
+ * | |
+ * +---------+---------+---------+----------+ 1500
+ *
+ * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
+ *
+ * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
+ * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
+ *
+ * 0 1000 2000
+ * +---------+---------+---------+----------+
+ * | Active pixel array |
+ * | |
+ * | |
+ * + +---O==================O---+ + 375
+ * | | I 640x480 stream I | |
+ * | | I I | |
+ * | | I I | |
+ * + | I I | + 750
+ * | | I I | |
+ * | | I I | |
+ * | | I I | |
+ * + +---O==================O---+ + 1125
+ * | Crop region, 1280x720 stream |
+ * | |
+ * | |
+ * +---------+---------+---------+----------+ 1500
+ *
+ * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
+ *
+ * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
+ * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
+ *
+ * 0 1000 2000
+ * +---------+---------+---------+----------+
+ * | Active pixel array |
+ * | |
+ * | |
+ * + +--------------+ + 375
+ * | O==============O |
+ * | ################ |
+ * | # # |
+ * + # # + 750
+ * | # # |
+ * | ################ 1280x720 |
+ * | O==============O 640x480 |
+ * + +--------------+ + 1125
+ * | Crop region |
+ * | |
+ * | |
+ * +---------+---------+---------+----------+ 1500
+ *
+ * And a final example, a 1024x1024 square aspect ratio stream instead of the
+ * 480p stream:
+ *
+ * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
+ *
+ * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
+ * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
+ *
+ * 0 1000 2000
+ * +---------+---------+---------+----------+
+ * | Active pixel array |
+ * | |
+ * | 1024x1024 stream |
+ * + +--###############--+ + 375
+ * | | # # | |
+ * | O===================O |
+ * | I 1280x720 stream I |
+ * + I I + 750
+ * | I I |
+ * | O===================O |
+ * | | # # | |
+ * + +--###############--+ + 1125
+ * | Crop region |
+ * | |
+ * | |
+ * +---------+---------+---------+----------+ 1500
+ *
+ */
+
+/**
+ * S6. Error management:
+ *
+ * Camera HAL device ops functions that have a return value will all return
+ * -ENODEV / NULL in case of a serious error. This means the device cannot
+ * continue operation, and must be closed by the framework. Once this error is
+ * returned by some method, or if notify() is called with ERROR_DEVICE, only
+ * the close() method can be called successfully. All other methods will return
+ * -ENODEV / NULL.
+ *
+ * If a device op is called in the wrong sequence, for example if the framework
+ * calls configure_streams() is called before initialize(), the device must
+ * return -ENOSYS from the call, and do nothing.
+ *
+ * Transient errors in image capture must be reported through notify() as follows:
+ *
+ * - The failure of an entire capture to occur must be reported by the HAL by
+ * calling notify() with ERROR_REQUEST. Individual errors for the result
+ * metadata or the output buffers must not be reported in this case.
+ *
+ * - If the metadata for a capture cannot be produced, but some image buffers
+ * were filled, the HAL must call notify() with ERROR_RESULT.
+ *
+ * - If an output image buffer could not be filled, but either the metadata was
+ * produced or some other buffers were filled, the HAL must call notify() with
+ * ERROR_BUFFER for each failed buffer.
+ *
+ * In each of these transient failure cases, the HAL must still call
+ * process_capture_result, with valid output and input (if an input buffer was
+ * submitted) buffer_handle_t. If the result metadata could not be produced, it
+ * should be NULL. If some buffers could not be filled, they must be returned with
+ * process_capture_result in the error state, their release fences must be set to
+ * the acquire fences passed by the framework, or -1 if they have been waited on by
+ * the HAL already.
+ *
+ * Invalid input arguments result in -EINVAL from the appropriate methods. In
+ * that case, the framework must act as if that call had never been made.
+ *
+ */
+
+/**
+ * S7. Key Performance Indicator (KPI) glossary:
+ *
+ * This includes some critical definitions that are used by KPI metrics.
+ *
+ * Pipeline Latency:
+ * For a given capture request, the duration from the framework calling
+ * process_capture_request to the HAL sending capture result and all buffers
+ * back by process_capture_result call. To make the Pipeline Latency measure
+ * independent of frame rate, it is measured by frame count.
+ *
+ * For example, when frame rate is 30 (fps), the frame duration (time interval
+ * between adjacent frame capture time) is 33 (ms).
+ * If it takes 5 frames for framework to get the result and buffers back for
+ * a given request, then the Pipeline Latency is 5 (frames), instead of
+ * 5 x 33 = 165 (ms).
+ *
+ * The Pipeline Latency is determined by android.request.pipelineDepth and
+ * android.request.pipelineMaxDepth, see their definitions for more details.
+ *
+ */
+
+/**
+ * S8. Sample Use Cases:
+ *
+ * This includes some typical use case examples the camera HAL may support.
+ *
+ * S8.1 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_BIDIRECTIONAL stream.
+ *
+ * For this use case, the bidirectional stream will be used by the framework as follows:
+ *
+ * 1. The framework includes a buffer from this stream as output buffer in a
+ * request as normal.
+ *
+ * 2. Once the HAL device returns a filled output buffer to the framework,
+ * the framework may do one of two things with the filled buffer:
+ *
+ * 2. a. The framework uses the filled data, and returns the now-used buffer
+ * to the stream queue for reuse. This behavior exactly matches the
+ * OUTPUT type of stream.
+ *
+ * 2. b. The framework wants to reprocess the filled data, and uses the
+ * buffer as an input buffer for a request. Once the HAL device has
+ * used the reprocessing buffer, it then returns it to the
+ * framework. The framework then returns the now-used buffer to the
+ * stream queue for reuse.
+ *
+ * 3. The HAL device will be given the buffer again as an output buffer for
+ * a request at some future point.
+ *
+ * For ZSL use case, the pixel format for bidirectional stream will be
+ * HAL_PIXEL_FORMAT_RAW_OPAQUE or HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED if it
+ * is listed in android.scaler.availableInputOutputFormatsMap. When
+ * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, the gralloc
+ * usage flags for the consumer endpoint will be set to GRALLOC_USAGE_HW_CAMERA_ZSL.
+ * A configuration stream list that has BIDIRECTIONAL stream used as input, will
+ * usually also have a distinct OUTPUT stream to get the reprocessing data. For example,
+ * for the ZSL use case, the stream list might be configured with the following:
+ *
+ * - A HAL_PIXEL_FORMAT_RAW_OPAQUE bidirectional stream is used
+ * as input.
+ * - And a HAL_PIXEL_FORMAT_BLOB (JPEG) output stream.
+ *
+ * S8.2 ZSL (OPAQUE) reprocessing with CAMERA3_STREAM_INPUT stream.
+ *
+ * CAMERA_DEVICE_API_VERSION_3_3:
+ * When OPAQUE_REPROCESSING capability is supported by the camera device, the INPUT stream
+ * can be used for application/framework implemented use case like Zero Shutter Lag (ZSL).
+ * This kind of stream will be used by the framework as follows:
+ *
+ * 1. Application/framework configures an opaque (RAW or YUV based) format output stream that is
+ * used to produce the ZSL output buffers. The stream pixel format will be
+ * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED.
+ *
+ * 2. Application/framework configures an opaque format input stream that is used to
+ * send the reprocessing ZSL buffers to the HAL. The stream pixel format will
+ * also be HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED.
+ *
+ * 3. Application/framework configures a YUV/JPEG output stream that is used to receive the
+ * reprocessed data. The stream pixel format will be YCbCr_420/HAL_PIXEL_FORMAT_BLOB.
+ *
+ * 4. Application/framework picks a ZSL buffer from the ZSL output stream when a ZSL capture is
+ * issued by the application, and sends the data back as an input buffer in a
+ * reprocessing request, then sends to the HAL for reprocessing.
+ *
+ * 5. The HAL sends back the output YUV/JPEG result to framework.
+ *
+ * The HAL can select the actual opaque buffer format and configure the ISP pipeline
+ * appropriately based on the HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED format and
+ * the gralloc usage flag GRALLOC_USAGE_HW_CAMERA_ZSL.
+
+ * S8.3 YUV reprocessing with CAMERA3_STREAM_INPUT stream.
+ *
+ * When YUV reprocessing is supported by the HAL, the INPUT stream
+ * can be used for the YUV reprocessing use cases like lucky-shot and image fusion.
+ * This kind of stream will be used by the framework as follows:
+ *
+ * 1. Application/framework configures an YCbCr_420 format output stream that is
+ * used to produce the output buffers.
+ *
+ * 2. Application/framework configures an YCbCr_420 format input stream that is used to
+ * send the reprocessing YUV buffers to the HAL.
+ *
+ * 3. Application/framework configures a YUV/JPEG output stream that is used to receive the
+ * reprocessed data. The stream pixel format will be YCbCr_420/HAL_PIXEL_FORMAT_BLOB.
+ *
+ * 4. Application/framework processes the output buffers (could be as simple as picking
+ * an output buffer directly) from the output stream when a capture is issued, and sends
+ * the data back as an input buffer in a reprocessing request, then sends to the HAL
+ * for reprocessing.
+ *
+ * 5. The HAL sends back the output YUV/JPEG result to framework.
+ *
+ */
+
+/**
+ * S9. Notes on Controls and Metadata
+ *
+ * This section contains notes about the interpretation and usage of various metadata tags.
+ *
+ * S9.1 HIGH_QUALITY and FAST modes.
+ *
+ * Many camera post-processing blocks may be listed as having HIGH_QUALITY,
+ * FAST, and OFF operating modes. These blocks will typically also have an
+ * 'available modes' tag representing which of these operating modes are
+ * available on a given device. The general policy regarding implementing
+ * these modes is as follows:
+ *
+ * 1. Operating mode controls of hardware blocks that cannot be disabled
+ * must not list OFF in their corresponding 'available modes' tags.
+ *
+ * 2. OFF will always be included in their corresponding 'available modes'
+ * tag if it is possible to disable that hardware block.
+ *
+ * 3. FAST must always be included in the 'available modes' tags for all
+ * post-processing blocks supported on the device. If a post-processing
+ * block also has a slower and higher quality operating mode that does
+ * not meet the framerate requirements for FAST mode, HIGH_QUALITY should
+ * be included in the 'available modes' tag to represent this operating
+ * mode.
+ */
+
+/**
+ * S10. Reprocessing flow and controls
+ *
+ * This section describes the OPAQUE and YUV reprocessing flow and controls. OPAQUE reprocessing
+ * uses an opaque format that is not directly application-visible, and the application can
+ * only select some of the output buffers and send back to HAL for reprocessing, while YUV
+ * reprocessing gives the application opportunity to process the buffers before reprocessing.
+ *
+ * S8 gives the stream configurations for the typical reprocessing uses cases,
+ * this section specifies the buffer flow and controls in more details.
+ *
+ * S10.1 OPAQUE (typically for ZSL use case) reprocessing flow and controls
+ *
+ * For OPAQUE reprocessing (e.g. ZSL) use case, after the application creates the specific
+ * output and input streams, runtime buffer flow and controls are specified as below:
+ *
+ * 1. Application starts output streaming by sending repeating requests for output
+ * opaque buffers and preview. The buffers are held by an application
+ * maintained circular buffer. The requests are based on CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG
+ * capture template, which should have all necessary settings that guarantee output
+ * frame rate is not slowed down relative to sensor output frame rate.
+ *
+ * 2. When a capture is issued, the application selects one output buffer based
+ * on application buffer selection logic, e.g. good AE and AF statistics etc.
+ * Application then creates an reprocess request based on the capture result associated
+ * with this selected buffer. The selected output buffer is now added to this reprocess
+ * request as an input buffer, the output buffer of this reprocess request should be
+ * either JPEG output buffer or YUV output buffer, or both, depending on the application
+ * choice.
+ *
+ * 3. Application then alters the reprocess settings to get best image quality. The HAL must
+ * support and only support below controls if the HAL support OPAQUE_REPROCESSING capability:
+ * - android.jpeg.* (if JPEG buffer is included as one of the output)
+ * - android.noiseReduction.mode (change to HIGH_QUALITY if it is supported)
+ * - android.edge.mode (change to HIGH_QUALITY if it is supported)
+ * All other controls must be ignored by the HAL.
+ * 4. HAL processed the input buffer and return the output buffers in the capture results
+ * as normal.
+ *
+ * S10.2 YUV reprocessing flow and controls
+ *
+ * The YUV reprocessing buffer flow is similar as OPAQUE reprocessing, with below difference:
+ *
+ * 1. Application may want to have finer granularity control of the intermediate YUV images
+ * (before reprocessing). For example, application may choose
+ * - android.noiseReduction.mode == MINIMAL
+ * to make sure the no YUV domain noise reduction has applied to the output YUV buffers,
+ * then it can do its own advanced noise reduction on them. For OPAQUE reprocessing case, this
+ * doesn't matter, as long as the final reprocessed image has the best quality.
+ * 2. Application may modify the YUV output buffer data. For example, for image fusion use
+ * case, where multiple output images are merged together to improve the signal-to-noise
+ * ratio (SNR). The input buffer may be generated from multiple buffers by the application.
+ * To avoid excessive amount of noise reduction and insufficient amount of edge enhancement
+ * being applied to the input buffer, the application can hint the HAL how much effective
+ * exposure time improvement has been done by the application, then the HAL can adjust the
+ * noise reduction and edge enhancement paramters to get best reprocessed image quality.
+ * Below tag can be used for this purpose:
+ * - android.reprocess.effectiveExposureFactor
+ * The value would be exposure time increase factor applied to the original output image,
+ * for example, if there are N image merged, the exposure time increase factor would be up
+ * to sqrt(N). See this tag spec for more details.
+ *
+ * S10.3 Reprocessing pipeline characteristics
+ *
+ * Reprocessing pipeline has below different characteristics comparing with normal output
+ * pipeline:
+ *
+ * 1. The reprocessing result can be returned ahead of the pending normal output results. But
+ * the FIFO ordering must be maintained for all reprocessing results. For example, there are
+ * below requests (A stands for output requests, B stands for reprocessing requests)
+ * being processed by the HAL:
+ * A1, A2, A3, A4, B1, A5, B2, A6...
+ * result of B1 can be returned before A1-A4, but result of B2 must be returned after B1.
+ * 2. Single input rule: For a given reprocessing request, all output buffers must be from the
+ * input buffer, rather than sensor output. For example, if a reprocess request include both
+ * JPEG and preview buffers, all output buffers must be produced from the input buffer
+ * included by the reprocessing request, rather than sensor. The HAL must not output preview
+ * buffers from sensor, while output JPEG buffer from the input buffer.
+ * 3. Input buffer will be from camera output directly (ZSL case) or indirectly(image fusion
+ * case). For the case where buffer is modified, the size will remain same. The HAL can
+ * notify CAMERA3_MSG_ERROR_REQUEST if buffer from unknown source is sent.
+ * 4. Result as reprocessing request: The HAL can expect that a reprocessing request is a copy
+ * of one of the output results with minor allowed setting changes. The HAL can notify
+ * CAMERA3_MSG_ERROR_REQUEST if a request from unknown source is issued.
+ * 5. Output buffers may not be used as inputs across the configure stream boundary, This is
+ * because an opaque stream like the ZSL output stream may have different actual image size
+ * inside of the ZSL buffer to save power and bandwidth for smaller resolution JPEG capture.
+ * The HAL may notify CAMERA3_MSG_ERROR_REQUEST if this case occurs.
+ * 6. HAL Reprocess requests error reporting during flush should follow the same rule specified
+ * by flush() method.
+ *
+ */
+
+__BEGIN_DECLS
+
+struct camera3_device;
+
+/**********************************************************************
+ *
+ * Camera3 stream and stream buffer definitions.
+ *
+ * These structs and enums define the handles and contents of the input and
+ * output streams connecting the HAL to various framework and application buffer
+ * consumers. Each stream is backed by a gralloc buffer queue.
+ *
+ */
+
+/**
+ * camera3_stream_type_t:
+ *
+ * The type of the camera stream, which defines whether the camera HAL device is
+ * the producer or the consumer for that stream, and how the buffers of the
+ * stream relate to the other streams.
+ */
+typedef enum camera3_stream_type {
+ /**
+ * This stream is an output stream; the camera HAL device will be
+ * responsible for filling buffers from this stream with newly captured or
+ * reprocessed image data.
+ */
+ CAMERA3_STREAM_OUTPUT = 0,
+
+ /**
+ * This stream is an input stream; the camera HAL device will be responsible
+ * for reading buffers from this stream and sending them through the camera
+ * processing pipeline, as if the buffer was a newly captured image from the
+ * imager.
+ *
+ * The pixel format for input stream can be any format reported by
+ * android.scaler.availableInputOutputFormatsMap. The pixel format of the
+ * output stream that is used to produce the reprocessing data may be any
+ * format reported by android.scaler.availableStreamConfigurations. The
+ * supported input/output stream combinations depends the camera device
+ * capabilities, see android.scaler.availableInputOutputFormatsMap for
+ * stream map details.
+ *
+ * This kind of stream is generally used to reprocess data into higher
+ * quality images (that otherwise would cause a frame rate performance
+ * loss), or to do off-line reprocessing.
+ *
+ * CAMERA_DEVICE_API_VERSION_3_3:
+ * The typical use cases are OPAQUE (typically ZSL) and YUV reprocessing,
+ * see S8.2, S8.3 and S10 for more details.
+ */
+ CAMERA3_STREAM_INPUT = 1,
+
+ /**
+ * This stream can be used for input and output. Typically, the stream is
+ * used as an output stream, but occasionally one already-filled buffer may
+ * be sent back to the HAL device for reprocessing.
+ *
+ * This kind of stream is meant generally for Zero Shutter Lag (ZSL)
+ * features, where copying the captured image from the output buffer to the
+ * reprocessing input buffer would be expensive. See S8.1 for more details.
+ *
+ * Note that the HAL will always be reprocessing data it produced.
+ *
+ */
+ CAMERA3_STREAM_BIDIRECTIONAL = 2,
+
+ /**
+ * Total number of framework-defined stream types
+ */
+ CAMERA3_NUM_STREAM_TYPES
+
+} camera3_stream_type_t;
+
+/**
+ * camera3_stream_rotation_t:
+ *
+ * The required counterclockwise rotation of camera stream.
+ */
+typedef enum camera3_stream_rotation {
+ /* No rotation */
+ CAMERA3_STREAM_ROTATION_0 = 0,
+
+ /* Rotate by 90 degree counterclockwise */
+ CAMERA3_STREAM_ROTATION_90 = 1,
+
+ /* Rotate by 180 degree counterclockwise */
+ CAMERA3_STREAM_ROTATION_180 = 2,
+
+ /* Rotate by 270 degree counterclockwise */
+ CAMERA3_STREAM_ROTATION_270 = 3
+} camera3_stream_rotation_t;
+
+/**
+ * camera3_stream_configuration_mode_t:
+ *
+ * This defines the general operation mode for the HAL (for a given stream configuration), where
+ * modes besides NORMAL have different semantics, and usually limit the generality of the API in
+ * exchange for higher performance in some particular area.
+ */
+typedef enum camera3_stream_configuration_mode {
+ /**
+ * Normal stream configuration operation mode. This is the default camera operation mode,
+ * where all semantics of HAL APIs and metadata controls apply.
+ */
+ CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE = 0,
+
+ /**
+ * Special constrained high speed operation mode for devices that can not support high
+ * speed output in NORMAL mode. All streams in this configuration are operating at high speed
+ * mode and have different characteristics and limitations to achieve high speed output.
+ * The NORMAL mode can still be used for high speed output if the HAL can support high speed
+ * output while satisfying all the semantics of HAL APIs and metadata controls. It is
+ * recommended for the HAL to support high speed output in NORMAL mode (by advertising the high
+ * speed FPS ranges in android.control.aeAvailableTargetFpsRanges) if possible.
+ *
+ * This mode has below limitations/requirements:
+ *
+ * 1. The HAL must support up to 2 streams with sizes reported by
+ * android.control.availableHighSpeedVideoConfigurations.
+ * 2. In this mode, the HAL is expected to output up to 120fps or higher. This mode must
+ * support the targeted FPS range and size configurations reported by
+ * android.control.availableHighSpeedVideoConfigurations.
+ * 3. The HAL must support HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED output stream format.
+ * 4. To achieve efficient high speed streaming, the HAL may have to aggregate
+ * multiple frames together and send to camera device for processing where the request
+ * controls are same for all the frames in this batch (batch mode). The HAL must support
+ * max batch size and the max batch size requirements defined by
+ * android.control.availableHighSpeedVideoConfigurations.
+ * 5. In this mode, the HAL must override aeMode, awbMode, and afMode to ON, ON, and
+ * CONTINUOUS_VIDEO, respectively. All post-processing block mode controls must be
+ * overridden to be FAST. Therefore, no manual control of capture and post-processing
+ * parameters is possible. All other controls operate the same as when
+ * android.control.mode == AUTO. This means that all other android.control.* fields
+ * must continue to work, such as
+ *
+ * android.control.aeTargetFpsRange
+ * android.control.aeExposureCompensation
+ * android.control.aeLock
+ * android.control.awbLock
+ * android.control.effectMode
+ * android.control.aeRegions
+ * android.control.afRegions
+ * android.control.awbRegions
+ * android.control.afTrigger
+ * android.control.aePrecaptureTrigger
+ *
+ * Outside of android.control.*, the following controls must work:
+ *
+ * android.flash.mode (TORCH mode only, automatic flash for still capture will not work
+ * since aeMode is ON)
+ * android.lens.opticalStabilizationMode (if it is supported)
+ * android.scaler.cropRegion
+ * android.statistics.faceDetectMode (if it is supported)
+ *
+ * For more details about high speed stream requirements, see
+ * android.control.availableHighSpeedVideoConfigurations and CONSTRAINED_HIGH_SPEED_VIDEO
+ * capability defined in android.request.availableCapabilities.
+ *
+ * This mode only needs to be supported by HALs that include CONSTRAINED_HIGH_SPEED_VIDEO in
+ * the android.request.availableCapabilities static metadata.
+ */
+ CAMERA3_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE = 1,
+
+ /**
+ * First value for vendor-defined stream configuration modes.
+ */
+ CAMERA3_VENDOR_STREAM_CONFIGURATION_MODE_START = 0x8000
+} camera3_stream_configuration_mode_t;
+
+/**
+ * camera3_stream_t:
+ *
+ * A handle to a single camera input or output stream. A stream is defined by
+ * the framework by its buffer resolution and format, and additionally by the
+ * HAL with the gralloc usage flags and the maximum in-flight buffer count.
+ *
+ * The stream structures are owned by the framework, but pointers to a
+ * camera3_stream passed into the HAL by configure_streams() are valid until the
+ * end of the first subsequent configure_streams() call that _does not_ include
+ * that camera3_stream as an argument, or until the end of the close() call.
+ *
+ * All camera3_stream framework-controlled members are immutable once the
+ * camera3_stream is passed into configure_streams(). The HAL may only change
+ * the HAL-controlled parameters during a configure_streams() call, except for
+ * the contents of the private pointer.
+ *
+ * If a configure_streams() call returns a non-fatal error, all active streams
+ * remain valid as if configure_streams() had not been called.
+ *
+ * The endpoint of the stream is not visible to the camera HAL device.
+ * In DEVICE_API_VERSION_3_1, this was changed to share consumer usage flags
+ * on streams where the camera is a producer (OUTPUT and BIDIRECTIONAL stream
+ * types) see the usage field below.
+ */
+typedef struct camera3_stream {
+
+ /*****
+ * Set by framework before configure_streams()
+ */
+
+ /**
+ * The type of the stream, one of the camera3_stream_type_t values.
+ */
+ int stream_type;
+
+ /**
+ * The width in pixels of the buffers in this stream
+ */
+ uint32_t width;
+
+ /**
+ * The height in pixels of the buffers in this stream
+ */
+ uint32_t height;
+
+ /**
+ * The pixel format for the buffers in this stream. Format is a value from
+ * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
+ * from device-specific headers.
+ *
+ * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
+ * gralloc module will select a format based on the usage flags provided by
+ * the camera device and the other endpoint of the stream.
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * The camera HAL device must inspect the buffers handed to it in the
+ * subsequent register_stream_buffers() call to obtain the
+ * implementation-specific format details, if necessary.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * register_stream_buffers() won't be called by the framework, so the HAL
+ * should configure the ISP and sensor pipeline based purely on the sizes,
+ * usage flags, and formats for the configured streams.
+ */
+ int format;
+
+ /*****
+ * Set by HAL during configure_streams().
+ */
+
+ /**
+ * The gralloc usage flags for this stream, as needed by the HAL. The usage
+ * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
+ * headers.
+ *
+ * For output streams, these are the HAL's producer usage flags. For input
+ * streams, these are the HAL's consumer usage flags. The usage flags from
+ * the producer and the consumer will be combined together and then passed
+ * to the platform gralloc HAL module for allocating the gralloc buffers for
+ * each stream.
+ *
+ * Version information:
+ *
+ * == CAMERA_DEVICE_API_VERSION_3_0:
+ *
+ * No initial value guaranteed when passed via configure_streams().
+ * HAL may not use this field as input, and must write over this field
+ * with its usage flags.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * For stream_type OUTPUT and BIDIRECTIONAL, when passed via
+ * configure_streams(), the initial value of this is the consumer's
+ * usage flags. The HAL may use these consumer flags to decide stream
+ * configuration.
+ * For stream_type INPUT, when passed via configure_streams(), the initial
+ * value of this is 0.
+ * For all streams passed via configure_streams(), the HAL must write
+ * over this field with its usage flags.
+ */
+ uint32_t usage;
+
+ /**
+ * The maximum number of buffers the HAL device may need to have dequeued at
+ * the same time. The HAL device may not have more buffers in-flight from
+ * this stream than this value.
+ */
+ uint32_t max_buffers;
+
+ /**
+ * A handle to HAL-private information for the stream. Will not be inspected
+ * by the framework code.
+ */
+ void *priv;
+
+ /**
+ * A field that describes the contents of the buffer. The format and buffer
+ * dimensions define the memory layout and structure of the stream buffers,
+ * while dataSpace defines the meaning of the data within the buffer.
+ *
+ * For most formats, dataSpace defines the color space of the image data.
+ * In addition, for some formats, dataSpace indicates whether image- or
+ * depth-based data is requested. See system/core/include/system/graphics.h
+ * for details of formats and valid dataSpace values for each format.
+ *
+ * Version information:
+ *
+ * < CAMERA_DEVICE_API_VERSION_3_3:
+ *
+ * Not defined and should not be accessed. dataSpace should be assumed to
+ * be HAL_DATASPACE_UNKNOWN, and the appropriate color space, etc, should
+ * be determined from the usage flags and the format.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_3:
+ *
+ * Always set by the camera service. HAL must use this dataSpace to
+ * configure the stream to the correct colorspace, or to select between
+ * color and depth outputs if supported.
+ */
+ android_dataspace_t data_space;
+
+ /**
+ * The required output rotation of the stream, one of
+ * the camera3_stream_rotation_t values. This must be inspected by HAL along
+ * with stream width and height. For example, if the rotation is 90 degree
+ * and the stream width and height is 720 and 1280 respectively, camera service
+ * will supply buffers of size 720x1280, and HAL should capture a 1280x720 image
+ * and rotate the image by 90 degree counterclockwise. The rotation field is
+ * no-op when the stream type is input. Camera HAL must ignore the rotation
+ * field for an input stream.
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * Not defined and must not be accessed. HAL must not apply any rotation
+ * on output images.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_3:
+ *
+ * Always set by camera service. HAL must inspect this field during stream
+ * configuration and returns -EINVAL if HAL cannot perform such rotation.
+ * HAL must always support CAMERA3_STREAM_ROTATION_0, so a
+ * configure_streams() call must not fail for unsupported rotation if
+ * rotation field of all streams is CAMERA3_STREAM_ROTATION_0.
+ *
+ */
+ int rotation;
+
+ /* reserved for future use */
+ void *reserved[7];
+
+} camera3_stream_t;
+
+/**
+ * camera3_stream_configuration_t:
+ *
+ * A structure of stream definitions, used by configure_streams(). This
+ * structure defines all the output streams and the reprocessing input
+ * stream for the current camera use case.
+ */
+typedef struct camera3_stream_configuration {
+ /**
+ * The total number of streams requested by the framework. This includes
+ * both input and output streams. The number of streams will be at least 1,
+ * and there will be at least one output-capable stream.
+ */
+ uint32_t num_streams;
+
+ /**
+ * An array of camera stream pointers, defining the input/output
+ * configuration for the camera HAL device.
+ *
+ * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
+ * in a single configuration.
+ *
+ * At least one output-capable stream must be defined (OUTPUT or
+ * BIDIRECTIONAL).
+ */
+ camera3_stream_t **streams;
+
+ /**
+ * >= CAMERA_DEVICE_API_VERSION_3_3:
+ *
+ * The operation mode of streams in this configuration, one of the value defined in
+ * camera3_stream_configuration_mode_t.
+ * The HAL can use this mode as an indicator to set the stream property (e.g.,
+ * camera3_stream->max_buffers) appropriately. For example, if the configuration is
+ * CAMERA3_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE, the HAL may want to set aside more
+ * buffers for batch mode operation (see android.control.availableHighSpeedVideoConfigurations
+ * for batch mode definition).
+ *
+ */
+ uint32_t operation_mode;
+} camera3_stream_configuration_t;
+
+/**
+ * camera3_buffer_status_t:
+ *
+ * The current status of a single stream buffer.
+ */
+typedef enum camera3_buffer_status {
+ /**
+ * The buffer is in a normal state, and can be used after waiting on its
+ * sync fence.
+ */
+ CAMERA3_BUFFER_STATUS_OK = 0,
+
+ /**
+ * The buffer does not contain valid data, and the data in it should not be
+ * used. The sync fence must still be waited on before reusing the buffer.
+ */
+ CAMERA3_BUFFER_STATUS_ERROR = 1
+
+} camera3_buffer_status_t;
+
+/**
+ * camera3_stream_buffer_t:
+ *
+ * A single buffer from a camera3 stream. It includes a handle to its parent
+ * stream, the handle to the gralloc buffer itself, and sync fences
+ *
+ * The buffer does not specify whether it is to be used for input or output;
+ * that is determined by its parent stream type and how the buffer is passed to
+ * the HAL device.
+ */
+typedef struct camera3_stream_buffer {
+ /**
+ * The handle of the stream this buffer is associated with
+ */
+ camera3_stream_t *stream;
+
+ /**
+ * The native handle to the buffer
+ */
+ buffer_handle_t *buffer;
+
+ /**
+ * Current state of the buffer, one of the camera3_buffer_status_t
+ * values. The framework will not pass buffers to the HAL that are in an
+ * error state. In case a buffer could not be filled by the HAL, it must
+ * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
+ * framework with process_capture_result().
+ */
+ int status;
+
+ /**
+ * The acquire sync fence for this buffer. The HAL must wait on this fence
+ * fd before attempting to read from or write to this buffer.
+ *
+ * The framework may be set to -1 to indicate that no waiting is necessary
+ * for this buffer.
+ *
+ * When the HAL returns an output buffer to the framework with
+ * process_capture_result(), the acquire_fence must be set to -1. If the HAL
+ * never waits on the acquire_fence due to an error in filling a buffer,
+ * when calling process_capture_result() the HAL must set the release_fence
+ * of the buffer to be the acquire_fence passed to it by the framework. This
+ * will allow the framework to wait on the fence before reusing the buffer.
+ *
+ * For input buffers, the HAL must not change the acquire_fence field during
+ * the process_capture_request() call.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * When the HAL returns an input buffer to the framework with
+ * process_capture_result(), the acquire_fence must be set to -1. If the HAL
+ * never waits on input buffer acquire fence due to an error, the sync
+ * fences should be handled similarly to the way they are handled for output
+ * buffers.
+ */
+ int acquire_fence;
+
+ /**
+ * The release sync fence for this buffer. The HAL must set this fence when
+ * returning buffers to the framework, or write -1 to indicate that no
+ * waiting is required for this buffer.
+ *
+ * For the output buffers, the fences must be set in the output_buffers
+ * array passed to process_capture_result().
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * For the input buffer, the release fence must be set by the
+ * process_capture_request() call.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * For the input buffer, the fences must be set in the input_buffer
+ * passed to process_capture_result().
+ *
+ * After signaling the release_fence for this buffer, the HAL
+ * should not make any further attempts to access this buffer as the
+ * ownership has been fully transferred back to the framework.
+ *
+ * If a fence of -1 was specified then the ownership of this buffer
+ * is transferred back immediately upon the call of process_capture_result.
+ */
+ int release_fence;
+
+} camera3_stream_buffer_t;
+
+/**
+ * camera3_stream_buffer_set_t:
+ *
+ * The complete set of gralloc buffers for a stream. This structure is given to
+ * register_stream_buffers() to allow the camera HAL device to register/map/etc
+ * newly allocated stream buffers.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * Deprecated (and not used). In particular,
+ * register_stream_buffers is also deprecated and will never be invoked.
+ *
+ */
+typedef struct camera3_stream_buffer_set {
+ /**
+ * The stream handle for the stream these buffers belong to
+ */
+ camera3_stream_t *stream;
+
+ /**
+ * The number of buffers in this stream. It is guaranteed to be at least
+ * stream->max_buffers.
+ */
+ uint32_t num_buffers;
+
+ /**
+ * The array of gralloc buffer handles for this stream. If the stream format
+ * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
+ * should inspect the passed-in buffers to determine any platform-private
+ * pixel format information.
+ */
+ buffer_handle_t **buffers;
+
+} camera3_stream_buffer_set_t;
+
+/**
+ * camera3_jpeg_blob:
+ *
+ * Transport header for compressed JPEG buffers in output streams.
+ *
+ * To capture JPEG images, a stream is created using the pixel format
+ * HAL_PIXEL_FORMAT_BLOB. The buffer size for the stream is calculated by the
+ * framework, based on the static metadata field android.jpeg.maxSize. Since
+ * compressed JPEG images are of variable size, the HAL needs to include the
+ * final size of the compressed image using this structure inside the output
+ * stream buffer. The JPEG blob ID field must be set to CAMERA3_JPEG_BLOB_ID.
+ *
+ * Transport header should be at the end of the JPEG output stream buffer. That
+ * means the jpeg_blob_id must start at byte[buffer_size -
+ * sizeof(camera3_jpeg_blob)], where the buffer_size is the size of gralloc buffer.
+ * Any HAL using this transport header must account for it in android.jpeg.maxSize
+ * The JPEG data itself starts at the beginning of the buffer and should be
+ * jpeg_size bytes long.
+ */
+typedef struct camera3_jpeg_blob {
+ uint16_t jpeg_blob_id;
+ uint32_t jpeg_size;
+} camera3_jpeg_blob_t;
+
+enum {
+ CAMERA3_JPEG_BLOB_ID = 0x00FF
+};
+
+/**********************************************************************
+ *
+ * Message definitions for the HAL notify() callback.
+ *
+ * These definitions are used for the HAL notify callback, to signal
+ * asynchronous events from the HAL device to the Android framework.
+ *
+ */
+
+/**
+ * camera3_msg_type:
+ *
+ * Indicates the type of message sent, which specifies which member of the
+ * message union is valid.
+ *
+ */
+typedef enum camera3_msg_type {
+ /**
+ * An error has occurred. camera3_notify_msg.message.error contains the
+ * error information.
+ */
+ CAMERA3_MSG_ERROR = 1,
+
+ /**
+ * The exposure of a given request or processing a reprocess request has
+ * begun. camera3_notify_msg.message.shutter contains the information
+ * the capture.
+ */
+ CAMERA3_MSG_SHUTTER = 2,
+
+ /**
+ * Number of framework message types
+ */
+ CAMERA3_NUM_MESSAGES
+
+} camera3_msg_type_t;
+
+/**
+ * Defined error codes for CAMERA_MSG_ERROR
+ */
+typedef enum camera3_error_msg_code {
+ /**
+ * A serious failure occured. No further frames or buffer streams will
+ * be produced by the device. Device should be treated as closed. The
+ * client must reopen the device to use it again. The frame_number field
+ * is unused.
+ */
+ CAMERA3_MSG_ERROR_DEVICE = 1,
+
+ /**
+ * An error has occurred in processing a request. No output (metadata or
+ * buffers) will be produced for this request. The frame_number field
+ * specifies which request has been dropped. Subsequent requests are
+ * unaffected, and the device remains operational.
+ */
+ CAMERA3_MSG_ERROR_REQUEST = 2,
+
+ /**
+ * An error has occurred in producing an output result metadata buffer
+ * for a request, but output stream buffers for it will still be
+ * available. Subsequent requests are unaffected, and the device remains
+ * operational. The frame_number field specifies the request for which
+ * result metadata won't be available.
+ */
+ CAMERA3_MSG_ERROR_RESULT = 3,
+
+ /**
+ * An error has occurred in placing an output buffer into a stream for a
+ * request. The frame metadata and other buffers may still be
+ * available. Subsequent requests are unaffected, and the device remains
+ * operational. The frame_number field specifies the request for which the
+ * buffer was dropped, and error_stream contains a pointer to the stream
+ * that dropped the frame.u
+ */
+ CAMERA3_MSG_ERROR_BUFFER = 4,
+
+ /**
+ * Number of error types
+ */
+ CAMERA3_MSG_NUM_ERRORS
+
+} camera3_error_msg_code_t;
+
+/**
+ * camera3_error_msg_t:
+ *
+ * Message contents for CAMERA3_MSG_ERROR
+ */
+typedef struct camera3_error_msg {
+ /**
+ * Frame number of the request the error applies to. 0 if the frame number
+ * isn't applicable to the error.
+ */
+ uint32_t frame_number;
+
+ /**
+ * Pointer to the stream that had a failure. NULL if the stream isn't
+ * applicable to the error.
+ */
+ camera3_stream_t *error_stream;
+
+ /**
+ * The code for this error; one of the CAMERA_MSG_ERROR enum values.
+ */
+ int error_code;
+
+} camera3_error_msg_t;
+
+/**
+ * camera3_shutter_msg_t:
+ *
+ * Message contents for CAMERA3_MSG_SHUTTER
+ */
+typedef struct camera3_shutter_msg {
+ /**
+ * Frame number of the request that has begun exposure or reprocessing.
+ */
+ uint32_t frame_number;
+
+ /**
+ * Timestamp for the start of capture. For a reprocess request, this must
+ * be input image's start of capture. This must match the capture result
+ * metadata's sensor exposure start timestamp.
+ */
+ uint64_t timestamp;
+
+} camera3_shutter_msg_t;
+
+/**
+ * camera3_notify_msg_t:
+ *
+ * The message structure sent to camera3_callback_ops_t.notify()
+ */
+typedef struct camera3_notify_msg {
+
+ /**
+ * The message type. One of camera3_notify_msg_type, or a private extension.
+ */
+ int type;
+
+ union {
+ /**
+ * Error message contents. Valid if type is CAMERA3_MSG_ERROR
+ */
+ camera3_error_msg_t error;
+
+ /**
+ * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
+ */
+ camera3_shutter_msg_t shutter;
+
+ /**
+ * Generic message contents. Used to ensure a minimum size for custom
+ * message types.
+ */
+ uint8_t generic[32];
+ } message;
+
+} camera3_notify_msg_t;
+
+/**********************************************************************
+ *
+ * Capture request/result definitions for the HAL process_capture_request()
+ * method, and the process_capture_result() callback.
+ *
+ */
+
+/**
+ * camera3_request_template_t:
+ *
+ * Available template types for
+ * camera3_device_ops.construct_default_request_settings()
+ */
+typedef enum camera3_request_template {
+ /**
+ * Standard camera preview operation with 3A on auto.
+ */
+ CAMERA3_TEMPLATE_PREVIEW = 1,
+
+ /**
+ * Standard camera high-quality still capture with 3A and flash on auto.
+ */
+ CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
+
+ /**
+ * Standard video recording plus preview with 3A on auto, torch off.
+ */
+ CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
+
+ /**
+ * High-quality still capture while recording video. Application will
+ * include preview, video record, and full-resolution YUV or JPEG streams in
+ * request. Must not cause stuttering on video stream. 3A on auto.
+ */
+ CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
+
+ /**
+ * Zero-shutter-lag mode. Application will request preview and
+ * full-resolution data for each frame, and reprocess it to JPEG when a
+ * still image is requested by user. Settings should provide highest-quality
+ * full-resolution images without compromising preview frame rate. 3A on
+ * auto.
+ */
+ CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
+
+ /**
+ * A basic template for direct application control of capture
+ * parameters. All automatic control is disabled (auto-exposure, auto-white
+ * balance, auto-focus), and post-processing parameters are set to preview
+ * quality. The manual capture parameters (exposure, sensitivity, etc.)
+ * are set to reasonable defaults, but should be overridden by the
+ * application depending on the intended use case.
+ */
+ CAMERA3_TEMPLATE_MANUAL = 6,
+
+ /* Total number of templates */
+ CAMERA3_TEMPLATE_COUNT,
+
+ /**
+ * First value for vendor-defined request templates
+ */
+ CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
+
+} camera3_request_template_t;
+
+/**
+ * camera3_capture_request_t:
+ *
+ * A single request for image capture/buffer reprocessing, sent to the Camera
+ * HAL device by the framework in process_capture_request().
+ *
+ * The request contains the settings to be used for this capture, and the set of
+ * output buffers to write the resulting image data in. It may optionally
+ * contain an input buffer, in which case the request is for reprocessing that
+ * input buffer instead of capturing a new image with the camera sensor. The
+ * capture is identified by the frame_number.
+ *
+ * In response, the camera HAL device must send a camera3_capture_result
+ * structure asynchronously to the framework, using the process_capture_result()
+ * callback.
+ */
+typedef struct camera3_capture_request {
+ /**
+ * The frame number is an incrementing integer set by the framework to
+ * uniquely identify this capture. It needs to be returned in the result
+ * call, and is also used to identify the request in asynchronous
+ * notifications sent to camera3_callback_ops_t.notify().
+ */
+ uint32_t frame_number;
+
+ /**
+ * The settings buffer contains the capture and processing parameters for
+ * the request. As a special case, a NULL settings buffer indicates that the
+ * settings are identical to the most-recently submitted capture request. A
+ * NULL buffer cannot be used as the first submitted request after a
+ * configure_streams() call.
+ */
+ const camera_metadata_t *settings;
+
+ /**
+ * The input stream buffer to use for this request, if any.
+ *
+ * If input_buffer is NULL, then the request is for a new capture from the
+ * imager. If input_buffer is valid, the request is for reprocessing the
+ * image contained in input_buffer.
+ *
+ * In the latter case, the HAL must set the release_fence of the
+ * input_buffer to a valid sync fence, or to -1 if the HAL does not support
+ * sync, before process_capture_request() returns.
+ *
+ * The HAL is required to wait on the acquire sync fence of the input buffer
+ * before accessing it.
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * Any input buffer included here will have been registered with the HAL
+ * through register_stream_buffers() before its inclusion in a request.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * The buffers will not have been pre-registered with the HAL.
+ * Subsequent requests may reuse buffers, or provide entirely new buffers.
+ */
+ camera3_stream_buffer_t *input_buffer;
+
+ /**
+ * The number of output buffers for this capture request. Must be at least
+ * 1.
+ */
+ uint32_t num_output_buffers;
+
+ /**
+ * An array of num_output_buffers stream buffers, to be filled with image
+ * data from this capture/reprocess. The HAL must wait on the acquire fences
+ * of each stream buffer before writing to them.
+ *
+ * The HAL takes ownership of the actual buffer_handle_t entries in
+ * output_buffers; the framework does not access them until they are
+ * returned in a camera3_capture_result_t.
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * All the buffers included here will have been registered with the HAL
+ * through register_stream_buffers() before their inclusion in a request.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * Any or all of the buffers included here may be brand new in this
+ * request (having never before seen by the HAL).
+ */
+ const camera3_stream_buffer_t *output_buffers;
+
+} camera3_capture_request_t;
+
+/**
+ * camera3_capture_result_t:
+ *
+ * The result of a single capture/reprocess by the camera HAL device. This is
+ * sent to the framework asynchronously with process_capture_result(), in
+ * response to a single capture request sent to the HAL with
+ * process_capture_request(). Multiple process_capture_result() calls may be
+ * performed by the HAL for each request.
+ *
+ * Each call, all with the same frame
+ * number, may contain some subset of the output buffers, and/or the result
+ * metadata. The metadata may only be provided once for a given frame number;
+ * all other calls must set the result metadata to NULL.
+ *
+ * The result structure contains the output metadata from this capture, and the
+ * set of output buffers that have been/will be filled for this capture. Each
+ * output buffer may come with a release sync fence that the framework will wait
+ * on before reading, in case the buffer has not yet been filled by the HAL.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * The metadata may be provided multiple times for a single frame number. The
+ * framework will accumulate together the final result set by combining each
+ * partial result together into the total result set.
+ *
+ * If an input buffer is given in a request, the HAL must return it in one of
+ * the process_capture_result calls, and the call may be to just return the input
+ * buffer, without metadata and output buffers; the sync fences must be handled
+ * the same way they are done for output buffers.
+ *
+ *
+ * Performance considerations:
+ *
+ * Applications will also receive these partial results immediately, so sending
+ * partial results is a highly recommended performance optimization to avoid
+ * the total pipeline latency before sending the results for what is known very
+ * early on in the pipeline.
+ *
+ * A typical use case might be calculating the AF state halfway through the
+ * pipeline; by sending the state back to the framework immediately, we get a
+ * 50% performance increase and perceived responsiveness of the auto-focus.
+ *
+ */
+typedef struct camera3_capture_result {
+ /**
+ * The frame number is an incrementing integer set by the framework in the
+ * submitted request to uniquely identify this capture. It is also used to
+ * identify the request in asynchronous notifications sent to
+ * camera3_callback_ops_t.notify().
+ */
+ uint32_t frame_number;
+
+ /**
+ * The result metadata for this capture. This contains information about the
+ * final capture parameters, the state of the capture and post-processing
+ * hardware, the state of the 3A algorithms, if enabled, and the output of
+ * any enabled statistics units.
+ *
+ * Only one call to process_capture_result() with a given frame_number may
+ * include the result metadata. All other calls for the same frame_number
+ * must set this to NULL.
+ *
+ * If there was an error producing the result metadata, result must be an
+ * empty metadata buffer, and notify() must be called with ERROR_RESULT.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * Multiple calls to process_capture_result() with a given frame_number
+ * may include the result metadata.
+ *
+ * Partial metadata submitted should not include any metadata key returned
+ * in a previous partial result for a given frame. Each new partial result
+ * for that frame must also set a distinct partial_result value.
+ *
+ * If notify has been called with ERROR_RESULT, all further partial
+ * results for that frame are ignored by the framework.
+ */
+ const camera_metadata_t *result;
+
+ /**
+ * The number of output buffers returned in this result structure. Must be
+ * less than or equal to the matching capture request's count. If this is
+ * less than the buffer count in the capture request, at least one more call
+ * to process_capture_result with the same frame_number must be made, to
+ * return the remaining output buffers to the framework. This may only be
+ * zero if the structure includes valid result metadata or an input buffer
+ * is returned in this result.
+ */
+ uint32_t num_output_buffers;
+
+ /**
+ * The handles for the output stream buffers for this capture. They may not
+ * yet be filled at the time the HAL calls process_capture_result(); the
+ * framework will wait on the release sync fences provided by the HAL before
+ * reading the buffers.
+ *
+ * The HAL must set the stream buffer's release sync fence to a valid sync
+ * fd, or to -1 if the buffer has already been filled.
+ *
+ * If the HAL encounters an error while processing the buffer, and the
+ * buffer is not filled, the buffer's status field must be set to
+ * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
+ * before encountering the error, the acquire fence should be copied into
+ * the release fence, to allow the framework to wait on the fence before
+ * reusing the buffer.
+ *
+ * The acquire fence must be set to -1 for all output buffers. If
+ * num_output_buffers is zero, this may be NULL. In that case, at least one
+ * more process_capture_result call must be made by the HAL to provide the
+ * output buffers.
+ *
+ * When process_capture_result is called with a new buffer for a frame,
+ * all previous frames' buffers for that corresponding stream must have been
+ * already delivered (the fences need not have yet been signaled).
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * Gralloc buffers for a frame may be sent to framework before the
+ * corresponding SHUTTER-notify.
+ *
+ * Performance considerations:
+ *
+ * Buffers delivered to the framework will not be dispatched to the
+ * application layer until a start of exposure timestamp has been received
+ * via a SHUTTER notify() call. It is highly recommended to
+ * dispatch that call as early as possible.
+ */
+ const camera3_stream_buffer_t *output_buffers;
+
+ /**
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * The handle for the input stream buffer for this capture. It may not
+ * yet be consumed at the time the HAL calls process_capture_result(); the
+ * framework will wait on the release sync fences provided by the HAL before
+ * reusing the buffer.
+ *
+ * The HAL should handle the sync fences the same way they are done for
+ * output_buffers.
+ *
+ * Only one input buffer is allowed to be sent per request. Similarly to
+ * output buffers, the ordering of returned input buffers must be
+ * maintained by the HAL.
+ *
+ * Performance considerations:
+ *
+ * The input buffer should be returned as early as possible. If the HAL
+ * supports sync fences, it can call process_capture_result to hand it back
+ * with sync fences being set appropriately. If the sync fences are not
+ * supported, the buffer can only be returned when it is consumed, which
+ * may take long time; the HAL may choose to copy this input buffer to make
+ * the buffer return sooner.
+ */
+ const camera3_stream_buffer_t *input_buffer;
+
+ /**
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * In order to take advantage of partial results, the HAL must set the
+ * static metadata android.request.partialResultCount to the number of
+ * partial results it will send for each frame.
+ *
+ * Each new capture result with a partial result must set
+ * this field (partial_result) to a distinct inclusive value between
+ * 1 and android.request.partialResultCount.
+ *
+ * HALs not wishing to take advantage of this feature must not
+ * set an android.request.partialResultCount or partial_result to a value
+ * other than 1.
+ *
+ * This value must be set to 0 when a capture result contains buffers only
+ * and no metadata.
+ */
+ uint32_t partial_result;
+
+} camera3_capture_result_t;
+
+/**********************************************************************
+ *
+ * Callback methods for the HAL to call into the framework.
+ *
+ * These methods are used to return metadata and image buffers for a completed
+ * or failed captures, and to notify the framework of asynchronous events such
+ * as errors.
+ *
+ * The framework will not call back into the HAL from within these callbacks,
+ * and these calls will not block for extended periods.
+ *
+ */
+typedef struct camera3_callback_ops {
+
+ /**
+ * process_capture_result:
+ *
+ * Send results from a completed capture to the framework.
+ * process_capture_result() may be invoked multiple times by the HAL in
+ * response to a single capture request. This allows, for example, the
+ * metadata and low-resolution buffers to be returned in one call, and
+ * post-processed JPEG buffers in a later call, once it is available. Each
+ * call must include the frame number of the request it is returning
+ * metadata or buffers for.
+ *
+ * A component (buffer or metadata) of the complete result may only be
+ * included in one process_capture_result call. A buffer for each stream,
+ * and the result metadata, must be returned by the HAL for each request in
+ * one of the process_capture_result calls, even in case of errors producing
+ * some of the output. A call to process_capture_result() with neither
+ * output buffers or result metadata is not allowed.
+ *
+ * The order of returning metadata and buffers for a single result does not
+ * matter, but buffers for a given stream must be returned in FIFO order. So
+ * the buffer for request 5 for stream A must always be returned before the
+ * buffer for request 6 for stream A. This also applies to the result
+ * metadata; the metadata for request 5 must be returned before the metadata
+ * for request 6.
+ *
+ * However, different streams are independent of each other, so it is
+ * acceptable and expected that the buffer for request 5 for stream A may be
+ * returned after the buffer for request 6 for stream B is. And it is
+ * acceptable that the result metadata for request 6 for stream B is
+ * returned before the buffer for request 5 for stream A is.
+ *
+ * The HAL retains ownership of result structure, which only needs to be
+ * valid to access during this call. The framework will copy whatever it
+ * needs before this call returns.
+ *
+ * The output buffers do not need to be filled yet; the framework will wait
+ * on the stream buffer release sync fence before reading the buffer
+ * data. Therefore, this method should be called by the HAL as soon as
+ * possible, even if some or all of the output buffers are still in
+ * being filled. The HAL must include valid release sync fences into each
+ * output_buffers stream buffer entry, or -1 if that stream buffer is
+ * already filled.
+ *
+ * If the result buffer cannot be constructed for a request, the HAL should
+ * return an empty metadata buffer, but still provide the output buffers and
+ * their sync fences. In addition, notify() must be called with an
+ * ERROR_RESULT message.
+ *
+ * If an output buffer cannot be filled, its status field must be set to
+ * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
+ * message.
+ *
+ * If the entire capture has failed, then this method still needs to be
+ * called to return the output buffers to the framework. All the buffer
+ * statuses should be STATUS_ERROR, and the result metadata should be an
+ * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
+ * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
+ * should not be sent.
+ *
+ * Performance requirements:
+ *
+ * This is a non-blocking call. The framework will return this call in 5ms.
+ *
+ * The pipeline latency (see S7 for definition) should be less than or equal to
+ * 4 frame intervals, and must be less than or equal to 8 frame intervals.
+ *
+ */
+ void (*process_capture_result)(const struct camera3_callback_ops *,
+ const camera3_capture_result_t *result);
+
+ /**
+ * notify:
+ *
+ * Asynchronous notification callback from the HAL, fired for various
+ * reasons. Only for information independent of frame capture, or that
+ * require specific timing. The ownership of the message structure remains
+ * with the HAL, and the msg only needs to be valid for the duration of this
+ * call.
+ *
+ * Multiple threads may call notify() simultaneously.
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * The notification for the start of exposure for a given request must be
+ * sent by the HAL before the first call to process_capture_result() for
+ * that request is made.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * Buffers delivered to the framework will not be dispatched to the
+ * application layer until a start of exposure timestamp (or input image's
+ * start of exposure timestamp for a reprocess request) has been received
+ * via a SHUTTER notify() call. It is highly recommended to dispatch this
+ * call as early as possible.
+ *
+ * ------------------------------------------------------------------------
+ * Performance requirements:
+ *
+ * This is a non-blocking call. The framework will return this call in 5ms.
+ */
+ void (*notify)(const struct camera3_callback_ops *,
+ const camera3_notify_msg_t *msg);
+
+} camera3_callback_ops_t;
+
+/**********************************************************************
+ *
+ * Camera device operations
+ *
+ */
+typedef struct camera3_device_ops {
+
+ /**
+ * initialize:
+ *
+ * One-time initialization to pass framework callback function pointers to
+ * the HAL. Will be called once after a successful open() call, before any
+ * other functions are called on the camera3_device_ops structure.
+ *
+ * Performance requirements:
+ *
+ * This should be a non-blocking call. The HAL should return from this call
+ * in 5ms, and must return from this call in 10ms.
+ *
+ * Return values:
+ *
+ * 0: On successful initialization
+ *
+ * -ENODEV: If initialization fails. Only close() can be called successfully
+ * by the framework after this.
+ */
+ int (*initialize)(const struct camera3_device *,
+ const camera3_callback_ops_t *callback_ops);
+
+ /**********************************************************************
+ * Stream management
+ */
+
+ /**
+ * configure_streams:
+ *
+ * CAMERA_DEVICE_API_VERSION_3_0 only:
+ *
+ * Reset the HAL camera device processing pipeline and set up new input and
+ * output streams. This call replaces any existing stream configuration with
+ * the streams defined in the stream_list. This method will be called at
+ * least once after initialize() before a request is submitted with
+ * process_capture_request().
+ *
+ * The stream_list must contain at least one output-capable stream, and may
+ * not contain more than one input-capable stream.
+ *
+ * The stream_list may contain streams that are also in the currently-active
+ * set of streams (from the previous call to configure_stream()). These
+ * streams will already have valid values for usage, max_buffers, and the
+ * private pointer.
+ *
+ * If such a stream has already had its buffers registered,
+ * register_stream_buffers() will not be called again for the stream, and
+ * buffers from the stream can be immediately included in input requests.
+ *
+ * If the HAL needs to change the stream configuration for an existing
+ * stream due to the new configuration, it may rewrite the values of usage
+ * and/or max_buffers during the configure call.
+ *
+ * The framework will detect such a change, and will then reallocate the
+ * stream buffers, and call register_stream_buffers() again before using
+ * buffers from that stream in a request.
+ *
+ * If a currently-active stream is not included in stream_list, the HAL may
+ * safely remove any references to that stream. It will not be reused in a
+ * later configure() call by the framework, and all the gralloc buffers for
+ * it will be freed after the configure_streams() call returns.
+ *
+ * The stream_list structure is owned by the framework, and may not be
+ * accessed once this call completes. The address of an individual
+ * camera3_stream_t structure will remain valid for access by the HAL until
+ * the end of the first configure_stream() call which no longer includes
+ * that camera3_stream_t in the stream_list argument. The HAL may not change
+ * values in the stream structure outside of the private pointer, except for
+ * the usage and max_buffers members during the configure_streams() call
+ * itself.
+ *
+ * If the stream is new, the usage, max_buffer, and private pointer fields
+ * of the stream structure will all be set to 0. The HAL device must set
+ * these fields before the configure_streams() call returns. These fields
+ * are then used by the framework and the platform gralloc module to
+ * allocate the gralloc buffers for each stream.
+ *
+ * Before such a new stream can have its buffers included in a capture
+ * request, the framework will call register_stream_buffers() with that
+ * stream. However, the framework is not required to register buffers for
+ * _all_ streams before submitting a request. This allows for quick startup
+ * of (for example) a preview stream, with allocation for other streams
+ * happening later or concurrently.
+ *
+ * ------------------------------------------------------------------------
+ * CAMERA_DEVICE_API_VERSION_3_1 only:
+ *
+ * Reset the HAL camera device processing pipeline and set up new input and
+ * output streams. This call replaces any existing stream configuration with
+ * the streams defined in the stream_list. This method will be called at
+ * least once after initialize() before a request is submitted with
+ * process_capture_request().
+ *
+ * The stream_list must contain at least one output-capable stream, and may
+ * not contain more than one input-capable stream.
+ *
+ * The stream_list may contain streams that are also in the currently-active
+ * set of streams (from the previous call to configure_stream()). These
+ * streams will already have valid values for usage, max_buffers, and the
+ * private pointer.
+ *
+ * If such a stream has already had its buffers registered,
+ * register_stream_buffers() will not be called again for the stream, and
+ * buffers from the stream can be immediately included in input requests.
+ *
+ * If the HAL needs to change the stream configuration for an existing
+ * stream due to the new configuration, it may rewrite the values of usage
+ * and/or max_buffers during the configure call.
+ *
+ * The framework will detect such a change, and will then reallocate the
+ * stream buffers, and call register_stream_buffers() again before using
+ * buffers from that stream in a request.
+ *
+ * If a currently-active stream is not included in stream_list, the HAL may
+ * safely remove any references to that stream. It will not be reused in a
+ * later configure() call by the framework, and all the gralloc buffers for
+ * it will be freed after the configure_streams() call returns.
+ *
+ * The stream_list structure is owned by the framework, and may not be
+ * accessed once this call completes. The address of an individual
+ * camera3_stream_t structure will remain valid for access by the HAL until
+ * the end of the first configure_stream() call which no longer includes
+ * that camera3_stream_t in the stream_list argument. The HAL may not change
+ * values in the stream structure outside of the private pointer, except for
+ * the usage and max_buffers members during the configure_streams() call
+ * itself.
+ *
+ * If the stream is new, max_buffer, and private pointer fields of the
+ * stream structure will all be set to 0. The usage will be set to the
+ * consumer usage flags. The HAL device must set these fields before the
+ * configure_streams() call returns. These fields are then used by the
+ * framework and the platform gralloc module to allocate the gralloc
+ * buffers for each stream.
+ *
+ * Before such a new stream can have its buffers included in a capture
+ * request, the framework will call register_stream_buffers() with that
+ * stream. However, the framework is not required to register buffers for
+ * _all_ streams before submitting a request. This allows for quick startup
+ * of (for example) a preview stream, with allocation for other streams
+ * happening later or concurrently.
+ *
+ * ------------------------------------------------------------------------
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * Reset the HAL camera device processing pipeline and set up new input and
+ * output streams. This call replaces any existing stream configuration with
+ * the streams defined in the stream_list. This method will be called at
+ * least once after initialize() before a request is submitted with
+ * process_capture_request().
+ *
+ * The stream_list must contain at least one output-capable stream, and may
+ * not contain more than one input-capable stream.
+ *
+ * The stream_list may contain streams that are also in the currently-active
+ * set of streams (from the previous call to configure_stream()). These
+ * streams will already have valid values for usage, max_buffers, and the
+ * private pointer.
+ *
+ * If the HAL needs to change the stream configuration for an existing
+ * stream due to the new configuration, it may rewrite the values of usage
+ * and/or max_buffers during the configure call.
+ *
+ * The framework will detect such a change, and may then reallocate the
+ * stream buffers before using buffers from that stream in a request.
+ *
+ * If a currently-active stream is not included in stream_list, the HAL may
+ * safely remove any references to that stream. It will not be reused in a
+ * later configure() call by the framework, and all the gralloc buffers for
+ * it will be freed after the configure_streams() call returns.
+ *
+ * The stream_list structure is owned by the framework, and may not be
+ * accessed once this call completes. The address of an individual
+ * camera3_stream_t structure will remain valid for access by the HAL until
+ * the end of the first configure_stream() call which no longer includes
+ * that camera3_stream_t in the stream_list argument. The HAL may not change
+ * values in the stream structure outside of the private pointer, except for
+ * the usage and max_buffers members during the configure_streams() call
+ * itself.
+ *
+ * If the stream is new, max_buffer, and private pointer fields of the
+ * stream structure will all be set to 0. The usage will be set to the
+ * consumer usage flags. The HAL device must set these fields before the
+ * configure_streams() call returns. These fields are then used by the
+ * framework and the platform gralloc module to allocate the gralloc
+ * buffers for each stream.
+ *
+ * Newly allocated buffers may be included in a capture request at any time
+ * by the framework. Once a gralloc buffer is returned to the framework
+ * with process_capture_result (and its respective release_fence has been
+ * signaled) the framework may free or reuse it at any time.
+ *
+ * ------------------------------------------------------------------------
+ *
+ * Preconditions:
+ *
+ * The framework will only call this method when no captures are being
+ * processed. That is, all results have been returned to the framework, and
+ * all in-flight input and output buffers have been returned and their
+ * release sync fences have been signaled by the HAL. The framework will not
+ * submit new requests for capture while the configure_streams() call is
+ * underway.
+ *
+ * Postconditions:
+ *
+ * The HAL device must configure itself to provide maximum possible output
+ * frame rate given the sizes and formats of the output streams, as
+ * documented in the camera device's static metadata.
+ *
+ * Performance requirements:
+ *
+ * This call is expected to be heavyweight and possibly take several hundred
+ * milliseconds to complete, since it may require resetting and
+ * reconfiguring the image sensor and the camera processing pipeline.
+ * Nevertheless, the HAL device should attempt to minimize the
+ * reconfiguration delay to minimize the user-visible pauses during
+ * application operational mode changes (such as switching from still
+ * capture to video recording).
+ *
+ * The HAL should return from this call in 500ms, and must return from this
+ * call in 1000ms.
+ *
+ * Return values:
+ *
+ * 0: On successful stream configuration
+ *
+ * -EINVAL: If the requested stream configuration is invalid. Some examples
+ * of invalid stream configurations include:
+ *
+ * - Including more than 1 input-capable stream (INPUT or
+ * BIDIRECTIONAL)
+ *
+ * - Not including any output-capable streams (OUTPUT or
+ * BIDIRECTIONAL)
+ *
+ * - Including streams with unsupported formats, or an unsupported
+ * size for that format.
+ *
+ * - Including too many output streams of a certain format.
+ *
+ * - Unsupported rotation configuration (only applies to
+ * devices with version >= CAMERA_DEVICE_API_VERSION_3_3)
+ *
+ * - Stream sizes/formats don't satisfy the
+ * camera3_stream_configuration_t->operation_mode requirements for non-NORMAL mode,
+ * or the requested operation_mode is not supported by the HAL.
+ * (only applies to devices with version >= CAMERA_DEVICE_API_VERSION_3_3)
+ *
+ * Note that the framework submitting an invalid stream
+ * configuration is not normal operation, since stream
+ * configurations are checked before configure. An invalid
+ * configuration means that a bug exists in the framework code, or
+ * there is a mismatch between the HAL's static metadata and the
+ * requirements on streams.
+ *
+ * -ENODEV: If there has been a fatal error and the device is no longer
+ * operational. Only close() can be called successfully by the
+ * framework after this error is returned.
+ */
+ int (*configure_streams)(const struct camera3_device *,
+ camera3_stream_configuration_t *stream_list);
+
+ /**
+ * register_stream_buffers:
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * DEPRECATED. This will not be called and must be set to NULL.
+ *
+ * <= CAMERA_DEVICE_API_VERSION_3_1:
+ *
+ * Register buffers for a given stream with the HAL device. This method is
+ * called by the framework after a new stream is defined by
+ * configure_streams, and before buffers from that stream are included in a
+ * capture request. If the same stream is listed in a subsequent
+ * configure_streams() call, register_stream_buffers will _not_ be called
+ * again for that stream.
+ *
+ * The framework does not need to register buffers for all configured
+ * streams before it submits the first capture request. This allows quick
+ * startup for preview (or similar use cases) while other streams are still
+ * being allocated.
+ *
+ * This method is intended to allow the HAL device to map or otherwise
+ * prepare the buffers for later use. The buffers passed in will already be
+ * locked for use. At the end of the call, all the buffers must be ready to
+ * be returned to the stream. The buffer_set argument is only valid for the
+ * duration of this call.
+ *
+ * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
+ * the camera HAL should inspect the passed-in buffers here to determine any
+ * platform-private pixel format information.
+ *
+ * Performance requirements:
+ *
+ * This should be a non-blocking call. The HAL should return from this call
+ * in 1ms, and must return from this call in 5ms.
+ *
+ * Return values:
+ *
+ * 0: On successful registration of the new stream buffers
+ *
+ * -EINVAL: If the stream_buffer_set does not refer to a valid active
+ * stream, or if the buffers array is invalid.
+ *
+ * -ENOMEM: If there was a failure in registering the buffers. The framework
+ * must consider all the stream buffers to be unregistered, and can
+ * try to register again later.
+ *
+ * -ENODEV: If there is a fatal error, and the device is no longer
+ * operational. Only close() can be called successfully by the
+ * framework after this error is returned.
+ */
+ int (*register_stream_buffers)(const struct camera3_device *,
+ const camera3_stream_buffer_set_t *buffer_set);
+
+ /**********************************************************************
+ * Request creation and submission
+ */
+
+ /**
+ * construct_default_request_settings:
+ *
+ * Create capture settings for standard camera use cases.
+ *
+ * The device must return a settings buffer that is configured to meet the
+ * requested use case, which must be one of the CAMERA3_TEMPLATE_*
+ * enums. All request control fields must be included.
+ *
+ * The HAL retains ownership of this structure, but the pointer to the
+ * structure must be valid until the device is closed. The framework and the
+ * HAL may not modify the buffer once it is returned by this call. The same
+ * buffer may be returned for subsequent calls for the same template, or for
+ * other templates.
+ *
+ * Performance requirements:
+ *
+ * This should be a non-blocking call. The HAL should return from this call
+ * in 1ms, and must return from this call in 5ms.
+ *
+ * Return values:
+ *
+ * Valid metadata: On successful creation of a default settings
+ * buffer.
+ *
+ * NULL: In case of a fatal error. After this is returned, only
+ * the close() method can be called successfully by the
+ * framework.
+ */
+ const camera_metadata_t* (*construct_default_request_settings)(
+ const struct camera3_device *,
+ int type);
+
+ /**
+ * process_capture_request:
+ *
+ * Send a new capture request to the HAL. The HAL should not return from
+ * this call until it is ready to accept the next request to process. Only
+ * one call to process_capture_request() will be made at a time by the
+ * framework, and the calls will all be from the same thread. The next call
+ * to process_capture_request() will be made as soon as a new request and
+ * its associated buffers are available. In a normal preview scenario, this
+ * means the function will be called again by the framework almost
+ * instantly.
+ *
+ * The actual request processing is asynchronous, with the results of
+ * capture being returned by the HAL through the process_capture_result()
+ * call. This call requires the result metadata to be available, but output
+ * buffers may simply provide sync fences to wait on. Multiple requests are
+ * expected to be in flight at once, to maintain full output frame rate.
+ *
+ * The framework retains ownership of the request structure. It is only
+ * guaranteed to be valid during this call. The HAL device must make copies
+ * of the information it needs to retain for the capture processing. The HAL
+ * is responsible for waiting on and closing the buffers' fences and
+ * returning the buffer handles to the framework.
+ *
+ * The HAL must write the file descriptor for the input buffer's release
+ * sync fence into input_buffer->release_fence, if input_buffer is not
+ * NULL. If the HAL returns -1 for the input buffer release sync fence, the
+ * framework is free to immediately reuse the input buffer. Otherwise, the
+ * framework will wait on the sync fence before refilling and reusing the
+ * input buffer.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ *
+ * The input/output buffers provided by the framework in each request
+ * may be brand new (having never before seen by the HAL).
+ *
+ * ------------------------------------------------------------------------
+ * Performance considerations:
+ *
+ * Handling a new buffer should be extremely lightweight and there should be
+ * no frame rate degradation or frame jitter introduced.
+ *
+ * This call must return fast enough to ensure that the requested frame
+ * rate can be sustained, especially for streaming cases (post-processing
+ * quality settings set to FAST). The HAL should return this call in 1
+ * frame interval, and must return from this call in 4 frame intervals.
+ *
+ * Return values:
+ *
+ * 0: On a successful start to processing the capture request
+ *
+ * -EINVAL: If the input is malformed (the settings are NULL when not
+ * allowed, there are 0 output buffers, etc) and capture processing
+ * cannot start. Failures during request processing should be
+ * handled by calling camera3_callback_ops_t.notify(). In case of
+ * this error, the framework will retain responsibility for the
+ * stream buffers' fences and the buffer handles; the HAL should
+ * not close the fences or return these buffers with
+ * process_capture_result.
+ *
+ * -ENODEV: If the camera device has encountered a serious error. After this
+ * error is returned, only the close() method can be successfully
+ * called by the framework.
+ *
+ */
+ int (*process_capture_request)(const struct camera3_device *,
+ camera3_capture_request_t *request);
+
+ /**********************************************************************
+ * Miscellaneous methods
+ */
+
+ /**
+ * get_metadata_vendor_tag_ops:
+ *
+ * Get methods to query for vendor extension metadata tag information. The
+ * HAL should fill in all the vendor tag operation methods, or leave ops
+ * unchanged if no vendor tags are defined.
+ *
+ * The definition of vendor_tag_query_ops_t can be found in
+ * system/media/camera/include/system/camera_metadata.h.
+ *
+ * >= CAMERA_DEVICE_API_VERSION_3_2:
+ * DEPRECATED. This function has been deprecated and should be set to
+ * NULL by the HAL. Please implement get_vendor_tag_ops in camera_common.h
+ * instead.
+ */
+ void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
+ vendor_tag_query_ops_t* ops);
+
+ /**
+ * dump:
+ *
+ * Print out debugging state for the camera device. This will be called by
+ * the framework when the camera service is asked for a debug dump, which
+ * happens when using the dumpsys tool, or when capturing a bugreport.
+ *
+ * The passed-in file descriptor can be used to write debugging text using
+ * dprintf() or write(). The text should be in ASCII encoding only.
+ *
+ * Performance requirements:
+ *
+ * This must be a non-blocking call. The HAL should return from this call
+ * in 1ms, must return from this call in 10ms. This call must avoid
+ * deadlocks, as it may be called at any point during camera operation.
+ * Any synchronization primitives used (such as mutex locks or semaphores)
+ * should be acquired with a timeout.
+ */
+ void (*dump)(const struct camera3_device *, int fd);
+
+ /**
+ * flush:
+ *
+ * Flush all currently in-process captures and all buffers in the pipeline
+ * on the given device. The framework will use this to dump all state as
+ * quickly as possible in order to prepare for a configure_streams() call.
+ *
+ * No buffers are required to be successfully returned, so every buffer
+ * held at the time of flush() (whether successfully filled or not) may be
+ * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
+ * to return valid (CAMERA3_BUFFER_STATUS_OK) buffers during this call,
+ * provided they are successfully filled.
+ *
+ * All requests currently in the HAL are expected to be returned as soon as
+ * possible. Not-in-process requests should return errors immediately. Any
+ * interruptible hardware blocks should be stopped, and any uninterruptible
+ * blocks should be waited on.
+ *
+ * flush() may be called concurrently to process_capture_request(), with the expectation that
+ * process_capture_request will return quickly and the request submitted in that
+ * process_capture_request call is treated like all other in-flight requests. Due to
+ * concurrency issues, it is possible that from the HAL's point of view, a
+ * process_capture_request() call may be started after flush has been invoked but has not
+ * returned yet. If such a call happens before flush() returns, the HAL should treat the new
+ * capture request like other in-flight pending requests (see #4 below).
+ *
+ * More specifically, the HAL must follow below requirements for various cases:
+ *
+ * 1. For captures that are too late for the HAL to cancel/stop, and will be
+ * completed normally by the HAL; i.e. the HAL can send shutter/notify and
+ * process_capture_result and buffers as normal.
+ *
+ * 2. For pending requests that have not done any processing, the HAL must call notify
+ * CAMERA3_MSG_ERROR_REQUEST, and return all the output buffers with
+ * process_capture_result in the error state (CAMERA3_BUFFER_STATUS_ERROR).
+ * The HAL must not place the release fence into an error state, instead,
+ * the release fences must be set to the acquire fences passed by the framework,
+ * or -1 if they have been waited on by the HAL already. This is also the path
+ * to follow for any captures for which the HAL already called notify() with
+ * CAMERA3_MSG_SHUTTER but won't be producing any metadata/valid buffers for.
+ * After CAMERA3_MSG_ERROR_REQUEST, for a given frame, only process_capture_results with
+ * buffers in CAMERA3_BUFFER_STATUS_ERROR are allowed. No further notifys or
+ * process_capture_result with non-null metadata is allowed.
+ *
+ * 3. For partially completed pending requests that will not have all the output
+ * buffers or perhaps missing metadata, the HAL should follow below:
+ *
+ * 3.1. Call notify with CAMERA3_MSG_ERROR_RESULT if some of the expected result
+ * metadata (i.e. one or more partial metadata) won't be available for the capture.
+ *
+ * 3.2. Call notify with CAMERA3_MSG_ERROR_BUFFER for every buffer that won't
+ * be produced for the capture.
+ *
+ * 3.3 Call notify with CAMERA3_MSG_SHUTTER with the capture timestamp before
+ * any buffers/metadata are returned with process_capture_result.
+ *
+ * 3.4 For captures that will produce some results, the HAL must not call
+ * CAMERA3_MSG_ERROR_REQUEST, since that indicates complete failure.
+ *
+ * 3.5. Valid buffers/metadata should be passed to the framework as normal.
+ *
+ * 3.6. Failed buffers should be returned to the framework as described for case 2.
+ * But failed buffers do not have to follow the strict ordering valid buffers do,
+ * and may be out-of-order with respect to valid buffers. For example, if buffers
+ * A, B, C, D, E are sent, D and E are failed, then A, E, B, D, C is an acceptable
+ * return order.
+ *
+ * 3.7. For fully-missing metadata, calling CAMERA3_MSG_ERROR_RESULT is sufficient, no
+ * need to call process_capture_result with NULL metadata or equivalent.
+ *
+ * 4. If a flush() is invoked while a process_capture_request() invocation is active, that
+ * process call should return as soon as possible. In addition, if a process_capture_request()
+ * call is made after flush() has been invoked but before flush() has returned, the
+ * capture request provided by the late process_capture_request call should be treated like
+ * a pending request in case #2 above.
+ *
+ * flush() should only return when there are no more outstanding buffers or
+ * requests left in the HAL. The framework may call configure_streams (as
+ * the HAL state is now quiesced) or may issue new requests.
+ *
+ * Note that it's sufficient to only support fully-succeeded and fully-failed result cases.
+ * However, it is highly desirable to support the partial failure cases as well, as it
+ * could help improve the flush call overall performance.
+ *
+ * Performance requirements:
+ *
+ * The HAL should return from this call in 100ms, and must return from this
+ * call in 1000ms. And this call must not be blocked longer than pipeline
+ * latency (see S7 for definition).
+ *
+ * Version information:
+ *
+ * only available if device version >= CAMERA_DEVICE_API_VERSION_3_1.
+ *
+ * Return values:
+ *
+ * 0: On a successful flush of the camera HAL.
+ *
+ * -EINVAL: If the input is malformed (the device is not valid).
+ *
+ * -ENODEV: If the camera device has encountered a serious error. After this
+ * error is returned, only the close() method can be successfully
+ * called by the framework.
+ */
+ int (*flush)(const struct camera3_device *);
+
+ /* reserved for future use */
+ void *reserved[8];
+} camera3_device_ops_t;
+
+/**********************************************************************
+ *
+ * Camera device definition
+ *
+ */
+typedef struct camera3_device {
+ /**
+ * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
+ * device as implementing version 3.0 of the camera device HAL.
+ *
+ * Performance requirements:
+ *
+ * Camera open (common.module->common.methods->open) should return in 200ms, and must return
+ * in 500ms.
+ * Camera close (common.close) should return in 200ms, and must return in 500ms.
+ *
+ */
+ hw_device_t common;
+ camera3_device_ops_t *ops;
+ void *priv;
+} camera3_device_t;
+
+__END_DECLS
+
+#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */
diff --git a/libhardware/include/hardware/camera_common.h b/libhardware/include/hardware/camera_common.h
new file mode 100644
index 0000000..7658dd4
--- /dev/null
+++ b/libhardware/include/hardware/camera_common.h
@@ -0,0 +1,916 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// FIXME: add well-defined names for cameras
+
+#ifndef ANDROID_INCLUDE_CAMERA_COMMON_H
+#define ANDROID_INCLUDE_CAMERA_COMMON_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <cutils/native_handle.h>
+#include <system/camera.h>
+#include <system/camera_vendor_tags.h>
+#include <hardware/hardware.h>
+#include <hardware/gralloc.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define CAMERA_HARDWARE_MODULE_ID "camera"
+
+/**
+ * Module versioning information for the Camera hardware module, based on
+ * camera_module_t.common.module_api_version. The two most significant hex
+ * digits represent the major version, and the two least significant represent
+ * the minor version.
+ *
+ *******************************************************************************
+ * Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
+ *
+ * Camera modules that report these version numbers implement the initial
+ * camera module HAL interface. All camera devices openable through this
+ * module support only version 1 of the camera device HAL. The device_version
+ * and static_camera_characteristics fields of camera_info are not valid. Only
+ * the android.hardware.Camera API can be supported by this module and its
+ * devices.
+ *
+ *******************************************************************************
+ * Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
+ *
+ * Camera modules that report this version number implement the second version
+ * of the camera module HAL interface. Camera devices openable through this
+ * module may support either version 1.0 or version 2.0 of the camera device
+ * HAL interface. The device_version field of camera_info is always valid; the
+ * static_camera_characteristics field of camera_info is valid if the
+ * device_version field is 2.0 or higher.
+ *
+ *******************************************************************************
+ * Version: 2.1 [CAMERA_MODULE_API_VERSION_2_1]
+ *
+ * This camera module version adds support for asynchronous callbacks to the
+ * framework from the camera HAL module, which is used to notify the framework
+ * about changes to the camera module state. Modules that provide a valid
+ * set_callbacks() method must report at least this version number.
+ *
+ *******************************************************************************
+ * Version: 2.2 [CAMERA_MODULE_API_VERSION_2_2]
+ *
+ * This camera module version adds vendor tag support from the module, and
+ * deprecates the old vendor_tag_query_ops that were previously only
+ * accessible with a device open.
+ *
+ *******************************************************************************
+ * Version: 2.3 [CAMERA_MODULE_API_VERSION_2_3]
+ *
+ * This camera module version adds open legacy camera HAL device support.
+ * Framework can use it to open the camera device as lower device HAL version
+ * HAL device if the same device can support multiple device API versions.
+ * The standard hardware module open call (common.methods->open) continues
+ * to open the camera device with the latest supported version, which is
+ * also the version listed in camera_info_t.device_version.
+ *
+ *******************************************************************************
+ * Version: 2.4 [CAMERA_MODULE_API_VERSION_2_4]
+ *
+ * This camera module version adds below API changes:
+ *
+ * 1. Torch mode support. The framework can use it to turn on torch mode for
+ * any camera device that has a flash unit, without opening a camera device. The
+ * camera device has a higher priority accessing the flash unit than the camera
+ * module; opening a camera device will turn off the torch if it had been enabled
+ * through the module interface. When there are any resource conflicts, such as
+ * open() is called to open a camera device, the camera HAL module must notify the
+ * framework through the torch mode status callback that the torch mode has been
+ * turned off.
+ *
+ * 2. External camera (e.g. USB hot-plug camera) support. The API updates specify that
+ * the camera static info is only available when camera is connected and ready to
+ * use for external hot-plug cameras. Calls to get static info will be invalid
+ * calls when camera status is not CAMERA_DEVICE_STATUS_PRESENT. The frameworks
+ * will only count on device status change callbacks to manage the available external
+ * camera list.
+ *
+ * 3. Camera arbitration hints. This module version adds support for explicitly
+ * indicating the number of camera devices that can be simultaneously opened and used.
+ * To specify valid combinations of devices, the resource_cost and conflicting_devices
+ * fields should always be set in the camera_info structure returned by the
+ * get_camera_info call.
+ *
+ * 4. Module initialization method. This will be called by the camera service
+ * right after the HAL module is loaded, to allow for one-time initialization
+ * of the HAL. It is called before any other module methods are invoked.
+ */
+
+/**
+ * Predefined macros for currently-defined version numbers
+ */
+
+/**
+ * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
+ * as CAMERA_MODULE_API_VERSION_1_0
+ */
+#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
+#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
+#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
+#define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3)
+#define CAMERA_MODULE_API_VERSION_2_4 HARDWARE_MODULE_API_VERSION(2, 4)
+
+#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_4
+
+/**
+ * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
+ * as CAMERA_DEVICE_API_VERSION_1_0
+ */
+#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
+#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
+#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1)
+#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
+#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
+#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
+#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
+
+// Device version 3.3 is current, older HAL camera device versions are not
+// recommended for new devices.
+#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_3
+
+/**
+ * Defined in /system/media/camera/include/system/camera_metadata.h
+ */
+typedef struct camera_metadata camera_metadata_t;
+
+typedef struct camera_info {
+ /**
+ * The direction that the camera faces to. See system/core/include/system/camera.h
+ * for camera facing definitions.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * It should be CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4 or higher:
+ *
+ * It should be CAMERA_FACING_BACK, CAMERA_FACING_FRONT or
+ * CAMERA_FACING_EXTERNAL.
+ */
+ int facing;
+
+ /**
+ * The orientation of the camera image. The value is the angle that the
+ * camera image needs to be rotated clockwise so it shows correctly on the
+ * display in its natural orientation. It should be 0, 90, 180, or 270.
+ *
+ * For example, suppose a device has a naturally tall screen. The
+ * back-facing camera sensor is mounted in landscape. You are looking at the
+ * screen. If the top side of the camera sensor is aligned with the right
+ * edge of the screen in natural orientation, the value should be 90. If the
+ * top side of a front-facing camera sensor is aligned with the right of the
+ * screen, the value should be 270.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * Valid in all camera_module versions.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4 or higher:
+ *
+ * Valid if camera facing is CAMERA_FACING_BACK or CAMERA_FACING_FRONT,
+ * not valid if camera facing is CAMERA_FACING_EXTERNAL.
+ */
+ int orientation;
+
+ /**
+ * The value of camera_device_t.common.version.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_0:
+ *
+ * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
+ * not read this field.
+ *
+ * CAMERA_MODULE_API_VERSION_2_0 or higher:
+ *
+ * Always valid
+ *
+ */
+ uint32_t device_version;
+
+ /**
+ * The camera's fixed characteristics, which include all static camera metadata
+ * specified in system/media/camera/docs/docs.html. This should be a sorted metadata
+ * buffer, and may not be modified or freed by the caller. The pointer should remain
+ * valid for the lifetime of the camera module, and values in it may not
+ * change after it is returned by get_camera_info().
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_0:
+ *
+ * Not valid. Extra characteristics are not available. Do not read this
+ * field.
+ *
+ * CAMERA_MODULE_API_VERSION_2_0 or higher:
+ *
+ * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
+ * otherwise.
+ *
+ */
+ const camera_metadata_t *static_camera_characteristics;
+
+ /**
+ * The total resource "cost" of using this camera, represented as an integer
+ * value in the range [0, 100] where 100 represents total usage of the shared
+ * resource that is the limiting bottleneck of the camera subsystem. This may
+ * be a very rough estimate, and is used as a hint to the camera service to
+ * determine when to disallow multiple applications from simultaneously
+ * opening different cameras advertised by the camera service.
+ *
+ * The camera service must be able to simultaneously open and use any
+ * combination of camera devices exposed by the HAL where the sum of
+ * the resource costs of these cameras is <= 100. For determining cost,
+ * each camera device must be assumed to be configured and operating at
+ * the maximally resource-consuming framerate and stream size settings
+ * available in the configuration settings exposed for that device through
+ * the camera metadata.
+ *
+ * The camera service may still attempt to simultaneously open combinations
+ * of camera devices with a total resource cost > 100. This may succeed or
+ * fail. If this succeeds, combinations of configurations that are not
+ * supported due to resource constraints from having multiple open devices
+ * should fail during the configure calls. If the total resource cost is
+ * <= 100, open and configure should never fail for any stream configuration
+ * settings or other device capabilities that would normally succeed for a
+ * device when it is the only open camera device.
+ *
+ * This field will be used to determine whether background applications are
+ * allowed to use this camera device while other applications are using other
+ * camera devices. Note: multiple applications will never be allowed by the
+ * camera service to simultaneously open the same camera device.
+ *
+ * Example use cases:
+ *
+ * Ex. 1: Camera Device 0 = Back Camera
+ * Camera Device 1 = Front Camera
+ * - Using both camera devices causes a large framerate slowdown due to
+ * limited ISP bandwidth.
+ *
+ * Configuration:
+ *
+ * Camera Device 0 - resource_cost = 51
+ * conflicting_devices = null
+ * Camera Device 1 - resource_cost = 51
+ * conflicting_devices = null
+ *
+ * Result:
+ *
+ * Since the sum of the resource costs is > 100, if a higher-priority
+ * application has either device open, no lower-priority applications will be
+ * allowed by the camera service to open either device. If a lower-priority
+ * application is using a device that a higher-priority subsequently attempts
+ * to open, the lower-priority application will be forced to disconnect the
+ * the device.
+ *
+ * If the highest-priority application chooses, it may still attempt to open
+ * both devices (since these devices are not listed as conflicting in the
+ * conflicting_devices fields), but usage of these devices may fail in the
+ * open or configure calls.
+ *
+ * Ex. 2: Camera Device 0 = Left Back Camera
+ * Camera Device 1 = Right Back Camera
+ * Camera Device 2 = Combined stereo camera using both right and left
+ * back camera sensors used by devices 0, and 1
+ * Camera Device 3 = Front Camera
+ * - Due to do hardware constraints, up to two cameras may be open at once. The
+ * combined stereo camera may never be used at the same time as either of the
+ * two back camera devices (device 0, 1), and typically requires too much
+ * bandwidth to use at the same time as the front camera (device 3).
+ *
+ * Configuration:
+ *
+ * Camera Device 0 - resource_cost = 50
+ * conflicting_devices = { 2 }
+ * Camera Device 1 - resource_cost = 50
+ * conflicting_devices = { 2 }
+ * Camera Device 2 - resource_cost = 100
+ * conflicting_devices = { 0, 1 }
+ * Camera Device 3 - resource_cost = 50
+ * conflicting_devices = null
+ *
+ * Result:
+ *
+ * Based on the conflicting_devices fields, the camera service guarantees that
+ * the following sets of open devices will never be allowed: { 1, 2 }, { 0, 2 }.
+ *
+ * Based on the resource_cost fields, if a high-priority foreground application
+ * is using camera device 0, a background application would be allowed to open
+ * camera device 1 or 3 (but would be forced to disconnect it again if the
+ * foreground application opened another device).
+ *
+ * The highest priority application may still attempt to simultaneously open
+ * devices 0, 2, and 3, but the HAL may fail in open or configure calls for
+ * this combination.
+ *
+ * Ex. 3: Camera Device 0 = Back Camera
+ * Camera Device 1 = Front Camera
+ * Camera Device 2 = Low-power Front Camera that uses the same
+ * sensor as device 1, but only exposes image stream
+ * resolutions that can be used in low-power mode
+ * - Using both front cameras (device 1, 2) at the same time is impossible due
+ * a shared physical sensor. Using the back and "high-power" front camera
+ * (device 1) may be impossible for some stream configurations due to hardware
+ * limitations, but the "low-power" front camera option may always be used as
+ * it has special dedicated hardware.
+ *
+ * Configuration:
+ *
+ * Camera Device 0 - resource_cost = 100
+ * conflicting_devices = null
+ * Camera Device 1 - resource_cost = 100
+ * conflicting_devices = { 2 }
+ * Camera Device 2 - resource_cost = 0
+ * conflicting_devices = { 1 }
+ * Result:
+ *
+ * Based on the conflicting_devices fields, the camera service guarantees that
+ * the following sets of open devices will never be allowed: { 1, 2 }.
+ *
+ * Based on the resource_cost fields, only the highest priority application
+ * may attempt to open both device 0 and 1 at the same time. If a higher-priority
+ * application is not using device 1 or 2, a low-priority background application
+ * may open device 2 (but will be forced to disconnect it if a higher-priority
+ * application subsequently opens device 1 or 2).
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * Not valid. Can be assumed to be 100. Do not read this field.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4 or higher:
+ *
+ * Always valid.
+ */
+ int resource_cost;
+
+ /**
+ * An array of camera device IDs represented as NULL-terminated strings
+ * indicating other devices that cannot be simultaneously opened while this
+ * camera device is in use.
+ *
+ * This field is intended to be used to indicate that this camera device
+ * is a composite of several other camera devices, or otherwise has
+ * hardware dependencies that prohibit simultaneous usage. If there are no
+ * dependencies, a NULL may be returned in this field to indicate this.
+ *
+ * The camera service will never simultaneously open any of the devices
+ * in this list while this camera device is open.
+ *
+ * The strings pointed to in this field will not be cleaned up by the camera
+ * service, and must remain while this device is plugged in.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * Not valid. Can be assumed to be NULL. Do not read this field.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4 or higher:
+ *
+ * Always valid.
+ */
+ char** conflicting_devices;
+
+ /**
+ * The length of the array given in the conflicting_devices field.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * Not valid. Can be assumed to be 0. Do not read this field.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4 or higher:
+ *
+ * Always valid.
+ */
+ size_t conflicting_devices_length;
+
+} camera_info_t;
+
+/**
+ * camera_device_status_t:
+ *
+ * The current status of the camera device, as provided by the HAL through the
+ * camera_module_callbacks.camera_device_status_change() call.
+ *
+ * At module load time, the framework will assume all camera devices are in the
+ * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
+ * camera_module_callbacks::camera_device_status_change to inform the framework
+ * of any initially NOT_PRESENT devices.
+ *
+ * Allowed transitions:
+ * PRESENT -> NOT_PRESENT
+ * NOT_PRESENT -> ENUMERATING
+ * NOT_PRESENT -> PRESENT
+ * ENUMERATING -> PRESENT
+ * ENUMERATING -> NOT_PRESENT
+ */
+typedef enum camera_device_status {
+ /**
+ * The camera device is not currently connected, and opening it will return
+ * failure.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * Calls to get_camera_info must still succeed, and provide the same information
+ * it would if the camera were connected.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4:
+ *
+ * The camera device at this status must return -EINVAL for get_camera_info call,
+ * as the device is not connected.
+ */
+ CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
+
+ /**
+ * The camera device is connected, and opening it will succeed.
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * The information returned by get_camera_info cannot change due to this status
+ * change. By default, the framework will assume all devices are in this state.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4:
+ *
+ * The information returned by get_camera_info will become valid after a device's
+ * status changes to this. By default, the framework will assume all devices are in
+ * this state.
+ */
+ CAMERA_DEVICE_STATUS_PRESENT = 1,
+
+ /**
+ * The camera device is connected, but it is undergoing an enumeration and
+ * so opening the device will return -EBUSY.
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * Calls to get_camera_info must still succeed, as if the camera was in the
+ * PRESENT status.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4:
+ *
+ * The camera device at this status must return -EINVAL for get_camera_info for call,
+ * as the device is not ready.
+ */
+ CAMERA_DEVICE_STATUS_ENUMERATING = 2,
+
+} camera_device_status_t;
+
+/**
+ * torch_mode_status_t:
+ *
+ * The current status of the torch mode, as provided by the HAL through the
+ * camera_module_callbacks.torch_mode_status_change() call.
+ *
+ * The torch mode status of a camera device is applicable only when the camera
+ * device is present. The framework will not call set_torch_mode() to turn on
+ * torch mode of a camera device if the camera device is not present. At module
+ * load time, the framework will assume torch modes are in the
+ * TORCH_MODE_STATUS_AVAILABLE_OFF state if the camera device is present and
+ * android.flash.info.available is reported as true via get_camera_info() call.
+ *
+ * The behaviors of the camera HAL module that the framework expects in the
+ * following situations when a camera device's status changes:
+ * 1. A previously-disconnected camera device becomes connected.
+ * After camera_module_callbacks::camera_device_status_change() is invoked
+ * to inform the framework that the camera device is present, the framework
+ * will assume the camera device's torch mode is in
+ * TORCH_MODE_STATUS_AVAILABLE_OFF state. The camera HAL module does not need
+ * to invoke camera_module_callbacks::torch_mode_status_change() unless the
+ * flash unit is unavailable to use by set_torch_mode().
+ *
+ * 2. A previously-connected camera becomes disconnected.
+ * After camera_module_callbacks::camera_device_status_change() is invoked
+ * to inform the framework that the camera device is not present, the
+ * framework will not call set_torch_mode() for the disconnected camera
+ * device until its flash unit becomes available again. The camera HAL
+ * module does not need to invoke
+ * camera_module_callbacks::torch_mode_status_change() separately to inform
+ * that the flash unit has become unavailable.
+ *
+ * 3. open() is called to open a camera device.
+ * The camera HAL module must invoke
+ * camera_module_callbacks::torch_mode_status_change() for all flash units
+ * that have entered TORCH_MODE_STATUS_NOT_AVAILABLE state and can not be
+ * turned on by calling set_torch_mode() anymore due to this open() call.
+ * open() must not trigger TORCH_MODE_STATUS_AVAILABLE_OFF before
+ * TORCH_MODE_STATUS_NOT_AVAILABLE for all flash units that have become
+ * unavailable.
+ *
+ * 4. close() is called to close a camera device.
+ * The camera HAL module must invoke
+ * camera_module_callbacks::torch_mode_status_change() for all flash units
+ * that have entered TORCH_MODE_STATUS_AVAILABLE_OFF state and can be turned
+ * on by calling set_torch_mode() again because of enough resources freed
+ * up by this close() call.
+ *
+ * Note that the framework calling set_torch_mode() successfully must trigger
+ * TORCH_MODE_STATUS_AVAILABLE_OFF or TORCH_MODE_STATUS_AVAILABLE_ON callback
+ * for the given camera device. Additionally it must trigger
+ * TORCH_MODE_STATUS_AVAILABLE_OFF callbacks for other previously-on torch
+ * modes if HAL cannot keep multiple torch modes on simultaneously.
+ */
+typedef enum torch_mode_status {
+
+ /**
+ * The flash unit is no longer available and the torch mode can not be
+ * turned on by calling set_torch_mode(). If the torch mode is on, it
+ * will be turned off by HAL before HAL calls torch_mode_status_change().
+ */
+ TORCH_MODE_STATUS_NOT_AVAILABLE = 0,
+
+ /**
+ * A torch mode has become off and available to be turned on via
+ * set_torch_mode(). This may happen in the following
+ * cases:
+ * 1. After the resources to turn on the torch mode have become available.
+ * 2. After set_torch_mode() is called to turn off the torch mode.
+ * 3. After the framework turned on the torch mode of some other camera
+ * device and HAL had to turn off the torch modes of any camera devices
+ * that were previously on.
+ */
+ TORCH_MODE_STATUS_AVAILABLE_OFF = 1,
+
+ /**
+ * A torch mode has become on and available to be turned off via
+ * set_torch_mode(). This can happen only after set_torch_mode() is called
+ * to turn on the torch mode.
+ */
+ TORCH_MODE_STATUS_AVAILABLE_ON = 2,
+
+} torch_mode_status_t;
+
+/**
+ * Callback functions for the camera HAL module to use to inform the framework
+ * of changes to the camera subsystem.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * Each callback is called only by HAL modules implementing the indicated
+ * version or higher of the HAL module API interface.
+ *
+ * CAMERA_MODULE_API_VERSION_2_1:
+ * camera_device_status_change()
+ *
+ * CAMERA_MODULE_API_VERSION_2_4:
+ * torch_mode_status_change()
+
+ */
+typedef struct camera_module_callbacks {
+
+ /**
+ * camera_device_status_change:
+ *
+ * Callback to the framework to indicate that the state of a specific camera
+ * device has changed. At module load time, the framework will assume all
+ * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
+ * must call this method to inform the framework of any initially
+ * NOT_PRESENT devices.
+ *
+ * This callback is added for CAMERA_MODULE_API_VERSION_2_1.
+ *
+ * camera_module_callbacks: The instance of camera_module_callbacks_t passed
+ * to the module with set_callbacks.
+ *
+ * camera_id: The ID of the camera device that has a new status.
+ *
+ * new_status: The new status code, one of the camera_device_status_t enums,
+ * or a platform-specific status.
+ *
+ */
+ void (*camera_device_status_change)(const struct camera_module_callbacks*,
+ int camera_id,
+ int new_status);
+
+ /**
+ * torch_mode_status_change:
+ *
+ * Callback to the framework to indicate that the state of the torch mode
+ * of the flash unit associated with a specific camera device has changed.
+ * At module load time, the framework will assume the torch modes are in
+ * the TORCH_MODE_STATUS_AVAILABLE_OFF state if android.flash.info.available
+ * is reported as true via get_camera_info() call.
+ *
+ * This callback is added for CAMERA_MODULE_API_VERSION_2_4.
+ *
+ * camera_module_callbacks: The instance of camera_module_callbacks_t
+ * passed to the module with set_callbacks.
+ *
+ * camera_id: The ID of camera device whose flash unit has a new torch mode
+ * status.
+ *
+ * new_status: The new status code, one of the torch_mode_status_t enums.
+ */
+ void (*torch_mode_status_change)(const struct camera_module_callbacks*,
+ const char* camera_id,
+ int new_status);
+
+
+} camera_module_callbacks_t;
+
+typedef struct camera_module {
+ /**
+ * Common methods of the camera module. This *must* be the first member of
+ * camera_module as users of this structure will cast a hw_module_t to
+ * camera_module pointer in contexts where it's known the hw_module_t
+ * references a camera_module.
+ *
+ * The return values for common.methods->open for camera_module are:
+ *
+ * 0: On a successful open of the camera device.
+ *
+ * -ENODEV: The camera device cannot be opened due to an internal
+ * error.
+ *
+ * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
+ * and/or the module is invalid.
+ *
+ * -EBUSY: The camera device was already opened for this camera id
+ * (by using this method or open_legacy),
+ * regardless of the device HAL version it was opened as.
+ *
+ * -EUSERS: The maximal number of camera devices that can be
+ * opened concurrently were opened already, either by
+ * this method or the open_legacy method.
+ *
+ * All other return values from common.methods->open will be treated as
+ * -ENODEV.
+ */
+ hw_module_t common;
+
+ /**
+ * get_number_of_cameras:
+ *
+ * Returns the number of camera devices accessible through the camera
+ * module. The camera devices are numbered 0 through N-1, where N is the
+ * value returned by this call. The name of the camera device for open() is
+ * simply the number converted to a string. That is, "0" for camera ID 0,
+ * "1" for camera ID 1.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_2_3 or lower:
+ *
+ * The value here must be static, and cannot change after the first call
+ * to this method.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4 or higher:
+ *
+ * The value here must be static, and must count only built-in cameras,
+ * which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values
+ * (camera_info.facing). The HAL must not include the external cameras
+ * (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value
+ * of this call. Frameworks will use camera_device_status_change callback
+ * to manage number of external cameras.
+ */
+ int (*get_number_of_cameras)(void);
+
+ /**
+ * get_camera_info:
+ *
+ * Return the static camera information for a given camera device. This
+ * information may not change for a camera device.
+ *
+ * Return values:
+ *
+ * 0: On a successful operation
+ *
+ * -ENODEV: The information cannot be provided due to an internal
+ * error.
+ *
+ * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
+ * and/or the module is invalid.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_2_4 or higher:
+ *
+ * When a camera is disconnected, its camera id becomes invalid. Calling this
+ * this method with this invalid camera id will get -EINVAL and NULL camera
+ * static metadata (camera_info.static_camera_characteristics).
+ */
+ int (*get_camera_info)(int camera_id, struct camera_info *info);
+
+ /**
+ * set_callbacks:
+ *
+ * Provide callback function pointers to the HAL module to inform framework
+ * of asynchronous camera module events. The framework will call this
+ * function once after initial camera HAL module load, after the
+ * get_number_of_cameras() method is called for the first time, and before
+ * any other calls to the module.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
+ *
+ * Not provided by HAL module. Framework may not call this function.
+ *
+ * CAMERA_MODULE_API_VERSION_2_1:
+ *
+ * Valid to be called by the framework.
+ *
+ * Return values:
+ *
+ * 0: On a successful operation
+ *
+ * -ENODEV: The operation cannot be completed due to an internal
+ * error.
+ *
+ * -EINVAL: The input arguments are invalid, i.e. the callbacks are
+ * null
+ */
+ int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
+
+ /**
+ * get_vendor_tag_ops:
+ *
+ * Get methods to query for vendor extension metadata tag information. The
+ * HAL should fill in all the vendor tag operation methods, or leave ops
+ * unchanged if no vendor tags are defined.
+ *
+ * The vendor_tag_ops structure used here is defined in:
+ * system/media/camera/include/system/vendor_tags.h
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
+ * Not provided by HAL module. Framework may not call this function.
+ *
+ * CAMERA_MODULE_API_VERSION_2_2:
+ * Valid to be called by the framework.
+ */
+ void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
+
+ /**
+ * open_legacy:
+ *
+ * Open a specific legacy camera HAL device if multiple device HAL API
+ * versions are supported by this camera HAL module. For example, if the
+ * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
+ * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
+ * framework can call this function to open the camera device as
+ * CAMERA_DEVICE_API_VERSION_1_0 device.
+ *
+ * This is an optional method. A Camera HAL module does not need to support
+ * more than one device HAL version per device, and such modules may return
+ * -ENOSYS for all calls to this method. For all older HAL device API
+ * versions that are not supported, it may return -EOPNOTSUPP. When above
+ * cases occur, The normal open() method (common.methods->open) will be
+ * used by the framework instead.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
+ * Not provided by HAL module. Framework will not call this function.
+ *
+ * CAMERA_MODULE_API_VERSION_2_3:
+ * Valid to be called by the framework.
+ *
+ * Return values:
+ *
+ * 0: On a successful open of the camera device.
+ *
+ * -ENOSYS This method is not supported.
+ *
+ * -EOPNOTSUPP: The requested HAL version is not supported by this method.
+ *
+ * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
+ * and/or the module is invalid.
+ *
+ * -EBUSY: The camera device was already opened for this camera id
+ * (by using this method or common.methods->open method),
+ * regardless of the device HAL version it was opened as.
+ *
+ * -EUSERS: The maximal number of camera devices that can be
+ * opened concurrently were opened already, either by
+ * this method or common.methods->open method.
+ */
+ int (*open_legacy)(const struct hw_module_t* module, const char* id,
+ uint32_t halVersion, struct hw_device_t** device);
+
+ /**
+ * set_torch_mode:
+ *
+ * Turn on or off the torch mode of the flash unit associated with a given
+ * camera ID. If the operation is successful, HAL must notify the framework
+ * torch state by invoking
+ * camera_module_callbacks.torch_mode_status_change() with the new state.
+ *
+ * The camera device has a higher priority accessing the flash unit. When
+ * there are any resource conflicts, such as open() is called to open a
+ * camera device, HAL module must notify the framework through
+ * camera_module_callbacks.torch_mode_status_change() that the
+ * torch mode has been turned off and the torch mode state has become
+ * TORCH_MODE_STATUS_NOT_AVAILABLE. When resources to turn on torch mode
+ * become available again, HAL module must notify the framework through
+ * camera_module_callbacks.torch_mode_status_change() that the torch mode
+ * state has become TORCH_MODE_STATUS_AVAILABLE_OFF for set_torch_mode() to
+ * be called.
+ *
+ * When the framework calls set_torch_mode() to turn on the torch mode of a
+ * flash unit, if HAL cannot keep multiple torch modes on simultaneously,
+ * HAL should turn off the torch mode that was turned on by
+ * a previous set_torch_mode() call and notify the framework that the torch
+ * mode state of that flash unit has become TORCH_MODE_STATUS_AVAILABLE_OFF.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
+ * Not provided by HAL module. Framework will not call this function.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4:
+ * Valid to be called by the framework.
+ *
+ * Return values:
+ *
+ * 0: On a successful operation.
+ *
+ * -ENOSYS: The camera device does not support this operation. It is
+ * returned if and only if android.flash.info.available is
+ * false.
+ *
+ * -EBUSY: The camera device is already in use.
+ *
+ * -EUSERS: The resources needed to turn on the torch mode are not
+ * available, typically because other camera devices are
+ * holding the resources to make using the flash unit not
+ * possible.
+ *
+ * -EINVAL: camera_id is invalid.
+ *
+ */
+ int (*set_torch_mode)(const char* camera_id, bool enabled);
+
+ /**
+ * init:
+ *
+ * This method is called by the camera service before any other methods
+ * are invoked, right after the camera HAL library has been successfully
+ * loaded. It may be left as NULL by the HAL module, if no initialization
+ * in needed.
+ *
+ * It can be used by HAL implementations to perform initialization and
+ * other one-time operations.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
+ * Not provided by HAL module. Framework will not call this function.
+ *
+ * CAMERA_MODULE_API_VERSION_2_4:
+ * If not NULL, will always be called by the framework once after the HAL
+ * module is loaded, before any other HAL module method is called.
+ *
+ * Return values:
+ *
+ * 0: On a successful operation.
+ *
+ * -ENODEV: Initialization cannot be completed due to an internal
+ * error. The HAL must be assumed to be in a nonfunctional
+ * state.
+ *
+ */
+ int (*init)();
+
+ /* reserved for future use */
+ void* reserved[5];
+} camera_module_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */
diff --git a/libhardware/include/hardware/consumerir.h b/libhardware/include/hardware/consumerir.h
new file mode 100644
index 0000000..15334c1
--- /dev/null
+++ b/libhardware/include/hardware/consumerir.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_HARDWARE_CONSUMERIR_H
+#define ANDROID_INCLUDE_HARDWARE_CONSUMERIR_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <hardware/hardware.h>
+#include <hardware/hwcomposer_defs.h>
+
+#define CONSUMERIR_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define CONSUMERIR_HARDWARE_MODULE_ID "consumerir"
+#define CONSUMERIR_TRANSMITTER "transmitter"
+
+typedef struct consumerir_freq_range {
+ int min;
+ int max;
+} consumerir_freq_range_t;
+
+typedef struct consumerir_module {
+ /**
+ * Common methods of the consumer IR module. This *must* be the first member of
+ * consumerir_module as users of this structure will cast a hw_module_t to
+ * consumerir_module pointer in contexts where it's known the hw_module_t references a
+ * consumerir_module.
+ */
+ struct hw_module_t common;
+} consumerir_module_t;
+
+typedef struct consumerir_device {
+ /**
+ * Common methods of the consumer IR device. This *must* be the first member of
+ * consumerir_device as users of this structure will cast a hw_device_t to
+ * consumerir_device pointer in contexts where it's known the hw_device_t references a
+ * consumerir_device.
+ */
+ struct hw_device_t common;
+
+ /*
+ * (*transmit)() is called to by the ConsumerIrService to send an IR pattern
+ * at a given carrier_freq.
+ *
+ * The pattern is alternating series of carrier on and off periods measured in
+ * microseconds. The carrier should be turned off at the end of a transmit
+ * even if there are and odd number of entries in the pattern array.
+ *
+ * This call should return when the transmit is complete or encounters an error.
+ *
+ * returns: 0 on success. A negative error code on error.
+ */
+ int (*transmit)(struct consumerir_device *dev, int carrier_freq,
+ const int pattern[], int pattern_len);
+
+ /*
+ * (*get_num_carrier_freqs)() is called by the ConsumerIrService to get the
+ * number of carrier freqs to allocate space for, which is then filled by
+ * a subsequent call to (*get_carrier_freqs)().
+ *
+ * returns: the number of ranges on success. A negative error code on error.
+ */
+ int (*get_num_carrier_freqs)(struct consumerir_device *dev);
+
+ /*
+ * (*get_carrier_freqs)() is called by the ConsumerIrService to enumerate
+ * which frequencies the IR transmitter supports. The HAL implementation
+ * should fill an array of consumerir_freq_range structs with the
+ * appropriate values for the transmitter, up to len elements.
+ *
+ * returns: the number of ranges on success. A negative error code on error.
+ */
+ int (*get_carrier_freqs)(struct consumerir_device *dev,
+ size_t len, consumerir_freq_range_t *ranges);
+
+ /* Reserved for future use. Must be NULL. */
+ void* reserved[8 - 3];
+} consumerir_device_t;
+
+#endif /* ANDROID_INCLUDE_HARDWARE_CONSUMERIR_H */
diff --git a/libhardware/include/hardware/fb.h b/libhardware/include/hardware/fb.h
new file mode 100644
index 0000000..9df9416
--- /dev/null
+++ b/libhardware/include/hardware/fb.h
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_FB_INTERFACE_H
+#define ANDROID_FB_INTERFACE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/native_handle.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define GRALLOC_HARDWARE_FB0 "fb0"
+
+/*****************************************************************************/
+
+
+/*****************************************************************************/
+
+typedef struct framebuffer_device_t {
+ /**
+ * Common methods of the framebuffer device. This *must* be the first member of
+ * framebuffer_device_t as users of this structure will cast a hw_device_t to
+ * framebuffer_device_t pointer in contexts where it's known the hw_device_t references a
+ * framebuffer_device_t.
+ */
+ struct hw_device_t common;
+
+ /* flags describing some attributes of the framebuffer */
+ const uint32_t flags;
+
+ /* dimensions of the framebuffer in pixels */
+ const uint32_t width;
+ const uint32_t height;
+
+ /* frambuffer stride in pixels */
+ const int stride;
+
+ /* framebuffer pixel format */
+ const int format;
+
+ /* resolution of the framebuffer's display panel in pixel per inch*/
+ const float xdpi;
+ const float ydpi;
+
+ /* framebuffer's display panel refresh rate in frames per second */
+ const float fps;
+
+ /* min swap interval supported by this framebuffer */
+ const int minSwapInterval;
+
+ /* max swap interval supported by this framebuffer */
+ const int maxSwapInterval;
+
+ /* Number of framebuffers supported*/
+ const int numFramebuffers;
+
+ int reserved[7];
+
+ /*
+ * requests a specific swap-interval (same definition than EGL)
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*setSwapInterval)(struct framebuffer_device_t* window,
+ int interval);
+
+ /*
+ * This hook is OPTIONAL.
+ *
+ * It is non NULL If the framebuffer driver supports "update-on-demand"
+ * and the given rectangle is the area of the screen that gets
+ * updated during (*post)().
+ *
+ * This is useful on devices that are able to DMA only a portion of
+ * the screen to the display panel, upon demand -- as opposed to
+ * constantly refreshing the panel 60 times per second, for instance.
+ *
+ * Only the area defined by this rectangle is guaranteed to be valid, that
+ * is, the driver is not allowed to post anything outside of this
+ * rectangle.
+ *
+ * The rectangle evaluated during (*post)() and specifies which area
+ * of the buffer passed in (*post)() shall to be posted.
+ *
+ * return -EINVAL if width or height <=0, or if left or top < 0
+ */
+ int (*setUpdateRect)(struct framebuffer_device_t* window,
+ int left, int top, int width, int height);
+
+ /*
+ * Post <buffer> to the display (display it on the screen)
+ * The buffer must have been allocated with the
+ * GRALLOC_USAGE_HW_FB usage flag.
+ * buffer must be the same width and height as the display and must NOT
+ * be locked.
+ *
+ * The buffer is shown during the next VSYNC.
+ *
+ * If the same buffer is posted again (possibly after some other buffer),
+ * post() will block until the the first post is completed.
+ *
+ * Internally, post() is expected to lock the buffer so that a
+ * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
+ * USAGE_*_WRITE will block until it is safe; that is typically once this
+ * buffer is shown and another buffer has been posted.
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
+
+
+ /*
+ * The (*compositionComplete)() method must be called after the
+ * compositor has finished issuing GL commands for client buffers.
+ */
+
+ int (*compositionComplete)(struct framebuffer_device_t* dev);
+
+ /*
+ * This hook is OPTIONAL.
+ *
+ * If non NULL it will be caused by SurfaceFlinger on dumpsys
+ */
+ void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
+
+ /*
+ * (*enableScreen)() is used to either blank (enable=0) or
+ * unblank (enable=1) the screen this framebuffer is attached to.
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*enableScreen)(struct framebuffer_device_t* dev, int enable);
+
+ void* reserved_proc[6];
+
+} framebuffer_device_t;
+
+
+/** convenience API for opening and closing a supported device */
+
+static inline int framebuffer_open(const struct hw_module_t* module,
+ struct framebuffer_device_t** device) {
+ return module->methods->open(module,
+ GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
+}
+
+static inline int framebuffer_close(struct framebuffer_device_t* device) {
+ return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif // ANDROID_FB_INTERFACE_H
diff --git a/libhardware/include/hardware/fingerprint.h b/libhardware/include/hardware/fingerprint.h
new file mode 100644
index 0000000..ac88c10
--- /dev/null
+++ b/libhardware/include/hardware/fingerprint.h
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H
+#define ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H
+
+#include <hardware/hw_auth_token.h>
+
+#define FINGERPRINT_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define FINGERPRINT_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
+#define FINGERPRINT_HARDWARE_MODULE_ID "fingerprint"
+
+typedef enum fingerprint_msg_type {
+ FINGERPRINT_ERROR = -1,
+ FINGERPRINT_ACQUIRED = 1,
+ FINGERPRINT_TEMPLATE_ENROLLING = 3,
+ FINGERPRINT_TEMPLATE_REMOVED = 4,
+ FINGERPRINT_AUTHENTICATED = 5
+} fingerprint_msg_type_t;
+
+/*
+ * Fingerprint errors are meant to tell the framework to terminate the current operation and ask
+ * for the user to correct the situation. These will almost always result in messaging and user
+ * interaction to correct the problem.
+ *
+ * For example, FINGERPRINT_ERROR_CANCELED should follow any acquisition message that results in
+ * a situation where the current operation can't continue without user interaction. For example,
+ * if the sensor is dirty during enrollment and no further enrollment progress can be made,
+ * send FINGERPRINT_ACQUIRED_IMAGER_DIRTY followed by FINGERPRINT_ERROR_CANCELED.
+ */
+typedef enum fingerprint_error {
+ FINGERPRINT_ERROR_HW_UNAVAILABLE = 1, /* The hardware has an error that can't be resolved. */
+ FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2, /* Bad data; operation can't continue */
+ FINGERPRINT_ERROR_TIMEOUT = 3, /* The operation has timed out waiting for user input. */
+ FINGERPRINT_ERROR_NO_SPACE = 4, /* No space available to store a template */
+ FINGERPRINT_ERROR_CANCELED = 5, /* The current operation can't proceed. See above. */
+ FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6, /* fingerprint with given id can't be removed */
+ FINGERPRINT_ERROR_VENDOR_BASE = 1000 /* vendor-specific error messages start here */
+} fingerprint_error_t;
+
+/*
+ * Fingerprint acquisition info is meant as feedback for the current operation. Anything but
+ * FINGERPRINT_ACQUIRED_GOOD will be shown to the user as feedback on how to take action on the
+ * current operation. For example, FINGERPRINT_ACQUIRED_IMAGER_DIRTY can be used to tell the user
+ * to clean the sensor. If this will cause the current operation to fail, an additional
+ * FINGERPRINT_ERROR_CANCELED can be sent to stop the operation in progress (e.g. enrollment).
+ * In general, these messages will result in a "Try again" message.
+ */
+typedef enum fingerprint_acquired_info {
+ FINGERPRINT_ACQUIRED_GOOD = 0,
+ FINGERPRINT_ACQUIRED_PARTIAL = 1, /* sensor needs more data, i.e. longer swipe. */
+ FINGERPRINT_ACQUIRED_INSUFFICIENT = 2, /* image doesn't contain enough detail for recognition*/
+ FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3, /* sensor needs to be cleaned */
+ FINGERPRINT_ACQUIRED_TOO_SLOW = 4, /* mostly swipe-type sensors; not enough data collected */
+ FINGERPRINT_ACQUIRED_TOO_FAST = 5, /* for swipe and area sensors; tell user to slow down*/
+ FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
+} fingerprint_acquired_info_t;
+
+typedef struct fingerprint_finger_id {
+ uint32_t gid;
+ uint32_t fid;
+} fingerprint_finger_id_t;
+
+typedef struct fingerprint_enroll {
+ fingerprint_finger_id_t finger;
+ /* samples_remaining goes from N (no data collected, but N scans needed)
+ * to 0 (no more data is needed to build a template). */
+ uint32_t samples_remaining;
+ uint64_t msg; /* Vendor specific message. Used for user guidance */
+} fingerprint_enroll_t;
+
+typedef struct fingerprint_removed {
+ fingerprint_finger_id_t finger;
+} fingerprint_removed_t;
+
+typedef struct fingerprint_acquired {
+ fingerprint_acquired_info_t acquired_info; /* information about the image */
+} fingerprint_acquired_t;
+
+typedef struct fingerprint_authenticated {
+ fingerprint_finger_id_t finger;
+ hw_auth_token_t hat;
+} fingerprint_authenticated_t;
+
+typedef struct fingerprint_msg {
+ fingerprint_msg_type_t type;
+ union {
+ fingerprint_error_t error;
+ fingerprint_enroll_t enroll;
+ fingerprint_removed_t removed;
+ fingerprint_acquired_t acquired;
+ fingerprint_authenticated_t authenticated;
+ } data;
+} fingerprint_msg_t;
+
+/* Callback function type */
+typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
+
+/* Synchronous operation */
+typedef struct fingerprint_device {
+ /**
+ * Common methods of the fingerprint device. This *must* be the first member
+ * of fingerprint_device as users of this structure will cast a hw_device_t
+ * to fingerprint_device pointer in contexts where it's known
+ * the hw_device_t references a fingerprint_device.
+ */
+ struct hw_device_t common;
+
+ /*
+ * Client provided callback function to receive notifications.
+ * Do not set by hand, use the function above instead.
+ */
+ fingerprint_notify_t notify;
+
+ /*
+ * Set notification callback:
+ * Registers a user function that would receive notifications from the HAL
+ * The call will block if the HAL state machine is in busy state until HAL
+ * leaves the busy state.
+ *
+ * Function return: 0 if callback function is successfuly registered
+ * or a negative number in case of error, generally from the errno.h set.
+ */
+ int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
+
+ /*
+ * Fingerprint pre-enroll enroll request:
+ * Generates a unique token to upper layers to indicate the start of an enrollment transaction.
+ * This token will be wrapped by security for verification and passed to enroll() for
+ * verification before enrollment will be allowed. This is to ensure adding a new fingerprint
+ * template was preceded by some kind of credential confirmation (e.g. device password).
+ *
+ * Function return: 0 if function failed
+ * otherwise, a uint64_t of token
+ */
+ uint64_t (*pre_enroll)(struct fingerprint_device *dev);
+
+ /*
+ * Fingerprint enroll request:
+ * Switches the HAL state machine to collect and store a new fingerprint
+ * template. Switches back as soon as enroll is complete
+ * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
+ * fingerprint_msg.data.enroll.samples_remaining == 0)
+ * or after timeout_sec seconds.
+ * The fingerprint template will be assigned to the group gid. User has a choice
+ * to supply the gid or set it to 0 in which case a unique group id will be generated.
+ *
+ * Function return: 0 if enrollment process can be successfully started
+ * or a negative number in case of error, generally from the errno.h set.
+ * A notify() function may be called indicating the error condition.
+ */
+ int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
+ uint32_t gid, uint32_t timeout_sec);
+
+ /*
+ * Finishes the enroll operation and invalidates the pre_enroll() generated challenge.
+ * This will be called at the end of a multi-finger enrollment session to indicate
+ * that no more fingers will be added.
+ *
+ * Function return: 0 if the request is accepted
+ * or a negative number in case of error, generally from the errno.h set.
+ */
+ int (*post_enroll)(struct fingerprint_device *dev);
+
+ /*
+ * get_authenticator_id:
+ * Returns a token associated with the current fingerprint set. This value will
+ * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
+ * set.
+ *
+ * Function return: current authenticator id or 0 if function failed.
+ */
+ uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
+
+ /*
+ * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
+ * to all running clients. Switches the HAL state machine back to the idle state.
+ * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge.
+ *
+ * Function return: 0 if cancel request is accepted
+ * or a negative number in case of error, generally from the errno.h set.
+ */
+ int (*cancel)(struct fingerprint_device *dev);
+
+ /*
+ * Enumerate all the fingerprint templates found in the directory set by
+ * set_active_group()
+ * This is a synchronous call. The function takes:
+ * - A pointer to an array of fingerprint_finger_id_t.
+ * - The size of the array provided, in fingerprint_finger_id_t elements.
+ * Max_size is a bi-directional parameter and returns the actual number
+ * of elements copied to the caller supplied array.
+ * In the absence of errors the function returns the total number of templates
+ * in the user directory.
+ * If the caller has no good guess on the size of the array he should call this
+ * function witn *max_size == 0 and use the return value for the array allocation.
+ * The caller of this function has a complete list of the templates when *max_size
+ * is the same as the function return.
+ *
+ * Function return: Total number of fingerprint templates in the current storage directory.
+ * or a negative number in case of error, generally from the errno.h set.
+ */
+ int (*enumerate)(struct fingerprint_device *dev, fingerprint_finger_id_t *results,
+ uint32_t *max_size);
+
+ /*
+ * Fingerprint remove request:
+ * Deletes a fingerprint template.
+ * Works only within a path set by set_active_group().
+ * notify() will be called with details on the template deleted.
+ * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
+ * fingerprint_msg.data.removed.id indicating the template id removed.
+ *
+ * Function return: 0 if fingerprint template(s) can be successfully deleted
+ * or a negative number in case of error, generally from the errno.h set.
+ */
+ int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
+
+ /*
+ * Restricts the HAL operation to a set of fingerprints belonging to a
+ * group provided.
+ * The caller must provide a path to a storage location within the user's
+ * data directory.
+ *
+ * Function return: 0 on success
+ * or a negative number in case of error, generally from the errno.h set.
+ */
+ int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
+ const char *store_path);
+
+ /*
+ * Authenticates an operation identifed by operation_id
+ *
+ * Function return: 0 on success
+ * or a negative number in case of error, generally from the errno.h set.
+ */
+ int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
+
+ /* Reserved for backward binary compatibility */
+ void *reserved[4];
+} fingerprint_device_t;
+
+typedef struct fingerprint_module {
+ /**
+ * Common methods of the fingerprint module. This *must* be the first member
+ * of fingerprint_module as users of this structure will cast a hw_module_t
+ * to fingerprint_module pointer in contexts where it's known
+ * the hw_module_t references a fingerprint_module.
+ */
+ struct hw_module_t common;
+} fingerprint_module_t;
+
+#endif /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */
diff --git a/libhardware/include/hardware/fused_location.h b/libhardware/include/hardware/fused_location.h
new file mode 100644
index 0000000..73360a1
--- /dev/null
+++ b/libhardware/include/hardware/fused_location.h
@@ -0,0 +1,825 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_HARDWARE_FUSED_LOCATION_H
+#define ANDROID_INCLUDE_HARDWARE_FUSED_LOCATION_H
+
+#include <hardware/hardware.h>
+
+
+/**
+ * This header file defines the interface of the Fused Location Provider.
+ * Fused Location Provider is designed to fuse data from various sources
+ * like GPS, Wifi, Cell, Sensors, Bluetooth etc to provide a fused location to the
+ * upper layers. The advantage of doing fusion in hardware is power savings.
+ * The goal is to do this without waking up the AP to get additional data.
+ * The software implementation of FLP will decide when to use
+ * the hardware fused location. Other location features like geofencing will
+ * also be implemented using fusion in hardware.
+ */
+__BEGIN_DECLS
+
+#define FLP_HEADER_VERSION 1
+#define FLP_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+#define FLP_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, FLP_HEADER_VERSION)
+
+/**
+ * The id of this module
+ */
+#define FUSED_LOCATION_HARDWARE_MODULE_ID "flp"
+
+/**
+ * Name for the FLP location interface
+ */
+#define FLP_LOCATION_INTERFACE "flp_location"
+
+/**
+ * Name for the FLP location interface
+ */
+#define FLP_DIAGNOSTIC_INTERFACE "flp_diagnostic"
+
+/**
+ * Name for the FLP_Geofencing interface.
+ */
+#define FLP_GEOFENCING_INTERFACE "flp_geofencing"
+
+/**
+ * Name for the FLP_device context interface.
+ */
+#define FLP_DEVICE_CONTEXT_INTERFACE "flp_device_context"
+
+/**
+ * Constants to indicate the various subsystems
+ * that will be used.
+ */
+#define FLP_TECH_MASK_GNSS (1U<<0)
+#define FLP_TECH_MASK_WIFI (1U<<1)
+#define FLP_TECH_MASK_SENSORS (1U<<2)
+#define FLP_TECH_MASK_CELL (1U<<3)
+#define FLP_TECH_MASK_BLUETOOTH (1U<<4)
+
+/**
+ * Set when your implementation can produce GNNS-derived locations,
+ * for use with flp_capabilities_callback.
+ *
+ * GNNS is a required capability for a particular feature to be used
+ * (batching or geofencing). If not supported that particular feature
+ * won't be used by the upper layer.
+ */
+#define CAPABILITY_GNSS (1U<<0)
+/**
+ * Set when your implementation can produce WiFi-derived locations, for
+ * use with flp_capabilities_callback.
+ */
+#define CAPABILITY_WIFI (1U<<1)
+/**
+ * Set when your implementation can produce cell-derived locations, for
+ * use with flp_capabilities_callback.
+ */
+#define CAPABILITY_CELL (1U<<3)
+
+/**
+ * Status to return in flp_status_callback when your implementation transitions
+ * from being unsuccessful in determining location to being successful.
+ */
+#define FLP_STATUS_LOCATION_AVAILABLE 0
+/**
+ * Status to return in flp_status_callback when your implementation transitions
+ * from being successful in determining location to being unsuccessful.
+ */
+#define FLP_STATUS_LOCATION_UNAVAILABLE 1
+
+/**
+ * This constant is used with the batched locations
+ * APIs. Batching is mandatory when FLP implementation
+ * is supported. If the flag is set, the hardware implementation
+ * will wake up the application processor when the FIFO is full,
+ * If the flag is not set, the hardware implementation will drop
+ * the oldest data when the FIFO is full.
+ */
+#define FLP_BATCH_WAKEUP_ON_FIFO_FULL 0x0000001
+
+/**
+ * While batching, the implementation should not call the
+ * flp_location_callback on every location fix. However,
+ * sometimes in high power mode, the system might need
+ * a location callback every single time the location
+ * fix has been obtained. This flag controls that option.
+ * Its the responsibility of the upper layers (caller) to switch
+ * it off, if it knows that the AP might go to sleep.
+ * When this bit is on amidst a batching session, batching should
+ * continue while location fixes are reported in real time.
+ */
+#define FLP_BATCH_CALLBACK_ON_LOCATION_FIX 0x0000002
+
+/** Flags to indicate which values are valid in a FlpLocation. */
+typedef uint16_t FlpLocationFlags;
+
+// IMPORTANT: Note that the following values must match
+// constants in the corresponding java file.
+
+/** FlpLocation has valid latitude and longitude. */
+#define FLP_LOCATION_HAS_LAT_LONG (1U<<0)
+/** FlpLocation has valid altitude. */
+#define FLP_LOCATION_HAS_ALTITUDE (1U<<1)
+/** FlpLocation has valid speed. */
+#define FLP_LOCATION_HAS_SPEED (1U<<2)
+/** FlpLocation has valid bearing. */
+#define FLP_LOCATION_HAS_BEARING (1U<<4)
+/** FlpLocation has valid accuracy. */
+#define FLP_LOCATION_HAS_ACCURACY (1U<<8)
+
+
+typedef int64_t FlpUtcTime;
+
+/** Represents a location. */
+typedef struct {
+ /** set to sizeof(FlpLocation) */
+ size_t size;
+
+ /** Flags associated with the location object. */
+ FlpLocationFlags flags;
+
+ /** Represents latitude in degrees. */
+ double latitude;
+
+ /** Represents longitude in degrees. */
+ double longitude;
+
+ /**
+ * Represents altitude in meters above the WGS 84 reference
+ * ellipsoid. */
+ double altitude;
+
+ /** Represents speed in meters per second. */
+ float speed;
+
+ /** Represents heading in degrees. */
+ float bearing;
+
+ /** Represents expected accuracy in meters. */
+ float accuracy;
+
+ /** Timestamp for the location fix. */
+ FlpUtcTime timestamp;
+
+ /** Sources used, will be Bitwise OR of the FLP_TECH_MASK bits. */
+ uint32_t sources_used;
+} FlpLocation;
+
+typedef enum {
+ ASSOCIATE_JVM,
+ DISASSOCIATE_JVM,
+} ThreadEvent;
+
+/**
+ * Callback with location information.
+ * Can only be called from a thread associated to JVM using set_thread_event_cb.
+ * Parameters:
+ * num_locations is the number of batched locations available.
+ * location is the pointer to an array of pointers to location objects.
+ */
+typedef void (*flp_location_callback)(int32_t num_locations, FlpLocation** location);
+
+/**
+ * Callback utility for acquiring a wakelock.
+ * This can be used to prevent the CPU from suspending while handling FLP events.
+ */
+typedef void (*flp_acquire_wakelock)();
+
+/**
+ * Callback utility for releasing the FLP wakelock.
+ */
+typedef void (*flp_release_wakelock)();
+
+/**
+ * Callback for associating a thread that can call into the Java framework code.
+ * This must be used to initialize any threads that report events up to the framework.
+ * Return value:
+ * FLP_RESULT_SUCCESS on success.
+ * FLP_RESULT_ERROR if the association failed in the current thread.
+ */
+typedef int (*flp_set_thread_event)(ThreadEvent event);
+
+/**
+ * Callback for technologies supported by this implementation.
+ *
+ * Parameters: capabilities is a bitmask of FLP_CAPABILITY_* values describing
+ * which features your implementation supports. You should support
+ * CAPABILITY_GNSS at a minimum for your implementation to be utilized. You can
+ * return 0 in FlpGeofenceCallbacks to indicate you don't support geofencing,
+ * or 0 in FlpCallbacks to indicate you don't support location batching.
+ */
+typedef void (*flp_capabilities_callback)(int capabilities);
+
+/**
+ * Callback with status information on the ability to compute location.
+ * To avoid waking up the application processor you should only send
+ * changes in status (you shouldn't call this method twice in a row
+ * with the same status value). As a guideline you should not call this
+ * more frequently then the requested batch period set with period_ns
+ * in FlpBatchOptions. For example if period_ns is set to 5 minutes and
+ * the status changes many times in that interval, you should only report
+ * one status change every 5 minutes.
+ *
+ * Parameters:
+ * status is one of FLP_STATUS_LOCATION_AVAILABLE
+ * or FLP_STATUS_LOCATION_UNAVAILABLE.
+ */
+typedef void (*flp_status_callback)(int32_t status);
+
+/** FLP callback structure. */
+typedef struct {
+ /** set to sizeof(FlpCallbacks) */
+ size_t size;
+ flp_location_callback location_cb;
+ flp_acquire_wakelock acquire_wakelock_cb;
+ flp_release_wakelock release_wakelock_cb;
+ flp_set_thread_event set_thread_event_cb;
+ flp_capabilities_callback flp_capabilities_cb;
+ flp_status_callback flp_status_cb;
+} FlpCallbacks;
+
+
+/** Options with the batching FLP APIs */
+typedef struct {
+ /**
+ * Maximum power in mW that the underlying implementation
+ * can use for this batching call.
+ * If max_power_allocation_mW is 0, only fixes that are generated
+ * at no additional cost of power shall be reported.
+ */
+ double max_power_allocation_mW;
+
+ /** Bitwise OR of the FLP_TECH_MASKS to use */
+ uint32_t sources_to_use;
+
+ /**
+ * FLP_BATCH_WAKEUP_ON_FIFO_FULL - If set the hardware
+ * will wake up the AP when the buffer is full. If not set, the
+ * hardware will drop the oldest location object.
+ *
+ * FLP_BATCH_CALLBACK_ON_LOCATION_FIX - If set the location
+ * callback will be called every time there is a location fix.
+ * Its the responsibility of the upper layers (caller) to switch
+ * it off, if it knows that the AP might go to sleep. When this
+ * bit is on amidst a batching session, batching should continue
+ * while location fixes are reported in real time.
+ *
+ * Other flags to be bitwised ORed in the future.
+ */
+ uint32_t flags;
+
+ /**
+ * Frequency with which location needs to be batched in nano
+ * seconds.
+ */
+ int64_t period_ns;
+
+ /**
+ * The smallest displacement between reported locations in meters.
+ *
+ * If set to 0, then you should report locations at the requested
+ * interval even if the device is stationary. If positive, you
+ * can use this parameter as a hint to save power (e.g. throttling
+ * location period if the user hasn't traveled close to the displacement
+ * threshold). Even small positive values can be interpreted to mean
+ * that you don't have to compute location when the device is stationary.
+ *
+ * There is no need to filter location delivery based on this parameter.
+ * Locations can be delivered even if they have a displacement smaller than
+ * requested. This parameter can safely be ignored at the cost of potential
+ * power savings.
+ */
+ float smallest_displacement_meters;
+} FlpBatchOptions;
+
+#define FLP_RESULT_SUCCESS 0
+#define FLP_RESULT_ERROR -1
+#define FLP_RESULT_INSUFFICIENT_MEMORY -2
+#define FLP_RESULT_TOO_MANY_GEOFENCES -3
+#define FLP_RESULT_ID_EXISTS -4
+#define FLP_RESULT_ID_UNKNOWN -5
+#define FLP_RESULT_INVALID_GEOFENCE_TRANSITION -6
+
+/**
+ * Represents the standard FLP interface.
+ */
+typedef struct {
+ /**
+ * set to sizeof(FlpLocationInterface)
+ */
+ size_t size;
+
+ /**
+ * Opens the interface and provides the callback routines
+ * to the implementation of this interface. Once called you should respond
+ * by calling the flp_capabilities_callback in FlpCallbacks to
+ * specify the capabilities that your implementation supports.
+ */
+ int (*init)(FlpCallbacks* callbacks );
+
+ /**
+ * Return the batch size (in number of FlpLocation objects)
+ * available in the hardware. Note, different HW implementations
+ * may have different sample sizes. This shall return number
+ * of samples defined in the format of FlpLocation.
+ * This will be used by the upper layer, to decide on the batching
+ * interval and whether the AP should be woken up or not.
+ */
+ int (*get_batch_size)();
+
+ /**
+ * Start batching locations. This API is primarily used when the AP is
+ * asleep and the device can batch locations in the hardware.
+ * flp_location_callback is used to return the locations. When the buffer
+ * is full and FLP_BATCH_WAKEUP_ON_FIFO_FULL is used, the AP is woken up.
+ * When the buffer is full and FLP_BATCH_WAKEUP_ON_FIFO_FULL is not set,
+ * the oldest location object is dropped. In this case the AP will not be
+ * woken up. The upper layer will use get_batched_location
+ * API to explicitly ask for the location.
+ * If FLP_BATCH_CALLBACK_ON_LOCATION_FIX is set, the implementation
+ * will call the flp_location_callback every single time there is a location
+ * fix. This overrides FLP_BATCH_WAKEUP_ON_FIFO_FULL flag setting.
+ * It's the responsibility of the upper layers (caller) to switch
+ * it off, if it knows that the AP might go to sleep. This is useful
+ * for nagivational applications when the system is in high power mode.
+ * Parameters:
+ * id - Id for the request.
+ * options - See FlpBatchOptions struct definition.
+ * Return value:
+ * FLP_RESULT_SUCCESS on success, FLP_RESULT_INSUFFICIENT_MEMORY,
+ * FLP_RESULT_ID_EXISTS, FLP_RESULT_ERROR on failure.
+ */
+ int (*start_batching)(int id, FlpBatchOptions* options);
+
+ /**
+ * Update FlpBatchOptions associated with a batching request.
+ * When a batching operation is in progress and a batching option
+ * such as FLP_BATCH_WAKEUP_ON_FIFO_FULL needs to be updated, this API
+ * will be used. For instance, this can happen when the AP is awake and
+ * the maps application is being used.
+ * Parameters:
+ * id - Id of an existing batch request.
+ * new_options - Updated FlpBatchOptions
+ * Return value:
+ * FLP_RESULT_SUCCESS on success, FLP_RESULT_ID_UNKNOWN,
+ * FLP_RESULT_ERROR on error.
+ */
+ int (*update_batching_options)(int id, FlpBatchOptions* new_options);
+
+ /**
+ * Stop batching.
+ * Parameters:
+ * id - Id for the request.
+ * Return Value:
+ * FLP_RESULT_SUCCESS on success, FLP_RESULT_ID_UNKNOWN or
+ * FLP_RESULT_ERROR on failure.
+ */
+ int (*stop_batching)(int id);
+
+ /**
+ * Closes the interface. If any batch operations are in progress,
+ * they should be stopped.
+ */
+ void (*cleanup)();
+
+ /**
+ * Get the fused location that was batched.
+ * flp_location_callback is used to return the location. The location object
+ * is dropped from the buffer only when the buffer is full. Do not remove it
+ * from the buffer just because it has been returned using the callback.
+ * In other words, when there is no new location object, two calls to
+ * get_batched_location(1) should return the same location object.
+ * Parameters:
+ * last_n_locations - Number of locations to get. This can be one or many.
+ * If the last_n_locations is 1, you get the latest location known to the
+ * hardware.
+ */
+ void (*get_batched_location)(int last_n_locations);
+
+ /**
+ * Injects current location from another location provider
+ * latitude and longitude are measured in degrees
+ * expected accuracy is measured in meters
+ * Parameters:
+ * location - The location object being injected.
+ * Return value: FLP_RESULT_SUCCESS or FLP_RESULT_ERROR.
+ */
+ int (*inject_location)(FlpLocation* location);
+
+ /**
+ * Get a pointer to extension information.
+ */
+ const void* (*get_extension)(const char* name);
+
+ /**
+ * Retrieve all batched locations currently stored and clear the buffer.
+ * flp_location_callback MUST be called in response, even if there are
+ * no locations to flush (in which case num_locations should be 0).
+ * Subsequent calls to get_batched_location or flush_batched_locations
+ * should not return any of the locations returned in this call.
+ */
+ void (*flush_batched_locations)();
+} FlpLocationInterface;
+
+struct flp_device_t {
+ struct hw_device_t common;
+
+ /**
+ * Get a handle to the FLP Interface.
+ */
+ const FlpLocationInterface* (*get_flp_interface)(struct flp_device_t* dev);
+};
+
+/**
+ * Callback for reports diagnostic data into the Java framework code.
+*/
+typedef void (*report_data)(char* data, int length);
+
+/**
+ * FLP diagnostic callback structure.
+ * Currently, not used - but this for future extension.
+ */
+typedef struct {
+ /** set to sizeof(FlpDiagnosticCallbacks) */
+ size_t size;
+
+ flp_set_thread_event set_thread_event_cb;
+
+ /** reports diagnostic data into the Java framework code */
+ report_data data_cb;
+} FlpDiagnosticCallbacks;
+
+/** Extended interface for diagnostic support. */
+typedef struct {
+ /** set to sizeof(FlpDiagnosticInterface) */
+ size_t size;
+
+ /**
+ * Opens the diagnostic interface and provides the callback routines
+ * to the implemenation of this interface.
+ */
+ void (*init)(FlpDiagnosticCallbacks* callbacks);
+
+ /**
+ * Injects diagnostic data into the FLP subsystem.
+ * Return 0 on success, -1 on error.
+ **/
+ int (*inject_data)(char* data, int length );
+} FlpDiagnosticInterface;
+
+/**
+ * Context setting information.
+ * All these settings shall be injected to FLP HAL at FLP init time.
+ * Following that, only the changed setting need to be re-injected
+ * upon changes.
+ */
+
+#define FLP_DEVICE_CONTEXT_GPS_ENABLED (1U<<0)
+#define FLP_DEVICE_CONTEXT_AGPS_ENABLED (1U<<1)
+#define FLP_DEVICE_CONTEXT_NETWORK_POSITIONING_ENABLED (1U<<2)
+#define FLP_DEVICE_CONTEXT_WIFI_CONNECTIVITY_ENABLED (1U<<3)
+#define FLP_DEVICE_CONTEXT_WIFI_POSITIONING_ENABLED (1U<<4)
+#define FLP_DEVICE_CONTEXT_HW_NETWORK_POSITIONING_ENABLED (1U<<5)
+#define FLP_DEVICE_CONTEXT_AIRPLANE_MODE_ON (1U<<6)
+#define FLP_DEVICE_CONTEXT_DATA_ENABLED (1U<<7)
+#define FLP_DEVICE_CONTEXT_ROAMING_ENABLED (1U<<8)
+#define FLP_DEVICE_CONTEXT_CURRENTLY_ROAMING (1U<<9)
+#define FLP_DEVICE_CONTEXT_SENSOR_ENABLED (1U<<10)
+#define FLP_DEVICE_CONTEXT_BLUETOOTH_ENABLED (1U<<11)
+#define FLP_DEVICE_CONTEXT_CHARGER_ON (1U<<12)
+
+/** Extended interface for device context support. */
+typedef struct {
+ /** set to sizeof(FlpDeviceContextInterface) */
+ size_t size;
+
+ /**
+ * Injects debug data into the FLP subsystem.
+ * Return 0 on success, -1 on error.
+ **/
+ int (*inject_device_context)(uint32_t enabledMask);
+} FlpDeviceContextInterface;
+
+
+/**
+ * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
+ * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
+ *
+ * An example state diagram with confidence level: 95% and Unknown time limit
+ * set as 30 secs is shown below. (confidence level and Unknown time limit are
+ * explained latter)
+ * ____________________________
+ * | Unknown (30 secs) |
+ * """"""""""""""""""""""""""""
+ * ^ | | ^
+ * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
+ * | v v |
+ * ________ EXITED _________
+ * | Inside | -----------> | Outside |
+ * | | <----------- | |
+ * """""""" ENTERED """""""""
+ *
+ * Inside state: We are 95% confident that the user is inside the geofence.
+ * Outside state: We are 95% confident that the user is outside the geofence
+ * Unknown state: Rest of the time.
+ *
+ * The Unknown state is better explained with an example:
+ *
+ * __________
+ * | c|
+ * | ___ | _______
+ * | |a| | | b |
+ * | """ | """""""
+ * | |
+ * """"""""""
+ * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
+ * circle reported by the FLP subsystem. Now with regard to "b", the system is
+ * confident that the user is outside. But with regard to "a" is not confident
+ * whether it is inside or outside the geofence. If the accuracy remains the
+ * same for a sufficient period of time, the UNCERTAIN transition would be
+ * triggered with the state set to Unknown. If the accuracy improves later, an
+ * appropriate transition should be triggered. This "sufficient period of time"
+ * is defined by the parameter in the add_geofence_area API.
+ * In other words, Unknown state can be interpreted as a state in which the
+ * FLP subsystem isn't confident enough that the user is either inside or
+ * outside the Geofence. It moves to Unknown state only after the expiry of the
+ * timeout.
+ *
+ * The geofence callback needs to be triggered for the ENTERED and EXITED
+ * transitions, when the FLP system is confident that the user has entered
+ * (Inside state) or exited (Outside state) the Geofence. An implementation
+ * which uses a value of 95% as the confidence is recommended. The callback
+ * should be triggered only for the transitions requested by the
+ * add_geofence_area call.
+ *
+ * Even though the diagram and explanation talks about states and transitions,
+ * the callee is only interested in the transistions. The states are mentioned
+ * here for illustrative purposes.
+ *
+ * Startup Scenario: When the device boots up, if an application adds geofences,
+ * and then we get an accurate FLP location fix, it needs to trigger the
+ * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
+ * By default, all the Geofences will be in the Unknown state.
+ *
+ * When the FLP system is unavailable, flp_geofence_status_callback should be
+ * called to inform the upper layers of the same. Similarly, when it becomes
+ * available the callback should be called. This is a global state while the
+ * UNKNOWN transition described above is per geofence.
+ *
+ */
+#define FLP_GEOFENCE_TRANSITION_ENTERED (1L<<0)
+#define FLP_GEOFENCE_TRANSITION_EXITED (1L<<1)
+#define FLP_GEOFENCE_TRANSITION_UNCERTAIN (1L<<2)
+
+#define FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE (1L<<0)
+#define FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE (1L<<1)
+
+/**
+ * The callback associated with the geofence.
+ * Parameters:
+ * geofence_id - The id associated with the add_geofence_area.
+ * location - The current location as determined by the FLP subsystem.
+ * transition - Can be one of FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED,
+ * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
+ * timestamp - Timestamp when the transition was detected; -1 if not available.
+ * sources_used - Bitwise OR of FLP_TECH_MASK flags indicating which
+ * subsystems were used.
+ *
+ * The callback should only be called when the caller is interested in that
+ * particular transition. For instance, if the caller is interested only in
+ * ENTERED transition, then the callback should NOT be called with the EXITED
+ * transition.
+ *
+ * IMPORTANT: If a transition is triggered resulting in this callback, the
+ * subsystem will wake up the application processor, if its in suspend state.
+ */
+typedef void (*flp_geofence_transition_callback) (int32_t geofence_id, FlpLocation* location,
+ int32_t transition, FlpUtcTime timestamp, uint32_t sources_used);
+
+/**
+ * The callback associated with the availablity of one the sources used for geofence
+ * monitoring by the FLP sub-system For example, if the GPS system determines that it cannot
+ * monitor geofences because of lack of reliability or unavailability of the GPS signals,
+ * it will call this callback with FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE parameter and the
+ * source set to FLP_TECH_MASK_GNSS.
+ *
+ * Parameters:
+ * status - FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE or FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE.
+ * source - One of the FLP_TECH_MASKS
+ * last_location - Last known location.
+ */
+typedef void (*flp_geofence_monitor_status_callback) (int32_t status, uint32_t source,
+ FlpLocation* last_location);
+
+/**
+ * The callback associated with the add_geofence call.
+ *
+ * Parameter:
+ * geofence_id - Id of the geofence.
+ * result - FLP_RESULT_SUCCESS
+ * FLP_RESULT_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
+ * FLP_RESULT_ID_EXISTS - geofence with id already exists
+ * FLP_RESULT_INVALID_GEOFENCE_TRANSITION - the monitorTransition contains an
+ * invalid transition
+ * FLP_RESULT_ERROR - for other errors.
+ */
+typedef void (*flp_geofence_add_callback) (int32_t geofence_id, int32_t result);
+
+/**
+ * The callback associated with the remove_geofence call.
+ *
+ * Parameter:
+ * geofence_id - Id of the geofence.
+ * result - FLP_RESULT_SUCCESS
+ * FLP_RESULT_ID_UNKNOWN - for invalid id
+ * FLP_RESULT_ERROR for others.
+ */
+typedef void (*flp_geofence_remove_callback) (int32_t geofence_id, int32_t result);
+
+
+/**
+ * The callback associated with the pause_geofence call.
+ *
+ * Parameter:
+ * geofence_id - Id of the geofence.
+ * result - FLP_RESULT_SUCCESS
+ * FLP_RESULT__ID_UNKNOWN - for invalid id
+ * FLP_RESULT_INVALID_TRANSITION -
+ * when monitor_transitions is invalid
+ * FLP_RESULT_ERROR for others.
+ */
+typedef void (*flp_geofence_pause_callback) (int32_t geofence_id, int32_t result);
+
+/**
+ * The callback associated with the resume_geofence call.
+ *
+ * Parameter:
+ * geofence_id - Id of the geofence.
+ * result - FLP_RESULT_SUCCESS
+ * FLP_RESULT_ID_UNKNOWN - for invalid id
+ * FLP_RESULT_ERROR for others.
+ */
+typedef void (*flp_geofence_resume_callback) (int32_t geofence_id, int32_t result);
+
+typedef struct {
+ /** set to sizeof(FlpGeofenceCallbacks) */
+ size_t size;
+ flp_geofence_transition_callback geofence_transition_callback;
+ flp_geofence_monitor_status_callback geofence_status_callback;
+ flp_geofence_add_callback geofence_add_callback;
+ flp_geofence_remove_callback geofence_remove_callback;
+ flp_geofence_pause_callback geofence_pause_callback;
+ flp_geofence_resume_callback geofence_resume_callback;
+ flp_set_thread_event set_thread_event_cb;
+ flp_capabilities_callback flp_capabilities_cb;
+} FlpGeofenceCallbacks;
+
+
+/** Type of geofence */
+typedef enum {
+ TYPE_CIRCLE = 0,
+} GeofenceType;
+
+/** Circular geofence is represented by lat / long / radius */
+typedef struct {
+ double latitude;
+ double longitude;
+ double radius_m;
+} GeofenceCircle;
+
+/** Represents the type of geofence and data */
+typedef struct {
+ GeofenceType type;
+ union {
+ GeofenceCircle circle;
+ } geofence;
+} GeofenceData;
+
+/** Geofence Options */
+typedef struct {
+ /**
+ * The current state of the geofence. For example, if
+ * the system already knows that the user is inside the geofence,
+ * this will be set to FLP_GEOFENCE_TRANSITION_ENTERED. In most cases, it
+ * will be FLP_GEOFENCE_TRANSITION_UNCERTAIN. */
+ int last_transition;
+
+ /**
+ * Transitions to monitor. Bitwise OR of
+ * FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED and
+ * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
+ */
+ int monitor_transitions;
+
+ /**
+ * Defines the best-effort description
+ * of how soon should the callback be called when the transition
+ * associated with the Geofence is triggered. For instance, if set
+ * to 1000 millseconds with FLP_GEOFENCE_TRANSITION_ENTERED, the callback
+ * should be called 1000 milliseconds within entering the geofence.
+ * This parameter is defined in milliseconds.
+ * NOTE: This is not to be confused with the rate that the GPS is
+ * polled at. It is acceptable to dynamically vary the rate of
+ * sampling the GPS for power-saving reasons; thus the rate of
+ * sampling may be faster or slower than this.
+ */
+ int notification_responsivenes_ms;
+
+ /**
+ * The time limit after which the UNCERTAIN transition
+ * should be triggered. This paramter is defined in milliseconds.
+ */
+ int unknown_timer_ms;
+
+ /**
+ * The sources to use for monitoring geofences. Its a BITWISE-OR
+ * of FLP_TECH_MASK flags.
+ */
+ uint32_t sources_to_use;
+} GeofenceOptions;
+
+/** Geofence struct */
+typedef struct {
+ int32_t geofence_id;
+ GeofenceData* data;
+ GeofenceOptions* options;
+} Geofence;
+
+/** Extended interface for FLP_Geofencing support */
+typedef struct {
+ /** set to sizeof(FlpGeofencingInterface) */
+ size_t size;
+
+ /**
+ * Opens the geofence interface and provides the callback routines
+ * to the implemenation of this interface. Once called you should respond
+ * by calling the flp_capabilities_callback in FlpGeofenceCallbacks to
+ * specify the capabilities that your implementation supports.
+ */
+ void (*init)( FlpGeofenceCallbacks* callbacks );
+
+ /**
+ * Add a list of geofences.
+ * Parameters:
+ * number_of_geofences - The number of geofences that needed to be added.
+ * geofences - Pointer to array of pointers to Geofence structure.
+ */
+ void (*add_geofences) (int32_t number_of_geofences, Geofence** geofences);
+
+ /**
+ * Pause monitoring a particular geofence.
+ * Parameters:
+ * geofence_id - The id for the geofence.
+ */
+ void (*pause_geofence) (int32_t geofence_id);
+
+ /**
+ * Resume monitoring a particular geofence.
+ * Parameters:
+ * geofence_id - The id for the geofence.
+ * monitor_transitions - Which transitions to monitor. Bitwise OR of
+ * FLP_GEOFENCE_TRANSITION_ENTERED, FLP_GEOFENCE_TRANSITION_EXITED and
+ * FLP_GEOFENCE_TRANSITION_UNCERTAIN.
+ * This supersedes the value associated provided in the
+ * add_geofence_area call.
+ */
+ void (*resume_geofence) (int32_t geofence_id, int monitor_transitions);
+
+ /**
+ * Modify a particular geofence option.
+ * Parameters:
+ * geofence_id - The id for the geofence.
+ * options - Various options associated with the geofence. See
+ * GeofenceOptions structure for details.
+ */
+ void (*modify_geofence_option) (int32_t geofence_id, GeofenceOptions* options);
+
+ /**
+ * Remove a list of geofences. After the function returns, no notifications
+ * should be sent.
+ * Parameter:
+ * number_of_geofences - The number of geofences that needed to be added.
+ * geofence_id - Pointer to array of geofence_ids to be removed.
+ */
+ void (*remove_geofences) (int32_t number_of_geofences, int32_t* geofence_id);
+} FlpGeofencingInterface;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_HARDWARE_FLP_H */
+
diff --git a/libhardware/include/hardware/gatekeeper.h b/libhardware/include/hardware/gatekeeper.h
new file mode 100644
index 0000000..2bb2b08
--- /dev/null
+++ b/libhardware/include/hardware/gatekeeper.h
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HARDWARE_GATEKEEPER_H
+#define ANDROID_HARDWARE_GATEKEEPER_H
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define GATEKEEPER_HARDWARE_MODULE_ID "gatekeeper"
+
+#define GATEKEEPER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+
+#define HARDWARE_GATEKEEPER "gatekeeper"
+
+struct gatekeeper_module {
+ /**
+ * Comon methods of the gatekeeper module. This *must* be the first member of
+ * gatekeeper_module as users of this structure will cast a hw_module_t to
+ * a gatekeeper_module pointer in the appropriate context.
+ */
+ hw_module_t common;
+};
+
+struct gatekeeper_device {
+ /**
+ * Common methods of the gatekeeper device. As above, this must be the first
+ * member of keymaster_device.
+ */
+ hw_device_t common;
+
+ /**
+ * Enrolls desired_password, which should be derived from a user selected pin or password,
+ * with the authentication factor private key used only for enrolling authentication
+ * factor data.
+ *
+ * If there was already a password enrolled, it should be provided in
+ * current_password_handle, along with the current password in current_password
+ * that should validate against current_password_handle.
+ *
+ * Parameters:
+ * - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open
+ * - uid: the Android user identifier
+ *
+ * - current_password_handle: the currently enrolled password handle the user
+ * wants to replace. May be null if there's no currently enrolled password.
+ * - current_password_handle_length: the length in bytes of the buffer pointed
+ * at by current_password_handle. Must be 0 if current_password_handle is NULL.
+ *
+ * - current_password: the user's current password in plain text. If presented,
+ * it MUST verify against current_password_handle.
+ * - current_password_length: the size in bytes of the buffer pointed at by
+ * current_password. Must be 0 if the current_password is NULL.
+ *
+ * - desired_password: the new password the user wishes to enroll in plain-text.
+ * Cannot be NULL.
+ * - desired_password_length: the length in bytes of the buffer pointed at by
+ * desired_password.
+ *
+ * - enrolled_password_handle: on success, a buffer will be allocated with the
+ * new password handle referencing the password provided in desired_password.
+ * This buffer can be used on subsequent calls to enroll or verify.
+ * The caller is responsible for deallocating this buffer via a call to delete[]
+ * - enrolled_password_handle_length: pointer to the length in bytes of the buffer allocated
+ * by this function and pointed to by *enrolled_password_handle_length.
+ *
+ * Returns:
+ * - 0 on success
+ * - An error code < 0 on failure, or
+ * - A timeout value T > 0 if the call should not be re-attempted until T milliseconds
+ * have elapsed.
+ *
+ * On error, enrolled_password_handle will not be allocated.
+ */
+ int (*enroll)(const struct gatekeeper_device *dev, uint32_t uid,
+ const uint8_t *current_password_handle, uint32_t current_password_handle_length,
+ const uint8_t *current_password, uint32_t current_password_length,
+ const uint8_t *desired_password, uint32_t desired_password_length,
+ uint8_t **enrolled_password_handle, uint32_t *enrolled_password_handle_length);
+
+ /**
+ * Verifies provided_password matches enrolled_password_handle.
+ *
+ * Implementations of this module may retain the result of this call
+ * to attest to the recency of authentication.
+ *
+ * On success, writes the address of a verification token to auth_token,
+ * usable to attest password verification to other trusted services. Clients
+ * may pass NULL for this value.
+ *
+ * Parameters:
+ * - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open
+ * - uid: the Android user identifier
+ *
+ * - challenge: An optional challenge to authenticate against, or 0. Used when a separate
+ * authenticator requests password verification, or for transactional
+ * password authentication.
+ *
+ * - enrolled_password_handle: the currently enrolled password handle that the
+ * user wishes to verify against.
+ * - enrolled_password_handle_length: the length in bytes of the buffer pointed
+ * to by enrolled_password_handle
+ *
+ * - provided_password: the plaintext password to be verified against the
+ * enrolled_password_handle
+ * - provided_password_length: the length in bytes of the buffer pointed to by
+ * provided_password
+ *
+ * - auth_token: on success, a buffer containing the authentication token
+ * resulting from this verification is assigned to *auth_token. The caller
+ * is responsible for deallocating this memory via a call to delete[]
+ * - auth_token_length: on success, the length in bytes of the authentication
+ * token assigned to *auth_token will be assigned to *auth_token_length
+ *
+ * - request_reenroll: a request to the upper layers to re-enroll the verified
+ * password due to a version change. Not set if verification fails.
+ *
+ * Returns:
+ * - 0 on success
+ * - An error code < 0 on failure, or
+ * - A timeout value T > 0 if the call should not be re-attempted until T milliseconds
+ * have elapsed.
+ * On error, auth token will not be allocated
+ */
+ int (*verify)(const struct gatekeeper_device *dev, uint32_t uid, uint64_t challenge,
+ const uint8_t *enrolled_password_handle, uint32_t enrolled_password_handle_length,
+ const uint8_t *provided_password, uint32_t provided_password_length,
+ uint8_t **auth_token, uint32_t *auth_token_length, bool *request_reenroll);
+
+ /*
+ * Deletes the enrolled_password_handle associated wth the uid. Once deleted
+ * the user cannot be verified anymore.
+ * This function is optional and should be set to NULL if it is not implemented.
+ *
+ * Parameters
+ * - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open
+ * - uid: the Android user identifier
+ *
+ * Returns:
+ * - 0 on success
+ * - An error code < 0 on failure
+ */
+ int (*delete_user)(const struct gatekeeper_device *dev, uint32_t uid);
+
+ /*
+ * Deletes all the enrolled_password_handles for all uid's. Once called,
+ * no users will be enrolled on the device.
+ * This function is optional and should be set to NULL if it is not implemented.
+ *
+ * Parameters
+ * - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open
+ *
+ * Returns:
+ * - 0 on success
+ * - An error code < 0 on failure
+ */
+ int (*delete_all_users)(const struct gatekeeper_device *dev);
+};
+
+typedef struct gatekeeper_device gatekeeper_device_t;
+
+static inline int gatekeeper_open(const struct hw_module_t *module,
+ gatekeeper_device_t **device) {
+ return module->methods->open(module, HARDWARE_GATEKEEPER,
+ (struct hw_device_t **) device);
+}
+
+static inline int gatekeeper_close(gatekeeper_device_t *device) {
+ return device->common.close(&device->common);
+}
+
+__END_DECLS
+
+#endif // ANDROID_HARDWARE_GATEKEEPER_H
diff --git a/libhardware/include/hardware/gps.h b/libhardware/include/hardware/gps.h
new file mode 100644
index 0000000..76b6cb7
--- /dev/null
+++ b/libhardware/include/hardware/gps.h
@@ -0,0 +1,1871 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_HARDWARE_GPS_H
+#define ANDROID_INCLUDE_HARDWARE_GPS_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include <sys/socket.h>
+#include <stdbool.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define GPS_HARDWARE_MODULE_ID "gps"
+
+
+/** Milliseconds since January 1, 1970 */
+typedef int64_t GpsUtcTime;
+
+/** Maximum number of SVs for gps_sv_status_callback(). */
+#define GPS_MAX_SVS 32
+
+/** Maximum number of Measurements in gps_measurement_callback(). */
+#define GPS_MAX_MEASUREMENT 32
+
+/** Requested operational mode for GPS operation. */
+typedef uint32_t GpsPositionMode;
+// IMPORTANT: Note that the following values must match
+// constants in GpsLocationProvider.java.
+/** Mode for running GPS standalone (no assistance). */
+#define GPS_POSITION_MODE_STANDALONE 0
+/** AGPS MS-Based mode. */
+#define GPS_POSITION_MODE_MS_BASED 1
+/**
+ * AGPS MS-Assisted mode. This mode is not maintained by the platform anymore.
+ * It is strongly recommended to use GPS_POSITION_MODE_MS_BASE instead.
+ */
+#define GPS_POSITION_MODE_MS_ASSISTED 2
+
+/** Requested recurrence mode for GPS operation. */
+typedef uint32_t GpsPositionRecurrence;
+// IMPORTANT: Note that the following values must match
+// constants in GpsLocationProvider.java.
+/** Receive GPS fixes on a recurring basis at a specified period. */
+#define GPS_POSITION_RECURRENCE_PERIODIC 0
+/** Request a single shot GPS fix. */
+#define GPS_POSITION_RECURRENCE_SINGLE 1
+
+/** GPS status event values. */
+typedef uint16_t GpsStatusValue;
+// IMPORTANT: Note that the following values must match
+// constants in GpsLocationProvider.java.
+/** GPS status unknown. */
+#define GPS_STATUS_NONE 0
+/** GPS has begun navigating. */
+#define GPS_STATUS_SESSION_BEGIN 1
+/** GPS has stopped navigating. */
+#define GPS_STATUS_SESSION_END 2
+/** GPS has powered on but is not navigating. */
+#define GPS_STATUS_ENGINE_ON 3
+/** GPS is powered off. */
+#define GPS_STATUS_ENGINE_OFF 4
+
+/** Flags to indicate which values are valid in a GpsLocation. */
+typedef uint16_t GpsLocationFlags;
+// IMPORTANT: Note that the following values must match
+// constants in GpsLocationProvider.java.
+/** GpsLocation has valid latitude and longitude. */
+#define GPS_LOCATION_HAS_LAT_LONG 0x0001
+/** GpsLocation has valid altitude. */
+#define GPS_LOCATION_HAS_ALTITUDE 0x0002
+/** GpsLocation has valid speed. */
+#define GPS_LOCATION_HAS_SPEED 0x0004
+/** GpsLocation has valid bearing. */
+#define GPS_LOCATION_HAS_BEARING 0x0008
+/** GpsLocation has valid accuracy. */
+#define GPS_LOCATION_HAS_ACCURACY 0x0010
+
+/** Flags for the gps_set_capabilities callback. */
+
+/** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode.
+ If this is not set, then the framework will use 1000ms for min_interval
+ and will start and call start() and stop() to schedule the GPS.
+ */
+#define GPS_CAPABILITY_SCHEDULING 0x0000001
+/** GPS supports MS-Based AGPS mode */
+#define GPS_CAPABILITY_MSB 0x0000002
+/** GPS supports MS-Assisted AGPS mode */
+#define GPS_CAPABILITY_MSA 0x0000004
+/** GPS supports single-shot fixes */
+#define GPS_CAPABILITY_SINGLE_SHOT 0x0000008
+/** GPS supports on demand time injection */
+#define GPS_CAPABILITY_ON_DEMAND_TIME 0x0000010
+/** GPS supports Geofencing */
+#define GPS_CAPABILITY_GEOFENCING 0x0000020
+/** GPS supports Measurements */
+#define GPS_CAPABILITY_MEASUREMENTS 0x0000040
+/** GPS supports Navigation Messages */
+#define GPS_CAPABILITY_NAV_MESSAGES 0x0000080
+
+/** Flags used to specify which aiding data to delete
+ when calling delete_aiding_data(). */
+typedef uint16_t GpsAidingData;
+// IMPORTANT: Note that the following values must match
+// con