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

Commit 4bf6d455 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Use ftl::Flags for InputReaderConfiguration::Change

Convert the config flags into an enum class and use ftl::Flags when
dealing with configuration changes.

Bug: 245989146
Test: Presubmit
Change-Id: I0aed947ce433a1def11a60e73a14575561374700
parent 12f8913b
Loading
Loading
Loading
Loading
+0 −44
Original line number Original line Diff line number Diff line
@@ -38,50 +38,6 @@ namespace android {


// --- InputReaderConfiguration ---
// --- InputReaderConfiguration ---


std::string InputReaderConfiguration::changesToString(uint32_t changes) {
    if (changes == 0) {
        return "<none>";
    }
    std::string result;
    if (changes & CHANGE_POINTER_SPEED) {
        result += "POINTER_SPEED | ";
    }
    if (changes & CHANGE_POINTER_GESTURE_ENABLEMENT) {
        result += "POINTER_GESTURE_ENABLEMENT | ";
    }
    if (changes & CHANGE_DISPLAY_INFO) {
        result += "DISPLAY_INFO | ";
    }
    if (changes & CHANGE_SHOW_TOUCHES) {
        result += "SHOW_TOUCHES | ";
    }
    if (changes & CHANGE_KEYBOARD_LAYOUTS) {
        result += "KEYBOARD_LAYOUTS | ";
    }
    if (changes & CHANGE_DEVICE_ALIAS) {
        result += "DEVICE_ALIAS | ";
    }
    if (changes & CHANGE_TOUCH_AFFINE_TRANSFORMATION) {
        result += "TOUCH_AFFINE_TRANSFORMATION | ";
    }
    if (changes & CHANGE_EXTERNAL_STYLUS_PRESENCE) {
        result += "EXTERNAL_STYLUS_PRESENCE | ";
    }
    if (changes & CHANGE_POINTER_CAPTURE) {
        result += "POINTER_CAPTURE | ";
    }
    if (changes & CHANGE_ENABLED_STATE) {
        result += "ENABLED_STATE | ";
    }
    if (changes & CHANGE_TOUCHPAD_SETTINGS) {
        result += "TOUCHPAD_SETTINGS | ";
    }
    if (changes & CHANGE_MUST_REOPEN) {
        result += "MUST_REOPEN | ";
    }
    return result;
}

std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByUniqueId(
std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByUniqueId(
        const std::string& uniqueDisplayId) const {
        const std::string& uniqueDisplayId) const {
    if (uniqueDisplayId.empty()) {
    if (uniqueDisplayId.empty()) {
+126 −130
Original line number Original line Diff line number Diff line
@@ -42,118 +42,6 @@


namespace android {
namespace android {


// --- InputReaderInterface ---

/* The interface for the InputReader shared library.
 *
 * Manages one or more threads that process raw input events and sends cooked event data to an
 * input listener.
 *
 * The implementation must guarantee thread safety for this interface. However, since the input
 * listener is NOT thread safe, all calls to the listener must happen from the same thread.
 */
class InputReaderInterface {
public:
    InputReaderInterface() { }
    virtual ~InputReaderInterface() { }

    /* Dumps the state of the input reader.
     *
     * This method may be called on any thread (usually by the input manager). */
    virtual void dump(std::string& dump) = 0;

    /* Called by the heartbeat to ensures that the reader has not deadlocked. */
    virtual void monitor() = 0;

    /* Returns true if the input device is enabled. */
    virtual bool isInputDeviceEnabled(int32_t deviceId) = 0;

    /* Makes the reader start processing events from the kernel. */
    virtual status_t start() = 0;

    /* Makes the reader stop processing any more events. */
    virtual status_t stop() = 0;

    /* Gets information about all input devices.
     *
     * This method may be called on any thread (usually by the input manager).
     */
    virtual std::vector<InputDeviceInfo> getInputDevices() const = 0;

    /* Query current input state. */
    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
            int32_t scanCode) = 0;
    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
            int32_t keyCode) = 0;
    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
            int32_t sw) = 0;

    virtual void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode,
                                 int32_t toKeyCode) const = 0;

    virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0;

    /* Toggle Caps Lock */
    virtual void toggleCapsLockState(int32_t deviceId) = 0;

    /* Determine whether physical keys exist for the given framework-domain key codes. */
    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
                         const std::vector<int32_t>& keyCodes, uint8_t* outFlags) = 0;

    /* Requests that a reconfiguration of all input devices.
     * The changes flag is a bitfield that indicates what has changed and whether
     * the input devices must all be reopened. */
    virtual void requestRefreshConfiguration(uint32_t changes) = 0;

    /* Controls the vibrator of a particular input device. */
    virtual void vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat,
                         int32_t token) = 0;
    virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;

    virtual bool isVibrating(int32_t deviceId) = 0;

    virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0;
    /* Get battery level of a particular input device. */
    virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0;
    /* Get battery status of a particular input device. */
    virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0;
    /* Get the device path for the battery of an input device. */
    virtual std::optional<std::string> getBatteryDevicePath(int32_t deviceId) = 0;

    virtual std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) = 0;

    virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0;

    /* Return true if the device can send input events to the specified display. */
    virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;

    /* Enable sensor in input reader mapper. */
    virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType,
                              std::chrono::microseconds samplingPeriod,
                              std::chrono::microseconds maxBatchReportLatency) = 0;

    /* Disable sensor in input reader mapper. */
    virtual void disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;

    /* Flush sensor data in input reader mapper. */
    virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;

    /* Set color for the light */
    virtual bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) = 0;
    /* Set player ID for the light */
    virtual bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) = 0;
    /* Get light color */
    virtual std::optional<int32_t> getLightColor(int32_t deviceId, int32_t lightId) = 0;
    /* Get light player ID */
    virtual std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) = 0;

    /* Get the Bluetooth address of an input device, if known. */
    virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0;

    /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */
    virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0;
};

