From 88336c62468149df2491997a506ed7886d9222d2 Mon Sep 17 00:00:00 2001 From: Steve McKay Date: Wed, 4 Apr 2018 11:44:18 -0700 Subject: Silently ignore illegal call to start. BUG: 70518185 Test: Passing Change-Id: I079a482bb808a42e433bc4b7ddb3947334a543bd --- src/com/android/documentsui/selection/ContentLock.java | 11 +++++++++-- .../android/documentsui/selection/GestureSelectionHelper.java | 8 +++++++- .../documentsui/selection/GestureSelectionHelperTest.java | 7 +++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/com/android/documentsui/selection/ContentLock.java b/src/com/android/documentsui/selection/ContentLock.java index 2c87d3a6d..5cc313277 100644 --- a/src/com/android/documentsui/selection/ContentLock.java +++ b/src/com/android/documentsui/selection/ContentLock.java @@ -73,17 +73,24 @@ public final class ContentLock { } } + /** + * Returns true if locked. + */ + synchronized boolean isLocked() { + return mLocks > 0; + } + /** * Allows other selection code to perform a precondition check asserting the state is locked. */ final void checkLocked() { - checkState(mLocks > 0); + checkState(isLocked()); } /** * Allows other selection code to perform a precondition check asserting the state is unlocked. */ final void checkUnlocked() { - checkState(mLocks == 0); + checkState(!isLocked()); } } diff --git a/src/com/android/documentsui/selection/GestureSelectionHelper.java b/src/com/android/documentsui/selection/GestureSelectionHelper.java index f3456fd1a..3bbd09d8f 100644 --- a/src/com/android/documentsui/selection/GestureSelectionHelper.java +++ b/src/com/android/documentsui/selection/GestureSelectionHelper.java @@ -78,7 +78,13 @@ public final class GestureSelectionHelper extends ScrollHost implements OnItemTo */ public void start() { checkState(!mStarted); - checkState(mLastStartedItemPos > -1); + // See: b/70518185. It appears start() is being called via onLongPress + // even though we never received an intial handleInterceptedDownEvent + // where we would usually initialize mLastStartedItemPos. + if (mLastStartedItemPos < 0){ + Log.w(TAG, "Illegal state. Can't start without valid mLastStartedItemPos."); + return; + } // Partner code in MotionInputHandler ensures items // are selected and range established prior to diff --git a/tests/unit/com/android/documentsui/selection/GestureSelectionHelperTest.java b/tests/unit/com/android/documentsui/selection/GestureSelectionHelperTest.java index 71b1c1425..a7ac76544 100644 --- a/tests/unit/com/android/documentsui/selection/GestureSelectionHelperTest.java +++ b/tests/unit/com/android/documentsui/selection/GestureSelectionHelperTest.java @@ -80,11 +80,10 @@ public class GestureSelectionHelperTest { @Test public void testNoStartOnIllegalPosition() { + mView.mNextPosition = -1; mHelper.onInterceptTouchEvent(null, DOWN); - try { - mHelper.start(); - fail("Should have thrown."); - } catch (Exception expected) {} + mHelper.start(); + assertFalse(mLock.isLocked()); } @Test -- cgit v1.2.3-59-g8ed1b