Home | History | Annotate | Download | only in input
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _LIBINPUT_INPUT_DEVICE_H
     18 #define _LIBINPUT_INPUT_DEVICE_H
     19 
     20 #include <input/Input.h>
     21 #include <input/KeyCharacterMap.h>
     22 
     23 namespace android {
     24 
     25 /*
     26  * Identifies a device.
     27  */
     28 struct InputDeviceIdentifier {
     29     inline InputDeviceIdentifier() :
     30             bus(0), vendor(0), product(0), version(0) {
     31     }
     32 
     33     // Information provided by the kernel.
     34     String8 name;
     35     String8 location;
     36     String8 uniqueId;
     37     uint16_t bus;
     38     uint16_t vendor;
     39     uint16_t product;
     40     uint16_t version;
     41 
     42     // A composite input device descriptor string that uniquely identifies the device
     43     // even across reboots or reconnections.  The value of this field is used by
     44     // upper layers of the input system to associate settings with individual devices.
     45     // It is hashed from whatever kernel provided information is available.
     46     // Ideally, the way this value is computed should not change between Android releases
     47     // because that would invalidate persistent settings that rely on it.
     48     String8 descriptor;
     49 
     50     // A value added to uniquely identify a device in the absence of a unique id. This
     51     // is intended to be a minimum way to distinguish from other active devices and may
     52     // reuse values that are not associated with an input anymore.
     53     uint16_t nonce;
     54 };
     55 
     56 /*
     57  * Describes the characteristics and capabilities of an input device.
     58  */
     59 class InputDeviceInfo {
     60 public:
     61     InputDeviceInfo();
     62     InputDeviceInfo(const InputDeviceInfo& other);
     63     ~InputDeviceInfo();
     64 
     65     struct MotionRange {
     66         int32_t axis;
     67         uint32_t source;
     68         float min;
     69         float max;
     70         float flat;
     71         float fuzz;
     72         float resolution;
     73     };
     74 
     75     void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
     76             const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal);
     77 
     78     inline int32_t getId() const { return mId; }
     79     inline int32_t getControllerNumber() const { return mControllerNumber; }
     80     inline int32_t getGeneration() const { return mGeneration; }
     81     inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; }
     82     inline const String8& getAlias() const { return mAlias; }
     83     inline const String8& getDisplayName() const {
     84         return mAlias.isEmpty() ? mIdentifier.name : mAlias;
     85     }
     86     inline bool isExternal() const { return mIsExternal; }
     87     inline uint32_t getSources() const { return mSources; }
     88 
     89     const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
     90 
     91     void addSource(uint32_t source);
     92     void addMotionRange(int32_t axis, uint32_t source,
     93             float min, float max, float flat, float fuzz, float resolution);
     94     void addMotionRange(const MotionRange& range);
     95 
     96     inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
     97     inline int32_t getKeyboardType() const { return mKeyboardType; }
     98 
     99     inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
    100         mKeyCharacterMap = value;
    101     }
    102 
    103     inline sp<KeyCharacterMap> getKeyCharacterMap() const {
    104         return mKeyCharacterMap;
    105     }
    106 
    107     inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
    108     inline bool hasVibrator() const { return mHasVibrator; }
    109 
    110     inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; }
    111     inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; }
    112 
    113     inline const Vector<MotionRange>& getMotionRanges() const {
    114         return mMotionRanges;
    115     }
    116 
    117 private:
    118     int32_t mId;
    119     int32_t mGeneration;
    120     int32_t mControllerNumber;
    121     InputDeviceIdentifier mIdentifier;
    122     String8 mAlias;
    123     bool mIsExternal;
    124     uint32_t mSources;
    125     int32_t mKeyboardType;
    126     sp<KeyCharacterMap> mKeyCharacterMap;
    127     bool mHasVibrator;
    128     bool mHasButtonUnderPad;
    129 
    130     Vector<MotionRange> mMotionRanges;
    131 };
    132 
    133 /* Types of input device configuration files. */
    134 enum InputDeviceConfigurationFileType {
    135     INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0,     /* .idc file */
    136     INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1,        /* .kl file */
    137     INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
    138 };
    139 
    140 /*
    141  * Gets the path of an input device configuration file, if one is available.
    142  * Considers both system provided and user installed configuration files.
    143  *
    144  * The device identifier is used to construct several default configuration file
    145  * names to try based on the device name, vendor, product, and version.
    146  *
    147  * Returns an empty string if not found.
    148  */
    149 extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(
    150         const InputDeviceIdentifier& deviceIdentifier,
    151         InputDeviceConfigurationFileType type);
    152 
    153 /*
    154  * Gets the path of an input device configuration file, if one is available.
    155  * Considers both system provided and user installed configuration files.
    156  *
    157  * The name is case-sensitive and is used to construct the filename to resolve.
    158  * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores.
    159  *
    160  * Returns an empty string if not found.
    161  */
    162 extern String8 getInputDeviceConfigurationFilePathByName(
    163         const String8& name, InputDeviceConfigurationFileType type);
    164 
    165 } // namespace android
    166 
    167 #endif // _LIBINPUT_INPUT_DEVICE_H
    168