Merge "Add driving status to default vehicle HAL"
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index f9e3276..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(call all-subdir-makefiles)
diff --git a/boot/1.0/default/BootControl.h b/boot/1.0/default/BootControl.h
index 73af4f4..be8a814 100644
--- a/boot/1.0/default/BootControl.h
+++ b/boot/1.0/default/BootControl.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_boot_V1_0_BootControl_H_
-#define HIDL_GENERATED_android_hardware_boot_V1_0_BootControl_H_
+#ifndef ANDROID_HARDWARE_BOOT_V1_0_BOOTCONTROL_H
+#define ANDROID_HARDWARE_BOOT_V1_0_BOOTCONTROL_H
#include <android/hardware/boot/1.0/IBootControl.h>
#include <hidl/Status.h>
@@ -43,4 +43,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_boot_V1_0_BootControl_H_
+#endif // ANDROID_HARDWARE_BOOT_V1_0_BOOTCONTROL_H
diff --git a/dumpstate/1.0/Android.bp b/dumpstate/1.0/Android.bp
new file mode 100644
index 0000000..ab34af2
--- /dev/null
+++ b/dumpstate/1.0/Android.bp
@@ -0,0 +1,50 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+genrule {
+ name: "android.hardware.dumpstate@1.0_genc++",
+ tools: ["hidl-gen"],
+ cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces android.hardware.dumpstate@1.0",
+ srcs: [
+ "IDumpstateDevice.hal",
+ ],
+ out: [
+ "android/hardware/dumpstate/1.0/DumpstateDeviceAll.cpp",
+ ],
+}
+
+genrule {
+ name: "android.hardware.dumpstate@1.0_genc++_headers",
+ tools: ["hidl-gen"],
+ cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces android.hardware.dumpstate@1.0",
+ srcs: [
+ "IDumpstateDevice.hal",
+ ],
+ out: [
+ "android/hardware/dumpstate/1.0/IDumpstateDevice.h",
+ "android/hardware/dumpstate/1.0/IHwDumpstateDevice.h",
+ "android/hardware/dumpstate/1.0/BnDumpstateDevice.h",
+ "android/hardware/dumpstate/1.0/BpDumpstateDevice.h",
+ "android/hardware/dumpstate/1.0/BsDumpstateDevice.h",
+ ],
+}
+
+cc_library_shared {
+ name: "android.hardware.dumpstate@1.0",
+ generated_sources: ["android.hardware.dumpstate@1.0_genc++"],
+ generated_headers: ["android.hardware.dumpstate@1.0_genc++_headers"],
+ export_generated_headers: ["android.hardware.dumpstate@1.0_genc++_headers"],
+ shared_libs: [
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "liblog",
+ "libutils",
+ "libcutils",
+ ],
+ export_shared_lib_headers: [
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "libutils",
+ ],
+}
diff --git a/dumpstate/1.0/IDumpstateDevice.hal b/dumpstate/1.0/IDumpstateDevice.hal
new file mode 100644
index 0000000..fec3eb4
--- /dev/null
+++ b/dumpstate/1.0/IDumpstateDevice.hal
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+package android.hardware.dumpstate@1.0;
+
+interface IDumpstateDevice {
+ /*
+ * Dumps device-specific state into the given file descriptor.
+ */
+ dumpstateBoard(handle h);
+};
diff --git a/dumpstate/1.0/default/Android.mk b/dumpstate/1.0/default/Android.mk
new file mode 100644
index 0000000..4d5c908
--- /dev/null
+++ b/dumpstate/1.0/default/Android.mk
@@ -0,0 +1,22 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.dumpstate@1.0-impl
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := \
+ DumpstateDevice.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+ android.hardware.dumpstate@1.0 \
+ libbase \
+ libcutils \
+ libhidlbase \
+ libhidltransport \
+ libhwbinder \
+ liblog \
+ libutils
+
+LOCAL_STATIC_LIBRARIES := \
+ libdumpstateutil
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/dumpstate/1.0/default/DumpstateDevice.cpp b/dumpstate/1.0/default/DumpstateDevice.cpp
new file mode 100644
index 0000000..a279b89
--- /dev/null
+++ b/dumpstate/1.0/default/DumpstateDevice.cpp
@@ -0,0 +1,51 @@
+#define LOG_TAG "dumpstate"
+
+#include "DumpstateDevice.h"
+
+#include <log/log.h>
+
+#include "DumpstateUtil.h"
+
+namespace android {
+namespace hardware {
+namespace dumpstate {
+namespace V1_0 {
+namespace implementation {
+
+// Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
+Return<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
+ if (handle->numFds < 1) {
+ ALOGE("no FDs\n");
+ return Void();
+ }
+
+ int fd = handle->data[0];
+ if (fd < 0) {
+ ALOGE("invalid FD: %d\n", handle->data[0]);
+ return Void();
+ }
+ ALOGD("DumpstateDevice::dumpstateBoard() FD: %d\n", fd);
+ ALOGI("Dumpstate HIDL not provided by device\n");
+ dprintf(fd, "Dumpstate HIDL not provided by device; providing bogus data.\n");
+
+ // Shows some examples on how to use the libdumpstateutils API.
+ dprintf(fd, "Time now is: ");
+ RunCommandToFd(fd, {"/system/bin/date"});
+ dprintf(fd, "Contents of a small file (/system/etc/hosts):\n");
+ DumpFileToFd(fd, "/system/etc/hosts");
+
+ return Void();
+}
+
+
+IDumpstateDevice* HIDL_FETCH_IDumpstateDevice(const char* /* name */) {
+ // TODO: temporary returning nullptr until it's implemented on master devices
+ return nullptr;
+// return new DumpstateDevice();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace dumpstate
+} // namespace hardware
+} // namespace android
diff --git a/dumpstate/1.0/default/DumpstateDevice.h b/dumpstate/1.0/default/DumpstateDevice.h
new file mode 100644
index 0000000..6f860c0
--- /dev/null
+++ b/dumpstate/1.0/default/DumpstateDevice.h
@@ -0,0 +1,37 @@
+#ifndef ANDROID_HARDWARE_DUMPSTATE_V1_0_DUMPSTATEDEVICE_H
+#define ANDROID_HARDWARE_DUMPSTATE_V1_0_DUMPSTATEDEVICE_H
+
+#include <android/hardware/dumpstate/1.0/IDumpstateDevice.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace dumpstate {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::dumpstate::V1_0::IDumpstateDevice;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_handle;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct DumpstateDevice : public IDumpstateDevice {
+ // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
+ Return<void> dumpstateBoard(const hidl_handle& h) override;
+
+};
+
+extern "C" IDumpstateDevice* HIDL_FETCH_IDumpstateDevice(const char* name);
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace dumpstate
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_DUMPSTATE_V1_0_DUMPSTATEDEVICE_H
diff --git a/dumpstate/Android.bp b/dumpstate/Android.bp
new file mode 100644
index 0000000..bbb3e4b
--- /dev/null
+++ b/dumpstate/Android.bp
@@ -0,0 +1,4 @@
+// This is an autogenerated file, do not edit.
+subdirs = [
+ "1.0",
+]
diff --git a/gatekeeper/1.0/Android.bp b/gatekeeper/1.0/Android.bp
new file mode 100644
index 0000000..c841510
--- /dev/null
+++ b/gatekeeper/1.0/Android.bp
@@ -0,0 +1,54 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+genrule {
+ name: "android.hardware.gatekeeper@1.0_genc++",
+ tools: ["hidl-gen"],
+ cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces android.hardware.gatekeeper@1.0",
+ srcs: [
+ "types.hal",
+ "IGatekeeper.hal",
+ ],
+ out: [
+ "android/hardware/gatekeeper/1.0/types.cpp",
+ "android/hardware/gatekeeper/1.0/GatekeeperAll.cpp",
+ ],
+}
+
+genrule {
+ name: "android.hardware.gatekeeper@1.0_genc++_headers",
+ tools: ["hidl-gen"],
+ cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces android.hardware.gatekeeper@1.0",
+ srcs: [
+ "types.hal",
+ "IGatekeeper.hal",
+ ],
+ out: [
+ "android/hardware/gatekeeper/1.0/types.h",
+ "android/hardware/gatekeeper/1.0/IGatekeeper.h",
+ "android/hardware/gatekeeper/1.0/IHwGatekeeper.h",
+ "android/hardware/gatekeeper/1.0/BnGatekeeper.h",
+ "android/hardware/gatekeeper/1.0/BpGatekeeper.h",
+ "android/hardware/gatekeeper/1.0/BsGatekeeper.h",
+ ],
+}
+
+cc_library_shared {
+ name: "android.hardware.gatekeeper@1.0",
+ generated_sources: ["android.hardware.gatekeeper@1.0_genc++"],
+ generated_headers: ["android.hardware.gatekeeper@1.0_genc++_headers"],
+ export_generated_headers: ["android.hardware.gatekeeper@1.0_genc++_headers"],
+ shared_libs: [
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "liblog",
+ "libutils",
+ "libcutils",
+ ],
+ export_shared_lib_headers: [
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "libutils",
+ ],
+}
diff --git a/gatekeeper/1.0/IGatekeeper.hal b/gatekeeper/1.0/IGatekeeper.hal
new file mode 100644
index 0000000..999a311
--- /dev/null
+++ b/gatekeeper/1.0/IGatekeeper.hal
@@ -0,0 +1,108 @@
+package android.hardware.gatekeeper@1.0;
+
+interface IGatekeeper {
+
+/**
+ * Enrolls desiredPassword, which may be derived from a user selected pin
+ * or password, with the private key used only for enrolling authentication
+ * factor data.
+ *
+ * If there was already a password enrolled, current password handle must be
+ * passed in currentPasswordHandle, and current password must be passed in
+ * currentPassword. Valid currentPassword must verify() against
+ * currentPasswordHandle.
+ *
+ * @param uid The Android user identifier
+ *
+ * @param currentPasswordHandle The currently enrolled password handle the user
+ * wants to replace. May be empty only if there's no currently enrolled
+ * password. Otherwise must be non-empty.
+ *
+ * @param currentPassword The user's current password in plain text.
+ * it MUST verify against current_password_handle if the latter is not-empty
+ *
+ * @param desiredPassword The new password the user wishes to enroll in
+ * plaintext.
+ *
+ * @return response
+ * On success, data buffer must contain the new password handle referencing
+ * the password provided in desiredPassword.
+ * This buffer can be used on subsequent calls to enroll or
+ * verify. On error, this buffer must be empty.
+ * response.code must always contain operation completion status.
+ * This method may return ERROR_GENERAL_FAILURE or ERROR_RETRY_TIMEOUT on
+ * failure. It must return STATUS_OK on success.
+ * If ERROR_RETRY_TIMEOUT is returned, response.timeout must be non-zero.
+ */
+enroll(uint32_t uid,
+ vec<uint8_t> currentPasswordHandle,
+ vec<uint8_t> currentPassword,
+ vec<uint8_t> desiredPassword)
+ generates (GatekeeperResponse response);
+
+/**
+ * Verifies that providedPassword matches enrolledPasswordHandle.
+ *
+ * Implementations of this module may retain the result of this call
+ * to attest to the recency of authentication.
+ *
+ * On success, returns verification token in response.data, which shall be
+ * usable to attest password verification to other trusted services.
+ *
+ * @param uid The Android user identifier
+ *
+ * @param challenge An optional challenge to authenticate against, or 0.
+ * Used when a separate authenticator requests password verification,
+ * or for transactional password authentication.
+ *
+ * @param enrolledPasswordHandle The currently enrolled password handle that
+ * user wishes to verify against. Must be non-empty.
+ *
+ * @param providedPassword The plaintext password to be verified against the
+ * enrolledPasswordHandle
+ *
+ * @return response
+ * On success, a non-empty data buffer containing the
+ * authentication token resulting from this verification is returned.
+ * On error, data buffer must be empty.
+ * response.code must always contain operation completion status.
+ * This method may return ERROR_GENERAL_FAILURE or ERROR_RETRY_TIMEOUT on
+ * failure. It must return STATUS_OK on success.
+ * If password re-enrollment is necessary, it must return STATUS_REENROLL.
+ * If ERROR_RETRY_TIMEOUT is returned, response.timeout must be non-zero.
+ */
+verify(uint32_t uid, uint64_t challenge,
+ vec<uint8_t> enrolledPasswordHandle,
+ vec<uint8_t> providedPassword)
+ generates (GatekeeperResponse response);
+
+/*
+ * Deletes the enrolledPasswordHandle associated with the uid. Once deleted
+ * the user cannot be verified anymore.
+ * This is an optional method.
+ *
+ * @param uid The Android user identifier
+ *
+ * @return response
+ * response.code must always contain operation completion status.
+ * This method may return ERROR_GENERAL_FAILURE or ERROR_RETRY_TIMEOUT on
+ * failure. It must return STATUS_OK on success.
+ * If not implemented, it must return ERROR_NOT_IMPLEMENTED.
+ * If ERROR_RETRY_TIMEOUT is returned, response.timeout must be non-zero.
+ */
+deleteUser(uint32_t uid) generates (GatekeeperResponse response);
+
+/*
+ * Deletes all the enrolled_password_handles for all uid's. Once called,
+ * no users must be enrolled on the device.
+ * This is an optional method.
+ *
+ * @return response
+ * response.code must always contain operation completion status.
+ * This method may return ERROR_GENERAL_FAILURE or ERROR_RETRY_TIMEOUT on
+ * failure. It must return STATUS_OK on success.
+ * If not implemented, it must return ERROR_NOT_IMPLEMENTED.
+ * If ERROR_RETRY_TIMEOUT is returned, response.timeout must be non-zero.
+ */
+deleteAllUsers() generates (GatekeeperResponse response);
+};
diff --git a/gatekeeper/1.0/default/Android.mk b/gatekeeper/1.0/default/Android.mk
new file mode 100644
index 0000000..e3b7d10
--- /dev/null
+++ b/gatekeeper/1.0/default/Android.mk
@@ -0,0 +1,40 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE := android.hardware.gatekeeper@1.0-impl
+
+LOCAL_SRC_FILES := \
+ Gatekeeper.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+ android.hardware.gatekeeper@1.0 \
+ libhardware \
+ libhidlbase \
+ libhidltransport \
+ libhwbinder \
+ libutils \
+ liblog \
+
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE := android.hardware.gatekeeper@1.0-service
+LOCAL_INIT_RC := android.hardware.gatekeeper@1.0-service.rc
+
+LOCAL_SRC_FILES := \
+ service.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+ android.hardware.gatekeeper@1.0 \
+ libhardware \
+ libhidlbase \
+ libhidltransport \
+ libhwbinder \
+ libutils \
+ liblog \
+
+include $(BUILD_EXECUTABLE)
diff --git a/gatekeeper/1.0/default/Gatekeeper.cpp b/gatekeeper/1.0/default/Gatekeeper.cpp
new file mode 100644
index 0000000..8fcd8ca
--- /dev/null
+++ b/gatekeeper/1.0/default/Gatekeeper.cpp
@@ -0,0 +1,149 @@
+#define LOG_TAG "android.hardware.gatekeeper@1.0-service"
+
+#include <utils/Log.h>
+#include <dlfcn.h>
+
+#include "Gatekeeper.h"
+
+namespace android {
+namespace hardware {
+namespace gatekeeper {
+namespace V1_0 {
+namespace implementation {
+
+Gatekeeper::Gatekeeper()
+{
+ int ret = hw_get_module_by_class(GATEKEEPER_HARDWARE_MODULE_ID, NULL, &module);
+ device = NULL;
+
+ if (!ret) {
+ ret = gatekeeper_open(module, &device);
+ }
+ if (ret < 0) {
+ LOG_ALWAYS_FATAL_IF(ret < 0, "Unable to open GateKeeper HAL");
+ }
+}
+
+Gatekeeper::~Gatekeeper()
+{
+ if (device != nullptr) {
+ int ret = gatekeeper_close(device);
+ if (ret < 0) {
+ ALOGE("Unable to close GateKeeper HAL");
+ }
+ }
+ dlclose(module->dso);
+}
+
+// Methods from ::android::hardware::gatekeeper::V1_0::IGatekeeper follow.
+Return<void> Gatekeeper::enroll(uint32_t uid,
+ const hidl_vec<uint8_t>& currentPasswordHandle,
+ const hidl_vec<uint8_t>& currentPassword,
+ const hidl_vec<uint8_t>& desiredPassword,
+ enroll_cb cb)
+{
+ GatekeeperResponse rsp;
+ uint8_t *enrolled_password_handle = nullptr;
+ uint32_t enrolled_password_handle_length = 0;
+
+ int ret = device->enroll(device, uid,
+ currentPasswordHandle.data(), currentPasswordHandle.size(),
+ currentPassword.data(), currentPassword.size(),
+ desiredPassword.data(), desiredPassword.size(),
+ &enrolled_password_handle, &enrolled_password_handle_length);
+ if (!ret) {
+ rsp.data.setToExternal(enrolled_password_handle,
+ enrolled_password_handle_length,
+ true);
+ rsp.code = GatekeeperStatusCode::STATUS_OK;
+ } else if (ret > 0) {
+ rsp.timeout = ret;
+ rsp.code = GatekeeperStatusCode::ERROR_RETRY_TIMEOUT;
+ } else {
+ rsp.code = GatekeeperStatusCode::ERROR_GENERAL_FAILURE;
+ }
+ cb(rsp);
+ return Void();
+}
+
+Return<void> Gatekeeper::verify(uint32_t uid,
+ uint64_t challenge,
+ const hidl_vec<uint8_t>& enrolledPasswordHandle,
+ const hidl_vec<uint8_t>& providedPassword,
+ verify_cb cb)
+{
+ GatekeeperResponse rsp;
+ uint8_t *auth_token = nullptr;
+ uint32_t auth_token_length = 0;
+ bool request_reenroll = false;
+
+ int ret = device->verify(device, uid, challenge,
+ enrolledPasswordHandle.data(), enrolledPasswordHandle.size(),
+ providedPassword.data(), providedPassword.size(),
+ &auth_token, &auth_token_length,
+ &request_reenroll);
+ if (!ret) {
+ rsp.data.setToExternal(auth_token, auth_token_length, true);
+ if (request_reenroll) {
+ rsp.code = GatekeeperStatusCode::STATUS_REENROLL;
+ } else {
+ rsp.code = GatekeeperStatusCode::STATUS_OK;
+ }
+ } else if (ret > 0) {
+ rsp.timeout = ret;
+ rsp.code = GatekeeperStatusCode::ERROR_RETRY_TIMEOUT;
+ } else {
+ rsp.code = GatekeeperStatusCode::ERROR_GENERAL_FAILURE;
+ }
+ cb(rsp);
+ return Void();
+}
+
+Return<void> Gatekeeper::deleteUser(uint32_t uid, deleteUser_cb cb) {
+ GatekeeperResponse rsp;
+
+ if (device->delete_user != nullptr) {
+ int ret = device->delete_user(device, uid);
+ if (!ret) {
+ rsp.code = GatekeeperStatusCode::STATUS_OK;
+ } else if (ret > 0) {
+ rsp.timeout = ret;
+ rsp.code = GatekeeperStatusCode::ERROR_RETRY_TIMEOUT;
+ } else {
+ rsp.code = GatekeeperStatusCode::ERROR_GENERAL_FAILURE;
+ }
+ } else {
+ rsp.code = GatekeeperStatusCode::ERROR_NOT_IMPLEMENTED;
+ }
+ cb(rsp);
+ return Void();
+}
+
+Return<void> Gatekeeper::deleteAllUsers(deleteAllUsers_cb cb) {
+ GatekeeperResponse rsp;
+ if (device->delete_all_users != nullptr) {
+ int ret = device->delete_all_users(device);
+ if (!ret) {
+ rsp.code = GatekeeperStatusCode::STATUS_OK;
+ } else if (ret > 0) {
+ rsp.timeout = ret;
+ rsp.code = GatekeeperStatusCode::ERROR_RETRY_TIMEOUT;
+ } else {
+ rsp.code = GatekeeperStatusCode::ERROR_GENERAL_FAILURE;
+ }
+ } else {
+ rsp.code = GatekeeperStatusCode::ERROR_NOT_IMPLEMENTED;
+ }
+ cb(rsp);
+ return Void();
+}
+
+IGatekeeper* HIDL_FETCH_IGatekeeper(const char* /* name */) {
+ return new Gatekeeper();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace gatekeeper
+} // namespace hardware
+} // namespace android
diff --git a/gatekeeper/1.0/default/Gatekeeper.h b/gatekeeper/1.0/default/Gatekeeper.h
new file mode 100644
index 0000000..a2188d4
--- /dev/null
+++ b/gatekeeper/1.0/default/Gatekeeper.h
@@ -0,0 +1,57 @@
+#ifndef HIDL_GENERATED_android_hardware_gatekeeper_V1_0_Gatekeeper_H_
+#define HIDL_GENERATED_android_hardware_gatekeeper_V1_0_Gatekeeper_H_
+
+#include <android/hardware/gatekeeper/1.0/IGatekeeper.h>
+#include <hidl/Status.h>
+
+#include <hidl/MQDescriptor.h>
+
+#include <hardware/hardware.h>
+#include <hardware/gatekeeper.h>
+
+namespace android {
+namespace hardware {
+namespace gatekeeper {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gatekeeper::V1_0::GatekeeperResponse;
+using ::android::hardware::gatekeeper::V1_0::IGatekeeper;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+class Gatekeeper : public IGatekeeper {
+public:
+ Gatekeeper();
+ ~Gatekeeper();
+
+ // Methods from ::android::hardware::gatekeeper::V1_0::IGatekeeper follow.
+ Return<void> enroll(uint32_t uid,
+ const hidl_vec<uint8_t>& currentPasswordHandle,
+ const hidl_vec<uint8_t>& currentPassword,
+ const hidl_vec<uint8_t>& desiredPassword,
+ enroll_cb _hidl_cb) override;
+ Return<void> verify(uint32_t uid,
+ uint64_t challenge,
+ const hidl_vec<uint8_t>& enrolledPasswordHandle,
+ const hidl_vec<uint8_t>& providedPassword,
+ verify_cb _hidl_cb) override;
+ Return<void> deleteUser(uint32_t uid, deleteUser_cb _hidl_cb) override;
+ Return<void> deleteAllUsers(deleteAllUsers_cb _hidl_cb) override;
+private:
+ gatekeeper_device_t *device;
+ const hw_module_t *module;
+};
+
+extern "C" IGatekeeper* HIDL_FETCH_IGatekeeper(const char* name);
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace gatekeeper
+} // namespace hardware
+} // namespace android
+
+#endif // HIDL_GENERATED_android_hardware_gatekeeper_V1_0_Gatekeeper_H_
diff --git a/gatekeeper/1.0/default/android.hardware.gatekeeper@1.0-service.rc b/gatekeeper/1.0/default/android.hardware.gatekeeper@1.0-service.rc
new file mode 100644
index 0000000..ac15e23
--- /dev/null
+++ b/gatekeeper/1.0/default/android.hardware.gatekeeper@1.0-service.rc
@@ -0,0 +1,4 @@
+service gatekeeper-1-0 /system/bin/hw/android.hardware.gatekeeper@1.0-service
+ class hal
+ user system
+ group system
diff --git a/gatekeeper/1.0/default/service.cpp b/gatekeeper/1.0/default/service.cpp
new file mode 100644
index 0000000..c3fc25c
--- /dev/null
+++ b/gatekeeper/1.0/default/service.cpp
@@ -0,0 +1,13 @@
+#define LOG_TAG "android.hardware.gatekeeper@1.0-service"
+
+#include <android/hardware/gatekeeper/1.0/IGatekeeper.h>
+
+#include <hidl/LegacySupport.h>
+
+// Generated HIDL files
+using android::hardware::gatekeeper::V1_0::IGatekeeper;
+using android::hardware::defaultPassthroughServiceImplementation;
+
+int main() {
+ return defaultPassthroughServiceImplementation<IGatekeeper>("gatekeeper");
+}
diff --git a/gatekeeper/1.0/types.hal b/gatekeeper/1.0/types.hal
new file mode 100644
index 0000000..9ab1152
--- /dev/null
+++ b/gatekeeper/1.0/types.hal
@@ -0,0 +1,27 @@
+package android.hardware.gatekeeper@1.0;
+
+/**
+ * Gatekeeper response codes; success >= 0; error < 0
+ */
+enum GatekeeperStatusCode : int32_t {
+ STATUS_REENROLL = 1, // success, but upper layers should re-enroll
+ // the verified password due to a version change
+ STATUS_OK = 0, // operation is successful
+ ERROR_GENERAL_FAILURE = -1, // operation failed
+ ERROR_RETRY_TIMEOUT = -2, // operation should be retried after timeout
+ ERROR_NOT_IMPLEMENTED = -3, // operation is not implemented
+};
+
+/**
+ * Gatekeeper response to any/all requests has this structure as mandatory part
+ */
+struct GatekeeperResponse {
+ /* request completion status */
+ GatekeeperStatusCode code;
+ /* retry timeout in ms, if code == ERROR_RETRY_TIMEOUT
+ * otherwise unused (0)
+ */
+ uint32_t timeout;
+ /* optional crypto blob */
+ vec<uint8_t> data;
+};
diff --git a/gatekeeper/Android.bp b/gatekeeper/Android.bp
new file mode 100644
index 0000000..bbb3e4b
--- /dev/null
+++ b/gatekeeper/Android.bp
@@ -0,0 +1,4 @@
+// This is an autogenerated file, do not edit.
+subdirs = [
+ "1.0",
+]
diff --git a/graphics/allocator/2.0/Android.bp b/graphics/allocator/2.0/Android.bp
index e26e9a3..f823570 100644
--- a/graphics/allocator/2.0/Android.bp
+++ b/graphics/allocator/2.0/Android.bp
@@ -7,10 +7,12 @@
srcs: [
"types.hal",
"IAllocator.hal",
+ "IAllocatorClient.hal",
],
out: [
"android/hardware/graphics/allocator/2.0/types.cpp",
"android/hardware/graphics/allocator/2.0/AllocatorAll.cpp",
+ "android/hardware/graphics/allocator/2.0/AllocatorClientAll.cpp",
],
}
@@ -21,6 +23,7 @@
srcs: [
"types.hal",
"IAllocator.hal",
+ "IAllocatorClient.hal",
],
out: [
"android/hardware/graphics/allocator/2.0/types.h",
@@ -29,6 +32,11 @@
"android/hardware/graphics/allocator/2.0/BnAllocator.h",
"android/hardware/graphics/allocator/2.0/BpAllocator.h",
"android/hardware/graphics/allocator/2.0/BsAllocator.h",
+ "android/hardware/graphics/allocator/2.0/IAllocatorClient.h",
+ "android/hardware/graphics/allocator/2.0/IHwAllocatorClient.h",
+ "android/hardware/graphics/allocator/2.0/BnAllocatorClient.h",
+ "android/hardware/graphics/allocator/2.0/BpAllocatorClient.h",
+ "android/hardware/graphics/allocator/2.0/BsAllocatorClient.h",
],
}
diff --git a/graphics/allocator/2.0/IAllocator.hal b/graphics/allocator/2.0/IAllocator.hal
index 9a45444..00d07d5 100644
--- a/graphics/allocator/2.0/IAllocator.hal
+++ b/graphics/allocator/2.0/IAllocator.hal
@@ -16,7 +16,7 @@
package android.hardware.graphics.allocator@2.0;
-import android.hardware.graphics.common@1.0::PixelFormat;
+import IAllocatorClient;
interface IAllocator {
enum Capability : int32_t {
@@ -24,53 +24,18 @@
INVALID = 0,
/*
- * testAllocate will always return UNDEFINED unless this capability
- * is supported.
+ * IAllocatorClient::testAllocate must always return UNDEFINED unless
+ * this capability is supported.
*/
TEST_ALLOCATE = 1,
/*
- * layerCount must be 1 unless this capability is supported.
+ * IAllocatorClient::BufferDescriptorInfo::layerCount must be 1 unless
+ * this capability is supported.
*/
LAYERED_BUFFERS = 2,
};
- struct BufferDescriptorInfo {
- /*
- * The width specifies how many columns of pixels must be in the
- * allocated buffer, but does not necessarily represent the offset in
- * columns between the same column in adjacent rows. The rows may be
- * padded.
- */
- uint32_t width;
-
- /*
- * The height specifies how many rows of pixels must be in the
- * allocated buffer.
- */
- uint32_t height;
-
- /*
- * The number of image layers that must be in the allocated buffer.
- */
- uint32_t layerCount;
-
- /* Buffer pixel format. */
- PixelFormat format;
-
- /*
- * Buffer producer usage mask; valid flags can be found in the
- * definition of ProducerUsage.
- */
- uint64_t producerUsageMask;
-
- /*
- * Buffer consumer usage mask; valid flags can be found in the
- * definition of ConsumerUsage.
- */
- uint64_t consumerUsageMask;
- };
-
/*
* Provides a list of supported capabilities (as described in the
* definition of Capability above). This list must not change after
@@ -95,110 +60,15 @@
dumpDebugInfo() generates (string debugInfo);
/*
- * Creates a new, opaque buffer descriptor.
+ * Creates a client of the allocator. All resources created by the client
+ * are owned by the client and are only visible to the client, unless they
+ * are exported by exportHandle.
*
- * @param descriptorInfo specifies the attributes of the buffer
- * descriptor.
* @return error is NONE upon success. Otherwise,
- * BAD_VALUE when any attribute in descriptorInfo is invalid.
- * NO_RESOURCES when no more descriptors can currently be created.
- * @return descriptor is the newly created buffer descriptor.
+ * NO_RESOURCES when no more client can currently be created.
+ * @return client is the newly created client.
*/
@entry
@callflow(next="*")
- createDescriptor(BufferDescriptorInfo descriptorInfo)
- generates (Error error,
- BufferDescriptor descriptor);
-
- /*
- * Destroys an existing buffer descriptor.
- *
- * @param descriptor is the descriptor to destroy.
- * @return error is either NONE or BAD_DESCRIPTOR.
- */
- @exit
- @callflow(next="*")
- destroyDescriptor(BufferDescriptor descriptor) generates (Error error);
-
- /*
- * Tests whether a buffer allocation can succeed, ignoring potential
- * resource contention which might lead to a NO_RESOURCES error.
- *
- * @param descriptors is a list of buffer descriptors.
- * @return error is NONE or NOT_SHARED upon success;
- * NONE when buffers can be created and share a backing store.
- * NOT_SHARED when buffers can be created but require more than a
- * backing store.
- * Otherwise,
- * BAD_DESCRIPTOR when any of the descriptors is invalid.
- * UNSUPPORTED when any of the descriptors can never be satisfied.
- * UNDEFINED when TEST_ALLOCATE is not listed in getCapabilities.
- */
- @callflow(next="allocate")
- testAllocate(vec<BufferDescriptor> descriptors) generates (Error error);
-
- /*
- * Attempts to allocate a list of buffers sharing a backing store.
- *
- * Each buffer will correspond to one of the descriptors passed into the
- * function and will hold a reference to its backing store. If the device
- * is unable to share the backing store between the buffers, it must
- * attempt to allocate the buffers with different backing stores and
- * return NOT_SHARED if it is successful.
- *
- * @param descriptors is the buffer descriptors to attempt to allocate.
- * @return error is NONE or NOT_SHARED upon success;
- * NONE when buffers can be created and share a backing store.
- * NOT_SHARED when buffers can be created but require more than a
- * backing store.
- * Otherwise,
- * BAD_DESCRIPTOR when any of the descriptors is invalid.
- * UNSUPPORTED when any of the descriptors can never be satisfied.
- * NO_RESOURCES when any of the buffers cannot be created at this
- * time.
- * @return buffers is the allocated buffers.
- */
- @callflow(next="exportHandle")
- allocate(vec<BufferDescriptor> descriptors)
- generates (Error error,
- vec<Buffer> buffers);
-
- /*
- * Frees a buffer.
- *
- * @param buffer is the buffer to be freed.
- * @return error is NONE upon success. Otherwise,
- * BAD_BUFFER when the buffer is invalid.
- */
- @exit
- @callflow(next="*")
- free(Buffer buffer) generates (Error error);
-
- /*
- * Exports a buffer for use in other client libraries or for cross-process
- * sharing.
- *
- * The exported handle is a handle to the backing store of the buffer, not
- * to the buffer itself. It however may not hold any reference to the
- * backing store and may be considered invalid by client libraries. To use
- * it and, in most cases, to save it for later use, a client must make a
- * clone of the handle and have the cloned handle hold a reference to the
- * backing store. Such a cloned handle will stay valid even after the
- * original buffer is freed. Refer to native_handle_clone and IMapper for
- * how a handle is cloned and how a reference is added.
- *
- * @param descriptor is the descriptor used to allocate the buffer.
- * @param buffer is the buffer to be exported.
- * @return error is NONE upon success. Otherwise,
- * BAD_DESCRIPTOR when the descriptor is invalid.
- * BAD_BUFFER when the buffer is invalid.
- * BAD_VALUE when descriptor and buffer do not match.
- * NO_RESOURCES when the buffer cannot be exported at this time.
- * @return bufferHandle is the exported handle.
- */
- @callflow(next="free")
- exportHandle(BufferDescriptor descriptor,
- Buffer buffer)
- generates (Error error,
- handle bufferHandle);
+ createClient() generates (Error error, IAllocatorClient client);
};
diff --git a/graphics/allocator/2.0/IAllocatorClient.hal b/graphics/allocator/2.0/IAllocatorClient.hal
new file mode 100644
index 0000000..080e3ea
--- /dev/null
+++ b/graphics/allocator/2.0/IAllocatorClient.hal
@@ -0,0 +1,165 @@
+/*
+ * 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.
+ */
+
+package android.hardware.graphics.allocator@2.0;
+
+import android.hardware.graphics.common@1.0::PixelFormat;
+
+interface IAllocatorClient {
+ struct BufferDescriptorInfo {
+ /*
+ * The width specifies how many columns of pixels must be in the
+ * allocated buffer, but does not necessarily represent the offset in
+ * columns between the same column in adjacent rows. The rows may be
+ * padded.
+ */
+ uint32_t width;
+
+ /*
+ * The height specifies how many rows of pixels must be in the
+ * allocated buffer.
+ */
+ uint32_t height;
+
+ /*
+ * The number of image layers that must be in the allocated buffer.
+ */
+ uint32_t layerCount;
+
+ /* Buffer pixel format. */
+ PixelFormat format;
+
+ /*
+ * Buffer producer usage mask; valid flags can be found in the
+ * definition of ProducerUsage.
+ */
+ uint64_t producerUsageMask;
+
+ /*
+ * Buffer consumer usage mask; valid flags can be found in the
+ * definition of ConsumerUsage.
+ */
+ uint64_t consumerUsageMask;
+ };
+
+ /*
+ * Creates a new, opaque buffer descriptor.
+ *
+ * @param descriptorInfo specifies the attributes of the buffer
+ * descriptor.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_VALUE when any attribute in descriptorInfo is invalid.
+ * NO_RESOURCES when no more descriptors can currently be created.
+ * @return descriptor is the newly created buffer descriptor.
+ */
+ @entry
+ @callflow(next="*")
+ createDescriptor(BufferDescriptorInfo descriptorInfo)
+ generates (Error error,
+ BufferDescriptor descriptor);
+
+ /*
+ * Destroys an existing buffer descriptor.
+ *
+ * @param descriptor is the descriptor to destroy.
+ * @return error is either NONE or BAD_DESCRIPTOR.
+ */
+ @exit
+ @callflow(next="*")
+ destroyDescriptor(BufferDescriptor descriptor) generates (Error error);
+
+ /*
+ * Tests whether a buffer allocation can succeed, ignoring potential
+ * resource contention which might lead to a NO_RESOURCES error.
+ *
+ * @param descriptors is a list of buffer descriptors.
+ * @return error is NONE or NOT_SHARED upon success;
+ * NONE when buffers can be created and share a backing store.
+ * NOT_SHARED when buffers can be created but require more than a
+ * backing store.
+ * Otherwise,
+ * BAD_DESCRIPTOR when any of the descriptors is invalid.
+ * UNSUPPORTED when any of the descriptors can never be satisfied.
+ * UNDEFINED when TEST_ALLOCATE is not listed in getCapabilities.
+ */
+ @callflow(next="allocate")
+ testAllocate(vec<BufferDescriptor> descriptors) generates (Error error);
+
+ /*
+ * Attempts to allocate a list of buffers sharing a backing store.
+ *
+ * Each buffer must correspond to one of the descriptors passed into the
+ * function and must hold a reference to its backing store. If the device
+ * is unable to share the backing store between the buffers, it must
+ * attempt to allocate the buffers with different backing stores and
+ * return NOT_SHARED if it is successful.
+ *
+ * @param descriptors is the buffer descriptors to attempt to allocate.
+ * @return error is NONE or NOT_SHARED upon success;
+ * NONE when buffers can be created and share a backing store.
+ * NOT_SHARED when buffers can be created but require more than a
+ * backing store.
+ * Otherwise,
+ * BAD_DESCRIPTOR when any of the descriptors is invalid.
+ * UNSUPPORTED when any of the descriptors can never be satisfied.
+ * NO_RESOURCES when any of the buffers cannot be created at this
+ * time.
+ * @return buffers is the allocated buffers.
+ */
+ @callflow(next="exportHandle")
+ allocate(vec<BufferDescriptor> descriptors)
+ generates (Error error,
+ vec<Buffer> buffers);
+
+ /*
+ * Frees a buffer.
+ *
+ * @param buffer is the buffer to be freed.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_BUFFER when the buffer is invalid.
+ */
+ @exit
+ @callflow(next="*")
+ free(Buffer buffer) generates (Error error);
+
+ /*
+ * Exports a buffer for use in other client libraries or for cross-process
+ * sharing.
+ *
+ * The exported handle is a handle to the backing store of the buffer, not
+ * to the buffer itself. It however may not hold any reference to the
+ * backing store and may be considered invalid by client libraries. To use
+ * it and, in most cases, to save it for later use, a client must make a
+ * clone of the handle and have the cloned handle hold a reference to the
+ * backing store. Such a cloned handle will stay valid even after the
+ * original buffer is freed. Refer to native_handle_clone and IMapper for
+ * how a handle is cloned and how a reference is added.
+ *
+ * @param descriptor is the descriptor used to allocate the buffer.
+ * @param buffer is the buffer to be exported.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DESCRIPTOR when the descriptor is invalid.
+ * BAD_BUFFER when the buffer is invalid.
+ * BAD_VALUE when descriptor and buffer do not match.
+ * NO_RESOURCES when the buffer cannot be exported at this time.
+ * @return bufferHandle is the exported handle.
+ */
+ @callflow(next="free")
+ exportHandle(BufferDescriptor descriptor,
+ Buffer buffer)
+ generates (Error error,
+ handle bufferHandle);
+};
diff --git a/graphics/allocator/2.0/default/Gralloc.cpp b/graphics/allocator/2.0/default/Gralloc.cpp
index 8a74661..e3d2703 100644
--- a/graphics/allocator/2.0/default/Gralloc.cpp
+++ b/graphics/allocator/2.0/default/Gralloc.cpp
@@ -16,6 +16,7 @@
#define LOG_TAG "GrallocPassthrough"
+#include <mutex>
#include <type_traits>
#include <unordered_set>
#include <vector>
@@ -42,18 +43,19 @@
// IAllocator interface
Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
- Return<void> createDescriptor(const BufferDescriptorInfo& descriptorInfo,
- createDescriptor_cb hidl_cb) override;
- Return<Error> destroyDescriptor(BufferDescriptor descriptor) override;
+ Return<void> createClient(createClient_cb hidl_cb) override;
- Return<Error> testAllocate(
- const hidl_vec<BufferDescriptor>& descriptors) override;
- Return<void> allocate(const hidl_vec<BufferDescriptor>& descriptors,
- allocate_cb hidl_cb) override;
- Return<Error> free(Buffer buffer) override;
+ Error createDescriptor(
+ const IAllocatorClient::BufferDescriptorInfo& descriptorInfo,
+ BufferDescriptor& outDescriptor);
+ Error destroyDescriptor(BufferDescriptor descriptor);
- Return<void> exportHandle(BufferDescriptor descriptor,
- Buffer buffer, exportHandle_cb hidl_cb) override;
+ Error testAllocate(const hidl_vec<BufferDescriptor>& descriptors);
+ Error allocate(const hidl_vec<BufferDescriptor>& descriptors,
+ hidl_vec<Buffer>& outBuffers);
+ Error free(Buffer buffer);
+
+ Error exportHandle(Buffer buffer, const native_handle_t*& outHandle);
private:
void initCapabilities();
@@ -79,12 +81,36 @@
GRALLOC1_PFN_SET_PRODUCER_USAGE setProducerUsage;
GRALLOC1_PFN_ALLOCATE allocate;
GRALLOC1_PFN_RELEASE release;
- GRALLOC1_PFN_GET_BACKING_STORE getBackingStore;
- GRALLOC1_PFN_GET_STRIDE getStride;
- GRALLOC1_PFN_GET_NUM_FLEX_PLANES getNumFlexPlanes;
} mDispatch;
};
+class GrallocClient : public IAllocatorClient {
+public:
+ GrallocClient(GrallocHal& hal);
+ virtual ~GrallocClient();
+
+ // IAllocatorClient interface
+ Return<void> createDescriptor(const BufferDescriptorInfo& descriptorInfo,
+ createDescriptor_cb hidl_cb) override;
+ Return<Error> destroyDescriptor(BufferDescriptor descriptor) override;
+
+ Return<Error> testAllocate(
+ const hidl_vec<BufferDescriptor>& descriptors) override;
+ Return<void> allocate(const hidl_vec<BufferDescriptor>& descriptors,
+ allocate_cb hidl_cb) override;
+ Return<Error> free(Buffer buffer) override;
+
+ Return<void> exportHandle(BufferDescriptor descriptor,
+ Buffer buffer, exportHandle_cb hidl_cb) override;
+
+private:
+ GrallocHal& mHal;
+
+ std::mutex mMutex;
+ std::unordered_set<BufferDescriptor> mDescriptors;
+ std::unordered_set<Buffer> mBuffers;
+};
+
GrallocHal::GrallocHal(const hw_module_t* module)
: mDevice(nullptr), mDispatch()
{
@@ -182,24 +208,37 @@
return Void();
}
-Return<void> GrallocHal::createDescriptor(
- const BufferDescriptorInfo& descriptorInfo,
- createDescriptor_cb hidl_cb)
+Return<void> GrallocHal::createClient(createClient_cb hidl_cb)
{
- BufferDescriptor descriptor;
+ sp<IAllocatorClient> client = new GrallocClient(*this);
+ hidl_cb(Error::NONE, client);
+
+ return Void();
+}
+
+Error GrallocHal::createDescriptor(
+ const IAllocatorClient::BufferDescriptorInfo& descriptorInfo,
+ BufferDescriptor& outDescriptor)
+{
+ gralloc1_buffer_descriptor_t descriptor;
int32_t err = mDispatch.createDescriptor(mDevice, &descriptor);
- if (err == GRALLOC1_ERROR_NONE) {
- err = mDispatch.setDimensions(mDevice, descriptor,
- descriptorInfo.width, descriptorInfo.height);
+ if (err != GRALLOC1_ERROR_NONE) {
+ return static_cast<Error>(err);
}
+
+ err = mDispatch.setDimensions(mDevice, descriptor,
+ descriptorInfo.width, descriptorInfo.height);
if (err == GRALLOC1_ERROR_NONE) {
err = mDispatch.setFormat(mDevice, descriptor,
static_cast<int32_t>(descriptorInfo.format));
}
- if (err == GRALLOC1_ERROR_NONE &&
- hasCapability(Capability::LAYERED_BUFFERS)) {
- err = mDispatch.setLayerCount(mDevice, descriptor,
- descriptorInfo.layerCount);
+ if (err == GRALLOC1_ERROR_NONE) {
+ if (hasCapability(Capability::LAYERED_BUFFERS)) {
+ err = mDispatch.setLayerCount(mDevice, descriptor,
+ descriptorInfo.layerCount);
+ } else if (descriptorInfo.layerCount != 1) {
+ err = GRALLOC1_ERROR_BAD_VALUE;
+ }
}
if (err == GRALLOC1_ERROR_NONE) {
uint64_t producerUsageMask = descriptorInfo.producerUsageMask;
@@ -221,64 +260,189 @@
consumerUsageMask);
}
- hidl_cb(static_cast<Error>(err), descriptor);
+ if (err == GRALLOC1_ERROR_NONE) {
+ outDescriptor = descriptor;
+ } else {
+ mDispatch.destroyDescriptor(mDevice, descriptor);
+ }
- return Void();
+ return static_cast<Error>(err);
}
-Return<Error> GrallocHal::destroyDescriptor(
- BufferDescriptor descriptor)
+Error GrallocHal::destroyDescriptor(BufferDescriptor descriptor)
{
int32_t err = mDispatch.destroyDescriptor(mDevice, descriptor);
return static_cast<Error>(err);
}
-Return<Error> GrallocHal::testAllocate(
- const hidl_vec<BufferDescriptor>& descriptors)
+Error GrallocHal::testAllocate(const hidl_vec<BufferDescriptor>& descriptors)
{
if (!hasCapability(Capability::TEST_ALLOCATE)) {
return Error::UNDEFINED;
}
int32_t err = mDispatch.allocate(mDevice, descriptors.size(),
- &descriptors[0], nullptr);
+ descriptors.data(), nullptr);
return static_cast<Error>(err);
}
-Return<void> GrallocHal::allocate(
- const hidl_vec<BufferDescriptor>& descriptors,
- allocate_cb hidl_cb) {
+Error GrallocHal::allocate(const hidl_vec<BufferDescriptor>& descriptors,
+ hidl_vec<Buffer>& outBuffers)
+{
std::vector<buffer_handle_t> buffers(descriptors.size());
int32_t err = mDispatch.allocate(mDevice, descriptors.size(),
- &descriptors[0], buffers.data());
- if (err != GRALLOC1_ERROR_NONE && err != GRALLOC1_ERROR_NOT_SHARED) {
- buffers.clear();
+ descriptors.data(), buffers.data());
+ if (err == GRALLOC1_ERROR_NONE || err == GRALLOC1_ERROR_NOT_SHARED) {
+ outBuffers.resize(buffers.size());
+ for (size_t i = 0; i < outBuffers.size(); i++) {
+ outBuffers[i] = static_cast<Buffer>(
+ reinterpret_cast<uintptr_t>(buffers[i]));
+ }
}
- hidl_vec<Buffer> reply;
- reply.setToExternal(
- reinterpret_cast<Buffer*>(buffers.data()),
- buffers.size());
- hidl_cb(static_cast<Error>(err), reply);
-
- return Void();
+ return static_cast<Error>(err);
}
-Return<Error> GrallocHal::free(Buffer buffer)
+Error GrallocHal::free(Buffer buffer)
{
- buffer_handle_t handle = reinterpret_cast<buffer_handle_t>(buffer);
+ buffer_handle_t handle = reinterpret_cast<buffer_handle_t>(
+ static_cast<uintptr_t>(buffer));
+
int32_t err = mDispatch.release(mDevice, handle);
return static_cast<Error>(err);
}
-Return<void> GrallocHal::exportHandle(BufferDescriptor /*descriptor*/,
+Error GrallocHal::exportHandle(Buffer buffer,
+ const native_handle_t*& outHandle)
+{
+ // we rely on the caller to validate buffer here
+ outHandle = reinterpret_cast<buffer_handle_t>(
+ static_cast<uintptr_t>(buffer));
+ return Error::NONE;
+}
+
+GrallocClient::GrallocClient(GrallocHal& hal)
+ : mHal(hal)
+{
+}
+
+GrallocClient::~GrallocClient()
+{
+ if (!mBuffers.empty()) {
+ ALOGW("client destroyed with valid buffers");
+ for (auto buf : mBuffers) {
+ mHal.free(buf);
+ }
+ }
+
+ if (!mDescriptors.empty()) {
+ ALOGW("client destroyed with valid buffer descriptors");
+ for (auto desc : mDescriptors) {
+ mHal.destroyDescriptor(desc);
+ }
+ }
+}
+
+Return<void> GrallocClient::createDescriptor(
+ const BufferDescriptorInfo& descriptorInfo,
+ createDescriptor_cb hidl_cb)
+{
+ BufferDescriptor descriptor;
+ Error err = mHal.createDescriptor(descriptorInfo, descriptor);
+
+ if (err == Error::NONE) {
+ std::lock_guard<std::mutex> lock(mMutex);
+
+ auto result = mDescriptors.insert(descriptor);
+ if (!result.second) {
+ ALOGW("duplicated buffer descriptor id returned");
+ mHal.destroyDescriptor(descriptor);
+ err = Error::NO_RESOURCES;
+ }
+ }
+
+ hidl_cb(err, descriptor);
+ return Void();
+}
+
+Return<Error> GrallocClient::destroyDescriptor(BufferDescriptor descriptor)
+{
+ {
+ std::lock_guard<std::mutex> lock(mMutex);
+ if (!mDescriptors.erase(descriptor)) {
+ return Error::BAD_DESCRIPTOR;
+ }
+ }
+
+ return mHal.destroyDescriptor(descriptor);
+}
+
+Return<Error> GrallocClient::testAllocate(
+ const hidl_vec<BufferDescriptor>& descriptors)
+{
+ return mHal.testAllocate(descriptors);
+}
+
+Return<void> GrallocClient::allocate(
+ const hidl_vec<BufferDescriptor>& descriptors,
+ allocate_cb hidl_cb) {
+ hidl_vec<Buffer> buffers;
+ Error err = mHal.allocate(descriptors, buffers);
+
+ if (err == Error::NONE || err == Error::NOT_SHARED) {
+ std::lock_guard<std::mutex> lock(mMutex);
+
+ for (size_t i = 0; i < buffers.size(); i++) {
+ auto result = mBuffers.insert(buffers[i]);
+ if (!result.second) {
+ ALOGW("duplicated buffer id returned");
+
+ for (size_t j = 0; j < buffers.size(); j++) {
+ if (j < i) {
+ mBuffers.erase(buffers[i]);
+ }
+ mHal.free(buffers[i]);
+ }
+
+ buffers = hidl_vec<Buffer>();
+ err = Error::NO_RESOURCES;
+ break;
+ }
+ }
+ }
+
+ hidl_cb(err, buffers);
+ return Void();
+}
+
+Return<Error> GrallocClient::free(Buffer buffer)
+{
+ {
+ std::lock_guard<std::mutex> lock(mMutex);
+ if (!mBuffers.erase(buffer)) {
+ return Error::BAD_BUFFER;
+ }
+ }
+
+ return mHal.free(buffer);
+}
+
+Return<void> GrallocClient::exportHandle(BufferDescriptor /*descriptor*/,
Buffer buffer, exportHandle_cb hidl_cb)
{
- // do we want to validate?
- buffer_handle_t handle = reinterpret_cast<buffer_handle_t>(buffer);
+ const native_handle_t* handle = nullptr;
- hidl_cb(Error::NONE, handle);
+ {
+ std::lock_guard<std::mutex> lock(mMutex);
+ if (mBuffers.count(buffer) == 0) {
+ hidl_cb(Error::BAD_BUFFER, handle);
+ return Void();
+ }
+ }
+ Error err = mHal.exportHandle(buffer, handle);
+
+ hidl_cb(err, handle);
return Void();
}
diff --git a/graphics/allocator/2.0/vts/functional/graphics_allocator_hidl_hal_test.cpp b/graphics/allocator/2.0/vts/functional/graphics_allocator_hidl_hal_test.cpp
index 54369a4..bd846c4 100644
--- a/graphics/allocator/2.0/vts/functional/graphics_allocator_hidl_hal_test.cpp
+++ b/graphics/allocator/2.0/vts/functional/graphics_allocator_hidl_hal_test.cpp
@@ -43,10 +43,10 @@
class TempDescriptor {
public:
- TempDescriptor(const sp<IAllocator>& allocator,
- const IAllocator::BufferDescriptorInfo& info)
- : mAllocator(allocator), mError(Error::NO_RESOURCES) {
- mAllocator->createDescriptor(
+ TempDescriptor(const sp<IAllocatorClient>& client,
+ const IAllocatorClient::BufferDescriptorInfo& info)
+ : mClient(client), mError(Error::NO_RESOURCES) {
+ mClient->createDescriptor(
info, [&](const auto& tmpError, const auto& tmpDescriptor) {
mError = tmpError;
mDescriptor = tmpDescriptor;
@@ -55,7 +55,7 @@
~TempDescriptor() {
if (mError == Error::NONE) {
- mAllocator->destroyDescriptor(mDescriptor);
+ mClient->destroyDescriptor(mDescriptor);
}
}
@@ -64,7 +64,7 @@
operator BufferDescriptor() const { return mDescriptor; }
private:
- sp<IAllocator> mAllocator;
+ sp<IAllocatorClient> mClient;
Error mError;
BufferDescriptor mDescriptor;
};
@@ -75,10 +75,18 @@
mAllocator = IAllocator::getService("gralloc");
ASSERT_NE(mAllocator, nullptr);
+ mAllocator->createClient([this](const auto& error, const auto& client) {
+ if (error == Error::NONE) {
+ mClient = client;
+ }
+ });
+ ASSERT_NE(mClient, nullptr);
+
initCapabilities();
mDummyDescriptorInfo.width = 64;
mDummyDescriptorInfo.height = 64;
+ mDummyDescriptorInfo.layerCount = 1;
mDummyDescriptorInfo.format = PixelFormat::RGBA_8888;
mDummyDescriptorInfo.producerUsageMask =
static_cast<uint64_t>(ProducerUsage::CPU_WRITE);
@@ -106,7 +114,8 @@
}
sp<IAllocator> mAllocator;
- IAllocator::BufferDescriptorInfo mDummyDescriptorInfo{};
+ sp<IAllocatorClient> mClient;
+ IAllocatorClient::BufferDescriptorInfo mDummyDescriptorInfo{};
private:
std::unordered_set<IAllocator::Capability> mCapabilities;
@@ -134,7 +143,7 @@
TEST_F(GraphicsAllocatorHidlTest, CreateDestroyDescriptor) {
Error error;
BufferDescriptor descriptor;
- auto ret = mAllocator->createDescriptor(
+ auto ret = mClient->createDescriptor(
mDummyDescriptorInfo,
[&](const auto& tmpError, const auto& tmpDescriptor) {
error = tmpError;
@@ -144,7 +153,7 @@
ASSERT_TRUE(ret.getStatus().isOk());
ASSERT_EQ(Error::NONE, error);
- auto err_ret = mAllocator->destroyDescriptor(descriptor);
+ auto err_ret = mClient->destroyDescriptor(descriptor);
ASSERT_TRUE(err_ret.getStatus().isOk());
ASSERT_EQ(Error::NONE, static_cast<Error>(err_ret));
}
@@ -155,14 +164,14 @@
TEST_F(GraphicsAllocatorHidlTest, TestAllocateBasic) {
CHECK_FEATURE_OR_SKIP(IAllocator::Capability::TEST_ALLOCATE);
- TempDescriptor descriptor(mAllocator, mDummyDescriptorInfo);
+ TempDescriptor descriptor(mClient, mDummyDescriptorInfo);
ASSERT_TRUE(descriptor.isValid());
hidl_vec<BufferDescriptor> descriptors;
descriptors.resize(1);
descriptors[0] = descriptor;
- auto ret = mAllocator->testAllocate(descriptors);
+ auto ret = mClient->testAllocate(descriptors);
ASSERT_TRUE(ret.getStatus().isOk());
auto error = static_cast<Error>(ret);
@@ -175,7 +184,7 @@
TEST_F(GraphicsAllocatorHidlTest, TestAllocateArray) {
CHECK_FEATURE_OR_SKIP(IAllocator::Capability::TEST_ALLOCATE);
- TempDescriptor descriptor(mAllocator, mDummyDescriptorInfo);
+ TempDescriptor descriptor(mClient, mDummyDescriptorInfo);
ASSERT_TRUE(descriptor.isValid());
hidl_vec<BufferDescriptor> descriptors;
@@ -183,7 +192,7 @@
descriptors[0] = descriptor;
descriptors[1] = descriptor;
- auto ret = mAllocator->testAllocate(descriptors);
+ auto ret = mClient->testAllocate(descriptors);
ASSERT_TRUE(ret.getStatus().isOk());
auto error = static_cast<Error>(ret);
@@ -194,7 +203,7 @@
* Test allocate/free with a single buffer descriptor.
*/
TEST_F(GraphicsAllocatorHidlTest, AllocateFreeBasic) {
- TempDescriptor descriptor(mAllocator, mDummyDescriptorInfo);
+ TempDescriptor descriptor(mClient, mDummyDescriptorInfo);
ASSERT_TRUE(descriptor.isValid());
hidl_vec<BufferDescriptor> descriptors;
@@ -203,7 +212,7 @@
Error error;
std::vector<Buffer> buffers;
- auto ret = mAllocator->allocate(
+ auto ret = mClient->allocate(
descriptors, [&](const auto& tmpError, const auto& tmpBuffers) {
error = tmpError;
buffers = tmpBuffers;
@@ -214,7 +223,7 @@
EXPECT_EQ(1u, buffers.size());
if (!buffers.empty()) {
- auto err_ret = mAllocator->free(buffers[0]);
+ auto err_ret = mClient->free(buffers[0]);
EXPECT_TRUE(err_ret.getStatus().isOk());
EXPECT_EQ(Error::NONE, static_cast<Error>(err_ret));
}
@@ -224,10 +233,10 @@
* Test allocate/free with an array of buffer descriptors.
*/
TEST_F(GraphicsAllocatorHidlTest, AllocateFreeArray) {
- TempDescriptor descriptor1(mAllocator, mDummyDescriptorInfo);
+ TempDescriptor descriptor1(mClient, mDummyDescriptorInfo);
ASSERT_TRUE(descriptor1.isValid());
- TempDescriptor descriptor2(mAllocator, mDummyDescriptorInfo);
+ TempDescriptor descriptor2(mClient, mDummyDescriptorInfo);
ASSERT_TRUE(descriptor2.isValid());
hidl_vec<BufferDescriptor> descriptors;
@@ -238,7 +247,7 @@
Error error;
std::vector<Buffer> buffers;
- auto ret = mAllocator->allocate(
+ auto ret = mClient->allocate(
descriptors, [&](const auto& tmpError, const auto& tmpBuffers) {
error = tmpError;
buffers = tmpBuffers;
@@ -249,14 +258,14 @@
EXPECT_EQ(descriptors.size(), buffers.size());
for (auto buf : buffers) {
- auto err_ret = mAllocator->free(buf);
+ auto err_ret = mClient->free(buf);
EXPECT_TRUE(err_ret.getStatus().isOk());
EXPECT_EQ(Error::NONE, static_cast<Error>(err_ret));
}
}
TEST_F(GraphicsAllocatorHidlTest, ExportHandle) {
- TempDescriptor descriptor(mAllocator, mDummyDescriptorInfo);
+ TempDescriptor descriptor(mClient, mDummyDescriptorInfo);
ASSERT_TRUE(descriptor.isValid());
hidl_vec<BufferDescriptor> descriptors;
@@ -265,7 +274,7 @@
Error error;
std::vector<Buffer> buffers;
- auto ret = mAllocator->allocate(
+ auto ret = mClient->allocate(
descriptors, [&](const auto& tmpError, const auto& tmpBuffers) {
error = tmpError;
buffers = tmpBuffers;
@@ -275,13 +284,13 @@
ASSERT_TRUE(error == Error::NONE || error == Error::NOT_SHARED);
ASSERT_EQ(1u, buffers.size());
- ret = mAllocator->exportHandle(
+ ret = mClient->exportHandle(
descriptors[0], buffers[0],
[&](const auto& tmpError, const auto&) { error = tmpError; });
EXPECT_TRUE(ret.getStatus().isOk());
EXPECT_EQ(Error::NONE, error);
- auto err_ret = mAllocator->free(buffers[0]);
+ auto err_ret = mClient->free(buffers[0]);
EXPECT_TRUE(err_ret.getStatus().isOk());
EXPECT_EQ(Error::NONE, static_cast<Error>(err_ret));
}
diff --git a/light/2.0/vts/functional/Android.bp b/light/2.0/vts/functional/Android.bp
new file mode 100644
index 0000000..c3475a6
--- /dev/null
+++ b/light/2.0/vts/functional/Android.bp
@@ -0,0 +1,32 @@
+//
+// 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.
+//
+
+cc_test {
+ name: "light_hidl_hal_test",
+ gtest: true,
+ srcs: ["light_hidl_hal_test.cpp"],
+ shared_libs: [
+ "liblog",
+ "libutils",
+ "android.hardware.light@2.0",
+ ],
+ static_libs: ["libgtest"],
+ cflags: [
+ "-O0",
+ "-g",
+ ],
+}
+
diff --git a/light/2.0/vts/functional/light_hidl_hal_test.cpp b/light/2.0/vts/functional/light_hidl_hal_test.cpp
new file mode 100644
index 0000000..db67467
--- /dev/null
+++ b/light/2.0/vts/functional/light_hidl_hal_test.cpp
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "light_hidl_hal_test"
+
+#include <android-base/logging.h>
+#include <android/hardware/light/2.0/ILight.h>
+#include <android/hardware/light/2.0/types.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+
+using ::android::hardware::light::V2_0::Brightness;
+using ::android::hardware::light::V2_0::Flash;
+using ::android::hardware::light::V2_0::ILight;
+using ::android::hardware::light::V2_0::LightState;
+using ::android::hardware::light::V2_0::Status;
+using ::android::hardware::light::V2_0::Type;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+#define LIGHT_SERVICE_NAME "light"
+
+#define EXPECT_OK(ret) EXPECT_TRUE(ret.getStatus().isOk())
+
+// The main test class for VIBRATOR HIDL HAL.
+class LightHidlTest : public ::testing::Test {
+public:
+ virtual void SetUp() override {
+ light = ILight::getService(LIGHT_SERVICE_NAME);
+
+ ASSERT_NE(light, nullptr);
+ ALOGI("Test is remote: %d", light->isRemote());
+ }
+
+ virtual void TearDown() override {}
+
+ sp<ILight> light;
+};
+
+// A class for test environment setup (kept since this file is a template).
+class LightHidlEnvironment : public ::testing::Environment {
+public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+
+private:
+};
+
+const static LightState kWhite = {
+ .color = 0xFFFFFFFF,
+ .flashMode = Flash::TIMED,
+ .flashOnMs = 100,
+ .flashOffMs = 50,
+ .brightnessMode = Brightness::USER,
+};
+
+const static LightState kOff = {
+ .color = 0x00000000,
+ .flashMode = Flash::NONE,
+ .flashOnMs = 0,
+ .flashOffMs = 0,
+ .brightnessMode = Brightness::USER,
+};
+
+/**
+ * Ensure all lights which are reported as supported work.
+ */
+TEST_F(LightHidlTest, TestSupported) {
+ EXPECT_OK(light->getSupportedTypes([this](const hidl_vec<Type> &supportedTypes) {
+ for (size_t i = 0; i < supportedTypes.size(); i++) {
+ EXPECT_OK(light->setLight(supportedTypes[i], kWhite));
+ }
+
+ usleep(500000);
+
+ for (size_t i = 0; i < supportedTypes.size(); i++) {
+ EXPECT_OK(light->setLight(supportedTypes[i], kOff));
+ }
+ }));
+}
+
+int main(int argc, char **argv) {
+ ::testing::AddGlobalTestEnvironment(new LightHidlEnvironment);
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = RUN_ALL_TESTS();
+ ALOGI("Test result = %d", status);
+ return status;
+}
diff --git a/light/Android.bp b/light/Android.bp
index c12cd4f..8d2c986 100644
--- a/light/Android.bp
+++ b/light/Android.bp
@@ -1,4 +1,5 @@
// This is an autogenerated file, do not edit.
subdirs = [
"2.0",
+ "2.0/vts/functional",
]
diff --git a/nfc/1.0/INfc.hal b/nfc/1.0/INfc.hal
index 1c952db..c6e1511 100644
--- a/nfc/1.0/INfc.hal
+++ b/nfc/1.0/INfc.hal
@@ -27,72 +27,80 @@
* NCI initialization - ie accept CORE_RESET and subsequent commands through
* the write() call.
*
- * If open() returns 0, the NCI stack will wait for a NfcEvent.OPEN_CPLT
- * before continuing.
+ * If open() returns NfcStatus::OK, the NCI stack will wait for a
+ * NfcEvent.OPEN_CPLT before continuing.
*
- * If open() returns any other value, the NCI stack will stop.
+ * If open() returns NfcStatus::FAILED, the NCI stack will stop.
*
*/
@entry
@callflow(next={"write", "coreInitialized", "prediscover", "powerCycle", "controlGranted"})
- open(INfcClientCallback clientCallback) generates (int32_t retval);
+ open(INfcClientCallback clientCallback) generates (NfcStatus status);
/*
* Performs an NCI write.
*
* This method may queue writes and return immediately. The only
* requirement is that the writes are executed in order.
+ *
+ * @return number of bytes written to the NFCC
*/
@callflow(next={"write", "prediscover", "coreInitialized", "close", "powerCycle",
"controlGranted"})
- write(NfcData data) generates (int32_t retval);
+ write(NfcData data) generates (uint32_t retval);
/*
- * coreInitialized() is called after the CORE_INIT_RSP is received from the NFCC.
- * At this time, the HAL can do any chip-specific configuration.
+ * coreInitialized() is called after the CORE_INIT_RSP is received from the
+ * NFCC. At this time, the HAL can do any chip-specific configuration.
*
- * If coreInitialized() returns 0, the NCI stack will wait for a NfcEvent.POST_INIT_CPLT
- * before continuing.
+ * If coreInitialized() returns NfcStatus::OK, the NCI stack will wait for a
+ * NfcEvent.POST_INIT_CPLT before continuing.
*
- * If coreInitialized() returns any other value, the NCI stack will continue
- * immediately.
+ * If coreInitialized() returns NfcStatus::FAILED, the NCI stack will
+ * continue immediately.
*/
@callflow(next={"write", "prediscover", "close"})
- coreInitialized(NfcData data) generates (int32_t retval);
+ coreInitialized(NfcData data) generates (NfcStatus status);
/*
* prediscover is called every time before starting RF discovery.
* It is a good place to do vendor-specific configuration that must be
* performed every time RF discovery is about to be started.
*
- * If prediscover() returns 0, the NCI stack will wait for a NfcEvent.PREDISCOVER_CPLT
- * before continuing.
+ * If prediscover() returns NfcStatus::OK, the NCI stack will wait for a
+ * NfcEvent.PREDISCOVER_CPLT before continuing.
*
- * If prediscover() returns any other value, the NCI stack will start
+ * If prediscover() returns NfcStatus::FAILED, the NCI stack will start
* RF discovery immediately.
*/
@callflow(next={"write", "close", "coreInitialized", "powerCycle", "controlGranted"})
- prediscover() generates (int32_t retval);
+ prediscover() generates (NfcStatus status);
/*
* Close the NFC controller. Should free all resources.
+ *
+ * @return NfcStatus::OK on success and NfcStatus::FAILED on error.
*/
@exit
- close() generates (int32_t retval);
+ close() generates (NfcStatus status);
/*
* Grant HAL the exclusive control to send NCI commands.
* Called in response to NfcEvent.REQUEST_CONTROL.
* Must only be called when there are no NCI commands pending.
* NfcEvent.RELEASE_CONTROL will notify when HAL no longer needs exclusive control.
+ *
+ * @return NfcStatus::OK on success and NfcStatus::FAILED on error.
*/
@callflow(next={"write", "close", "prediscover", "coreInitialized", "powerCycle"})
- controlGranted() generates (int32_t retval);
+ controlGranted() generates (NfcStatus status);
/*
* Restart controller by power cyle;
* NfcEvent.OPEN_CPLT will notify when operation is complete.
+ *
+ * @return NfcStatus::OK on success and NfcStatus::FAILED on error.
*/
@callflow(next={"write", "coreInitialized", "prediscover", "controlGranted", "close"})
- powerCycle() generates (int32_t retval);
+ powerCycle() generates (NfcStatus status);
};
diff --git a/nfc/1.0/default/Nfc.cpp b/nfc/1.0/default/Nfc.cpp
index d3868c1..bee374d 100644
--- a/nfc/1.0/default/Nfc.cpp
+++ b/nfc/1.0/default/Nfc.cpp
@@ -17,34 +17,36 @@
}
// Methods from ::android::hardware::nfc::V1_0::INfc follow.
-::android::hardware::Return<int32_t> Nfc::open(const sp<INfcClientCallback>& clientCallback) {
+::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback) {
mCallback = clientCallback;
- return mDevice->open(mDevice, eventCallback, dataCallback);
+ int ret = mDevice->open(mDevice, eventCallback, dataCallback);
+ return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
}
-::android::hardware::Return<int32_t> Nfc::write(const hidl_vec<uint8_t>& data) {
+::android::hardware::Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data) {
return mDevice->write(mDevice, data.size(), &data[0]);
}
-::android::hardware::Return<int32_t> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) {
+::android::hardware::Return<NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) {
hidl_vec<uint8_t> copy = data;
- return mDevice->core_initialized(mDevice, ©[0]);
+ int ret = mDevice->core_initialized(mDevice, ©[0]);
+ return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
}
-::android::hardware::Return<int32_t> Nfc::prediscover() {
- return mDevice->pre_discover(mDevice);
+::android::hardware::Return<NfcStatus> Nfc::prediscover() {
+ return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}
-::android::hardware::Return<int32_t> Nfc::close() {
- return mDevice->close(mDevice);
+::android::hardware::Return<NfcStatus> Nfc::close() {
+ return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}
-::android::hardware::Return<int32_t> Nfc::controlGranted() {
- return mDevice->control_granted(mDevice);
+::android::hardware::Return<NfcStatus> Nfc::controlGranted() {
+ return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}
-::android::hardware::Return<int32_t> Nfc::powerCycle() {
- return mDevice->power_cycle(mDevice);
+::android::hardware::Return<NfcStatus> Nfc::powerCycle() {
+ return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}
diff --git a/nfc/1.0/default/Nfc.h b/nfc/1.0/default/Nfc.h
index e596495..13004a5 100644
--- a/nfc/1.0/default/Nfc.h
+++ b/nfc/1.0/default/Nfc.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_nfc_V1_0_Nfc_H_
-#define HIDL_GENERATED_android_hardware_nfc_V1_0_Nfc_H_
+#ifndef ANDROID_HARDWARE_NFC_V1_0_NFC_H
+#define ANDROID_HARDWARE_NFC_V1_0_NFC_H
#include <android/hardware/nfc/1.0/INfc.h>
#include <hidl/Status.h>
@@ -21,13 +21,13 @@
struct Nfc : public INfc {
Nfc(nfc_nci_device_t* device);
- ::android::hardware::Return<int32_t> open(const sp<INfcClientCallback>& clientCallback) override;
- ::android::hardware::Return<int32_t> write(const hidl_vec<uint8_t>& data) override;
- ::android::hardware::Return<int32_t> coreInitialized(const hidl_vec<uint8_t>& data) override;
- ::android::hardware::Return<int32_t> prediscover() override;
- ::android::hardware::Return<int32_t> close() override;
- ::android::hardware::Return<int32_t> controlGranted() override;
- ::android::hardware::Return<int32_t> powerCycle() override;
+ ::android::hardware::Return<NfcStatus> open(const sp<INfcClientCallback>& clientCallback) override;
+ ::android::hardware::Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
+ ::android::hardware::Return<NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override;
+ ::android::hardware::Return<NfcStatus> prediscover() override;
+ ::android::hardware::Return<NfcStatus> close() override;
+ ::android::hardware::Return<NfcStatus> controlGranted() override;
+ ::android::hardware::Return<NfcStatus> powerCycle() override;
static void eventCallback(uint8_t event, uint8_t status) {
if (mCallback != nullptr) {
@@ -56,4 +56,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_nfc_V1_0_Nfc_H_
+#endif // ANDROID_HARDWARE_NFC_V1_0_NFC_H
diff --git a/nfc/1.0/vts/Nfc.vts b/nfc/1.0/vts/Nfc.vts
index c2313d5..5882bf5 100644
--- a/nfc/1.0/vts/Nfc.vts
+++ b/nfc/1.0/vts/Nfc.vts
@@ -11,8 +11,8 @@
api: {
name: "open"
return_type_hidl: {
- type: TYPE_SCALAR
- scalar_type: "int32_t"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::nfc::V1_0::NfcStatus"
}
arg: {
type: TYPE_HIDL_CALLBACK
@@ -35,7 +35,7 @@
name: "write"
return_type_hidl: {
type: TYPE_SCALAR
- scalar_type: "int32_t"
+ scalar_type: "uint32_t"
}
arg: {
type: TYPE_VECTOR
@@ -57,8 +57,8 @@
api: {
name: "coreInitialized"
return_type_hidl: {
- type: TYPE_SCALAR
- scalar_type: "int32_t"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::nfc::V1_0::NfcStatus"
}
arg: {
type: TYPE_VECTOR
@@ -77,8 +77,8 @@
api: {
name: "prediscover"
return_type_hidl: {
- type: TYPE_SCALAR
- scalar_type: "int32_t"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::nfc::V1_0::NfcStatus"
}
callflow: {
next: "write"
@@ -92,8 +92,8 @@
api: {
name: "close"
return_type_hidl: {
- type: TYPE_SCALAR
- scalar_type: "int32_t"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::nfc::V1_0::NfcStatus"
}
callflow: {
exit: true
@@ -103,8 +103,8 @@
api: {
name: "controlGranted"
return_type_hidl: {
- type: TYPE_SCALAR
- scalar_type: "int32_t"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::nfc::V1_0::NfcStatus"
}
callflow: {
next: "write"
@@ -118,8 +118,8 @@
api: {
name: "powerCycle"
return_type_hidl: {
- type: TYPE_SCALAR
- scalar_type: "int32_t"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::nfc::V1_0::NfcStatus"
}
callflow: {
next: "write"
diff --git a/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp b/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
index e215704..4d7c557 100644
--- a/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
+++ b/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
@@ -17,63 +17,145 @@
#define LOG_TAG "nfc_hidl_hal_test"
#include <android-base/logging.h>
-#include <hardware/nfc.h>
-#include <android/hardware/nfc/1.0/types.h>
#include <android/hardware/nfc/1.0/INfc.h>
#include <android/hardware/nfc/1.0/INfcClientCallback.h>
+#include <android/hardware/nfc/1.0/types.h>
+#include <hardware/nfc.h>
+#include <hwbinder/ProcessState.h>
#include <gtest/gtest.h>
+#include <chrono>
+#include <condition_variable>
+#include <mutex>
+using ::android::hardware::ProcessState;
using ::android::hardware::nfc::V1_0::INfc;
using ::android::hardware::nfc::V1_0::INfcClientCallback;
+using ::android::hardware::nfc::V1_0::NfcEvent;
+using ::android::hardware::nfc::V1_0::NfcStatus;
+using ::android::hardware::nfc::V1_0::NfcData;
using ::android::hardware::Return;
using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
using ::android::sp;
#define NFC_NCI_SERVICE_NAME "nfc_nci"
+/* NCI Commands */
+#define CORE_RESET_CMD \
+ { 0x20, 0x00, 0x01, 0x00 }
+#define CORE_CONN_CREATE_CMD \
+ { 0x20, 0x04, 0x02, 0x01, 0x00 }
+#define INVALID_COMMAND \
+ { 0x20, 0x00, 0x00 }
+#define FAULTY_DATA_PACKET \
+ { 0x00, 0x00, 0xFF }
-// Simple NfcClientCallback used as part of testing.
-class NfcClientCallback : public INfcClientCallback {
- public:
- NfcClientCallback() {};
+#define LOOP_BACK_HEADER_SIZE 3
+#define SYNTAX_ERROR 5
+#define NUMBER_LOOPS 3922
+#define VERSION 0x11
+#define TIMEOUT_PERIOD 5
- virtual ~NfcClientCallback() = default;
-
- // sendEvent callback function - currently no-op.
- Return<void> sendEvent(
- ::android::hardware::nfc::V1_0::NfcEvent event,
- ::android::hardware::nfc::V1_0::NfcStatus event_status) override {
- return Void();
- };
-
- // sendData callback function - currently no-op.
- Return<void> sendData(const ::android::hardware::nfc::V1_0::NfcData &data ) override {
- ::android::hardware::nfc::V1_0::NfcData copy = data;
- return Void();
- };
-};
-
+static bool passthrough = true;
// The main test class for NFC HIDL HAL.
class NfcHidlTest : public ::testing::Test {
public:
virtual void SetUp() override {
- // currently test passthrough mode only
- nfc = INfc::getService(NFC_NCI_SERVICE_NAME, true);
- ASSERT_NE(nfc, nullptr);
+ nfc_ = INfc::getService(NFC_NCI_SERVICE_NAME, passthrough);
+ ASSERT_NE(nfc_, nullptr);
- nfc_cb = new NfcClientCallback();
- ASSERT_NE(nfc_cb, nullptr);
+ // TODO:b/31748996
+ if (nfc_->isRemote()) {
+ ProcessState::self()->setThreadPoolMaxThreadCount(1);
+ ProcessState::self()->startThreadPool();
+ }
+
+ nfc_cb_ = new NfcClientCallback(*this);
+ ASSERT_NE(nfc_cb_, nullptr);
+
+ count = 0;
+ last_event_ = NfcEvent::ERROR;
+ last_status_ = NfcStatus::FAILED;
+
+ EXPECT_EQ(NfcStatus::OK, nfc_->open(nfc_cb_));
+ // Wait for OPEN_CPLT event
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(NfcEvent::OPEN_CPLT, last_event_);
+ EXPECT_EQ(NfcStatus::OK, last_status_);
}
- virtual void TearDown() override {}
+ virtual void TearDown() override {
+ EXPECT_EQ(NfcStatus::OK, nfc_->close());
+ // Wait for CLOSE_CPLT event
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(NfcEvent::CLOSE_CPLT, last_event_);
+ EXPECT_EQ(NfcStatus::OK, last_status_);
+ }
- sp<INfc> nfc;
- sp<INfcClientCallback> nfc_cb;
+ /* Used as a mechanism to inform the test about data/event callback */
+ inline void notify() {
+ std::unique_lock<std::mutex> lock(mtx);
+ count++;
+ cv.notify_one();
+ }
+
+ /* Test code calls this function to wait for data/event callback */
+ inline std::cv_status wait() {
+ std::unique_lock<std::mutex> lock(mtx);
+
+ std::cv_status status = std::cv_status::no_timeout;
+ auto now = std::chrono::system_clock::now();
+ while (count == 0) {
+ status = cv.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
+ if (status == std::cv_status::timeout) return status;
+ }
+ count--;
+ return status;
+ }
+
+ /* Callback class for data & Event. */
+ class NfcClientCallback : public INfcClientCallback {
+ NfcHidlTest& parent_;
+
+ public:
+ NfcClientCallback(NfcHidlTest& parent) : parent_(parent){};
+
+ virtual ~NfcClientCallback() = default;
+
+ /* sendEvent callback function - Records the Event & Status
+ * and notifies the TEST
+ **/
+ Return<void> sendEvent(NfcEvent event, NfcStatus event_status) override {
+ parent_.last_event_ = event;
+ parent_.last_status_ = event_status;
+ parent_.notify();
+ return Void();
+ };
+
+ /* sendData callback function. Records the data and notifies the TEST*/
+ Return<void> sendData(const NfcData& data) override {
+ size_t size = parent_.last_data_.size();
+ parent_.last_data_.resize(size + 1);
+ parent_.last_data_[size] = data;
+ parent_.notify();
+ return Void();
+ };
+ };
+
+ sp<INfc> nfc_;
+ sp<INfcClientCallback> nfc_cb_;
+ NfcEvent last_event_;
+ NfcStatus last_status_;
+ hidl_vec<NfcData> last_data_;
+
+ private:
+ std::mutex mtx;
+ std::condition_variable cv;
+ int count;
};
-
// A class for test environment setup (kept since this file is a template).
class NfcHidlEnvironment : public ::testing::Environment {
public:
@@ -83,15 +165,201 @@
private:
};
-TEST_F(NfcHidlTest, OpenAndClose) {
- EXPECT_EQ(0, (int)nfc->open(nfc_cb));
- EXPECT_EQ(0, (int)nfc->close());
+/*
+ * OpenAndClose:
+ * Makes an open call, waits for NfcEvent.OPEN_CPLT
+ * Immediately calls close() and waits for NfcEvent.CLOSE_CPLT
+ * Since open and close calls are a part of SetUp() and TearDown(),
+ * the function definition is intentionally kept empty
+ */
+TEST_F(NfcHidlTest, OpenAndClose) {}
+
+/*
+ * WriteCoreReset:
+ * Sends CORE_RESET_CMD
+ * Waits for CORE_RESET_RSP
+ * Checks the status and the version number
+ */
+TEST_F(NfcHidlTest, WriteCoreReset) {
+ std::vector<uint8_t> cmd = CORE_RESET_CMD;
+ NfcData data = cmd;
+ EXPECT_EQ(data.size(), nfc_->write(data));
+ // Wait for CORE_RESET_RSP
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(1ul, last_data_.size());
+ EXPECT_EQ(6ul, last_data_[0].size());
+ EXPECT_EQ((int)NfcStatus::OK, last_data_[0][3]);
+ EXPECT_GE(VERSION, last_data_[0][4]);
}
-int main(int argc, char **argv) {
+/*
+ * WriteInvalidCommand:
+ * Sends an invalid command
+ * Waits for response
+ * Checks SYNTAX_ERROR status
+ */
+TEST_F(NfcHidlTest, WriteInvalidCommand) {
+ // Send an Error Command
+ std::vector<uint8_t> cmd = INVALID_COMMAND;
+ NfcData data = cmd;
+ EXPECT_EQ(data.size(), nfc_->write(data));
+ // Wait for RSP
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(1ul, last_data_.size());
+ EXPECT_EQ(4ul, last_data_[0].size());
+ EXPECT_EQ(SYNTAX_ERROR, last_data_[0][3]);
+}
+
+/*
+ * WriteInvalidAndThenValidCommand:
+ * Sends an Faulty Data Packet
+ * Waits for CORE_INTERFACE_ERROR_NTF
+ * Checks SYNTAX_ERROR status
+ * Repeat for 100 times appending 0xFF each time to the packet
+ * Send CORE_CONN_CREATE_CMD for loop-back mode
+ * Check the response
+ */
+TEST_F(NfcHidlTest, WriteInvalidAndThenValidCommand) {
+ // Send an Error Data Packet
+ std::vector<uint8_t> cmd = FAULTY_DATA_PACKET;
+ NfcData data = cmd;
+ size_t size = data.size();
+
+ for (int i = 0; i < 100; i++) {
+ last_data_.resize(0);
+ data.resize(++size);
+ data[size - 1] = 0xFF;
+ EXPECT_EQ(data.size(), nfc_->write(data));
+ // Wait for CORE_INTERFACE_ERROR_NTF
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(1ul, last_data_.size());
+ EXPECT_EQ(5ul, last_data_[0].size());
+ EXPECT_EQ(0x60, last_data_[0][0]);
+ EXPECT_EQ(0x08, last_data_[0][1]);
+ EXPECT_EQ(0x02, last_data_[0][2]);
+ EXPECT_EQ(SYNTAX_ERROR, last_data_[0][3]);
+ }
+
+ cmd = CORE_CONN_CREATE_CMD;
+ data = cmd;
+ last_data_.resize(0);
+ EXPECT_EQ(data.size(), nfc_->write(data));
+ // Wait for CORE_CONN_CREATE_RSP
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(1ul, last_data_.size());
+ EXPECT_EQ(7ul, last_data_[0].size());
+ EXPECT_EQ((int)NfcStatus::OK, last_data_[0][3]);
+}
+/*
+ * Bandwidth:
+ * Sets the loop-back mode using CORE_CONN_CREATE_CMD
+ * Sends max payload size data
+ * Waits for the response
+ * Checks the data received
+ * Repeat to send total of 1Mb data
+ */
+TEST_F(NfcHidlTest, Bandwidth) {
+ std::vector<uint8_t> cmd = CORE_CONN_CREATE_CMD;
+ NfcData data = cmd;
+ EXPECT_EQ(data.size(), nfc_->write(data));
+ // Wait for CORE_CONN_CREATE_RSP
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(1ul, last_data_.size());
+ EXPECT_EQ(7ul, last_data_[0].size());
+ EXPECT_EQ((int)NfcStatus::OK, last_data_[0][3]);
+ uint8_t conn_id = last_data_[0][6];
+ uint32_t max_payload_size = last_data_[0][4];
+
+ for (int loops = 0; loops < NUMBER_LOOPS; loops++) {
+ last_data_.resize(0);
+ data.resize(max_payload_size + LOOP_BACK_HEADER_SIZE);
+ data[0] = conn_id;
+ data[1] = 0x00;
+ data[2] = max_payload_size;
+ for (uint32_t i = 0; i < max_payload_size; i++) {
+ data[i + LOOP_BACK_HEADER_SIZE] = i;
+ }
+ EXPECT_EQ(max_payload_size + LOOP_BACK_HEADER_SIZE, nfc_->write(data));
+ // Wait for data and CORE_CONN_CREDITS_NTF
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ // Check if the same data was recieved back
+ EXPECT_EQ(2ul, last_data_.size());
+ EXPECT_EQ(data.size(), last_data_[0].size());
+ for (size_t i = 0; i < data.size(); i++) {
+ EXPECT_EQ(data[i], last_data_[0][i]);
+ }
+
+ EXPECT_EQ(6ul, last_data_[1].size());
+ // Check if the credit is refilled to 1
+ EXPECT_EQ(1, last_data_[1][5]);
+ }
+}
+
+/*
+ * PowerCycle:
+ * Calls powerCycle()
+ * Waits for NfcEvent.OPEN_CPLT
+ * Checks status
+ */
+TEST_F(NfcHidlTest, PowerCycle) {
+ EXPECT_EQ(NfcStatus::OK, nfc_->powerCycle());
+ // Wait for NfcEvent.OPEN_CPLT
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(NfcEvent::OPEN_CPLT, last_event_);
+ EXPECT_EQ(NfcStatus::OK, last_status_);
+}
+
+/*
+ * CoreInitialized:
+ * Calls coreInitialized()
+ * Waits for NfcEvent.POST_INIT_CPLT
+ */
+TEST_F(NfcHidlTest, CoreInitialized) {
+ NfcData data;
+ data.resize(1);
+ data[0] = 0;
+ EXPECT_EQ(NfcStatus::OK, nfc_->coreInitialized(data));
+ // Wait for NfcEvent.POST_INIT_CPLT
+ EXPECT_EQ(std::cv_status::no_timeout, wait());
+ EXPECT_EQ(NfcEvent::POST_INIT_CPLT, last_event_);
+}
+
+/*
+ * ControlGranted:
+ * Calls controlGranted()
+ * Checks the return value
+ */
+TEST_F(NfcHidlTest, ControlGranted) {
+ EXPECT_EQ(NfcStatus::OK, nfc_->controlGranted());
+}
+
+/* PreDiscover:
+ * Calls prediscover()
+ * Checks the return value
+ */
+TEST_F(NfcHidlTest, PreDiscover) {
+ EXPECT_EQ(NfcStatus::OK, nfc_->prediscover());
+}
+
+int main(int argc, char** argv) {
::testing::AddGlobalTestEnvironment(new NfcHidlEnvironment);
::testing::InitGoogleTest(&argc, argv);
+
+ for (int i = 0; i < argc; i++) {
+ if (strstr(argv[i], "passthrough=false") != nullptr) {
+ passthrough = false;
+ break;
+ }
+ }
+ std::system("svc nfc disable"); /* Turn off NFC */
+ sleep(5);
+
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
+
+ std::system("svc nfc enable"); /* Turn on NFC */
+ sleep(5);
+
return status;
}
diff --git a/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/host/NfcHidlBasicTest.py b/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/host/NfcHidlBasicTest.py
index 0c34f99..ede7897 100644
--- a/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/host/NfcHidlBasicTest.py
+++ b/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/host/NfcHidlBasicTest.py
@@ -37,8 +37,8 @@
self.dut.shell.InvokeTerminal("one")
self.dut.shell.one.Execute("setenforce 0") # SELinux permissive mode
- self.dut.shell.one.Execute("service call nfc 6") # Turn off
- time.sleep(2)
+ self.dut.shell.one.Execute("svc nfc disable") # Turn off
+ time.sleep(5)
if getattr(self, PASSTHROUGH_MODE_KEY, True):
self.dut.shell.one.Execute(
@@ -56,7 +56,9 @@
def tearDownClass(self):
"""Turns off the framework-layer NFC service."""
- self.dut.shell.one.Execute("service call nfc 6") # make sure it's off
+ # Ideally, we would want to store the nfc service's state before
+ # turning that off in setUpClass and restore the original state.
+ self.dut.shell.one.Execute("svc nfc disable") # make sure it's off
def testBase(self):
"""A simple test case which just calls each registered function."""
diff --git a/tests/bar/1.0/default/Bar.h b/tests/bar/1.0/default/Bar.h
index 29eedec..d23c1e1 100644
--- a/tests/bar/1.0/default/Bar.h
+++ b/tests/bar/1.0/default/Bar.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_bar_V1_0_Bar_H_
-#define HIDL_GENERATED_android_hardware_tests_bar_V1_0_Bar_H_
+#ifndef ANDROID_HARDWARE_TESTS_BAR_V1_0_BAR_H
+#define ANDROID_HARDWARE_TESTS_BAR_V1_0_BAR_H
#include <android/hardware/tests/bar/1.0/IBar.h>
#include <hidl/Status.h>
@@ -79,4 +79,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_bar_V1_0_Bar_H_
+#endif // ANDROID_HARDWARE_TESTS_BAR_V1_0_BAR_H
diff --git a/tests/bar/1.0/default/ImportTypes.h b/tests/bar/1.0/default/ImportTypes.h
index b43be70..59c7bea 100644
--- a/tests/bar/1.0/default/ImportTypes.h
+++ b/tests/bar/1.0/default/ImportTypes.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_bar_V1_0_ImportTypes_H_
-#define HIDL_GENERATED_android_hardware_tests_bar_V1_0_ImportTypes_H_
+#ifndef ANDROID_HARDWARE_TESTS_BAR_V1_0_IMPORTTYPES_H
+#define ANDROID_HARDWARE_TESTS_BAR_V1_0_IMPORTTYPES_H
#include <android/hardware/tests/bar/1.0/IImportTypes.h>
#include <hidl/Status.h>
@@ -33,4 +33,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_bar_V1_0_ImportTypes_H_
+#endif // ANDROID_HARDWARE_TESTS_BAR_V1_0_IMPORTTYPES_H
diff --git a/tests/foo/1.0/default/Foo.cpp b/tests/foo/1.0/default/Foo.cpp
index a1df3b2..7053b44 100644
--- a/tests/foo/1.0/default/Foo.cpp
+++ b/tests/foo/1.0/default/Foo.cpp
@@ -108,7 +108,13 @@
"should block for %" PRId64 " seconds", cb.get(),
DELAY_S);
c[1] = systemTime();
- bool answer = cb->heyItsYouIsntIt(cb);
+ Return<bool> ret = cb->heyItsYouIsntIt(cb);
+ if (!ret.isOk()) {
+ ALOGE("SERVER(Foo) callMe %p encountered transport error (%d).",
+ cb.get(), ret.getStatus().exceptionCode());
+ return Void();
+ }
+ bool answer = ret.get();
c[1] = systemTime() - c[1];
ALOGI("SERVER(Foo) callMe %p IFooCallback::heyItsYouIsntIt " \
"responded with %d after %" PRId64 "ns", cb.get(), answer, c[1]);
diff --git a/tests/foo/1.0/default/Foo.h b/tests/foo/1.0/default/Foo.h
index 703c210..84629db 100644
--- a/tests/foo/1.0/default/Foo.h
+++ b/tests/foo/1.0/default/Foo.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_foo_V1_0_Foo_H_
-#define HIDL_GENERATED_android_hardware_tests_foo_V1_0_Foo_H_
+#ifndef ANDROID_HARDWARE_TESTS_FOO_V1_0_FOO_H
+#define ANDROID_HARDWARE_TESTS_FOO_V1_0_FOO_H
#include <android/hardware/tests/foo/1.0/IFoo.h>
#include <hidl/Status.h>
@@ -71,4 +71,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_foo_V1_0_Foo_H_
+#endif // ANDROID_HARDWARE_TESTS_FOO_V1_0_FOO_H
diff --git a/tests/foo/1.0/default/FooCallback.h b/tests/foo/1.0/default/FooCallback.h
index 00233b5..3164a9d 100644
--- a/tests/foo/1.0/default/FooCallback.h
+++ b/tests/foo/1.0/default/FooCallback.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_foo_V1_0_FooCallback_H_
-#define HIDL_GENERATED_android_hardware_tests_foo_V1_0_FooCallback_H_
+#ifndef ANDROID_HARDWARE_TESTS_FOO_V1_0_FOOCALLBACK_H
+#define ANDROID_HARDWARE_TESTS_FOO_V1_0_FOOCALLBACK_H
#include <android/hardware/tests/foo/1.0/IFooCallback.h>
#include <hidl/Status.h>
@@ -43,4 +43,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_foo_V1_0_FooCallback_H_
+#endif // ANDROID_HARDWARE_TESTS_FOO_V1_0_FOOCALLBACK_H
diff --git a/tests/inheritance/1.0/default/Child.h b/tests/inheritance/1.0/default/Child.h
index 0d34e83..268dfeb 100644
--- a/tests/inheritance/1.0/default/Child.h
+++ b/tests/inheritance/1.0/default/Child.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Child_H_
-#define HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Child_H_
+#ifndef ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_CHILD_H
+#define ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_CHILD_H
#include <android/hardware/tests/inheritance/1.0/IChild.h>
#include <hidl/Status.h>
@@ -41,4 +41,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Child_H_
+#endif // ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_CHILD_H
diff --git a/tests/inheritance/1.0/default/Fetcher.h b/tests/inheritance/1.0/default/Fetcher.h
index d389853..da9b153 100644
--- a/tests/inheritance/1.0/default/Fetcher.h
+++ b/tests/inheritance/1.0/default/Fetcher.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Fetcher_H_
-#define HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Fetcher_H_
+#ifndef ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_FETCHER_H
+#define ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_FETCHER_H
#include "Child.h"
#include <android/hardware/tests/inheritance/1.0/IFetcher.h>
@@ -42,4 +42,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Fetcher_H_
+#endif // ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_FETCHER_H
diff --git a/tests/inheritance/1.0/default/Grandparent.h b/tests/inheritance/1.0/default/Grandparent.h
index e1113bf..5458b01 100644
--- a/tests/inheritance/1.0/default/Grandparent.h
+++ b/tests/inheritance/1.0/default/Grandparent.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Grandparent_H_
-#define HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Grandparent_H_
+#ifndef ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_GRANDPARENT_H
+#define ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_GRANDPARENT_H
#include <android/hardware/tests/inheritance/1.0/IGrandparent.h>
#include <hidl/Status.h>
@@ -34,4 +34,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Grandparent_H_
+#endif // ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_GRANDPARENT_H
diff --git a/tests/inheritance/1.0/default/Parent.h b/tests/inheritance/1.0/default/Parent.h
index 2e07fdc..48085fd 100644
--- a/tests/inheritance/1.0/default/Parent.h
+++ b/tests/inheritance/1.0/default/Parent.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Parent_H_
-#define HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Parent_H_
+#ifndef ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_PARENT_H
+#define ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_PARENT_H
#include <android/hardware/tests/inheritance/1.0/IParent.h>
#include <hidl/Status.h>
@@ -37,4 +37,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_inheritance_V1_0_Parent_H_
+#endif // ANDROID_HARDWARE_TESTS_INHERITANCE_V1_0_PARENT_H
diff --git a/tests/libhwbinder/1.0/default/Benchmark.h b/tests/libhwbinder/1.0/default/Benchmark.h
index 454fdf2..74b3745 100644
--- a/tests/libhwbinder/1.0/default/Benchmark.h
+++ b/tests/libhwbinder/1.0/default/Benchmark.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_benchmark_V1_0_Benchmark_H_
-#define HIDL_GENERATED_android_hardware_benchmark_V1_0_Benchmark_H_
+#ifndef ANDROID_HARDWARE_BENCHMARK_V1_0_BENCHMARK_H
+#define ANDROID_HARDWARE_BENCHMARK_V1_0_BENCHMARK_H
#include <android/hardware/tests/libhwbinder/1.0/IBenchmark.h>
#include <hidl/Status.h>
@@ -28,4 +28,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_benchmark_V1_0_Benchmark_H_
+#endif // ANDROID_HARDWARE_BENCHMARK_V1_0_BENCHMARK_H
diff --git a/tests/pointer/1.0/default/Graph.h b/tests/pointer/1.0/default/Graph.h
index cbd5a8a..03bd163 100644
--- a/tests/pointer/1.0/default/Graph.h
+++ b/tests/pointer/1.0/default/Graph.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_pointer_V1_0_Graph_H_
-#define HIDL_GENERATED_android_hardware_tests_pointer_V1_0_Graph_H_
+#ifndef ANDROID_HARDWARE_TESTS_POINTER_V1_0_GRAPH_H
+#define ANDROID_HARDWARE_TESTS_POINTER_V1_0_GRAPH_H
#include <android/hardware/tests/pointer/1.0/IGraph.h>
#include <hidl/Status.h>
@@ -44,4 +44,4 @@
} // namespace hardware
} // namespace android
-#endif // HIDL_GENERATED_android_hardware_tests_pointer_V1_0_Graph_H_
+#endif // ANDROID_HARDWARE_TESTS_POINTER_V1_0_GRAPH_H
diff --git a/tests/pointer/1.0/default/Pointer.h b/tests/pointer/1.0/default/Pointer.h
index 41d96fd..87b0f56 100644
--- a/tests/pointer/1.0/default/Pointer.h
+++ b/tests/pointer/1.0/default/Pointer.h
@@ -1,5 +1,5 @@
-#ifndef HIDL_GENERATED_android_hardware_tests_pointer_V1_0_Pointer_H_
-#define HIDL_GENERATED_android_hardware_tests_pointer_V1_0_Pointer_H_
+#ifndef ANDROID_HARDWARE_TESTS_POINTER_V1_0_POINTER_H
+#define ANDROID_HARDWARE_TESTS_POINTER_V1_0_POINTER_H
#include <android/hardware/tests/pointer/1.0/IPointer.h>
#include <android-base/logging.h>
@@ -345,4 +345,4 @@
#undef PUSH_ERROR_IF
-#endif // HIDL_GENERATED_android_hardware_tests_pointer_V1_0_Pointer_H_
+#endif // ANDROID_HARDWARE_TESTS_POINTER_V1_0_POINTER_H
diff --git a/thermal/1.0/vts/functional/vts/testcases/hal/thermal/hidl/target/AndroidTest.xml b/thermal/1.0/vts/functional/vts/testcases/hal/thermal/hidl/target/AndroidTest.xml
index cc159b9..169264d 100644
--- a/thermal/1.0/vts/functional/vts/testcases/hal/thermal/hidl/target/AndroidTest.xml
+++ b/thermal/1.0/vts/functional/vts/testcases/hal/thermal/hidl/target/AndroidTest.xml
@@ -25,7 +25,7 @@
_64bit::DATA/nativetest64/thermal_hidl_hal_test/thermal_hidl_hal_test,
"/>
<option name="binary-test-type" value="gtest" />
- <option name="test-timeout" value="1m" />
+ <option name="test-timeout" value="5m" />
</test>
</configuration>
diff --git a/thermal/1.0/vts/functional/vts/testcases/hal/thermal/hidl/target_profiling/AndroidTest.xml b/thermal/1.0/vts/functional/vts/testcases/hal/thermal/hidl/target_profiling/AndroidTest.xml
index 038dfe2..3790c56 100644
--- a/thermal/1.0/vts/functional/vts/testcases/hal/thermal/hidl/target_profiling/AndroidTest.xml
+++ b/thermal/1.0/vts/functional/vts/testcases/hal/thermal/hidl/target_profiling/AndroidTest.xml
@@ -26,7 +26,7 @@
"/>
<option name="test-config-path" value="vts/testcases/hal/thermal/hidl/target_profiling/ThermalHidlTargetProfilingTest.config" />
<option name="binary-test-type" value="gtest" />
- <option name="test-timeout" value="1m" />
+ <option name="test-timeout" value="5m" />
</test>
</configuration>
diff --git a/wifi/1.0/default/wifi_legacy_hal.cpp b/wifi/1.0/default/wifi_legacy_hal.cpp
index 15b6bfc..560a273 100644
--- a/wifi/1.0/default/wifi_legacy_hal.cpp
+++ b/wifi/1.0/default/wifi_legacy_hal.cpp
@@ -36,6 +36,8 @@
static constexpr uint32_t kMaxCachedGscanResults = 64;
static constexpr uint32_t kMaxGscanFrequenciesForBand = 64;
static constexpr uint32_t kLinkLayerStatsDataMpduSizeThreshold = 128;
+static constexpr uint32_t kMaxWakeReasonStatsArraySize = 32;
+static constexpr uint32_t kMaxRingBuffers = 10;
// Legacy HAL functions accept "C" style function pointers, so use global
// functions to pass to the legacy HAL function and store the corresponding
@@ -97,6 +99,141 @@
}
}
+// Callback to be invoked for ring buffer data indication.
+std::function<void(char*, char*, int, wifi_ring_buffer_status*)>
+ on_ring_buffer_data_internal_callback;
+void onRingBufferData(char* ring_name,
+ char* buffer,
+ int buffer_size,
+ wifi_ring_buffer_status* status) {
+ if (on_ring_buffer_data_internal_callback) {
+ on_ring_buffer_data_internal_callback(
+ ring_name, buffer, buffer_size, status);
+ }
+}
+
+// Callback to be invoked for rtt results results.
+std::function<void(
+ wifi_request_id, unsigned num_results, wifi_rtt_result* rtt_results[])>
+ on_rtt_results_internal_callback;
+void onRttResults(wifi_request_id id,
+ unsigned num_results,
+ wifi_rtt_result* rtt_results[]) {
+ if (on_rtt_results_internal_callback) {
+ on_rtt_results_internal_callback(id, num_results, rtt_results);
+ }
+}
+
+// Callbacks for the various NAN operations.
+// NOTE: These have very little conversions to perform before invoking the user
+// callbacks.
+// So, handle all of them here directly to avoid adding an unnecessary layer.
+std::function<void(transaction_id, const NanResponseMsg&)>
+ on_nan_notify_response_user_callback;
+void onNanNotifyResponse(transaction_id id, NanResponseMsg* msg) {
+ if (on_nan_notify_response_user_callback && msg) {
+ on_nan_notify_response_user_callback(id, *msg);
+ }
+}
+
+std::function<void(const NanPublishTerminatedInd&)>
+ on_nan_event_publish_terminated_user_callback;
+void onNanEventPublishTerminated(NanPublishTerminatedInd* event) {
+ if (on_nan_event_publish_terminated_user_callback && event) {
+ on_nan_event_publish_terminated_user_callback(*event);
+ }
+}
+
+std::function<void(const NanMatchInd&)> on_nan_event_match_user_callback;
+void onNanEventMatch(NanMatchInd* event) {
+ if (on_nan_event_match_user_callback && event) {
+ on_nan_event_match_user_callback(*event);
+ }
+}
+
+std::function<void(const NanMatchExpiredInd&)>
+ on_nan_event_match_expired_user_callback;
+void onNanEventMatchExpired(NanMatchExpiredInd* event) {
+ if (on_nan_event_match_expired_user_callback && event) {
+ on_nan_event_match_expired_user_callback(*event);
+ }
+}
+
+std::function<void(const NanSubscribeTerminatedInd&)>
+ on_nan_event_subscribe_terminated_user_callback;
+void onNanEventSubscribeTerminated(NanSubscribeTerminatedInd* event) {
+ if (on_nan_event_subscribe_terminated_user_callback && event) {
+ on_nan_event_subscribe_terminated_user_callback(*event);
+ }
+}
+
+std::function<void(const NanFollowupInd&)> on_nan_event_followup_user_callback;
+void onNanEventFollowup(NanFollowupInd* event) {
+ if (on_nan_event_followup_user_callback && event) {
+ on_nan_event_followup_user_callback(*event);
+ }
+}
+
+std::function<void(const NanDiscEngEventInd&)>
+ on_nan_event_disc_eng_event_user_callback;
+void onNanEventDiscEngEvent(NanDiscEngEventInd* event) {
+ if (on_nan_event_disc_eng_event_user_callback && event) {
+ on_nan_event_disc_eng_event_user_callback(*event);
+ }
+}
+
+std::function<void(const NanDisabledInd&)> on_nan_event_disabled_user_callback;
+void onNanEventDisabled(NanDisabledInd* event) {
+ if (on_nan_event_disabled_user_callback && event) {
+ on_nan_event_disabled_user_callback(*event);
+ }
+}
+
+std::function<void(const NanTCAInd&)> on_nan_event_tca_user_callback;
+void onNanEventTca(NanTCAInd* event) {
+ if (on_nan_event_tca_user_callback && event) {
+ on_nan_event_tca_user_callback(*event);
+ }
+}
+
+std::function<void(const NanBeaconSdfPayloadInd&)>
+ on_nan_event_beacon_sdf_payload_user_callback;
+void onNanEventBeaconSdfPayload(NanBeaconSdfPayloadInd* event) {
+ if (on_nan_event_beacon_sdf_payload_user_callback && event) {
+ on_nan_event_beacon_sdf_payload_user_callback(*event);
+ }
+}
+
+std::function<void(const NanDataPathRequestInd&)>
+ on_nan_event_data_path_request_user_callback;
+void onNanEventDataPathRequest(NanDataPathRequestInd* event) {
+ if (on_nan_event_data_path_request_user_callback && event) {
+ on_nan_event_data_path_request_user_callback(*event);
+ }
+}
+std::function<void(const NanDataPathConfirmInd&)>
+ on_nan_event_data_path_confirm_user_callback;
+void onNanEventDataPathConfirm(NanDataPathConfirmInd* event) {
+ if (on_nan_event_data_path_confirm_user_callback && event) {
+ on_nan_event_data_path_confirm_user_callback(*event);
+ }
+}
+
+std::function<void(const NanDataPathEndInd&)>
+ on_nan_event_data_path_end_user_callback;
+void onNanEventDataPathEnd(NanDataPathEndInd* event) {
+ if (on_nan_event_data_path_end_user_callback && event) {
+ on_nan_event_data_path_end_user_callback(*event);
+ }
+}
+
+std::function<void(const NanTransmitFollowupInd&)>
+ on_nan_event_transmit_follow_up_user_callback;
+void onNanEventTransmitFollowUp(NanTransmitFollowupInd* event) {
+ if (on_nan_event_transmit_follow_up_user_callback && event) {
+ on_nan_event_transmit_follow_up_user_callback(*event);
+ }
+}
// End of the free-standing "C" style callbacks.
WifiLegacyHal::WifiLegacyHal()
@@ -402,6 +539,406 @@
return {status, link_stats};
}
+std::pair<wifi_error, uint32_t> WifiLegacyHal::getLoggerSupportedFeatureSet() {
+ uint32_t supported_features;
+ wifi_error status = global_func_table_.wifi_get_logger_supported_feature_set(
+ wlan_interface_handle_, &supported_features);
+ return {status, supported_features};
+}
+
+wifi_error WifiLegacyHal::startPktFateMonitoring() {
+ return global_func_table_.wifi_start_pkt_fate_monitoring(
+ wlan_interface_handle_);
+}
+
+std::pair<wifi_error, std::vector<wifi_tx_report>>
+WifiLegacyHal::getTxPktFates() {
+ std::vector<wifi_tx_report> tx_pkt_fates;
+ tx_pkt_fates.resize(MAX_FATE_LOG_LEN);
+ size_t num_fates = 0;
+ wifi_error status =
+ global_func_table_.wifi_get_tx_pkt_fates(wlan_interface_handle_,
+ tx_pkt_fates.data(),
+ tx_pkt_fates.size(),
+ &num_fates);
+ CHECK(num_fates <= MAX_FATE_LOG_LEN);
+ tx_pkt_fates.resize(num_fates);
+ return {status, std::move(tx_pkt_fates)};
+}
+
+std::pair<wifi_error, std::vector<wifi_rx_report>>
+WifiLegacyHal::getRxPktFates() {
+ std::vector<wifi_rx_report> rx_pkt_fates;
+ rx_pkt_fates.resize(MAX_FATE_LOG_LEN);
+ size_t num_fates = 0;
+ wifi_error status =
+ global_func_table_.wifi_get_rx_pkt_fates(wlan_interface_handle_,
+ rx_pkt_fates.data(),
+ rx_pkt_fates.size(),
+ &num_fates);
+ CHECK(num_fates <= MAX_FATE_LOG_LEN);
+ rx_pkt_fates.resize(num_fates);
+ return {status, std::move(rx_pkt_fates)};
+}
+
+std::pair<wifi_error, WakeReasonStats> WifiLegacyHal::getWakeReasonStats() {
+ WakeReasonStats stats;
+ stats.cmd_event_wake_cnt.resize(kMaxWakeReasonStatsArraySize);
+ stats.driver_fw_local_wake_cnt.resize(kMaxWakeReasonStatsArraySize);
+
+ // This legacy struct needs separate memory to store the variable sized wake
+ // reason types.
+ stats.wake_reason_cnt.cmd_event_wake_cnt =
+ reinterpret_cast<int32_t*>(stats.cmd_event_wake_cnt.data());
+ stats.wake_reason_cnt.cmd_event_wake_cnt_sz = stats.cmd_event_wake_cnt.size();
+ stats.wake_reason_cnt.cmd_event_wake_cnt_used = 0;
+ stats.wake_reason_cnt.driver_fw_local_wake_cnt =
+ reinterpret_cast<int32_t*>(stats.driver_fw_local_wake_cnt.data());
+ stats.wake_reason_cnt.driver_fw_local_wake_cnt_sz =
+ stats.driver_fw_local_wake_cnt.size();
+ stats.wake_reason_cnt.driver_fw_local_wake_cnt_used = 0;
+
+ wifi_error status = global_func_table_.wifi_get_wake_reason_stats(
+ wlan_interface_handle_, &stats.wake_reason_cnt);
+
+ CHECK(stats.wake_reason_cnt.cmd_event_wake_cnt_used >= 0 &&
+ static_cast<uint32_t>(stats.wake_reason_cnt.cmd_event_wake_cnt_used) <=
+ kMaxWakeReasonStatsArraySize);
+ stats.cmd_event_wake_cnt.resize(
+ stats.wake_reason_cnt.cmd_event_wake_cnt_used);
+ stats.wake_reason_cnt.cmd_event_wake_cnt = nullptr;
+
+ CHECK(stats.wake_reason_cnt.driver_fw_local_wake_cnt_used >= 0 &&
+ static_cast<uint32_t>(
+ stats.wake_reason_cnt.driver_fw_local_wake_cnt_used) <=
+ kMaxWakeReasonStatsArraySize);
+ stats.driver_fw_local_wake_cnt.resize(
+ stats.wake_reason_cnt.driver_fw_local_wake_cnt_used);
+ stats.wake_reason_cnt.driver_fw_local_wake_cnt = nullptr;
+
+ return {status, stats};
+}
+
+wifi_error WifiLegacyHal::registerRingBufferCallbackHandler(
+ const on_ring_buffer_data_callback& on_user_data_callback) {
+ if (on_ring_buffer_data_internal_callback) {
+ return WIFI_ERROR_NOT_AVAILABLE;
+ }
+ on_ring_buffer_data_internal_callback = [on_user_data_callback](
+ char* ring_name,
+ char* buffer,
+ int buffer_size,
+ wifi_ring_buffer_status* status) {
+ if (status && buffer) {
+ std::vector<uint8_t> buffer_vector(
+ reinterpret_cast<uint8_t*>(buffer),
+ reinterpret_cast<uint8_t*>(buffer) + buffer_size);
+ on_user_data_callback(ring_name, buffer_vector, *status);
+ }
+ };
+ return global_func_table_.wifi_set_log_handler(
+ 0, wlan_interface_handle_, {onRingBufferData});
+}
+
+std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
+WifiLegacyHal::getRingBuffersStatus() {
+ std::vector<wifi_ring_buffer_status> ring_buffers_status;
+ ring_buffers_status.resize(kMaxRingBuffers);
+ uint32_t num_rings = 0;
+ wifi_error status = global_func_table_.wifi_get_ring_buffers_status(
+ wlan_interface_handle_, &num_rings, ring_buffers_status.data());
+ CHECK(num_rings <= kMaxRingBuffers);
+ ring_buffers_status.resize(num_rings);
+ return {status, std::move(ring_buffers_status)};
+}
+
+wifi_error WifiLegacyHal::startRingBufferLogging(const std::string& ring_name,
+ uint32_t verbose_level,
+ uint32_t max_interval_sec,
+ uint32_t min_data_size) {
+ std::vector<char> ring_name_internal(ring_name.begin(), ring_name.end());
+ return global_func_table_.wifi_start_logging(wlan_interface_handle_,
+ verbose_level,
+ 0,
+ max_interval_sec,
+ min_data_size,
+ ring_name_internal.data());
+}
+
+wifi_error WifiLegacyHal::getRingBufferData(const std::string& ring_name) {
+ std::vector<char> ring_name_internal(ring_name.begin(), ring_name.end());
+ return global_func_table_.wifi_get_ring_data(wlan_interface_handle_,
+ ring_name_internal.data());
+}
+
+wifi_error WifiLegacyHal::startRttRangeRequest(
+ wifi_request_id id,
+ const std::vector<wifi_rtt_config>& rtt_configs,
+ const on_rtt_results_callback& on_results_user_callback) {
+ if (on_rtt_results_internal_callback) {
+ return WIFI_ERROR_NOT_AVAILABLE;
+ }
+
+ on_rtt_results_internal_callback = [on_results_user_callback](
+ wifi_request_id id,
+ unsigned num_results,
+ wifi_rtt_result* rtt_results[]) {
+ if (num_results > 0 && !rtt_results) {
+ LOG(ERROR) << "Unexpected nullptr in RTT results";
+ return;
+ }
+ std::vector<const wifi_rtt_result*> rtt_results_vec;
+ std::copy_if(
+ rtt_results,
+ rtt_results + num_results,
+ back_inserter(rtt_results_vec),
+ [](wifi_rtt_result* rtt_result) { return rtt_result != nullptr; });
+ on_results_user_callback(id, rtt_results_vec);
+ };
+
+ std::vector<wifi_rtt_config> rtt_configs_internal(rtt_configs);
+ return global_func_table_.wifi_rtt_range_request(id,
+ wlan_interface_handle_,
+ rtt_configs.size(),
+ rtt_configs_internal.data(),
+ {onRttResults});
+}
+
+wifi_error WifiLegacyHal::cancelRttRangeRequest(
+ wifi_request_id id, const std::vector<std::array<uint8_t, 6>>& mac_addrs) {
+ if (!on_rtt_results_internal_callback) {
+ return WIFI_ERROR_NOT_AVAILABLE;
+ }
+ static_assert(sizeof(mac_addr) == sizeof(std::array<uint8_t, 6>),
+ "MAC address size mismatch");
+ // TODO: How do we handle partial cancels (i.e only a subset of enabled mac
+ // addressed are cancelled).
+ std::vector<std::array<uint8_t, 6>> mac_addrs_internal(mac_addrs);
+ wifi_error status = global_func_table_.wifi_rtt_range_cancel(
+ id,
+ wlan_interface_handle_,
+ mac_addrs.size(),
+ reinterpret_cast<mac_addr*>(mac_addrs_internal.data()));
+ // If the request Id is wrong, don't stop the ongoing range request. Any
+ // other error should be treated as the end of rtt ranging.
+ if (status != WIFI_ERROR_INVALID_REQUEST_ID) {
+ on_rtt_results_internal_callback = nullptr;
+ }
+ return status;
+}
+
+std::pair<wifi_error, wifi_rtt_capabilities>
+WifiLegacyHal::getRttCapabilities() {
+ wifi_rtt_capabilities rtt_caps;
+ wifi_error status = global_func_table_.wifi_get_rtt_capabilities(
+ wlan_interface_handle_, &rtt_caps);
+ return {status, rtt_caps};
+}
+
+std::pair<wifi_error, wifi_rtt_responder> WifiLegacyHal::getRttResponderInfo() {
+ wifi_rtt_responder rtt_responder;
+ wifi_error status = global_func_table_.wifi_rtt_get_responder_info(
+ wlan_interface_handle_, &rtt_responder);
+ return {status, rtt_responder};
+}
+
+wifi_error WifiLegacyHal::enableRttResponder(
+ wifi_request_id id,
+ const wifi_channel_info& channel_hint,
+ uint32_t max_duration_secs,
+ const wifi_rtt_responder& info) {
+ wifi_rtt_responder info_internal(info);
+ return global_func_table_.wifi_enable_responder(id,
+ wlan_interface_handle_,
+ channel_hint,
+ max_duration_secs,
+ &info_internal);
+}
+
+wifi_error WifiLegacyHal::disableRttResponder(wifi_request_id id) {
+ return global_func_table_.wifi_disable_responder(id, wlan_interface_handle_);
+}
+
+wifi_error WifiLegacyHal::setRttLci(wifi_request_id id,
+ const wifi_lci_information& info) {
+ wifi_lci_information info_internal(info);
+ return global_func_table_.wifi_set_lci(
+ id, wlan_interface_handle_, &info_internal);
+}
+
+wifi_error WifiLegacyHal::setRttLcr(wifi_request_id id,
+ const wifi_lcr_information& info) {
+ wifi_lcr_information info_internal(info);
+ return global_func_table_.wifi_set_lcr(
+ id, wlan_interface_handle_, &info_internal);
+}
+
+wifi_error WifiLegacyHal::nanRegisterCallbackHandlers(
+ const NanCallbackHandlers& user_callbacks) {
+ on_nan_notify_response_user_callback = user_callbacks.on_notify_response;
+ on_nan_event_publish_terminated_user_callback =
+ user_callbacks.on_event_publish_terminated;
+ on_nan_event_match_user_callback = user_callbacks.on_event_match;
+ on_nan_event_match_expired_user_callback =
+ user_callbacks.on_event_match_expired;
+ on_nan_event_subscribe_terminated_user_callback =
+ user_callbacks.on_event_subscribe_terminated;
+ on_nan_event_followup_user_callback = user_callbacks.on_event_followup;
+ on_nan_event_disc_eng_event_user_callback =
+ user_callbacks.on_event_disc_eng_event;
+ on_nan_event_disabled_user_callback = user_callbacks.on_event_disabled;
+ on_nan_event_tca_user_callback = user_callbacks.on_event_tca;
+ on_nan_event_beacon_sdf_payload_user_callback =
+ user_callbacks.on_event_beacon_sdf_payload;
+ on_nan_event_data_path_request_user_callback =
+ user_callbacks.on_event_data_path_request;
+ on_nan_event_data_path_confirm_user_callback =
+ user_callbacks.on_event_data_path_confirm;
+ on_nan_event_data_path_end_user_callback =
+ user_callbacks.on_event_data_path_end;
+ on_nan_event_transmit_follow_up_user_callback =
+ user_callbacks.on_event_transmit_follow_up;
+
+ return global_func_table_.wifi_nan_register_handler(
+ wlan_interface_handle_,
+ {onNanNotifyResponse,
+ onNanEventPublishTerminated,
+ onNanEventMatch,
+ onNanEventMatchExpired,
+ onNanEventSubscribeTerminated,
+ onNanEventFollowup,
+ onNanEventDiscEngEvent,
+ onNanEventDisabled,
+ onNanEventTca,
+ onNanEventBeaconSdfPayload,
+ onNanEventDataPathRequest,
+ onNanEventDataPathConfirm,
+ onNanEventDataPathEnd,
+ onNanEventTransmitFollowUp});
+}
+
+wifi_error WifiLegacyHal::nanEnableRequest(transaction_id id,
+ const NanEnableRequest& msg) {
+ NanEnableRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_enable_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanDisableRequest(transaction_id id) {
+ return global_func_table_.wifi_nan_disable_request(id,
+ wlan_interface_handle_);
+}
+
+wifi_error WifiLegacyHal::nanPublishRequest(transaction_id id,
+ const NanPublishRequest& msg) {
+ NanPublishRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_publish_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanPublishCancelRequest(
+ transaction_id id, const NanPublishCancelRequest& msg) {
+ NanPublishCancelRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_publish_cancel_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanSubscribeRequest(transaction_id id,
+ const NanSubscribeRequest& msg) {
+ NanSubscribeRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_subscribe_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanSubscribeCancelRequest(
+ transaction_id id, const NanSubscribeCancelRequest& msg) {
+ NanSubscribeCancelRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_subscribe_cancel_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanTransmitFollowupRequest(
+ transaction_id id, const NanTransmitFollowupRequest& msg) {
+ NanTransmitFollowupRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_transmit_followup_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanStatsRequest(transaction_id id,
+ const NanStatsRequest& msg) {
+ NanStatsRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_stats_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanConfigRequest(transaction_id id,
+ const NanConfigRequest& msg) {
+ NanConfigRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_config_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanTcaRequest(transaction_id id,
+ const NanTCARequest& msg) {
+ NanTCARequest msg_internal(msg);
+ return global_func_table_.wifi_nan_tca_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanBeaconSdfPayloadRequest(
+ transaction_id id, const NanBeaconSdfPayloadRequest& msg) {
+ NanBeaconSdfPayloadRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_beacon_sdf_payload_request(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+std::pair<wifi_error, NanVersion> WifiLegacyHal::nanGetVersion() {
+ NanVersion version;
+ wifi_error status =
+ global_func_table_.wifi_nan_get_version(global_handle_, &version);
+ return {status, version};
+}
+
+wifi_error WifiLegacyHal::nanGetCapabilities(transaction_id id) {
+ return global_func_table_.wifi_nan_get_capabilities(id,
+ wlan_interface_handle_);
+}
+
+wifi_error WifiLegacyHal::nanDataInterfaceCreate(
+ transaction_id id, const std::string& iface_name) {
+ std::vector<char> iface_name_internal(iface_name.begin(), iface_name.end());
+ return global_func_table_.wifi_nan_data_interface_create(
+ id, wlan_interface_handle_, iface_name_internal.data());
+}
+
+wifi_error WifiLegacyHal::nanDataInterfaceDelete(
+ transaction_id id, const std::string& iface_name) {
+ std::vector<char> iface_name_internal(iface_name.begin(), iface_name.end());
+ return global_func_table_.wifi_nan_data_interface_delete(
+ id, wlan_interface_handle_, iface_name_internal.data());
+}
+
+wifi_error WifiLegacyHal::nanDataRequestInitiator(
+ transaction_id id, const NanDataPathInitiatorRequest& msg) {
+ NanDataPathInitiatorRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_data_request_initiator(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanDataIndicationResponse(
+ transaction_id id, const NanDataPathIndicationResponse& msg) {
+ NanDataPathIndicationResponse msg_internal(msg);
+ return global_func_table_.wifi_nan_data_indication_response(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
+wifi_error WifiLegacyHal::nanDataEnd(transaction_id id,
+ const NanDataPathEndRequest& msg) {
+ NanDataPathEndRequest msg_internal(msg);
+ return global_func_table_.wifi_nan_data_end(
+ id, wlan_interface_handle_, &msg_internal);
+}
+
wifi_error WifiLegacyHal::retrieveWlanInterfaceHandle() {
const std::string& ifname_to_find = getStaIfaceName();
wifi_interface_handle* iface_handles = nullptr;
@@ -479,6 +1016,22 @@
on_gscan_event_internal_callback = nullptr;
on_gscan_full_result_internal_callback = nullptr;
on_link_layer_stats_result_internal_callback = nullptr;
+ on_ring_buffer_data_internal_callback = nullptr;
+ on_rtt_results_internal_callback = nullptr;
+ on_nan_notify_response_user_callback = nullptr;
+ on_nan_event_publish_terminated_user_callback = nullptr;
+ on_nan_event_match_user_callback = nullptr;
+ on_nan_event_match_expired_user_callback = nullptr;
+ on_nan_event_subscribe_terminated_user_callback = nullptr;
+ on_nan_event_followup_user_callback = nullptr;
+ on_nan_event_disc_eng_event_user_callback = nullptr;
+ on_nan_event_disabled_user_callback = nullptr;
+ on_nan_event_tca_user_callback = nullptr;
+ on_nan_event_beacon_sdf_payload_user_callback = nullptr;
+ on_nan_event_data_path_request_user_callback = nullptr;
+ on_nan_event_data_path_confirm_user_callback = nullptr;
+ on_nan_event_data_path_end_user_callback = nullptr;
+ on_nan_event_transmit_follow_up_user_callback = nullptr;
}
} // namespace legacy_hal
diff --git a/wifi/1.0/default/wifi_legacy_hal.h b/wifi/1.0/default/wifi_legacy_hal.h
index df1c3d6..62b773e 100644
--- a/wifi/1.0/default/wifi_legacy_hal.h
+++ b/wifi/1.0/default/wifi_legacy_hal.h
@@ -54,6 +54,41 @@
};
#pragma GCC diagnostic pop
+// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
+// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
+// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
+// API. Separate that out into a separate return elements to avoid passing
+// pointers around.
+struct WakeReasonStats {
+ WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
+ std::vector<uint32_t> cmd_event_wake_cnt;
+ std::vector<uint32_t> driver_fw_local_wake_cnt;
+};
+
+// NAN response and event callbacks struct.
+struct NanCallbackHandlers {
+ // NotifyResponse invoked to notify the status of the Request.
+ std::function<void(transaction_id, const NanResponseMsg&)> on_notify_response;
+ // Various event callbacks.
+ std::function<void(const NanPublishTerminatedInd&)>
+ on_event_publish_terminated;
+ std::function<void(const NanMatchInd&)> on_event_match;
+ std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
+ std::function<void(const NanSubscribeTerminatedInd&)>
+ on_event_subscribe_terminated;
+ std::function<void(const NanFollowupInd&)> on_event_followup;
+ std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
+ std::function<void(const NanDisabledInd&)> on_event_disabled;
+ std::function<void(const NanTCAInd&)> on_event_tca;
+ std::function<void(const NanBeaconSdfPayloadInd&)>
+ on_event_beacon_sdf_payload;
+ std::function<void(const NanDataPathRequestInd&)> on_event_data_path_request;
+ std::function<void(const NanDataPathConfirmInd&)> on_event_data_path_confirm;
+ std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
+ std::function<void(const NanTransmitFollowupInd&)>
+ on_event_transmit_follow_up;
+};
+
// Full scan results contain IE info and are hence passed by reference, to
// preserve the variable length array member |ie_data|. Callee must not retain
// the pointer.
@@ -64,6 +99,19 @@
using on_gscan_results_callback = std::function<void(
wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
+// Callback for RTT range request results.
+// Rtt results contain IE info and are hence passed by reference, to
+// preserve the |LCI| and |LCR| pointers. Callee must not retain
+// the pointer.
+using on_rtt_results_callback = std::function<void(
+ wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
+
+// Callback for ring buffer data.
+using on_ring_buffer_data_callback =
+ std::function<void(const std::string&,
+ const std::vector<uint8_t>&,
+ const wifi_ring_buffer_status&)>;
+
/**
* Class that encapsulates all legacy HAL interactions.
* This class manages the lifetime of the event loop thread used by legacy HAL.
@@ -115,6 +163,66 @@
wifi_error enableLinkLayerStats(bool debug);
wifi_error disableLinkLayerStats();
std::pair<wifi_error, LinkLayerStats> getLinkLayerStats();
+ // Logger/debug functions.
+ std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet();
+ wifi_error startPktFateMonitoring();
+ std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates();
+ std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates();
+ std::pair<wifi_error, WakeReasonStats> getWakeReasonStats();
+ wifi_error registerRingBufferCallbackHandler(
+ const on_ring_buffer_data_callback& on_data_callback);
+ std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
+ getRingBuffersStatus();
+ wifi_error startRingBufferLogging(const std::string& ring_name,
+ uint32_t verbose_level,
+ uint32_t max_interval_sec,
+ uint32_t min_data_size);
+ wifi_error getRingBufferData(const std::string& ring_name);
+ // RTT functions.
+ wifi_error startRttRangeRequest(
+ wifi_request_id id,
+ const std::vector<wifi_rtt_config>& rtt_configs,
+ const on_rtt_results_callback& on_results_callback);
+ wifi_error cancelRttRangeRequest(
+ wifi_request_id id, const std::vector<std::array<uint8_t, 6>>& mac_addrs);
+ std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities();
+ std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo();
+ wifi_error enableRttResponder(wifi_request_id id,
+ const wifi_channel_info& channel_hint,
+ uint32_t max_duration_secs,
+ const wifi_rtt_responder& info);
+ wifi_error disableRttResponder(wifi_request_id id);
+ wifi_error setRttLci(wifi_request_id id, const wifi_lci_information& info);
+ wifi_error setRttLcr(wifi_request_id id, const wifi_lcr_information& info);
+ // NAN functions.
+ wifi_error nanRegisterCallbackHandlers(const NanCallbackHandlers& callbacks);
+ wifi_error nanEnableRequest(transaction_id id, const NanEnableRequest& msg);
+ wifi_error nanDisableRequest(transaction_id id);
+ wifi_error nanPublishRequest(transaction_id id, const NanPublishRequest& msg);
+ wifi_error nanPublishCancelRequest(transaction_id id,
+ const NanPublishCancelRequest& msg);
+ wifi_error nanSubscribeRequest(transaction_id id,
+ const NanSubscribeRequest& msg);
+ wifi_error nanSubscribeCancelRequest(transaction_id id,
+ const NanSubscribeCancelRequest& msg);
+ wifi_error nanTransmitFollowupRequest(transaction_id id,
+ const NanTransmitFollowupRequest& msg);
+ wifi_error nanStatsRequest(transaction_id id, const NanStatsRequest& msg);
+ wifi_error nanConfigRequest(transaction_id id, const NanConfigRequest& msg);
+ wifi_error nanTcaRequest(transaction_id id, const NanTCARequest& msg);
+ wifi_error nanBeaconSdfPayloadRequest(transaction_id id,
+ const NanBeaconSdfPayloadRequest& msg);
+ std::pair<wifi_error, NanVersion> nanGetVersion();
+ wifi_error nanGetCapabilities(transaction_id id);
+ wifi_error nanDataInterfaceCreate(transaction_id id,
+ const std::string& iface_name);
+ wifi_error nanDataInterfaceDelete(transaction_id id,
+ const std::string& iface_name);
+ wifi_error nanDataRequestInitiator(transaction_id id,
+ const NanDataPathInitiatorRequest& msg);
+ wifi_error nanDataIndicationResponse(
+ transaction_id id, const NanDataPathIndicationResponse& msg);
+ wifi_error nanDataEnd(transaction_id id, const NanDataPathEndRequest& msg);
private:
// Retrieve the interface handle to be used for the "wlan" interface.