Java 类android.content.ContentProviderClient 实例源码

项目:simple-share-android    文件:DocumentsContract.java   
public static boolean uncompressDocument(ContentResolver resolver, Uri fromDocumentUri) {
    final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
            fromDocumentUri.getAuthority());
    try {
        final Bundle in = new Bundle();
        in.putString(Document.COLUMN_DOCUMENT_ID, getDocumentId(fromDocumentUri));
        in.putParcelable(DocumentsContract.EXTRA_URI, fromDocumentUri);

        resolver.call(fromDocumentUri, METHOD_UNCOMPRESS_DOCUMENT, null, in);
        return true;
    } catch (Exception e) {
        Log.w(TAG, "Failed to uncompress document", e);
        return false;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:easyfilemanager    文件:StandaloneActivity.java   
@Override
protected Uri doInBackground(Void... params) {
    final ContentResolver resolver = getContentResolver();
    final DocumentInfo cwd = getCurrentDirectory();
    ContentProviderClient client = null;
    Uri childUri = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                resolver, cwd.derivedUri.getAuthority());

        childUri = DocumentsContract.createDocument(
                resolver, cwd.derivedUri, mMimeType, mDisplayName);
    } catch (Exception e) {
        Log.w(TAG, "Failed to create document", e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
    if (childUri != null) {
        saveStackBlocking();
    }
    return childUri;
}
项目:easyfilemanager    文件:CreateFileFragment.java   
@Override
protected Uri doInBackground(Void... params) {
    final ContentResolver resolver = mActivity.getContentResolver();
    ContentProviderClient client = null;
    Uri childUri = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                resolver, mCwd.derivedUri.getAuthority());
        childUri = DocumentsContract.createDocument(
                resolver, mCwd.derivedUri, mMimeType, mDisplayName);
    } catch (Exception e) {
        Log.w(DocumentsActivity.TAG, "Failed to create document", e);
        CrashReportingManager.logException(e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }

    return childUri;
}
项目:simple-share-android    文件:RenameFragment.java   
@Override
protected DocumentInfo doInBackground(Void... params) {
    final ContentResolver resolver = mActivity.getContentResolver();
    ContentProviderClient client = null;
    try {
        final Uri childUri = DocumentsContract.renameDocument(
                resolver, mDoc.derivedUri, mFileName);
        return DocumentInfo.fromUri(resolver, childUri);
    } catch (Exception e) {
        Log.w(TAG, "Failed to rename directory", e);
        CrashReportingManager.logException(e);
        return null;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:easyfilemanager    文件:CreateDirectoryFragment.java   
@Override
    protected DocumentInfo doInBackground(Void... params) {
        final ContentResolver resolver = mActivity.getContentResolver();
        ContentProviderClient client = null;
        try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mCwd.derivedUri.getAuthority());
            final Uri childUri = DocumentsContract.createDocument(
                    resolver, mCwd.derivedUri, Document.MIME_TYPE_DIR, mDisplayName);
            return DocumentInfo.fromUri(resolver, childUri);
        } catch (Exception e) {
            Log.w(TAG, "Failed to create directory", e);
            CrashReportingManager.logException(e);
            return null;
        } finally {
            ContentProviderClientCompat.releaseQuietly(client);
        }
    }
项目:easyfilemanager    文件:RecentLoader.java   
public void runInternal() {
    ContentProviderClient client = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                getContext().getContentResolver(), authority);

        final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootId);
        final Cursor cursor = client.query(
                uri, null, null, null, DirectoryLoader.getQuerySortOrder(mSortOrder));
        mWithRoot = new RootCursorWrapper(authority, rootId, cursor, MAX_DOCS_FROM_ROOT);

    } catch (Exception e) {
        Log.w(TAG, "Failed to load " + authority + ", " + rootId, e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }

    set(mWithRoot);

    mFirstPassLatch.countDown();
    if (mFirstPassDone) {
        onContentChanged();
    }
}
项目:easyfilemanager    文件:DocumentsContract.java   
/**
 * Return thumbnail representing the document at the given URI. Callers are
 * responsible for their own in-memory caching.
 *
 * @param documentUri document to return thumbnail for, which must have
 *            {@link Document#FLAG_SUPPORTS_THUMBNAIL} set.
 * @param size optimal thumbnail size desired. A provider may return a
 *            thumbnail of a different size, but never more than double the
 *            requested size.
 * @param signal signal used to indicate if caller is no longer interested
 *            in the thumbnail.
 * @return decoded thumbnail, or {@code null} if problem was encountered.
 * @see DocumentsProvider#openDocumentThumbnail(String, Point,
 *      CancellationSignal)
 */
