Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0115ac12 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Honor text-operation user in "Add to dictionary"

This is a follow up CL to my previous CL [1], which introduced a
concept of "text-operation user" into TextView then plumbed it to IME
APIs and spell checker APIs as a short term workaround for System UI's
hosting multiple users' text contents in user 0 process.

With this CL, "Add to dictionary" menu item for misspelled words also
takes this text-operation user into account.

 [1]: I6d11e4d6a84570bc2991a8552349e8b216b0d139
      401e3d4c

Fix: 123955642
Test: Manually done as follows.
   1. Build aosp_taimen-userdebug and flash it.
   2. adb shell pm create-user test_user
   3. adb shell am switch-user 10
   4. make -j EditTextVariations
   5. adb install -r \
        $ANDROID_TARGET_OUT_TESTCASES/EditTextVariations/EditTextVariations.apk
   6. adb shell am start \
        -n com.android.inputmethod.tools.edittextvariations/.EditTextVariations
   7. Tap the menu icon on the EditTextVariations then click "Direct Reply"
   8. Open notification shade.
   9. Tap reply icon on "Message from UserHandle{10}".
  10. Type "gggg".
  11. Make sure a red underline is shown.
  12. Tap "gggg".
  13. Make sure a dropdown UI is shown below "gggg".
  14. Tap "ADD TO DICTIONARY"
  15. Dismiss the notification shade.
  16. Make sure "Add to dictionary" dialog is shown.
Change-Id: Iaf11cd7e54636ab552e2469006e120e39dca99a8
parent 42257a8b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3660,7 +3660,7 @@ public class Editor {
                    intent.putExtra(USER_DICTIONARY_EXTRA_LOCALE,
                            mTextView.getTextServicesLocale().toString());
                    intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                    mTextView.getContext().startActivity(intent);
                    mTextView.startActivityAsTextOperationUserIfNecessary(intent);
                    // There is no way to know if the word was indeed added. Re-check.
                    // TODO The ExtractEditText should remove the span in the original text instead
                    editable.removeSpan(mMisspelledSpanInfo.mSuggestionSpan);
+16 −0
Original line number Diff line number Diff line
@@ -11234,6 +11234,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }
    /**
     * Starts {@link Activity} as a text-operation user if it is specified with
     * {@link #setTextOperationUser(UserHandle)}.
     *
     * <p>Otherwise, just starts {@link Activity} with {@link Context#startActivity(Intent)}.</p>
     *
     * @param intent The description of the activity to start.
     */
    void startActivityAsTextOperationUserIfNecessary(@NonNull Intent intent) {
        if (mTextOperationUser != null) {
            getContext().startActivityAsUser(intent, mTextOperationUser);
        } else {
            getContext().startActivity(intent);
        }
    }
    /**
     * This is a temporary method. Future versions may support multi-locale text.
     * Caveat: This method may not return the latest text services locale, but this should be