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

Commit dd4b3467 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Check input device's all sub devices for isEnabled()"

parents 0a8314df e14523a4
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -54,10 +54,11 @@ bool InputDevice::isEnabled() {
    if (!hasEventHubDevices()) {
    if (!hasEventHubDevices()) {
        return false;
        return false;
    }
    }
    // devices are either all enabled or all disabled, so we only need to check the first
    // An input device composed of sub devices can be individually enabled or disabled.
    auto& devicePair = mDevices.begin()->second;
    // If any of the sub device is enabled then the input device is considered as enabled.
    auto& contextPtr = devicePair.first;
    bool enabled = false;
    return contextPtr->isDeviceEnabled();
    for_each_subdevice([&enabled](auto& context) { enabled |= context.isDeviceEnabled(); });
    return enabled;
}
}


void InputDevice::setEnabled(bool enabled, nsecs_t when) {
void InputDevice::setEnabled(bool enabled, nsecs_t when) {
+3 −1
Original line number Original line Diff line number Diff line
@@ -222,7 +222,9 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
    }
    }


    // Sensor input device is noisy, to save power disable it by default.
    // Sensor input device is noisy, to save power disable it by default.
    if (device->getClasses().test(InputDeviceClass::SENSOR)) {
    // Input device is classified as SENSOR when any sub device is a SENSOR device, check Eventhub
    // device class to disable SENSOR sub device only.
    if (mEventHub->getDeviceClasses(eventHubId).test(InputDeviceClass::SENSOR)) {
        mEventHub->disableDevice(eventHubId);
        mEventHub->disableDevice(eventHubId);
    }
    }
}
}
+28 −0
Original line number Original line Diff line number Diff line
@@ -1481,6 +1481,32 @@ TEST_F(InputReaderTest, GetMergedInputDevices) {
    ASSERT_EQ(1U, mReader->getInputDevices().size());
    ASSERT_EQ(1U, mReader->getInputDevices().size());
}
}


TEST_F(InputReaderTest, GetMergedInputDevicesEnabled) {
    constexpr int32_t deviceId = END_RESERVED_ID + 1000;
    constexpr int32_t eventHubIds[2] = {END_RESERVED_ID, END_RESERVED_ID + 1};
    // Add two subdevices to device
    std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
    // Must add at least one mapper or the device will be ignored!
    device->addMapper<FakeInputMapper>(eventHubIds[0], AINPUT_SOURCE_KEYBOARD);
    device->addMapper<FakeInputMapper>(eventHubIds[1], AINPUT_SOURCE_KEYBOARD);

    // Push same device instance for next device to be added, so they'll have same identifier.
    mReader->pushNextDevice(device);
    mReader->pushNextDevice(device);
    // Sensor device is initially disabled
    ASSERT_NO_FATAL_FAILURE(addDevice(eventHubIds[0], "fake1",
                                      InputDeviceClass::KEYBOARD | InputDeviceClass::SENSOR,
                                      nullptr));
    // Device is disabled because the only sub device is a sensor device and disabled initially.
    ASSERT_FALSE(mFakeEventHub->isDeviceEnabled(eventHubIds[0]));
    ASSERT_FALSE(device->isEnabled());
    ASSERT_NO_FATAL_FAILURE(
            addDevice(eventHubIds[1], "fake2", InputDeviceClass::KEYBOARD, nullptr));
    // The merged device is enabled if any sub device is enabled
    ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(eventHubIds[1]));
    ASSERT_TRUE(device->isEnabled());
}

TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) {
TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) {
    constexpr int32_t deviceId = END_RESERVED_ID + 1000;
    constexpr int32_t deviceId = END_RESERVED_ID + 1000;
    constexpr Flags<InputDeviceClass> deviceClass(InputDeviceClass::KEYBOARD);
    constexpr Flags<InputDeviceClass> deviceClass(InputDeviceClass::KEYBOARD);
@@ -2721,6 +2747,7 @@ TEST_F(SensorInputMapperTest, ProcessAccelerometerSensor) {
    ASSERT_TRUE(mapper.enableSensor(InputDeviceSensorType::ACCELEROMETER,
    ASSERT_TRUE(mapper.enableSensor(InputDeviceSensorType::ACCELEROMETER,
                                    std::chrono::microseconds(10000),
                                    std::chrono::microseconds(10000),
                                    std::chrono::microseconds(0)));
                                    std::chrono::microseconds(0)));
    ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(EVENTHUB_ID));
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_X, 20000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_X, 20000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_Y, -20000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_Y, -20000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_Z, 40000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_Z, 40000);
@@ -2750,6 +2777,7 @@ TEST_F(SensorInputMapperTest, ProcessGyroscopeSensor) {
    ASSERT_TRUE(mapper.enableSensor(InputDeviceSensorType::GYROSCOPE,
    ASSERT_TRUE(mapper.enableSensor(InputDeviceSensorType::GYROSCOPE,
                                    std::chrono::microseconds(10000),
                                    std::chrono::microseconds(10000),
                                    std::chrono::microseconds(0)));
                                    std::chrono::microseconds(0)));
    ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(EVENTHUB_ID));
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_RX, 20000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_RX, 20000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_RY, -20000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_RY, -20000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_RZ, 40000);
    process(mapper, ARBITRARY_TIME, EV_ABS, ABS_RZ, 40000);