Pass through availability of audio mic for input devices.

Bug: 15374820
Change-Id: Id2ca6da10165e3a887ebfbb18f663a3bf316ac79
This commit is contained in:
Tim Kilbourn 2015-04-08 10:26:18 -07:00
parent 82f393aad6
commit 063ff53d0b
6 changed files with 43 additions and 9 deletions

View File

@ -73,7 +73,8 @@ public:
}; };
void initialize(int32_t id, int32_t generation, int32_t controllerNumber, void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal); const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal,
bool hasMic);
inline int32_t getId() const { return mId; } inline int32_t getId() const { return mId; }
inline int32_t getControllerNumber() const { return mControllerNumber; } inline int32_t getControllerNumber() const { return mControllerNumber; }
@ -84,6 +85,7 @@ public:
return mAlias.isEmpty() ? mIdentifier.name : mAlias; return mAlias.isEmpty() ? mIdentifier.name : mAlias;
} }
inline bool isExternal() const { return mIsExternal; } inline bool isExternal() const { return mIsExternal; }
inline bool hasMic() const { return mHasMic; }
inline uint32_t getSources() const { return mSources; } inline uint32_t getSources() const { return mSources; }
const MotionRange* getMotionRange(int32_t axis, uint32_t source) const; const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
@ -121,6 +123,7 @@ private:
InputDeviceIdentifier mIdentifier; InputDeviceIdentifier mIdentifier;
String8 mAlias; String8 mAlias;
bool mIsExternal; bool mIsExternal;
bool mHasMic;
uint32_t mSources; uint32_t mSources;
int32_t mKeyboardType; int32_t mKeyboardType;
sp<KeyCharacterMap> mKeyCharacterMap; sp<KeyCharacterMap> mKeyCharacterMap;

View File

