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

Commit 4f200193 authored by Stephen Hughes's avatar Stephen Hughes Committed by Android (Google) Code Review
Browse files

Merge "Prevent OPEN_DOCUMENT_TREE when root does not support children Test:...

Merge "Prevent OPEN_DOCUMENT_TREE when root does not support children Test: ActionHandlerTest updated Bug: 142214700"
parents 16455790 3bd3e0d6
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -544,7 +544,14 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
    }

    private void onRootLoaded(@Nullable RootInfo root) {
        if (root != null) {
        boolean invalidRootForAction =
                (root != null
                && !root.supportsChildren()
                && mState.action == State.ACTION_OPEN_TREE);

        if (invalidRootForAction) {
            loadDeviceRoot();
        } else if (root != null) {
            mActivity.onRootPicked(root);
        } else {
            launchToDefaultLocation();
+10 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ public class TestProvidersAccess implements ProvidersAccess {
    public static final RootInfo AUDIO;
    public static final RootInfo VIDEO;
    public static final RootInfo EXTERNALSTORAGE;
    public static final RootInfo NO_TREE_ROOT;


    static {
@@ -121,6 +122,13 @@ public class TestProvidersAccess implements ProvidersAccess {
        EXTERNALSTORAGE.derivedType = RootInfo.TYPE_LOCAL;
        EXTERNALSTORAGE.flags = Root.FLAG_LOCAL_ONLY
                | Root.FLAG_SUPPORTS_IS_CHILD;

        NO_TREE_ROOT = new RootInfo();
        NO_TREE_ROOT.authority = "no.tree.authority";
        NO_TREE_ROOT.rootId = "1";
        NO_TREE_ROOT.title = "No Tree Title";
        NO_TREE_ROOT.derivedType = RootInfo.TYPE_LOCAL;
        NO_TREE_ROOT.flags = Root.FLAG_LOCAL_ONLY;
    }

    public final Map<String, Collection<RootInfo>> roots = new HashMap<>();
@@ -132,6 +140,7 @@ public class TestProvidersAccess implements ProvidersAccess {
        add(HAMMY);
        add(PICKLES);
        add(EXTERNALSTORAGE);
        add(NO_TREE_ROOT);
    }

    private void add(RootInfo root) {
@@ -146,6 +155,7 @@ public class TestProvidersAccess implements ProvidersAccess {
        pm.addStubContentProviderForRoot(TestProvidersAccess.HOME);
        pm.addStubContentProviderForRoot(TestProvidersAccess.HAMMY);
        pm.addStubContentProviderForRoot(TestProvidersAccess.PICKLES);
        pm.addStubContentProviderForRoot(TestProvidersAccess.NO_TREE_ROOT);
    }

    @Override
+15 −0
Original line number Diff line number Diff line
@@ -231,6 +231,21 @@ public class ActionHandlerTest {
        assertRootPicked(TestProvidersAccess.EXTERNALSTORAGE.getUri());
    }

    @Test
    public void testInitLocation_DefaultToDeviceRoot_ActionOpenTree_RootDoesNotSupportChildren()
            throws Exception {
        mEnv.state.action = State.ACTION_OPEN_TREE;

        String authority = TestProvidersAccess.NO_TREE_ROOT.authority;
        String rootId = TestProvidersAccess.NO_TREE_ROOT.rootId;
        Uri hintUri = DocumentsContract.buildRootUri(authority, rootId);

        mActivity.getIntent().putExtra(DocumentsContract.EXTRA_INITIAL_URI, hintUri);
        mHandler.initLocation(mActivity.getIntent());

        assertRootPicked(TestProvidersAccess.EXTERNALSTORAGE.getUri());
    }

    @Test
    public void testOpenContainerDocument() {
        mHandler.openContainerDocument(TestEnv.FOLDER_0);