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

Commit 62e023bc authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Mark VDM created devices as "virtual device" in inputfinger

Bug: 402596982
Flag: EXEMPT refactor
Test: atest inputflinger_tests
Change-Id: Ife252ec034d88936120107f493fe9fd231c1e446
parent 0d77e992
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -282,7 +282,8 @@ public:

    void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
                    const InputDeviceIdentifier& identifier, const std::string& alias,
                    bool isExternal, bool hasMic, ui::LogicalDisplayId associatedDisplayId,
                    bool isExternal, bool isVirtualDevice, bool hasMic,
                    ui::LogicalDisplayId associatedDisplayId,
                    InputDeviceViewBehavior viewBehavior = {{}}, bool enabled = true);

    inline int32_t getId() const { return mId; }
@@ -294,6 +295,7 @@ public:
        return mAlias.empty() ? mIdentifier.name : mAlias;
    }
    inline bool isExternal() const { return mIsExternal; }
    inline bool isVirtualDevice() const { return mIsVirtualDevice; }
    inline bool hasMic() const { return mHasMic; }
    inline uint32_t getSources() const { return mSources; }

@@ -357,6 +359,7 @@ private:
    InputDeviceIdentifier mIdentifier;
    std::string mAlias;
    bool mIsExternal;
    bool mIsVirtualDevice;
    bool mHasMic;
    std::optional<KeyboardLayoutInfo> mKeyboardLayoutInfo;
    uint32_t mSources;
+7 −4
Original line number Diff line number Diff line
@@ -178,11 +178,11 @@ std::string InputDeviceIdentifier::getCanonicalName() const {
    return replacedName;
}


// --- InputDeviceInfo ---

InputDeviceInfo::InputDeviceInfo() {
    initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false, ui::LogicalDisplayId::INVALID);
    initialize(/*id=*/-1, /*generation=*/0, /*controllerNumber=*/-1, InputDeviceIdentifier(),
               /*alias=*/"", /*isExternal=*/false, /*isVirtualDevice=*/false, /*hasMic=*/false,
               ui::LogicalDisplayId::INVALID);
}

InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
@@ -192,6 +192,7 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
        mIdentifier(other.mIdentifier),
        mAlias(other.mAlias),
        mIsExternal(other.mIsExternal),
        mIsVirtualDevice(other.mIsVirtualDevice),
        mHasMic(other.mHasMic),
        mKeyboardLayoutInfo(other.mKeyboardLayoutInfo),
        mSources(other.mSources),
