Search in sources :

Example 36 with InputDevice

use of android.view.InputDevice in project android_frameworks_base by AOSPA.

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) {
            }
            mLowPowerMode = mPowerManagerInternal.getLowPowerModeEnabled();
            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();
    }
}
Also used : InputDevice(android.view.InputDevice) Vibrator(android.os.Vibrator) SettingNotFoundException(android.provider.Settings.SettingNotFoundException)

Example 37 with InputDevice

use of android.view.InputDevice in project android_frameworks_base by AOSPA.

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.
    List<InputDevice> keyboardsMissingLayout = new ArrayList<>();
    final int numFullKeyboards = mTempFullKeyboards.size();
    synchronized (mDataStore) {
        for (int i = 0; i < numFullKeyboards; i++) {
            final InputDevice inputDevice = mTempFullKeyboards.get(i);
            String layout = getCurrentKeyboardLayoutForInputDevice(inputDevice.getIdentifier());
            if (layout == null) {
                layout = getDefaultKeyboardLayout(inputDevice);
                if (layout != null) {
                    setCurrentKeyboardLayoutForInputDevice(inputDevice.getIdentifier(), layout);
                }
            }
            if (layout == null) {
                keyboardsMissingLayout.add(inputDevice);
            }
        }
    }
    if (mNotificationManager != null) {
        if (!keyboardsMissingLayout.isEmpty()) {
            if (keyboardsMissingLayout.size() > 1) {
                // We have more than one keyboard missing a layout, so drop the
                // user at the generic input methods page so they can pick which
                // one to set.
                showMissingKeyboardLayoutNotification(null);
            } else {
                showMissingKeyboardLayoutNotification(keyboardsMissingLayout.get(0));
            }
        } else if (mKeyboardLayoutNotificationShown) {
            hideMissingKeyboardLayoutNotification();
        }
    }
    mTempFullKeyboards.clear();
}
Also used : InputDevice(android.view.InputDevice) ArrayList(java.util.ArrayList)

Example 38 with InputDevice

use of android.view.InputDevice in project android_frameworks_base by AOSPA.

the class PointerLocationView method onPointerEvent.

@Override
public void onPointerEvent(MotionEvent event) {
    final int action = event.getAction();
    int NP = mPointers.size();
    if (action == MotionEvent.ACTION_DOWN || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
        final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> // will be 0 for down
        MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        if (action == MotionEvent.ACTION_DOWN) {
            for (int p = 0; p < NP; p++) {
                final PointerState ps = mPointers.get(p);
                ps.clearTrace();
                ps.mCurDown = false;
            }
            mCurDown = true;
            mCurNumPointers = 0;
            mMaxNumPointers = 0;
            mVelocity.clear();
            if (mAltVelocity != null) {
                mAltVelocity.clear();
            }
        }
        mCurNumPointers += 1;
        if (mMaxNumPointers < mCurNumPointers) {
            mMaxNumPointers = mCurNumPointers;
        }
        final int id = event.getPointerId(index);
        while (NP <= id) {
            PointerState ps = new PointerState();
            mPointers.add(ps);
            NP++;
        }
        if (mActivePointerId < 0 || !mPointers.get(mActivePointerId).mCurDown) {
            mActivePointerId = id;
        }
        final PointerState ps = mPointers.get(id);
        ps.mCurDown = true;
        InputDevice device = InputDevice.getDevice(event.getDeviceId());
        ps.mHasBoundingBox = device != null && device.getMotionRange(MotionEvent.AXIS_GENERIC_1) != null;
    }
    final int NI = event.getPointerCount();
    mVelocity.addMovement(event);
    mVelocity.computeCurrentVelocity(1);
    if (mAltVelocity != null) {
        mAltVelocity.addMovement(event);
        mAltVelocity.computeCurrentVelocity(1);
    }
    final int N = event.getHistorySize();
    for (int historyPos = 0; historyPos < N; historyPos++) {
        for (int i = 0; i < NI; i++) {
            final int id = event.getPointerId(i);
            final PointerState ps = mCurDown ? mPointers.get(id) : null;
            final PointerCoords coords = ps != null ? ps.mCoords : mTempCoords;
            event.getHistoricalPointerCoords(i, historyPos, coords);
            if (mPrintCoords) {
                logCoords("Pointer", action, i, coords, id, event);
            }
            if (ps != null) {
                ps.addTrace(coords.x, coords.y, false);
            }
        }
    }
    for (int i = 0; i < NI; i++) {
        final int id = event.getPointerId(i);
        final PointerState ps = mCurDown ? mPointers.get(id) : null;
        final PointerCoords coords = ps != null ? ps.mCoords : mTempCoords;
        event.getPointerCoords(i, coords);
        if (mPrintCoords) {
            logCoords("Pointer", action, i, coords, id, event);
        }
        if (ps != null) {
            ps.addTrace(coords.x, coords.y, true);
            ps.mXVelocity = mVelocity.getXVelocity(id);
            ps.mYVelocity = mVelocity.getYVelocity(id);
            mVelocity.getEstimator(id, ps.mEstimator);
            if (mAltVelocity != null) {
                ps.mAltXVelocity = mAltVelocity.getXVelocity(id);
                ps.mAltYVelocity = mAltVelocity.getYVelocity(id);
                mAltVelocity.getEstimator(id, ps.mAltEstimator);
            }
            ps.mToolType = event.getToolType(i);
            if (ps.mHasBoundingBox) {
                ps.mBoundingLeft = event.getAxisValue(MotionEvent.AXIS_GENERIC_1, i);
                ps.mBoundingTop = event.getAxisValue(MotionEvent.AXIS_GENERIC_2, i);
                ps.mBoundingRight = event.getAxisValue(MotionEvent.AXIS_GENERIC_3, i);
                ps.mBoundingBottom = event.getAxisValue(MotionEvent.AXIS_GENERIC_4, i);
            }
        }
    }
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) {
        final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> // will be 0 for UP
        MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        final int id = event.getPointerId(index);
        final PointerState ps = mPointers.get(id);
        ps.mCurDown = false;
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
            mCurDown = false;
            mCurNumPointers = 0;
        } else {
            mCurNumPointers -= 1;
            if (mActivePointerId == id) {
                mActivePointerId = event.getPointerId(index == 0 ? 1 : 0);
            }
            ps.addTrace(Float.NaN, Float.NaN, false);
        }
    }
    invalidate();
}
Also used : InputDevice(android.view.InputDevice) PointerCoords(android.view.MotionEvent.PointerCoords) Paint(android.graphics.Paint)

