Protect against bogus input for ListViews

Guard against cases where ListView might receive touch events while
detached.

Update ListMenuPresenter to dispatch a data set change when the
backing menu is changed.

Bug 6543282

Change-Id: If2fb9b6aa3cf4a1b7070a7cd0de0edf0fc2f4cca
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 5f60735..c7d0569 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -3351,6 +3351,14 @@
             mPositionScroller.stop();
         }
 
+        if (!mIsAttached) {
+            // Something isn't right.
+            // Since we rely on being attached to get data set change notifications,
+            // don't risk doing anything where we might try to resync and find things
+            // in a bogus state.
+            return false;
+        }
+
         if (mFastScroller != null) {
             boolean intercepted = mFastScroller.onTouchEvent(ev);
             if (intercepted) {
@@ -3846,6 +3854,14 @@
             mPositionScroller.stop();
         }
 
+        if (!mIsAttached) {
+            // Something isn't right.
+            // Since we rely on being attached to get data set change notifications,
+            // don't risk doing anything where we might try to resync and find things
+            // in a bogus state.
+            return false;
+        }
+
         if (mFastScroller != null) {
             boolean intercepted = mFastScroller.onInterceptTouchEvent(ev);
             if (intercepted) {
diff --git a/core/java/com/android/internal/view/menu/ListMenuPresenter.java b/core/java/com/android/internal/view/menu/ListMenuPresenter.java
index b3e2d27..4882adc 100644
--- a/core/java/com/android/internal/view/menu/ListMenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/ListMenuPresenter.java
@@ -88,6 +88,9 @@
             }
         }
         mMenu = menu;
+        if (mAdapter != null) {
+            mAdapter.notifyDataSetChanged();
+        }
     }
 
     @Override