Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9bb98f31 authored by Steve McKay's avatar Steve McKay
Browse files

Send APKs through safe install path.

Basically push them through downloads.ui TrampolineActivity
    to get origin url and referer and other security bits
    added before handing off to package manager.

Bug: 24676446
Change-Id: Id40787ada6ace424c4e5e4bfeedc0a8005b7a734
parent 9eb7190a
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -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();

+7 −0
Original line number Diff line number Diff line
@@ -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);
    }
}