// --- InputReaderConfiguration ---
// --- InputReaderConfiguration ---


/*
/*
@@ -163,51 +51,51 @@ public:
 */
 */
struct InputReaderConfiguration {
struct InputReaderConfiguration {
    // Describes changes that have occurred.
    // Describes changes that have occurred.
    enum {
    enum class Change : uint32_t {
        // The mouse pointer speed changed.
        // The mouse pointer speed changed.
        CHANGE_POINTER_SPEED = 1 << 0,
        POINTER_SPEED = 1u << 0,


        // The pointer gesture control changed.
        // The pointer gesture control changed.
        CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1,
        POINTER_GESTURE_ENABLEMENT = 1u << 1,


        // The display size or orientation changed.
        // The display size or orientation changed.
        CHANGE_DISPLAY_INFO = 1 << 2,
        DISPLAY_INFO = 1u << 2,


        // The visible touches option changed.
        // The visible touches option changed.
        CHANGE_SHOW_TOUCHES = 1 << 3,
        SHOW_TOUCHES = 1u << 3,


        // The keyboard layouts must be reloaded.
        // The keyboard layouts must be reloaded.
        CHANGE_KEYBOARD_LAYOUTS = 1 << 4,
        KEYBOARD_LAYOUTS = 1u << 4,


        // The device name alias supplied by the may have changed for some devices.
        // The device name alias supplied by the may have changed for some devices.
        CHANGE_DEVICE_ALIAS = 1 << 5,
        DEVICE_ALIAS = 1u << 5,


        // The location calibration matrix changed.
        // The location calibration matrix changed.
        CHANGE_TOUCH_AFFINE_TRANSFORMATION = 1 << 6,
        TOUCH_AFFINE_TRANSFORMATION = 1u << 6,


        // The presence of an external stylus has changed.
        // The presence of an external stylus has changed.
        CHANGE_EXTERNAL_STYLUS_PRESENCE = 1 << 7,
        EXTERNAL_STYLUS_PRESENCE = 1u << 7,


        // The pointer capture mode has changed.
        // The pointer capture mode has changed.
        CHANGE_POINTER_CAPTURE = 1 << 8,
        POINTER_CAPTURE = 1u << 8,


        // The set of disabled input devices (disabledDevices) has changed.
        // The set of disabled input devices (disabledDevices) has changed.
        CHANGE_ENABLED_STATE = 1 << 9,
        ENABLED_STATE = 1u << 9,


