use of android.view.InputDevice in project android_frameworks_base by ParanoidAndroid.
the class InputManager method onInputDevicesChanged.
private void onInputDevicesChanged(int[] deviceIdAndGeneration) {
if (DEBUG) {
Log.d(TAG, "Received input devices changed.");
}
synchronized (mInputDevicesLock) {
for (int i = mInputDevices.size(); --i > 0; ) {
final int deviceId = mInputDevices.keyAt(i);
if (!containsDeviceId(deviceIdAndGeneration, deviceId)) {
if (DEBUG) {
Log.d(TAG, "Device removed: " + deviceId);
}
mInputDevices.removeAt(i);
sendMessageToInputDeviceListenersLocked(MSG_DEVICE_REMOVED, deviceId);
}
}
for (int i = 0; i < deviceIdAndGeneration.length; i += 2) {
final int deviceId = deviceIdAndGeneration[i];
int index = mInputDevices.indexOfKey(deviceId);
if (index >= 0) {
final InputDevice device = mInputDevices.valueAt(index);
if (device != null) {
final int generation = deviceIdAndGeneration[i + 1];
if (device.getGeneration() != generation) {
if (DEBUG) {
Log.d(TAG, "Device changed: " + deviceId);
}
mInputDevices.setValueAt(index, null);
sendMessageToInputDeviceListenersLocked(MSG_DEVICE_CHANGED, deviceId);
}
}
} else {
if (DEBUG) {
Log.d(TAG, "Device added: " + deviceId);
}
mInputDevices.put(deviceId, null);
sendMessageToInputDeviceListenersLocked(MSG_DEVICE_ADDED, deviceId);
}
}
}
}
use of android.view.InputDevice in project android_frameworks_base by ParanoidAndroid.
the class InputManager method getInputDevice.
/**
* Gets information about the input device with the specified id.
* @param id The device id.
* @return The input device or null if not found.
*/
public InputDevice getInputDevice(int id) {
synchronized (mInputDevicesLock) {
populateInputDevicesLocked();
int index = mInputDevices.indexOfKey(id);
if (index < 0) {
return null;
}
InputDevice inputDevice = mInputDevices.valueAt(index);
if (inputDevice == null) {
try {
inputDevice = mIm.getInputDevice(id);
} catch (RemoteException ex) {
throw new RuntimeException("Could not get input device information.", ex);
}
if (inputDevice != null) {
mInputDevices.setValueAt(index, inputDevice);
}
}
return inputDevice;
}
}
use of android.view.InputDevice in project android_frameworks_base by ParanoidAndroid.
the class VibratorService method updateInputDeviceVibrators.
private void updateInputDeviceVibrators() {
synchronized (mVibrations) {
doCancelVibrateLocked();
synchronized (mInputDeviceVibrators) {
mVibrateInputDevicesSetting = false;
try {
mVibrateInputDevicesSetting = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.VIBRATE_INPUT_DEVICES, UserHandle.USER_CURRENT) > 0;
} catch (SettingNotFoundException snfe) {
}
if (mVibrateInputDevicesSetting) {
if (!mInputDeviceListenerRegistered) {
mInputDeviceListenerRegistered = true;
mIm.registerInputDeviceListener(this, mH);
}
} else {
if (mInputDeviceListenerRegistered) {
mInputDeviceListenerRegistered = false;
mIm.unregisterInputDeviceListener(this);
}
}
mInputDeviceVibrators.clear();
if (mVibrateInputDevicesSetting) {
int[] ids = mIm.getInputDeviceIds();
for (int i = 0; i < ids.length; i++) {
InputDevice device = mIm.getInputDevice(ids[i]);
Vibrator vibrator = device.getVibrator();
if (vibrator.hasVibrator()) {
mInputDeviceVibrators.add(vibrator);
}
}
}
}
startNextVibrationLocked();
}
}
use of android.view.InputDevice in project android_frameworks_base by ParanoidAndroid.
the class InputManagerService method handleSwitchKeyboardLayout.
// Must be called on handler.
private void handleSwitchKeyboardLayout(int deviceId, int direction) {
final InputDevice device = getInputDevice(deviceId);
if (device != null) {
final String inputDeviceDescriptor = device.getDescriptor();
final boolean changed;
final String keyboardLayoutDescriptor;
synchronized (mDataStore) {
try {
changed = mDataStore.switchKeyboardLayout(inputDeviceDescriptor, direction);
keyboardLayoutDescriptor = mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor);
} finally {
mDataStore.saveIfNeeded();
}
}
if (changed) {
if (mSwitchedKeyboardLayoutToast != null) {
mSwitchedKeyboardLayoutToast.cancel();
mSwitchedKeyboardLayoutToast = null;
}
if (keyboardLayoutDescriptor != null) {
KeyboardLayout keyboardLayout = getKeyboardLayout(keyboardLayoutDescriptor);
if (keyboardLayout != null) {
mSwitchedKeyboardLayoutToast = Toast.makeText(mContext, keyboardLayout.getLabel(), Toast.LENGTH_SHORT);
mSwitchedKeyboardLayoutToast.show();
}
}
reloadKeyboardLayouts();
}
}
}
use of android.view.InputDevice in project android_frameworks_base by ParanoidAndroid.
the class InputManagerService method deliverInputDevicesChanged.
// Must be called on handler.
private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) {
// Scan for changes.
int numFullKeyboardsAdded = 0;
mTempInputDevicesChangedListenersToNotify.clear();
mTempFullKeyboards.clear();
final int numListeners;
final int[] deviceIdAndGeneration;
synchronized (mInputDevicesLock) {
if (!mInputDevicesChangedPending) {
return;
}
mInputDevicesChangedPending = false;
numListeners = mInputDevicesChangedListeners.size();
for (int i = 0; i < numListeners; i++) {
mTempInputDevicesChangedListenersToNotify.add(mInputDevicesChangedListeners.valueAt(i));
}
final int numDevices = mInputDevices.length;
deviceIdAndGeneration = new int[numDevices * 2];
for (int i = 0; i < numDevices; i++) {
final InputDevice inputDevice = mInputDevices[i];
deviceIdAndGeneration[i * 2] = inputDevice.getId();
deviceIdAndGeneration[i * 2 + 1] = inputDevice.getGeneration();
if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
if (!containsInputDeviceWithDescriptor(oldInputDevices, inputDevice.getDescriptor())) {
mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice);
} else {
mTempFullKeyboards.add(inputDevice);
}
}
}
}
// Notify listeners.
for (int i = 0; i < numListeners; i++) {
mTempInputDevicesChangedListenersToNotify.get(i).notifyInputDevicesChanged(deviceIdAndGeneration);
}
mTempInputDevicesChangedListenersToNotify.clear();
// Check for missing keyboard layouts.
if (mNotificationManager != null) {
final int numFullKeyboards = mTempFullKeyboards.size();
boolean missingLayoutForExternalKeyboard = false;
boolean missingLayoutForExternalKeyboardAdded = false;
synchronized (mDataStore) {
for (int i = 0; i < numFullKeyboards; i++) {
final InputDevice inputDevice = mTempFullKeyboards.get(i);
if (mDataStore.getCurrentKeyboardLayout(inputDevice.getDescriptor()) == null) {
missingLayoutForExternalKeyboard = true;
if (i < numFullKeyboardsAdded) {
missingLayoutForExternalKeyboardAdded = true;
}
}
}
}
if (missingLayoutForExternalKeyboard) {
if (missingLayoutForExternalKeyboardAdded) {
showMissingKeyboardLayoutNotification();
}
} else if (mKeyboardLayoutNotificationShown) {
hideMissingKeyboardLayoutNotification();
}
}
mTempFullKeyboards.clear();
}
Aggregations