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

Commit 26b4bb3c authored by Ben Reich's avatar Ben Reich
Browse files

Fix crash when opening overflow menu whilst selection active

When the material 3 flag is enabled, the NavigationViewManager takes
care of updating the options menu. This means we don't delegate it to
the menu manager directly but we do it through the NVM. Previously a
call to the MenuManager was missed in the Picker which caused a null
dereference. Update that call site and add a test to avoid a regression

Fix: 408935808
Test: atest PickActivityTest#testOptionMenuWorksWhileOptionSelected
Flag: com.android.documentsui.flags.use_material3
Change-Id: I5a692c7593327c0493bbe38bdd4a1289f0761cb6
parent c6c97f12
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -362,7 +362,9 @@ public class PickActivity extends BaseActivity implements ActionHandler.Addons {
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        if (!isUseMaterial3FlagEnabled()) {
            mInjector.menuManager.updateOptionMenu(menu);
        }

        final DocumentInfo cwd = getCurrentDirectory();

+35 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.documentsui;

import static com.android.documentsui.StubProvider.ROOT_0_ID;
import static com.android.documentsui.base.Providers.AUTHORITY_STORAGE;

import static com.google.common.truth.Truth.assertThat;
@@ -31,9 +32,13 @@ import android.provider.DocumentsContract;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObjectNotFoundException;

import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.bots.Bots;
import com.android.documentsui.picker.PickActivity;
import com.android.documentsui.rules.TestFilesRule;
import com.android.documentsui.testing.TestProvidersAccess;
import com.android.documentsui.ui.TestDialogController;
import com.android.documentsui.util.VersionUtils;
@@ -73,10 +78,17 @@ public class PickActivityTest {
        return Lists.newArrayList(true, false);
    }

    @Rule
    public final TestFilesRule mTestFilesRule =
            new TestFilesRule()
                    .createFileInRoot(ROOT_0_ID, TestFilesRule.FILE_NAME_1, "text/plain");

    @Rule
    public final ActivityTestRule<PickActivity> mRule =
            new ActivityTestRule<>(PickActivity.class, false, false);

    private Bots mBots = null;

    @Before
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
@@ -91,6 +103,14 @@ public class PickActivityTest {
        mTestConfigStore = new TestConfigStore();

        isPrivateSpaceEnabled = SdkLevel.isAtLeastS() && isPrivateSpaceEnabled;

        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
        mBots =
                new Bots(
                        UiDevice.getInstance(instrumentation),
                        instrumentation.getUiAutomation(),
                        mTargetContext,
                        5000);
    }

    @Test
@@ -166,4 +186,19 @@ public class PickActivityTest {
        assertThat(pickActivity.isFinishing()).isFalse();
        mTestDialogs.assertActionNotAllowedShown();
    }

    @Test
    public void testOptionMenuWorksWhileOptionSelected() throws UiObjectNotFoundException {
        // Launch the PickActivity using `GET_CONTENT` action, and navigate to test root.
        mRule.launchActivity(mIntentGetContent);
        mBots.roots.openRoot(ROOT_0_ID);

        // Switch to list mode and select the test document.
        mBots.main.switchToListMode();
        mBots.directory.selectDocument(TestFilesRule.FILE_NAME_1, 1);

        // Open the overflow menu and assert that the Sort by menu option is there.
        mBots.main.openOverflowMenu();
        mBots.menu.hasMenuItem("Sort by...");
    }
}