public static Bitmap getDocumentThumbnail(
        ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal) {
    final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient(resolver, 
            documentUri.getAuthority());
    try {
        if(UsbStorageProvider.AUTHORITY.equals(documentUri.getAuthority())) {
            return ImageUtils.getThumbnail(resolver, documentUri, size.x, size.y);
        }
        return getDocumentThumbnails(client, documentUri, size, signal);
    } catch (Exception e) {
        if (!(e instanceof OperationCanceledException)) {
            Log.w(TAG, "Failed to load thumbnail for " + documentUri + ": " + e);
        }
        return null;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:EasyAppleSyncAdapter    文件:BaseSyncAdapter.java   
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
                          SyncResult syncResult) {
    // required for dav4android (ServiceLoader)
    Thread.currentThread().setContextClassLoader(getContext().getClassLoader());

    try {
        syncLocalAndRemoteCollections(account, provider);
        syncCalendarsEvents(account, provider, extras);

        // notify any registered caller that sync operation is finished
        getContext().getContentResolver().notifyChange(GlobalConstant.CONTENT_URI, null, false);
    } catch (InvalidAccountException | CalendarStorageException e) {
        e.printStackTrace();
    }
}
项目:TVGuide    文件:TvGuideSyncAdapter.java   
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {

    if ( Utility.isNotDuplicateSync(getContext())) {
        if (BuildConfig.DEBUG) Log.d(LOG_TAG,"Start sync!");
        sendSyncStatus(START_SYNC);
        final TvService service = TvApiClient.getClient().create(TvService.class);
        syncCategories(service, provider, syncResult);
        syncChannels(service, provider, syncResult);
        syncPrograms(service, provider, syncResult);
        notifyTvGuide(syncResult.stats.numInserts, syncResult.stats.numIoExceptions);
        prefHelper.setLastSyncTime(getContext().getString(R.string.pref_last_sync_time_key),
                                            System.currentTimeMillis());
        prefHelper.setFirstRun(getContext().getString(R.string.pref_fist_run_key),false);
        sendSyncStatus(END_SYNC);
        if (BuildConfig.DEBUG) Log.d(LOG_TAG,"End sync!");
    }
}
项目:simple-share-android    文件:DocumentsContract.java   
/**
 * Return thumbnail representing the document at the given URI. Callers are
 * responsible for their own in-memory caching.
 *
 * @param documentUri document to return thumbnail for, which must have
 *            {@link Document#FLAG_SUPPORTS_THUMBNAIL} set.
 * @param size optimal thumbnail size desired. A provider may return a
 *            thumbnail of a different size, but never more than double the
 *            requested size.
 * @param signal signal used to indicate if caller is no longer interested
 *            in the thumbnail.
 * @return decoded thumbnail, or {@code null} if problem was encountered.
 * @see DocumentsProvider#openDocumentThumbnail(String, Point,
 *      CancellationSignal)
 */
public static Bitmap getDocumentThumbnail(
        ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal) {
    final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient(resolver, 
            documentUri.getAuthority());
    try {
        if(UsbStorageProvider.AUTHORITY.equals(documentUri.getAuthority())) {
            return ImageUtils.getThumbnail(resolver, documentUri, size.x, size.y);
        }
        return getDocumentThumbnails(client, documentUri, size, signal);
    } catch (Exception e) {
        if (!(e instanceof OperationCanceledException)) {
            Log.w(TAG, "Failed to load thumbnail for " + documentUri + ": " + e);
        }
        return null;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:easyfilemanager    文件:DocumentsContract.java   
public static boolean uncompressDocument(ContentResolver resolver, Uri fromDocumentUri) {
    final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
            fromDocumentUri.getAuthority());
    try {
        final Bundle in = new Bundle();
        in.putString(Document.COLUMN_DOCUMENT_ID, getDocumentId(fromDocumentUri));
        in.putParcelable(DocumentsContract.EXTRA_URI, fromDocumentUri);

        resolver.call(fromDocumentUri, METHOD_UNCOMPRESS_DOCUMENT, null, in);
        return true;
    } catch (Exception e) {
        Log.w(TAG, "Failed to uncompress document", e);
        return false;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:easyfilemanager    文件:DocumentInfo.java   
public void updateFromUri(ContentResolver resolver, Uri uri) throws FileNotFoundException {
    ContentProviderClient client = null;
    Cursor cursor = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                resolver, uri.getAuthority());
        cursor = client.query(uri, null, null, null, null);
        if (!cursor.moveToFirst()) {
            throw new FileNotFoundException("Missing details for " + uri);
        }
        updateFromCursor(cursor, uri.getAuthority());
    } catch (Throwable t) {
        throw asFileNotFoundException(t);
    } finally {
        IoUtils.closeQuietly(cursor);
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:simple-share-android    文件:DocumentsActivity.java   
@Override
protected Uri doInBackground(Void... params) {
    final ContentResolver resolver = getContentResolver();
    final DocumentInfo cwd = getCurrentDirectory();

    ContentProviderClient client = null;
    Uri childUri = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                resolver, cwd.derivedUri.getAuthority());
        childUri = DocumentsContract.createDocument(
                resolver, cwd.derivedUri, mMimeType, mDisplayName);
    } catch (Exception e) {
        Log.w(TAG, "Failed to create document", e);
        CrashReportingManager.logException(e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }

    if (childUri != null) {
        saveStackBlocking();
    }

    return childUri;
}
项目:simple-share-android    文件:RecentLoader.java   
public void runInternal() {
    ContentProviderClient client = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                getContext().getContentResolver(), authority);

        final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootId);
        final Cursor cursor = client.query(
                uri, null, null, null, DirectoryLoader.getQuerySortOrder(mSortOrder));
        mWithRoot = new RootCursorWrapper(authority, rootId, cursor, MAX_DOCS_FROM_ROOT);

    } catch (Exception e) {
        Log.w(TAG, "Failed to load " + authority + ", " + rootId, e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }

    set(mWithRoot);

    mFirstPassLatch.countDown();
    if (mFirstPassDone) {
        onContentChanged();
    }
}
项目:FireFiles    文件:DocumentsActivity.java   
@Override
protected Uri doInBackground(Void... params) {
    final ContentResolver resolver = getContentResolver();
    final DocumentInfo cwd = getCurrentDirectory();

    ContentProviderClient client = null;
    Uri childUri = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                resolver, cwd.derivedUri.getAuthority());
        childUri = DocumentsContract.createDocument(
                resolver, cwd.derivedUri, mMimeType, mDisplayName);
    } catch (Exception e) {
        Log.w(TAG, "Failed to create document", e);
        CrashReportingManager.logException(e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }

    if (childUri != null) {
        saveStackBlocking();
    }

    return childUri;
}
项目:FireFiles    文件:CreateFileFragment.java   
@Override
protected Uri doInBackground(Void... params) {
    final ContentResolver resolver = mActivity.getContentResolver();
    ContentProviderClient client = null;
    Uri childUri = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                resolver, mCwd.derivedUri.getAuthority());
        childUri = DocumentsContract.createDocument(
                resolver, mCwd.derivedUri, mMimeType, mDisplayName);
    } catch (Exception e) {
        Log.w(DocumentsActivity.TAG, "Failed to create document", e);
        CrashReportingManager.logException(e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }

    return childUri;
}
项目:FireFiles    文件:RenameFragment.java   
@Override
protected DocumentInfo doInBackground(Void... params) {
    final ContentResolver resolver = mActivity.getContentResolver();
    ContentProviderClient client = null;
    try {
        final Uri childUri = DocumentsContract.renameDocument(
                resolver, mDoc.derivedUri, mFileName);
        return DocumentInfo.fromUri(resolver, childUri);
    } catch (Exception e) {
        Log.w(TAG, "Failed to rename directory", e);
        CrashReportingManager.logException(e);
        return null;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:FireFiles    文件:RecentLoader.java   
public void runInternal() {
    ContentProviderClient client = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                getContext().getContentResolver(), authority);

        final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootId);
        final Cursor cursor = client.query(
                uri, null, null, null, DirectoryLoader.getQuerySortOrder(mSortOrder));
        mWithRoot = new RootCursorWrapper(authority, rootId, cursor, MAX_DOCS_FROM_ROOT);

    } catch (Exception e) {
        Log.w(TAG, "Failed to load " + authority + ", " + rootId, e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }

    set(mWithRoot);

    mFirstPassLatch.countDown();
    if (mFirstPassDone) {
        onContentChanged();
    }
}
项目:FireFiles    文件:DocumentsContract.java   
public static boolean isChildDocument(ContentProviderClient client, Uri parentDocumentUri,
                                      Uri childDocumentUri) throws RemoteException {

    final Bundle in = new Bundle();
    in.putParcelable(DocumentsContract.EXTRA_URI, parentDocumentUri);
    in.putParcelable(DocumentsContract.EXTRA_TARGET_URI, childDocumentUri);

    final Bundle out = client.call(METHOD_IS_CHILD_DOCUMENT, null, in);
    if (out == null) {
        throw new RemoteException("Failed to get a reponse from isChildDocument query.");
    }
    if (!out.containsKey(DocumentsContract.EXTRA_RESULT)) {
        throw new RemoteException("Response did not include result field..");
    }
    return out.getBoolean(DocumentsContract.EXTRA_RESULT);
}
项目:simple-share-android    文件:DocumentsContract.java   
public static boolean isChildDocument(ContentProviderClient client, Uri parentDocumentUri,
                                      Uri childDocumentUri) throws RemoteException {

    final Bundle in = new Bundle();
    in.putParcelable(DocumentsContract.EXTRA_URI, parentDocumentUri);
    in.putParcelable(DocumentsContract.EXTRA_TARGET_URI, childDocumentUri);

    final Bundle out = client.call(METHOD_IS_CHILD_DOCUMENT, null, in);
    if (out == null) {
        throw new RemoteException("Failed to get a reponse from isChildDocument query.");
    }
    if (!out.containsKey(DocumentsContract.EXTRA_RESULT)) {
        throw new RemoteException("Response did not include result field..");
    }
    return out.getBoolean(DocumentsContract.EXTRA_RESULT);
}
项目:FireFiles    文件:DocumentsContract.java   
public static boolean uncompressDocument(ContentResolver resolver, Uri fromDocumentUri) {
    final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
            fromDocumentUri.getAuthority());
    try {
        final Bundle in = new Bundle();
        in.putString(Document.COLUMN_DOCUMENT_ID, getDocumentId(fromDocumentUri));
        in.putParcelable(DocumentsContract.EXTRA_URI, fromDocumentUri);

        resolver.call(fromDocumentUri, METHOD_UNCOMPRESS_DOCUMENT, null, in);
        return true;
    } catch (Exception e) {
        Log.w(TAG, "Failed to uncompress document", e);
        return false;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:simplest-sync-adapter    文件:SyncAdapter.java   
/**
 * Called by the Android system in response to a request to run the sync adapter. The work
 * required to read data from the network, parse it, and store it in the content provider
 * should be done here. Extending AbstractThreadedSyncAdapter ensures that all methods within SyncAdapter
 * run on a background thread. For this reason, blocking I/O and other long-running tasks can be
 * run <em>in situ</em>, and you don't have to set up a separate thread for them.
 *
 * <p>
 * <p>This is where we actually perform any work required to perform a sync.
 * {@link AbstractThreadedSyncAdapter} guarantees that this will be called on a non-UI thread,
 * so it is safe to perform blocking I/O here.
 * <p>
 *
 * <p>The syncResult argument allows you to pass information back to the method that triggered
 * the sync.
 */
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult) {

    // Your code to sync data
    // between mobile database and
    // the server goes here.

    for (int i = 0; i < 15; i++) {
        try {
            Thread.sleep(1000);
            Log.i(TAG, ">>>> sleeping the thread: " + (i + 1));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }   // end for

    // write DB data sanity checks at the end.
}
项目:simple-share-android    文件:CreateFileFragment.java   
@Override
protected Uri doInBackground(Void... params) {
    final ContentResolver resolver = mActivity.getContentResolver();
    ContentProviderClient client = null;
    Uri childUri = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(
                resolver, mCwd.derivedUri.getAuthority());
        childUri = DocumentsContract.createDocument(
                resolver, mCwd.derivedUri, mMimeType, mDisplayName);
    } catch (Exception e) {
        Log.w(DocumentsActivity.TAG, "Failed to create document", e);
        CrashReportingManager.logException(e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }

    return childUri;
}
项目:springreplugin    文件:PluginProviderClient2.java   
/**
 * 调用插件里的Provider
 *
 * @see android.content.ContentProviderClient#query(Uri, String[], String, String[], String)
 */
public static Cursor query(Context c, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    ContentProviderClient client = PluginProviderClient.acquireContentProviderClient(c, "");
    if (client != null) {
        try {
            Uri toUri = toCalledUri(c, uri);
            return client.query(toUri, projection, selection, selectionArgs, sortOrder);
        } catch (RemoteException e) {
            if (LogDebug.LOG) {
                Log.d(TAG, e.toString());
            }
        }
    }
    if (LogDebug.LOG) {
        Log.d(TAG, String.format("call query1 %s fail", uri.toString()));
    }
    return null;
}
项目:springreplugin    文件:PluginProviderClient2.java   
/**
 * 调用插件里的Provider
 *
 * @see android.content.ContentProviderClient#query(Uri, String[], String, String[], String, CancellationSignal)
 */
@TargetApi(16)
public static Cursor query(Context c, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) {
    ContentProviderClient client = PluginProviderClient.acquireContentProviderClient(c, "");
    if (client != null) {
        try {
            Uri toUri = toCalledUri(c, uri);
            return client.query(toUri, projection, selection, selectionArgs, sortOrder, cancellationSignal);
        } catch (RemoteException e) {
            if (LogDebug.LOG) {
                Log.d(TAG, e.toString());
            }
        }
    }

    if (LogDebug.LOG) {
        Log.d(TAG, String.format("call query2 %s fail", uri.toString()));
    }

    return null;
}
项目:springreplugin    文件:PluginProviderClient2.java   
/**
 * 调用插件里的Provider
 *
 * @see android.content.ContentProviderClient#update(Uri, ContentValues, String, String[])
 */
public static int update(Context c, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    ContentProviderClient client = PluginProviderClient.acquireContentProviderClient(c, "");
    if (client != null) {
        try {
            Uri toUri = toCalledUri(c, uri);
            return client.update(toUri, values, selection, selectionArgs);
        } catch (RemoteException e) {
            if (LogDebug.LOG) {
                Log.d(TAG, e.toString());
            }
        }
    }
    if (LogDebug.LOG) {
        Log.d(TAG, String.format("call update %s", uri.toString()));
    }
    return -1;
}
项目:AOSP-Kayboard-7.1.2    文件:BinaryDictionaryFileDumper.java   
/**
 * Queries a content provider for word list data for some locale and stage the returned files
 *
 * This will query a content provider for word list data for a given locale, and copy the
 * files locally so that they can be mmap'ed. This may overwrite previously cached word lists
 * with newer versions if a newer version is made available by the content provider.
 * @throw FileNotFoundException if the provider returns non-existent data.
 * @throw IOException if the provider-returned data could not be read.
 */
public static void installDictToStagingFromContentProvider(final Locale locale,
        final Context context, final boolean hasDefaultWordList) {
    final ContentProviderClient providerClient;
    try {
        providerClient = context.getContentResolver().
            acquireContentProviderClient(getProviderUriBuilder("").build());
    } catch (final SecurityException e) {
        Log.e(TAG, "No permission to communicate with the dictionary provider", e);
        return;
    }
    if (null == providerClient) {
        Log.e(TAG, "Can't establish communication with the dictionary provider");
        return;
    }
    try {
        final List<WordListInfo> idList = getWordListWordListInfos(locale, context,
                hasDefaultWordList);
        for (WordListInfo id : idList) {
            installWordListToStaging(id.mId, id.mLocale, id.mRawChecksum, providerClient,
                    context);
        }
    } finally {
        providerClient.release();
    }
}
项目:FBEventSync    文件:SyncContext.java   
public SyncContext(Context context, Account account, String accessToken,
                   ContentProviderClient providerClient, SyncResult syncResult, Logger logger) {
    mContext = context;
    mAccount = account;
    mAccessToken = accessToken;
    mProviderClient = providerClient;
    mSyncResult = syncResult;
    mLogger = logger;
}
项目:simple-share-android    文件:ContentProviderClientCompat.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
   public static Bundle call(ContentResolver resolver, ContentProviderClient client, Uri uri, String method, String arg, Bundle extras) throws Exception{
    if(Utils.hasJellyBeanMR1()){
        return client.call(method, arg, extras);
    }
    else{
        return resolver.call(uri, method, arg, extras);
    }
}
项目:airgram    文件:ContactsSyncAdapterService.java   
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    try {
        ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
    } catch (OperationCanceledException e) {
        FileLog.e("tmessages", e);
    }
}
项目:easyfilemanager    文件:DocumentsApplication.java   
public static ContentProviderClient acquireUnstableProviderOrThrow(
        ContentResolver resolver, String authority) throws RemoteException {
    final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient(resolver, authority);
    if (client == null) {
        throw new RemoteException("Failed to acquire provider for " + authority);
    }
    ContentProviderClientCompat.setDetectNotResponding(client, PROVIDER_ANR_TIMEOUT);
    return client;
}
项目:easyfilemanager    文件:DetailFragment.java   
@Override
protected Void doInBackground(Void... params) {
    filePath = doc.path;

    if (!Utils.isDir(doc.mimeType)) {
              final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, doc.mimeType);
        int thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
        Point mThumbSize = new Point(thumbSize, thumbSize);
        final Uri uri = DocumentsContract.buildDocumentUri(doc.authority, doc.documentId);
        final Context context = getActivity();
        final ContentResolver resolver = context.getContentResolver();
        ContentProviderClient client = null;
        try {

            if (doc.mimeType.equals(Document.MIME_TYPE_APK) && !TextUtils.isEmpty(filePath)) {
                result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, filePath, Document.MIME_TYPE_APK)).getBitmap();
            } else {
                client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, uri.getAuthority());
                result = DocumentsContract.getDocumentThumbnail(resolver, uri, mThumbSize, null);
            }
        } catch (Exception e) {
            if (!(e instanceof OperationCanceledException)) {
                Log.w(TAG_DETAIL, "Failed to load thumbnail for " + uri + ": " + e);
            }
            CrashReportingManager.logException(e);
        } finally {
            ContentProviderClientCompat.releaseQuietly(client);
        }

        sizeString = Formatter.formatFileSize(context, doc.size);
    }
    else{
        if(!TextUtils.isEmpty(filePath)){
            File dir = new File(filePath);
            sizeString = Formatter.formatFileSize(getActivity(), Utils.getDirectorySize(dir));
        }               
    }

    return null;
}
项目:easyfilemanager    文件:DirectoryFragment.java   
@Override
protected Bitmap doInBackground(Uri... params) {
    if (isCancelled())
        return null;

    final Context context = mIconThumb.getContext();
    final ContentResolver resolver = context.getContentResolver();

    ContentProviderClient client = null;
    Bitmap result = null;
    try {
        if (Utils.isAPK(mMimeType)) {
            result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, mPath, Document.MIME_TYPE_APK)).getBitmap();
        } else {
            client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority());
            result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal);
        }
        if (null == result){
            result = ImageUtils.getThumbnail(mPath, mMimeType, mThumbSize.x, mThumbSize.y);
        }
        if (result != null) {
            final ThumbnailCache thumbs = DocumentsApplication.getThumbnailsCache(context, mThumbSize);
            thumbs.put(mUri, result);
        }
    } catch (Exception e) {
        if (!(e instanceof OperationCanceledException)) {
            Log.w(TAG, "Failed to load thumbnail for " + mUri + ": " + e);
        }
        CrashReportingManager.logException(e);
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
    return result;
}
项目:easyfilemanager    文件:DirectoryFragment.java   
private synchronized ContentProviderClient getExternalStorageClient() {
    if (mExternalStorageClient == null) {
        mExternalStorageClient = getActivity().
                getContentResolver().acquireContentProviderClient(ExternalStorageProvider.AUTHORITY);
    }
    return mExternalStorageClient;
}
项目:easyfilemanager    文件:DocumentsContract.java   
/**
 * Create a new document with given MIME type and display name.
 *
 * @param parentDocumentUri directory with
 *            {@link DocumentsContract.Document#FLAG_DIR_SUPPORTS_CREATE}
 * @param mimeType MIME type of new document
 * @param displayName name of new document
 * @return newly created document, or {@code null} if failed
 */
