From 4a092d43c40d956bfaad7c230a7b9722268027f3 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Mon, 2 May 2022 15:16:52 -0700 Subject: [PATCH] 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 --- .../statusbar/policy/RemoteInputView.java | 15 ++++++++++++++- .../statusbar/policy/RemoteInputViewTest.java | 7 ++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java index 006edcaf41de4..37517219f1034 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java @@ -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); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java index 3a0a7c9d80fc5..c47ea9cea75ef 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java @@ -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();