OSDN Git Service

Check for DeviceAdminInfo type before casting
authorZoltan Szatmary-Ban <szatmz@google.com>
Thu, 28 Aug 2014 12:13:34 +0000 (13:13 +0100)
committerZoltan Szatmary-Ban <szatmz@google.com>
Thu, 28 Aug 2014 12:13:34 +0000 (13:13 +0100)
Race conditions seem to cause disabled list adapter items to trigger an
onListItemClick event. Type of item object needs to be checked therefore.

Bug:17187120
Change-Id: I469004081c89c9ba24dfa95872b54648a26213f9

src/com/android/settings/DeviceAdminSettings.java

index 1ea9859..2eb6f99 100644 (file)
@@ -127,7 +127,12 @@ public class DeviceAdminSettings extends ListFragment {
 
     @Override
     public void onListItemClick(ListView l, View v, int position, long id) {
-        DeviceAdminInfo dpi = (DeviceAdminInfo) l.getAdapter().getItem(position);
+        Object o = l.getAdapter().getItem(position);
+        if (!(o instanceof DeviceAdminInfo)) {
+            // race conditions may cause this
+            return;
+        }
+        DeviceAdminInfo dpi = (DeviceAdminInfo) o;
         final Activity activity = getActivity();
         final int userId = getUserId(dpi);
         if (userId == UserHandle.myUserId() || !isProfileOwner(dpi)) {