Search in sources :

Example 41 with VisibleForTesting

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

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

Example 42 with VisibleForTesting

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

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 43 with VisibleForTesting

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

the class StubProvider method createRegularFile.

@VisibleForTesting
public Uri createRegularFile(String rootId, String path, String mimeType, 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.createRegularDocument(file, mimeType, 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 44 with VisibleForTesting

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

the class RootsCache method getMatchingRoots.

@VisibleForTesting
static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
    final List<RootInfo> matching = new ArrayList<>();
    for (RootInfo root : roots) {
        if (DEBUG)
            Log.d(TAG, "Evaluating " + root);
        if (state.action == State.ACTION_CREATE && !root.supportsCreate()) {
            if (DEBUG)
                Log.d(TAG, "Excluding read-only root because: ACTION_CREATE.");
            continue;
        }
        if (state.action == State.ACTION_PICK_COPY_DESTINATION && !root.supportsCreate()) {
            if (DEBUG)
                Log.d(TAG, "Excluding read-only root because: ACTION_PICK_COPY_DESTINATION.");
            continue;
        }
        if (state.action == State.ACTION_OPEN_TREE && !root.supportsChildren()) {
            if (DEBUG)
                Log.d(TAG, "Excluding root !supportsChildren because: ACTION_OPEN_TREE.");
            continue;
        }
        if (!state.showAdvanced && root.isAdvanced()) {
            if (DEBUG)
                Log.d(TAG, "Excluding root because: unwanted advanced device.");
            continue;
        }
        if (state.localOnly && !root.isLocalOnly()) {
            if (DEBUG)
                Log.d(TAG, "Excluding root because: unwanted non-local device.");
            continue;
        }
        if (state.directoryCopy && root.isDownloads()) {
            if (DEBUG)
                Log.d(TAG, "Excluding downloads root because: unsupported directory copy.");
            continue;
        }
        if (state.action == State.ACTION_OPEN && root.isEmpty()) {
            if (DEBUG)
                Log.d(TAG, "Excluding empty root because: ACTION_OPEN.");
            continue;
        }
        if (state.action == State.ACTION_GET_CONTENT && root.isEmpty()) {
            if (DEBUG)
                Log.d(TAG, "Excluding empty root because: ACTION_GET_CONTENT.");
            continue;
        }
        final boolean overlap = MimePredicate.mimeMatches(root.derivedMimeTypes, state.acceptMimes) || MimePredicate.mimeMatches(state.acceptMimes, root.derivedMimeTypes);
        if (!overlap) {
            if (DEBUG)
                Log.d(TAG, "Excluding root because: unsupported content types > " + state.acceptMimes);
            continue;
        }
        if (state.excludedAuthorities.contains(root.authority)) {
            if (DEBUG)
                Log.d(TAG, "Excluding root because: owned by calling package.");
            continue;
        }
        if (DEBUG)
            Log.d(TAG, "Including " + root);
        matching.add(root);
    }
    return matching;
}
Also used : RootInfo(com.android.documentsui.model.RootInfo) ArrayList(java.util.ArrayList) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 45 with VisibleForTesting

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

the class HashUtils method sha256.

@NonNull
@VisibleForTesting
static String sha256(@NonNull String data, String charsetName) {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        digest.update(data.getBytes(charsetName));
        return encodeHex(digest.digest());
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
        /*
             * Never happens as every device has UTF-8 support and SHA-256,
             * but if it ever happens make sure we propagate exception as unchecked.
             */
        throw new RuntimeException(e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) VisibleForTesting(android.support.annotation.VisibleForTesting) NonNull(android.support.annotation.NonNull)

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