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

Commit 9201d5ad authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "Fetch country code information from Device sysfs path"

parents 5e8ae0d5 dd82b8eb
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@
#include <unordered_map>
#include <vector>

#include "android/hardware/input/InputDeviceCountryCode.h"

namespace android {

/*
@@ -210,8 +212,10 @@ public:
    };

    void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
            const InputDeviceIdentifier& identifier, const std::string& alias, bool isExternal,
            bool hasMic);
                    const InputDeviceIdentifier& identifier, const std::string& alias,
                    bool isExternal, bool hasMic,
                    hardware::input::InputDeviceCountryCode countryCode =
                            hardware::input::InputDeviceCountryCode::INVALID);

    inline int32_t getId() const { return mId; }
    inline int32_t getControllerNumber() const { return mControllerNumber; }
@@ -223,6 +227,7 @@ public:
    }
    inline bool isExternal() const { return mIsExternal; }
    inline bool hasMic() const { return mHasMic; }
    inline hardware::input::InputDeviceCountryCode getCountryCode() const { return mCountryCode; }
    inline uint32_t getSources() const { return mSources; }

    const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
@@ -274,9 +279,11 @@ private:
    std::string mAlias;
    bool mIsExternal;
    bool mHasMic;
    hardware::input::InputDeviceCountryCode mCountryCode;
    uint32_t mSources;
    int32_t mKeyboardType;
    std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;

    bool mHasVibrator;
    bool mHasBattery;
    bool mHasButtonUnderPad;
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ package {
filegroup {
    name: "inputconstants_aidl",
    srcs: [
        "android/hardware/input/InputDeviceCountryCode.aidl",
        "android/os/IInputConstants.aidl",
        "android/os/InputEventInjectionResult.aidl",
        "android/os/InputEventInjectionSync.aidl",
+5 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <input/InputEventLabels.h>

using android::base::StringPrintf;
using android::hardware::input::InputDeviceCountryCode;

namespace android {

@@ -177,6 +178,7 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
        mAlias(other.mAlias),
        mIsExternal(other.mIsExternal),
        mHasMic(other.mHasMic),
        mCountryCode(other.mCountryCode),
        mSources(other.mSources),
        mKeyboardType(other.mKeyboardType),
        mKeyCharacterMap(other.mKeyCharacterMap),
@@ -192,8 +194,8 @@ 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) {
                                 const InputDeviceIdentifier& identifier, const std::string& alias,
                                 bool isExternal, bool hasMic, InputDeviceCountryCode countryCode) {
    mId = id;
    mGeneration = generation;
    mControllerNumber = controllerNumber;
@@ -201,6 +203,7 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control
    mAlias = alias;
    mIsExternal = isExternal;
    mHasMic = hasMic;
    mCountryCode = countryCode;
    mSources = 0;
    mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
    mHasVibrator = false;
+212 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */

package android.hardware.input;

/**
 * Constant for HID country code declared by a HID device. These constants are declared as AIDL to
 * be used by java and native input code.
 *
 * @hide
 */
@Backing(type="int")
enum InputDeviceCountryCode {
    /**
     * Used as default value where country code is not set in the device HID descriptor
     */
    INVALID = -1,

    /**
     * Used as default value when country code is not supported by the HID device. The HID
     * descriptor sets "00" as the country code in this case.
     */
    NOT_SUPPORTED = 0,

    /**
     * Arabic
     */
    ARABIC = 1,

    /**
     * Belgian
     */
    BELGIAN = 2,

    /**
     * Canadian (Bilingual)
     */
    CANADIAN_BILINGUAL = 3,

    /**
     * Canadian (French)
     */
    CANADIAN_FRENCH = 4,

    /**
     * Czech Republic
     */
    CZECH_REPUBLIC = 5,

    /**
     * Danish
     */
    DANISH = 6,

    /**
     * Finnish
     */
    FINNISH = 7,

    /**
     * French
     */
    FRENCH = 8,

    /**
     * German
     */
    GERMAN = 9,

    /**
     * Greek
     */
    GREEK = 10,

    /**
     * Hebrew
     */
    HEBREW = 11,

    /**
     * Hungary
     */
    HUNGARY = 12,

    /**
     * International (ISO)
     */
    INTERNATIONAL = 13,

    /**
     * Italian
     */
    ITALIAN = 14,

