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

Commit 5036862d authored by Tony Huang's avatar Tony Huang
Browse files

Update getDefaultRoot rule

When user in ejectable root then eject the root, is will jump to
Downloads root or Recents root. But in document tree case, it
should jump to storage root rahter than above both.
Fix the rule and move this logic to ProvidersAccess for testing.

Fix: 145186010
Test: manual
Test: atest DocumentsUIGoogleTests
Change-Id: I3d72da8a3cd1b0e15040ab145216c14519bc642f
parent e62906a3
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static com.android.documentsui.base.SharedMinimal.VERBOSE;

import android.util.Log;

import androidx.annotation.Nullable;

import com.android.documentsui.base.MimeTypes;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.State;
@@ -144,4 +146,20 @@ public interface ProvidersAccess {
        }
        return matching;
    }

    /**
     * Returns the root should default show on current state.
     */
    static @Nullable RootInfo getDefaultRoot(Collection<RootInfo> roots, State state) {
        for (RootInfo root : ProvidersAccess.getMatchingRoots(roots, state)) {
            if (root.isExternalStorage() && state.action == State.ACTION_OPEN_TREE) {
                return root;
            }
            if (root.isDownloads()) {
                return root;
            }
        }
        return null;
    }

}
+6 −10
Original line number Diff line number Diff line
@@ -35,26 +35,26 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.FileUtils;
import android.os.Handler;
import android.os.SystemClock;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Root;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.util.Log;

import androidx.annotation.GuardedBy;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.android.documentsui.DocumentsApplication;
import com.android.documentsui.R;
import com.android.documentsui.archives.ArchivesProvider;
import com.android.documentsui.base.Providers;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.State;
import androidx.annotation.GuardedBy;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

import android.os.FileUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -409,12 +409,8 @@ public class ProvidersCache implements ProvidersAccess {

    @Override
    public RootInfo getDefaultRootBlocking(State state) {
        for (RootInfo root : ProvidersAccess.getMatchingRoots(getRootsBlocking(), state)) {
            if (root.isDownloads()) {
                return root;
            }
        }
        return mRecentsRoot;
        RootInfo root = ProvidersAccess.getDefaultRoot(getRootsBlocking(), state);
        return root != null ? root : mRecentsRoot;
    }

    public void logCache() {
+23 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.documentsui.roots;

import static com.google.common.collect.Lists.newArrayList;

import android.provider.DocumentsContract;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

@@ -130,6 +131,28 @@ public class ProvidersAccessTest extends AndroidTestCase {
                ProvidersAccess.getMatchingRoots(mRoots, mState));
    }

    public void testDefaultRoot() {
        mState.acceptMimes = new String[] { "*/*" };
        assertNull(ProvidersAccess.getDefaultRoot(mRoots, mState));

        RootInfo downloads = buildForMimeTypes("*/*");
        downloads.authority = Providers.AUTHORITY_DOWNLOADS;
        mRoots.add(downloads);

        assertEquals(downloads, ProvidersAccess.getDefaultRoot(mRoots, mState));
    }

    public void testDefaultRoot_openDocumentTree() {
        RootInfo storage = buildForMimeTypes("*/*");
        storage.authority = Providers.AUTHORITY_STORAGE;
        storage.flags = DocumentsContract.Root.FLAG_SUPPORTS_IS_CHILD;
        mRoots.add(storage);

        mState.action = State.ACTION_OPEN_TREE;
        mState.acceptMimes = new String[] { "*/*" };
        assertEquals(storage, ProvidersAccess.getDefaultRoot(mRoots, mState));
    }

    public void testExcludedAuthorities() throws Exception {
        final List<RootInfo> roots = newArrayList();