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

Commit 7dc9abb3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Refactor input code for require_kernel_config parameter" into...

Merge "Refactor input code for require_kernel_config parameter" into tm-dev-plus-aosp am: 145c9735 am: 3528f0ec

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/18833969



Change-Id: I63fa028fc37d36d643b1427771f452223f938a23
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e1dbfb4e 3528f0ec
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -21,7 +21,6 @@
#include <stdint.h>
#include <stdint.h>
#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/KeyedVector.h>
#include <utils/RefBase.h>
#include <utils/Tokenizer.h>
#include <utils/Tokenizer.h>


#include <input/InputDevice.h>
#include <input/InputDevice.h>
@@ -66,7 +65,6 @@ struct AxisInfo {
class KeyLayoutMap {
class KeyLayoutMap {
public:
public:
    static base::Result<std::shared_ptr<KeyLayoutMap>> load(const std::string& filename);
    static base::Result<std::shared_ptr<KeyLayoutMap>> load(const std::string& filename);
    static base::Result<std::shared_ptr<KeyLayoutMap>> load(Tokenizer* tokenizer);
    static base::Result<std::shared_ptr<KeyLayoutMap>> loadContents(const std::string& filename,
    static base::Result<std::shared_ptr<KeyLayoutMap>> loadContents(const std::string& filename,
                                                                    const char* contents);
                                                                    const char* contents);


@@ -84,6 +82,8 @@ public:
    virtual ~KeyLayoutMap();
    virtual ~KeyLayoutMap();


private:
private:
    static base::Result<std::shared_ptr<KeyLayoutMap>> load(Tokenizer* tokenizer);

    struct Key {
    struct Key {
        int32_t keyCode;
        int32_t keyCode;
        uint32_t flags;
        uint32_t flags;
+49 −66
Original line number Original line Diff line number Diff line
@@ -21,8 +21,8 @@
#include <input/InputEventLabels.h>
#include <input/InputEventLabels.h>
#include <input/KeyLayoutMap.h>
#include <input/KeyLayoutMap.h>
#include <input/Keyboard.h>
#include <input/Keyboard.h>
#include <log/log.h>
#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/Log.h>
#include <utils/Timers.h>
#include <utils/Timers.h>
#include <utils/Tokenizer.h>
#include <utils/Tokenizer.h>


@@ -30,15 +30,22 @@
#include <string_view>
#include <string_view>
#include <unordered_map>
#include <unordered_map>


// Enables debug output for the parser.
/**
#define DEBUG_PARSER 0
 * Log debug output for the parser.
 * Enable this via "adb shell setprop log.tag.KeyLayoutMapParser DEBUG" (requires restart)
 */
const bool DEBUG_PARSER =
        __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Parser", ANDROID_LOG_INFO);


// Enables debug output for parser performance.
// Enables debug output for parser performance.
#define DEBUG_PARSER_PERFORMANCE 0
#define DEBUG_PARSER_PERFORMANCE 0


// Enables debug output for mapping.
/**
#define DEBUG_MAPPING 0
 * Log debug output for mapping.

 * Enable this via "adb shell setprop log.tag.KeyLayoutMapMapping DEBUG" (requires restart)
 */
const bool DEBUG_MAPPING =
        __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Mapping", ANDROID_LOG_INFO);


namespace android {
namespace android {
namespace {
namespace {
@@ -134,9 +141,8 @@ status_t KeyLayoutMap::mapKey(int32_t scanCode, int32_t usageCode,
        int32_t* outKeyCode, uint32_t* outFlags) const {
        int32_t* outKeyCode, uint32_t* outFlags) const {
    const Key* key = getKey(scanCode, usageCode);
    const Key* key = getKey(scanCode, usageCode);
    if (!key) {
    if (!key) {
#if DEBUG_MAPPING
        ALOGD_IF(DEBUG_MAPPING, "mapKey: scanCode=%d, usageCode=0x%08x ~ Failed.", scanCode,
        ALOGD("mapKey: scanCode=%d, usageCode=0x%08x ~ Failed.", scanCode, usageCode);
                 usageCode);
#endif
        *outKeyCode = AKEYCODE_UNKNOWN;
        *outKeyCode = AKEYCODE_UNKNOWN;
        *outFlags = 0;
        *outFlags = 0;
        return NAME_NOT_FOUND;
        return NAME_NOT_FOUND;
@@ -145,10 +151,9 @@ status_t KeyLayoutMap::mapKey(int32_t scanCode, int32_t usageCode,
    *outKeyCode = key->keyCode;
    *outKeyCode = key->keyCode;
    *outFlags = key->flags;
    *outFlags = key->flags;


#if DEBUG_MAPPING
    ALOGD_IF(DEBUG_MAPPING,
    ALOGD("mapKey: scanCode=%d, usageCode=0x%08x ~ Result keyCode=%d, outFlags=0x%08x.",
             "mapKey: scanCode=%d, usageCode=0x%08x ~ Result keyCode=%d, outFlags=0x%08x.",
             scanCode, usageCode, *outKeyCode, *outFlags);
             scanCode, usageCode, *outKeyCode, *outFlags);
#endif
    return NO_ERROR;
    return NO_ERROR;
}
}


@@ -156,17 +161,12 @@ status_t KeyLayoutMap::mapKey(int32_t scanCode, int32_t usageCode,
base::Result<std::pair<InputDeviceSensorType, int32_t>> KeyLayoutMap::mapSensor(int32_t absCode) {
base::Result<std::pair<InputDeviceSensorType, int32_t>> KeyLayoutMap::mapSensor(int32_t absCode) {
    auto it = mSensorsByAbsCode.find(absCode);
    auto it = mSensorsByAbsCode.find(absCode);
    if (it == mSensorsByAbsCode.end()) {
    if (it == mSensorsByAbsCode.end()) {
#if DEBUG_MAPPING
        ALOGD_IF(DEBUG_MAPPING, "mapSensor: absCode=%d, ~ Failed.", absCode);
        ALOGD("mapSensor: absCode=%d, ~ Failed.", absCode);
#endif
        return Errorf("Can't find abs code {}.", absCode);
        return Errorf("Can't find abs code {}.", absCode);
    }
    }
    const Sensor& sensor = it->second;
    const Sensor& sensor = it->second;

    ALOGD_IF(DEBUG_MAPPING, "mapSensor: absCode=%d, sensorType=%s, sensorDataIndex=0x%x.", absCode,
#if DEBUG_MAPPING
    ALOGD("mapSensor: absCode=%d, sensorType=%s, sensorDataIndex=0x%x.", absCode,
             ftl::enum_string(sensor.sensorType).c_str(), sensor.sensorDataIndex);
             ftl::enum_string(sensor.sensorType).c_str(), sensor.sensorDataIndex);
#endif
    return std::make_pair(sensor.sensorType, sensor.sensorDataIndex);
    return std::make_pair(sensor.sensorType, sensor.sensorDataIndex);
}
}


@@ -200,21 +200,18 @@ status_t KeyLayoutMap::findScanCodesForKey(
status_t KeyLayoutMap::mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
status_t KeyLayoutMap::mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
    ssize_t index = mAxes.indexOfKey(scanCode);
    ssize_t index = mAxes.indexOfKey(scanCode);
    if (index < 0) {
    if (index < 0) {
#if DEBUG_MAPPING
        ALOGD_IF(DEBUG_MAPPING, "mapAxis: scanCode=%d ~ Failed.", scanCode);
        ALOGD("mapAxis: scanCode=%d ~ Failed.", scanCode);
#endif
        return NAME_NOT_FOUND;
        return NAME_NOT_FOUND;
    }
    }


    *outAxisInfo = mAxes.valueAt(index);
    *outAxisInfo = mAxes.valueAt(index);


#if DEBUG_MAPPING
    ALOGD_IF(DEBUG_MAPPING,
    ALOGD("mapAxis: scanCode=%d ~ Result mode=%d, axis=%d, highAxis=%d, "
             "mapAxis: scanCode=%d ~ Result mode=%d, axis=%d, highAxis=%d, "
             "splitValue=%d, flatOverride=%d.",
             "splitValue=%d, flatOverride=%d.",
            scanCode,
             scanCode, outAxisInfo->mode, outAxisInfo->axis, outAxisInfo->highAxis,
            outAxisInfo->mode, outAxisInfo->axis, outAxisInfo->highAxis,
             outAxisInfo->splitValue, outAxisInfo->flatOverride);
             outAxisInfo->splitValue, outAxisInfo->flatOverride);
#endif

    return NO_ERROR;
    return NO_ERROR;
}
}


@@ -223,15 +220,12 @@ status_t KeyLayoutMap::findScanCodeForLed(int32_t ledCode, int32_t* outScanCode)
    for (size_t i = 0; i < N; i++) {
    for (size_t i = 0; i < N; i++) {
        if (mLedsByScanCode.valueAt(i).ledCode == ledCode) {
        if (mLedsByScanCode.valueAt(i).ledCode == ledCode) {
            *outScanCode = mLedsByScanCode.keyAt(i);
            *outScanCode = mLedsByScanCode.keyAt(i);
#if DEBUG_MAPPING
            ALOGD_IF(DEBUG_MAPPING, "findScanCodeForLed: ledCode=%d, scanCode=%d.", ledCode,
            ALOGD("findScanCodeForLed: ledCode=%d, scanCode=%d.", ledCode, *outScanCode);
                     *outScanCode);
#endif
            return NO_ERROR;
            return NO_ERROR;
        }
        }
    }
    }
#if DEBUG_MAPPING
    ALOGD_IF(DEBUG_MAPPING, "findScanCodeForLed: ledCode=%d ~ Not found.", ledCode);
            ALOGD("findScanCodeForLed: ledCode=%d ~ Not found.", ledCode);
#endif
    return NAME_NOT_FOUND;
    return NAME_NOT_FOUND;
}
}


@@ -240,15 +234,12 @@ status_t KeyLayoutMap::findUsageCodeForLed(int32_t ledCode, int32_t* outUsageCod
    for (size_t i = 0; i < N; i++) {
    for (size_t i = 0; i < N; i++) {
        if (mLedsByUsageCode.valueAt(i).ledCode == ledCode) {
        if (mLedsByUsageCode.valueAt(i).ledCode == ledCode) {
            *outUsageCode = mLedsByUsageCode.keyAt(i);
            *outUsageCode = mLedsByUsageCode.keyAt(i);
#if DEBUG_MAPPING
            ALOGD_IF(DEBUG_MAPPING, "%s: ledCode=%d, usage=%x.", __func__, ledCode, *outUsageCode);
            ALOGD("findUsageForLed: ledCode=%d, usage=%x.", ledCode, *outUsageCode);
#endif
            return NO_ERROR;
            return NO_ERROR;
        }
        }
    }
    }
#if DEBUG_MAPPING
    ALOGD_IF(DEBUG_MAPPING, "%s: ledCode=%d ~ Not found.", __func__, ledCode);
            ALOGD("findUsageForLed: ledCode=%d ~ Not found.", ledCode);

#endif
    return NAME_NOT_FOUND;
    return NAME_NOT_FOUND;
}
}


@@ -264,10 +255,8 @@ KeyLayoutMap::Parser::~Parser() {


status_t KeyLayoutMap::Parser::parse() {
status_t KeyLayoutMap::Parser::parse() {
    while (!mTokenizer->isEof()) {
    while (!mTokenizer->isEof()) {
#if DEBUG_PARSER
        ALOGD_IF(DEBUG_PARSER, "Parsing %s: '%s'.", mTokenizer->getLocation().string(),
        ALOGD("Parsing %s: '%s'.", mTokenizer->getLocation().string(),
                 mTokenizer->peekRemainderOfLine().string());
                 mTokenizer->peekRemainderOfLine().string());
#endif


        mTokenizer->skipDelimiters(WHITESPACE);
        mTokenizer->skipDelimiters(WHITESPACE);


@@ -361,10 +350,9 @@ status_t KeyLayoutMap::Parser::parseKey() {
        flags |= flag;
        flags |= flag;
    }
    }


#if DEBUG_PARSER
    ALOGD_IF(DEBUG_PARSER, "Parsed key %s: code=%d, keyCode=%d, flags=0x%08x.",
    ALOGD("Parsed key %s: code=%d, keyCode=%d, flags=0x%08x.",
             mapUsage ? "usage" : "scan code", code, keyCode, flags);
             mapUsage ? "usage" : "scan code", code, keyCode, flags);
#endif

    Key key;
    Key key;
    key.keyCode = keyCode;
    key.keyCode = keyCode;
    key.flags = flags;
    key.flags = flags;
@@ -462,13 +450,12 @@ status_t KeyLayoutMap::Parser::parseAxis() {
        }
        }
    }
    }


#if DEBUG_PARSER
    ALOGD_IF(DEBUG_PARSER,
    ALOGD("Parsed axis: scanCode=%d, mode=%d, axis=%d, highAxis=%d, "
             "Parsed axis: scanCode=%d, mode=%d, axis=%d, highAxis=%d, "
             "splitValue=%d, flatOverride=%d.",
             "splitValue=%d, flatOverride=%d.",
            scanCode,
             scanCode, axisInfo.mode, axisInfo.axis, axisInfo.highAxis, axisInfo.splitValue,
            axisInfo.mode, axisInfo.axis, axisInfo.highAxis,
             axisInfo.flatOverride);
            axisInfo.splitValue, axisInfo.flatOverride);

#endif
    mMap->mAxes.add(scanCode, axisInfo);
    mMap->mAxes.add(scanCode, axisInfo);
    return NO_ERROR;
    return NO_ERROR;
}
}
@@ -505,10 +492,8 @@ status_t KeyLayoutMap::Parser::parseLed() {
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }


#if DEBUG_PARSER
    ALOGD_IF(DEBUG_PARSER, "Parsed led %s: code=%d, ledCode=%d.", mapUsage ? "usage" : "scan code",
    ALOGD("Parsed led %s: code=%d, ledCode=%d.",
             code, ledCode);
            mapUsage ? "usage" : "scan code", code, ledCode);
#endif


    Led led;
    Led led;
    led.ledCode = ledCode;
    led.ledCode = ledCode;
@@ -584,10 +569,8 @@ status_t KeyLayoutMap::Parser::parseSensor() {
    }
    }
    int32_t sensorDataIndex = indexOpt.value();
    int32_t sensorDataIndex = indexOpt.value();


#if DEBUG_PARSER
    ALOGD_IF(DEBUG_PARSER, "Parsed sensor: abs code=%d, sensorType=%s, sensorDataIndex=%d.", code,
    ALOGD("Parsed sensor: abs code=%d, sensorType=%s, sensorDataIndex=%d.", code,
             ftl::enum_string(sensorType).c_str(), sensorDataIndex);
             ftl::enum_string(sensorType).c_str(), sensorDataIndex);
#endif


    Sensor sensor;
    Sensor sensor;
    sensor.sensorType = sensorType;
    sensor.sensorType = sensorType;
+1 −3
Original line number Original line Diff line number Diff line
@@ -64,13 +64,11 @@ protected:
        mKeyMap.keyCharacterMapFile = path;
        mKeyMap.keyCharacterMapFile = path;
    }
    }


    virtual void SetUp() override {
    void SetUp() override {
        loadKeyLayout("Generic");
        loadKeyLayout("Generic");
        loadKeyCharacterMap("Generic");
        loadKeyCharacterMap("Generic");
    }
    }


    virtual void TearDown() override {}

    KeyMap mKeyMap;
    KeyMap mKeyMap;
};
};