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);
}
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;
}
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();
}
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;
}
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;
}
Aggregations