use of android.support.annotation.VisibleForTesting in project platform_frameworks_base by android.
the class FileOperations method copy.
@VisibleForTesting
public static String copy(Activity activity, List<DocumentInfo> srcDocs, DocumentStack destination) {
String jobId = createJobId();
if (DEBUG)
Log.d(TAG, "Initiating 'copy' operation id: " + jobId);
Intent intent = createBaseIntent(OPERATION_COPY, activity, jobId, srcDocs, destination);
createSharedSnackBar(activity, R.plurals.copy_begin, srcDocs.size()).show();
activity.startService(intent);
return jobId;
}
use of android.support.annotation.VisibleForTesting in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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 android-priority-jobqueue by yigit.
the class FrameworkScheduler method createId.
/**
* Creates a new ID for the job info. Can be overridden if you need to provide different ids not
* to conflict with the rest of your application.
*
* @return A unique integer id for the next Job request to be sent to system scheduler
*/
@SuppressLint("CommitPrefEdits")
@VisibleForTesting
int createId() {
synchronized (FrameworkScheduler.class) {
final SharedPreferences preferences = getPreferences(getApplicationContext());
final int id = preferences.getInt(KEY_ID, 0) + 1;
preferences.edit().putInt(KEY_ID, id).commit();
return id;
}
}
use of android.support.annotation.VisibleForTesting in project android-priority-jobqueue by yigit.
the class CallbackManager method waitUntilAllMessagesAreConsumed.
/**
* convenience method to wait for existing callbacks to be consumed
*/
@VisibleForTesting
public boolean waitUntilAllMessagesAreConsumed(int seconds) {
final CountDownLatch latch = new CountDownLatch(1);
CommandMessage poke = factory.obtain(CommandMessage.class);
poke.set(CommandMessage.RUNNABLE);
poke.setRunnable(new Runnable() {
@Override
public void run() {
latch.countDown();
}
});
messageQueue.post(poke);
try {
return latch.await(seconds, TimeUnit.SECONDS);
} catch (InterruptedException e) {
return false;
}
}
Aggregations