diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java index 0ff791494f9a..3ad37aaaf676 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java @@ -8,7 +8,6 @@ package org.mozilla.gecko; import java.util.ArrayList; import java.util.List; import java.util.Timer; -import java.util.TimerTask; import org.mozilla.gecko.annotation.WrapForJNI; import org.mozilla.gecko.util.GamepadUtils; @@ -16,7 +15,6 @@ import org.mozilla.gecko.util.ThreadUtils; import android.content.Context; import android.hardware.input.InputManager; -import android.os.Build; import android.util.SparseArray; import android.view.InputDevice; import android.view.KeyEvent; @@ -363,67 +361,44 @@ public class AndroidGamepadManager { } private static void addDeviceListener(final Context context) { - if (Build.VERSION.SDK_INT < 16) { - // Poll known gamepads to see if they've disappeared. - sPollTimer = new Timer(); - sPollTimer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - for (int i = 0; i < sGamepads.size(); ++i) { - final int deviceId = sGamepads.keyAt(i); - if (InputDevice.getDevice(deviceId) == null) { - removeGamepad(deviceId); - } - } - } - }, POLL_TIMER_PERIOD, POLL_TIMER_PERIOD); - } else { - sListener = new InputManager.InputDeviceListener() { - @Override - public void onInputDeviceAdded(final int deviceId) { - InputDevice device = InputDevice.getDevice(deviceId); - if (device == null) { - return; - } - if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) { - addGamepad(device); - } + sListener = new InputManager.InputDeviceListener() { + @Override + public void onInputDeviceAdded(final int deviceId) { + InputDevice device = InputDevice.getDevice(deviceId); + if (device == null) { + return; } + if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) { + addGamepad(device); + } + } - @Override - public void onInputDeviceRemoved(final int deviceId) { - if (sPendingGamepads.get(deviceId) != null) { - // Got removed before Gecko's ack reached us. - // gamepadAdded will deal with it. - sPendingGamepads.remove(deviceId); - return; - } - if (sGamepads.get(deviceId) != null) { - removeGamepad(deviceId); - } + @Override + public void onInputDeviceRemoved(final int deviceId) { + if (sPendingGamepads.get(deviceId) != null) { + // Got removed before Gecko's ack reached us. + // gamepadAdded will deal with it. + sPendingGamepads.remove(deviceId); + return; } + if (sGamepads.get(deviceId) != null) { + removeGamepad(deviceId); + } + } - @Override - public void onInputDeviceChanged(final int deviceId) { - } - }; - final InputManager im = (InputManager) - context.getSystemService(Context.INPUT_SERVICE); - im.registerInputDeviceListener(sListener, ThreadUtils.getUiHandler()); - } + @Override + public void onInputDeviceChanged(final int deviceId) { + } + }; + final InputManager im = (InputManager) + context.getSystemService(Context.INPUT_SERVICE); + im.registerInputDeviceListener(sListener, ThreadUtils.getUiHandler()); } private static void removeDeviceListener(final Context context) { - if (Build.VERSION.SDK_INT < 16) { - if (sPollTimer != null) { - sPollTimer.cancel(); - sPollTimer = null; - } - } else { - final InputManager im = (InputManager) - context.getSystemService(Context.INPUT_SERVICE); - im.unregisterInputDeviceListener(sListener); - sListener = null; - } + final InputManager im = (InputManager) + context.getSystemService(Context.INPUT_SERVICE); + im.unregisterInputDeviceListener(sListener); + sListener = null; } }