Merge "Send APKs through safe install path." into nyc-dev

This commit is contained in:
Steve McKay
2016-03-07 23:43:53 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 1 deletions

View File

@ -282,6 +282,24 @@ public class FilesActivity extends BaseActivity {
* Launches an intent to view the specified document.
*/
private void openDocument(DocumentInfo doc, Model model) {
// Provide specialized handling of downloaded APKs This sends the APK
// details off to get extra security information added, and finally
// to be handled by the package manager.
if (MimePredicate.isApkType(doc.mimeType)) {
// First try managing the document; we expect manager to filter
// based on authority, so we don't grant.
final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT);
manage.setData(doc.derivedUri);
try {
startActivity(manage);
return;
} catch (ActivityNotFoundException ex) {
// fall back to regular handling below.
}
}
Intent intent = new QuickViewIntentBuilder(
getPackageManager(), getResources(), doc, model).build();
@ -296,7 +314,7 @@ public class FilesActivity extends BaseActivity {
}
}
// Fallback to traditional VIEW action...
// Fall back to traditional VIEW action...
intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setData(doc.derivedUri);

View File

@ -16,12 +16,15 @@
package com.android.documentsui;
import android.annotation.Nullable;
import com.android.documentsui.model.DocumentInfo;
import com.android.internal.util.Predicate;
public class MimePredicate implements Predicate<DocumentInfo> {
private final String[] mFilters;
private static final String APK_TYPE = "application/vnd.android.package-archive";
/**
* MIME types that are visual in nature. For example, they should always be
* shown as thumbnails in list mode.
@ -92,4 +95,8 @@ public class MimePredicate implements Predicate<DocumentInfo> {
return false;
}
}
public static boolean isApkType(@Nullable String mimeType) {
return APK_TYPE.equals(mimeType);
}
}