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

Commit 4a092d43 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Avoid Spell Checker initialization during anim

TextView initializes the spell checker when the view is attached to a
window, making a couple of IPCs.
These IPCs can contribute to jank, so we should avoid them if we can.

This CL delays the initialization until the edit text actually becomes
visible.

Test: perfetto trace
Test: atest RemoteInputViewTest
Fixes: 191953960
Change-Id: I27820986ec925f5edbf7e26f6b8f7311f6d2f467
parent e5f9c3da
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
    private final UiEventLogger mUiEventLogger;
    private NotificationEntry mEntry;
    private boolean mRemoved;
    private boolean mSending;
    private NotificationViewWrapper mWrapper;

    // TODO(b/193539698): remove this; views shouldn't have access to their controller, and places
@@ -251,6 +252,10 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        contentView.setBackground(mContentBackground);
        mEditText = findViewById(R.id.remote_input_text);
        mEditText.setInnerFocusable(false);
        // TextView initializes the spell checked when the view is attached to a window.
        // This causes a couple of IPCs that can jank, especially during animations.
        // By default the text view should be disabled, to avoid the unnecessary initialization.
        mEditText.setEnabled(false);
        mEditText.setWindowInsetsAnimationCallback(
                new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {
            @NonNull
@@ -336,6 +341,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
    /** Show the "sending in-progress" UI. */
    public void startSending() {
        mEditText.setEnabled(false);
        mSending = true;
        mSendButton.setVisibility(INVISIBLE);
        mProgressBar.setVisibility(VISIBLE);
        mEditText.mShowImeOnInputConnection = false;
@@ -444,6 +450,12 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene
        mController.removeSpinning(mEntry.getKey(), mToken);
    }

    @Override
    public void onVisibilityAggregated(boolean isVisible) {
        super.onVisibilityAggregated(isVisible);
        mEditText.setEnabled(isVisible && !mSending);
    }

    public void setHintText(CharSequence hintText) {
        mEditText.setHint(hintText);
    }
@@ -508,10 +520,11 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene

    private void reset() {
        mResetting = true;
        mSending = false;
        mEntry.remoteInputTextWhenReset = SpannedString.valueOf(mEditText.getText());

        mEditText.getText().clear();
        mEditText.setEnabled(true);
        mEditText.setEnabled(isAggregatedVisible());
        mSendButton.setVisibility(VISIBLE);
        mProgressBar.setVisibility(INVISIBLE);
        mController.removeSpinning(mEntry.getKey(), mToken);
+6 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ package com.android.systemui.statusbar.policy;

import static android.view.ContentInfo.SOURCE_CLIPBOARD;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

@@ -174,12 +176,15 @@ public class RemoteInputViewTest extends SysuiTestCase {
                toUser);
        RemoteInputView view = RemoteInputView.inflate(mContext, null, row.getEntry(), mController);
        RemoteInputViewController controller = bindController(view, row.getEntry());
        EditText editText = view.findViewById(R.id.remote_input_text);

        setTestPendingIntent(controller);
        assertThat(editText.isEnabled()).isFalse();
        view.onVisibilityAggregated(true);
        assertThat(editText.isEnabled()).isTrue();

        view.focus();

        EditText editText = view.findViewById(R.id.remote_input_text);
        EditorInfo editorInfo = new EditorInfo();
        editorInfo.packageName = DUMMY_MESSAGE_APP_PKG;
        editorInfo.fieldId = editText.getId();