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

Commit 7766c03e authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Use NamedEnum for printing Entry type

Currently, we are using InputMessage::typeToString, a manually written
function, to print the entry type.

Let's use "NamedEnum" instead to simplify the process of adding new
types.

Bug: 167947340
Test: compile only
Change-Id: I26d0a469bf93adbe2795d8a378c25e6ded891274
parent 86d048d6
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -181,21 +181,6 @@ struct InputMessage {
    bool isValid(size_t actualSize) const;
    size_t size() const;
    void getSanitizedCopy(InputMessage* msg) const;

    static const char* typeToString(Type type) {
        switch (type) {
            case Type::KEY:
                return "KEY";
            case Type::MOTION:
                return "MOTION";
            case Type::FINISHED:
                return "FINISHED";
            case Type::FOCUS:
                return "FOCUS";
            case Type::CAPTURE:
                return "CAPTURE";
        }
    }
};

/*
+3 −3
Original line number Diff line number Diff line
@@ -83,13 +83,13 @@ cc_library {
                "InputWindow.cpp",
                "android/FocusRequest.aidl",
                "android/InputApplicationInfo.aidl",
                "android/os/BlockUntrustedTouchesMode.aidl",
                "android/os/IInputConstants.aidl",
                "android/os/IInputFlinger.aidl",
                "android/os/InputEventInjectionResult.aidl",
                "android/os/InputEventInjectionSync.aidl",
                "android/os/TouchOcclusionMode.aidl",
                "android/os/BlockUntrustedTouchesMode.aidl",
                "android/os/IInputFlinger.aidl",
                "android/os/ISetInputWindowsListener.aidl",
                "android/os/TouchOcclusionMode.aidl",
            ],

            export_shared_lib_headers: ["libbinder"],
+8 −6
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ static constexpr bool DEBUG_TRANSPORT_ACTIONS = false;
#include <utils/Trace.h>

#include <input/InputTransport.h>
#include <input/NamedEnum.h>

using android::base::StringPrintf;

@@ -610,8 +611,8 @@ status_t InputPublisher::receiveFinishedSignal(
        return result;
    }
    if (msg.header.type != InputMessage::Type::FINISHED) {
        ALOGE("channel '%s' publisher ~ Received unexpected message of type %d from consumer",
                mChannel->getName().c_str(), msg.header.type);
        ALOGE("channel '%s' publisher ~ Received unexpected %s message from consumer",
              mChannel->getName().c_str(), NamedEnum::string(msg.header.type).c_str());
        return UNKNOWN_ERROR;
    }
    callback(msg.header.seq, msg.body.finished.handled == 1, msg.body.finished.consumeTime);
@@ -753,8 +754,9 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum
            }

            case InputMessage::Type::FINISHED: {
                LOG_ALWAYS_FATAL("Consumed a FINISHED message, which should never be seen by "
                                 "InputConsumer!");
                LOG_ALWAYS_FATAL("Consumed a %s message, which should never be seen by "
                                 "InputConsumer!",
                                 NamedEnum::string(mMsg.header.type).c_str());
                break;
            }

@@ -1299,14 +1301,14 @@ std::string InputConsumer::dump() const {
    out = out + "mChannel = " + mChannel->getName() + "\n";
    out = out + "mMsgDeferred: " + toString(mMsgDeferred) + "\n";
    if (mMsgDeferred) {
        out = out + "mMsg : " + InputMessage::typeToString(mMsg.header.type) + "\n";
        out = out + "mMsg : " + NamedEnum::string(mMsg.header.type) + "\n";
    }
    out += "Batches:\n";
    for (const Batch& batch : mBatches) {
        out += "    Batch:\n";
        for (const InputMessage& msg : batch.samples) {
            out += android::base::StringPrintf("        Message %" PRIu32 ": %s ", msg.header.seq,
                                               InputMessage::typeToString(msg.header.type));
                                               NamedEnum::string(msg.header.type).c_str());
            switch (msg.header.type) {
                case InputMessage::Type::KEY: {
                    out += android::base::StringPrintf("action=%s keycode=%" PRId32,
+6 −6
Original line number Diff line number Diff line
@@ -43,19 +43,19 @@ public:

    InputFlinger() ANDROID_API;

    virtual status_t dump(int fd, const Vector<String16>& args);
    status_t dump(int fd, const Vector<String16>& args) override;
    binder::Status setInputWindows(const std::vector<InputWindowInfo>&,
                                   const sp<ISetInputWindowsListener>&) {
                                   const sp<ISetInputWindowsListener>&) override {
        return binder::Status::ok();
    }
    binder::Status createInputChannel(const std::string&, InputChannel*) {
    binder::Status createInputChannel(const std::string&, InputChannel*) override {
        return binder::Status::ok();
    }
    binder::Status removeInputChannel(const sp<IBinder>&) { return binder::Status::ok(); }
    binder::Status setFocusedWindow(const FocusRequest&) { return binder::Status::ok(); }
    binder::Status removeInputChannel(const sp<IBinder>&) override { return binder::Status::ok(); }
    binder::Status setFocusedWindow(const FocusRequest&) override { return binder::Status::ok(); }

private:
    virtual ~InputFlinger();
    ~InputFlinger() override;

    void dumpInternal(String8& result);