@ -127,28 +127,31 @@ String8 getInputDeviceConfigurationFilePathByName(
// --- InputDeviceInfo --- // --- InputDeviceInfo ---
InputDeviceInfo::InputDeviceInfo() { InputDeviceInfo::InputDeviceInfo() {
initialize(-1, 0, -1, InputDeviceIdentifier(), String8(), false); initialize(-1, 0, -1, InputDeviceIdentifier(), String8(), false, false);
} }
InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) : InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) :
mId(other.mId), mGeneration(other.mGeneration), mControllerNumber(other.mControllerNumber), mId(other.mId), mGeneration(other.mGeneration), mControllerNumber(other.mControllerNumber),
mIdentifier(other.mIdentifier), mAlias(other.mAlias), mIsExternal(other.mIsExternal), mIdentifier(other.mIdentifier), mAlias(other.mAlias), mIsExternal(other.mIsExternal),
mSources(other.mSources), mKeyboardType(other.mKeyboardType), mHasMic(other.mHasMic), mSources(other.mSources),
mKeyCharacterMap(other.mKeyCharacterMap), mHasVibrator(other.mHasVibrator), mKeyboardType(other.mKeyboardType), mKeyCharacterMap(other.mKeyCharacterMap),
mHasButtonUnderPad(other.mHasButtonUnderPad), mMotionRanges(other.mMotionRanges) { mHasVibrator(other.mHasVibrator), mHasButtonUnderPad(other.mHasButtonUnderPad),
mMotionRanges(other.mMotionRanges) {
} }
InputDeviceInfo::~InputDeviceInfo() { InputDeviceInfo::~InputDeviceInfo() {
} }
void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t controllerNumber, void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t controllerNumber,
const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal) { const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal,
bool hasMic) {
mId = id; mId = id;
mGeneration = generation; mGeneration = generation;
mControllerNumber = controllerNumber; mControllerNumber = controllerNumber;
mIdentifier = identifier; mIdentifier = identifier;
mAlias = alias; mAlias = alias;
mIsExternal = isExternal; mIsExternal = isExternal;
mHasMic = hasMic;
mSources = 0; mSources = 0;
mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE; mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
mHasVibrator = false; mHasVibrator = false;

View File

@ -1279,6 +1279,11 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {
return -1; return -1;
} }
// Determine whether the device has a mic.
if (deviceHasMicLocked(device)) {
device->classes |= INPUT_DEVICE_CLASS_MIC;
}
// Determine whether the device is external or internal. // Determine whether the device is external or internal.
if (isExternalDeviceLocked(device)) { if (isExternalDeviceLocked(device)) {
device->classes |= INPUT_DEVICE_CLASS_EXTERNAL; device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
@ -1415,6 +1420,16 @@ bool EventHub::isExternalDeviceLocked(Device* device) {
return device->identifier.bus == BUS_USB || device->identifier.bus == BUS_BLUETOOTH; return device->identifier.bus == BUS_USB || device->identifier.bus == BUS_BLUETOOTH;
} }
bool EventHub::deviceHasMicLocked(Device* device) {
if (device->configuration) {
bool value;
if (device->configuration->tryGetProperty(String8("audio.mic"), value)) {
return value;
}
}
return false;
}
int32_t EventHub::getNextControllerNumberLocked(Device* device) { int32_t EventHub::getNextControllerNumberLocked(Device* device) {
if (mControllerNumbers.isFull()) { if (mControllerNumbers.isFull()) {
ALOGI("Maximum number of controllers reached, assigning controller number 0 to device %s", ALOGI("Maximum number of controllers reached, assigning controller number 0 to device %s",

View File

@ -131,6 +131,9 @@ enum {
/* The input device has a vibrator (supports FF_RUMBLE). */ /* The input device has a vibrator (supports FF_RUMBLE). */
INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200, INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200,
/* The input device has a microphone. */
INPUT_DEVICE_CLASS_MIC = 0x00000400,
/* The input device is virtual (not a real device, not part of UI configuration). */ /* The input device is virtual (not a real device, not part of UI configuration). */
INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000, INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000,
@ -394,6 +397,7 @@ private:
status_t loadKeyMapLocked(Device* device); status_t loadKeyMapLocked(Device* device);
bool isExternalDeviceLocked(Device* device); bool isExternalDeviceLocked(Device* device);
bool deviceHasMicLocked(Device* device);
int32_t getNextControllerNumberLocked(Device* device); int32_t getNextControllerNumberLocked(Device* device);
void releaseControllerNumberLocked(Device* device); void releaseControllerNumberLocked(Device* device);

View File

@ -417,6 +417,11 @@ InputDevice* InputReader::createDeviceLocked(int32_t deviceId, int32_t controlle
device->setExternal(true); device->setExternal(true);
} }
// Devices with mics.
if (classes & INPUT_DEVICE_CLASS_MIC) {
device->setMic(true);
}
// Switch-like devices. // Switch-like devices.
if (classes & INPUT_DEVICE_CLASS_SWITCH) { if (classes & INPUT_DEVICE_CLASS_SWITCH) {
device->addMapper(new SwitchInputMapper(device)); device->addMapper(new SwitchInputMapper(device));
@ -858,7 +863,7 @@ InputDevice::InputDevice(InputReaderContext* context, int32_t id, int32_t genera
int32_t controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes) : int32_t controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes) :
mContext(context), mId(id), mGeneration(generation), mControllerNumber(controllerNumber), mContext(context), mId(id), mGeneration(generation), mControllerNumber(controllerNumber),
mIdentifier(identifier), mClasses(classes), mIdentifier(identifier), mClasses(classes),
mSources(0), mIsExternal(false), mDropUntilNextSync(false) { mSources(0), mIsExternal(false), mHasMic(false), mDropUntilNextSync(false) {
} }
InputDevice::~InputDevice() { InputDevice::~InputDevice() {
@ -877,6 +882,7 @@ void InputDevice::dump(String8& dump) {
deviceInfo.getDisplayName().string()); deviceInfo.getDisplayName().string());
dump.appendFormat(INDENT2 "Generation: %d\n", mGeneration); dump.appendFormat(INDENT2 "Generation: %d\n", mGeneration);
dump.appendFormat(INDENT2 "IsExternal: %s\n", toString(mIsExternal)); dump.appendFormat(INDENT2 "IsExternal: %s\n", toString(mIsExternal));
dump.appendFormat(INDENT2 "HasMic: %s\n", toString(mHasMic));
dump.appendFormat(INDENT2 "Sources: 0x%08x\n", deviceInfo.getSources()); dump.appendFormat(INDENT2 "Sources: 0x%08x\n", deviceInfo.getSources());
dump.appendFormat(INDENT2 "KeyboardType: %d\n", deviceInfo.getKeyboardType()); dump.appendFormat(INDENT2 "KeyboardType: %d\n", deviceInfo.getKeyboardType());
@ -1008,8 +1014,7 @@ void InputDevice::timeoutExpired(nsecs_t when) {
void InputDevice::getDeviceInfo(InputDeviceInfo* outDeviceInfo) { void InputDevice::getDeviceInfo(InputDeviceInfo* outDeviceInfo) {
outDeviceInfo->initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, outDeviceInfo->initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias,
mIsExternal); mIsExternal, mHasMic);
size_t numMappers = mMappers.size(); size_t numMappers = mMappers.size();
for (size_t i = 0; i < numMappers; i++) { for (size_t i = 0; i < numMappers; i++) {
InputMapper* mapper = mMappers[i]; InputMapper* mapper = mMappers[i];

View File

@ -555,6 +555,9 @@ public:
inline bool isExternal() { return mIsExternal; } inline bool isExternal() { return mIsExternal; }
inline void setExternal(bool external) { mIsExternal = external; } inline void setExternal(bool external) { mIsExternal = external; }
inline void setMic(bool hasMic) { mHasMic = hasMic; }
inline bool hasMic() const { return mHasMic; }
inline bool isIgnored() { return mMappers.isEmpty(); } inline bool isIgnored() { return mMappers.isEmpty(); }
void dump(String8& dump); void dump(String8& dump);
@ -618,6 +621,7 @@ private:
uint32_t mSources; uint32_t mSources;
bool mIsExternal; bool mIsExternal;
bool mHasMic;
bool mDropUntilNextSync; bool mDropUntilNextSync;
typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code); typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);