Search in sources :

Example 11 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

the class RootsCacheTest method testExcludedAuthorities.

public void testExcludedAuthorities() throws Exception {
    final List<RootInfo> roots = newArrayList();
    // Set up some roots
    for (int i = 0; i < 5; ++i) {
        RootInfo root = new RootInfo();
        root.authority = "authority" + i;
        roots.add(root);
    }
    // Make some allowed authorities
    List<RootInfo> allowedRoots = newArrayList(roots.get(0), roots.get(2), roots.get(4));
    // Set up the excluded authority list
    for (RootInfo root : roots) {
        if (!allowedRoots.contains(root)) {
            mState.excludedAuthorities.add(root.authority);
        }
    }
    mState.acceptMimes = new String[] { "*/*" };
    assertContainsExactly(allowedRoots, getMatchingRoots(roots, mState));
}
Also used : RootInfo(com.android.documentsui.model.RootInfo)

Example 12 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

the class RootsCacheTest method buildForMimeTypes.

private static RootInfo buildForMimeTypes(String... mimeTypes) {
    final RootInfo root = new RootInfo();
    root.derivedMimeTypes = mimeTypes;
    return root;
}
Also used : RootInfo(com.android.documentsui.model.RootInfo)

Example 13 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

the class RootsFragment method onCurrentRootChanged.

public void onCurrentRootChanged() {
    if (mAdapter == null) {
        return;
    }
    final RootInfo root = ((BaseActivity) getActivity()).getCurrentRoot();
    for (int i = 0; i < mAdapter.getCount(); i++) {
        final Object item = mAdapter.getItem(i);
        if (item instanceof RootItem) {
            final RootInfo testRoot = ((RootItem) item).root;
            if (Objects.equals(testRoot, root)) {
                mList.setItemChecked(i, true);
                mList.setSelection(i);
                return;
            }
        }
    }
}
Also used : RootInfo(com.android.documentsui.model.RootInfo)

Example 14 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

the class RootsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getActivity();
    final RootsCache roots = DocumentsApplication.getRootsCache(context);
    final State state = ((BaseActivity) context).getDisplayState();
    mCallbacks = new LoaderCallbacks<Collection<RootInfo>>() {

        @Override
        public Loader<Collection<RootInfo>> onCreateLoader(int id, Bundle args) {
            return new RootsLoader(context, roots, state);
        }

        @Override
        public void onLoadFinished(Loader<Collection<RootInfo>> loader, Collection<RootInfo> result) {
            if (!isAdded()) {
                return;
            }
            Intent handlerAppIntent = getArguments().getParcelable(EXTRA_INCLUDE_APPS);
            mAdapter = new RootsAdapter(context, result, handlerAppIntent, state);
            mList.setAdapter(mAdapter);
            onCurrentRootChanged();
        }

        @Override
        public void onLoaderReset(Loader<Collection<RootInfo>> loader) {
            mAdapter = null;
            mList.setAdapter(null);
        }
    };
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Loader(android.content.Loader) Intent(android.content.Intent) RootInfo(com.android.documentsui.model.RootInfo) Collection(java.util.Collection)

Example 15 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

the class RootsCache method loadRootsForAuthority.

/**
     * Bring up requested provider and query for all active roots.
     */
private Collection<RootInfo> loadRootsForAuthority(ContentResolver resolver, String authority, boolean forceRefresh) {
    if (DEBUG)
        Log.d(TAG, "Loading roots for " + authority);
    synchronized (mObservedAuthorities) {
        if (mObservedAuthorities.add(authority)) {
            // Watch for any future updates
            final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
            mContext.getContentResolver().registerContentObserver(rootsUri, true, mObserver);
        }
    }
    final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
    if (!forceRefresh) {
        // Look for roots data that we might have cached for ourselves in the
        // long-lived system process.
        final Bundle systemCache = resolver.getCache(rootsUri);
        if (systemCache != null) {
            if (DEBUG)
                Log.d(TAG, "System cache hit for " + authority);
            return systemCache.getParcelableArrayList(TAG);
        }
    }
    final ArrayList<RootInfo> roots = new ArrayList<>();
    ContentProviderClient client = null;
    Cursor cursor = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority);
        cursor = client.query(rootsUri, null, null, null, null);
        while (cursor.moveToNext()) {
            final RootInfo root = RootInfo.fromRootsCursor(authority, cursor);
            roots.add(root);
        }
    } catch (Exception e) {
        Log.w(TAG, "Failed to load some roots from " + authority + ": " + e);
    } finally {
        IoUtils.closeQuietly(cursor);
        ContentProviderClient.releaseQuietly(client);
    }
    // Cache these freshly parsed roots over in the long-lived system
    // process, in case our process goes away. The system takes care of
    // invalidating the cache if the package or Uri changes.
    final Bundle systemCache = new Bundle();
    systemCache.putParcelableArrayList(TAG, roots);
    resolver.putCache(rootsUri, systemCache);
    return roots;
}
Also used : RootInfo(com.android.documentsui.model.RootInfo) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentProviderClient(android.content.ContentProviderClient)

Aggregations

RootInfo (com.android.documentsui.model.RootInfo)85 DocumentInfo (com.android.documentsui.model.DocumentInfo)20 FragmentManager (android.app.FragmentManager)15 Bundle (android.os.Bundle)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)10 Cursor (android.database.Cursor)10 ContentProviderClient (android.content.ContentProviderClient)5 Context (android.content.Context)5 Loader (android.content.Loader)5 MatrixCursor (android.database.MatrixCursor)5 MergeCursor (android.database.MergeCursor)5 Uri (android.net.Uri)5 VisibleForTesting (android.support.annotation.VisibleForTesting)5 MenuItem (android.view.MenuItem)5 DirectoryFragment (com.android.documentsui.dirlist.DirectoryFragment)5 IOException (java.io.IOException)5 Collection (java.util.Collection)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ExecutionException (java.util.concurrent.ExecutionException)5