Add a check for misspelled span change.

Previously, misspelled span is directly used in AddToDicitonary's
OnClickListener. It can crash because misspelled span can have been
updated since SuggestiosPopup is shown.
Also, AddToDictionary didn't work correctly in full screen extracted
mode. Use findEquivalentSuggestionSpan to resolve it.

Bug: 27557526
Change-Id: I51d713dbdd0c44ea2c553164b81b1123a2325aa1
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index c5fb1ce..749d621 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -3284,10 +3284,18 @@
                     com.android.internal.R.id.addToDictionaryButton);
             mAddToDictionaryButton.setOnClickListener(new View.OnClickListener() {
                 public void onClick(View v) {
+                    final SuggestionSpan misspelledSpan =
+                            findEquivalentSuggestionSpan(mMisspelledSpanInfo);
+                    if (misspelledSpan == null) {
+                        // Span has been removed.
+                        return;
+                    }
                     final Editable editable = (Editable) mTextView.getText();
-                    final int spanStart = editable.getSpanStart(
-                            mMisspelledSpanInfo.mSuggestionSpan);
-                    final int spanEnd = editable.getSpanEnd(mMisspelledSpanInfo.mSuggestionSpan);
+                    final int spanStart = editable.getSpanStart(misspelledSpan);
+                    final int spanEnd = editable.getSpanEnd(misspelledSpan);
+                    if (spanStart < 0 || spanEnd <= spanStart) {
+                        return;
+                    }
                     final String originalText = TextUtils.substring(editable, spanStart, spanEnd);
 
                     final Intent intent = new Intent(Settings.ACTION_USER_DICTIONARY_INSERT);