diff options
| author | 2024-06-27 13:03:58 +0000 | |
|---|---|---|
| committer | 2024-06-27 13:03:58 +0000 | |
| commit | 973ae3b13c6c602b031e1ec15025c460b44fd8e7 (patch) | |
| tree | 479b008bfa22afb936f084a2d7fe87b274c8dc7e | |
| parent | 50a9cfa11b000c2e3c138b3ef693b6519fc35404 (diff) | |
| parent | 1973f979f6c41fa96582517e46a838a46595f653 (diff) | |
Merge "[Inline Reply] Fix RemoteInputView visibility listener leak" into main
3 files changed, 8 insertions, 15 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java index 96b1cf2db662..646d0b11221b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java @@ -1477,7 +1477,7 @@ public class NotificationContentView extends FrameLayout implements Notification } if (hasRemoteInput) { result.mView.setWrapper(wrapper); - result.mView.addOnVisibilityChangedListener(this::setRemoteInputVisible); + result.mView.setOnVisibilityChangedListener(this::setRemoteInputVisible); if (existingPendingIntent != null || result.mView.isActive()) { // The current action could be gone, or the pending intent no longer valid. 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 1fc7bf467757..31776cf5ad1b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java @@ -115,7 +115,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene private final SendButtonTextWatcher mTextWatcher; private final TextView.OnEditorActionListener mEditorActionHandler; private final ArrayList<Runnable> mOnSendListeners = new ArrayList<>(); - private final ArrayList<Consumer<Boolean>> mOnVisibilityChangedListeners = new ArrayList<>(); + private Consumer<Boolean> mOnVisibilityChangedListener = null; private final ArrayList<OnFocusChangeListener> mEditTextFocusChangeListeners = new ArrayList<>(); @@ -733,24 +733,17 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene * {@link #getVisibility()} would return {@link View#VISIBLE}, and {@code false} it would return * any other value. */ - public void addOnVisibilityChangedListener(Consumer<Boolean> listener) { - mOnVisibilityChangedListeners.add(listener); - } - - /** - * Unregister a listener previously registered via - * {@link #addOnVisibilityChangedListener(Consumer)}. - */ - public void removeOnVisibilityChangedListener(Consumer<Boolean> listener) { - mOnVisibilityChangedListeners.remove(listener); + public void setOnVisibilityChangedListener(Consumer<Boolean> listener) { + mOnVisibilityChangedListener = listener; } @Override protected void onVisibilityChanged(View changedView, int visibility) { super.onVisibilityChanged(changedView, visibility); if (changedView == this) { - for (Consumer<Boolean> listener : new ArrayList<>(mOnVisibilityChangedListeners)) { - listener.accept(visibility == VISIBLE); + final Consumer<Boolean> visibilityChangedListener = mOnVisibilityChangedListener; + if (visibilityChangedListener != null) { + visibilityChangedListener.accept(visibility == VISIBLE); } // Hide soft-keyboard when the input view became invisible // (i.e. The notification shade collapsed by pressing the home key) 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 70afbd82df11..ffe7750dadfa 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 @@ -247,7 +247,7 @@ public class RemoteInputViewTest extends SysuiTestCase { ExpandableNotificationRow row = helper.createRow(); RemoteInputView view = RemoteInputView.inflate(mContext, null, row.getEntry(), mController); - view.addOnVisibilityChangedListener(null); + view.setOnVisibilityChangedListener(null); view.setVisibility(View.INVISIBLE); view.setVisibility(View.VISIBLE); } |