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

Commit 0783e99d authored by Chris Ye's avatar Chris Ye
Browse files

AIDL-ize InputManager IInputFlinger interface.

Use AIDL interface to define the IInputFlinger interface and replace
the manual interface.

Bug:155425003
Test: atest libgui_test, atest libinput_test.

Change-Id: Ibad036b8ceb3a3f5c6d58f8de4ea8c79379d29b5
parent 8dcf124c
Loading
Loading
Loading
Loading

include/input/IInputFlinger.h

deleted100644 → 0
+0 −62
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _LIBINPUT_IINPUT_FLINGER_H
#define _LIBINPUT_IINPUT_FLINGER_H

#include <stdint.h>
#include <sys/types.h>

#include <binder/IInterface.h>

#include <input/InputWindow.h>
#include <input/ISetInputWindowsListener.h>

namespace android {

/*
 * This class defines the Binder IPC interface for accessing various
 * InputFlinger features.
 */
class IInputFlinger : public IInterface {
public:
    DECLARE_META_INTERFACE(InputFlinger)

    virtual void setInputWindows(const std::vector<InputWindowInfo>& inputHandles,
            const sp<ISetInputWindowsListener>& setInputWindowsListener) = 0;
    virtual void registerInputChannel(const sp<InputChannel>& channel) = 0;
    virtual void unregisterInputChannel(const sp<InputChannel>& channel) = 0;
};


/**
 * Binder implementation.
 */
class BnInputFlinger : public BnInterface<IInputFlinger> {
public:
    enum {
        SET_INPUT_WINDOWS_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
        REGISTER_INPUT_CHANNEL_TRANSACTION,
        UNREGISTER_INPUT_CHANNEL_TRANSACTION
    };

    virtual status_t onTransact(uint32_t code, const Parcel& data,
            Parcel* reply, uint32_t flags = 0);
};

} // namespace android

#endif // _LIBINPUT_IINPUT_FLINGER_H
+8 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

#include <binder/IBinder.h>
#include <binder/Parcel.h>
#include <binder/Parcelable.h>