@@ -217,6 +218,7 @@ InputDeviceInfo& InputDeviceInfo::operator=(const InputDeviceInfo& other) {
    mIdentifier = other.mIdentifier;
    mAlias = other.mAlias;
    mIsExternal = other.mIsExternal;
    mIsVirtualDevice = other.mIsVirtualDevice;
    mHasMic = other.mHasMic;
    mKeyboardLayoutInfo = other.mKeyboardLayoutInfo;
    mSources = other.mSources;
@@ -242,7 +244,7 @@ InputDeviceInfo::~InputDeviceInfo() {

void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t controllerNumber,
                                 const InputDeviceIdentifier& identifier, const std::string& alias,
                                 bool isExternal, bool hasMic,
                                 bool isExternal, bool isVirtualDevice, bool hasMic,
                                 ui::LogicalDisplayId associatedDisplayId,
                                 InputDeviceViewBehavior viewBehavior, bool enabled) {
    mId = id;
@@ -251,6 +253,7 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control
    mIdentifier = identifier;
    mAlias = alias;
    mIsExternal = isExternal;
    mIsVirtualDevice = isVirtualDevice;
    mHasMic = hasMic;
    mSources = 0;
    mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
+7 −0
Original line number Diff line number Diff line
@@ -100,6 +100,9 @@ struct InputReaderConfiguration {
        // primary button.
        MOUSE_SETTINGS = 1u << 15,

        // The virtual devices list is updated
        VIRTUAL_DEVICES = 1u << 16,

        // All devices must be reopened.
        MUST_REOPEN = 1u << 31,
    };
@@ -133,6 +136,10 @@ struct InputReaderConfiguration {
    // Can be used to determine the layout of the keyboard device.
    std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations;

    // List of input device physical port locations of devices that are marked as virtual and should
    // not be treated as physically connected peripheral (e.g. created using VDM in userspace)
    std::set<std::string> virtualDevicePorts;

    // The suggested display ID to show the cursor.
    ui::LogicalDisplayId defaultPointerDisplayId;

+12 −1
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ InputDevice::InputDevice(InputReaderContext* context, int32_t id, int32_t genera
        mSources(0),
        mIsWaking(false),
        mIsExternal(false),
        mIsVirtualDevice(false),
        mHasMic(false),
        mDropUntilNextSync(false) {}

@@ -136,6 +137,7 @@ void InputDevice::dump(std::string& dump, const std::string& eventHubDevStr) {
    dump += StringPrintf(INDENT "%s", eventHubDevStr.c_str());
    dump += StringPrintf(INDENT2 "Generation: %d\n", mGeneration);
    dump += StringPrintf(INDENT2 "IsExternal: %s\n", toString(mIsExternal));
    dump += StringPrintf(INDENT2 "IsVirtualDevice: %s\n", toString(mIsVirtualDevice));
    dump += StringPrintf(INDENT2 "IsWaking: %s\n", toString(mIsWaking));
    dump += StringPrintf(INDENT2 "AssociatedDisplayPort: ");
    if (mAssociatedDisplayPort) {
@@ -287,6 +289,15 @@ std::list<NotifyArgs> InputDevice::configureInternal(nsecs_t when,
            mShouldSmoothScroll = mConfiguration.getBool("device.viewBehavior_smoothScroll");
        }

        if (!changes.any() || changes.test(Change::VIRTUAL_DEVICES)) {
            const bool isVirtualDevice =
                    readerConfig.virtualDevicePorts.contains(mIdentifier.location);
            if (mIsVirtualDevice != isVirtualDevice) {
                mIsVirtualDevice = isVirtualDevice;
                bumpGeneration();
            }
        }

        if (!changes.any() || changes.test(Change::DEVICE_ALIAS)) {
            if (!(mClasses.test(InputDeviceClass::VIRTUAL))) {
                std::string alias = mContext->getPolicy()->getDeviceAlias(mIdentifier);
@@ -481,7 +492,7 @@ std::list<NotifyArgs> InputDevice::updateExternalStylusState(const StylusState&
InputDeviceInfo InputDevice::getDeviceInfo() {
    InputDeviceInfo outDeviceInfo;
    outDeviceInfo.initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal,
                             mHasMic,
                             mIsVirtualDevice, mHasMic,
                             getAssociatedDisplayId().value_or(ui::LogicalDisplayId::INVALID),
                             {mShouldSmoothScroll}, isEnabled());
    outDeviceInfo.setKeyboardType(static_cast<int32_t>(mKeyboardType));
+3 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public:
    inline bool hasEventHubDevices() const { return !mDevices.empty(); }

    inline virtual bool isExternal() { return mIsExternal; }
    inline virtual bool isVirtualDevice() const { return mIsVirtualDevice; }
    inline std::optional<uint8_t> getAssociatedDisplayPort() const {
        return mAssociatedDisplayPort;
    }
@@ -202,6 +203,7 @@ private:
    uint32_t mSources;
    bool mIsWaking;
    bool mIsExternal;
    bool mIsVirtualDevice;
    KeyboardType mKeyboardType = KeyboardType::NONE;
    std::optional<uint8_t> mAssociatedDisplayPort;
    std::optional<std::string> mAssociatedDisplayUniqueIdByPort;
@@ -450,6 +452,7 @@ public:
    inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
    inline const std::string getLocation() { return mDevice.getLocation(); }
    inline bool isExternal() const { return mDevice.isExternal(); }
    inline bool isVirtualDevice() const { return mDevice.isVirtualDevice(); }
    inline std::optional<uint8_t> getAssociatedDisplayPort() const {
        return mDevice.getAssociatedDisplayPort();
    }
Loading