widget/gonk/libui/InputDevice.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/libui/InputDevice.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,156 @@
     1.4 +/*
     1.5 + * Copyright (C) 2012 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef _ANDROIDFW_INPUT_DEVICE_H
    1.21 +#define _ANDROIDFW_INPUT_DEVICE_H
    1.22 +
    1.23 +#include "Input.h"
    1.24 +#include "KeyCharacterMap.h"
    1.25 +
    1.26 +namespace android {
    1.27 +
    1.28 +/*
    1.29 + * Identifies a device.
    1.30 + */
    1.31 +struct InputDeviceIdentifier {
    1.32 +    inline InputDeviceIdentifier() :
    1.33 +            bus(0), vendor(0), product(0), version(0) {
    1.34 +    }
    1.35 +
    1.36 +    // Information provided by the kernel.
    1.37 +    String8 name;
    1.38 +    String8 location;
    1.39 +    String8 uniqueId;
    1.40 +    uint16_t bus;
    1.41 +    uint16_t vendor;
    1.42 +    uint16_t product;
    1.43 +    uint16_t version;
    1.44 +
    1.45 +    // A composite input device descriptor string that uniquely identifies the device
    1.46 +    // even across reboots or reconnections.  The value of this field is used by
    1.47 +    // upper layers of the input system to associate settings with individual devices.
    1.48 +    // It is hashed from whatever kernel provided information is available.
    1.49 +    // Ideally, the way this value is computed should not change between Android releases
    1.50 +    // because that would invalidate persistent settings that rely on it.
    1.51 +    String8 descriptor;
    1.52 +};
    1.53 +
    1.54 +/*
    1.55 + * Describes the characteristics and capabilities of an input device.
    1.56 + */
    1.57 +class InputDeviceInfo {
    1.58 +public:
    1.59 +    InputDeviceInfo();
    1.60 +    InputDeviceInfo(const InputDeviceInfo& other);
    1.61 +    ~InputDeviceInfo();
    1.62 +
    1.63 +    struct MotionRange {
    1.64 +        int32_t axis;
    1.65 +        uint32_t source;
    1.66 +        float min;
    1.67 +        float max;
    1.68 +        float flat;
    1.69 +        float fuzz;
    1.70 +        float resolution;
    1.71 +    };
    1.72 +
    1.73 +    void initialize(int32_t id, int32_t generation, const InputDeviceIdentifier& identifier,
    1.74 +            const String8& alias, bool isExternal);
    1.75 +
    1.76 +    inline int32_t getId() const { return mId; }
    1.77 +    inline int32_t getGeneration() const { return mGeneration; }
    1.78 +    inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; }
    1.79 +    inline const String8& getAlias() const { return mAlias; }
    1.80 +    inline const String8& getDisplayName() const {
    1.81 +        return mAlias.isEmpty() ? mIdentifier.name : mAlias;
    1.82 +    }
    1.83 +    inline bool isExternal() const { return mIsExternal; }
    1.84 +    inline uint32_t getSources() const { return mSources; }
    1.85 +
    1.86 +    const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
    1.87 +
    1.88 +    void addSource(uint32_t source);
    1.89 +    void addMotionRange(int32_t axis, uint32_t source,
    1.90 +            float min, float max, float flat, float fuzz, float resolution);
    1.91 +    void addMotionRange(const MotionRange& range);
    1.92 +
    1.93 +    inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
    1.94 +    inline int32_t getKeyboardType() const { return mKeyboardType; }
    1.95 +
    1.96 +    inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
    1.97 +        mKeyCharacterMap = value;
    1.98 +    }
    1.99 +
   1.100 +    inline sp<KeyCharacterMap> getKeyCharacterMap() const {
   1.101 +        return mKeyCharacterMap;
   1.102 +    }
   1.103 +
   1.104 +    inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
   1.105 +    inline bool hasVibrator() const { return mHasVibrator; }
   1.106 +
   1.107 +    inline const Vector<MotionRange>& getMotionRanges() const {
   1.108 +        return mMotionRanges;
   1.109 +    }
   1.110 +
   1.111 +private:
   1.112 +    int32_t mId;
   1.113 +    int32_t mGeneration;
   1.114 +    InputDeviceIdentifier mIdentifier;
   1.115 +    String8 mAlias;
   1.116 +    bool mIsExternal;
   1.117 +    uint32_t mSources;
   1.118 +    int32_t mKeyboardType;
   1.119 +    sp<KeyCharacterMap> mKeyCharacterMap;
   1.120 +    bool mHasVibrator;
   1.121 +
   1.122 +    Vector<MotionRange> mMotionRanges;
   1.123 +};
   1.124 +
   1.125 +/* Types of input device configuration files. */
   1.126 +enum InputDeviceConfigurationFileType {
   1.127 +    INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0,     /* .idc file */
   1.128 +    INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1,        /* .kl file */
   1.129 +    INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
   1.130 +};
   1.131 +
   1.132 +/*
   1.133 + * Gets the path of an input device configuration file, if one is available.
   1.134 + * Considers both system provided and user installed configuration files.
   1.135 + *
   1.136 + * The device identifier is used to construct several default configuration file
   1.137 + * names to try based on the device name, vendor, product, and version.
   1.138 + *
   1.139 + * Returns an empty string if not found.
   1.140 + */
   1.141 +extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(
   1.142 +        const InputDeviceIdentifier& deviceIdentifier,
   1.143 +        InputDeviceConfigurationFileType type);
   1.144 +
   1.145 +/*
   1.146 + * Gets the path of an input device configuration file, if one is available.
   1.147 + * Considers both system provided and user installed configuration files.
   1.148 + *
   1.149 + * The name is case-sensitive and is used to construct the filename to resolve.
   1.150 + * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores.
   1.151 + *
   1.152 + * Returns an empty string if not found.
   1.153 + */
   1.154 +extern String8 getInputDeviceConfigurationFilePathByName(
   1.155 +        const String8& name, InputDeviceConfigurationFileType type);
   1.156 +
   1.157 +} // namespace android
   1.158 +
   1.159 +#endif // _ANDROIDFW_INPUT_DEVICE_H

mercurial