Merge "[WPA3] Move KeyMgmt capability API from StaNetwork to StaIface"
diff --git a/audio/common/all-versions/default/service/Android.mk b/audio/common/all-versions/default/service/Android.mk
index 84de75e..e6ae03e 100644
--- a/audio/common/all-versions/default/service/Android.mk
+++ b/audio/common/all-versions/default/service/Android.mk
@@ -57,7 +57,4 @@
LOCAL_MULTILIB := $(AUDIOSERVER_MULTILIB)
endif
-# b/117506164
-LOCAL_SANITIZE := never
-
include $(BUILD_EXECUTABLE)
diff --git a/bluetooth/1.0/default/vendor_interface.cc b/bluetooth/1.0/default/vendor_interface.cc
index e5f02f3..d56e344 100644
--- a/bluetooth/1.0/default/vendor_interface.cc
+++ b/bluetooth/1.0/default/vendor_interface.cc
@@ -294,6 +294,7 @@
lib_interface_->op(BT_VND_OP_POWER_CTRL, &power_state);
lib_interface_->cleanup();
+ lib_interface_ = nullptr;
}
if (lib_handle_ != nullptr) {
diff --git a/bluetooth/1.0/default/vendor_interface.h b/bluetooth/1.0/default/vendor_interface.h
index 36f4e1b..1d69040 100644
--- a/bluetooth/1.0/default/vendor_interface.h
+++ b/bluetooth/1.0/default/vendor_interface.h
@@ -58,15 +58,15 @@
void HandleIncomingEvent(const hidl_vec<uint8_t>& hci_packet);
- void* lib_handle_;
- bt_vendor_interface_t* lib_interface_;
+ void* lib_handle_ = nullptr;
+ bt_vendor_interface_t* lib_interface_ = nullptr;
async::AsyncFdWatcher fd_watcher_;
InitializeCompleteCallback initialize_complete_cb_;
- hci::HciProtocol* hci_;
+ hci::HciProtocol* hci_ = nullptr;
PacketReadCallback event_cb_;
- FirmwareStartupTimer* firmware_startup_timer_;
+ FirmwareStartupTimer* firmware_startup_timer_ = nullptr;
};
} // namespace implementation
diff --git a/bluetooth/1.0/vts/OWNERS b/bluetooth/1.0/vts/OWNERS
new file mode 100644
index 0000000..58d3a66
--- /dev/null
+++ b/bluetooth/1.0/vts/OWNERS
@@ -0,0 +1,8 @@
+zachoverflow@google.com
+siyuanh@google.com
+mylesgw@google.com
+jpawlowski@google.com
+apanicke@google.com
+stng@google.com
+hsz@google.com
+
diff --git a/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
index 88d4234..90fbb3f 100644
--- a/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
+++ b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
@@ -26,7 +26,10 @@
#include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
+
+#include <chrono>
#include <queue>
+#include <thread>
using ::android::sp;
using ::android::hardware::hidl_death_recipient;
@@ -46,6 +49,7 @@
#define WAIT_FOR_HCI_EVENT_TIMEOUT std::chrono::milliseconds(2000)
#define WAIT_FOR_SCO_DATA_TIMEOUT std::chrono::milliseconds(1000)
#define WAIT_FOR_ACL_DATA_TIMEOUT std::chrono::milliseconds(1000)
+#define INTERFACE_CLOSE_DELAY_MS std::chrono::milliseconds(200)
#define COMMAND_HCI_SHOULD_BE_UNKNOWN \
{ 0xff, 0x3B, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }
@@ -197,8 +201,10 @@
}
virtual void TearDown() override {
+ ALOGI("TearDown");
// Should not be checked in production code
ASSERT_TRUE(bluetooth->close().isOk());
+ std::this_thread::sleep_for(INTERFACE_CLOSE_DELAY_MS);
handle_no_ops();
EXPECT_EQ(static_cast<size_t>(0), event_queue.size());
EXPECT_EQ(static_cast<size_t>(0), sco_queue.size());
@@ -222,9 +228,10 @@
class BluetoothHciDeathRecipient : public hidl_death_recipient {
public:
- virtual void serviceDied(
+ void serviceDied(
uint64_t /*cookie*/,
- const android::wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
+ const android::wp<::android::hidl::base::V1_0::IBase>& /*who*/)
+ override {
FAIL();
}
};
@@ -308,7 +315,7 @@
if (event_is_no_op) {
event_queue.pop();
} else {
- return;
+ break;
}
}
}
diff --git a/bluetooth/OWNERS b/bluetooth/OWNERS
deleted file mode 100644
index 3fa1def..0000000
--- a/bluetooth/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-per-file **/vts/** = siyuanh@google.com, mylesgw@google.com, jpawlowski@google.com, apanicke@google.com, stng@google.com, hsz@google.com
diff --git a/bluetooth/a2dp/1.0/vts/OWNERS b/bluetooth/a2dp/1.0/vts/OWNERS
new file mode 100644
index 0000000..58d3a66
--- /dev/null
+++ b/bluetooth/a2dp/1.0/vts/OWNERS
@@ -0,0 +1,8 @@
+zachoverflow@google.com
+siyuanh@google.com
+mylesgw@google.com
+jpawlowski@google.com
+apanicke@google.com
+stng@google.com
+hsz@google.com
+
diff --git a/camera/common/1.0/default/CameraModule.cpp b/camera/common/1.0/default/CameraModule.cpp
index 392ebbc..9c2b02b 100644
--- a/camera/common/1.0/default/CameraModule.cpp
+++ b/camera/common/1.0/default/CameraModule.cpp
@@ -466,8 +466,8 @@
}
void CameraModule::removeCamera(int cameraId) {
- free_camera_metadata(
- const_cast<camera_metadata_t*>(mCameraInfoMap[cameraId].static_camera_characteristics));
+ free_camera_metadata(const_cast<camera_metadata_t*>(
+ mCameraInfoMap.valueFor(cameraId).static_camera_characteristics));
mCameraInfoMap.removeItem(cameraId);
mDeviceVersionMap.removeItem(cameraId);
}
diff --git a/camera/metadata/3.2/types.hal b/camera/metadata/3.2/types.hal
index 67b4e44..cef0397 100644
--- a/camera/metadata/3.2/types.hal
+++ b/camera/metadata/3.2/types.hal
@@ -1396,7 +1396,8 @@
*
* <p>The arrangement of color filters on sensor;
* represents the colors in the top-left 2x2 section of
- * the sensor, in reading order.</p>
+ * the sensor, in reading order, for a Bayer camera, or the
+ * light spectrum it captures for MONOCHROME camera.</p>
*/
ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT,
diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml
index e117a98..fd996fb 100644
--- a/compatibility_matrices/compatibility_matrix.current.xml
+++ b/compatibility_matrices/compatibility_matrix.current.xml
@@ -145,7 +145,7 @@
</hal>
<hal format="hidl" optional="true">
<name>android.hardware.drm</name>
- <version>1.0</version>
+ <version>1.0-1</version>
<interface>
<name>ICryptoFactory</name>
<regex-instance>.*</regex-instance>
@@ -157,7 +157,7 @@
</hal>
<hal format="hidl" optional="false">
<name>android.hardware.drm</name>
- <version>1.1</version>
+ <version>1.2</version>
<interface>
<name>ICryptoFactory</name>
<regex-instance>.*</regex-instance>
diff --git a/current.txt b/current.txt
index 8b10648..e19fb63 100644
--- a/current.txt
+++ b/current.txt
@@ -388,8 +388,10 @@
2a55e224aa9bc62c0387cd85ad3c97e33f0c33a4e1489cbae86b2523e6f9df35 android.hardware.camera.device@3.2::ICameraDevice
f61b616732d8f374e030f90575d7eba3ecc99d209a05b945949ba892bcb81e1d android.hardware.camera.device@3.2::ICameraDeviceSession
684702a60deef03a1e8093961dc0a18c555c857ad5a77ba7340b0635ae01eb70 android.hardware.camera.device@3.4::ICameraDeviceSession
+291638a1b6d4e63283e9e722ab5049d9351717ffa2b66162124f84d1aa7c2835 android.hardware.camera.metadata@3.2::types
dd2436f251a90f3e5e7ed773b1aeae21e381b00ae26b10ebe3a1001c894e5980 android.hardware.camera.metadata@3.3::types
da33234403ff5d60f3473711917b9948e6484a4260b5247acdafb111193a9de2 android.hardware.configstore@1.0::ISurfaceFlingerConfigs
+21165b8e30c4b2d52980e4728f661420adc16e38bbe73476c06b2085be908f4c android.hardware.gnss@1.0::IGnssCallback
d702fb01dc2a0733aa820b7eb65435ee3334f75632ef880bafd2fb8803a20a58 android.hardware.gnss@1.0::IGnssMeasurementCallback
b7ecf29927055ec422ec44bf776223f07d79ad9f92ccf9becf167e62c2607e7a android.hardware.keymaster@4.0::IKeymasterDevice
574e8f1499436fb4075894dcae0b36682427956ecb114f17f1fe22d116a83c6b android.hardware.neuralnetworks@1.0::IPreparedModel
diff --git a/drm/1.2/Android.bp b/drm/1.2/Android.bp
new file mode 100644
index 0000000..66a1bd8
--- /dev/null
+++ b/drm/1.2/Android.bp
@@ -0,0 +1,26 @@
+// This file is autogenerated by hidl-gen -Landroidbp.
+
+hidl_interface {
+ name: "android.hardware.drm@1.2",
+ root: "android.hardware",
+ vndk: {
+ enabled: true,
+ },
+ srcs: [
+ "types.hal",
+ "ICryptoFactory.hal",
+ "IDrmFactory.hal",
+ "IDrmPlugin.hal",
+ ],
+ interfaces: [
+ "android.hardware.drm@1.0",
+ "android.hardware.drm@1.1",
+ "android.hidl.base@1.0",
+ ],
+ types: [
+ "KeySetId",
+ "OfflineLicenseState",
+ ],
+ gen_java: false,
+}
+
diff --git a/drm/1.2/ICryptoFactory.hal b/drm/1.2/ICryptoFactory.hal
new file mode 100644
index 0000000..c4a9b4b
--- /dev/null
+++ b/drm/1.2/ICryptoFactory.hal
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2018 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.drm@1.2;
+
+import @1.1::ICryptoFactory;
+
+/**
+ * ICryptoFactory is the main entry point for interacting with a vendor's
+ * crypto HAL to create crypto plugins. Crypto plugins create crypto sessions
+ * which are used by a codec to decrypt protected video content.
+ *
+ * The 1.2 factory must always create 1.2 ICryptoPlugin interfaces, which are
+ * returned via the 1.0 createPlugin method.
+ *
+ * To use 1.2 features the caller must cast the returned interface to a
+ * 1.2 HAL, using V1_2::IDrmPlugin::castFrom().
+ *
+ * The ICryptoFactory hal is required because all top-level interfaces
+ * have to be updated in a minor uprev.
+ */
+interface ICryptoFactory extends @1.1::ICryptoFactory {
+};
diff --git a/drm/1.2/IDrmFactory.hal b/drm/1.2/IDrmFactory.hal
new file mode 100644
index 0000000..c94e4bb
--- /dev/null
+++ b/drm/1.2/IDrmFactory.hal
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2018 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.drm@1.2;
+
+import @1.1::IDrmFactory;
+import @1.1::IDrmPlugin;
+
+/**
+ * IDrmFactory is the main entry point for interacting with a vendor's
+ * drm HAL to create drm plugin instances. A drm plugin instance
+ * creates drm sessions which are used to obtain keys for a crypto
+ * session so it can decrypt protected video content.
+ *
+ * The 1.2 factory must always create 1.2 IDrmPlugin interfaces, which are
+ * returned via the 1.0 createPlugin method.
+ *
+ * To use 1.2 features the caller must cast the returned interface to a
+ * 1.2 HAL, using V1_2::IDrmPlugin::castFrom().
+ *
+ * The IDrmFactory hal is required because all top-level interfaces
+ * have to be updated in a minor uprev.
+ */
+
+interface IDrmFactory extends @1.1::IDrmFactory {
+};
diff --git a/drm/1.2/IDrmPlugin.hal b/drm/1.2/IDrmPlugin.hal
new file mode 100644
index 0000000..88338d6
--- /dev/null
+++ b/drm/1.2/IDrmPlugin.hal
@@ -0,0 +1,94 @@
+/**
+ * Copyright (C) 2018 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.drm@1.2;
+
+import @1.1::IDrmPlugin;
+import @1.0::Status;
+
+/**
+ * IDrmPlugin is used to interact with a specific drm plugin that was created by
+ * IDrm::createPlugin. A drm plugin provides methods for obtaining drm keys that
+ * may be used by a codec to decrypt protected video content.
+ */
+interface IDrmPlugin extends @1.1::IDrmPlugin {
+
+ /**
+ * The keys in an offline license allow protected content to be
+ * played even if the device is not connected to a network.
+ * Offline licenses are stored on the device after a key
+ * request/response exchange when the key request KeyType is
+ * OFFLINE. Normally each app is responsible for keeping track of
+ * the KeySetIds it has created. In some situations however, it
+ * may be necessary to request the list of stored offline license
+ * KeySetIds. If an app loses the KeySetId for any stored licenses
+ * that it created, for example, it must be able to recover the
+ * stored KeySetIds so those licenses can be removed when they
+ * expire or when the app is uninstalled.
+ * <p>
+ * This method returns a list of the KeySetIds for all offline
+ * licenses. The offline license KeySetId may be used to query
+ * the status of an offline license or remove it.
+ *
+ * @return status the status of the call. May be OK or
+ * ERROR_DRM_INVALID_STATE if the HAL is in a state where the
+ * KeySetIds can't be returned.
+ * @return a list of offline license keySetIds. If there are no offline
+ * licenses, the list must be empty and OK must be returned as the
+ * status.
+ */
+ getOfflineLicenseKeySetIds() generates (Status status, vec<KeySetId> keySetIds);
+
+ /**
+ * Normally offline licenses are released using a key
+ * request/response exchange using getKeyRequest where the KeyType
+ * is RELEASE, followed by provideKeyResponse. This allows the
+ * server to cryptographically confirm that the license has been
+ * removed and then adjust the count of offline licenses allocated
+ * to the device.
+ * <p>
+ * In some exceptional situations it may be necessary to directly
+ * remove offline licenses without notifying the server, which may
+ * be performed using this method.
+ *
+ * @param keySetId the id of the offline license to remove
+ * @return status the status of the call. May be one of OK on
+ * success, BAD_VALUE if the license is not found or
+ * ERROR_DRM_INVALID_STATE if the HAL is in a state where the
+ * KeySetIds can't be returned.
+ */
+ removeOfflineLicense(KeySetId keySetId) generates (Status status);
+
+ /**
+ * Request the state of an offline license. An offline license may
+ * be usable or inactive. The keys in a usable offline license are
+ * available for decryption. When the offline license state is
+ * inactive, the keys have been marked for release using
+ * getKeyRequest with KeyType RELEASE but the key response has not
+ * been received. The keys in an inactive offline license are not
+ * usable for decryption.
+ *
+ * @param keySetId the id of the offline license
+ * @return status the status of the call. May be one of OK on
+ * success, BAD_VALUE if the license is not found or
+ * ERROR_DRM_INVALID_STATE if the HAL is in a state where the
+ * offline license state can't be queried.
+ * @return the offline license state, one of USABLE or INACTIVE.
+ * If the return status is not OK then state must be set to
+ * UNKNOWN.
+ */
+ getOfflineLicenseState(KeySetId keySetId) generates (Status status,
+ OfflineLicenseState state);
+};
diff --git a/drm/1.2/types.hal b/drm/1.2/types.hal
new file mode 100644
index 0000000..8770c79
--- /dev/null
+++ b/drm/1.2/types.hal
@@ -0,0 +1,45 @@
+/**
+ * Copyright (C) 2018 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.drm@1.2;
+
+enum OfflineLicenseState : uint32_t {
+ /**
+ * Offline license state is unknown
+ */
+ UNKNOWN,
+
+ /**
+ * Offline license state is usable, the keys may be used for decryption.
+ */
+ USABLE,
+
+ /**
+ * Offline license state is inactive, the keys have been marked for
+ * release using {@link #getKeyRequest} with KEY_TYPE_RELEASE but the
+ * key response has not been received.
+ */
+ INACTIVE
+};
+
+/**
+ * KeySetId is an identifier that references a set of keys in an
+ * offline license. The keySetId is created by the HAL implementation
+ * and returned from provideKeyResponse and getOfflineLicenseIds. The
+ * framework passes KeySetId back to the HAL when referring to the key
+ * set in methods that take a KeySetId as an input parameter.
+ */
+typedef vec<uint8_t> KeySetId;
diff --git a/gnss/1.0/IGnssCallback.hal b/gnss/1.0/IGnssCallback.hal
index 7fb38c5..d62676f 100644
--- a/gnss/1.0/IGnssCallback.hal
+++ b/gnss/1.0/IGnssCallback.hal
@@ -115,9 +115,9 @@
/**
* Carrier frequency of the signal tracked, for example it can be the
* GPS central frequency for L1 = 1575.45 MHz, or L2 = 1227.60 MHz, L5 =
- * 1176.45 MHz, varying GLO channels, etc. If the field is not set, it
- * is the primary common use central frequency, e.g. L1 = 1575.45 MHz
- * for GPS.
+ * 1176.45 MHz, varying GLO channels, etc. If the field is zero, it is
+ * the primary common use central frequency, e.g. L1 = 1575.45 MHz for
+ * GPS.
*
* For an L1, L5 receiver tracking a satellite on L1 and L5 at the same
* time, two GnssSvInfo structs must be reported for this same
@@ -125,8 +125,7 @@
* to L1 must be filled, and in the other all of the values related to
* L5 must be filled.
*
- * If the data is available, gnssClockFlags must contain
- * HAS_CARRIER_FREQUENCY.
+ * If the data is available, svFlag must contain HAS_CARRIER_FREQUENCY.
*/
float carrierFrequencyHz;
diff --git a/keymaster/3.0/vts/functional/authorization_set.h b/keymaster/3.0/vts/functional/authorization_set.h
index 5f92d81..60b00e4 100644
--- a/keymaster/3.0/vts/functional/authorization_set.h
+++ b/keymaster/3.0/vts/functional/authorization_set.h
@@ -201,7 +201,7 @@
void push_back(TypedTag<TagType::BYTES, tag> ttag, const uint8_t* data, size_t data_length) {
hidl_vec<uint8_t> new_blob;
new_blob.setToExternal(const_cast<uint8_t*>(data), data_length);
- push_back(ttag, std::move(new_blob));
+ push_back(ttag, new_blob);
}
/**
@@ -225,8 +225,7 @@
}
hidl_vec<KeyParameter> hidl_data() const {
- hidl_vec<KeyParameter> result;
- result.setToExternal(const_cast<KeyParameter*>(data()), size());
+ hidl_vec<KeyParameter> result(begin(), end());
return result;
}
@@ -252,7 +251,7 @@
size_t data_length) {
hidl_vec<uint8_t> new_blob;
new_blob.setToExternal(const_cast<uint8_t*>(data), data_length);
- push_back(ttag, std::move(new_blob));
+ push_back(ttag, new_blob);
return *this;
}
diff --git a/keymaster/4.0/support/authorization_set.cpp b/keymaster/4.0/support/authorization_set.cpp
index 10d272a..d6b50f5 100644
--- a/keymaster/4.0/support/authorization_set.cpp
+++ b/keymaster/4.0/support/authorization_set.cpp
@@ -203,6 +203,7 @@
struct OutStreams {
std::ostream& indirect;
std::ostream& elements;
+ size_t skipped;
};
OutStreams& serializeParamValue(OutStreams& out, const hidl_vec<uint8_t>& blob) {
@@ -241,6 +242,7 @@
OutStreams& serialize(TAG_INVALID_t&&, OutStreams& out, const KeyParameter&) {
// skip invalid entries.
+ ++out.skipped;
return out;
}
template <typename T>
@@ -261,9 +263,9 @@
template <>
struct choose_serializer<> {
static OutStreams& serialize(OutStreams& out, const KeyParameter& param) {
- LOG(FATAL) << "Trying to serialize unknown tag " << unsigned(param.tag)
- << ". Did you forget to add it to all_tags_t?";
- abort();
+ LOG(WARNING) << "Trying to serialize unknown tag " << unsigned(param.tag)
+ << ". Did you forget to add it to all_tags_t?";
+ ++out.skipped;
return out;
}
};
@@ -286,7 +288,7 @@
std::ostream& serialize(std::ostream& out, const std::vector<KeyParameter>& params) {
std::stringstream indirect;
std::stringstream elements;
- OutStreams streams = {indirect, elements};
+ OutStreams streams = {indirect, elements, 0};
for (const auto& param : params) {
serialize(streams, param);
}
@@ -306,7 +308,7 @@
return out;
}
uint32_t elements_size = pos;
- uint32_t element_count = params.size();
+ uint32_t element_count = params.size() - streams.skipped;
out.write(reinterpret_cast<const char*>(&indirect_size), sizeof(uint32_t));
@@ -327,6 +329,7 @@
struct InStreams {
std::istream& indirect;
std::istream& elements;
+ size_t invalids;
};
InStreams& deserializeParamValue(InStreams& in, hidl_vec<uint8_t>* blob) {
@@ -348,6 +351,7 @@
InStreams& deserialize(TAG_INVALID_t&&, InStreams& in, KeyParameter*) {
// there should be no invalid KeyParamaters but if handle them as zero sized.
+ ++in.invalids;
return in;
}
@@ -415,13 +419,28 @@
// TODO write one-shot stream buffer to avoid copying here
std::stringstream indirect(indirect_buffer);
std::stringstream elements(elements_buffer);
- InStreams streams = {indirect, elements};
+ InStreams streams = {indirect, elements, 0};
params->resize(element_count);
for (uint32_t i = 0; i < element_count; ++i) {
deserialize(streams, &(*params)[i]);
}
+
+ /*
+ * There are legacy blobs which have invalid tags in them due to a bug during serialization.
+ * This makes sure that invalid tags are filtered from the result before it is returned.
+ */
+ if (streams.invalids > 0) {
+ std::vector<KeyParameter> filtered(element_count - streams.invalids);
+ auto ifiltered = filtered.begin();
+ for (auto& p : *params) {
+ if (p.tag != Tag::INVALID) {
+ *ifiltered++ = std::move(p);
+ }
+ }
+ *params = std::move(filtered);
+ }
return in;
}
diff --git a/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h b/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h
index ac96c86..a131423 100644
--- a/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h
+++ b/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h
@@ -214,9 +214,8 @@
}
}
- const hidl_vec<KeyParameter> hidl_data() const {
- hidl_vec<KeyParameter> result;
- result.setToExternal(const_cast<KeyParameter*>(data()), size());
+ hidl_vec<KeyParameter> hidl_data() const {
+ hidl_vec<KeyParameter> result(begin(), end());
return result;
}
@@ -242,7 +241,7 @@
size_t data_length) {
hidl_vec<uint8_t> new_blob;
new_blob.setToExternal(const_cast<uint8_t*>(data), data_length);
- push_back(ttag, std::move(new_blob));
+ push_back(ttag, new_blob);
return *this;
}
diff --git a/keymaster/4.0/support/include/keymasterV4_0/keymaster_utils.h b/keymaster/4.0/support/include/keymasterV4_0/keymaster_utils.h
index 90a0f1b..5e5ae8d 100644
--- a/keymaster/4.0/support/include/keymasterV4_0/keymaster_utils.h
+++ b/keymaster/4.0/support/include/keymasterV4_0/keymaster_utils.h
@@ -33,25 +33,19 @@
namespace support {
-inline static hidl_vec<uint8_t> blob2hidlVec(const uint8_t* data, const size_t length,
- bool inPlace = true) {
- hidl_vec<uint8_t> result;
- result.setToExternal(const_cast<unsigned char*>(data), length, !inPlace);
+inline static hidl_vec<uint8_t> blob2hidlVec(const uint8_t* data, const size_t length) {
+ hidl_vec<uint8_t> result(data, data + length);
return result;
}
-inline static hidl_vec<uint8_t> blob2hidlVec(const std::string& value, bool inPlace = true) {
- hidl_vec<uint8_t> result;
- result.setToExternal(const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(value.data())),
- static_cast<size_t>(value.size()), !inPlace);
+inline static hidl_vec<uint8_t> blob2hidlVec(const std::string& value) {
+ hidl_vec<uint8_t> result(reinterpret_cast<const uint8_t*>(value.data()),
+ reinterpret_cast<const uint8_t*>(value.data()) + value.size());
return result;
}
-inline static hidl_vec<uint8_t> blob2hidlVec(const std::vector<uint8_t>& blob,
- bool inPlace = true) {
- hidl_vec<uint8_t> result;
- result.setToExternal(const_cast<uint8_t*>(blob.data()), static_cast<size_t>(blob.size()),
- !inPlace);
+inline static hidl_vec<uint8_t> blob2hidlVec(const std::vector<uint8_t>& blob) {
+ hidl_vec<uint8_t> result(blob.data(), blob.data() + static_cast<size_t>(blob.size()));
return result;
}
diff --git a/media/c2/1.0/Android.bp b/media/c2/1.0/Android.bp
index 3c99b6a..28829d2 100644
--- a/media/c2/1.0/Android.bp
+++ b/media/c2/1.0/Android.bp
@@ -17,11 +17,9 @@
"IInputSurfaceConnection.hal",
],
interfaces: [
- "android.hardware.graphics.bufferqueue@2.0",
+ "android.hardware.graphics.bufferqueue@1.0",
"android.hardware.graphics.common@1.0",
- "android.hardware.graphics.common@1.1",
- "android.hardware.graphics.common@1.2",
- "android.hardware.media.bufferpool@2.0",
+ "android.hardware.media.bufferpool@1.0",
"android.hardware.media.omx@1.0",
"android.hardware.media@1.0",
"android.hidl.base@1.0",
diff --git a/media/c2/1.0/IComponent.hal b/media/c2/1.0/IComponent.hal
index 822b24e..7fd551f 100644
--- a/media/c2/1.0/IComponent.hal
+++ b/media/c2/1.0/IComponent.hal
@@ -16,7 +16,7 @@
package android.hardware.media.c2@1.0;
-import android.hardware.graphics.bufferqueue@2.0::IGraphicBufferProducer;
+import android.hardware.graphics.bufferqueue@1.0::IGraphicBufferProducer;
import android.hardware.media.omx@1.0::IGraphicBufferSource;
import IConfigurable;
diff --git a/media/c2/1.0/IComponentStore.hal b/media/c2/1.0/IComponentStore.hal
index 6a57c38..a027afe 100644
--- a/media/c2/1.0/IComponentStore.hal
+++ b/media/c2/1.0/IComponentStore.hal
@@ -16,7 +16,7 @@
package android.hardware.media.c2@1.0;
-import android.hardware.media.bufferpool@2.0::IClientManager;
+import android.hardware.media.bufferpool@1.0::IClientManager;
import IComponentInterface;
import IComponentListener;
import IComponent;
diff --git a/media/c2/1.0/IInputSurface.hal b/media/c2/1.0/IInputSurface.hal
index 0a1b56d..25c6c8e 100644
--- a/media/c2/1.0/IInputSurface.hal
+++ b/media/c2/1.0/IInputSurface.hal
@@ -16,7 +16,7 @@
package android.hardware.media.c2@1.0;
-import android.hardware.graphics.bufferqueue@2.0::IGraphicBufferProducer;
+import android.hardware.graphics.bufferqueue@1.0::IGraphicBufferProducer;
import IConfigurable;
diff --git a/media/c2/1.0/types.hal b/media/c2/1.0/types.hal
index 7b75041..13269d2 100644
--- a/media/c2/1.0/types.hal
+++ b/media/c2/1.0/types.hal
@@ -16,7 +16,7 @@
package android.hardware.media.c2@1.0;
-import android.hardware.media.bufferpool@2.0::BufferStatusMessage;
+import android.hardware.media.bufferpool@1.0::BufferStatusMessage;
/**
* Common return values for Codec2 operations.
diff --git a/neuralnetworks/1.2/types.hal b/neuralnetworks/1.2/types.hal
index 4a1e7a8..366e626 100644
--- a/neuralnetworks/1.2/types.hal
+++ b/neuralnetworks/1.2/types.hal
@@ -47,6 +47,18 @@
};
/**
+ * The range of values in the OperandType enum.
+ *
+ * THE MAX VALUES MUST BE UPDATED WHEN ADDING NEW TYPES to the OperandType enum.
+ */
+enum OperandTypeRange : uint32_t {
+ OPERAND_FUNDAMENTAL_MIN = 0,
+ OPERAND_FUNDAMENTAL_MAX = 8,
+ OPERAND_OEM_MIN = 10000,
+ OPERAND_OEM_MAX = 10001,
+};
+
+/**
* Operation types.
*
* The type of an operation in a model.
@@ -103,6 +115,20 @@
UNIDIRECTIONAL_SEQUENCE_LSTM = 85,
UNIDIRECTIONAL_SEQUENCE_RNN = 86,
ROTATED_BBOX_TRANSFORM = 87,
+ ABS = 88,
+ ROI_POOLING = 89,
+};
+
+/**
+ * The range of values in the OperationType enum.
+ *
+ * THE MAX VALUES MUST BE UPDATED WHEN ADDING NEW TYPES to the OperationType enum.
+ */
+enum OperationTypeRange : uint32_t {
+ OPERATION_FUNDAMENTAL_MIN = 0,
+ OPERATION_FUNDAMENTAL_MAX = 87,
+ OPERATION_OEM_MIN = 10000,
+ OPERATION_OEM_MAX = 10000,
};
/**
diff --git a/neuralnetworks/1.2/vts/functional/ValidateModel.cpp b/neuralnetworks/1.2/vts/functional/ValidateModel.cpp
index c1c6e55..e309642 100644
--- a/neuralnetworks/1.2/vts/functional/ValidateModel.cpp
+++ b/neuralnetworks/1.2/vts/functional/ValidateModel.cpp
@@ -128,16 +128,16 @@
///////////////////////// VALIDATE MODEL OPERAND TYPE /////////////////////////
-static const int32_t invalidOperandTypes[] = {
- static_cast<int32_t>(OperandType::FLOAT32) - 1, // lower bound fundamental
- static_cast<int32_t>(OperandType::TENSOR_QUANT16_ASYMM) + 1, // upper bound fundamental
- static_cast<int32_t>(OperandType::OEM) - 1, // lower bound OEM
- static_cast<int32_t>(OperandType::TENSOR_OEM_BYTE) + 1, // upper bound OEM
+static const uint32_t invalidOperandTypes[] = {
+ static_cast<uint32_t>(OperandTypeRange::OPERAND_FUNDAMENTAL_MIN) - 1,
+ static_cast<uint32_t>(OperandTypeRange::OPERAND_FUNDAMENTAL_MAX) + 1,
+ static_cast<uint32_t>(OperandTypeRange::OPERAND_OEM_MIN) - 1,
+ static_cast<uint32_t>(OperandTypeRange::OPERAND_OEM_MAX) + 1,
};
static void mutateOperandTypeTest(const sp<IDevice>& device, const Model& model) {
for (size_t operand = 0; operand < model.operands.size(); ++operand) {
- for (int32_t invalidOperandType : invalidOperandTypes) {
+ for (uint32_t invalidOperandType : invalidOperandTypes) {
const std::string message = "mutateOperandTypeTest: operand " +
std::to_string(operand) + " set to value " +
std::to_string(invalidOperandType);
@@ -224,8 +224,9 @@
case OperandType::TENSOR_INT32:
return {1};
case OperandType::TENSOR_QUANT8_ASYMM:
- case OperandType::TENSOR_QUANT16_ASYMM:
return {-1, 256};
+ case OperandType::TENSOR_QUANT16_ASYMM:
+ return {-32769, 32768};
default:
return {};
}
@@ -291,15 +292,33 @@
*operand = newOperand;
}
-static bool mutateOperationOperandTypeSkip(size_t operand, const Model& model) {
- // LSH_PROJECTION's second argument is allowed to have any type. This is the
- // only operation that currently has a type that can be anything independent
- // from any other type. Changing the operand type to any other type will
- // result in a valid model for LSH_PROJECTION. If this is the case, skip the
- // test.
+static bool mutateOperationOperandTypeSkip(size_t operand, OperandType type, const Model& model) {
+ // Do not test OEM types
+ if (type == model.operands[operand].type || type == OperandType::OEM ||
+ type == OperandType::TENSOR_OEM_BYTE) {
+ return true;
+ }
for (const Operation& operation : model.operations) {
- if (operation.type == OperationType::LSH_PROJECTION && operand == operation.inputs[1]) {
- return true;
+ // Skip mutateOperationOperandTypeTest for the following operations.
+ // - LSH_PROJECTION's second argument is allowed to have any type.
+ // - ARGMIN and ARGMAX's first argument can be any of TENSOR_(FLOAT32|INT32|QUANT8_ASYMM).
+ // - CAST's argument can be any of TENSOR_(FLOAT32|INT32|QUANT8_ASYMM).
+ switch (operation.type) {
+ case OperationType::LSH_PROJECTION: {
+ if (operand == operation.inputs[1]) {
+ return true;
+ }
+ } break;
+ case OperationType::CAST:
+ case OperationType::ARGMAX:
+ case OperationType::ARGMIN: {
+ if (type == OperandType::TENSOR_FLOAT32 || type == OperandType::TENSOR_INT32 ||
+ type == OperandType::TENSOR_QUANT8_ASYMM) {
+ return true;
+ }
+ } break;
+ default:
+ break;
}
}
return false;
@@ -307,14 +326,8 @@
static void mutateOperationOperandTypeTest(const sp<IDevice>& device, const Model& model) {
for (size_t operand = 0; operand < model.operands.size(); ++operand) {
- if (mutateOperationOperandTypeSkip(operand, model)) {
- continue;
- }
for (OperandType invalidOperandType : hidl_enum_range<OperandType>{}) {
- // Do not test OEM types
- if (invalidOperandType == model.operands[operand].type ||
- invalidOperandType == OperandType::OEM ||
- invalidOperandType == OperandType::TENSOR_OEM_BYTE) {
+ if (mutateOperationOperandTypeSkip(operand, invalidOperandType, model)) {
continue;
}
const std::string message = "mutateOperationOperandTypeTest: operand " +
@@ -329,16 +342,16 @@
///////////////////////// VALIDATE MODEL OPERATION TYPE /////////////////////////
-static const int32_t invalidOperationTypes[] = {
- static_cast<int32_t>(OperationType::ADD) - 1, // lower bound fundamental
- static_cast<int32_t>(OperationType::TRANSPOSE) + 1, // upper bound fundamental
- static_cast<int32_t>(OperationType::OEM_OPERATION) - 1, // lower bound OEM
- static_cast<int32_t>(OperationType::OEM_OPERATION) + 1, // upper bound OEM
+static const uint32_t invalidOperationTypes[] = {
+ static_cast<uint32_t>(OperationTypeRange::OPERATION_FUNDAMENTAL_MIN) - 1,
+ static_cast<uint32_t>(OperationTypeRange::OPERATION_FUNDAMENTAL_MAX) + 1,
+ static_cast<uint32_t>(OperationTypeRange::OPERATION_OEM_MIN) - 1,
+ static_cast<uint32_t>(OperationTypeRange::OPERATION_OEM_MAX) + 1,
};
static void mutateOperationTypeTest(const sp<IDevice>& device, const Model& model) {
for (size_t operation = 0; operation < model.operations.size(); ++operation) {
- for (int32_t invalidOperationType : invalidOperationTypes) {
+ for (uint32_t invalidOperationType : invalidOperationTypes) {
const std::string message = "mutateOperationTypeTest: operation " +
std::to_string(operation) + " set to value " +
std::to_string(invalidOperationType);
@@ -406,8 +419,26 @@
removeValueAndDecrementGreaterValues(&model->outputIndexes, index);
}
+static bool removeOperandSkip(size_t operand, const Model& model) {
+ for (const Operation& operation : model.operations) {
+ // Skip removeOperandTest for the following operations.
+ // - SPLIT's outputs are not checked during prepareModel.
+ if (operation.type == OperationType::SPLIT) {
+ for (const size_t outOprand : operation.outputs) {
+ if (operand == outOprand) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
static void removeOperandTest(const sp<IDevice>& device, const Model& model) {
for (size_t operand = 0; operand < model.operands.size(); ++operand) {
+ if (removeOperandSkip(operand, model)) {
+ continue;
+ }
const std::string message = "removeOperandTest: operand " + std::to_string(operand);
validate(device, message, model,
[operand](Model* model) { removeOperand(model, operand); });
@@ -433,15 +464,76 @@
///////////////////////// REMOVE OPERATION INPUT /////////////////////////
+static bool removeOperationInputSkip(const Operation& op, size_t input) {
+ // Skip removeOperationInputTest for the following operations.
+ // - CONCATENATION has at least 2 inputs, with the last element being INT32.
+ // - CONV_2D, DEPTHWISE_CONV_2D, MAX_POOL_2D, AVERAGE_POOL_2D, L2_POOL_2D, RESIZE_BILINEAR,
+ // SPACE_TO_DEPTH, SPACE_TO_DEPTH, SPACE_TO_BATCH_ND, BATCH_TO_SPACE_ND can have an optional
+ // layout parameter.
+ // - L2_NORMALIZATION, LOCAL_RESPONSE_NORMALIZATION, SOFTMAX can have an optional axis
+ // parameter.
+ switch (op.type) {
+ case OperationType::CONCATENATION: {
+ if (op.inputs.size() > 2 && input != op.inputs.size() - 1) {
+ return true;
+ }
+ } break;
+ case OperationType::DEPTHWISE_CONV_2D: {
+ if ((op.inputs.size() == 12 && input == 11) || (op.inputs.size() == 9 && input == 8)) {
+ return true;
+ }
+ } break;
+ case OperationType::CONV_2D:
+ case OperationType::AVERAGE_POOL_2D:
+ case OperationType::MAX_POOL_2D:
+ case OperationType::L2_POOL_2D: {
+ if ((op.inputs.size() == 11 && input == 10) || (op.inputs.size() == 8 && input == 7)) {
+ return true;
+ }
+ } break;
+ case OperationType::RESIZE_BILINEAR: {
+ if (op.inputs.size() == 4 && input == 3) {
+ return true;
+ }
+ } break;
+ case OperationType::SPACE_TO_DEPTH:
+ case OperationType::DEPTH_TO_SPACE:
+ case OperationType::BATCH_TO_SPACE_ND: {
+ if (op.inputs.size() == 3 && input == 2) {
+ return true;
+ }
+ } break;
+ case OperationType::SPACE_TO_BATCH_ND: {
+ if (op.inputs.size() == 4 && input == 3) {
+ return true;
+ }
+ } break;
+ case OperationType::L2_NORMALIZATION: {
+ if (op.inputs.size() == 2 && input == 1) {
+ return true;
+ }
+ } break;
+ case OperationType::LOCAL_RESPONSE_NORMALIZATION: {
+ if (op.inputs.size() == 6 && input == 5) {
+ return true;
+ }
+ } break;
+ case OperationType::SOFTMAX: {
+ if (op.inputs.size() == 3 && input == 2) {
+ return true;
+ }
+ } break;
+ default:
+ break;
+ }
+ return false;
+}
+
static void removeOperationInputTest(const sp<IDevice>& device, const Model& model) {
for (size_t operation = 0; operation < model.operations.size(); ++operation) {
for (size_t input = 0; input < model.operations[operation].inputs.size(); ++input) {
const Operation& op = model.operations[operation];
- // CONCATENATION has at least 2 inputs, with the last element being
- // INT32. Skip this test if removing one of CONCATENATION's
- // inputs still produces a valid model.
- if (op.type == OperationType::CONCATENATION && op.inputs.size() > 2 &&
- input != op.inputs.size() - 1) {
+ if (removeOperationInputSkip(op, input)) {
continue;
}
const std::string message = "removeOperationInputTest: operation " +
@@ -479,12 +571,13 @@
///////////////////////// ADD OPERATION INPUT /////////////////////////
-static bool addOperationInputSkip(const Operation& operation) {
+static bool addOperationInputSkip(const Operation& op) {
// Skip addOperationInputTest for the following operations.
- // L2_NORMALIZATION, LOCAL_RESPONSE_NORMALIZATION, SOFTMAX can have an optional axis parameter.
- if (operation.type == OperationType::L2_NORMALIZATION ||
- operation.type == OperationType::LOCAL_RESPONSE_NORMALIZATION ||
- operation.type == OperationType::SOFTMAX) {
+ // - L2_NORMALIZATION, LOCAL_RESPONSE_NORMALIZATION, SOFTMAX can have an optional INT32 axis
+ // parameter.
+ if ((op.type == OperationType::L2_NORMALIZATION && op.inputs.size() == 1) ||
+ (op.type == OperationType::LOCAL_RESPONSE_NORMALIZATION && op.inputs.size() == 5) ||
+ (op.type == OperationType::SOFTMAX && op.inputs.size() == 2)) {
return true;
}
return false;
diff --git a/power/stats/1.0/default/Android.bp b/power/stats/1.0/default/Android.bp
new file mode 100644
index 0000000..04270c1
--- /dev/null
+++ b/power/stats/1.0/default/Android.bp
@@ -0,0 +1,34 @@
+// Copyright (C) 2018 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
+
+cc_library_shared {
+ name: "android.hardware.power.stats@1.0-service",
+ relative_install_path: "hw",
+ init_rc: ["android.hardware.power.stats@1.0-service.rc"],
+ srcs: ["service.cpp", "PowerStats.cpp"],
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+ shared_libs: [
+ "libbase",
+ "libcutils",
+ "libfmq",
+ "libhidlbase",
+ "libhidltransport",
+ "liblog",
+ "libutils",
+ "android.hardware.power.stats@1.0",
+ ],
+ vendor: true,
+}
diff --git a/power/stats/1.0/default/PowerStats.cpp b/power/stats/1.0/default/PowerStats.cpp
new file mode 100644
index 0000000..810c575
--- /dev/null
+++ b/power/stats/1.0/default/PowerStats.cpp
@@ -0,0 +1,317 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "PowerStats.h"
+#include <android-base/file.h>
+#include <android-base/logging.h>
+#include <android-base/properties.h>
+#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <algorithm>
+#include <exception>
+#include <thread>
+
+namespace android {
+namespace hardware {
+namespace power {
+namespace stats {
+namespace V1_0 {
+namespace implementation {
+
+#define MAX_FILE_PATH_LEN 128
+#define MAX_DEVICE_NAME_LEN 64
+#define MAX_QUEUE_SIZE 8192
+
+constexpr char kIioDirRoot[] = "/sys/bus/iio/devices/";
+constexpr char kDeviceName[] = "pm_device_name";
+constexpr char kDeviceType[] = "iio:device";
+constexpr uint32_t MAX_SAMPLING_RATE = 10;
+constexpr uint64_t WRITE_TIMEOUT_NS = 1000000000;
+
+void PowerStats::findIioPowerMonitorNodes() {
+ struct dirent* ent;
+ int fd;
+ char devName[MAX_DEVICE_NAME_LEN];
+ char filePath[MAX_FILE_PATH_LEN];
+ DIR* iioDir = opendir(kIioDirRoot);
+ if (!iioDir) {
+ ALOGE("Error opening directory: %s", kIioDirRoot);
+ return;
+ }
+ while (ent = readdir(iioDir), ent) {
+ if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0 &&
+ strlen(ent->d_name) > strlen(kDeviceType) &&
+ strncmp(ent->d_name, kDeviceType, strlen(kDeviceType)) == 0) {
+ snprintf(filePath, MAX_FILE_PATH_LEN, "%s/%s", ent->d_name, "name");
+ fd = openat(dirfd(iioDir), filePath, O_RDONLY);
+ if (fd < 0) {
+ ALOGW("Failed to open directory: %s", filePath);
+ continue;
+ }
+ if (read(fd, devName, MAX_DEVICE_NAME_LEN) < 0) {
+ ALOGW("Failed to read device name from file: %s(%d)", filePath, fd);
+ close(fd);
+ continue;
+ }
+
+ if (strncmp(devName, kDeviceName, strlen(kDeviceName)) == 0) {
+ snprintf(filePath, MAX_FILE_PATH_LEN, "%s/%s", kIioDirRoot, ent->d_name);
+ mPm.devicePaths.push_back(filePath);
+ }
+ close(fd);
+ }
+ }
+ closedir(iioDir);
+ return;
+}
+
+size_t PowerStats::parsePowerRails() {
+ std::string data;
+ std::string railFileName;
+ std::string spsFileName;
+ uint32_t index = 0;
+ uint32_t samplingRate;
+ for (const auto& path : mPm.devicePaths) {
+ railFileName = path + "/enabled_rails";
+ spsFileName = path + "/sampling_rate";
+ if (!android::base::ReadFileToString(spsFileName, &data)) {
+ ALOGW("Error reading file: %s", spsFileName.c_str());
+ continue;
+ }
+ samplingRate = strtoul(data.c_str(), NULL, 10);
+ if (!samplingRate || samplingRate == ULONG_MAX) {
+ ALOGE("Error parsing: %s", spsFileName.c_str());
+ break;
+ }
+ if (!android::base::ReadFileToString(railFileName, &data)) {
+ ALOGW("Error reading file: %s", railFileName.c_str());
+ continue;
+ }
+ std::istringstream railNames(data);
+ std::string line;
+ while (std::getline(railNames, line)) {
+ std::vector<std::string> words = android::base::Split(line, ":");
+ if (words.size() == 2) {
+ mPm.railsInfo.emplace(words[0], RailData{.devicePath = path,
+ .index = index,
+ .subsysName = words[1],
+ .samplingRate = samplingRate});
+ index++;
+ } else {
+ ALOGW("Unexpected format in file: %s", railFileName.c_str());
+ }
+ }
+ }
+ return index;
+}
+
+int PowerStats::parseIioEnergyNode(std::string devName) {
+ int ret = 0;
+ std::string data;
+ std::string fileName = devName + "/energy_value";
+ if (!android::base::ReadFileToString(fileName, &data)) {
+ ALOGE("Error reading file: %s", fileName.c_str());
+ return -1;
+ }
+
+ std::istringstream energyData(data);
+ std::string line;
+ uint64_t timestamp = 0;
+ bool timestampRead = false;
+ while (std::getline(energyData, line)) {
+ std::vector<std::string> words = android::base::Split(line, ",");
+ if (timestampRead == false) {
+ if (words.size() == 1) {
+ timestamp = strtoull(words[0].c_str(), NULL, 10);
+ if (timestamp == 0 || timestamp == ULLONG_MAX) {
+ ALOGW("Potentially wrong timestamp: %" PRIu64, timestamp);
+ }
+ timestampRead = true;
+ }
+ } else if (words.size() == 2) {
+ std::string railName = words[0];
+ if (mPm.railsInfo.count(railName) != 0) {
+ size_t index = mPm.railsInfo[railName].index;
+ mPm.reading[index].index = index;
+ mPm.reading[index].timestamp = timestamp;
+ mPm.reading[index].energy = strtoull(words[1].c_str(), NULL, 10);
+ if (mPm.reading[index].energy == ULLONG_MAX) {
+ ALOGW("Potentially wrong energy value: %" PRIu64, mPm.reading[index].energy);
+ }
+ }
+ } else {
+ ALOGW("Unexpected format in file: %s", fileName.c_str());
+ ret = -1;
+ break;
+ }
+ }
+ return ret;
+}
+
+Status PowerStats::parseIioEnergyNodes() {
+ Status ret = Status::SUCCESS;
+ if (mPm.hwEnabled == false) {
+ return Status::NOT_SUPPORTED;
+ }
+
+ for (const auto& devicePath : mPm.devicePaths) {
+ if (parseIioEnergyNode(devicePath) < 0) {
+ ALOGE("Error in parsing power stats");
+ ret = Status::FILESYSTEM_ERROR;
+ break;
+ }
+ }
+ return ret;
+}
+
+PowerStats::PowerStats() {
+ findIioPowerMonitorNodes();
+ size_t numRails = parsePowerRails();
+ if (mPm.devicePaths.empty() || numRails == 0) {
+ mPm.hwEnabled = false;
+ } else {
+ mPm.hwEnabled = true;
+ mPm.reading.resize(numRails);
+ }
+}
+
+Return<void> PowerStats::getRailInfo(getRailInfo_cb _hidl_cb) {
+ hidl_vec<RailInfo> rInfo;
+ Status ret = Status::SUCCESS;
+ size_t index;
+ std::lock_guard<std::mutex> _lock(mPm.mLock);
+ if (mPm.hwEnabled == false) {
+ _hidl_cb(rInfo, Status::NOT_SUPPORTED);
+ return Void();
+ }
+ rInfo.resize(mPm.railsInfo.size());
+ for (const auto& railData : mPm.railsInfo) {
+ index = railData.second.index;
+ rInfo[index].railName = railData.first;
+ rInfo[index].subsysName = railData.second.subsysName;
+ rInfo[index].index = index;
+ rInfo[index].samplingRate = railData.second.samplingRate;
+ }
+ _hidl_cb(rInfo, ret);
+ return Void();
+}
+
+Return<void> PowerStats::getEnergyData(const hidl_vec<uint32_t>& railIndices,
+ getEnergyData_cb _hidl_cb) {
+ hidl_vec<EnergyData> eVal;
+ std::lock_guard<std::mutex> _lock(mPm.mLock);
+ Status ret = parseIioEnergyNodes();
+
+ if (ret != Status::SUCCESS) {
+ ALOGE("Failed to getEnergyData");
+ _hidl_cb(eVal, ret);
+ return Void();
+ }
+
+ if (railIndices.size() == 0) {
+ eVal.resize(mPm.railsInfo.size());
+ memcpy(&eVal[0], &mPm.reading[0], mPm.reading.size() * sizeof(EnergyData));
+ } else {
+ eVal.resize(railIndices.size());
+ int i = 0;
+ for (const auto& railIndex : railIndices) {
+ if (railIndex >= mPm.reading.size()) {
+ ret = Status::INVALID_INPUT;
+ eVal.resize(0);
+ break;
+ }
+ memcpy(&eVal[i], &mPm.reading[railIndex], sizeof(EnergyData));
+ i++;
+ }
+ }
+ _hidl_cb(eVal, ret);
+ return Void();
+}
+
+Return<void> PowerStats::streamEnergyData(uint32_t timeMs, uint32_t samplingRate,
+ streamEnergyData_cb _hidl_cb) {
+ std::lock_guard<std::mutex> _lock(mPm.mLock);
+ if (mPm.fmqSynchronized != nullptr) {
+ _hidl_cb(MessageQueueSync::Descriptor(), 0, 0, Status::INSUFFICIENT_RESOURCES);
+ return Void();
+ }
+ uint32_t sps = std::min(samplingRate, MAX_SAMPLING_RATE);
+ uint32_t numSamples = timeMs * sps / 1000;
+ mPm.fmqSynchronized.reset(new (std::nothrow) MessageQueueSync(MAX_QUEUE_SIZE, true));
+ if (mPm.fmqSynchronized == nullptr || mPm.fmqSynchronized->isValid() == false) {
+ mPm.fmqSynchronized = nullptr;
+ _hidl_cb(MessageQueueSync::Descriptor(), 0, 0, Status::INSUFFICIENT_RESOURCES);
+ return Void();
+ }
+ std::thread pollThread = std::thread([this, sps, numSamples]() {
+ uint64_t sleepTimeUs = 1000000 / sps;
+ uint32_t currSamples = 0;
+ while (currSamples < numSamples) {
+ mPm.mLock.lock();
+ if (parseIioEnergyNodes() == Status::SUCCESS) {
+ mPm.fmqSynchronized->writeBlocking(&mPm.reading[0], mPm.reading.size(),
+ WRITE_TIMEOUT_NS);
+ mPm.mLock.unlock();
+ currSamples++;
+ if (usleep(sleepTimeUs) < 0) {
+ ALOGW("Sleep interrupted");
+ break;
+ }
+ } else {
+ mPm.mLock.unlock();
+ break;
+ }
+ }
+ mPm.mLock.lock();
+ mPm.fmqSynchronized = nullptr;
+ mPm.mLock.unlock();
+ return;
+ });
+ pollThread.detach();
+ _hidl_cb(*(mPm.fmqSynchronized)->getDesc(), numSamples, mPm.reading.size(), Status::SUCCESS);
+ return Void();
+}
+
+Return<void> PowerStats::getPowerEntityInfo(getPowerEntityInfo_cb _hidl_cb) {
+ hidl_vec<PowerEntityInfo> eInfo;
+ _hidl_cb(eInfo, Status::NOT_SUPPORTED);
+ return Void();
+}
+
+Return<void> PowerStats::getPowerEntityStateInfo(const hidl_vec<uint32_t>& powerEntityIds,
+ getPowerEntityStateInfo_cb _hidl_cb) {
+ (void)powerEntityIds;
+ hidl_vec<PowerEntityStateSpace> powerEntityStateSpaces;
+ _hidl_cb(powerEntityStateSpaces, Status::NOT_SUPPORTED);
+ return Void();
+}
+
+Return<void> PowerStats::getPowerEntityStateResidencyData(
+ const hidl_vec<uint32_t>& powerEntityIds, getPowerEntityStateResidencyData_cb _hidl_cb) {
+ (void)powerEntityIds;
+ hidl_vec<PowerEntityStateResidencyResult> results;
+ _hidl_cb(results, Status::NOT_SUPPORTED);
+ return Void();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace stats
+} // namespace power
+} // namespace hardware
+} // namespace android
diff --git a/power/stats/1.0/default/PowerStats.h b/power/stats/1.0/default/PowerStats.h
new file mode 100644
index 0000000..fb2c6a8
--- /dev/null
+++ b/power/stats/1.0/default/PowerStats.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H
+#define ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H
+
+#include <android/hardware/power/stats/1.0/IPowerStats.h>
+#include <fmq/MessageQueue.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace power {
+namespace stats {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::hidl_vec;
+using ::android::hardware::kSynchronizedReadWrite;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::power::stats::V1_0::EnergyData;
+using ::android::hardware::power::stats::V1_0::PowerEntityInfo;
+using ::android::hardware::power::stats::V1_0::PowerEntityStateInfo;
+using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyData;
+using ::android::hardware::power::stats::V1_0::PowerEntityStateResidencyResult;
+using ::android::hardware::power::stats::V1_0::PowerEntityStateSpace;
+using ::android::hardware::power::stats::V1_0::PowerEntityType;
+using ::android::hardware::power::stats::V1_0::RailInfo;
+using ::android::hardware::power::stats::V1_0::Status;
+
+typedef MessageQueue<EnergyData, kSynchronizedReadWrite> MessageQueueSync;
+struct RailData {
+ std::string devicePath;
+ uint32_t index;
+ std::string subsysName;
+ uint32_t samplingRate;
+};
+
+struct OnDeviceMmt {
+ std::mutex mLock;
+ bool hwEnabled;
+ std::vector<std::string> devicePaths;
+ std::map<std::string, RailData> railsInfo;
+ std::vector<EnergyData> reading;
+ std::unique_ptr<MessageQueueSync> fmqSynchronized;
+};
+
+struct PowerStats : public IPowerStats {
+ PowerStats();
+ // Methods from ::android::hardware::power::stats::V1_0::IPowerStats follow.
+ Return<void> getRailInfo(getRailInfo_cb _hidl_cb) override;
+ Return<void> getEnergyData(const hidl_vec<uint32_t>& railIndices,
+ getEnergyData_cb _hidl_cb) override;
+ Return<void> streamEnergyData(uint32_t timeMs, uint32_t samplingRate,
+ streamEnergyData_cb _hidl_cb) override;
+ Return<void> getPowerEntityInfo(getPowerEntityInfo_cb _hidl_cb) override;
+ Return<void> getPowerEntityStateInfo(const hidl_vec<uint32_t>& powerEntityIds,
+ getPowerEntityStateInfo_cb _hidl_cb) override;
+ Return<void> getPowerEntityStateResidencyData(
+ const hidl_vec<uint32_t>& powerEntityIds,
+ getPowerEntityStateResidencyData_cb _hidl_cb) override;
+
+ private:
+ OnDeviceMmt mPm;
+ void findIioPowerMonitorNodes();
+ size_t parsePowerRails();
+ int parseIioEnergyNode(std::string devName);
+ Status parseIioEnergyNodes();
+};
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace stats
+} // namespace power
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_POWERSTATS_V1_0_POWERSTATS_H
diff --git a/power/stats/1.0/default/android.hardware.power.stats@1.0-service.rc b/power/stats/1.0/default/android.hardware.power.stats@1.0-service.rc
new file mode 100644
index 0000000..d7e546b
--- /dev/null
+++ b/power/stats/1.0/default/android.hardware.power.stats@1.0-service.rc
@@ -0,0 +1,4 @@
+service vendor.power.stats-hal-1-0 /vendor/bin/hw/android.hardware.power.stats@1.0-service
+ class hal
+ user system
+ group system
diff --git a/power/stats/1.0/default/service.cpp b/power/stats/1.0/default/service.cpp
new file mode 100644
index 0000000..80649f5
--- /dev/null
+++ b/power/stats/1.0/default/service.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2018 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 "android.hardware.power.stats@1.0-service"
+
+#include <android/log.h>
+#include <hidl/HidlTransportSupport.h>
+
+#include "PowerStats.h"
+
+using android::OK;
+using android::sp;
+using android::status_t;
+
+// libhwbinder:
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
+
+// Generated HIDL files
+using android::hardware::power::stats::V1_0::IPowerStats;
+using android::hardware::power::stats::V1_0::implementation::PowerStats;
+
+int main(int /* argc */, char** /* argv */) {
+ ALOGI("power.stats service 1.0 is starting.");
+
+ android::sp<IPowerStats> service = new PowerStats();
+ if (service == nullptr) {
+ ALOGE("Can not create an instance of power.stats HAL Iface, exiting.");
+ return 1;
+ }
+
+ configureRpcThreadpool(1, true /*callerWillJoin*/);
+
+ status_t status = service->registerAsService();
+ if (status != OK) {
+ ALOGE("Could not register service for power.stats HAL Iface (%d), exiting.", status);
+ return 1;
+ }
+
+ ALOGI("power.stats service is ready");
+ joinRpcThreadpool();
+
+ // In normal operation, we don't expect the thread pool to exit
+ ALOGE("power.stats service is shutting down");
+ return 1;
+}
diff --git a/radio/1.3/Android.bp b/radio/1.3/Android.bp
index b6610e0..7012f6b 100644
--- a/radio/1.3/Android.bp
+++ b/radio/1.3/Android.bp
@@ -21,12 +21,17 @@
],
types: [
"AccessNetwork",
+ "CellConfigLte",
+ "CellInfo",
+ "CellInfoLte",
+ "CardStatus",
"DataProfileInfo",
"DataRegStateResult",
"EmergencyNumber",
"EmergencyNumberSource",
"EmergencyServiceCategory",
"LteVopsInfo",
+ "NetworkScanResult",
],
gen_java: true,
}
diff --git a/radio/1.3/IRadioIndication.hal b/radio/1.3/IRadioIndication.hal
index 509eef8..e7f26ac 100644
--- a/radio/1.3/IRadioIndication.hal
+++ b/radio/1.3/IRadioIndication.hal
@@ -49,4 +49,17 @@
*/
oneway currentEmergencyNumberList(RadioIndicationType type,
vec<EmergencyNumber> emergencyNumberList);
+
+ /**
+ * Request all of the current cell information known to the radio.
+ *
+ * @param type Type of radio indication
+ * @param records Current cell information
+ */
+ oneway cellInfoList_1_3(RadioIndicationType type, vec<CellInfo> records);
+
+ /**
+ * Incremental network scan results
+ */
+ oneway networkScanResult_1_3(RadioIndicationType type, NetworkScanResult result);
};
diff --git a/radio/1.3/IRadioResponse.hal b/radio/1.3/IRadioResponse.hal
index 10e7d63..fecd951 100644
--- a/radio/1.3/IRadioResponse.hal
+++ b/radio/1.3/IRadioResponse.hal
@@ -50,6 +50,17 @@
/**
* @param info Response info struct containing response type, serial no. and error
+ * @param cellInfo List of current cell information known to radio
+ *
+ * Valid errors returned:
+ * RadioError:NONE
+ * RadioError:RADIO_NOT_AVAILABLE
+ * RadioError:INTERNAL_ERR
+ */
+ oneway getCellInfoListResponse_1_3(RadioResponseInfo info, vec<CellInfo> cellInfo);
+
+ /**
+ * @param info Response info struct containing response type, serial no. and error
* @param dataRegResponse Current Data registration response as defined by DataRegStateResult in
* types.hal
*
@@ -61,4 +72,19 @@
*/
oneway getDataRegistrationStateResponse_1_3(RadioResponseInfo info,
DataRegStateResult dataRegResponse);
+
+ /**
+ * @param info Response info struct containing response type, serial no. and error
+ * @param cardStatus ICC card status as defined by CardStatus in types.hal
+ *
+ * Valid errors returned:
+ * RadioError:NONE
+ * RadioError:RADIO_NOT_AVAILABLE
+ * RadioError:INTERNAL_ERR
+ * RadioError:NO_MEMORY
+ * RadioError:NO_RESOURCES
+ * RadioError:CANCELLED
+ * RadioError:REQUEST_NOT_SUPPORTED
+ */
+ oneway getIccCardStatusResponse_1_3(RadioResponseInfo info, CardStatus cardStatus);
};
diff --git a/radio/1.3/types.hal b/radio/1.3/types.hal
index 8b0891c..d3a6f78 100644
--- a/radio/1.3/types.hal
+++ b/radio/1.3/types.hal
@@ -18,11 +18,22 @@
import @1.0::ApnAuthType;
import @1.0::ApnTypes;
+import @1.0::CellInfoType;
import @1.0::DataProfileId;
import @1.0::DataProfileInfoType;
import @1.0::RadioAccessFamily;
+import @1.0::RadioError;
import @1.0::RegState;
+import @1.0::TimeStampType;
+import @1.1::ScanStatus;
import @1.2::AccessNetwork;
+import @1.2::CellInfo;
+import @1.2::CellInfoCdma;
+import @1.2::CellInfoGsm;
+import @1.2::CellInfoLte;
+import @1.2::CellInfoTdscdma;
+import @1.2::CellInfoWcdma;
+import @1.2::CardStatus;
import @1.2::CellIdentity;
import @1.2::DataRegStateResult;
@@ -168,6 +179,78 @@
LteVopsInfo lteVopsInfo; // LTE network capability
} vopsInfo;
+
+ /**
+ * True if use of dual connectivity with NR is restricted.
+ * Reference: 3GPP TS 24.301 v15.03 section 9.3.3.12A.
+ */
+ bool isDcNrRestricted;
+
+ /**
+ * True if the bit N is in the PLMN-InfoList-r15 is true and the selected PLMN is present in
+ * plmn-IdentityList at position N.
+ * Reference: 3GPP TS 36.331 v15.2.2 section 6.3.1 PLMN-InfoList-r15.
+ * 3GPP TS 36.331 v15.2.2 section 6.2.2 SystemInformationBlockType1 message.
+ */
+ bool isNrAvailable;
+};
+
+/** Contains the configuration of the LTE cell tower. */
+struct CellConfigLte {
+ /**
+ * Indicates that if E-UTRA-NR Dual Connectivity (EN-DC) is supported by the LTE cell.
+ *
+ * True if the plmn-InfoList-r15 is present in SIB2 and at least one bit in this list is true,
+ * otherwise this value should be false.
+ *
+ * Reference: 3GPP TS 36.331 v15.2.2 6.3.1 System information blocks.
+ */
+ bool isEndcAvailable;
+};
+
+/** Inherits from @1.2::CellInfoLte, in order to add the LTE configuration. */
+struct CellInfoLte {
+ @1.2::CellInfoLte base;
+ CellConfigLte cellConfig;
+};
+
+/** Overwritten from @1.2::CellInfo in order to update the CellInfoLte to 1.3 version. */
+struct CellInfo {
+ /** Cell type for selecting from union CellInfo. */
+ CellInfoType cellInfoType;
+
+ /**
+ * True if the phone is registered to a mobile network that provides service on this cell and
+ * this cell is being used or would be used for network signaling.
+ */
+ bool isRegistered;
+
+ /** CellInfo details, cellInfoType can tell which cell info should be used. */
+ safe_union Info {
+ CellInfoGsm gsm;
+ CellInfoCdma cdma;
+ CellInfoWcdma wcdma;
+ CellInfoTdscdma tdscdma;
+ CellInfoLte lte;
+ } info;
+};
+
+/** Overwritten from @1.2::NetworkScanResult in order to update the CellInfo to 1.3 version. */
+struct NetworkScanResult {
+ /**
+ * The status of the scan.
+ */
+ ScanStatus status;
+
+ /**
+ * The error code of the incremental result.
+ */
+ RadioError error;
+
+ /**
+ * List of network information as CellInfo.
+ */
+ vec<CellInfo> networkInfos;
};
/**
@@ -243,3 +326,15 @@
*/
bool persistent;
};
+
+struct CardStatus {
+ @1.2::CardStatus base;
+ /**
+ * The EID is the eUICC identifier. The EID shall be stored within the ECASD and can be
+ * retrieved by the Device at any time using the standard GlobalPlatform GET DATA command.
+ *
+ * This data is mandatory and applicable only when cardState is CardState:PRESENT and SIM card
+ * supports eUICC.
+ */
+ string eid;
+};
diff --git a/sensors/2.0/default/Android.bp b/sensors/2.0/default/Android.bp
index 11612d3..db0b148 100644
--- a/sensors/2.0/default/Android.bp
+++ b/sensors/2.0/default/Android.bp
@@ -32,6 +32,7 @@
"libhidlbase",
"libhidltransport",
"liblog",
+ "libpower",
"libutils",
],
}
diff --git a/sensors/2.0/default/Sensor.cpp b/sensors/2.0/default/Sensor.cpp
index d3e3f7e..168b402 100644
--- a/sensors/2.0/default/Sensor.cpp
+++ b/sensors/2.0/default/Sensor.cpp
@@ -29,14 +29,20 @@
using ::android::hardware::sensors::V1_0::SensorStatus;
Sensor::Sensor(ISensorsEventCallback* callback)
- : mIsEnabled(false), mSamplingPeriodNs(0), mLastSampleTimeNs(0), mCallback(callback) {
+ : mIsEnabled(false),
+ mSamplingPeriodNs(0),
+ mLastSampleTimeNs(0),
+ mCallback(callback),
+ mMode(OperationMode::NORMAL) {
mRunThread = std::thread(startThread, this);
}
Sensor::~Sensor() {
+ std::unique_lock<std::mutex> lock(mRunMutex);
mStopThread = true;
mIsEnabled = false;
mWaitCV.notify_all();
+ lock.release();
mRunThread.join();
}
@@ -60,6 +66,7 @@
void Sensor::activate(bool enable) {
if (mIsEnabled != enable) {
+ std::unique_lock<std::mutex> lock(mRunMutex);
mIsEnabled = enable;
mWaitCV.notify_all();
}
@@ -79,7 +86,7 @@
ev.sensorType = SensorType::ADDITIONAL_INFO;
ev.u.meta.what = MetaDataEventType::META_DATA_FLUSH_COMPLETE;
std::vector<Event> evs{ev};
- mCallback->postEvents(evs);
+ mCallback->postEvents(evs, isWakeUpSensor());
return Result::OK;
}
@@ -89,13 +96,14 @@
}
void Sensor::run() {
- std::mutex runMutex;
- std::unique_lock<std::mutex> runLock(runMutex);
+ std::unique_lock<std::mutex> runLock(mRunMutex);
constexpr int64_t kNanosecondsInSeconds = 1000 * 1000 * 1000;
while (!mStopThread) {
- if (!mIsEnabled) {
- mWaitCV.wait(runLock, [&] { return mIsEnabled || mStopThread; });
+ if (!mIsEnabled || mMode == OperationMode::DATA_INJECTION) {
+ mWaitCV.wait(runLock, [&] {
+ return ((mIsEnabled && mMode == OperationMode::NORMAL) || mStopThread);
+ });
} else {
timespec curTime;
clock_gettime(CLOCK_REALTIME, &curTime);
@@ -105,7 +113,7 @@
if (now >= nextSampleTime) {
mLastSampleTimeNs = now;
nextSampleTime = mLastSampleTimeNs + mSamplingPeriodNs;
- mCallback->postEvents(readEvents());
+ mCallback->postEvents(readEvents(), isWakeUpSensor());
}
mWaitCV.wait_for(runLock, std::chrono::nanoseconds(nextSampleTime - now));
@@ -113,6 +121,10 @@
}
}
+bool Sensor::isWakeUpSensor() {
+ return mSensorInfo.flags & static_cast<uint32_t>(SensorFlagBits::WAKE_UP);
+}
+
std::vector<Event> Sensor::readEvents() {
std::vector<Event> events;
Event event;
@@ -127,6 +139,33 @@
return events;
}
+void Sensor::setOperationMode(OperationMode mode) {
+ if (mMode != mode) {
+ std::unique_lock<std::mutex> lock(mRunMutex);
+ mMode = mode;
+ mWaitCV.notify_all();
+ }
+}
+
+bool Sensor::supportsDataInjection() const {
+ return mSensorInfo.flags & static_cast<uint32_t>(SensorFlagBits::DATA_INJECTION);
+}
+
+Result Sensor::injectEvent(const Event& event) {
+ Result result = Result::OK;
+ if (event.sensorType == SensorType::ADDITIONAL_INFO) {
+ // When in OperationMode::NORMAL, SensorType::ADDITIONAL_INFO is used to push operation
+ // environment data into the device.
+ } else if (!supportsDataInjection()) {
+ result = Result::INVALID_OPERATION;
+ } else if (mMode == OperationMode::DATA_INJECTION) {
+ mCallback->postEvents(std::vector<Event>{event}, isWakeUpSensor());
+ } else {
+ result = Result::BAD_VALUE;
+ }
+ return result;
+}
+
AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) {
mSensorInfo.sensorHandle = sensorHandle;
mSensorInfo.name = "Accel Sensor";
@@ -142,7 +181,8 @@
mSensorInfo.fifoReservedEventCount = 0;
mSensorInfo.fifoMaxEventCount = 0;
mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::WAKE_UP);
+ mSensorInfo.flags =
+ static_cast<uint32_t>(SensorFlagBits::WAKE_UP | SensorFlagBits::DATA_INJECTION);
};
} // namespace implementation
diff --git a/sensors/2.0/default/Sensor.h b/sensors/2.0/default/Sensor.h
index 75d9aab..3ab2299 100644
--- a/sensors/2.0/default/Sensor.h
+++ b/sensors/2.0/default/Sensor.h
@@ -21,10 +21,12 @@
#include <condition_variable>
#include <memory>
+#include <mutex>
#include <thread>
#include <vector>
using ::android::hardware::sensors::V1_0::Event;
+using ::android::hardware::sensors::V1_0::OperationMode;
using ::android::hardware::sensors::V1_0::Result;
using ::android::hardware::sensors::V1_0::SensorInfo;
using ::android::hardware::sensors::V1_0::SensorType;
@@ -38,7 +40,7 @@
class ISensorsEventCallback {
public:
virtual ~ISensorsEventCallback(){};
- virtual void postEvents(const std::vector<Event>& events) = 0;
+ virtual void postEvents(const std::vector<Event>& events, bool wakeup) = 0;
};
class Sensor {
@@ -51,11 +53,17 @@
void activate(bool enable);
Result flush();
+ void setOperationMode(OperationMode mode);
+ bool supportsDataInjection() const;
+ Result injectEvent(const Event& event);
+
protected:
void run();
virtual std::vector<Event> readEvents();
static void startThread(Sensor* sensor);
+ bool isWakeUpSensor();
+
bool mIsEnabled;
int64_t mSamplingPeriodNs;
int64_t mLastSampleTimeNs;
@@ -63,9 +71,12 @@
std::atomic_bool mStopThread;
std::condition_variable mWaitCV;
+ std::mutex mRunMutex;
std::thread mRunThread;
ISensorsEventCallback* mCallback;
+
+ OperationMode mMode;
};
class AccelSensor : public Sensor {
diff --git a/sensors/2.0/default/Sensors.cpp b/sensors/2.0/default/Sensors.cpp
index cceb7d5..efc8b05 100644
--- a/sensors/2.0/default/Sensors.cpp
+++ b/sensors/2.0/default/Sensors.cpp
@@ -30,8 +30,16 @@
using ::android::hardware::sensors::V1_0::RateLevel;
using ::android::hardware::sensors::V1_0::Result;
using ::android::hardware::sensors::V1_0::SharedMemInfo;
+using ::android::hardware::sensors::V2_0::SensorTimeout;
-Sensors::Sensors() : mEventQueueFlag(nullptr) {
+constexpr const char* kWakeLockName = "SensorsHAL_WAKEUP";
+
+Sensors::Sensors()
+ : mEventQueueFlag(nullptr),
+ mOutstandingWakeUpEvents(0),
+ mReadWakeLockQueueRun(false),
+ mAutoReleaseWakeLockTime(0),
+ mHasWakeLock(false) {
std::shared_ptr<AccelSensor> accel =
std::make_shared<AccelSensor>(1 /* sensorHandle */, this /* callback */);
mSensors[accel->getSensorInfo().sensorHandle] = accel;
@@ -39,6 +47,8 @@
Sensors::~Sensors() {
deleteEventFlag();
+ mReadWakeLockQueueRun = false;
+ mWakeLockThread.join();
}
// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
@@ -54,9 +64,11 @@
return Void();
}
-Return<Result> Sensors::setOperationMode(OperationMode /* mode */) {
- // TODO implement
- return Result{};
+Return<Result> Sensors::setOperationMode(OperationMode mode) {
+ for (auto sensor : mSensors) {
+ sensor.second->setOperationMode(mode);
+ }
+ return Result::OK;
}
Return<Result> Sensors::activate(int32_t sensorHandle, bool enabled) {
@@ -99,6 +111,10 @@
result = Result::BAD_VALUE;
}
+ // Start the thread to read events from the Wake Lock FMQ
+ mReadWakeLockQueueRun = true;
+ mWakeLockThread = std::thread(startReadWakeLockThread, this);
+
return result;
}
@@ -120,14 +136,18 @@
return Result::BAD_VALUE;
}
-Return<Result> Sensors::injectSensorData(const Event& /* event */) {
- // TODO implement
- return Result{};
+Return<Result> Sensors::injectSensorData(const Event& event) {
+ auto sensor = mSensors.find(event.sensorHandle);
+ if (sensor != mSensors.end()) {
+ return sensor->second->injectEvent(event);
+ }
+
+ return Result::BAD_VALUE;
}
Return<void> Sensors::registerDirectChannel(const SharedMemInfo& /* mem */,
registerDirectChannel_cb _hidl_cb) {
- _hidl_cb(Result::INVALID_OPERATION, 0 /* channelHandle */);
+ _hidl_cb(Result::INVALID_OPERATION, -1 /* channelHandle */);
return Return<void>();
}
@@ -141,15 +161,67 @@
return Return<void>();
}
-void Sensors::postEvents(const std::vector<Event>& events) {
- std::lock_guard<std::mutex> l(mLock);
+void Sensors::postEvents(const std::vector<Event>& events, bool wakeup) {
+ std::lock_guard<std::mutex> lock(mWriteLock);
+ if (mEventQueue->write(events.data(), events.size())) {
+ mEventQueueFlag->wake(static_cast<uint32_t>(EventQueueFlagBits::READ_AND_PROCESS));
- // TODO: read events from the Wake Lock FMQ in the right place
- std::vector<uint32_t> tmp(mWakeLockQueue->availableToRead());
- mWakeLockQueue->read(tmp.data(), mWakeLockQueue->availableToRead());
+ if (wakeup) {
+ // Keep track of the number of outstanding WAKE_UP events in order to properly hold
+ // a wake lock until the framework has secured a wake lock
+ updateWakeLock(events.size(), 0 /* eventsHandled */);
+ }
+ }
+}
- mEventQueue->write(events.data(), events.size());
- mEventQueueFlag->wake(static_cast<uint32_t>(EventQueueFlagBits::READ_AND_PROCESS));
+void Sensors::updateWakeLock(int32_t eventsWritten, int32_t eventsHandled) {
+ std::lock_guard<std::mutex> lock(mWakeLockLock);
+ int32_t newVal = mOutstandingWakeUpEvents + eventsWritten - eventsHandled;
+ if (newVal < 0) {
+ mOutstandingWakeUpEvents = 0;
+ } else {
+ mOutstandingWakeUpEvents = newVal;
+ }
+
+ if (eventsWritten > 0) {
+ // Update the time at which the last WAKE_UP event was sent
+ mAutoReleaseWakeLockTime = ::android::uptimeMillis() +
+ static_cast<uint32_t>(SensorTimeout::WAKE_LOCK_SECONDS) * 1000;
+ }
+
+ if (!mHasWakeLock && mOutstandingWakeUpEvents > 0 &&
+ acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLockName) == 0) {
+ mHasWakeLock = true;
+ } else if (mHasWakeLock) {
+ // Check if the wake lock should be released automatically if
+ // SensorTimeout::WAKE_LOCK_SECONDS has elapsed since the last WAKE_UP event was written to
+ // the Wake Lock FMQ.
+ if (::android::uptimeMillis() > mAutoReleaseWakeLockTime) {
+ ALOGD("No events read from wake lock FMQ for %d seconds, auto releasing wake lock",
+ SensorTimeout::WAKE_LOCK_SECONDS);
+ mOutstandingWakeUpEvents = 0;
+ }
+
+ if (mOutstandingWakeUpEvents == 0 && release_wake_lock(kWakeLockName) == 0) {
+ mHasWakeLock = false;
+ }
+ }
+}
+
+void Sensors::readWakeLockFMQ() {
+ while (mReadWakeLockQueueRun.load()) {
+ constexpr int64_t kReadTimeoutNs = 500 * 1000 * 1000; // 500 ms
+ uint32_t eventsHandled = 0;
+
+ // Read events from the Wake Lock FMQ. Timeout after a reasonable amount of time to ensure
+ // that any held wake lock is able to be released if it is held for too long.
+ mWakeLockQueue->readBlocking(&eventsHandled, 1 /* count */, kReadTimeoutNs);
+ updateWakeLock(0 /* eventsWritten */, eventsHandled);
+ }
+}
+
+void Sensors::startReadWakeLockThread(Sensors* sensors) {
+ sensors->readWakeLockFMQ();
}
void Sensors::deleteEventFlag() {
diff --git a/sensors/2.0/default/Sensors.h b/sensors/2.0/default/Sensors.h
index f543935..eba3f97 100644
--- a/sensors/2.0/default/Sensors.h
+++ b/sensors/2.0/default/Sensors.h
@@ -21,10 +21,13 @@
#include <android/hardware/sensors/2.0/ISensors.h>
#include <fmq/MessageQueue.h>
+#include <hardware_legacy/power.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
+#include <atomic>
#include <memory>
+#include <thread>
namespace android {
namespace hardware {
@@ -80,7 +83,7 @@
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
configDirectReport_cb _hidl_cb) override;
- void postEvents(const std::vector<Event>& events) override;
+ void postEvents(const std::vector<Event>& events, bool wakeup) override;
private:
/**
@@ -88,6 +91,18 @@
*/
void deleteEventFlag();
+ /**
+ * Function to read the Wake Lock FMQ and release the wake lock when appropriate
+ */
+ void readWakeLockFMQ();
+
+ static void startReadWakeLockThread(Sensors* sensors);
+
+ /**
+ * Responsible for acquiring and releasing a wake lock when there are unhandled WAKE_UP events
+ */
+ void updateWakeLock(int32_t eventsWritten, int32_t eventsHandled);
+
using EventMessageQueue = MessageQueue<Event, kSynchronizedReadWrite>;
using WakeLockMessageQueue = MessageQueue<uint32_t, kSynchronizedReadWrite>;
@@ -117,9 +132,39 @@
std::map<int32_t, std::shared_ptr<Sensor>> mSensors;
/**
- * Lock to protect writes and reads to the FMQs
+ * Lock to protect writes to the FMQs
*/
- std::mutex mLock;
+ std::mutex mWriteLock;
+
+ /**
+ * Lock to protect acquiring and releasing the wake lock
+ */
+ std::mutex mWakeLockLock;
+
+ /**
+ * Track the number of WAKE_UP events that have not been handled by the framework
+ */
+ uint32_t mOutstandingWakeUpEvents;
+
+ /**
+ * A thread to read the Wake Lock FMQ
+ */
+ std::thread mWakeLockThread;
+
+ /**
+ * Flag to indicate that the Wake Lock Thread should continue to run
+ */
+ std::atomic_bool mReadWakeLockQueueRun;
+
+ /**
+ * Track the time when the wake lock should automatically be released
+ */
+ int64_t mAutoReleaseWakeLockTime;
+
+ /**
+ * Flag to indicate if a wake lock has been acquired
+ */
+ bool mHasWakeLock;
};
} // namespace implementation
diff --git a/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp b/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp
index 3e5837b..ac020ad 100644
--- a/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp
+++ b/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp
@@ -18,6 +18,7 @@
#include "SensorsHidlEnvironmentV2_0.h"
#include "sensors-vts-utils/SensorsHidlTestBase.h"
+#include "sensors-vts-utils/SensorsTestSharedMemory.h"
#include <android/hardware/sensors/2.0/ISensors.h>
#include <android/hardware/sensors/2.0/types.h>
@@ -26,6 +27,7 @@
#include <cinttypes>
#include <condition_variable>
+#include <cstring>
#include <map>
#include <vector>
@@ -34,7 +36,9 @@
using ::android::hardware::Void;
using ::android::hardware::sensors::V1_0::MetaDataEventType;
using ::android::hardware::sensors::V1_0::OperationMode;
+using ::android::hardware::sensors::V1_0::SensorsEventFormatOffset;
using ::android::hardware::sensors::V1_0::SensorStatus;
+using ::android::hardware::sensors::V1_0::SharedMemType;
using ::android::hardware::sensors::V1_0::Vec3;
class EventCallback : public IEventCallback {
@@ -164,7 +168,17 @@
void activateAllSensors(bool enable);
std::vector<SensorInfo> getNonOneShotSensors();
std::vector<SensorInfo> getOneShotSensors();
+ std::vector<SensorInfo> getInjectEventSensors();
int32_t getInvalidSensorHandle();
+ void verifyDirectChannel(SharedMemType memType);
+ void verifyRegisterDirectChannel(const SensorInfo& sensor, SharedMemType memType,
+ std::shared_ptr<SensorsTestSharedMemory> mem,
+ int32_t* directChannelHandle);
+ void verifyConfigure(const SensorInfo& sensor, SharedMemType memType,
+ int32_t directChannelHandle);
+ void verifyUnregisterDirectChannel(const SensorInfo& sensor, SharedMemType memType,
+ int32_t directChannelHandle);
+ void checkRateLevel(const SensorInfo& sensor, int32_t directChannelHandle, RateLevel rateLevel);
};
Return<Result> SensorsHidlTest::activate(int32_t sensorHandle, bool enabled) {
@@ -243,6 +257,16 @@
return sensors;
}
+std::vector<SensorInfo> SensorsHidlTest::getInjectEventSensors() {
+ std::vector<SensorInfo> sensors;
+ for (const SensorInfo& info : getSensorsList()) {
+ if (info.flags & static_cast<uint32_t>(SensorFlagBits::DATA_INJECTION)) {
+ sensors.push_back(info);
+ }
+ }
+ return sensors;
+}
+
int32_t SensorsHidlTest::getInvalidSensorHandle() {
// Find a sensor handle that does not exist in the sensor list
int32_t maxHandle = 0;
@@ -297,63 +321,71 @@
});
}
-// Test if sensor list returned is valid
+// Test that SetOperationMode returns the expected value
TEST_F(SensorsHidlTest, SetOperationMode) {
- std::vector<SensorInfo> sensorList = getSensorsList();
-
- bool needOperationModeSupport =
- std::any_of(sensorList.begin(), sensorList.end(),
- [](const auto& s) { return (s.flags & SensorFlagBits::DATA_INJECTION) != 0; });
- if (!needOperationModeSupport) {
- return;
+ std::vector<SensorInfo> sensors = getInjectEventSensors();
+ if (getInjectEventSensors().size() > 0) {
+ ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL));
+ ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::DATA_INJECTION));
+ ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL));
+ } else {
+ ASSERT_EQ(Result::BAD_VALUE, getSensors()->setOperationMode(OperationMode::DATA_INJECTION));
}
-
- ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL));
- ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::DATA_INJECTION));
- ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL));
}
-// Test if sensor list returned is valid
+// Test that an injected event is written back to the Event FMQ
TEST_F(SensorsHidlTest, InjectSensorEventData) {
- std::vector<SensorInfo> sensorList = getSensorsList();
- std::vector<SensorInfo> sensorSupportInjection;
-
- bool needOperationModeSupport =
- std::any_of(sensorList.begin(), sensorList.end(), [&sensorSupportInjection](const auto& s) {
- bool ret = (s.flags & SensorFlagBits::DATA_INJECTION) != 0;
- if (ret) {
- sensorSupportInjection.push_back(s);
- }
- return ret;
- });
- if (!needOperationModeSupport) {
+ std::vector<SensorInfo> sensors = getInjectEventSensors();
+ if (sensors.size() == 0) {
return;
}
- ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL));
ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::DATA_INJECTION));
- for (const auto& s : sensorSupportInjection) {
- switch (s.type) {
- case SensorType::ACCELEROMETER:
- case SensorType::GYROSCOPE:
- case SensorType::MAGNETIC_FIELD: {
- usleep(100000); // sleep 100ms
+ EventCallback callback;
+ getEnvironment()->registerCallback(&callback);
- Event dummy;
- dummy.timestamp = android::elapsedRealtimeNano();
- dummy.sensorType = s.type;
- dummy.sensorHandle = s.sensorHandle;
- Vec3 v = {1, 2, 3, SensorStatus::ACCURACY_HIGH};
- dummy.u.vec3 = v;
+ // AdditionalInfo event should not be sent to Event FMQ
+ Event additionalInfoEvent;
+ additionalInfoEvent.sensorType = SensorType::ADDITIONAL_INFO;
+ additionalInfoEvent.timestamp = android::elapsedRealtimeNano();
- EXPECT_EQ(Result::OK, getSensors()->injectSensorData(dummy));
- break;
- }
- default:
- break;
- }
+ Event injectedEvent;
+ injectedEvent.timestamp = android::elapsedRealtimeNano();
+ Vec3 data = {1, 2, 3, SensorStatus::ACCURACY_HIGH};
+ injectedEvent.u.vec3 = data;
+
+ for (const auto& s : sensors) {
+ additionalInfoEvent.sensorHandle = s.sensorHandle;
+ EXPECT_EQ(Result::OK, getSensors()->injectSensorData(additionalInfoEvent));
+
+ injectedEvent.sensorType = s.type;
+ injectedEvent.sensorHandle = s.sensorHandle;
+ EXPECT_EQ(Result::OK, getSensors()->injectSensorData(injectedEvent));
}
+
+ // Wait for events to be written back to the Event FMQ
+ callback.waitForEvents(sensors, 1000 /* timeoutMs */);
+
+ for (const auto& s : sensors) {
+ auto events = callback.getEvents(s.sensorHandle);
+ auto lastEvent = events.back();
+
+ // Verify that only a single event has been received
+ ASSERT_EQ(events.size(), 1);
+
+ // Verify that the event received matches the event injected and is not the additional
+ // info event
+ ASSERT_EQ(lastEvent.sensorType, s.type);
+ ASSERT_EQ(lastEvent.sensorType, s.type);
+ ASSERT_EQ(lastEvent.timestamp, injectedEvent.timestamp);
+ ASSERT_EQ(lastEvent.u.vec3.x, injectedEvent.u.vec3.x);
+ ASSERT_EQ(lastEvent.u.vec3.y, injectedEvent.u.vec3.y);
+ ASSERT_EQ(lastEvent.u.vec3.z, injectedEvent.u.vec3.z);
+ ASSERT_EQ(lastEvent.u.vec3.status, injectedEvent.u.vec3.status);
+ }
+
+ getEnvironment()->unregisterCallback();
ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL));
}
@@ -789,6 +821,128 @@
getEnvironment()->unregisterCallback();
}
+void SensorsHidlTest::checkRateLevel(const SensorInfo& sensor, int32_t directChannelHandle,
+ RateLevel rateLevel) {
+ configDirectReport(sensor.sensorHandle, directChannelHandle, rateLevel,
+ [&](Result result, int32_t reportToken) {
+ if (isDirectReportRateSupported(sensor, rateLevel)) {
+ ASSERT_EQ(result, Result::OK);
+ ASSERT_GT(reportToken, 0);
+ } else {
+ ASSERT_EQ(result, Result::BAD_VALUE);
+ }
+ });
+}
+
+void SensorsHidlTest::verifyRegisterDirectChannel(const SensorInfo& sensor, SharedMemType memType,
+ std::shared_ptr<SensorsTestSharedMemory> mem,
+ int32_t* directChannelHandle) {
+ char* buffer = mem->getBuffer();
+ memset(buffer, 0xff, mem->getSize());
+
+ registerDirectChannel(mem->getSharedMemInfo(), [&](Result result, int32_t channelHandle) {
+ if (isDirectChannelTypeSupported(sensor, memType)) {
+ ASSERT_EQ(result, Result::OK);
+ ASSERT_GT(channelHandle, 0);
+
+ // Verify that the memory has been zeroed
+ for (size_t i = 0; i < mem->getSize(); i++) {
+ ASSERT_EQ(buffer[i], 0x00);
+ }
+ } else {
+ ASSERT_EQ(result, Result::INVALID_OPERATION);
+ ASSERT_EQ(channelHandle, -1);
+ }
+ *directChannelHandle = channelHandle;
+ });
+}
+
+void SensorsHidlTest::verifyConfigure(const SensorInfo& sensor, SharedMemType memType,
+ int32_t directChannelHandle) {
+ if (isDirectChannelTypeSupported(sensor, memType)) {
+ // Verify that each rate level is properly supported
+ checkRateLevel(sensor, directChannelHandle, RateLevel::NORMAL);
+ checkRateLevel(sensor, directChannelHandle, RateLevel::FAST);
+ checkRateLevel(sensor, directChannelHandle, RateLevel::VERY_FAST);
+ checkRateLevel(sensor, directChannelHandle, RateLevel::STOP);
+
+ // Verify that a sensor handle of -1 is only acceptable when using RateLevel::STOP
+ configDirectReport(
+ -1 /* sensorHandle */, directChannelHandle, RateLevel::NORMAL,
+ [](Result result, int32_t /* reportToken */) { ASSERT_EQ(result, Result::BAD_VALUE); });
+ configDirectReport(
+ -1 /* sensorHandle */, directChannelHandle, RateLevel::STOP,
+ [](Result result, int32_t /* reportToken */) { ASSERT_EQ(result, Result::OK); });
+ } else {
+ // Direct channel is not supported for this SharedMemType
+ configDirectReport(sensor.sensorHandle, directChannelHandle, RateLevel::NORMAL,
+ [](Result result, int32_t /* reportToken */) {
+ ASSERT_EQ(result, Result::INVALID_OPERATION);
+ });
+ }
+}
+
+void SensorsHidlTest::verifyUnregisterDirectChannel(const SensorInfo& sensor, SharedMemType memType,
+ int32_t directChannelHandle) {
+ Result result = unregisterDirectChannel(directChannelHandle);
+ if (isDirectChannelTypeSupported(sensor, memType)) {
+ ASSERT_EQ(result, Result::OK);
+ } else {
+ ASSERT_EQ(result, Result::INVALID_OPERATION);
+ }
+}
+
+void SensorsHidlTest::verifyDirectChannel(SharedMemType memType) {
+ constexpr size_t kEventSize = static_cast<size_t>(SensorsEventFormatOffset::TOTAL_LENGTH);
+ constexpr size_t kNumEvents = 1;
+ constexpr size_t kMemSize = kNumEvents * kEventSize;
+
+ std::shared_ptr<SensorsTestSharedMemory> mem(
+ SensorsTestSharedMemory::create(memType, kMemSize));
+ ASSERT_NE(mem, nullptr);
+
+ for (const SensorInfo& sensor : getSensorsList()) {
+ int32_t directChannelHandle = 0;
+ verifyRegisterDirectChannel(sensor, memType, mem, &directChannelHandle);
+ verifyConfigure(sensor, memType, directChannelHandle);
+ verifyUnregisterDirectChannel(sensor, memType, directChannelHandle);
+ }
+}
+
+TEST_F(SensorsHidlTest, DirectChannelAshmem) {
+ verifyDirectChannel(SharedMemType::ASHMEM);
+}
+
+TEST_F(SensorsHidlTest, DirectChannelGralloc) {
+ verifyDirectChannel(SharedMemType::GRALLOC);
+}
+
+TEST_F(SensorsHidlTest, ConfigureDirectChannelWithInvalidHandle) {
+ for (const SensorInfo& sensor : getSensorsList()) {
+ if (isDirectChannelTypeSupported(sensor, SharedMemType::ASHMEM) ||
+ isDirectChannelTypeSupported(sensor, SharedMemType::GRALLOC)) {
+ // Find a supported rate level
+ RateLevel rate = RateLevel::STOP;
+ if (isDirectReportRateSupported(sensor, RateLevel::NORMAL)) {
+ rate = RateLevel::NORMAL;
+ } else if (isDirectReportRateSupported(sensor, RateLevel::FAST)) {
+ rate = RateLevel::FAST;
+ } else if (isDirectReportRateSupported(sensor, RateLevel::VERY_FAST)) {
+ rate = RateLevel::VERY_FAST;
+ }
+
+ // Ensure that at least one rate level is supported
+ ASSERT_NE(rate, RateLevel::STOP);
+
+ // Verify that an invalid channel handle produces a BAD_VALUE result
+ configDirectReport(sensor.sensorHandle, -1, rate,
+ [](Result result, int32_t /* reportToken */) {
+ ASSERT_EQ(result, Result::BAD_VALUE);
+ });
+ }
+ }
+}
+
int main(int argc, char** argv) {
::testing::AddGlobalTestEnvironment(SensorsHidlEnvironmentV2_0::Instance());
::testing::InitGoogleTest(&argc, argv);
diff --git a/sensors/common/vts/utils/SensorsTestSharedMemory.cpp b/sensors/common/vts/utils/SensorsTestSharedMemory.cpp
index 5096498..819e297 100644
--- a/sensors/common/vts/utils/SensorsTestSharedMemory.cpp
+++ b/sensors/common/vts/utils/SensorsTestSharedMemory.cpp
@@ -35,6 +35,10 @@
return mBuffer;
}
+size_t SensorsTestSharedMemory::getSize() const {
+ return mSize;
+}
+
std::vector<Event> SensorsTestSharedMemory::parseEvents(int64_t lastCounter, size_t offset) const {
constexpr size_t kEventSize = static_cast<size_t>(SensorsEventFormatOffset::TOTAL_LENGTH);
constexpr size_t kOffsetSize = static_cast<size_t>(SensorsEventFormatOffset::SIZE_FIELD);
diff --git a/sensors/common/vts/utils/include/sensors-vts-utils/SensorsTestSharedMemory.h b/sensors/common/vts/utils/include/sensors-vts-utils/SensorsTestSharedMemory.h
index 055b8e7..002f42c 100644
--- a/sensors/common/vts/utils/include/sensors-vts-utils/SensorsTestSharedMemory.h
+++ b/sensors/common/vts/utils/include/sensors-vts-utils/SensorsTestSharedMemory.h
@@ -33,6 +33,7 @@
static SensorsTestSharedMemory* create(SharedMemType type, size_t size);
SharedMemInfo getSharedMemInfo() const;
char* getBuffer() const;
+ size_t getSize() const;
std::vector<Event> parseEvents(int64_t lastCounter = -1, size_t offset = 0) const;
virtual ~SensorsTestSharedMemory();