    /**
     * Japan (Katakana)
     */
    JAPAN = 15,

    /**
     * Korean
     */
    KOREAN = 16,

    /**
     * Latin American
     */
    LATIN_AMERICAN = 17,

    /**
     * Netherlands (Dutch)
     */
    DUTCH = 18,

    /**
     * Norwegian
     */
    NORWEGIAN = 19,

    /**
     * Persian
     */
    PERSIAN = 20,

    /**
     * Poland
     */
    POLAND = 21,

    /**
     * Portuguese
     */
    PORTUGUESE = 22,

    /**
     * Russia
     */
    RUSSIA = 23,

    /**
     * Slovakia
     */
    SLOVAKIA = 24,

    /**
     * Spanish
     */
    SPANISH = 25,

    /**
     * Swedish
     */
    SWEDISH = 26,

    /**
     * Swiss (French)
     */
    SWISS_FRENCH = 27,

    /**
     * Swiss (German)
     */
    SWISS_GERMAN = 28,

    /**
     * Switzerland
     */
    SWITZERLAND = 29,

    /**
     * Taiwan
     */
    TAIWAN = 30,

    /**
     * Turkish_Q
     */
    TURKISH_Q = 31,

    /**
     * UK
     */
    UK = 32,

    /**
     * US
     */
    US = 33,

    /**
     * Yugoslavia
     */
    YUGOSLAVIA = 34,

    /**
     * Turkish_F
     */
    TURKISH_F = 35,
}
 No newline at end of file
+32 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@
#define INDENT3 "      "

using android::base::StringPrintf;
using android::hardware::input::InputDeviceCountryCode;

namespace android {

@@ -301,6 +302,24 @@ static std::optional<std::array<LightColor, COLOR_NUM>> getColorIndexArray(
    return colors;
}

/**
 * Read country code information exposed through the sysfs path.
 */
static InputDeviceCountryCode readCountryCodeLocked(const std::filesystem::path& sysfsRootPath) {
    // Check the sysfs root path
    int hidCountryCode = static_cast<int>(InputDeviceCountryCode::INVALID);
    std::string str;
    if (base::ReadFileToString(sysfsRootPath / "country", &str)) {
        hidCountryCode = std::stoi(str, nullptr, 16);
        LOG_ALWAYS_FATAL_IF(hidCountryCode > 35 || hidCountryCode < 0,
                            "HID country code should be in range [0, 35]. Found country code "
                            "to be %d",
                            hidCountryCode);
    }

    return static_cast<InputDeviceCountryCode>(hidCountryCode);
}

/**
 * Read information about batteries exposed through the sysfs path.
 */
@@ -1238,6 +1257,15 @@ void EventHub::setLightIntensities(int32_t deviceId, int32_t lightId,
    }
}

InputDeviceCountryCode EventHub::getCountryCode(int32_t deviceId) const {
    std::scoped_lock _l(mLock);
    Device* device = getDeviceLocked(deviceId);
    if (device == nullptr || !device->associatedDevice) {
        return InputDeviceCountryCode::INVALID;
    }
    return device->associatedDevice->countryCode;
}

void EventHub::setExcludedDevices(const std::vector<std::string>& devices) {
    std::scoped_lock _l(mLock);

@@ -1384,6 +1412,7 @@ std::shared_ptr<const EventHub::AssociatedDevice> EventHub::obtainAssociatedDevi

    return std::make_shared<AssociatedDevice>(
            AssociatedDevice{.sysfsRootPath = path,
                             .countryCode = readCountryCodeLocked(path),
                             .batteryInfos = readBatteryConfiguration(path),
                             .lightInfos = readLightsConfiguration(path)});
}
@@ -2553,6 +2582,9 @@ void EventHub::dump(std::string& dump) const {
                                 device->keyMap.keyLayoutFile.c_str());
            dump += StringPrintf(INDENT3 "KeyCharacterMapFile: %s\n",
                                 device->keyMap.keyCharacterMapFile.c_str());
            dump += StringPrintf(INDENT3 "CountryCode: %d\n",
                                 device->associatedDevice ? device->associatedDevice->countryCode
                                                          : InputDeviceCountryCode::INVALID);
            dump += StringPrintf(INDENT3 "ConfigurationFile: %s\n",
                                 device->configurationFile.c_str());
            dump += StringPrintf(INDENT3 "VideoDevice: %s\n",
Loading