diff options
author | 2018-04-23 15:10:53 +0000 | |
---|---|---|
committer | 2018-04-23 15:10:53 +0000 | |
commit | f16521df400a914eaf245c4f8119b39dd10d5e7c (patch) | |
tree | 35a69dc2a1c30639a510c8abce88491e62d35bdd | |
parent | f2788e31dd554535c594a413e365b9dd68bda6eb (diff) | |
parent | 88336c62468149df2491997a506ed7886d9222d2 (diff) |
Merge "Silently ignore illegal call to start." into pi-dev
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 @@ -74,16 +74,23 @@ 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 |