Skip to content

Commit

Permalink
Fix a crash in TextView#onSaveInstanceState
Browse files Browse the repository at this point in the history
On Android JB, TextView#onSaveInstanceState() calls new
SpannableString() which causes a crash.

The reason is that SpannableStringInternal#setSpan() eventually calls
ChangeWatcher#onSpanChanged() and this causes onSelectionChanged().
However, the selection values remain the same, so we can simply ignore
the call when the values did not change.

BUG=760013

(cherry picked from commit acfc998)

Change-Id: I907afd43dae36513b8015572a5568060d8b545b3
Reviewed-on: https://chromium-review.googlesource.com/644495
Commit-Queue: Changwan Ryu <[email protected]>
Reviewed-by: Ted Choc <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#499100}
Reviewed-on: https://chromium-review.googlesource.com/653211
Reviewed-by: Changwan Ryu <[email protected]>
Cr-Commit-Position: refs/branch-heads/3202@{crosswalk-project#53}
Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
  • Loading branch information
galmacky committed Sep 6, 2017
1 parent 755f160 commit 95cf740
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public void onSetText(CharSequence text) {
@Override
public void onSelectionChanged(int selStart, int selEnd) {
if (DEBUG) Log.i(TAG, "onSelectionChanged [%d,%d]", selStart, selEnd);
if (mCurrentState.getSelStart() == selStart && mCurrentState.getSelEnd() == selEnd) return;

mCurrentState.setSelection(selStart, selEnd);
if (mBatchEditNestCount > 0) return;
int len = mCurrentState.getUserText().length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import android.app.Activity;
import android.content.Context;
import android.text.SpannableString;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.KeyEvent;
Expand Down Expand Up @@ -1091,4 +1092,16 @@ private void internalTestIgnoreAndGet() {
}
mInOrder.verifyNoMoreInteractions();
}

// crbug.com/760013
@Test
@Features(@Features.Register(
value = ChromeFeatureList.SPANNABLE_INLINE_AUTOCOMPLETE, enabled = true))
public void testOnSaveInstanceStateDoesNotCrash() {
mInputConnection.setComposingText("h", 1);
mAutocomplete.setAutocompleteText("h", "ello world");
// On Android JB, TextView#onSaveInstanceState() calls new SpannableString(mText). This
// should not crash.
new SpannableString(mAutocomplete.getText());
}
}

0 comments on commit 95cf740

Please sign in to comment.