OSDN Git Service

DO NOT MERGE: Disable SpellChecker in secondary user's direct reply
authorTarandeep Singh <tarandeep@google.com>
Mon, 1 Jul 2019 21:27:25 +0000 (14:27 -0700)
committerManjae Park <manjaepark@google.com>
Mon, 16 Dec 2019 20:46:39 +0000 (12:46 -0800)
For secondary users, when AOSP keyboard is used to type in
direct-reply, unknown words can be added to dictionary.
It's *not* OK for SpellCheckerService of primary user to
check unknown words typed by a secondary user.
The dialog to add these words shows up in primary user instead.

TextView uses TextView#isSuggestionsEnabled() to determine if
SpellChecker is enabled. This can be disabled by setting the flag
TYPE_TEXT_FLAG_NO_SUGGESTIONS in inputType.

Note: This doesn't affect workprofile users on P or older versions since
they use same SpellCheckerService for all workprofiles.

Bug: 123232892
Test: Manually tested using the steps mentioned in the bug.
 1. Flash latest P build.
 2. Install AOSP keyboard (LatinIME) and set it as default.
 3. Install and open EditTextVariations
 4. Initiate direct reply in primary user and type non-english
    words like "ggggg hhhhh".
 5. Observe that they get red underline and tapping it brings "add
    to dictionary" popup.
 6. Create a new secondary user and switch to it.
 7. Once the setup completes, initiate a direct reply and type words
    similar to step 4.
 8. Verify that red underlines dont appear.
 9. switch back to primary user and verify direct reply still has red
    underlines.

Change-Id: I93918eb2c12e37908e03a7951a9e2c5375bc0ecc
(cherry picked from commit b52efcb9d58348d2bcb9c83d36b0f1ae1244482b)

packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java

index 37b0de4..ad78b3a 100644 (file)
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.policy;
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.app.ActivityManager;
 import android.app.Notification;
 import android.app.PendingIntent;
 import android.app.RemoteInput;
@@ -27,7 +28,9 @@ import android.content.pm.ShortcutManager;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
+import android.os.UserHandle;
 import android.text.Editable;
+import android.text.InputType;
 import android.text.TextWatcher;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -278,12 +281,22 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
         if (mWrapper != null) {
             mWrapper.setRemoteInputVisible(true);
         }
-        mController.addRemoteInput(mEntry, mToken);
+
+        // Disable suggestions on non-owner (secondary) user.
+        // SpellCheckerService of primary user runs on secondary as well which shows
+        // "Add to dictionary" dialog on the primary user. (See b/123232892)
+        // Note: this doesn't affect work-profile users on P or older versions.
+        if (UserHandle.myUserId() != ActivityManager.getCurrentUser()) {
+            mEditText.setInputType(
+                    mEditText.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
+        }
+
         mEditText.setInnerFocusable(true);
         mEditText.mShowImeOnInputConnection = true;
         mEditText.setText(mEntry.remoteInputText);
         mEditText.setSelection(mEditText.getText().length());
         mEditText.requestFocus();
+        mController.addRemoteInput(mEntry, mToken);
         updateSendButton();
     }