public static Uri createDocument(ContentResolver resolver, Uri parentDocumentUri,
                                 String mimeType, String displayName) {
    final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
            parentDocumentUri.getAuthority());
    try {
        return createDocument(client, parentDocumentUri, mimeType, displayName);
    } catch (Exception e) {
        Log.w(TAG, "Failed to create document", e);
        return null;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:simple-share-android    文件:DocumentsContract.java   
public static Uri moveDocument(ContentProviderClient client, Uri sourceDocumentUri,
        Uri sourceParentDocumentUri, Uri targetParentDocumentUri) throws RemoteException {
    final Bundle in = new Bundle();
    in.putParcelable(DocumentsContract.EXTRA_URI, sourceDocumentUri);
    in.putParcelable(DocumentsContract.EXTRA_PARENT_URI, sourceParentDocumentUri);
    in.putParcelable(DocumentsContract.EXTRA_TARGET_URI, targetParentDocumentUri);

    final Bundle out = client.call(METHOD_MOVE_DOCUMENT, null, in);
    return out.getParcelable(DocumentsContract.EXTRA_URI);
}
项目:easyfilemanager    文件:DocumentsContract.java   
/**
 * Delete the given document.
 *
 * @param documentUri document with {@link Document#FLAG_SUPPORTS_DELETE}
 * @return if the document was deleted successfully.
 */
public static boolean deleteDocument(ContentResolver resolver, Uri documentUri) {
    final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
            documentUri.getAuthority());
    try {
        deleteDocument(client, documentUri);
        return true;
    } catch (Exception e) {
        Log.w(TAG, "Failed to delete document", e);
        return false;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:easyfilemanager    文件:DocumentsContract.java   
public static void deleteDocument(ContentProviderClient client, Uri documentUri)
        throws RemoteException {
    final Bundle in = new Bundle();
    in.putParcelable(DocumentsContract.EXTRA_URI, documentUri);

    client.call(METHOD_DELETE_DOCUMENT, null, in);
}
项目:easyfilemanager    文件:DocumentsContract.java   
/**
 * Copies the given document.
 *
 * @param sourceDocumentUri document with {@link DocumentsContract.Document#FLAG_SUPPORTS_COPY}
 * @param targetParentDocumentUri document which will become a parent of the source
 *         document's copy.
 * @return the copied document, or {@code null} if failed.
 */
public static Uri copyDocument(ContentResolver resolver, Uri sourceDocumentUri,
                               Uri targetParentDocumentUri) {
    final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
            sourceDocumentUri.getAuthority());
    try {
        return copyDocument(client, sourceDocumentUri, targetParentDocumentUri);
    } catch (Exception e) {
        Log.w(TAG, "Failed to copy document", e);
        return null;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
项目:simple-share-android    文件:DirectoryFragment.java   
private synchronized ContentProviderClient getExternalStorageClient() {
    if (mExternalStorageClient == null) {
        mExternalStorageClient = getActivity().
                getContentResolver().acquireContentProviderClient(ExternalStorageProvider.AUTHORITY);
    }
    return mExternalStorageClient;
}