Add NDK backend and VTS
Tag: #feature
Bug: 244406135
Test: atest VtsHalBluetoothPofTargetTest
Change-Id: I8646985b9b5b3ffa5636e8c12927778cb145e515
diff --git a/bluetooth/power_off_finder/OWNERS b/bluetooth/power_off_finder/OWNERS
new file mode 100644
index 0000000..51a96c1
--- /dev/null
+++ b/bluetooth/power_off_finder/OWNERS
@@ -0,0 +1,2 @@
+# Bug component: 27441
+quocbaodo@google.com
diff --git a/bluetooth/power_off_finder/aidl/Android.bp b/bluetooth/power_off_finder/aidl/Android.bp
index 46b0a34..ad40a9c 100644
--- a/bluetooth/power_off_finder/aidl/Android.bp
+++ b/bluetooth/power_off_finder/aidl/Android.bp
@@ -17,5 +17,12 @@
java: {
platform_apis: true,
},
+ ndk: {
+ apex_available: [
+ "//apex_available:platform",
+ "com.android.btservices",
+ ],
+ min_sdk_version: "33",
+ },
},
}
diff --git a/bluetooth/power_off_finder/aidl/vts/Android.bp b/bluetooth/power_off_finder/aidl/vts/Android.bp
new file mode 100644
index 0000000..cf709de
--- /dev/null
+++ b/bluetooth/power_off_finder/aidl/vts/Android.bp
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2023 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 {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_test {
+ name: "VtsHalBluetoothPofTargetTest",
+ defaults: [
+ "use_libaidlvintf_gtest_helper_static",
+ ],
+ srcs: ["VtsHalBluetoothPofTargetTest.cpp"],
+ shared_libs: [
+ "libbase",
+ "libcutils",
+ "libbinder_ndk",
+ "liblog",
+ "libutils",
+ "//hardware/google/interfaces:hardware.google.bluetooth.power_off_finder-V1-ndk",
+ ],
+ static_libs: [
+ "libbluetooth-types",
+ ],
+ test_config: "VtsHalBluetoothPofTargetTest.xml",
+ test_suites: [
+ "general-tests",
+ "vts",
+ ],
+}
diff --git a/bluetooth/power_off_finder/aidl/vts/VtsHalBluetoothPofTargetTest.cpp b/bluetooth/power_off_finder/aidl/vts/VtsHalBluetoothPofTargetTest.cpp
new file mode 100644
index 0000000..6ed84a8
--- /dev/null
+++ b/bluetooth/power_off_finder/aidl/vts/VtsHalBluetoothPofTargetTest.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2023 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 <aidl/Gtest.h>
+#include <aidl/Vintf.h>
+#include <aidl/hardware/google/bluetooth/power_off_finder/IBluetoothFinder.h>
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <binder/IServiceManager.h>
+#include <utils/Log.h>
+
+#include <vector>
+
+using ::aidl::hardware::google::bluetooth::power_off_finder::IBluetoothFinder;
+using ::ndk::ScopedAStatus;
+
+class BluetoothPofTest : public ::testing::TestWithParam<std::string> {
+public:
+ virtual void SetUp() override;
+ virtual void TearDown() override;
+
+ // test functions to call
+ ScopedAStatus sendAndCheckPrecomputedKeys(uint_t numKeys);
+ ScopedAStatus checkStartPowerOffMode(uint8_t startIndex);
+
+private:
+ std::shared_ptr<IBluetoothFinder> bluetooth_pof;
+};
+
+void BluetoothPofTest::SetUp() {
+ ALOGI("SetUp POF Test");
+ bluetooth_pof = IBluetoothFinder::fromBinder(
+ ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
+ ASSERT_NE(bluetooth_pof, nullptr);
+}
+
+void BluetoothPofTest::TearDown() {
+ ALOGI("TearDown POF Test");
+ bluetooth_pof = nullptr;
+ ASSERT_EQ(bluetooth_pof, nullptr);
+}
+
+ScopedAStatus BluetoothPofTest::sendAndCheckPrecomputedKeys(uint_t numKeys) {
+ // creating mock keys
+ std::vector<uint8_t> keys(20 * numKeys);
+ for (uint_t i = 0; i < keys.size(); ++i)
+ keys[i] = ((i / 20) + 1) & 0xff;
+ // sending keys to the controller
+ return bluetooth_pof->sendPrecomputedKeys(keys);
+}
+
+ScopedAStatus BluetoothPofTest::checkStartPowerOffMode(uint8_t startIndex) {
+ return bluetooth_pof->startPoweredOffMode(startIndex);
+}
+
+TEST_P(BluetoothPofTest, SendAndCheckPrecomputedKeySingle) {
+ ScopedAStatus status = sendAndCheckPrecomputedKeys(1);
+ ASSERT_TRUE(status.isOk());
+}
+
+TEST_P(BluetoothPofTest, SendAndCheckPrecomputedKeyManyKeys) {
+ ScopedAStatus status = sendAndCheckPrecomputedKeys(30);
+ ASSERT_TRUE(status.isOk());
+}
+
+TEST_P(BluetoothPofTest, StartPowerOffMode) {
+ ScopedAStatus status = checkStartPowerOffMode(0);
+ ASSERT_TRUE(status.isOk());
+}
+
+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothPofTest);
+INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothPofTest,
+ testing::ValuesIn(android::getAidlHalInstanceNames(
+ IBluetoothFinder::descriptor)),
+ android::PrintInstanceNameToString);
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ ABinderProcess_startThreadPool();
+ int status = RUN_ALL_TESTS();
+ ALOGI("Test result = %d", status);
+ return status;
+}
diff --git a/bluetooth/power_off_finder/aidl/vts/VtsHalBluetoothPofTargetTest.xml b/bluetooth/power_off_finder/aidl/vts/VtsHalBluetoothPofTargetTest.xml
new file mode 100644
index 0000000..006a99c
--- /dev/null
+++ b/bluetooth/power_off_finder/aidl/vts/VtsHalBluetoothPofTargetTest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2023 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.
+-->
+<configuration description="Runs VtsHalBluetoothPofTargetTest.">
+ <option name="test-suite-tag" value="apct" />
+ <option name="test-suite-tag" value="apct-native" />
+
+ <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer">
+ </target_preparer>
+
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="VtsHalBluetoothPofTargetTest->/data/local/tmp/VtsHalBluetoothPofTargetTest" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/local/tmp" />
+ <option name="module-name" value="VtsHalBluetoothPofTargetTest" />
+ </test>
+</configuration>