Commit 6f648668 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Launch files app when user choose to open a downloaded zip file

Chrome cannot open zip files. As a result, directing users to the
download Home won't help.
This CL will check if Files app are present on the device, and then
open the files app if no other apps register as the default handler
for zip file.

BUG=1050632

Change-Id: I052012113c2d38d52c37088839d75af5b206443d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2052570Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741145}
parent 71358f40
...@@ -9,6 +9,8 @@ import android.app.DownloadManager; ...@@ -9,6 +9,8 @@ import android.app.DownloadManager;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
...@@ -112,6 +114,8 @@ public class DownloadUtils { ...@@ -112,6 +114,8 @@ public class DownloadUtils {
private static final String EXTRA_IS_OFF_THE_RECORD = private static final String EXTRA_IS_OFF_THE_RECORD =
"org.chromium.chrome.browser.download.IS_OFF_THE_RECORD"; "org.chromium.chrome.browser.download.IS_OFF_THE_RECORD";
private static final String MIME_TYPE_ZIP = "application/zip";
private static final String DOCUMENTS_UI_PACKAGE_NAME = "com.android.documentsui";
public static final String EXTRA_SHOW_PREFETCHED_CONTENT = public static final String EXTRA_SHOW_PREFETCHED_CONTENT =
"org.chromium.chrome.browser.download.SHOW_PREFETCHED_CONTENT"; "org.chromium.chrome.browser.download.SHOW_PREFETCHED_CONTENT";
...@@ -452,14 +456,32 @@ public class DownloadUtils { ...@@ -452,14 +456,32 @@ public class DownloadUtils {
service.updateLastAccessTime(downloadGuid, isOffTheRecord); service.updateLastAccessTime(downloadGuid, isOffTheRecord);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
// Can't launch the Intent. Log.e(TAG, "Cannot start activity to open file", e);
if (source != DownloadOpenSource.DOWNLOAD_PROGRESS_INFO_BAR) { }
Toast.makeText(context, context.getString(R.string.download_cant_open_file),
Toast.LENGTH_SHORT) // If this is a zip file, check if Android Files app exists.
.show(); if (MIME_TYPE_ZIP.equals(mimeType)) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(
DOCUMENTS_UI_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
if (packageInfo != null) {
Intent viewDownloadsIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
viewDownloadsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
viewDownloadsIntent.setPackage(DOCUMENTS_UI_PACKAGE_NAME);
context.startActivity(viewDownloadsIntent);
return true;
}
} catch (Exception e) {
Log.e(TAG, "Cannot find files app for openning zip files", e);
} }
return false;
} }
// Can't launch the Intent.
if (source != DownloadOpenSource.DOWNLOAD_PROGRESS_INFO_BAR) {
Toast.makeText(context, context.getString(R.string.download_cant_open_file),
Toast.LENGTH_SHORT)
.show();
}
return false;
} }
@CalledByNative @CalledByNative
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment