michael@0: /* michael@0: * Copyright (C) 2012 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef _ANDROIDFW_INPUT_DEVICE_H michael@0: #define _ANDROIDFW_INPUT_DEVICE_H michael@0: michael@0: #include "Input.h" michael@0: #include "KeyCharacterMap.h" michael@0: michael@0: namespace android { michael@0: michael@0: /* michael@0: * Identifies a device. michael@0: */ michael@0: struct InputDeviceIdentifier { michael@0: inline InputDeviceIdentifier() : michael@0: bus(0), vendor(0), product(0), version(0) { michael@0: } michael@0: michael@0: // Information provided by the kernel. michael@0: String8 name; michael@0: String8 location; michael@0: String8 uniqueId; michael@0: uint16_t bus; michael@0: uint16_t vendor; michael@0: uint16_t product; michael@0: uint16_t version; michael@0: michael@0: // A composite input device descriptor string that uniquely identifies the device michael@0: // even across reboots or reconnections. The value of this field is used by michael@0: // upper layers of the input system to associate settings with individual devices. michael@0: // It is hashed from whatever kernel provided information is available. michael@0: // Ideally, the way this value is computed should not change between Android releases michael@0: // because that would invalidate persistent settings that rely on it. michael@0: String8 descriptor; michael@0: }; michael@0: michael@0: /* michael@0: * Describes the characteristics and capabilities of an input device. michael@0: */ michael@0: class InputDeviceInfo { michael@0: public: michael@0: InputDeviceInfo(); michael@0: InputDeviceInfo(const InputDeviceInfo& other); michael@0: ~InputDeviceInfo(); michael@0: michael@0: struct MotionRange { michael@0: int32_t axis; michael@0: uint32_t source; michael@0: float min; michael@0: float max; michael@0: float flat; michael@0: float fuzz; michael@0: float resolution; michael@0: }; michael@0: michael@0: void initialize(int32_t id, int32_t generation, const InputDeviceIdentifier& identifier, michael@0: const String8& alias, bool isExternal); michael@0: michael@0: inline int32_t getId() const { return mId; } michael@0: inline int32_t getGeneration() const { return mGeneration; } michael@0: inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; } michael@0: inline const String8& getAlias() const { return mAlias; } michael@0: inline const String8& getDisplayName() const { michael@0: return mAlias.isEmpty() ? mIdentifier.name : mAlias; michael@0: } michael@0: inline bool isExternal() const { return mIsExternal; } michael@0: inline uint32_t getSources() const { return mSources; } michael@0: michael@0: const MotionRange* getMotionRange(int32_t axis, uint32_t source) const; michael@0: michael@0: void addSource(uint32_t source); michael@0: void addMotionRange(int32_t axis, uint32_t source, michael@0: float min, float max, float flat, float fuzz, float resolution); michael@0: void addMotionRange(const MotionRange& range); michael@0: michael@0: inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } michael@0: inline int32_t getKeyboardType() const { return mKeyboardType; } michael@0: michael@0: inline void setKeyCharacterMap(const sp& value) { michael@0: mKeyCharacterMap = value; michael@0: } michael@0: michael@0: inline sp getKeyCharacterMap() const { michael@0: return mKeyCharacterMap; michael@0: } michael@0: michael@0: inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; } michael@0: inline bool hasVibrator() const { return mHasVibrator; } michael@0: michael@0: inline const Vector& getMotionRanges() const { michael@0: return mMotionRanges; michael@0: } michael@0: michael@0: private: michael@0: int32_t mId; michael@0: int32_t mGeneration; michael@0: InputDeviceIdentifier mIdentifier; michael@0: String8 mAlias; michael@0: bool mIsExternal; michael@0: uint32_t mSources; michael@0: int32_t mKeyboardType; michael@0: sp mKeyCharacterMap; michael@0: bool mHasVibrator; michael@0: michael@0: Vector mMotionRanges; michael@0: }; michael@0: michael@0: /* Types of input device configuration files. */ michael@0: enum InputDeviceConfigurationFileType { michael@0: INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */ michael@0: INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */ michael@0: INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */ michael@0: }; michael@0: michael@0: /* michael@0: * Gets the path of an input device configuration file, if one is available. michael@0: * Considers both system provided and user installed configuration files. michael@0: * michael@0: * The device identifier is used to construct several default configuration file michael@0: * names to try based on the device name, vendor, product, and version. michael@0: * michael@0: * Returns an empty string if not found. michael@0: */ michael@0: extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier( michael@0: const InputDeviceIdentifier& deviceIdentifier, michael@0: InputDeviceConfigurationFileType type); michael@0: michael@0: /* michael@0: * Gets the path of an input device configuration file, if one is available. michael@0: * Considers both system provided and user installed configuration files. michael@0: * michael@0: * The name is case-sensitive and is used to construct the filename to resolve. michael@0: * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores. michael@0: * michael@0: * Returns an empty string if not found. michael@0: */ michael@0: extern String8 getInputDeviceConfigurationFilePathByName( michael@0: const String8& name, InputDeviceConfigurationFileType type); michael@0: michael@0: } // namespace android michael@0: michael@0: #endif // _ANDROIDFW_INPUT_DEVICE_H