[Memory Leak] Fix leak of LauncherAppWidgetHostView via StateManager.StateListener

Rather than register a StateListener for each LauncherAppWidgetHostView, just register one StateListener which, upon launcher state is changed to NORMAL, iterate over all child views under Workspace and perform a11y action if view tag is set.

Fix: 397978703
Test: presubmit
Flag: EXEMPT bug fix
Change-Id: I044d012b74eaa5356196c5503318fa8ab389ec46
This commit is contained in:
Fengjiang Li committed 2025-02-20 22:05:02 -08:00
1 parent 4d9ce7c953
commit e0553d7da3
3 files changed
+37 -24

No files matched your search

+2 -14
View File
@@ -16,7 +16,6 @@
package com.android.launcher3;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.dragndrop.DraggableView.DRAGGABLE_ICON;
import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_REORDER_PREVIEW_OFFSET;
@@ -71,7 +70,6 @@ import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.folder.PreviewBackground;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.util.CellAndSpan;
import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.MSDLPlayerWrapper;
@@ -791,18 +789,8 @@ public class CellLayout extends ViewGroup {
// Whenever an app is added, if Accessibility service is enabled, focus on that app.
if (mActivity instanceof Launcher) {
Launcher.cast(mActivity).getStateManager().addStateListener(
new StateManager.StateListener<LauncherState>() {
@Override
public void onStateTransitionComplete(LauncherState finalState) {
if (finalState == NORMAL) {
child.performAccessibilityAction(
AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
Launcher.cast(mActivity).getStateManager()
.removeStateListener(this);
}
}
});
child.setTag(R.id.perform_a11y_action_on_launcher_state_normal_tag,
AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (markCells) markCellsAsOccupiedForView(child);