Search in sources :

Example 46 with VisibleForTesting

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

the class Distribute method getLatestReleaseDetails.

/**
     * Get latest release details from server.
     *
     * @param updateToken token to secure API call.
     */
@VisibleForTesting
synchronized void getLatestReleaseDetails(@NonNull String updateToken) {
    MobileCenterLog.debug(LOG_TAG, "Get latest release details...");
    HttpClientRetryer retryer = new HttpClientRetryer(new DefaultHttpClient());
    NetworkStateHelper networkStateHelper = NetworkStateHelper.getSharedInstance(mContext);
    HttpClient httpClient = new HttpClientNetworkStateHandler(retryer, networkStateHelper);
    String url = mApiUrl + String.format(GET_LATEST_RELEASE_PATH_FORMAT, mAppSecret, computeReleaseHash(mPackageInfo));
    Map<String, String> headers = new HashMap<>();
    headers.put(HEADER_API_TOKEN, updateToken);
    final Object releaseCallId = mCheckReleaseCallId = new Object();
    mCheckReleaseApiCall = httpClient.callAsync(url, METHOD_GET, headers, new HttpClient.CallTemplate() {

        @Override
        public String buildRequestBody() throws JSONException {
            /* Only GET is used by Distribute service. This method is never getting called. */
            return null;
        }

        @Override
        public void onBeforeCalling(URL url, Map<String, String> headers) {
            if (MobileCenterLog.getLogLevel() <= VERBOSE) {
                /* Log url. */
                String urlString = url.toString().replaceAll(mAppSecret, HttpUtils.hideSecret(mAppSecret));
                MobileCenterLog.verbose(LOG_TAG, "Calling " + urlString + "...");
                /* Log headers. */
                Map<String, String> logHeaders = new HashMap<>(headers);
                String apiToken = logHeaders.get(HEADER_API_TOKEN);
                if (apiToken != null) {
                    logHeaders.put(HEADER_API_TOKEN, HttpUtils.hideSecret(apiToken));
                }
                MobileCenterLog.verbose(LOG_TAG, "Headers: " + logHeaders);
            }
        }
    }, new ServiceCallback() {

        @Override
        public void onCallSucceeded(final String payload) {
            /* onPostExecute is not always called on UI thread due to an old Android bug. */
            HandlerUtils.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        handleApiCallSuccess(releaseCallId, payload, ReleaseDetails.parse(payload));
                    } catch (JSONException e) {
                        onCallFailed(e);
                    }
                }
            });
        }

        @Override
        public void onCallFailed(Exception e) {
            handleApiCallFailure(releaseCallId, e);
        }
    });
}
Also used : HashMap(java.util.HashMap) JSONException(org.json.JSONException) DefaultHttpClient(com.microsoft.azure.mobile.http.DefaultHttpClient) DEFAULT_API_URL(com.microsoft.azure.mobile.distribute.DistributeConstants.DEFAULT_API_URL) URL(java.net.URL) DEFAULT_INSTALL_URL(com.microsoft.azure.mobile.distribute.DistributeConstants.DEFAULT_INSTALL_URL) JSONException(org.json.JSONException) ActivityNotFoundException(android.content.ActivityNotFoundException) HttpException(com.microsoft.azure.mobile.http.HttpException) ServiceCallback(com.microsoft.azure.mobile.http.ServiceCallback) HttpClientRetryer(com.microsoft.azure.mobile.http.HttpClientRetryer) HttpClient(com.microsoft.azure.mobile.http.HttpClient) DefaultHttpClient(com.microsoft.azure.mobile.http.DefaultHttpClient) NetworkStateHelper(com.microsoft.azure.mobile.utils.NetworkStateHelper) HttpClientNetworkStateHandler(com.microsoft.azure.mobile.http.HttpClientNetworkStateHandler) Map(java.util.Map) HashMap(java.util.HashMap) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 47 with VisibleForTesting

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

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

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

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

Example 49 with VisibleForTesting

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

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

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

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)

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