use of android.support.annotation.VisibleForTesting in project android_frameworks_base by crdroidandroid.
the class StubProvider method clearCacheAndBuildRoots.
@VisibleForTesting
public void clearCacheAndBuildRoots() {
Log.d(TAG, "Resetting storage.");
removeChildrenRecursively(getContext().getCacheDir());
mStorage.clear();
mSimulateReadErrorIds.clear();
mPrefs = getContext().getSharedPreferences("com.android.documentsui.stubprovider.preferences", Context.MODE_PRIVATE);
Collection<String> rootIds = mPrefs.getStringSet("roots", null);
if (rootIds == null) {
rootIds = Arrays.asList(new String[] { ROOT_0_ID, ROOT_1_ID });
}
mRoots.clear();
for (String rootId : rootIds) {
// Make a subdir in the cache dir for each root.
final File file = new File(getContext().getCacheDir(), rootId);
if (file.mkdir()) {
Log.i(TAG, "Created new root directory @ " + file.getPath());
}
final RootInfo rootInfo = new RootInfo(file, getSize(rootId));
if (rootId.equals(ROOT_1_ID)) {
rootInfo.setSearchEnabled(false);
}
mStorage.put(rootInfo.document.documentId, rootInfo.document);
mRoots.put(rootId, rootInfo);
}
}
use of android.support.annotation.VisibleForTesting in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
the class FileOperations method cancel.
@VisibleForTesting
public static void cancel(Activity activity, String jobId) {
if (DEBUG)
Log.d(TAG, "Attempting to canceling operation: " + jobId);
Intent intent = new Intent(activity, FileOperationService.class);
intent.putExtra(EXTRA_CANCEL, true);
intent.putExtra(EXTRA_JOB_ID, jobId);
activity.startService(intent);
}
use of android.support.annotation.VisibleForTesting in project android_frameworks_base by crdroidandroid.
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