summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorTiger Huang <tigerhuang@google.com>2021-04-19 19:13:12 +0800
committerTiger Huang <tigerhuang@google.com>2021-04-20 00:13:55 +0800
commit88ae86be6b3de696bc5cdbec582be19625a1a10a (patch)
tree3b913892675816dbd0ec92d57be3234ff06a1695 /core/java
parente7f2887e7d25554a9fdb2e0fa7dc125aa3ab3859 (diff)
Clear controls in the temp list after using them
The list would be cleared while next time we use them, so it could constantly occupy the memory. This CL clears the temp list right after we use the controls. So it won't occupy the memory while they are not being used. This CL also sends a new list to the app when dispatching the insets animation progress. In this way, we don't need to clear mTmpRunningAnims after dispatching it. Also, the app might use the animation list AFTER the 'onProgress' callback. This change can make the list stay the same. Fix: 183684434 Test: Use Android Memory Profiler to check if there is InsetsAnimationControlImpl or WindowInsetsAnimation instances after GCing after playing insets animation in Launcher. Change-Id: I781233abb2c9c8400c6f76b537bef161745e67f7
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/view/InsetsController.java16
1 files changed, 7 insertions, 9 deletions
diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java
index c201e3beb9b2..f6cb18ea1d3c 100644
--- a/core/java/android/view/InsetsController.java
+++ b/core/java/android/view/InsetsController.java
@@ -541,9 +541,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
private final SparseArray<InsetsSourceControl> mTmpControlArray = new SparseArray<>();
private final ArrayList<RunningAnimation> mRunningAnimations = new ArrayList<>();
- private final ArrayList<WindowInsetsAnimation> mTmpRunningAnims = new ArrayList<>();
- private final List<WindowInsetsAnimation> mUnmodifiableTmpRunningAnims =
- Collections.unmodifiableList(mTmpRunningAnims);
private final ArrayList<InsetsAnimationControlImpl> mTmpFinishedControls = new ArrayList<>();
private final ArraySet<InsetsSourceConsumer> mRequestedVisibilityChanged = new ArraySet<>();
private WindowInsets mLastInsets;
@@ -601,9 +598,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
return;
}
- mTmpFinishedControls.clear();
- mTmpRunningAnims.clear();
- InsetsState state = new InsetsState(mState, true /* copySources */);
+ final List<WindowInsetsAnimation> runningAnimations = new ArrayList<>();
+ final InsetsState state = new InsetsState(mState, true /* copySources */);
for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
RunningAnimation runningAnimation = mRunningAnimations.get(i);
if (DEBUG) Log.d(TAG, "Running animation type: " + runningAnimation.type);
@@ -615,7 +611,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
// if it gets finished within applyChangeInsets we still dispatch it to
// onProgress.
if (runningAnimation.startDispatched) {
- mTmpRunningAnims.add(control.getAnimation());
+ runningAnimations.add(control.getAnimation());
}
if (control.applyChangeInsets(state)) {
@@ -628,9 +624,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
mLastInsets.isRound(), mLastInsets.shouldAlwaysConsumeSystemBars(),
mLastLegacySoftInputMode, mLastLegacyWindowFlags, mLastLegacySystemUiFlags,
mWindowType, mLastWindowingMode, null /* typeSideMap */);
- mHost.dispatchWindowInsetsAnimationProgress(insets, mUnmodifiableTmpRunningAnims);
+ mHost.dispatchWindowInsetsAnimationProgress(insets,
+ Collections.unmodifiableList(runningAnimations));
if (DEBUG) {
- for (WindowInsetsAnimation anim : mUnmodifiableTmpRunningAnims) {
+ for (WindowInsetsAnimation anim : runningAnimations) {
Log.d(TAG, String.format("Running animation type: %d, progress: %f",
anim.getTypeMask(), anim.getInterpolatedFraction()));
}
@@ -639,6 +636,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
for (int i = mTmpFinishedControls.size() - 1; i >= 0; i--) {
dispatchAnimationEnd(mTmpFinishedControls.get(i).getAnimation());
}
+ mTmpFinishedControls.clear();
};
}