| Harpreet \"Eli\" Sangha | eb8505c | 2020-04-10 12:40:23 +0900 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2020 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 "utils.h" | 
|  | 17 | #include "vibrator.h" | 
|  | 18 |  | 
|  | 19 | namespace android { | 
|  | 20 | namespace idlcli { | 
|  | 21 |  | 
|  | 22 | class CommandVibrator; | 
|  | 23 |  | 
|  | 24 | namespace vibrator { | 
|  | 25 |  | 
|  | 26 | class CommandAlwaysOnDisable : public Command { | 
|  | 27 | std::string getDescription() const override { return "Disarm always-on haptic source."; } | 
|  | 28 |  | 
|  | 29 | std::string getUsageSummary() const override { return "<id>"; } | 
|  | 30 |  | 
|  | 31 | UsageDetails getUsageDetails() const override { | 
|  | 32 | UsageDetails details{ | 
|  | 33 | {"<id>", {"Source ID (device-specific)."}}, | 
|  | 34 | }; | 
|  | 35 | return details; | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | Status doArgs(Args &args) override { | 
|  | 39 | if (auto id = args.pop<decltype(mId)>()) { | 
|  | 40 | mId = *id; | 
|  | 41 | std::cout << "Source ID: " << mId << std::endl; | 
|  | 42 | } else { | 
|  | 43 | std::cerr << "Missing or Invalid Source ID!" << std::endl; | 
|  | 44 | return USAGE; | 
|  | 45 | } | 
|  | 46 | if (!args.empty()) { | 
|  | 47 | std::cerr << "Unexpected Arguments!" << std::endl; | 
|  | 48 | return USAGE; | 
|  | 49 | } | 
|  | 50 | return OK; | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | Status doMain(Args && /*args*/) override { | 
|  | 54 | std::string statusStr; | 
|  | 55 | Status ret; | 
|  | 56 |  | 
|  | 57 | if (auto hal = getHal<aidl::IVibrator>()) { | 
|  | 58 | auto status = hal->call(&aidl::IVibrator::alwaysOnDisable, mId); | 
|  | 59 |  | 
|  | 60 | statusStr = status.getDescription(); | 
|  | 61 | ret = status.isOk() ? OK : ERROR; | 
|  | 62 | } else { | 
|  | 63 | return UNAVAILABLE; | 
|  | 64 | } | 
|  | 65 |  | 
|  | 66 | std::cout << "Status: " << statusStr << std::endl; | 
|  | 67 |  | 
|  | 68 | return ret; | 
|  | 69 | } | 
|  | 70 |  | 
|  | 71 | int32_t mId; | 
|  | 72 | }; | 
|  | 73 |  | 
|  | 74 | static const auto Command = | 
|  | 75 | CommandRegistry<CommandVibrator>::Register<CommandAlwaysOnDisable>("alwaysOnDisable"); | 
|  | 76 |  | 
|  | 77 | } // namespace vibrator | 
|  | 78 | } // namespace idlcli | 
|  | 79 | } // namespace android |