Example 39 with InputDevice

use of android.view.InputDevice in project android_frameworks_base by AOSPA.

the class InputManager method getInputDeviceByDescriptor.

/**
     * Gets information about the input device with the specified descriptor.
     * @param descriptor The input device descriptor.
     * @return The input device or null if not found.
     * @hide
     */
public InputDevice getInputDeviceByDescriptor(String descriptor) {
    if (descriptor == null) {
        throw new IllegalArgumentException("descriptor must not be null.");
    }
    synchronized (mInputDevicesLock) {
        populateInputDevicesLocked();
        int numDevices = mInputDevices.size();
        for (int i = 0; i < numDevices; i++) {
            InputDevice inputDevice = mInputDevices.valueAt(i);
            if (inputDevice == null) {
                int id = mInputDevices.keyAt(i);
                try {
                    inputDevice = mIm.getInputDevice(id);
                } catch (RemoteException ex) {
                    throw ex.rethrowFromSystemServer();
                }
                if (inputDevice == null) {
                    continue;
                }
                mInputDevices.setValueAt(i, inputDevice);
            }
            if (descriptor.equals(inputDevice.getDescriptor())) {
                return inputDevice;
            }
        }
        return null;
    }
}
Also used : InputDevice(android.view.InputDevice) RemoteException(android.os.RemoteException)

Example 40 with InputDevice

use of android.view.InputDevice in project android_frameworks_base by AOSPA.

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);
            }
        }
    }
}
Also used : InputDevice(android.view.InputDevice)

Aggregations

InputDevice (android.view.InputDevice)83 Paint (android.graphics.Paint)15 RemoteException (android.os.RemoteException)12 ArrayList (java.util.ArrayList)7 Vibrator (android.os.Vibrator)6 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)6 Point (android.graphics.Point)5 InputManager (android.hardware.input.InputManager)5 PointerCoords (android.view.MotionEvent.PointerCoords)5 DisplayInfo (android.view.DisplayInfo)4 KeyboardLayout (android.hardware.input.KeyboardLayout)2 DisplayMetrics (android.util.DisplayMetrics)2 Test (org.junit.Test)2 NonNull (android.annotation.NonNull)1 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 InputDeviceIdentifier (android.hardware.input.InputDeviceIdentifier)1