Search in sources :

Example 16 with VisibleForTesting

use of android.support.annotation.VisibleForTesting in project android_frameworks_base by DirtyUnicorns.

the class StubProvider method createVirtualFile.

@VisibleForTesting
public Uri createVirtualFile(String rootId, String path, String mimeType, List<String> streamTypes, byte[] content) throws FileNotFoundException, IOException {
    final File file = createFile(rootId, path, mimeType, content);
    final StubDocument parent = mStorage.get(getDocumentIdForFile(file.getParentFile()));
    if (parent == null) {
        throw new FileNotFoundException("Parent not found.");
    }
    final StubDocument document = StubDocument.createVirtualDocument(file, mimeType, streamTypes, parent);
    mStorage.put(document.documentId, document);
    return DocumentsContract.buildDocumentUri(mAuthority, document.documentId);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 17 with VisibleForTesting

use of android.support.annotation.VisibleForTesting in project android_frameworks_base by DirtyUnicorns.

the class StubProvider method getFile.

@VisibleForTesting
public File getFile(String rootId, String path) throws FileNotFoundException {
    StubDocument root = mRoots.get(rootId).document;
    if (root == null) {
        throw new FileNotFoundException("No roots with the ID " + rootId + " were found");
    }
    // Convert the path string into a path that's relative to the root.
    File needle = new File(root.file, path.substring(1));
    StubDocument found = mStorage.get(getDocumentIdForFile(needle));
    if (found == null) {
        return null;
    }
    return found.file;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 18 with VisibleForTesting

use of android.support.annotation.VisibleForTesting in project mobile-center-sdk-android by Microsoft.

the class Crashes method handleUserConfirmation.

@VisibleForTesting
private synchronized void handleUserConfirmation(@UserConfirmationDef final int userConfirmation) {
    if (mChannel == null) {
        MobileCenterLog.error(LOG_TAG, "Crashes service not initialized, discarding calls.");
        return;
    }
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            if (userConfirmation == DONT_SEND) {
                /* Clean up all pending error log and throwable files. */
                for (Iterator<UUID> iterator = mUnprocessedErrorReports.keySet().iterator(); iterator.hasNext(); ) {
                    UUID id = iterator.next();
                    iterator.remove();
                    removeAllStoredErrorLogFiles(id);
                }
            } else {
                if (userConfirmation == ALWAYS_SEND) {
                    StorageHelper.PreferencesStorage.putBoolean(PREF_KEY_ALWAYS_SEND, true);
                }
                Iterator<Map.Entry<UUID, ErrorLogReport>> unprocessedIterator = mUnprocessedErrorReports.entrySet().iterator();
                while (unprocessedIterator.hasNext()) {
                    if (shouldStopProcessingPendingErrors())
                        break;
                    Map.Entry<UUID, ErrorLogReport> unprocessedEntry = unprocessedIterator.next();
                    ErrorLogReport errorLogReport = unprocessedEntry.getValue();
                    mChannel.enqueue(errorLogReport.log, ERROR_GROUP);
                    Iterable<ErrorAttachmentLog> attachments = mCrashesListener.getErrorAttachments(errorLogReport.report);
                    handleErrorAttachmentLogs(attachments, errorLogReport);
                    /* Clean up an error log file and map entry. */
                    unprocessedIterator.remove();
                    ErrorLogHelper.removeStoredErrorLogFile(unprocessedEntry.getKey());
                }
            }
            /* Processed crash report for the last session. */
            if (isInstanceEnabled())
                mHandler.getLooper().quit();
        }
    };
    /* Run on background thread if current thread is UI thread. */
    if (Looper.myLooper() == Looper.getMainLooper())
        mHandler.post(runnable);
    else
        runnable.run();
}
Also used : ErrorAttachmentLog(com.microsoft.azure.mobile.crashes.ingestion.models.ErrorAttachmentLog) UUID(java.util.UUID) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 19 with VisibleForTesting

use of android.support.annotation.VisibleForTesting in project mobile-center-sdk-android by Microsoft.

the class Crashes method buildErrorReport.

@VisibleForTesting
@Nullable
ErrorReport buildErrorReport(ManagedErrorLog log) {
    UUID id = log.getId();
    if (mErrorReportCache.containsKey(id)) {
        return mErrorReportCache.get(id).report;
    } else {
        File file = ErrorLogHelper.getStoredThrowableFile(id);
        if (file != null) {
            try {
                Throwable throwable = StorageHelper.InternalStorage.readObject(file);
                ErrorReport report = ErrorLogHelper.getErrorReportFromErrorLog(log, throwable);
                mErrorReportCache.put(id, new ErrorLogReport(log, report));
                return report;
            } catch (ClassNotFoundException ignored) {
                MobileCenterLog.error(LOG_TAG, "Cannot read throwable file " + file.getName(), ignored);
            } catch (IOException ignored) {
                MobileCenterLog.error(LOG_TAG, "Cannot access serialized throwable file " + file.getName(), ignored);
            }
        }
    }
    return null;
}
Also used : ErrorReport(com.microsoft.azure.mobile.crashes.model.ErrorReport) IOException(java.io.IOException) UUID(java.util.UUID) File(java.io.File) VisibleForTesting(android.support.annotation.VisibleForTesting) Nullable(android.support.annotation.Nullable)

Example 20 with VisibleForTesting

use of android.support.annotation.VisibleForTesting in project android_frameworks_base by AOSPA.

the class StubProvider method getFile.

@VisibleForTesting
public File getFile(String rootId, String path) throws FileNotFoundException {
    StubDocument root = mRoots.get(rootId).document;
    if (root == null) {
        throw new FileNotFoundException("No roots with the ID " + rootId + " were found");
    }
    // Convert the path string into a path that's relative to the root.
    File needle = new File(root.file, path.substring(1));
    StubDocument found = mStorage.get(getDocumentIdForFile(needle));
    if (found == null) {
        return null;
    }
    return found.file;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) VisibleForTesting(android.support.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (android.support.annotation.VisibleForTesting)63 File (java.io.File)24 FileNotFoundException (java.io.FileNotFoundException)15 Intent (android.content.Intent)11 IOException (java.io.IOException)11 MessagingException (com.fsck.k9.mail.MessagingException)8 ArrayList (java.util.ArrayList)8 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)6 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)6 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)6 Shared.getQuantityString (com.android.documentsui.Shared.getQuantityString)5 RootInfo (com.android.documentsui.model.RootInfo)5 LocalFolder (com.fsck.k9.mailstore.LocalFolder)5 LocalStore (com.fsck.k9.mailstore.LocalStore)5 HashMap (java.util.HashMap)5 SuppressLint (android.annotation.SuppressLint)4 LocalMessage (com.fsck.k9.mailstore.LocalMessage)4 Bundle (android.os.Bundle)3 Nullable (android.support.annotation.Nullable)3 Folder (com.fsck.k9.mail.Folder)3