#include <input/Input.h>
#include <utils/RefBase.h>
@@ -31,15 +32,17 @@ namespace android {
/*
 * Describes the properties of an application that can receive input.
 */
struct InputApplicationInfo {
struct InputApplicationInfo : public Parcelable {
    sp<IBinder> token;
    std::string name;
    std::chrono::nanoseconds dispatchingTimeout;

    status_t write(Parcel& output) const;
    static InputApplicationInfo read(const Parcel& from);
};
    InputApplicationInfo() = default;

    status_t readFromParcel(const android::Parcel* parcel) override;

    status_t writeToParcel(android::Parcel* parcel) const override;
};

/*
 * Handle for an application that can receive input.
@@ -76,6 +79,7 @@ public:
     * Returns true on success, or false if the handle is no longer valid.
     */
    virtual bool updateInfo() = 0;

protected:
    InputApplicationHandle();
    virtual ~InputApplicationHandle();
+38 −11
Original line number Diff line number Diff line
@@ -34,7 +34,9 @@
#include <android-base/chrono_utils.h>

#include <binder/IBinder.h>
#include <binder/Parcelable.h>
#include <input/Input.h>
#include <sys/stat.h>
#include <utils/BitSet.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
@@ -174,6 +176,18 @@ struct InputMessage {
    void getSanitizedCopy(InputMessage* msg) const;
};

struct InputChannelInfo : public Parcelable {
    std::string mName;
    android::base::unique_fd mFd;
    sp<IBinder> mToken;

    InputChannelInfo() = default;
    InputChannelInfo(const std::string& name, android::base::unique_fd fd, sp<IBinder> token)
          : mName(name), mFd(std::move(fd)), mToken(token){};
    status_t readFromParcel(const android::Parcel* parcel) override;
    status_t writeToParcel(android::Parcel* parcel) const override;
};

/*
 * An input channel consists of a local unix domain socket used to send and receive
 * input messages across processes.  Each channel has a descriptive name for debugging purposes.
@@ -183,10 +197,10 @@ struct InputMessage {
 * The input channel is closed when all references to it are released.
 */
class InputChannel : public RefBase {
protected:
public:
    InputChannel();
    virtual ~InputChannel();

public:
    static sp<InputChannel> create(const std::string& name, android::base::unique_fd fd,
                                   sp<IBinder> token);

@@ -200,8 +214,10 @@ public:
    static status_t openInputChannelPair(const std::string& name,
            sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel);

    inline std::string getName() const { return mName; }
    inline int getFd() const { return mFd.get(); }
    inline std::string getName() const { return mInfo.mName; }
    inline int getFd() const { return mInfo.mFd.get(); }
    inline sp<IBinder> getToken() const { return mInfo.mToken; }
    inline InputChannelInfo& getInfo() { return mInfo; }

    /* Send a message to the other endpoint.
     *
@@ -231,8 +247,9 @@ public:
    /* Return a new object that has a duplicate of this channel's fd. */
    sp<InputChannel> dup() const;

    status_t write(Parcel& out) const;
    static sp<InputChannel> read(const Parcel& from);
    status_t readFromParcel(const android::Parcel* parcel);

    status_t writeToParcel(android::Parcel* parcel) const;

    /**
     * The connection token is used to identify the input connection, i.e.
@@ -248,12 +265,23 @@ public:
     */
    sp<IBinder> getConnectionToken() const;

    bool operator==(const InputChannel& inputChannel) const {
        struct stat lhsInfo, rhsInfo;
        if (fstat(mInfo.mFd.get(), &lhsInfo) != 0) {
            return false;
        }
        if (fstat(inputChannel.getFd(), &rhsInfo) != 0) {
            return false;
        }
        // If file descriptors are pointing to same inode they are duplicated fds.
        return inputChannel.getName() == getName() &&
                inputChannel.getConnectionToken() == mInfo.mToken &&
                lhsInfo.st_ino == rhsInfo.st_ino;
    }

private:
    InputChannel(const std::string& name, android::base::unique_fd fd, sp<IBinder> token);
    std::string mName;
    android::base::unique_fd mFd;

    sp<IBinder> mToken;
    InputChannelInfo mInfo;
};

/*
@@ -325,7 +353,6 @@ public:
    status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled);

private:

    sp<InputChannel> mChannel;
};

+19 −16
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
#ifndef _UI_INPUT_WINDOW_H
#define _UI_INPUT_WINDOW_H

#include <binder/Parcel.h>
#include <binder/Parcelable.h>
#include <input/Input.h>
#include <input/InputTransport.h>
#include <ui/Rect.h>
@@ -27,14 +29,12 @@
#include "InputApplication.h"

namespace android {
class Parcel;

/*
 * Describes the properties of a window that can receive input.
 */
struct InputWindowInfo {
struct InputWindowInfo : public Parcelable {
    InputWindowInfo() = default;
    InputWindowInfo(const Parcel& from);

    // Window flags from WindowManager.LayoutParams
    enum : uint32_t {
@@ -195,9 +195,11 @@ struct InputWindowInfo {

    bool overlaps(const InputWindowInfo* other) const;

    status_t write(Parcel& output) const;
    bool operator==(const InputWindowInfo& inputChannel) const;

    static InputWindowInfo read(const Parcel& from);
    status_t writeToParcel(android::Parcel* parcel) const override;

    status_t readFromParcel(const android::Parcel* parcel) override;
};

std::string inputWindowFlagsToString(uint32_t flags);
@@ -210,22 +212,19 @@ std::string inputWindowFlagsToString(uint32_t flags);
 */
class InputWindowHandle : public RefBase {
public:
    explicit InputWindowHandle();
    InputWindowHandle(const InputWindowHandle& other);
    InputWindowHandle(const InputWindowInfo& other);

    inline const InputWindowInfo* getInfo() const {
        return &mInfo;
    }
    inline const InputWindowInfo* getInfo() const { return &mInfo; }

    sp<IBinder> getToken() const;

    int32_t getId() const { return mInfo.id; }

    sp<IBinder> getApplicationToken() {
        return mInfo.applicationInfo.token;
    }
    sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; }

    inline std::string getName() const {
        return !mInfo.name.empty() ? mInfo.name : "<invalid>";
    }
    inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }

    inline std::chrono::nanoseconds getDispatchingTimeout(
            std::chrono::nanoseconds defaultValue) const {
@@ -235,13 +234,14 @@ public:
    /**
     * Requests that the state of this object be updated to reflect
     * the most current available information about the application.
     * As this class is created as RefBase object, no pure virtual function is allowed.
     *
     * This method should only be called from within the input dispatcher's
     * critical section.
     *
     * Returns true on success, or false if the handle is no longer valid.
     */
    virtual bool updateInfo() = 0;
    virtual bool updateInfo() { return false; }

    /**
     * Updates from another input window handle.
@@ -254,8 +254,11 @@ public:
     */
    void releaseChannel();

    // Not override since this class is not derrived from Parcelable.
    status_t readFromParcel(const android::Parcel* parcel);
    status_t writeToParcel(android::Parcel* parcel) const;

protected:
    explicit InputWindowHandle();
    virtual ~InputWindowHandle();

    InputWindowInfo mInfo;
+3 −3
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ status_t layer_state_t::write(Parcel& output) const
    output.writeFloat(color.g);
    output.writeFloat(color.b);
#ifndef NO_INPUT
    inputInfo.write(output);
    inputHandle->writeToParcel(&output);
#endif
    output.write(transparentRegion);
    output.writeUint32(transform);
@@ -152,7 +152,7 @@ status_t layer_state_t::read(const Parcel& input)
    color.b = input.readFloat();

#ifndef NO_INPUT
    inputInfo = InputWindowInfo::read(input);
    inputHandle->readFromParcel(&input);
#endif

    input.read(transparentRegion);
@@ -404,7 +404,7 @@ void layer_state_t::merge(const layer_state_t& other) {
#ifndef NO_INPUT
    if (other.what & eInputInfoChanged) {
        what |= eInputInfoChanged;
        inputInfo = other.inputInfo;
        inputHandle = new InputWindowHandle(*other.inputHandle);
    }
#endif

Loading