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

Commit f93fcf4c authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Prefer std::string over String8

String8 is obsolete, only use std::string in the
input libraries now.

Bug: 64258224
Test: make
Change-Id: I958b6b281d969138f39cc26825c877a24bc4a853
parent 236c2711
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@
#include <utils/Errors.h>
#include <utils/Timers.h>
#include <utils/RefBase.h>
#include <utils/String8.h>
#include <utils/Vector.h>
#include <utils/BitSet.h>

@@ -142,16 +141,16 @@ protected:
    virtual ~InputChannel();

public:
    InputChannel(const String8& name, int fd);
    InputChannel(const std::string& name, int fd);

    /* Creates a pair of input channels.
     *
     * Returns OK on success.
     */
    static status_t openInputChannelPair(const String8& name,
    static status_t openInputChannelPair(const std::string& name,
            sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel);

    inline String8 getName() const { return mName; }
    inline std::string getName() const { return mName; }
    inline int getFd() const { return mFd; }

    /* Sends a message to the other endpoint.
@@ -183,7 +182,7 @@ public:
    sp<InputChannel> dup() const;

private:
    String8 mName;
    std::string mName;
    int mFd;
};

+31 −31
Original line number Diff line number Diff line
@@ -99,34 +99,34 @@ size_t InputMessage::size() const {

// --- InputChannel ---

InputChannel::InputChannel(const String8& name, int fd) :
InputChannel::InputChannel(const std::string& name, int fd) :
        mName(name), mFd(fd) {
#if DEBUG_CHANNEL_LIFECYCLE
    ALOGD("Input channel constructed: name='%s', fd=%d",
            mName.string(), fd);
            mName.c_str(), fd);
#endif

    int result = fcntl(mFd, F_SETFL, O_NONBLOCK);
    LOG_ALWAYS_FATAL_IF(result != 0, "channel '%s' ~ Could not make socket "
            "non-blocking.  errno=%d", mName.string(), errno);
            "non-blocking.  errno=%d", mName.c_str(), errno);
}

InputChannel::~InputChannel() {
#if DEBUG_CHANNEL_LIFECYCLE
    ALOGD("Input channel destroyed: name='%s', fd=%d",
            mName.string(), mFd);
            mName.c_str(), mFd);
#endif

    ::close(mFd);
}

status_t InputChannel::openInputChannelPair(const String8& name,
status_t InputChannel::openInputChannelPair(const std::string& name,
        sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel) {
    int sockets[2];
    if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) {
        status_t result = -errno;
        ALOGE("channel '%s' ~ Could not create socket pair.  errno=%d",
                name.string(), errno);
                name.c_str(), errno);
        outServerChannel.clear();
        outClientChannel.clear();
        return result;
@@ -138,12 +138,12 @@ status_t InputChannel::openInputChannelPair(const String8& name,
    setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize));
    setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize));

    String8 serverChannelName = name;
    serverChannelName.append(" (server)");
    std::string serverChannelName = name;
    serverChannelName += " (server)";
    outServerChannel = new InputChannel(serverChannelName, sockets[0]);

    String8 clientChannelName = name;
    clientChannelName.append(" (client)");
    std::string clientChannelName = name;
    clientChannelName += " (client)";
    outClientChannel = new InputChannel(clientChannelName, sockets[1]);
    return OK;
}
@@ -158,7 +158,7 @@ status_t InputChannel::sendMessage(const InputMessage* msg) {
    if (nWrite < 0) {
        int error = errno;
#if DEBUG_CHANNEL_MESSAGES
        ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.string(),
        ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.c_str(),
                msg->header.type, error);
#endif
        if (error == EAGAIN || error == EWOULDBLOCK) {
@@ -173,13 +173,13 @@ status_t InputChannel::sendMessage(const InputMessage* msg) {
    if (size_t(nWrite) != msgLength) {
#if DEBUG_CHANNEL_MESSAGES
        ALOGD("channel '%s' ~ error sending message type %d, send was incomplete",
                mName.string(), msg->header.type);
                mName.c_str(), msg->header.type);
#endif
        return DEAD_OBJECT;
    }

#if DEBUG_CHANNEL_MESSAGES
    ALOGD("channel '%s' ~ sent message of type %d", mName.string(), msg->header.type);
    ALOGD("channel '%s' ~ sent message of type %d", mName.c_str(), msg->header.type);
#endif
    return OK;
}
@@ -193,7 +193,7 @@ status_t InputChannel::receiveMessage(InputMessage* msg) {
    if (nRead < 0) {
        int error = errno;
#if DEBUG_CHANNEL_MESSAGES
        ALOGD("channel '%s' ~ receive message failed, errno=%d", mName.string(), errno);
        ALOGD("channel '%s' ~ receive message failed, errno=%d", mName.c_str(), errno);
#endif
        if (error == EAGAIN || error == EWOULDBLOCK) {
            return WOULD_BLOCK;
@@ -206,20 +206,20 @@ status_t InputChannel::receiveMessage(InputMessage* msg) {

    if (nRead == 0) { // check for EOF
#if DEBUG_CHANNEL_MESSAGES
        ALOGD("channel '%s' ~ receive message failed because peer was closed", mName.string());
        ALOGD("channel '%s' ~ receive message failed because peer was closed", mName.c_str());
#endif
        return DEAD_OBJECT;
    }

    if (!msg->isValid(nRead)) {
#if DEBUG_CHANNEL_MESSAGES
        ALOGD("channel '%s' ~ received invalid message", mName.string());
        ALOGD("channel '%s' ~ received invalid message", mName.c_str());
#endif
        return BAD_VALUE;
    }

#if DEBUG_CHANNEL_MESSAGES
    ALOGD("channel '%s' ~ received message of type %d", mName.string(), msg->header.type);
    ALOGD("channel '%s' ~ received message of type %d", mName.c_str(), msg->header.type);
#endif
    return OK;
}
@@ -255,7 +255,7 @@ status_t InputPublisher::publishKeyEvent(
    ALOGD("channel '%s' publisher ~ publishKeyEvent: seq=%u, deviceId=%d, source=0x%x, "
            "action=0x%x, flags=0x%x, keyCode=%d, scanCode=%d, metaState=0x%x, repeatCount=%d,"
            "downTime=%" PRId64 ", eventTime=%" PRId64,
            mChannel->getName().string(), seq,
            mChannel->getName().c_str(), seq,
            deviceId, source, action, flags, keyCode, scanCode, metaState, repeatCount,
            downTime, eventTime);
#endif
@@ -307,7 +307,7 @@ status_t InputPublisher::publishMotionEvent(
            "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, "
            "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", "
            "pointerCount=%" PRIu32,
            mChannel->getName().string(), seq,
            mChannel->getName().c_str(), seq,
            deviceId, source, action, actionButton, flags, edgeFlags, metaState, buttonState,
            xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount);
#endif
@@ -319,7 +319,7 @@ status_t InputPublisher::publishMotionEvent(

    if (pointerCount > MAX_POINTERS || pointerCount < 1) {
        ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %" PRIu32 ".",
                mChannel->getName().string(), pointerCount);
                mChannel->getName().c_str(), pointerCount);
        return BAD_VALUE;
    }

@@ -352,7 +352,7 @@ status_t InputPublisher::publishMotionEvent(
status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandled) {
#if DEBUG_TRANSPORT_ACTIONS
    ALOGD("channel '%s' publisher ~ receiveFinishedSignal",
            mChannel->getName().string());
            mChannel->getName().c_str());
#endif

    InputMessage msg;
@@ -364,7 +364,7 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle
    }
    if (msg.header.type != InputMessage::TYPE_FINISHED) {
        ALOGE("channel '%s' publisher ~ Received unexpected message of type %d from consumer",
                mChannel->getName().string(), msg.header.type);
                mChannel->getName().c_str(), msg.header.type);
        return UNKNOWN_ERROR;
    }
    *outSeq = msg.body.finished.seq;
@@ -402,7 +402,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
        int32_t* displayId) {
#if DEBUG_TRANSPORT_ACTIONS
    ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64,
            mChannel->getName().string(), consumeBatches ? "true" : "false", frameTime);
            mChannel->getName().c_str(), consumeBatches ? "true" : "false", frameTime);
#endif

    *outSeq = 0;
@@ -426,7 +426,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
                    if (*outEvent) {
#if DEBUG_TRANSPORT_ACTIONS
                        ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u",
                                mChannel->getName().string(), *outSeq);
                                mChannel->getName().c_str(), *outSeq);
#endif
                        break;
                    }
@@ -445,7 +445,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
            *outEvent = keyEvent;
#if DEBUG_TRANSPORT_ACTIONS
            ALOGD("channel '%s' consumer ~ consumed key event, seq=%u",
                    mChannel->getName().string(), *outSeq);
                    mChannel->getName().c_str(), *outSeq);
#endif
            break;
        }
@@ -458,7 +458,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
                    batch.samples.push(mMsg);
#if DEBUG_TRANSPORT_ACTIONS
                    ALOGD("channel '%s' consumer ~ appended to batch event",
                            mChannel->getName().string());
                            mChannel->getName().c_str());
#endif
                    break;
                } else {
@@ -474,7 +474,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
#if DEBUG_TRANSPORT_ACTIONS
                    ALOGD("channel '%s' consumer ~ consumed batch event and "
                            "deferred current event, seq=%u",
                            mChannel->getName().string(), *outSeq);
                            mChannel->getName().c_str(), *outSeq);
#endif
                    break;
                }
@@ -488,7 +488,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
                batch.samples.push(mMsg);
#if DEBUG_TRANSPORT_ACTIONS
                ALOGD("channel '%s' consumer ~ started batch event",
                        mChannel->getName().string());
                        mChannel->getName().c_str());
#endif
                break;
            }
@@ -503,14 +503,14 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
            *displayId = mMsg.body.motion.displayId;
#if DEBUG_TRANSPORT_ACTIONS
            ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u",
                    mChannel->getName().string(), *outSeq);
                    mChannel->getName().c_str(), *outSeq);
#endif
            break;
        }

        default:
            ALOGE("channel '%s' consumer ~ Received unexpected message of type %d",
                    mChannel->getName().string(), mMsg.header.type);
                    mChannel->getName().c_str(), mMsg.header.type);
            return UNKNOWN_ERROR;
        }
    }
@@ -828,7 +828,7 @@ bool InputConsumer::shouldResampleTool(int32_t toolType) {
status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) {
#if DEBUG_TRANSPORT_ACTIONS
    ALOGD("channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s",
            mChannel->getName().string(), seq, handled ? "true" : "false");
            mChannel->getName().c_str(), seq, handled ? "true" : "false");
#endif

    if (!seq) {
+8 −8
Original line number Diff line number Diff line
@@ -41,9 +41,9 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor
    // of a pipe and to check for EPIPE on the other end after the channel is destroyed.
    Pipe pipe;

    sp<InputChannel> inputChannel = new InputChannel(String8("channel name"), pipe.sendFd);
    sp<InputChannel> inputChannel = new InputChannel("channel name", pipe.sendFd);

    EXPECT_STREQ("channel name", inputChannel->getName().string())
    EXPECT_STREQ("channel name", inputChannel->getName().c_str())
            << "channel should have provided name";
    EXPECT_EQ(pipe.sendFd, inputChannel->getFd())
            << "channel should have provided fd";
@@ -60,16 +60,16 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor
TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) {
    sp<InputChannel> serverChannel, clientChannel;

    status_t result = InputChannel::openInputChannelPair(String8("channel name"),
    status_t result = InputChannel::openInputChannelPair("channel name",
            serverChannel, clientChannel);

    ASSERT_EQ(OK, result)
            << "should have successfully opened a channel pair";

    // Name
    EXPECT_STREQ("channel name (server)", serverChannel->getName().string())
    EXPECT_STREQ("channel name (server)", serverChannel->getName().c_str())
            << "server channel should have suffixed name";
    EXPECT_STREQ("channel name (client)", clientChannel->getName().string())
    EXPECT_STREQ("channel name (client)", clientChannel->getName().c_str())
            << "client channel should have suffixed name";

    // Server->Client communication
@@ -111,7 +111,7 @@ TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) {
TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) {
    sp<InputChannel> serverChannel, clientChannel;

    status_t result = InputChannel::openInputChannelPair(String8("channel name"),
    status_t result = InputChannel::openInputChannelPair("channel name",
            serverChannel, clientChannel);

    ASSERT_EQ(OK, result)
@@ -125,7 +125,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) {
TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) {
    sp<InputChannel> serverChannel, clientChannel;

    status_t result = InputChannel::openInputChannelPair(String8("channel name"),
    status_t result = InputChannel::openInputChannelPair("channel name",
            serverChannel, clientChannel);

    ASSERT_EQ(OK, result)
@@ -141,7 +141,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) {
TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) {
    sp<InputChannel> serverChannel, clientChannel;

    status_t result = InputChannel::openInputChannelPair(String8("channel name"),
    status_t result = InputChannel::openInputChannelPair("channel name",
            serverChannel, clientChannel);

    ASSERT_EQ(OK, result)
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ protected:
    PreallocatedInputEventFactory mEventFactory;

    virtual void SetUp() {
        status_t result = InputChannel::openInputChannelPair(String8("channel name"),
        status_t result = InputChannel::openInputChannelPair("channel name",
                serverChannel, clientChannel);

        mPublisher = new InputPublisher(serverChannel);
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ cc_library_shared {
    ],

    shared_libs: [
        "libbase",
        "libbinder",
        "libcrypto",
        "libcutils",
Loading