From 91a1cf1db0b2a6ee72e467c37e7845584354eaf2 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Fri, 14 Jan 2011 16:05:48 -0800 Subject: [PATCH] Remove "view" button for .apk attachments We don't need to allow users to install applications directly from the email client. Instead, application installation is a two step process; the user must first save the APK and then find it on the filesystem. If the user does not want to allow installation of applications from unknown sources, we don't provide the ability to save. NOTE: After saving, we still try to open the APK which generates an error toast. We will be removing the auto-open-after-save feature in a separate CL. bug 3351137 Change-Id: I0eb1bc8224a154792fe852757e4b23a3059f4392 --- src/com/android/email/Email.java | 9 +++++++++ .../email/activity/MessageViewFragmentBase.java | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/com/android/email/Email.java b/src/com/android/email/Email.java index 73d6bd3d7..30f1c24c5 100644 --- a/src/com/android/email/Email.java +++ b/src/com/android/email/Email.java @@ -136,6 +136,15 @@ public class Email extends Application { "zip", "gz", "z", "tar", "tgz", "bz2", }; + /** + * Filename extensions of attachments that can be installed. + * Entries in this list are compared to the end of the lower-cased filename, so they must + * be lower case, and should not include a "." + */ + public static final String[] INSTALLABLE_ATTACHMENT_EXTENSIONS = new String[] { + "apk", + }; + /** * Specifies how many messages will be shown in a folder by default. This number is set * on each new folder and can be incremented with "Load more messages..." by the diff --git a/src/com/android/email/activity/MessageViewFragmentBase.java b/src/com/android/email/activity/MessageViewFragmentBase.java index ca2d62848..301a23f1b 100644 --- a/src/com/android/email/activity/MessageViewFragmentBase.java +++ b/src/com/android/email/activity/MessageViewFragmentBase.java @@ -60,6 +60,7 @@ import android.os.Environment; import android.os.Handler; import android.provider.ContactsContract; import android.provider.ContactsContract.QuickContact; +import android.provider.Settings; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.format.DateUtils; @@ -1172,6 +1173,18 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O attachmentInfo.allowSave = false; } + // Check for installable attachments by filename extension; hide both buttons + extension = AttachmentProvider.getFilenameExtension(attachmentInfo.name); + if (!TextUtils.isEmpty(extension) && + Utility.arrayContains(Email.INSTALLABLE_ATTACHMENT_EXTENSIONS, extension)) { + int sideloadEnabled; + sideloadEnabled = Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.INSTALL_NON_MARKET_APPS, 0 /* sideload disabled */); + // TODO Allow showing an "install" button + attachmentInfo.allowView = false; + attachmentInfo.allowSave = (sideloadEnabled == 1); + } + // File size exceeded; Hide both buttons // The size limit is overridden when on a wifi connection - any size is OK if (attachmentInfo.size > Email.MAX_ATTACHMENT_DOWNLOAD_SIZE) {