diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index bfaa7b37fa33e..7a8469c8b979f 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -41,7 +41,6 @@ import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.database.ContentObserver; import android.graphics.PointF; -import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayViewport; import android.hardware.input.IInputDevicesChangedListener; @@ -198,8 +197,9 @@ public class InputManagerService extends IInputManager.Stub private final Object mTabletModeLock = new Object(); // List of currently registered tablet mode changed listeners by process id + @GuardedBy("mTabletModeLock") private final SparseArray mTabletModeChangedListeners = - new SparseArray<>(); // guarded by mTabletModeLock + new SparseArray<>(); private final List mTempTabletModeChangedListenersToNotify = new ArrayList<>(); @@ -217,40 +217,39 @@ public class InputManagerService extends IInputManager.Stub private final PersistentDataStore mDataStore = new PersistentDataStore(); // List of currently registered input devices changed listeners by process id. - private Object mInputDevicesLock = new Object(); + private final Object mInputDevicesLock = new Object(); @GuardedBy("mInputDevicesLock") - private boolean mInputDevicesChangedPending; // guarded by mInputDevicesLock + private boolean mInputDevicesChangedPending; @GuardedBy("mInputDevicesLock") private InputDevice[] mInputDevices = new InputDevice[0]; + @GuardedBy("mInputDevicesLock") private final SparseArray mInputDevicesChangedListeners = - new SparseArray(); // guarded by mInputDevicesLock + new SparseArray<>(); private final ArrayList - mTempInputDevicesChangedListenersToNotify = - new ArrayList(); // handler thread only - private final ArrayList - mTempFullKeyboards = new ArrayList(); // handler thread only + mTempInputDevicesChangedListenersToNotify = new ArrayList<>(); // handler thread only + private final ArrayList mTempFullKeyboards = + new ArrayList<>(); // handler thread only private boolean mKeyboardLayoutNotificationShown; private Toast mSwitchedKeyboardLayoutToast; // State for vibrator tokens. - private Object mVibratorLock = new Object(); - private Map mVibratorTokens = new ArrayMap(); + private final Object mVibratorLock = new Object(); + private final Map mVibratorTokens = new ArrayMap<>(); private int mNextVibratorTokenValue; // List of currently registered vibrator state changed listeners by device id. @GuardedBy("mVibratorLock") private final SparseArray> mVibratorStateListeners = - new SparseArray>(); + new SparseArray<>(); // List of vibrator states by device id. @GuardedBy("mVibratorLock") private final SparseBooleanArray mIsVibrating = new SparseBooleanArray(); - private Object mLightLock = new Object(); + private final Object mLightLock = new Object(); // State for light tokens. A light token marks a lights manager session, it is generated // by light session open() and deleted in session close(). // When lights session requests light states, the token will be used to find the light session. @GuardedBy("mLightLock") - private final ArrayMap mLightSessions = - new ArrayMap(); + private final ArrayMap mLightSessions = new ArrayMap<>(); // State for lid switch // Lock for the lid switch state. Held when triggering callbacks to guarantee lid switch events @@ -259,19 +258,21 @@ public class InputManagerService extends IInputManager.Stub // events that occur at the same time are delivered after the callback has returned. private final Object mLidSwitchLock = new Object(); @GuardedBy("mLidSwitchLock") - private List mLidSwitchCallbacks = new ArrayList<>(); + private final List mLidSwitchCallbacks = new ArrayList<>(); // State for the currently installed input filter. final Object mInputFilterLock = new Object(); - IInputFilter mInputFilter; // guarded by mInputFilterLock - InputFilterHost mInputFilterHost; // guarded by mInputFilterLock + @GuardedBy("mInputFilterLock") + IInputFilter mInputFilter; + @GuardedBy("mInputFilterLock") + InputFilterHost mInputFilterHost; // The associations of input devices to displays by port. Maps from input device port (String) // to display id (int). Currently only accessed by InputReader. private final Map mStaticAssociations; private final Object mAssociationsLock = new Object(); @GuardedBy("mAssociationLock") - private final Map mRuntimeAssociations = new ArrayMap(); + private final Map mRuntimeAssociations = new ArrayMap<>(); @GuardedBy("mAssociationLock") private final Map mUniqueIdAssociations = new ArrayMap<>(); private final Object mPointerDisplayIdLock = new Object(); @@ -582,32 +583,6 @@ public class InputManagerService extends IInputManager.Stub nativeReloadDeviceAliases(mPtr); } - /** Rotates CCW by `delta` 90-degree increments. */ - private static void rotateBounds(Rect inOutBounds, int parentW, int parentH, int delta) { - int rdelta = ((delta % 4) + 4) % 4; - int origLeft = inOutBounds.left; - switch (rdelta) { - case 0: - return; - case 1: - inOutBounds.left = inOutBounds.top; - inOutBounds.top = parentW - inOutBounds.right; - inOutBounds.right = inOutBounds.bottom; - inOutBounds.bottom = parentW - origLeft; - return; - case 2: - inOutBounds.left = parentW - inOutBounds.right; - inOutBounds.right = parentW - origLeft; - return; - case 3: - inOutBounds.left = parentH - inOutBounds.bottom; - inOutBounds.bottom = inOutBounds.right; - inOutBounds.right = parentH - inOutBounds.top; - inOutBounds.top = origLeft; - return; - } - } - private void setDisplayViewportsInternal(List viewports) { final DisplayViewport[] vArray = new DisplayViewport[viewports.size()]; for (int i = viewports.size() - 1; i >= 0; --i) { @@ -934,9 +909,7 @@ public class InputManagerService extends IInputManager.Stub @Override // Binder call public InputDevice getInputDevice(int deviceId) { synchronized (mInputDevicesLock) { - final int count = mInputDevices.length; - for (int i = 0; i < count; i++) { - final InputDevice inputDevice = mInputDevices[i]; + for (final InputDevice inputDevice : mInputDevices) { if (inputDevice.getId() == deviceId) { return inputDevice; } @@ -1119,23 +1092,19 @@ public class InputManagerService extends IInputManager.Stub return null; } final List layouts = new ArrayList<>(); - visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { - @Override - public void visitKeyboardLayout(Resources resources, - int keyboardLayoutResId, KeyboardLayout layout) { - // Only select a default when we know the layout is appropriate. For now, this - // means its a custom layout for a specific keyboard. - if (layout.getVendorId() != d.getVendorId() - || layout.getProductId() != d.getProductId()) { - return; - } - final LocaleList locales = layout.getLocales(); - final int numLocales = locales.size(); - for (int localeIndex = 0; localeIndex < numLocales; ++localeIndex) { - if (isCompatibleLocale(systemLocale, locales.get(localeIndex))) { - layouts.add(layout); - break; - } + visitAllKeyboardLayouts((resources, keyboardLayoutResId, layout) -> { + // Only select a default when we know the layout is appropriate. For now, this + // means it's a custom layout for a specific keyboard. + if (layout.getVendorId() != d.getVendorId() + || layout.getProductId() != d.getProductId()) { + return; + } + final LocaleList locales = layout.getLocales(); + final int numLocales = locales.size(); + for (int localeIndex = 0; localeIndex < numLocales; ++localeIndex) { + if (isCompatibleLocale(systemLocale, locales.get(localeIndex))) { + layouts.add(layout); + break; } } }); @@ -1335,13 +1304,8 @@ public class InputManagerService extends IInputManager.Stub private void updateKeyboardLayouts() { // Scan all input devices state for keyboard layouts that have been uninstalled. final HashSet availableKeyboardLayouts = new HashSet(); - visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { - @Override - public void visitKeyboardLayout(Resources resources, - int keyboardLayoutResId, KeyboardLayout layout) { - availableKeyboardLayouts.add(layout.getDescriptor()); - } - }); + visitAllKeyboardLayouts((resources, keyboardLayoutResId, layout) -> + availableKeyboardLayouts.add(layout.getDescriptor())); synchronized (mDataStore) { try { mDataStore.removeUninstalledKeyboardLayouts(availableKeyboardLayouts); @@ -1368,14 +1332,8 @@ public class InputManagerService extends IInputManager.Stub @Override // Binder call public KeyboardLayout[] getKeyboardLayouts() { - final ArrayList list = new ArrayList(); - visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { - @Override - public void visitKeyboardLayout(Resources resources, - int keyboardLayoutResId, KeyboardLayout layout) { - list.add(layout); - } - }); + final ArrayList list = new ArrayList<>(); + visitAllKeyboardLayouts((resources, keyboardLayoutResId, layout) -> list.add(layout)); return list.toArray(new KeyboardLayout[list.size()]); } @@ -1383,10 +1341,10 @@ public class InputManagerService extends IInputManager.Stub public KeyboardLayout[] getKeyboardLayoutsForInputDevice( final InputDeviceIdentifier identifier) { final String[] enabledLayoutDescriptors = - getEnabledKeyboardLayoutsForInputDevice(identifier); + getEnabledKeyboardLayoutsForInputDevice(identifier); final ArrayList enabledLayouts = - new ArrayList(enabledLayoutDescriptors.length); - final ArrayList potentialLayouts = new ArrayList(); + new ArrayList<>(enabledLayoutDescriptors.length); + final ArrayList potentialLayouts = new ArrayList<>(); visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { boolean mHasSeenDeviceSpecificLayout; @@ -1434,13 +1392,8 @@ public class InputManagerService extends IInputManager.Stub "keyboardLayoutDescriptor must not be null"); final KeyboardLayout[] result = new KeyboardLayout[1]; - visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() { - @Override - public void visitKeyboardLayout(Resources resources, - int keyboardLayoutResId, KeyboardLayout layout) { - result[0] = layout; - } - }); + visitKeyboardLayout(keyboardLayoutDescriptor, + (resources, keyboardLayoutResId, layout) -> result[0] = layout); if (result[0] == null) { Slog.w(TAG, "Could not get keyboard layout with descriptor '" + keyboardLayoutDescriptor + "'."); @@ -1472,7 +1425,7 @@ public class InputManagerService extends IInputManager.Stub | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, 0, visitor); - } catch (NameNotFoundException ex) { + } catch (NameNotFoundException ignored) { } } } @@ -1502,11 +1455,10 @@ public class InputManagerService extends IInputManager.Stub try { Resources resources = pm.getResourcesForApplication(receiver.applicationInfo); - XmlResourceParser parser = resources.getXml(configResId); - try { + try (XmlResourceParser parser = resources.getXml(configResId)) { XmlUtils.beginDocument(parser, "keyboard-layouts"); - for (;;) { + while (true) { XmlUtils.nextElement(parser); String element = parser.getName(); if (element == null) { @@ -1514,22 +1466,22 @@ public class InputManagerService extends IInputManager.Stub } if (element.equals("keyboard-layout")) { TypedArray a = resources.obtainAttributes( - parser, com.android.internal.R.styleable.KeyboardLayout); + parser, R.styleable.KeyboardLayout); try { String name = a.getString( - com.android.internal.R.styleable.KeyboardLayout_name); + R.styleable.KeyboardLayout_name); String label = a.getString( - com.android.internal.R.styleable.KeyboardLayout_label); + R.styleable.KeyboardLayout_label); int keyboardLayoutResId = a.getResourceId( - com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, + R.styleable.KeyboardLayout_keyboardLayout, 0); String languageTags = a.getString( - com.android.internal.R.styleable.KeyboardLayout_locale); + R.styleable.KeyboardLayout_locale); LocaleList locales = getLocalesFromLanguageTags(languageTags); int vid = a.getInt( - com.android.internal.R.styleable.KeyboardLayout_vendorId, -1); + R.styleable.KeyboardLayout_vendorId, -1); int pid = a.getInt( - com.android.internal.R.styleable.KeyboardLayout_productId, -1); + R.styleable.KeyboardLayout_productId, -1); if (name == null || label == null || keyboardLayoutResId == 0) { Slog.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " @@ -1556,8 +1508,6 @@ public class InputManagerService extends IInputManager.Stub + receiver.packageName + "/" + receiver.name); } } - } finally { - parser.close(); } } catch (Exception ex) { Slog.w(TAG, "Could not parse keyboard layout resource from receiver " @@ -1584,10 +1534,7 @@ public class InputManagerService extends IInputManager.Stub if (identifier.getVendorId() == 0 && identifier.getProductId() == 0) { return identifier.getDescriptor(); } - StringBuilder bob = new StringBuilder(); - bob.append("vendor:").append(identifier.getVendorId()); - bob.append(",product:").append(identifier.getProductId()); - return bob.toString(); + return "vendor:" + identifier.getVendorId() + ",product:" + identifier.getProductId(); } @Override // Binder call @@ -1595,7 +1542,7 @@ public class InputManagerService extends IInputManager.Stub String key = getLayoutDescriptor(identifier); synchronized (mDataStore) { - String layout = null; + String layout; // try loading it using the layout descriptor if we have it layout = mDataStore.getCurrentKeyboardLayout(key); if (layout == null && !key.equals(identifier.getDescriptor())) { @@ -1870,7 +1817,7 @@ public class InputManagerService extends IInputManager.Stub try { speed = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.POINTER_SPEED, UserHandle.USER_CURRENT); - } catch (SettingNotFoundException snfe) { + } catch (SettingNotFoundException ignored) { } return speed; } @@ -2134,7 +2081,7 @@ public class InputManagerService extends IInputManager.Stub SparseArray effects = stereo.getEffects(); long[] pattern = new long[0]; int repeat = Integer.MIN_VALUE; - SparseArray amplitudes = new SparseArray(effects.size()); + SparseArray amplitudes = new SparseArray<>(effects.size()); for (int i = 0; i < effects.size(); i++) { VibrationInfo info = new VibrationInfo(effects.valueAt(i)); // Pattern of all effects should be same @@ -2184,6 +2131,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private void notifyVibratorState(int deviceId, boolean isOn) { if (DEBUG) { Slog.d(TAG, "notifyVibratorState: deviceId=" + deviceId + " isOn=" + isOn); @@ -2225,7 +2173,7 @@ public class InputManagerService extends IInputManager.Stub @Override // Binder call public boolean registerVibratorStateListener(int deviceId, IVibratorStateListener listener) { - Preconditions.checkNotNull(listener, "listener must not be null"); + Objects.requireNonNull(listener, "listener must not be null"); RemoteCallbackList listeners; synchronized (mVibratorLock) { @@ -2383,7 +2331,7 @@ public class InputManagerService extends IInputManager.Stub } Objects.requireNonNull(listener, "listener must not be null"); - synchronized (mInputDevicesLock) { + synchronized (mSensorEventLock) { int callingPid = Binder.getCallingPid(); if (mSensorEventListeners.get(callingPid) != null) { Slog.e(TAG, "The calling process " + callingPid + " has already " @@ -2415,7 +2363,7 @@ public class InputManagerService extends IInputManager.Stub Objects.requireNonNull(listener, "listener must not be null"); - synchronized (mInputDevicesLock) { + synchronized (mSensorEventLock) { int callingPid = Binder.getCallingPid(); if (mSensorEventListeners.get(callingPid) != null) { SensorEventListenerRecord record = mSensorEventListeners.get(callingPid); @@ -2429,7 +2377,7 @@ public class InputManagerService extends IInputManager.Stub @Override // Binder call public boolean flushSensor(int deviceId, int sensorType) { - synchronized (mInputDevicesLock) { + synchronized (mSensorEventLock) { int callingPid = Binder.getCallingPid(); SensorEventListenerRecord listener = mSensorEventListeners.get(callingPid); if (listener != null) { @@ -2497,7 +2445,7 @@ public class InputManagerService extends IInputManager.Stub * Set specified light state with for a specific input device. */ private void setLightStateInternal(int deviceId, Light light, LightState lightState) { - Preconditions.checkNotNull(light, "light does not exist"); + Objects.requireNonNull(light, "light does not exist"); if (DEBUG) { Slog.d(TAG, "setLightStateInternal device " + deviceId + " light " + light + "lightState " + lightState); @@ -2560,7 +2508,7 @@ public class InputManagerService extends IInputManager.Stub @Override public void openLightSession(int deviceId, String opPkg, IBinder token) { - Preconditions.checkNotNull(token); + Objects.requireNonNull(token); synchronized (mLightLock) { Preconditions.checkState(mLightSessions.get(token) == null, "already registered"); LightSession lightSession = new LightSession(deviceId, opPkg, token); @@ -2579,7 +2527,7 @@ public class InputManagerService extends IInputManager.Stub @Override public void closeLightSession(int deviceId, IBinder token) { - Preconditions.checkNotNull(token); + Objects.requireNonNull(token); synchronized (mLightLock) { LightSession lightSession = mLightSessions.get(token); Preconditions.checkState(lightSession != null, "not registered"); @@ -2689,11 +2637,13 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private void notifyConfigurationChanged(long whenNanos) { mWindowManagerCallbacks.notifyConfigurationChanged(); } // Native callback. + @SuppressWarnings("unused") private void notifyInputDevicesChanged(InputDevice[] inputDevices) { synchronized (mInputDevicesLock) { if (!mInputDevicesChangedPending) { @@ -2707,6 +2657,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private void notifySwitch(long whenNanos, int switchValues, int switchMask) { if (DEBUG) { Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues) @@ -2739,7 +2690,7 @@ public class InputManagerService extends IInputManager.Stub SomeArgs args = SomeArgs.obtain(); args.argi1 = (int) (whenNanos & 0xFFFFFFFF); args.argi2 = (int) (whenNanos >> 32); - args.arg1 = Boolean.valueOf((switchValues & SW_TABLET_MODE_BIT) != 0); + args.arg1 = (switchValues & SW_TABLET_MODE_BIT) != 0; mHandler.obtainMessage(MSG_DELIVER_TABLET_MODE_CHANGED, args).sendToTarget(); } @@ -2752,6 +2703,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private void notifyInputChannelBroken(IBinder token) { synchronized (mInputMonitors) { if (mInputMonitors.containsKey(token)) { @@ -2762,16 +2714,19 @@ public class InputManagerService extends IInputManager.Stub } // Native callback + @SuppressWarnings("unused") private void notifyFocusChanged(IBinder oldToken, IBinder newToken) { mWindowManagerCallbacks.notifyFocusChanged(oldToken, newToken); } // Native callback + @SuppressWarnings("unused") private void notifyDropWindow(IBinder token, float x, float y) { mWindowManagerCallbacks.notifyDropWindow(token, x, y); } // Native callback + @SuppressWarnings("unused") private void notifyUntrustedTouch(String packageName) { // TODO(b/169067926): Remove toast after gathering feedback on dogfood. if (!UNTRUSTED_TOUCHES_TOAST || ArrayUtils.contains( @@ -2787,11 +2742,13 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private void notifyNoFocusedWindowAnr(InputApplicationHandle inputApplicationHandle) { mWindowManagerCallbacks.notifyNoFocusedWindowAnr(inputApplicationHandle); } // Native callback + @SuppressWarnings("unused") private void notifyWindowUnresponsive(IBinder token, String reason) { int gestureMonitorPid = -1; synchronized (mInputMonitors) { @@ -2808,11 +2765,13 @@ public class InputManagerService extends IInputManager.Stub } // Native callback + @SuppressWarnings("unused") private void notifyMonitorUnresponsive(int pid, String reason) { mWindowManagerCallbacks.notifyGestureMonitorUnresponsive(pid, reason); } // Native callback + @SuppressWarnings("unused") private void notifyWindowResponsive(IBinder token) { int gestureMonitorPid = -1; synchronized (mInputMonitors) { @@ -2829,11 +2788,13 @@ public class InputManagerService extends IInputManager.Stub } // Native callback + @SuppressWarnings("unused") private void notifyMonitorResponsive(int pid) { mWindowManagerCallbacks.notifyGestureMonitorResponsive(pid); } // Native callback. + @SuppressWarnings("unused") private void notifySensorEvent(int deviceId, int sensorType, int accuracy, long timestamp, float[] values) { if (DEBUG) { @@ -2857,6 +2818,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private void notifySensorAccuracy(int deviceId, int sensorType, int accuracy) { mSensorAccuracyListenersToNotify.clear(); final int numListeners; @@ -2874,6 +2836,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") final boolean filterInputEvent(InputEvent event, int policyFlags) { synchronized (mInputFilterLock) { if (mInputFilter != null) { @@ -2890,11 +2853,13 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { return mWindowManagerCallbacks.interceptKeyBeforeQueueing(event, policyFlags); } // Native callback. + @SuppressWarnings("unused") private int interceptMotionBeforeQueueingNonInteractive(int displayId, long whenNanos, int policyFlags) { return mWindowManagerCallbacks.interceptMotionBeforeQueueingNonInteractive( @@ -2902,33 +2867,39 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private long interceptKeyBeforeDispatching(IBinder focus, KeyEvent event, int policyFlags) { return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags); } // Native callback. + @SuppressWarnings("unused") private KeyEvent dispatchUnhandledKey(IBinder focus, KeyEvent event, int policyFlags) { return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags); } // Native callback. + @SuppressWarnings("unused") private boolean checkInjectEventsPermission(int injectorPid, int injectorUid) { return mContext.checkPermission(android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid) == PackageManager.PERMISSION_GRANTED; } // Native callback. + @SuppressWarnings("unused") private void onPointerDownOutsideFocus(IBinder touchedToken) { mWindowManagerCallbacks.onPointerDownOutsideFocus(touchedToken); } // Native callback. + @SuppressWarnings("unused") private int getVirtualKeyQuietTimeMillis() { return mContext.getResources().getInteger( com.android.internal.R.integer.config_virtualKeyQuietTimeMillis); } // Native callback. + @SuppressWarnings("unused") private static String[] getExcludedDeviceNames() { List names = new ArrayList<>(); // Read partner-provided list of excluded input devices @@ -2984,6 +2955,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback + @SuppressWarnings("unused") private String[] getInputPortAssociations() { final Map associations = new HashMap<>(mStaticAssociations); @@ -2996,6 +2968,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback + @SuppressWarnings("unused") private String[] getInputUniqueIdAssociations() { final Map associations; synchronized (mAssociationsLock) { @@ -3016,46 +2989,55 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private int getKeyRepeatTimeout() { return ViewConfiguration.getKeyRepeatTimeout(); } // Native callback. + @SuppressWarnings("unused") private int getKeyRepeatDelay() { return ViewConfiguration.getKeyRepeatDelay(); } // Native callback. + @SuppressWarnings("unused") private int getHoverTapTimeout() { return ViewConfiguration.getHoverTapTimeout(); } // Native callback. + @SuppressWarnings("unused") private int getHoverTapSlop() { return ViewConfiguration.getHoverTapSlop(); } // Native callback. + @SuppressWarnings("unused") private int getDoubleTapTimeout() { return ViewConfiguration.getDoubleTapTimeout(); } // Native callback. + @SuppressWarnings("unused") private int getLongPressTimeout() { return ViewConfiguration.getLongPressTimeout(); } // Native callback. + @SuppressWarnings("unused") private int getPointerLayer() { return mWindowManagerCallbacks.getPointerLayer(); } // Native callback. + @SuppressWarnings("unused") private PointerIcon getPointerIcon(int displayId) { return PointerIcon.getDefaultIcon(getContextForPointerIcon(displayId)); } // Native callback. + @SuppressWarnings("unused") private long getParentSurfaceForPointers(int displayId) { final SurfaceControl sc = mWindowManagerCallbacks.getParentSurfaceForPointers(displayId); if (sc == null) { @@ -3101,6 +3083,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private int getPointerDisplayId() { synchronized (mPointerDisplayIdLock) { // Prefer the override to all other displays. @@ -3112,6 +3095,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) { if (!mSystemReady) { return null; @@ -3123,19 +3107,15 @@ public class InputManagerService extends IInputManager.Stub } final String[] result = new String[2]; - visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() { - @Override - public void visitKeyboardLayout(Resources resources, - int keyboardLayoutResId, KeyboardLayout layout) { - try (final InputStreamReader stream = new InputStreamReader( - resources.openRawResource(keyboardLayoutResId))) { - result[0] = layout.getDescriptor(); - result[1] = Streams.readFully(stream); - } catch (IOException ex) { - } catch (NotFoundException ex) { - } - } - }); + visitKeyboardLayout(keyboardLayoutDescriptor, + (resources, keyboardLayoutResId, layout) -> { + try (InputStreamReader stream = new InputStreamReader( + resources.openRawResource(keyboardLayoutResId))) { + result[0] = layout.getDescriptor(); + result[1] = Streams.readFully(stream); + } catch (IOException | NotFoundException ignored) { + } + }); if (result[0] == null) { Slog.w(TAG, "Could not get keyboard layout with descriptor '" + keyboardLayoutDescriptor + "'."); @@ -3145,6 +3125,7 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. + @SuppressWarnings("unused") private String getDeviceAlias(String uniqueId) { if (BluetoothAdapter.checkBluetoothAddress(uniqueId)) { // TODO(BT) mBluetoothService.getRemoteAlias(uniqueId) @@ -3294,8 +3275,18 @@ public class InputManagerService extends IInputManager.Stub * Callback interface implemented by WiredAccessoryObserver. */ public interface WiredAccessoryCallbacks { - public void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask); - public void systemReady(); + /** + * Notifies WiredAccessoryObserver that input state for wired accessories has changed + * @param whenNanos When the wired accessories changed + * @param switchValues The state of the switches + * @param switchMask The mask of switches that changed + */ + void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask); + + /** + * Notifies WiredAccessoryObserver that the system is now ready. + */ + void systemReady(); } /** @@ -3326,7 +3317,7 @@ public class InputManagerService extends IInputManager.Stub break; case MSG_DELIVER_TABLET_MODE_CHANGED: SomeArgs args = (SomeArgs) msg.obj; - long whenNanos = (args.argi1 & 0xFFFFFFFFl) | ((long) args.argi2 << 32); + long whenNanos = (args.argi1 & 0xFFFFFFFFL) | ((long) args.argi2 << 32); boolean inTabletMode = (boolean) args.arg1; deliverTabletModeChanged(whenNanos, inTabletMode); break; @@ -3338,8 +3329,10 @@ public class InputManagerService extends IInputManager.Stub * Hosting interface for input filters to call back into the input manager. */ private final class InputFilterHost extends IInputFilterHost.Stub { + @GuardedBy("mInputFilterLock") private boolean mDisconnected; + @GuardedBy("mInputFilterLock") public void disconnectLocked() { mDisconnected = true; }