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

Commit 8e74bb8d authored by Robin Lee's avatar Robin Lee
Browse files

Let deepCopyRectsObjectRecycling handle nulls

The input array is @NonNull. Sadly the elements of the array are not
@NonNull, which is the important part of being @NonNull. Since passing
nulls was OK in the past, we'll continue to support it.

Fix: 410803519
Bug: 410399557
Flag: com.android.window.flags.reduce_changed_exclusion_rects_msgs
Test: atest SystemGestureExclusionRectsTest
Change-Id: I0b37694332096bad50316e874927cb230e34821a
parent 6a740a37
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -12974,19 +12974,28 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
    }
    private void deepCopyRectsObjectRecycling(@NonNull ArrayList<Rect> dest, List<Rect> src) {
        dest.ensureCapacity(src.size());
        for (int i = 0; i < src.size(); i++) {
            if (i < dest.size()) {
                // Replace if there is an old rect to refresh
                dest.get(i).set(src.get(i));
    private void deepCopyRectsObjectRecycling(
            @NonNull ArrayList<Rect> dest, @NonNull List<Rect> src) {
        final int srcN = src.size();
        final int destN = dest.size();
        dest.ensureCapacity(srcN);
        // Copy over the existing elements in-place.
        for (int i = 0; i < srcN && i < destN; i++) {
            final Rect destVal = dest.get(i);
            final Rect srcVal = src.get(i);
            if (srcVal == null || destVal == null) {
                dest.set(i, Rect.copyOrNull(srcVal));
            } else {
                // Add a rect if the list enlarged
                dest.add(Rect.copyOrNull(src.get(i)));
                destVal.set(srcVal);
            }
        }
        // Add new elements if the list needs to grow.
        for (int i = destN; i < srcN; i++) {
            dest.add(Rect.copyOrNull(src.get(i)));
        }
        while (dest.size() > src.size()) {
            // Remove elements if the list shrank
        // Remove elements if the list needs to shrink.
        for (int i = destN; i > srcN; i--) {
            dest.removeLast();
        }
    }