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

Commit b0176c22 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz
Browse files

[Memory Improvement] Drop non existing items in mAdded lists

New items are added to mAddedItems whenever setData is called. This can happen regardless of whether messaging layouts are attached to the window or not.
With this solution, we want to align mAddedItems and mGroups by removing the items in mAddedItems that are no longer in mGroups. This will stop mAddedItems uncontrolled growth and potentially fix the memory leak issue.

Bug: 378101061
Bug: 391677602
Test: Presubmit
Flag: android.widget.flags.drop_non_existing_messages
Change-Id: Ic9c1cb2f9cb01608941a4b16ff01a79d816c334d
parent 76f8854f
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -67,3 +67,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "drop_non_existing_messages"
  namespace: "systemui"
  description: "Drops all group and message entries that no longer exist."
  bug: "378101061"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -1188,6 +1188,12 @@ public class ConversationLayout extends FrameLayout
            }
            newGroup.setMessages(group);
        }

        if (Flags.dropNonExistingMessages()) {
            // remove groups from mAddedGroups when they are no longer in mGroups.
            mAddedGroups.removeIf(
                    messagingGroup -> !mGroups.contains(messagingGroup));
        }
    }

    /**
+4 −0
Original line number Diff line number Diff line
@@ -569,6 +569,10 @@ public class MessagingGroup extends NotificationOptimizedLinearLayout implements
        mIsolatedMessage = isolatedMessage;
        updateImageContainerVisibility();
        mMessages = group;
        if (android.widget.flags.Flags.dropNonExistingMessages()) {
            // remove messages from mAddedMessages when they are no longer in mMessages.
            mAddedMessages.removeIf(message -> !mMessages.contains(message));
        }
        updateMessageColor();
    }

+7 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.view.animation.PathInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.flags.Flags;

import com.android.internal.R;

@@ -559,6 +560,12 @@ public class MessagingLayout extends FrameLayout
            }
            newGroup.setMessages(group);
        }

        if (Flags.dropNonExistingMessages()) {
            // remove groups from mAddedGroups when they are no longer in mGroups.
            mAddedGroups.removeIf(
                    messagingGroup -> !mGroups.contains(messagingGroup));
        }
    }

    private void findGroups(List<MessagingMessage> historicMessages,