Search in sources :

Example 56 with ContentProviderClient

use of android.content.ContentProviderClient in project android_frameworks_base by ResurrectionRemix.

the class MediaInserterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockProvider = EasyMock.createMock(IContentProvider.class);
    final ContentProviderClient client = new ContentProviderClient(getInstrumentation().getContext().getContentResolver(), mMockProvider, true);
    mMediaInserter = new MediaInserter(client, TEST_BUFFER_SIZE);
    mPackageName = getInstrumentation().getContext().getPackageName();
    mFilesCounter = 0;
    mAudioCounter = 0;
    mVideoCounter = 0;
    mImagesCounter = 0;
}
Also used : IContentProvider(android.content.IContentProvider) MediaInserter(android.media.MediaInserter) ContentProviderClient(android.content.ContentProviderClient)

Example 57 with ContentProviderClient

use of android.content.ContentProviderClient in project android_frameworks_base by ResurrectionRemix.

the class Job method getClient.

ContentProviderClient getClient(DocumentInfo doc) throws RemoteException {
    ContentProviderClient client = mClients.get(doc.authority);
    if (client == null) {
        // Acquire content providers.
        client = acquireUnstableProviderOrThrow(getContentResolver(), doc.authority);
        mClients.put(doc.authority, client);
    }
    assert (client != null);
    return client;
}
Also used : ContentProviderClient(android.content.ContentProviderClient)

Example 58 with ContentProviderClient

use of android.content.ContentProviderClient in project android_frameworks_base by DirtyUnicorns.

the class MediaInserterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockProvider = EasyMock.createMock(IContentProvider.class);
    final ContentProviderClient client = new ContentProviderClient(getInstrumentation().getContext().getContentResolver(), mMockProvider, true);
    mMediaInserter = new MediaInserter(client, TEST_BUFFER_SIZE);
    mPackageName = getInstrumentation().getContext().getPackageName();
    mFilesCounter = 0;
    mAudioCounter = 0;
    mVideoCounter = 0;
    mImagesCounter = 0;
}
Also used : IContentProvider(android.content.IContentProvider) MediaInserter(android.media.MediaInserter) ContentProviderClient(android.content.ContentProviderClient)

Example 59 with ContentProviderClient

use of android.content.ContentProviderClient in project android_frameworks_base by DirtyUnicorns.

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)

Example 60 with ContentProviderClient

use of android.content.ContentProviderClient in project android_frameworks_base by DirtyUnicorns.

the class OpenExternalDirectoryActivity method getIntentForExistingPermission.

private static Intent getIntentForExistingPermission(OpenExternalDirectoryActivity activity, boolean isRoot, File root, File file) {
    final String packageName = activity.getCallingPackage();
    final ContentProviderClient storageClient = activity.getExternalStorageClient();
    final Uri grantedUri = getGrantedUriPermission(activity, storageClient, file);
    final Uri rootUri = root.equals(file) ? grantedUri : getGrantedUriPermission(activity, storageClient, root);
    if (DEBUG)
        Log.d(TAG, "checking if " + packageName + " already has permission for " + grantedUri + " or its root (" + rootUri + ")");
    final ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
    for (UriPermission uriPermission : am.getGrantedUriPermissions(packageName).getList()) {
        final Uri uri = uriPermission.getUri();
        if (uri == null) {
            Log.w(TAG, "null URI for " + uriPermission);
            continue;
        }
        if (uri.equals(grantedUri) || uri.equals(rootUri)) {
            if (DEBUG)
                Log.d(TAG, packageName + " already has permission: " + uriPermission);
            return createGrantedUriPermissionsIntent(grantedUri);
        }
    }
    if (DEBUG)
        Log.d(TAG, packageName + " does not have permission for " + grantedUri);
    return null;
}
Also used : UriPermission(android.content.UriPermission) ActivityManager(android.app.ActivityManager) Uri(android.net.Uri) ContentProviderClient(android.content.ContentProviderClient)

Aggregations

ContentProviderClient (android.content.ContentProviderClient)66 Cursor (android.database.Cursor)23 Uri (android.net.Uri)21 RemoteException (android.os.RemoteException)21 ContentResolver (android.content.ContentResolver)15 ArrayList (java.util.ArrayList)12 Bundle (android.os.Bundle)11 FileNotFoundException (java.io.FileNotFoundException)11 Test (org.junit.Test)7 CancellationSignal (android.os.CancellationSignal)6 ActivityManager (android.app.ActivityManager)5 AlertDialog (android.app.AlertDialog)5 ClipData (android.content.ClipData)5 ComponentName (android.content.ComponentName)5 IContentProvider (android.content.IContentProvider)5 Intent (android.content.Intent)5 ServiceConnection (android.content.ServiceConnection)5 UriPermission (android.content.UriPermission)5 Configuration (android.content.res.Configuration)5 MediaInserter (android.media.MediaInserter)5