summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-13 00:20:08 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-13 00:20:08 +0000
commitd1c609d49981295137d59bb50b279808b374792c (patch)
treee982c911fe633f317a178c89c63f8979a290c1aa
parentbeb9ec59cac73e917b6043672356e0d67bdd7fe7 (diff)
parent16a489870823b83e6c64c94818be22caf8eb22d7 (diff)
downloadinterfaces-android14-qpr2-s2-release.tar.gz
Change-Id: I1be4908f03f4674ed7ed73f39d976e0fce36036b
-rw-r--r--vibrator/OWNERS2
-rw-r--r--vibrator/aidl/Android.bp40
-rw-r--r--vibrator/aidl/TEST_MAPPING7
-rw-r--r--vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorControlService.aidl43
-rw-r--r--vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorController.aidl39
-rw-r--r--vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/ScaleParam.aidl44
-rw-r--r--vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/VibrationParam.aidl38
-rw-r--r--vibrator/aidl/android/frameworks/vibrator/IVibratorControlService.aidl77
-rw-r--r--vibrator/aidl/android/frameworks/vibrator/IVibratorController.aidl39
-rw-r--r--vibrator/aidl/android/frameworks/vibrator/ScaleParam.aidl33
-rw-r--r--vibrator/aidl/android/frameworks/vibrator/VibrationParam.aidl27
-rw-r--r--vibrator/aidl/vts/functional/Android.bp44
-rw-r--r--vibrator/aidl/vts/functional/VtsHalVibratorControlServiceTargetTest.cpp149
13 files changed, 582 insertions, 0 deletions
diff --git a/vibrator/OWNERS b/vibrator/OWNERS
new file mode 100644
index 0000000..c4de58a
--- /dev/null
+++ b/vibrator/OWNERS
@@ -0,0 +1,2 @@
+# Bug component: 345036
+include platform/frameworks/base:/services/core/java/com/android/server/vibrator/OWNERS
diff --git a/vibrator/aidl/Android.bp b/vibrator/aidl/Android.bp
new file mode 100644
index 0000000..6df996f
--- /dev/null
+++ b/vibrator/aidl/Android.bp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+aidl_interface {
+ name: "android.frameworks.vibrator",
+ srcs: ["android/frameworks/vibrator/*.aidl"],
+ vendor_available: true,
+ host_supported: true,
+ stability: "vintf",
+ backend: {
+ java: {
+ platform_apis: true,
+ },
+ ndk: {
+ enabled: true,
+ },
+ cpp: {
+ enabled: false,
+ },
+ },
+ frozen: false,
+
+}
diff --git a/vibrator/aidl/TEST_MAPPING b/vibrator/aidl/TEST_MAPPING
new file mode 100644
index 0000000..f7f7b11
--- /dev/null
+++ b/vibrator/aidl/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+ "postsubmit": [
+ {
+ "name": "VtsHalVibratorControlServiceTargetTest"
+ }
+ ]
+}
diff --git a/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorControlService.aidl b/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorControlService.aidl
new file mode 100644
index 0000000..5f5fbcb
--- /dev/null
+++ b/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorControlService.aidl
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+// the interface (from the latest frozen version), the build system will
+// prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.frameworks.vibrator;
+/* @hide */
+@VintfStability
+interface IVibratorControlService {
+ oneway void registerVibratorController(in android.frameworks.vibrator.IVibratorController controller);
+ oneway void unregisterVibratorController(in android.frameworks.vibrator.IVibratorController controller);
+ oneway void setVibrationParams(in android.frameworks.vibrator.VibrationParam[] params, in android.frameworks.vibrator.IVibratorController token);
+ oneway void clearVibrationParams(in int typesMask, in android.frameworks.vibrator.IVibratorController token);
+ oneway void onRequestVibrationParamsComplete(in IBinder requestToken, in android.frameworks.vibrator.VibrationParam[] result);
+}
diff --git a/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorController.aidl b/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorController.aidl
new file mode 100644
index 0000000..cd9e6cd
--- /dev/null
+++ b/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorController.aidl
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+// the interface (from the latest frozen version), the build system will
+// prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.frameworks.vibrator;
+/* @hide */
+@VintfStability
+interface IVibratorController {
+ oneway void requestVibrationParams(in int typesMask, in long deadlineElapsedRealtimeMillis, in IBinder requestToken);
+}
diff --git a/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/ScaleParam.aidl b/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/ScaleParam.aidl
new file mode 100644
index 0000000..0e3bcdf
--- /dev/null
+++ b/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/ScaleParam.aidl
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+// the interface (from the latest frozen version), the build system will
+// prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.frameworks.vibrator;
+@VintfStability
+parcelable ScaleParam {
+ int typesMask;
+ float scale;
+ const int TYPE_ALARM = (1 << 0) /* 1 */;
+ const int TYPE_NOTIFICATION = (1 << 1) /* 2 */;
+ const int TYPE_RINGTONE = (1 << 2) /* 4 */;
+ const int TYPE_INTERACTIVE = (1 << 3) /* 8 */;
+ const int TYPE_MEDIA = (1 << 4) /* 16 */;
+}
diff --git a/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/VibrationParam.aidl b/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/VibrationParam.aidl
new file mode 100644
index 0000000..ddf7d05
--- /dev/null
+++ b/vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/VibrationParam.aidl
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+// the interface (from the latest frozen version), the build system will
+// prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.frameworks.vibrator;
+@VintfStability
+union VibrationParam {
+ android.frameworks.vibrator.ScaleParam scale;
+}
diff --git a/vibrator/aidl/android/frameworks/vibrator/IVibratorControlService.aidl b/vibrator/aidl/android/frameworks/vibrator/IVibratorControlService.aidl
new file mode 100644
index 0000000..3fe1586
--- /dev/null
+++ b/vibrator/aidl/android/frameworks/vibrator/IVibratorControlService.aidl
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+package android.frameworks.vibrator;
+
+import android.frameworks.vibrator.IVibratorController;
+import android.frameworks.vibrator.VibrationParam;
+
+/**
+ * IVibratorControlService is a service that allows clients to register IVibratorControllers to
+ * receive VibrationParams. It also allows the client to set and clear VibrationParams.
+ * @hide
+ */
+@VintfStability
+interface IVibratorControlService {
+ /**
+ * Registers an IVibratorController to allow pushing VibrationParams. These params will be used
+ * to modify vibration characteristics, such as scaling.
+ * <p>Only one controller should be registered at the same time. Registering a new controller
+ * must unregister the old controller before registering the new one.
+ *
+ * @param controller The vibrator controller used for pulling requests.
+ */
+ oneway void registerVibratorController(in IVibratorController controller);
+
+ /**
+ * Unregisters an IVibratorController.
+ * <p>If the provided controller is not the registered one, the request must be ignored.
+ *
+ * @param controller The vibrator controller to be removed.
+ */
+ oneway void unregisterVibratorController(in IVibratorController controller);
+
+ /**
+ * Sets VibrationParams which will be used to modify some vibration characteristics, such as
+ * scaling.
+ * <p>If the provided controller is not the registered one, the request must be ignored.
+ *
+ * @param params The vibration params to be applied to new vibrations.
+ * @param token The token to register a death recipient to expire these params.
+ */
+ oneway void setVibrationParams(in VibrationParam[] params, in IVibratorController token);
+
+ /**
+ * Clears any set VibrationParams and reverts the vibration characteristics to their default
+ * settings.
+ * <p>If the provided controller is not the registered one, the request must be ignored.
+ *
+ * @param typesMask The combined bitfield of vibration types to be cleared
+ * @param token The token to register a death recipient to expire these params
+ */
+ oneway void clearVibrationParams(in int typesMask, in IVibratorController token);
+
+ /**
+ * Notifies the VibrationControlService of new VibrationParams.
+ * <p>This method must be called by the IVibratorController after processing a
+ * 'requestVibrationParams()' call by the service.
+ *
+ * @param requestToken The token used for this request
+ * @param result The request result
+ */
+ oneway void onRequestVibrationParamsComplete(
+ in IBinder requestToken, in VibrationParam[] result);
+} \ No newline at end of file
diff --git a/vibrator/aidl/android/frameworks/vibrator/IVibratorController.aidl b/vibrator/aidl/android/frameworks/vibrator/IVibratorController.aidl
new file mode 100644
index 0000000..a1c8f79
--- /dev/null
+++ b/vibrator/aidl/android/frameworks/vibrator/IVibratorController.aidl
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package android.frameworks.vibrator;
+
+/**
+ * IVibratorController is an interface that allows clients to request the VibrationParams for the
+ * specified vibration types. If the request is longer than the specified deadline, the result will
+ * be ignored by the caller.
+ * @hide
+ */
+@VintfStability
+interface IVibratorController {
+ /**
+ * Triggers a request to receive VibrationParams for the specified vibration types. The
+ * received params are used to modify vibration characteristics, such as scaling.
+ * <p> If the request takes longer than the specified deadline, the request must be ignored by
+ * the caller.
+ *
+ * @param typesMask The combined bitfield of vibration types queried
+ * @param deadlineElapsedRealtimeMillis The request deadline, result ignored after this
+ * @param requestToken The token for the async result, used by the service
+ */
+ oneway void requestVibrationParams(in int typesMask,
+ in long deadlineElapsedRealtimeMillis, in IBinder requestToken);
+} \ No newline at end of file
diff --git a/vibrator/aidl/android/frameworks/vibrator/ScaleParam.aidl b/vibrator/aidl/android/frameworks/vibrator/ScaleParam.aidl
new file mode 100644
index 0000000..c0170cb
--- /dev/null
+++ b/vibrator/aidl/android/frameworks/vibrator/ScaleParam.aidl
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+package android.frameworks.vibrator;
+
+/**
+ * Vibration scale for one or more vibration types
+ */
+@VintfStability
+parcelable ScaleParam {
+ const int TYPE_ALARM = 1 << 0; // Alarm usage
+ const int TYPE_NOTIFICATION = 1 << 1; // Notification and communication request usages
+ const int TYPE_RINGTONE = 1 << 2; // Ringtone usage
+ const int TYPE_INTERACTIVE = 1 << 3; // Touch and hardware feedback usages
+ const int TYPE_MEDIA = 1 << 4; // Media and unknown usages
+
+ // combined bitfield of ScaleParam::TYPE* values
+ int typesMask;
+ float scale;
+} \ No newline at end of file
diff --git a/vibrator/aidl/android/frameworks/vibrator/VibrationParam.aidl b/vibrator/aidl/android/frameworks/vibrator/VibrationParam.aidl
new file mode 100644
index 0000000..e9bde2a
--- /dev/null
+++ b/vibrator/aidl/android/frameworks/vibrator/VibrationParam.aidl
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+package android.frameworks.vibrator;
+
+import android.frameworks.vibrator.ScaleParam;
+
+/**
+ * Consolidated representation of all vibration parameters
+ */
+@VintfStability
+union VibrationParam {
+ ScaleParam scale;
+} \ No newline at end of file
diff --git a/vibrator/aidl/vts/functional/Android.bp b/vibrator/aidl/vts/functional/Android.bp
new file mode 100644
index 0000000..e95eb01
--- /dev/null
+++ b/vibrator/aidl/vts/functional/Android.bp
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_test {
+ name: "VtsHalVibratorControlServiceTargetTest",
+ defaults: [
+ "VtsHalTargetTestDefaults",
+ "use_libaidlvintf_gtest_helper_static",
+ ],
+ tidy_timeout_srcs: [
+ "VtsHalVibratorControlServiceTargetTest.cpp",
+ ],
+ srcs: [
+ "VtsHalVibratorControlServiceTargetTest.cpp",
+ ],
+ static_libs: [
+ "android.frameworks.vibrator-V1-ndk",
+ "libgmock",
+ ],
+ shared_libs: [
+ "libbinder_ndk",
+ ],
+ test_suites: [
+ "general-tests",
+ "vts",
+ ],
+}
diff --git a/vibrator/aidl/vts/functional/VtsHalVibratorControlServiceTargetTest.cpp b/vibrator/aidl/vts/functional/VtsHalVibratorControlServiceTargetTest.cpp
new file mode 100644
index 0000000..9987440
--- /dev/null
+++ b/vibrator/aidl/vts/functional/VtsHalVibratorControlServiceTargetTest.cpp
@@ -0,0 +1,149 @@
+/*
+ * 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.
+ */
+
+#include <aidl/Gtest.h>
+#include <aidl/Vintf.h>
+#include <aidl/android/frameworks/vibrator/BnVibratorControlService.h>
+#include <aidl/android/frameworks/vibrator/BnVibratorController.h>
+#include <aidl/android/frameworks/vibrator/IVibratorControlService.h>
+#include <aidl/android/frameworks/vibrator/IVibratorController.h>
+#include <aidl/android/frameworks/vibrator/ScaleParam.h>
+#include <android-base/logging.h>
+#include <android/binder_auto_utils.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <utils/Condition.h>
+#include <utils/Mutex.h>
+
+namespace android {
+
+using ::aidl::android::frameworks::vibrator::BnVibratorController;
+using ::aidl::android::frameworks::vibrator::BnVibratorControlService;
+using ::aidl::android::frameworks::vibrator::IVibratorController;
+using ::aidl::android::frameworks::vibrator::IVibratorControlService;
+using ::aidl::android::frameworks::vibrator::ScaleParam;
+using ::aidl::android::frameworks::vibrator::VibrationParam;
+using ::android::getAidlHalInstanceNames;
+using ::android::PrintInstanceNameToString;
+using ndk::SpAIBinder;
+using ::testing::Eq;
+using ::testing::InitGoogleTest;
+using ::testing::TestWithParam;
+using ::testing::ValuesIn;
+
+std::vector<VibrationParam> generateVibrationParams(int in_typesMask, float scale) {
+ ScaleParam scaleParam = ScaleParam();
+ scaleParam.typesMask = in_typesMask;
+ scaleParam.scale = scale;
+ VibrationParam vibrationParam = VibrationParam(scaleParam);
+ std::vector<VibrationParam> vibrationParams = {vibrationParam};
+ return vibrationParams;
+}
+
+class VibratorController : public BnVibratorController {
+ public:
+ ~VibratorController() override = default;
+
+ ndk::ScopedAStatus requestVibrationParams(int in_typesMask,
+ int64_t in_deadlineElapsedRealtimeMillis,
+ const ::ndk::SpAIBinder& in_requestToken) override {
+ if (in_requestToken == nullptr) {
+ LOG(INFO) << "Vibrator controller failed to process a request for vibration params";
+ return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
+ }
+
+ LOG(INFO) << "Vibrator controller received a request for vibration params for type: "
+ << in_typesMask << ", with a timeout of: " << in_deadlineElapsedRealtimeMillis;
+
+ std::shared_ptr<IVibratorControlService> service =
+ IVibratorControlService::fromBinder(in_requestToken);
+
+ EXPECT_TRUE(service
+ ->onRequestVibrationParamsComplete(
+ in_requestToken, generateVibrationParams(in_typesMask, /* scale= */ 1))
+ .isOk());
+
+ return ndk::ScopedAStatus::ok();
+ }
+};
+
+class VibratorControlServiceTest : public ::testing::TestWithParam<std::string> {
+ public:
+ void SetUp() override {
+ SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str()));
+ service = IVibratorControlService::fromBinder(binder);
+ ASSERT_NE(service, nullptr);
+ }
+
+ std::shared_ptr<IVibratorControlService> service;
+};
+
+TEST_P(VibratorControlServiceTest, RegisterVibrationControllerTest) {
+ std::shared_ptr<IVibratorController> vibratorController =
+ ::ndk::SharedRefBase::make<VibratorController>();
+
+ EXPECT_TRUE(service->registerVibratorController(vibratorController).isOk());
+
+ EXPECT_TRUE(service->unregisterVibratorController(vibratorController).isOk());
+}
+
+TEST_P(VibratorControlServiceTest, RequestVibrationParamsTest) {
+ std::shared_ptr<IVibratorController> vibratorController =
+ ::ndk::SharedRefBase::make<VibratorController>();
+
+ EXPECT_TRUE(service->registerVibratorController(vibratorController).isOk());
+
+ EXPECT_TRUE(vibratorController
+ ->requestVibrationParams(ScaleParam::TYPE_ALARM,
+ /* deadlineElapsedRealtimeMillis= */ 50,
+ service->asBinder())
+ .isOk());
+ EXPECT_TRUE(service->unregisterVibratorController(vibratorController).isOk());
+}
+
+TEST_P(VibratorControlServiceTest, SetAndClearVibrationParamsTest) {
+ std::shared_ptr<IVibratorController> vibratorController =
+ ::ndk::SharedRefBase::make<VibratorController>();
+
+ EXPECT_TRUE(service->registerVibratorController(vibratorController).isOk());
+
+ EXPECT_TRUE(
+ service
+ ->setVibrationParams(generateVibrationParams(ScaleParam::TYPE_ALARM, /* scale= */ 1),
+ vibratorController->getDefaultImpl())
+ .isOk());
+
+ EXPECT_TRUE(
+ service->clearVibrationParams(ScaleParam::TYPE_ALARM, vibratorController->getDefaultImpl())
+ .isOk());
+
+ EXPECT_TRUE(service->unregisterVibratorController(vibratorController).isOk());
+}
+
+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VibratorControlServiceTest);
+
+INSTANTIATE_TEST_SUITE_P(
+ PerInstance, VibratorControlServiceTest,
+ testing::ValuesIn(getAidlHalInstanceNames(IVibratorControlService::descriptor)),
+ PrintInstanceNameToString);
+
+int main(int argc, char** argv) {
+ InitGoogleTest(&argc, argv);
+ ABinderProcess_setThreadPoolMaxThreadCount(/* numThreads= */ 1);
+ ABinderProcess_startThreadPool();
+ return RUN_ALL_TESTS();
+}
+} // namespace android