OSDN Git Service

Avoid redundant store into array list.
authorJeff Brown <jeffbrown@google.com>
Thu, 31 Jan 2013 00:23:40 +0000 (16:23 -0800)
committerJeff Brown <jeffbrown@google.com>
Thu, 31 Jan 2013 01:36:14 +0000 (17:36 -0800)
Prevent possible NPE in case of a race condition
while fetching input devices by descriptor.

Change-Id: I68d0738386c6723d943e595f829981b0890c2b3a

core/java/android/hardware/input/InputManager.java

index 262d87d..6b00c58 100644 (file)
@@ -212,8 +212,10 @@ public final class InputManager {
                 } catch (RemoteException ex) {
                     throw new RuntimeException("Could not get input device information.", ex);
                 }
+                if (inputDevice != null) {
+                    mInputDevices.setValueAt(index, inputDevice);
+                }
             }
-            mInputDevices.setValueAt(index, inputDevice);
             return inputDevice;
         }
     }
@@ -241,6 +243,8 @@ public final class InputManager {
                         inputDevice = mIm.getInputDevice(id);
                     } catch (RemoteException ex) {
                         // Ignore the problem for the purposes of this method.
+                    }
+                    if (inputDevice == null) {
                         continue;
                     }
                     mInputDevices.setValueAt(i, inputDevice);