Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32226c9b authored by Harpreet Eli Sangha's avatar Harpreet Eli Sangha Committed by chasewu
Browse files

idlcli: Add mutiple haptics command support



Bug: 176134689
Test: idlcli -n dual vibrator on 1000
Signed-off-by: default avatarchasewu <chasewu@google.com>
Change-Id: I499edd317db5858a2bc0cd76681c971926685c78
parent d4b67df6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ namespace idlcli {
class IdlCli;

class CommandVibrator : public CommandWithSubcommands<CommandVibrator> {
    std::string getDescription() const override { return "Invoke Vibrator HIDL APIs."; }
    std::string getDescription() const override { return "Invoke Vibrator IDL APIs."; }

    std::string getUsageSummary() const override { return "<api> [arguments]"; }

+34 −1
Original line number Diff line number Diff line
@@ -25,14 +25,47 @@ namespace idlcli {
class IdlCli : public CommandWithSubcommands<IdlCli> {
    std::string getDescription() const override { return "Invoke IDL APIs."; }

    std::string getUsageSummary() const override { return "<idl> [arguments]"; }
    std::string getUsageSummary() const override { return "<idl> [options] [arguments]"; }

    UsageDetails getUsageDetails() const override {
        UsageDetails details{
                {"-n <name>", {"Get named service, rather than default."}},
                {"<idl>", CommandRegistry<IdlCli>::List()},
        };
        return details;
    }

    Status doArgs(Args &args) override {
        while (args.get<std::string>().value_or("").find("-") == 0) {
            auto opt = *args.pop<std::string>();
            if (opt == "--") {
                break;
            } else if (opt == "-n") {
                if (auto name = args.pop<decltype(mName)>()) {
                    mName = *name;
                } else {
                    std::cerr << "Missing Value for Name!" << std::endl;
                    return USAGE;
                }
            } else {
                std::cerr << "Invalid Option '" << opt << "'!" << std::endl;
                return USAGE;
            }
        }
        return CommandWithSubcommands::doArgs(args);
    }

    IdlCli() {}

    std::string mName;

public:
    static IdlCli &Get() {
        static IdlCli instance;
        return instance;
    }

    auto getName() { return mName; }
};

} // namespace idlcli
+1 −1
Original line number Diff line number Diff line
@@ -19,5 +19,5 @@

int main(const int argc, const char* const argv[]) {
    using namespace ::android::idlcli;
    return IdlCli{}.main(Args{argc, argv});
    return IdlCli::Get().main(Args{argc, argv});
}
+1 −1
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ private:

template <typename T>
class CommandWithSubcommands : public Command {
private:
protected:
    Status doArgs(Args &args) override {
        mCommand = CommandRegistry<T>::Create(*args.get());
        if (!mCommand) {
+28 −15
Original line number Diff line number Diff line
@@ -13,24 +13,24 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_
#define FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_
#pragma once

#include <future>

#include <aidl/android/hardware/vibrator/BnVibratorCallback.h>
#include <aidl/android/hardware/vibrator/IVibrator.h>
#include <aidl/android/hardware/vibrator/IVibratorManager.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <android/hardware/vibrator/1.3/IVibrator.h>

#include "IdlCli.h"
#include "utils.h"

#include "log/log.h"

namespace android {

using hardware::Return;
using idlcli::IdlCli;

static constexpr int NUM_TRIES = 2;

@@ -47,20 +47,34 @@ inline ndk::ScopedAStatus NullptrStatus() {
}

template <typename I>
inline auto getService() {
    return I::getService();
inline auto getService(std::string name) {
    const auto instance = std::string() + I::descriptor + "/" + name;
    auto vibBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str()));
    return I::fromBinder(vibBinder);
}

template <>
inline auto getService<aidl::android::hardware::vibrator::IVibrator>() {
    const auto instance =
            std::string() + aidl::android::hardware::vibrator::IVibrator::descriptor + "/default";
    auto vibBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str()));
    return aidl::android::hardware::vibrator::IVibrator::fromBinder(vibBinder);
inline auto getService<android::hardware::vibrator::V1_0::IVibrator>(std::string name) {
    return android::hardware::vibrator::V1_0::IVibrator::getService(name);
}

template <>
inline auto getService<android::hardware::vibrator::V1_1::IVibrator>(std::string name) {
    return android::hardware::vibrator::V1_1::IVibrator::getService(name);
}

template <>
inline auto getService<android::hardware::vibrator::V1_2::IVibrator>(std::string name) {
    return android::hardware::vibrator::V1_2::IVibrator::getService(name);
}

template <>
inline auto getService<android::hardware::vibrator::V1_3::IVibrator>(std::string name) {
    return android::hardware::vibrator::V1_3::IVibrator::getService(name);
}

template <typename I>
using shared_ptr = std::result_of_t<decltype(getService<I>)&()>;
using shared_ptr = std::result_of_t<decltype(getService<I>)&(std::string)>;

template <typename I>
class HalWrapper {
@@ -68,7 +82,8 @@ public:
    static std::unique_ptr<HalWrapper> Create() {
        // Assume that if getService returns a nullptr, HAL is not available on the
        // device.
        auto hal = getService<I>();
        const auto name = IdlCli::Get().getName();
        auto hal = getService<I>(name.empty() ? "default" : name);
        return hal ? std::unique_ptr<HalWrapper>(new HalWrapper(std::move(hal))) : nullptr;
    }

@@ -121,5 +136,3 @@ private:
} // namespace idlcli

} // namespace android

#endif // FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_