Java 类android.os.OperationCanceledException 实例源码

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

    Long result = null;
    try {
        if (!TextUtils.isEmpty(mPath)) {
            File dir = new File(mPath);
            result = Utils.getDirectorySize(dir);
        }
    } catch (Exception e) {
        if (!(e instanceof OperationCanceledException)) {
            Log.w(TAG, "Failed to calculate size for " + mPath + ": " + e);
        }
        CrashReportingManager.logException(e);
    }
    return result;
}
项目:easyfilemanager    文件:UriDerivativeLoader.java   
@Override
public final R loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled2()) {
            throw new OperationCanceledException();
        }
        mCancellationSignal = new CancellationSignal();
    }
    try {
        return loadInBackground(mParam, mCancellationSignal);
    } finally {
        synchronized (this) {
            mCancellationSignal = null;
        }
    }
}
项目: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);
    }
}
项目:easyfilemanager    文件:AsyncTaskLoader.java   
@Override
protected D doInBackground(Void... params) {
    if (DEBUG) Log.v(TAG, this + " >>> doInBackground");
    try {
        D data = AsyncTaskLoader.this.onLoadInBackground();
        if (DEBUG) Log.v(TAG, this + "  <<< doInBackground");
        return data;
    } catch (OperationCanceledException ex) {
        if (!isCancelled()) {
            // onLoadInBackground threw a canceled exception spuriously.
            // This is problematic because it means that the LoaderManager did not
            // cancel the Loader itself and still expects to receive a result.
            // Additionally, the Loader's own state will not have been updated to
            // reflect the fact that the task was being canceled.
            // So we treat this case as an unhandled exception.
            throw ex;
        }
        if (DEBUG) Log.v(TAG, this + "  <<< doInBackground (was canceled)", ex);
        return null;
    }
}
项目:YuiHatano    文件:ShadowDatabaseUtils.java   
private static final void readExceptionFromParcel(Parcel reply, String msg, int code) {
    switch (code) {
        case 2:
            throw new IllegalArgumentException(msg);
        case 3:
            throw new UnsupportedOperationException(msg);
        case 4:
            throw new SQLiteAbortException(msg);
        case 5:
            throw new SQLiteConstraintException(msg);
        case 6:
            throw new SQLiteDatabaseCorruptException(msg);
        case 7:
            throw new SQLiteFullException(msg);
        case 8:
            throw new SQLiteDiskIOException(msg);
        case 9:
            throw new SQLiteException(msg);
        case 11:
            throw new OperationCanceledException(msg);
        default:
            reply.readException(code, msg);
    }
}
项目:FireFiles    文件:DirectoryFragment.java   
@Override
protected Long doInBackground(Uri... params) {
    if (isCancelled())
        return null;

    Long result = null;
    try {
        if (!TextUtils.isEmpty(mPath)) {
            File dir = new File(mPath);
            result = Utils.getDirectorySize(dir);
        }
    } catch (Exception e) {
        if (!(e instanceof OperationCanceledException)) {
            Log.w(TAG, "Failed to calculate size for " + mPath + ": " + e);
        }
        CrashReportingManager.logException(e);
    }
    return result;
}
项目:FireFiles    文件:UriDerivativeLoader.java   
@Override
public final R loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled2()) {
            throw new OperationCanceledException();
        }
        mCancellationSignal = new CancellationSignal();
    }
    try {
        return loadInBackground(mParam, mCancellationSignal);
    } finally {
        synchronized (this) {
            mCancellationSignal = null;
        }
    }
}
项目:FireFiles    文件: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);
    }
}
项目:FireFiles    文件:AsyncTaskLoader.java   
@Override
protected D doInBackground(Void... params) {
    if (DEBUG) Log.v(TAG, this + " >>> doInBackground");
    try {
        D data = AsyncTaskLoader.this.onLoadInBackground();
        if (DEBUG) Log.v(TAG, this + "  <<< doInBackground");
        return data;
    } catch (OperationCanceledException ex) {
        if (!isCancelled()) {
            // onLoadInBackground threw a canceled exception spuriously.
            // This is problematic because it means that the LoaderManager did not
            // cancel the Loader itself and still expects to receive a result.
            // Additionally, the Loader's own state will not have been updated to
            // reflect the fact that the task was being canceled.
            // So we treat this case as an unhandled exception.
            throw ex;
        }
        if (DEBUG) Log.v(TAG, this + "  <<< doInBackground (was canceled)", ex);
        return null;
    }
}
项目:simple-share-android    文件:DirectoryFragment.java   
@Override
protected Long doInBackground(Uri... params) {
    if (isCancelled())
        return null;

    Long result = null;
    try {
        if (!TextUtils.isEmpty(mPath)) {
            File dir = new File(mPath);
            result = Utils.getDirectorySize(dir);
        }
    } catch (Exception e) {
        if (!(e instanceof OperationCanceledException)) {
            Log.w(TAG, "Failed to calculate size for " + mPath + ": " + e);
        }
        CrashReportingManager.logException(e);
    }
    return result;
}
项目:simple-share-android    文件:UriDerivativeLoader.java   
@Override
public final R loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled2()) {
            throw new OperationCanceledException();
        }
        mCancellationSignal = new CancellationSignal();
    }
    try {
        return loadInBackground(mParam, mCancellationSignal);
    } finally {
        synchronized (this) {
            mCancellationSignal = null;
        }
    }
}
项目: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);
    }
}
项目:simple-share-android    文件:AsyncTaskLoader.java   
@Override
protected D doInBackground(Void... params) {
    if (DEBUG) Log.v(TAG, this + " >>> doInBackground");
    try {
        D data = AsyncTaskLoader.this.onLoadInBackground();
        if (DEBUG) Log.v(TAG, this + "  <<< doInBackground");
        return data;
    } catch (OperationCanceledException ex) {
        if (!isCancelled()) {
            // onLoadInBackground threw a canceled exception spuriously.
            // This is problematic because it means that the LoaderManager did not
            // cancel the Loader itself and still expects to receive a result.
            // Additionally, the Loader's own state will not have been updated to
            // reflect the fact that the task was being canceled.
            // So we treat this case as an unhandled exception.
            throw ex;
        }
        if (DEBUG) Log.v(TAG, this + "  <<< doInBackground (was canceled)", ex);
        return null;
    }
}
项目:KBUnitTest    文件:ShadowDatabaseUtils.java   
private static final void readExceptionFromParcel(Parcel reply, String msg, int code) {
    switch (code) {
        case 2:
            throw new IllegalArgumentException(msg);
        case 3:
            throw new UnsupportedOperationException(msg);
        case 4:
            throw new SQLiteAbortException(msg);
        case 5:
            throw new SQLiteConstraintException(msg);
        case 6:
            throw new SQLiteDatabaseCorruptException(msg);
        case 7:
            throw new SQLiteFullException(msg);
        case 8:
            throw new SQLiteDiskIOException(msg);
        case 9:
            throw new SQLiteException(msg);
        case 11:
            throw new OperationCanceledException(msg);
        default:
            reply.readException(code, msg);
    }
}
项目:forsuredbandroid    文件:FSCursorLoader.java   
@Override
public FSCursor loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled()) {
            throw new OperationCanceledException();
        }
        mCancellationSignal = new CancellationSignal();
    }

    FSCursor cursor = (FSCursor) resolver.preserveQueryStateAndGet();
    if (cursor != null) {
        try {
            cursor.getCount();  // TODO: determine whether you need to make this call
        } catch (RuntimeException ex) {
            cursor.close();
            throw ex;
        }
    }
    return cursor;
}
项目:FullRobolectricTestSample    文件:SQLiteDatabaseTest.java   
@Test
public void testRawQueryWithFactoryAndCancellationSignal() throws Exception {
    CancellationSignal signal = new CancellationSignal();

    Cursor cursor = database.rawQueryWithFactory(null, "select * from table_name", null, null, signal);
    assertThat(cursor).isNotNull();
    assertThat(cursor.getColumnCount()).isEqualTo(5);
    assertThat(cursor.isClosed()).isFalse();

    signal.cancel();

    try {
        cursor.moveToNext();
        fail("did not get cancellation signal");
    } catch (OperationCanceledException e) {
        // expected
    }
}
项目: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    文件:IconHelper.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 {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority());
        result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal);

        if (null == result){
            result = ImageUtils.getThumbnail(mPath, mimeType, 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;
}
项目:YuiHatano    文件:ShadowDatabaseUtils.java   
/**
 * Special function for writing an exception result at the header of
 * a parcel, to be used when returning an exception from a transaction.
 * exception will be re-thrown by the function in another process
 *
 * @param reply Parcel to write to
 * @param e     The Exception to be written.
 * @see Parcel#writeNoException
 * @see Parcel#writeException
 */
public static final void writeExceptionToParcel(Parcel reply, Exception e) {
    int     code         = 0;
    boolean logException = true;
    if (e instanceof FileNotFoundException) {
        code = 1;
        logException = false;
    } else if (e instanceof IllegalArgumentException) {
        code = 2;
    } else if (e instanceof UnsupportedOperationException) {
        code = 3;
    } else if (e instanceof SQLiteAbortException) {
        code = 4;
    } else if (e instanceof SQLiteConstraintException) {
        code = 5;
    } else if (e instanceof SQLiteDatabaseCorruptException) {
        code = 6;
    } else if (e instanceof SQLiteFullException) {
        code = 7;
    } else if (e instanceof SQLiteDiskIOException) {
        code = 8;
    } else if (e instanceof SQLiteException) {
        code = 9;
    } else if (e instanceof OperationApplicationException) {
        code = 10;
    } else if (e instanceof OperationCanceledException) {
        code = 11;
        logException = false;
    } else {
        reply.writeException(e);
        Log.e(TAG, "Writing exception to parcel", e);
        return;
    }
    reply.writeInt(code);
    reply.writeString(e.getMessage());

    if (logException) {
        Log.e(TAG, "Writing exception to parcel", e);
    }
}
项目:FireFiles    文件: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;
}
项目:FireFiles    文件: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;
}
项目:FireFiles    文件:IconHelper.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 {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority());
        result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal);

        if (null == result){
            result = ImageUtils.getThumbnail(mPath, mimeType, 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;
}
项目:simple-share-android    文件: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;
}
项目:simple-share-android    文件: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;
}
项目:simple-share-android    文件:IconHelper.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 {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, mUri.getAuthority());
        result = DocumentsContract.getDocumentThumbnail(resolver, mUri, mThumbSize, mSignal);

        if (null == result){
            result = ImageUtils.getThumbnail(mPath, mimeType, 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;
}
项目:KBUnitTest    文件:ShadowDatabaseUtils.java   
/**
 * Special function for writing an exception result at the header of
 * a parcel, to be used when returning an exception from a transaction.
 * exception will be re-thrown by the function in another process
 *
 * @param reply Parcel to write to
 * @param e     The Exception to be written.
 * @see Parcel#writeNoException
 * @see Parcel#writeException
 */
public static final void writeExceptionToParcel(Parcel reply, Exception e) {
    int     code         = 0;
    boolean logException = true;
    if (e instanceof FileNotFoundException) {
        code = 1;
        logException = false;
    } else if (e instanceof IllegalArgumentException) {
        code = 2;
    } else if (e instanceof UnsupportedOperationException) {
        code = 3;
    } else if (e instanceof SQLiteAbortException) {
        code = 4;
    } else if (e instanceof SQLiteConstraintException) {
        code = 5;
    } else if (e instanceof SQLiteDatabaseCorruptException) {
        code = 6;
    } else if (e instanceof SQLiteFullException) {
        code = 7;
    } else if (e instanceof SQLiteDiskIOException) {
        code = 8;
    } else if (e instanceof SQLiteException) {
        code = 9;
    } else if (e instanceof OperationApplicationException) {
        code = 10;
    } else if (e instanceof OperationCanceledException) {
        code = 11;
        logException = false;
    } else {
        reply.writeException(e);
        Log.e(TAG, "Writing exception to parcel", e);
        return;
    }
    reply.writeInt(code);
    reply.writeString(e.getMessage());

    if (logException) {
        Log.e(TAG, "Writing exception to parcel", e);
    }
}
项目:android_database    文件:BaseCursorDataLoader.java   
/**
 */
@Override
public D loadInBackground() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        synchronized (this) {
            if (isLoadInBackgroundCanceled()) {
                throw new OperationCanceledException();
            }
            this.mCancellationSignal = new CancellationSignal();
        }
    }
    try {
        final Cursor cursor = query();
        if (cursor != null) {
            try {
                // Ensure that the cursor window is filled.
                cursor.getCount();
                cursor.registerContentObserver(mObserver);
            } catch (RuntimeException e) {
                cursor.close();
                throw e;
            }
        }
        return cursor == null ? onLoadFailed() : onLoadFinished(cursor);
    } finally {
        synchronized (this) {
            this.mCancellationSignal = null;
        }
    }
}
项目:sprockets-android    文件:CursorWrapperLoader.java   
@Override
public D loadInBackground() {
    synchronized (this) {
        if (isLoadInBackgroundCanceled()) {
            throw new OperationCanceledException();
        }
        mCancellationSignal = new CancellationSignal();
    }
    try {
        Cursor cursor = getContext().getContentResolver()
                .query(mUri, mProjection, mSelection, mSelectionArgs, mSortOrder,
                        mCancellationSignal);
        if (cursor != null) {
            try {
                // Ensure the cursor window is filled.
                cursor.getCount();
                cursor.registerContentObserver(mObserver);
            } catch (RuntimeException ex) {
                cursor.close();
                throw ex;
            }
            return wrap(cursor);
        }
        return null;
    } finally {
        synchronized (this) {
            mCancellationSignal = null;
        }
    }
}
项目:android-oauth-client    文件:OAuthManagerTest.java   
@Test(expected = RuntimeException.class)
public void testTaskExecutionThatThrowsException() throws OperationCanceledException,
        IOException {
    OAuthFuture<String> future = mock.runTest(new Runnable() {
        @Override
        public void run() {
            throw new RuntimeException();
        }
    }, null, null);
    future.getResult();
}
项目:android-oauth-client    文件:OAuthManagerTest.java   
@Test
public void testCallback() throws InterruptedException, OperationCanceledException, IOException {
    MockOAuthCallback mockCallback = new MockOAuthCallback();
    mock.runTest(null, mockCallback, null);
    latch.await(10, TimeUnit.SECONDS);
    assertEquals("ok", mockCallback.getResult());
}
项目:boohee_v5.6    文件:ContentResolverCompatJellybean.java   
static boolean isFrameworkOperationCanceledException(Exception e) {
    return e instanceof OperationCanceledException;
}
项目:permissionsModule    文件:ContentResolverCompatJellybean.java   
static boolean isFrameworkOperationCanceledException(Exception e) {
    return e instanceof OperationCanceledException;
}
项目:MyCTFWriteUps    文件:ContentResolverCompatJellybean.java   
static boolean isFrameworkOperationCanceledException(Exception exception)
{
    return exception instanceof OperationCanceledException;
}
项目:android-observable-list    文件:OperationCanceledExceptionCompat.java   
@Override
public RuntimeException create() {
    return new OperationCanceledException();
}
项目:android-oauth-client    文件:OAuthManagerTest.java   
@Test
public void testNormalTaskExecution() throws OperationCanceledException, IOException {
    OAuthFuture<String> future = mock.runTest(null, null, null);
    String result = future.getResult();
    assertEquals("ok", result);
}
项目:android-oauth-client    文件:OAuthManagerTest.java   
public String getResult() throws OperationCanceledException, IOException {
    return future.getResult();
}