        // The device type has been updated.
        // The device type has been updated.
        CHANGE_DEVICE_TYPE = 1 << 10,
        DEVICE_TYPE = 1u << 10,


        // The keyboard layout association has changed.
        // The keyboard layout association has changed.
        CHANGE_KEYBOARD_LAYOUT_ASSOCIATION = 1 << 11,
        KEYBOARD_LAYOUT_ASSOCIATION = 1u << 11,


        // The stylus button reporting configurations has changed.
        // The stylus button reporting configurations has changed.
        CHANGE_STYLUS_BUTTON_REPORTING = 1 << 12,
        STYLUS_BUTTON_REPORTING = 1u << 12,


        // The touchpad settings changed.
        // The touchpad settings changed.
        CHANGE_TOUCHPAD_SETTINGS = 1 << 13,
        TOUCHPAD_SETTINGS = 1u << 13,


        // All devices must be reopened.
        // All devices must be reopened.
        CHANGE_MUST_REOPEN = 1 << 31,
        MUST_REOPEN = 1u << 31,
    };
    };


    // Gets the amount of time to disable virtual keys after the screen is touched
    // Gets the amount of time to disable virtual keys after the screen is touched
@@ -367,8 +255,6 @@ struct InputReaderConfiguration {
            stylusButtonMotionEventsEnabled(true),
            stylusButtonMotionEventsEnabled(true),
            stylusPointerIconEnabled(false) {}
            stylusPointerIconEnabled(false) {}


    static std::string changesToString(uint32_t changes);

    std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
    std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
    std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
    std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
            const;
            const;
@@ -383,6 +269,116 @@ private:
    std::vector<DisplayViewport> mDisplays;
    std::vector<DisplayViewport> mDisplays;
};
};


using ConfigurationChanges = ftl::Flags<InputReaderConfiguration::Change>;

// --- InputReaderInterface ---

/* The interface for the InputReader shared library.
 *
 * Manages one or more threads that process raw input events and sends cooked event data to an
 * input listener.
 *
 * The implementation must guarantee thread safety for this interface. However, since the input
 * listener is NOT thread safe, all calls to the listener must happen from the same thread.
 */
class InputReaderInterface {
public:
    InputReaderInterface() {}
    virtual ~InputReaderInterface() {}
    /* Dumps the state of the input reader.
     *
     * This method may be called on any thread (usually by the input manager). */
    virtual void dump(std::string& dump) = 0;

    /* Called by the heartbeat to ensures that the reader has not deadlocked. */
    virtual void monitor() = 0;

    /* Returns true if the input device is enabled. */
    virtual bool isInputDeviceEnabled(int32_t deviceId) = 0;

    /* Makes the reader start processing events from the kernel. */
    virtual status_t start() = 0;

    /* Makes the reader stop processing any more events. */
    virtual status_t stop() = 0;

    /* Gets information about all input devices.
     *
     * This method may be called on any thread (usually by the input manager).
     */
    virtual std::vector<InputDeviceInfo> getInputDevices() const = 0;

    /* Query current input state. */
    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) = 0;
    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) = 0;
    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0;

    virtual void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode,
                                 int32_t toKeyCode) const = 0;

    virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0;

    /* Toggle Caps Lock */
    virtual void toggleCapsLockState(int32_t deviceId) = 0;

    /* Determine whether physical keys exist for the given framework-domain key codes. */
    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
                         const std::vector<int32_t>& keyCodes, uint8_t* outFlags) = 0;

    /* Requests that a reconfiguration of all input devices.
     * The changes flag is a bitfield that indicates what has changed and whether
     * the input devices must all be reopened. */
    virtual void requestRefreshConfiguration(ConfigurationChanges changes) = 0;

    /* Controls the vibrator of a particular input device. */
    virtual void vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat,
                         int32_t token) = 0;
    virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;

    virtual bool isVibrating(int32_t deviceId) = 0;

    virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0;
    /* Get battery level of a particular input device. */
    virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0;
    /* Get battery status of a particular input device. */
    virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0;
    /* Get the device path for the battery of an input device. */
    virtual std::optional<std::string> getBatteryDevicePath(int32_t deviceId) = 0;

    virtual std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) = 0;

    virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0;

    /* Return true if the device can send input events to the specified display. */
    virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;

    /* Enable sensor in input reader mapper. */
    virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType,
                              std::chrono::microseconds samplingPeriod,
                              std::chrono::microseconds maxBatchReportLatency) = 0;

    /* Disable sensor in input reader mapper. */
    virtual void disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;

    /* Flush sensor data in input reader mapper. */
    virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;

    /* Set color for the light */
    virtual bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) = 0;
    /* Set player ID for the light */
    virtual bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) = 0;
    /* Get light color */
    virtual std::optional<int32_t> getLightColor(int32_t deviceId, int32_t lightId) = 0;
    /* Get light player ID */
    virtual std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) = 0;

    /* Get the Bluetooth address of an input device, if known. */
    virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0;

    /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */
    virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0;
};

