1 /* 2 * Copyright (C) 2024 The Android Open Source Project * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <thread> 17 18 #include "utils.h" 19 #include "vibrator.h" 20 21 using std::chrono::milliseconds; 22 using std::this_thread::sleep_for; 23 24 namespace android { 25 namespace idlcli { 26 27 class CommandVibrator; 28 29 namespace vibrator { 30 31 using aidl::VendorEffect; 32 33 class CommandPerformVendorEffect : public Command { getDescription() const34 std::string getDescription() const override { return "Perform vendor vibration effect."; } 35 getUsageSummary() const36 std::string getUsageSummary() const override { return "[options] <none>"; } 37 getUsageDetails() const38 UsageDetails getUsageDetails() const override { 39 UsageDetails details{ 40 {"-b", {"Block for duration of vibration."}}, 41 {"<none>", {"No valid input."}}, 42 }; 43 return details; 44 } 45 doArgs(Args & args)46 Status doArgs(Args& args) override { 47 while (args.get<std::string>().value_or("").find("-") == 0) { 48 auto opt = *args.pop<std::string>(); 49 if (opt == "--") { 50 break; 51 } else if (opt == "-b") { 52 mBlocking = true; 53 } else { 54 std::cerr << "Invalid Option '" << opt << "'!" << std::endl; 55 return USAGE; 56 } 57 } 58 59 return OK; 60 } 61 doMain(Args &&)62 Status doMain(Args&& /*args*/) override { return UNAVAILABLE; } 63 64 bool mBlocking; 65 VendorEffect mEffect; 66 }; 67 68 static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandPerformVendorEffect>( 69 "performVendorEffect"); 70 71 } // namespace vibrator 72 } // namespace idlcli 73 } // namespace android 74