org.chromium.base.ContentUriUtils Java Examples

The following examples show how to use org.chromium.base.ContentUriUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChromeBrowserInitializer.java    From delion with Apache License 2.0 6 votes vote down vote up
private void onFinishNativeInitialization() {
    if (mNativeInitializationComplete) return;

    mNativeInitializationComplete = true;
    ContentUriUtils.setFileProviderUtil(new FileProviderHelper());

    if (TextUtils.equals("true", VariationsAssociatedData.getVariationParamValue(
            MinidumpDirectoryObserver.MINIDUMP_EXPERIMENT_NAME, "Enabled"))) {

        // Start the file observer to watch the minidump directory.
        new AsyncTask<Void, Void, MinidumpDirectoryObserver>() {
            @Override
            protected MinidumpDirectoryObserver doInBackground(Void... params) {
                return new MinidumpDirectoryObserver();
            }

            @Override
            protected void onPostExecute(MinidumpDirectoryObserver minidumpDirectoryObserver) {
                mMinidumpDirectoryObserver = minidumpDirectoryObserver;
                mMinidumpDirectoryObserver.startWatching();
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
 
Example #2
Source File: ChromeBrowserInitializer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void onFinishNativeInitialization() {
    if (mNativeInitializationComplete) return;

    mNativeInitializationComplete = true;
    ContentUriUtils.setFileProviderUtil(new FileProviderHelper());

    // Start the file observer to watch the minidump directory.
    new AsyncTask<Void, Void, MinidumpDirectoryObserver>() {
        @Override
        protected MinidumpDirectoryObserver doInBackground(Void... params) {
            return new MinidumpDirectoryObserver();
        }

        @Override
        protected void onPostExecute(MinidumpDirectoryObserver minidumpDirectoryObserver) {
            mMinidumpDirectoryObserver = minidumpDirectoryObserver;
            mMinidumpDirectoryObserver.startWatching();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example #3
Source File: DownloadUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a URI that points at the file.
 * @param file File to get a URI for.
 * @return URI that points at that file, either as a content:// URI or a file:// URI.
 */
public static Uri getUriForItem(File file) {
    Uri uri = null;

    // #getContentUriFromFile causes a disk read when it calls into FileProvider#getUriForFile.
    // Obtaining a content URI is on the critical path for creating a share intent after the
    // user taps on the share button, so even if we were to run this method on a background
    // thread we would have to wait. As it depends on user-selected items, we cannot
    // know/preload which URIs we need until the user presses share.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        // Try to obtain a content:// URI, which is preferred to a file:// URI so that
        // receiving apps don't attempt to determine the file's mime type (which often fails).
        uri = ContentUriUtils.getContentUriFromFile(ContextUtils.getApplicationContext(), file);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Could not create content uri: " + e);
    }
    StrictMode.setThreadPolicy(oldPolicy);

    if (uri == null) uri = Uri.fromFile(file);

    return uri;
}
 
Example #4
Source File: ChromeBrowserInitializer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void onFinishNativeInitialization() {
    if (mNativeInitializationComplete) return;

    mNativeInitializationComplete = true;
    ContentUriUtils.setFileProviderUtil(new FileProviderHelper());

    // When a minidump is detected, extract and append a logcat to it, then upload it to the
    // crash server. Note that the logcat extraction might fail. This is ok; in that case, the
    // minidump will be found and uploaded upon the next browser launch.
    CrashDumpManager.registerUploadCallback(new CrashDumpManager.UploadMinidumpCallback() {
        @Override
        public void tryToUploadMinidump(File minidump) {
            AsyncTask.THREAD_POOL_EXECUTOR.execute(new LogcatExtractionRunnable(minidump));
        }
    });
}
 
Example #5
Source File: SelectFileDialog.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected String[] doInBackground(Uri...uris) {
    mFilePaths = new String[uris.length];
    String[] displayNames = new String[uris.length];
    try {
        for (int i = 0; i < uris.length; i++) {
            mFilePaths[i] = uris[i].toString();
            displayNames[i] = ContentUriUtils.getDisplayName(
                    uris[i], mContext, MediaStore.MediaColumns.DISPLAY_NAME);
        }
    }  catch (SecurityException e) {
        // Some third party apps will present themselves as being able
        // to handle the ACTION_GET_CONTENT intent but then declare themselves
        // as exported=false (or more often omit the exported keyword in
        // the manifest which defaults to false after JB).
        // In those cases trying to access the contents raises a security exception
        // which we should not crash on. See crbug.com/382367 for details.
        Log.w(TAG, "Unable to extract results from the content provider");
        return null;
    }

    return displayNames;
}