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

Commit c3607154 authored by Ben Reich's avatar Ben Reich
Browse files

Fix up findSelectionHotspot logic for use_material3

The current logic for the findSelectionHotspot (which underpins the
logic to selectDocument) doesn't work for grid view. It attempts to find
the `icon_wrapper` ID in the view hierarchy. When in grid mode and with
the use_material3 flag enabled the selectable region is actually
selection_circle instead. Update the logic to respect that.

Bug: 412776499
Test: atest com.android.documentsui.CancelFromNotificationUiTest
Flag: com.android.documentsui.flags.use_material3
Change-Id: If9f997455108a38f503b8f22542d166c40ccdac2
parent 918931f1
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@ public class DirectoryListBot extends Bots.BaseBot {
    private final String mDirListId;
    private final String mItemRootId;
    private final String mPreviewId;
    private final String mIconId;
    private final String mGridSelectionRegionId;
    private final String mListSelectionRegionId;

    private final UiAutomation mAutomation;

@@ -72,7 +73,11 @@ public class DirectoryListBot extends Bots.BaseBot {
        mDirListId = mTargetPackage + ":id/dir_list";
        mItemRootId = mTargetPackage + ":id/item_root";
        mPreviewId = mTargetPackage + ":id/preview_icon";
        mIconId = mTargetPackage + (isUseMaterial3FlagEnabled() ? ":id/icon_wrapper" : ":id/icon");
        mListSelectionRegionId =
                mTargetPackage + (isUseMaterial3FlagEnabled() ? ":id/icon_wrapper" : ":id/icon");
        mGridSelectionRegionId =
                mTargetPackage
                        + (isUseMaterial3FlagEnabled() ? ":id/selection_circle" : ":id/icon");
    }

    public void assertDocumentsCount(int count) throws UiObjectNotFoundException {
@@ -209,11 +214,15 @@ public class DirectoryListBot extends Bots.BaseBot {
        final UiSelector docList = findDocumentsListSelector();
        new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));

        BySelector selectionRegionSelector = By.res(mGridSelectionRegionId);
        if (mDevice.findObject(selectionRegionSelector) == null) {
            selectionRegionSelector = By.res(mListSelectionRegionId);
        }
        UiObject2 parent = mDevice.findObject(list).findObject(selector);
        UiObject2 selectionHotspot = null;
        for (int i = 1; i <= MAX_LAYOUT_LEVEL; i++) {
            parent = parent.getParent();
            selectionHotspot = parent.findObject(By.res(mIconId));
            selectionHotspot = parent.findObject(selectionRegionSelector);
            if (selectionHotspot != null) {
                break;
            }