Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include <aidl/Gtest.h> |
| 17 | #include <aidl/Vintf.h> |
| 18 | |
| 19 | #include <android/hardware/vibrator/BnVibratorCallback.h> |
| 20 | #include <android/hardware/vibrator/IVibrator.h> |
| 21 | #include <binder/IServiceManager.h> |
| 22 | #include <binder/ProcessState.h> |
| 23 | |
| 24 | #include <future> |
| 25 | |
| 26 | using android::ProcessState; |
| 27 | using android::sp; |
| 28 | using android::String16; |
| 29 | using android::binder::Status; |
| 30 | using android::hardware::vibrator::BnVibratorCallback; |
Harpreet \"Eli\" Sangha | f4de5b0 | 2019-10-23 09:25:52 +0900 | [diff] [blame] | 31 | using android::hardware::vibrator::CompositeEffect; |
| 32 | using android::hardware::vibrator::CompositePrimitive; |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 33 | using android::hardware::vibrator::Effect; |
| 34 | using android::hardware::vibrator::EffectStrength; |
| 35 | using android::hardware::vibrator::IVibrator; |
| 36 | |
Jooyung Han | 716648d | 2019-12-17 14:17:48 +0000 | [diff] [blame] | 37 | const std::vector<Effect> kEffects{android::enum_range<Effect>().begin(), |
| 38 | android::enum_range<Effect>().end()}; |
| 39 | const std::vector<EffectStrength> kEffectStrengths{android::enum_range<EffectStrength>().begin(), |
| 40 | android::enum_range<EffectStrength>().end()}; |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 41 | |
| 42 | const std::vector<Effect> kInvalidEffects = { |
Steven Moreland | f335388 | 2019-11-07 17:02:43 -0800 | [diff] [blame] | 43 | static_cast<Effect>(static_cast<int32_t>(kEffects.front()) - 1), |
| 44 | static_cast<Effect>(static_cast<int32_t>(kEffects.back()) + 1), |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | const std::vector<EffectStrength> kInvalidEffectStrengths = { |
Steven Moreland | f335388 | 2019-11-07 17:02:43 -0800 | [diff] [blame] | 48 | static_cast<EffectStrength>(static_cast<int8_t>(kEffectStrengths.front()) - 1), |
| 49 | static_cast<EffectStrength>(static_cast<int8_t>(kEffectStrengths.back()) + 1), |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Harpreet \"Eli\" Sangha | f4de5b0 | 2019-10-23 09:25:52 +0900 | [diff] [blame] | 52 | // TODO(b/143992652): autogenerate |
| 53 | const std::vector<CompositePrimitive> kCompositePrimitives = { |
| 54 | CompositePrimitive::NOOP, CompositePrimitive::CLICK, |
| 55 | CompositePrimitive::THUD, CompositePrimitive::SPIN, |
| 56 | CompositePrimitive::QUICK_RISE, CompositePrimitive::SLOW_RISE, |
| 57 | CompositePrimitive::QUICK_FALL, |
| 58 | }; |
| 59 | // TODO(b/143992652): autogenerate |
| 60 | |
| 61 | const std::vector<CompositePrimitive> kInvalidPrimitives = { |
| 62 | static_cast<CompositePrimitive>(static_cast<int32_t>(kCompositePrimitives.front()) - 1), |
| 63 | static_cast<CompositePrimitive>(static_cast<int32_t>(kCompositePrimitives.back()) + 1), |
| 64 | }; |
| 65 | |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 66 | class CompletionCallback : public BnVibratorCallback { |
| 67 | public: |
| 68 | CompletionCallback(const std::function<void()>& callback) : mCallback(callback) {} |
| 69 | Status onComplete() override { |
| 70 | mCallback(); |
| 71 | return Status::ok(); |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | std::function<void()> mCallback; |
| 76 | }; |
| 77 | |
| 78 | class VibratorAidl : public testing::TestWithParam<std::string> { |
| 79 | public: |
| 80 | virtual void SetUp() override { |
| 81 | vibrator = android::waitForDeclaredService<IVibrator>(String16(GetParam().c_str())); |
| 82 | ASSERT_NE(vibrator, nullptr); |
| 83 | ASSERT_TRUE(vibrator->getCapabilities(&capabilities).isOk()); |
| 84 | } |
| 85 | |
| 86 | sp<IVibrator> vibrator; |
| 87 | int32_t capabilities; |
| 88 | }; |
| 89 | |
| 90 | TEST_P(VibratorAidl, OnThenOffBeforeTimeout) { |
| 91 | EXPECT_TRUE(vibrator->on(2000, nullptr /*callback*/).isOk()); |
| 92 | sleep(1); |
| 93 | EXPECT_TRUE(vibrator->off().isOk()); |
| 94 | } |
| 95 | |
| 96 | TEST_P(VibratorAidl, OnWithCallback) { |
| 97 | if (!(capabilities & IVibrator::CAP_PERFORM_CALLBACK)) return; |
| 98 | |
| 99 | std::promise<void> completionPromise; |
| 100 | std::future<void> completionFuture{completionPromise.get_future()}; |
| 101 | sp<CompletionCallback> callback = |
| 102 | new CompletionCallback([&completionPromise] { completionPromise.set_value(); }); |
| 103 | uint32_t durationMs = 250; |
| 104 | std::chrono::milliseconds timeout{durationMs * 2}; |
| 105 | EXPECT_TRUE(vibrator->on(durationMs, callback).isOk()); |
| 106 | EXPECT_EQ(completionFuture.wait_for(timeout), std::future_status::ready); |
| 107 | EXPECT_TRUE(vibrator->off().isOk()); |
| 108 | } |
| 109 | |
| 110 | TEST_P(VibratorAidl, OnCallbackNotSupported) { |
| 111 | if (!(capabilities & IVibrator::CAP_PERFORM_CALLBACK)) { |
| 112 | sp<CompletionCallback> callback = new CompletionCallback([] {}); |
| 113 | EXPECT_EQ(Status::EX_UNSUPPORTED_OPERATION, vibrator->on(250, callback).exceptionCode()); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | TEST_P(VibratorAidl, ValidateEffect) { |
Steven Moreland | 2932b22 | 2019-11-05 14:30:17 -0800 | [diff] [blame] | 118 | std::vector<Effect> supported; |
| 119 | ASSERT_TRUE(vibrator->getSupportedEffects(&supported).isOk()); |
| 120 | |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 121 | for (Effect effect : kEffects) { |
Steven Moreland | 2932b22 | 2019-11-05 14:30:17 -0800 | [diff] [blame] | 122 | bool isEffectSupported = |
| 123 | std::find(supported.begin(), supported.end(), effect) != supported.end(); |
| 124 | |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 125 | for (EffectStrength strength : kEffectStrengths) { |
| 126 | int32_t lengthMs = 0; |
| 127 | Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs); |
Steven Moreland | 2932b22 | 2019-11-05 14:30:17 -0800 | [diff] [blame] | 128 | |
| 129 | if (isEffectSupported) { |
Harpreet \"Eli\" Sangha | e1723a4 | 2019-12-06 14:09:33 +0900 | [diff] [blame] | 130 | EXPECT_TRUE(status.isOk()) << toString(effect) << " " << toString(strength); |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 131 | EXPECT_GT(lengthMs, 0); |
Steven Moreland | f335388 | 2019-11-07 17:02:43 -0800 | [diff] [blame] | 132 | usleep(lengthMs * 1000); |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 133 | } else { |
Steven Moreland | f335388 | 2019-11-07 17:02:43 -0800 | [diff] [blame] | 134 | EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION) |
Harpreet \"Eli\" Sangha | e1723a4 | 2019-12-06 14:09:33 +0900 | [diff] [blame] | 135 | << toString(effect) << " " << toString(strength); |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 136 | EXPECT_EQ(lengthMs, 0); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | TEST_P(VibratorAidl, ValidateEffectWithCallback) { |
| 143 | if (!(capabilities & IVibrator::CAP_PERFORM_CALLBACK)) return; |
| 144 | |
Steven Moreland | 2932b22 | 2019-11-05 14:30:17 -0800 | [diff] [blame] | 145 | std::vector<Effect> supported; |
| 146 | ASSERT_TRUE(vibrator->getSupportedEffects(&supported).isOk()); |
| 147 | |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 148 | for (Effect effect : kEffects) { |
Steven Moreland | 2932b22 | 2019-11-05 14:30:17 -0800 | [diff] [blame] | 149 | bool isEffectSupported = |
| 150 | std::find(supported.begin(), supported.end(), effect) != supported.end(); |
| 151 | |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 152 | for (EffectStrength strength : kEffectStrengths) { |
| 153 | std::promise<void> completionPromise; |
| 154 | std::future<void> completionFuture{completionPromise.get_future()}; |
| 155 | sp<CompletionCallback> callback = |
| 156 | new CompletionCallback([&completionPromise] { completionPromise.set_value(); }); |
Steven Moreland | 2932b22 | 2019-11-05 14:30:17 -0800 | [diff] [blame] | 157 | int lengthMs = 0; |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 158 | Status status = vibrator->perform(effect, strength, callback, &lengthMs); |
Steven Moreland | 2932b22 | 2019-11-05 14:30:17 -0800 | [diff] [blame] | 159 | |
| 160 | if (isEffectSupported) { |
| 161 | EXPECT_TRUE(status.isOk()); |
| 162 | EXPECT_GT(lengthMs, 0); |
| 163 | } else { |
| 164 | EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION); |
| 165 | EXPECT_EQ(lengthMs, 0); |
| 166 | } |
| 167 | |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 168 | if (!status.isOk()) continue; |
| 169 | |
| 170 | std::chrono::milliseconds timeout{lengthMs * 2}; |
| 171 | EXPECT_EQ(completionFuture.wait_for(timeout), std::future_status::ready); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | TEST_P(VibratorAidl, ValidateEffectWithCallbackNotSupported) { |
| 177 | if (capabilities & IVibrator::CAP_PERFORM_CALLBACK) return; |
| 178 | |
| 179 | for (Effect effect : kEffects) { |
| 180 | for (EffectStrength strength : kEffectStrengths) { |
| 181 | sp<CompletionCallback> callback = new CompletionCallback([] {}); |
| 182 | int lengthMs; |
| 183 | Status status = vibrator->perform(effect, strength, callback, &lengthMs); |
| 184 | EXPECT_EQ(Status::EX_UNSUPPORTED_OPERATION, status.exceptionCode()); |
| 185 | EXPECT_EQ(lengthMs, 0); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | TEST_P(VibratorAidl, InvalidEffectsUnsupported) { |
| 191 | for (Effect effect : kInvalidEffects) { |
Steven Moreland | f335388 | 2019-11-07 17:02:43 -0800 | [diff] [blame] | 192 | for (EffectStrength strength : kEffectStrengths) { |
| 193 | int32_t lengthMs; |
| 194 | Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs); |
| 195 | EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION) |
Harpreet \"Eli\" Sangha | e1723a4 | 2019-12-06 14:09:33 +0900 | [diff] [blame] | 196 | << toString(effect) << " " << toString(strength); |
Steven Moreland | f335388 | 2019-11-07 17:02:43 -0800 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | for (Effect effect : kEffects) { |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 200 | for (EffectStrength strength : kInvalidEffectStrengths) { |
| 201 | int32_t lengthMs; |
| 202 | Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs); |
Steven Moreland | f335388 | 2019-11-07 17:02:43 -0800 | [diff] [blame] | 203 | EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION) |
Harpreet \"Eli\" Sangha | e1723a4 | 2019-12-06 14:09:33 +0900 | [diff] [blame] | 204 | << toString(effect) << " " << toString(strength); |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | TEST_P(VibratorAidl, ChangeVibrationAmplitude) { |
| 210 | if (capabilities & IVibrator::CAP_AMPLITUDE_CONTROL) { |
Harpreet \"Eli\" Sangha | f4de5b0 | 2019-10-23 09:25:52 +0900 | [diff] [blame] | 211 | EXPECT_EQ(Status::EX_NONE, vibrator->setAmplitude(0.1f).exceptionCode()); |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 212 | EXPECT_TRUE(vibrator->on(2000, nullptr /*callback*/).isOk()); |
Harpreet \"Eli\" Sangha | f4de5b0 | 2019-10-23 09:25:52 +0900 | [diff] [blame] | 213 | EXPECT_EQ(Status::EX_NONE, vibrator->setAmplitude(0.5f).exceptionCode()); |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 214 | sleep(1); |
Harpreet \"Eli\" Sangha | f4de5b0 | 2019-10-23 09:25:52 +0900 | [diff] [blame] | 215 | EXPECT_EQ(Status::EX_NONE, vibrator->setAmplitude(1.0f).exceptionCode()); |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 216 | sleep(1); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | TEST_P(VibratorAidl, AmplitudeOutsideRangeFails) { |
| 221 | if (capabilities & IVibrator::CAP_AMPLITUDE_CONTROL) { |
| 222 | EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, vibrator->setAmplitude(-1).exceptionCode()); |
| 223 | EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, vibrator->setAmplitude(0).exceptionCode()); |
Harpreet \"Eli\" Sangha | f4de5b0 | 2019-10-23 09:25:52 +0900 | [diff] [blame] | 224 | EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, vibrator->setAmplitude(1.1).exceptionCode()); |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | TEST_P(VibratorAidl, AmplitudeReturnsUnsupportedMatchingCapabilities) { |
| 229 | if ((capabilities & IVibrator::CAP_AMPLITUDE_CONTROL) == 0) { |
| 230 | EXPECT_EQ(Status::EX_UNSUPPORTED_OPERATION, vibrator->setAmplitude(1).exceptionCode()); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | TEST_P(VibratorAidl, ChangeVibrationExternalControl) { |
| 235 | if (capabilities & IVibrator::CAP_EXTERNAL_CONTROL) { |
| 236 | EXPECT_TRUE(vibrator->setExternalControl(true).isOk()); |
| 237 | sleep(1); |
| 238 | EXPECT_TRUE(vibrator->setExternalControl(false).isOk()); |
| 239 | sleep(1); |
| 240 | } |
| 241 | } |
| 242 | |
Steven Moreland | c0b92d5 | 2019-11-05 13:31:41 -0800 | [diff] [blame] | 243 | TEST_P(VibratorAidl, ExternalAmplitudeControl) { |
| 244 | const bool supportsExternalAmplitudeControl = |
| 245 | (capabilities & IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL) > 0; |
| 246 | |
| 247 | if (capabilities & IVibrator::CAP_EXTERNAL_CONTROL) { |
| 248 | EXPECT_TRUE(vibrator->setExternalControl(true).isOk()); |
| 249 | |
Harpreet \"Eli\" Sangha | f4de5b0 | 2019-10-23 09:25:52 +0900 | [diff] [blame] | 250 | Status amplitudeStatus = vibrator->setAmplitude(0.5); |
Steven Moreland | c0b92d5 | 2019-11-05 13:31:41 -0800 | [diff] [blame] | 251 | if (supportsExternalAmplitudeControl) { |
| 252 | EXPECT_TRUE(amplitudeStatus.isOk()); |
| 253 | } else { |
| 254 | EXPECT_EQ(amplitudeStatus.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION); |
| 255 | } |
| 256 | EXPECT_TRUE(vibrator->setExternalControl(false).isOk()); |
| 257 | } else { |
| 258 | EXPECT_FALSE(supportsExternalAmplitudeControl); |
| 259 | } |
| 260 | } |
| 261 | |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 262 | TEST_P(VibratorAidl, ExternalControlUnsupportedMatchingCapabilities) { |
| 263 | if ((capabilities & IVibrator::CAP_EXTERNAL_CONTROL) == 0) { |
| 264 | EXPECT_EQ(Status::EX_UNSUPPORTED_OPERATION, |
| 265 | vibrator->setExternalControl(true).exceptionCode()); |
| 266 | } |
| 267 | } |
| 268 | |
Harpreet \"Eli\" Sangha | f4de5b0 | 2019-10-23 09:25:52 +0900 | [diff] [blame] | 269 | TEST_P(VibratorAidl, ComposeValidPrimitives) { |
| 270 | if (capabilities & IVibrator::CAP_COMPOSE_EFFECTS) { |
| 271 | int32_t maxDelay, maxSize; |
| 272 | |
| 273 | EXPECT_EQ(Status::EX_NONE, vibrator->getCompositionDelayMax(&maxDelay).exceptionCode()); |
| 274 | EXPECT_EQ(Status::EX_NONE, vibrator->getCompositionSizeMax(&maxSize).exceptionCode()); |
| 275 | |
| 276 | std::vector<CompositeEffect> composite; |
| 277 | |
| 278 | for (auto primitive : kCompositePrimitives) { |
| 279 | CompositeEffect effect; |
| 280 | |
| 281 | effect.delayMs = std::rand() % (maxDelay + 1); |
| 282 | effect.primitive = primitive; |
| 283 | effect.scale = static_cast<float>(std::rand()) / RAND_MAX ?: 1.0f; |
| 284 | composite.emplace_back(effect); |
| 285 | |
| 286 | if (composite.size() == maxSize) { |
| 287 | EXPECT_EQ(Status::EX_NONE, vibrator->compose(composite, nullptr).exceptionCode()); |
| 288 | composite.clear(); |
| 289 | vibrator->off(); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if (composite.size() != 0) { |
| 294 | EXPECT_EQ(Status::EX_NONE, vibrator->compose(composite, nullptr).exceptionCode()); |
| 295 | vibrator->off(); |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | TEST_P(VibratorAidl, ComposeUnsupportedPrimitives) { |
| 301 | if (capabilities & IVibrator::CAP_COMPOSE_EFFECTS) { |
| 302 | for (auto primitive : kInvalidPrimitives) { |
| 303 | std::vector<CompositeEffect> composite(1); |
| 304 | |
| 305 | for (auto& effect : composite) { |
| 306 | effect.delayMs = 0; |
| 307 | effect.primitive = primitive; |
| 308 | effect.scale = 1.0f; |
| 309 | } |
| 310 | EXPECT_EQ(Status::EX_UNSUPPORTED_OPERATION, |
| 311 | vibrator->compose(composite, nullptr).exceptionCode()); |
| 312 | vibrator->off(); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | TEST_P(VibratorAidl, CompseDelayBoundary) { |
| 318 | if (capabilities & IVibrator::CAP_COMPOSE_EFFECTS) { |
| 319 | int32_t maxDelay; |
| 320 | |
| 321 | EXPECT_EQ(Status::EX_NONE, vibrator->getCompositionDelayMax(&maxDelay).exceptionCode()); |
| 322 | |
| 323 | std::vector<CompositeEffect> composite(1); |
| 324 | CompositeEffect effect; |
| 325 | |
| 326 | effect.delayMs = 1; |
| 327 | effect.primitive = CompositePrimitive::CLICK; |
| 328 | effect.scale = 1.0f; |
| 329 | |
| 330 | std::fill(composite.begin(), composite.end(), effect); |
| 331 | EXPECT_EQ(Status::EX_NONE, vibrator->compose(composite, nullptr).exceptionCode()); |
| 332 | |
| 333 | effect.delayMs = maxDelay + 1; |
| 334 | |
| 335 | std::fill(composite.begin(), composite.end(), effect); |
| 336 | EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, |
| 337 | vibrator->compose(composite, nullptr).exceptionCode()); |
| 338 | vibrator->off(); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | TEST_P(VibratorAidl, CompseSizeBoundary) { |
| 343 | if (capabilities & IVibrator::CAP_COMPOSE_EFFECTS) { |
| 344 | int32_t maxSize; |
| 345 | |
| 346 | EXPECT_EQ(Status::EX_NONE, vibrator->getCompositionSizeMax(&maxSize).exceptionCode()); |
| 347 | |
| 348 | std::vector<CompositeEffect> composite(maxSize); |
| 349 | CompositeEffect effect; |
| 350 | |
| 351 | effect.delayMs = 1; |
| 352 | effect.primitive = CompositePrimitive::CLICK; |
| 353 | effect.scale = 1.0f; |
| 354 | |
| 355 | std::fill(composite.begin(), composite.end(), effect); |
| 356 | EXPECT_EQ(Status::EX_NONE, vibrator->compose(composite, nullptr).exceptionCode()); |
| 357 | |
| 358 | composite.emplace_back(effect); |
| 359 | EXPECT_EQ(Status::EX_ILLEGAL_ARGUMENT, |
| 360 | vibrator->compose(composite, nullptr).exceptionCode()); |
| 361 | vibrator->off(); |
| 362 | } |
| 363 | } |
| 364 | |
Harpreet \"Eli\" Sangha | 6362409 | 2019-09-09 11:04:54 +0900 | [diff] [blame] | 365 | TEST_P(VibratorAidl, AlwaysOn) { |
| 366 | if (capabilities & IVibrator::CAP_ALWAYS_ON_CONTROL) { |
| 367 | std::vector<Effect> supported; |
| 368 | ASSERT_TRUE(vibrator->getSupportedAlwaysOnEffects(&supported).isOk()); |
| 369 | |
| 370 | for (Effect effect : kEffects) { |
| 371 | bool isEffectSupported = |
| 372 | std::find(supported.begin(), supported.end(), effect) != supported.end(); |
| 373 | |
| 374 | for (EffectStrength strength : kEffectStrengths) { |
| 375 | Status status = vibrator->alwaysOnEnable(0, effect, strength); |
| 376 | |
| 377 | if (isEffectSupported) { |
| 378 | EXPECT_EQ(Status::EX_NONE, status.exceptionCode()) |
| 379 | << toString(effect) << " " << toString(strength); |
| 380 | } else { |
| 381 | EXPECT_EQ(Status::EX_UNSUPPORTED_OPERATION, status.exceptionCode()) |
| 382 | << toString(effect) << " " << toString(strength); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | EXPECT_EQ(Status::EX_NONE, vibrator->alwaysOnDisable(0).exceptionCode()); |
| 388 | } |
| 389 | } |
| 390 | |
Haibo Huang | 83b4c1e | 2019-11-08 11:59:40 -0800 | [diff] [blame] | 391 | INSTANTIATE_TEST_SUITE_P(Vibrator, VibratorAidl, |
Steven Moreland | d44007e | 2019-10-24 18:12:46 -0700 | [diff] [blame] | 392 | testing::ValuesIn(android::getAidlHalInstanceNames(IVibrator::descriptor)), |
| 393 | android::PrintInstanceNameToString); |
| 394 | |
| 395 | int main(int argc, char** argv) { |
| 396 | ::testing::InitGoogleTest(&argc, argv); |
| 397 | ProcessState::self()->setThreadPoolMaxThreadCount(1); |
| 398 | ProcessState::self()->startThreadPool(); |
| 399 | return RUN_ALL_TESTS(); |
| 400 | } |