From 16a489870823b83e6c64c94818be22caf8eb22d7 Mon Sep 17 00:00:00 2001 From: Ahmad Khalil Date: Sat, 9 Dec 2023 21:07:57 +0000 Subject: Introducing IVibratorController and IVibratorControlService We're adding IVibratorController.aidl and IVibratorControlService.aidl to allow the HAL to set haptic intensity through VibrationParams. Bug: 305961689 Test: run vts --module VtsHalVibratorControlServiceTargetTest Change-Id: Ib1ef8fa4095b8f39cc68331637b0347f59ebe5a6 --- vibrator/OWNERS | 2 + vibrator/aidl/Android.bp | 40 ++++++ vibrator/aidl/TEST_MAPPING | 7 + .../vibrator/IVibratorControlService.aidl | 43 ++++++ .../frameworks/vibrator/IVibratorController.aidl | 39 ++++++ .../android/frameworks/vibrator/ScaleParam.aidl | 44 ++++++ .../frameworks/vibrator/VibrationParam.aidl | 38 ++++++ .../vibrator/IVibratorControlService.aidl | 77 +++++++++++ .../frameworks/vibrator/IVibratorController.aidl | 39 ++++++ .../android/frameworks/vibrator/ScaleParam.aidl | 33 +++++ .../frameworks/vibrator/VibrationParam.aidl | 27 ++++ vibrator/aidl/vts/functional/Android.bp | 44 ++++++ .../VtsHalVibratorControlServiceTargetTest.cpp | 149 +++++++++++++++++++++ 13 files changed, 582 insertions(+) create mode 100644 vibrator/OWNERS create mode 100644 vibrator/aidl/Android.bp create mode 100644 vibrator/aidl/TEST_MAPPING create mode 100644 vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorControlService.aidl create mode 100644 vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/IVibratorController.aidl create mode 100644 vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/ScaleParam.aidl create mode 100644 vibrator/aidl/aidl_api/android.frameworks.vibrator/current/android/frameworks/vibrator/VibrationParam.aidl create mode 100644 vibrator/aidl/android/frameworks/vibrator/IVibratorControlService.aidl create mode 100644 vibrator/aidl/android/frameworks/vibrator/IVibratorController.aidl create mode 100644 vibrator/aidl/android/frameworks/vibrator/ScaleParam.aidl create mode 100644 vibrator/aidl/android/frameworks/vibrator/VibrationParam.aidl create mode 100644 vibrator/aidl/vts/functional/Android.bp create mode 100644 vibrator/aidl/vts/functional/VtsHalVibratorControlServiceTargetTest.cpp 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 -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 -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 -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 -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. + *

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. + *

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. + *

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. + *

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. + *

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. + *

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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 generateVibrationParams(int in_typesMask, float scale) { + ScaleParam scaleParam = ScaleParam(); + scaleParam.typesMask = in_typesMask; + scaleParam.scale = scale; + VibrationParam vibrationParam = VibrationParam(scaleParam); + std::vector 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 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 { + public: + void SetUp() override { + SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str())); + service = IVibratorControlService::fromBinder(binder); + ASSERT_NE(service, nullptr); + } + + std::shared_ptr service; +}; + +TEST_P(VibratorControlServiceTest, RegisterVibrationControllerTest) { + std::shared_ptr vibratorController = + ::ndk::SharedRefBase::make(); + + EXPECT_TRUE(service->registerVibratorController(vibratorController).isOk()); + + EXPECT_TRUE(service->unregisterVibratorController(vibratorController).isOk()); +} + +TEST_P(VibratorControlServiceTest, RequestVibrationParamsTest) { + std::shared_ptr vibratorController = + ::ndk::SharedRefBase::make(); + + 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 vibratorController = + ::ndk::SharedRefBase::make(); + + 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 -- cgit v1.2.3