Search in sources :

Example 36 with VisibleForTesting

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;
}
Also used : Intent(android.content.Intent) Shared.getQuantityString(com.android.documentsui.Shared.getQuantityString) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 37 with VisibleForTesting

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);
    }
}
Also used : File(java.io.File) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 38 with VisibleForTesting

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;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 39 with VisibleForTesting

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;
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) SuppressLint(android.annotation.SuppressLint) VisibleForTesting(android.support.annotation.VisibleForTesting) SuppressLint(android.annotation.SuppressLint)

Example 40 with VisibleForTesting

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;
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CommandMessage(com.birbit.android.jobqueue.messaging.message.CommandMessage) 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