// --- TouchAffineTransformation ---
// --- TouchAffineTransformation ---


struct TouchAffineTransformation {
struct TouchAffineTransformation {
+10 −8
Original line number Original line Diff line number Diff line
@@ -180,7 +180,7 @@ void InputDevice::removeEventHubDevice(int32_t eventHubId) {


std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
                                             const InputReaderConfiguration& readerConfig,
                                             const InputReaderConfiguration& readerConfig,
                                             uint32_t changes) {
                                             ConfigurationChanges changes) {
    std::list<NotifyArgs> out;
    std::list<NotifyArgs> out;
    mSources = 0;
    mSources = 0;
    mClasses = ftl::Flags<InputDeviceClass>(0);
    mClasses = ftl::Flags<InputDeviceClass>(0);
@@ -201,12 +201,14 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
    mIsExternal = mClasses.test(InputDeviceClass::EXTERNAL);
    mIsExternal = mClasses.test(InputDeviceClass::EXTERNAL);
    mHasMic = mClasses.test(InputDeviceClass::MIC);
    mHasMic = mClasses.test(InputDeviceClass::MIC);


    using Change = InputReaderConfiguration::Change;

    if (!isIgnored()) {
    if (!isIgnored()) {
        // Full configuration should happen the first time configure is called
        // Full configuration should happen the first time configure is called
        // and when the device type is changed. Changing a device type can
        // and when the device type is changed. Changing a device type can
        // affect various other parameters so should result in a
        // affect various other parameters so should result in a
        // reconfiguration.
        // reconfiguration.
        if (!changes || (changes & InputReaderConfiguration::CHANGE_DEVICE_TYPE)) {
        if (!changes.any() || changes.test(Change::DEVICE_TYPE)) {
            mConfiguration.clear();
            mConfiguration.clear();
            for_each_subdevice([this](InputDeviceContext& context) {
            for_each_subdevice([this](InputDeviceContext& context) {
                std::optional<PropertyMap> configuration =
                std::optional<PropertyMap> configuration =
@@ -220,7 +222,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
                    getValueByKey(readerConfig.deviceTypeAssociations, mIdentifier.location);
                    getValueByKey(readerConfig.deviceTypeAssociations, mIdentifier.location);
        }
        }


        if (!changes || (changes & InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS)) {
        if (!changes.any() || changes.test(Change::KEYBOARD_LAYOUTS)) {
            if (!mClasses.test(InputDeviceClass::VIRTUAL)) {
            if (!mClasses.test(InputDeviceClass::VIRTUAL)) {
                std::shared_ptr<KeyCharacterMap> keyboardLayout =
                std::shared_ptr<KeyCharacterMap> keyboardLayout =
                        mContext->getPolicy()->getKeyboardLayoutOverlay(mIdentifier);
                        mContext->getPolicy()->getKeyboardLayoutOverlay(mIdentifier);
@@ -237,7 +239,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
            }
            }
        }
        }


        if (!changes || (changes & InputReaderConfiguration::CHANGE_DEVICE_ALIAS)) {
        if (!changes.any() || changes.test(Change::DEVICE_ALIAS)) {
            if (!(mClasses.test(InputDeviceClass::VIRTUAL))) {
            if (!(mClasses.test(InputDeviceClass::VIRTUAL))) {
                std::string alias = mContext->getPolicy()->getDeviceAlias(mIdentifier);
                std::string alias = mContext->getPolicy()->getDeviceAlias(mIdentifier);
                if (mAlias != alias) {
                if (mAlias != alias) {
@@ -247,7 +249,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
            }
            }
        }
        }


        if (changes & InputReaderConfiguration::CHANGE_ENABLED_STATE) {
        if (changes.test(Change::ENABLED_STATE)) {
            // Do not execute this code on the first configure, because 'setEnabled' would call
            // Do not execute this code on the first configure, because 'setEnabled' would call
            // InputMapper::reset, and you can't reset a mapper before it has been configured.
            // InputMapper::reset, and you can't reset a mapper before it has been configured.
            // The mappers are configured for the first time at the bottom of this function.
            // The mappers are configured for the first time at the bottom of this function.
@@ -256,7 +258,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
            out += setEnabled(enabled, when);
            out += setEnabled(enabled, when);
        }
        }


        if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
        if (!changes.any() || changes.test(Change::DISPLAY_INFO)) {
            // In most situations, no port or name will be specified.
            // In most situations, no port or name will be specified.
            mAssociatedDisplayPort = std::nullopt;
            mAssociatedDisplayPort = std::nullopt;
            mAssociatedDisplayUniqueId = std::nullopt;
            mAssociatedDisplayUniqueId = std::nullopt;
@@ -305,7 +307,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
                }
                }
            }
            }


            if (changes) {
            if (changes.any()) {
                // For first-time configuration, only allow device to be disabled after mappers have
                // For first-time configuration, only allow device to be disabled after mappers have
                // finished configuring. This is because we need to read some of the properties from
                // finished configuring. This is because we need to read some of the properties from
                // the device's open fd.
                // the device's open fd.
@@ -320,7 +322,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,


        // If a device is just plugged but it might be disabled, we need to update some info like
        // If a device is just plugged but it might be disabled, we need to update some info like
        // axis range of touch from each InputMapper first, then disable it.
        // axis range of touch from each InputMapper first, then disable it.
        if (!changes) {
        if (!changes.any()) {
            out += setEnabled(readerConfig.disabledDevices.find(mId) ==
            out += setEnabled(readerConfig.disabledDevices.find(mId) ==
                                      readerConfig.disabledDevices.end(),
                                      readerConfig.disabledDevices.end(),
                              when);
                              when);
+17 −17
Original line number Original line Diff line number Diff line
@@ -85,7 +85,7 @@ InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub,
        mDisableVirtualKeysTimeout(LLONG_MIN),
        mDisableVirtualKeysTimeout(LLONG_MIN),
        mNextTimeout(LLONG_MAX),
        mNextTimeout(LLONG_MAX),
        mConfigurationChangesToRefresh(0) {
        mConfigurationChangesToRefresh(0) {
    refreshConfigurationLocked(0);
    refreshConfigurationLocked(/*changes=*/{});
    updateGlobalMetaStateLocked();
    updateGlobalMetaStateLocked();
}
}


@@ -122,9 +122,9 @@ void InputReader::loopOnce() {
        oldGeneration = mGeneration;
        oldGeneration = mGeneration;
        timeoutMillis = -1;
        timeoutMillis = -1;


        uint32_t changes = mConfigurationChangesToRefresh;
        auto changes = mConfigurationChangesToRefresh;
        if (changes) {
        if (changes.any()) {
            mConfigurationChangesToRefresh = 0;
            mConfigurationChangesToRefresh.clear();
            timeoutMillis = 0;
            timeoutMillis = 0;
            refreshConfigurationLocked(changes);
            refreshConfigurationLocked(changes);
        } else if (mNextTimeout != LLONG_MAX) {
        } else if (mNextTimeout != LLONG_MAX) {
@@ -236,7 +236,7 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
    InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
    InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
    std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier);
    std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier);


    notifyAll(device->configure(when, mConfig, 0));
    notifyAll(device->configure(when, mConfig, /*changes=*/{}));
    notifyAll(device->reset(when));
    notifyAll(device->reset(when));


    if (device->isIgnored()) {
    if (device->isIgnored()) {
@@ -312,7 +312,7 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {


    std::list<NotifyArgs> resetEvents;
    std::list<NotifyArgs> resetEvents;
    if (device->hasEventHubDevices()) {
    if (device->hasEventHubDevices()) {
        resetEvents += device->configure(when, mConfig, 0);
        resetEvents += device->configure(when, mConfig, /*changes=*/{});
    }
    }
    resetEvents += device->reset(when);
    resetEvents += device->reset(when);
    notifyAll(std::move(resetEvents));
    notifyAll(std::move(resetEvents));
@@ -390,21 +390,21 @@ void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
    mQueuedListener.notifyConfigurationChanged({mContext.getNextId(), when});
    mQueuedListener.notifyConfigurationChanged({mContext.getNextId(), when});
}
}


void InputReader::refreshConfigurationLocked(uint32_t changes) {
void InputReader::refreshConfigurationLocked(ConfigurationChanges changes) {
    mPolicy->getReaderConfiguration(&mConfig);
    mPolicy->getReaderConfiguration(&mConfig);
    mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);
    mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);


    if (!changes) return;
    using Change = InputReaderConfiguration::Change;
    if (!changes.any()) return;


    ALOGI("Reconfiguring input devices, changes=%s",
    ALOGI("Reconfiguring input devices, changes=%s", changes.string().c_str());
          InputReaderConfiguration::changesToString(changes).c_str());
    nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
    nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);


    if (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO) {
    if (changes.test(Change::DISPLAY_INFO)) {
        updatePointerDisplayLocked();
        updatePointerDisplayLocked();
    }
    }


    if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) {
    if (changes.test(Change::MUST_REOPEN)) {
        mEventHub->requestReopenDevices();
        mEventHub->requestReopenDevices();
    } else {
    } else {
        for (auto& devicePair : mDevices) {
        for (auto& devicePair : mDevices) {
@@ -413,7 +413,7 @@ void InputReader::refreshConfigurationLocked(uint32_t changes) {
        }
        }
    }
    }


    if (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE) {
    if (changes.test(Change::POINTER_CAPTURE)) {
        if (mCurrentPointerCaptureRequest == mConfig.pointerCaptureRequest) {
        if (mCurrentPointerCaptureRequest == mConfig.pointerCaptureRequest) {
            ALOGV("Skipping notifying pointer capture changes: "
            ALOGV("Skipping notifying pointer capture changes: "
                  "There was no change in the pointer capture state.");
                  "There was no change in the pointer capture state.");
@@ -457,7 +457,7 @@ int32_t InputReader::getLedMetaStateLocked() {
}
}


void InputReader::notifyExternalStylusPresenceChangedLocked() {
void InputReader::notifyExternalStylusPresenceChangedLocked() {
    refreshConfigurationLocked(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE);
    refreshConfigurationLocked(InputReaderConfiguration::Change::EXTERNAL_STYLUS_PRESENCE);
}
}


void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) {
void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) {
@@ -671,11 +671,11 @@ int32_t InputReader::getKeyCodeForKeyLocation(int32_t deviceId, int32_t location
    return device->getKeyCodeForKeyLocation(locationKeyCode);
    return device->getKeyCodeForKeyLocation(locationKeyCode);
}
}


void InputReader::requestRefreshConfiguration(uint32_t changes) {
void InputReader::requestRefreshConfiguration(ConfigurationChanges changes) {
    std::scoped_lock _l(mLock);
    std::scoped_lock _l(mLock);


    if (changes) {
    if (changes.any()) {
        bool needWake = !mConfigurationChangesToRefresh;
        bool needWake = !mConfigurationChangesToRefresh.any();
        mConfigurationChangesToRefresh |= changes;
        mConfigurationChangesToRefresh |= changes;


        if (needWake) {
        if (needWake) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -85,7 +85,7 @@ public:
    void removeEventHubDevice(int32_t eventHubId);
    void removeEventHubDevice(int32_t eventHubId);
    [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
    [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
                                                  const InputReaderConfiguration& readerConfig,
                                                  const InputReaderConfiguration& readerConfig,
                                                  uint32_t changes);
                                                  ConfigurationChanges changes);
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
    [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
    [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
    [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
    [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
Loading