From a2db1356ba5f22388a8f9117f9aa566d6dbfef4e Mon Sep 17 00:00:00 2001 From: Stefan Andonian Date: Fri, 17 Jan 2025 16:30:37 -0800 Subject: [PATCH] Focus on newly added app for all Accessibility use cases when adding an app to the home screen. Bug: 377555526 Test: Verified that this works well for both this use case and for b/383456105's use case. Flag: EXEMPT bug fix Change-Id: I91426487f435d6c0b796cafe58b526c73dfaa398 --- src/com/android/launcher3/CellLayout.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 3d71ff178e..714c8b4d03 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -16,6 +16,7 @@ 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; @@ -47,6 +48,7 @@ import android.view.View; import android.view.ViewDebug; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityNodeInfo; import androidx.annotation.IntDef; import androidx.annotation.Nullable; @@ -69,6 +71,7 @@ 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; @@ -781,6 +784,22 @@ public class CellLayout extends ViewGroup { } mShortcutsAndWidgets.addView(child, index, lp); + // 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() { + @Override + public void onStateTransitionComplete(LauncherState finalState) { + if (finalState == NORMAL) { + child.performAccessibilityAction( + AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null); + Launcher.cast(mActivity).getStateManager() + .removeStateListener(this); + } + } + }); + } + if (markCells) markCellsAsOccupiedForView(child); return true;