From 467361dbcf14ad0612b987e5e7aef1a4eb37145a Mon Sep 17 00:00:00 2001 From: Tom Taylor Date: Thu, 5 Oct 2017 11:27:21 -0700 Subject: [PATCH 01/10] 37742976 - Catch bad gifs * A security researcher crafted a gif that would cause the Android Bitmap code to throw an NPE. That would cause messaging to crash when decoding the NPE. The frameworks team is changing the underlying code to throw an OutOfMemoryError instead of a NullPointerException. In order to catch both errors, the code needs to catch Throwable. Test: I added code to GifImageResource.getDrawable to throw a new OutOfMemoryError and then used the debugger to verify it was caught by the new catch Throwable statement. I did the same test with NullPointerException. I tested attaching gif images and sending them to verify the gif path still worked. BUG=37742976 Change-Id: If71a7e65f8c0b083fe6c4b79f78358666338d59d --- .../messaging/datamodel/media/GifImageResource.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/android/messaging/datamodel/media/GifImageResource.java b/src/com/android/messaging/datamodel/media/GifImageResource.java index 6801165..cbea1ee 100644 --- a/src/com/android/messaging/datamodel/media/GifImageResource.java +++ b/src/com/android/messaging/datamodel/media/GifImageResource.java @@ -58,10 +58,10 @@ public class GifImageResource extends ImageResource { public Drawable getDrawable(Resources resources) { try { return new FrameSequenceDrawable(mFrameSequence); - } catch (final Exception e) { - // Malicious gif images can make platform throw different kind of exceptions. Catch - // them all. - LogUtil.e(LogUtil.BUGLE_TAG, "Error getting drawable for GIF", e); + } catch (final Throwable t) { + // Malicious gif images can make the platform throw different kind of throwables, such + // as OutOfMemoryError and NullPointerException. Catch them all. + LogUtil.e(LogUtil.BUGLE_TAG, "Error getting drawable for GIF", t); return null; } } From ea59fb8c73461d89541d1d4a00061f1a24a6bcd3 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 16 Nov 2017 12:57:30 +0000 Subject: [PATCH 02/10] Use a.t.mock.stubs instead of a.t.mock.sdk Remove dependencies on android.test.mock.sdk as it is a duplicate of android.test.mock.stubs and will be removed. The following change descriptions were generated automatically and so may be a little repetitive. They are provided to give the reviewer enough information to check the comments match what has actually been changed and check the reasoning behind the changes. * tests/Android.mk Replaced 'android.test.mock.sdk' with 'android.test.mock.stubs' in LOCAL_JAVA_LIBRARIES because android.test.mock.sdk has been deprecated. Bug: 30188076 Test: make checkbuild Change-Id: I40d388f5e07293f7d958b563bc8ab94f89ff9f8d --- tests/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Android.mk b/tests/Android.mk index a137a92..b906684 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -32,7 +32,7 @@ LOCAL_CERTIFICATE := platform LOCAL_STATIC_JAVA_LIBRARIES := \ mockito-target -LOCAL_JAVA_LIBRARIES := android.test.mock.sdk legacy-android-test +LOCAL_JAVA_LIBRARIES := android.test.mock.stubs legacy-android-test include $(BUILD_PACKAGE) From 9812a75c014a24f87fe9f65b8997dcb362f4c2e2 Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Tue, 21 Nov 2017 12:50:18 -0800 Subject: [PATCH 03/10] Migrate messaging to aapt2. Test: make messaging Change-Id: I460554bc92244feeca6e28081daf66d0dc2e6281 --- Android.mk | 53 ++++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/Android.mk b/Android.mk index 06ac9e6..6b51b96 100644 --- a/Android.mk +++ b/Android.mk @@ -20,43 +20,34 @@ LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res -ifeq ($(TARGET_BUILD_APPS),) - LOCAL_RESOURCE_DIR += frameworks/support/v7/appcompat/res - LOCAL_RESOURCE_DIR += frameworks/support/v7/recyclerview/res -else - LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res - LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/recyclerview/res -endif -LOCAL_RESOURCE_DIR += frameworks/opt/chips/res -LOCAL_RESOURCE_DIR += frameworks/opt/colorpicker/res -LOCAL_RESOURCE_DIR += frameworks/opt/photoviewer/res -LOCAL_RESOURCE_DIR += frameworks/opt/photoviewer/activity/res +LOCAL_USE_AAPT2 := true -LOCAL_STATIC_JAVA_LIBRARIES := android-common -LOCAL_STATIC_JAVA_LIBRARIES += android-common-framesequence -LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4 -LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat -LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-palette -LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-recyclerview -LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13 -LOCAL_STATIC_JAVA_LIBRARIES += com.android.vcard -LOCAL_STATIC_JAVA_LIBRARIES += guava -LOCAL_STATIC_JAVA_LIBRARIES += libchips -LOCAL_STATIC_JAVA_LIBRARIES += libphotoviewer -LOCAL_STATIC_JAVA_LIBRARIES += libphonenumber -LOCAL_STATIC_JAVA_LIBRARIES += colorpicker +LOCAL_STATIC_ANDROID_LIBRARIES := \ + android-support-compat \ + android-support-media-compat \ + android-support-core-utils \ + android-support-core-ui \ + android-support-fragment \ + android-support-v7-appcompat \ + android-support-v7-palette \ + android-support-v7-recyclerview \ + android-support-v13 \ + colorpicker \ + libchips \ + libphotoviewer + +LOCAL_STATIC_JAVA_LIBRARIES := \ + android-support-annotations \ + android-common \ + android-common-framesequence \ + com.android.vcard \ + guava \ + libphonenumber include $(LOCAL_PATH)/version.mk -LOCAL_AAPT_FLAGS := --auto-add-overlay LOCAL_AAPT_FLAGS += --version-name "$(version_name_package)" LOCAL_AAPT_FLAGS += --version-code $(version_code_package) -LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat -LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.recyclerview -LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.chips -LOCAL_AAPT_FLAGS += --extra-packages com.android.vcard -LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.photo -LOCAL_AAPT_FLAGS += --extra-packages com.android.colorpicker ifdef TARGET_BUILD_APPS LOCAL_JNI_SHARED_LIBRARIES := libframesequence libgiftranscode From 2e86be170a8d554e06c94856953f1856796b9c47 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 5 Dec 2017 18:36:57 +0000 Subject: [PATCH 04/10] Flatten dependency hierarchy of legacy-android-test Previous changes statically included legacy-android-test in preparation for removing android.test.* and junit.* classes from the android.jar. Unfortunately, that lead to duplicate classes between APKs and the bootclasspath which caused build problems (Proguard) and also runtime problems (when targeting and running on older releases). Switching from statically including the classes to using the runtime libraries cannot be done in one step because legacy-android-test is statically included in libraries which are used in many APKs and so removing it from those libraries requires that all APKs be updated at once. Doing that atomically across dozens of projects is not practical. This change modifies APKS that statically include the legacy-android-test library indirectly. * If the APK manifest uses the android.test.runner library then the APK is modified to stop statically including legacy-android-test and instead build against android.test.base/mock/runner libraries instead. * Otherwise, the APK statically includes legacy-android-test. Also, any libraries that statically include are modified to stop statically including it and if it has source dependencies on the classes is changed to build against the android.test.base/mock/runner libraries. The following change descriptions were generated automatically and so may be a little repetitive. They are provided to give the reviewer enough information to check the comments match what has actually been changed and check the reasoning behind the changes. * tests/Android.mk Replaced 'legacy-android-test' with 'android.test.runner.stubs' in LOCAL_JAVA_LIBRARIES because messagingtests's source depends on its classes. The classes do not need to be statically included because the classes will be provided by the runtime, either from the default bootclasspath or from the android.test.runner library that messagingtests specifies in its manifest. Bug: 30188076 Test: make checkbuild Change-Id: I7fa5bcf37c3b003c84ba5e493c6d675a619b6bcd --- tests/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Android.mk b/tests/Android.mk index b906684..ecdb8ab 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -32,7 +32,7 @@ LOCAL_CERTIFICATE := platform LOCAL_STATIC_JAVA_LIBRARIES := \ mockito-target -LOCAL_JAVA_LIBRARIES := android.test.mock.stubs legacy-android-test +LOCAL_JAVA_LIBRARIES := android.test.mock.stubs android.test.runner.stubs include $(BUILD_PACKAGE) From ea5d77fa38ff557f583fc0eaaa183660cd7e85a9 Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Mon, 27 Nov 2017 12:58:51 -0800 Subject: [PATCH 05/10] Switch to modern ArgumentMatchers Test: - adb shell am instrument -w -e class com.android.messaging.ui.attachmentchooser.AttachmentChooserFragmentTest com.android.messaging.test/android.test.InstrumentationTestRunner - adb shell am instrument -w -e class com.android.messaging.ui.conversation.ComposeMessageViewTest com.android.messaging.test/android.test.InstrumentationTestRunner - adb shell am instrument -w -e class com.android.messaging.ui.conversationlist.ConversationListItemViewTest com.android.messaging.test/android.test.InstrumentationTestRunner Change-Id: Ic3f29ed0e13b392d5687934f25d99c2a0e8c4dac --- .../AttachmentChooserFragmentTest.java | 8 +++---- .../conversation/ComposeMessageViewTest.java | 24 +++++++++---------- .../ConversationListItemViewTest.java | 9 ++----- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/tests/src/com/android/messaging/ui/attachmentchooser/AttachmentChooserFragmentTest.java b/tests/src/com/android/messaging/ui/attachmentchooser/AttachmentChooserFragmentTest.java index 5ec5ab5..e81cd54 100644 --- a/tests/src/com/android/messaging/ui/attachmentchooser/AttachmentChooserFragmentTest.java +++ b/tests/src/com/android/messaging/ui/attachmentchooser/AttachmentChooserFragmentTest.java @@ -36,10 +36,10 @@ import com.android.messaging.ui.attachmentchooser.AttachmentGridView; import com.android.messaging.ui.attachmentchooser.AttachmentChooserFragment.AttachmentChooserFragmentHost; import com.android.messaging.ui.conversationlist.ConversationListFragment; +import org.mockito.ArgumentMatcher; import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.compat.ArgumentMatcher; import java.util.Arrays; import java.util.HashSet; @@ -62,16 +62,14 @@ public class AttachmentChooserFragmentTest extends FragmentTestCase> { + private class IsSetOfGivenAttachments implements ArgumentMatcher> { private final Set mGivenParts; public IsSetOfGivenAttachments(final Set givenParts) { mGivenParts = givenParts; } @Override - public boolean matchesObject(final Object set) { - @SuppressWarnings("unchecked") - final Set actualSet = (Set) set; + public boolean matches(final Set actualSet) { if (actualSet.size() != mGivenParts.size()) { return false; } diff --git a/tests/src/com/android/messaging/ui/conversation/ComposeMessageViewTest.java b/tests/src/com/android/messaging/ui/conversation/ComposeMessageViewTest.java index 8c372f2..2148c71 100644 --- a/tests/src/com/android/messaging/ui/conversation/ComposeMessageViewTest.java +++ b/tests/src/com/android/messaging/ui/conversation/ComposeMessageViewTest.java @@ -16,6 +16,9 @@ package com.android.messaging.ui.conversation; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isNull; + import android.content.Context; import android.media.MediaPlayer; import android.test.suitebuilder.annotation.MediumTest; @@ -39,10 +42,10 @@ import com.android.messaging.util.BugleGservices; import com.android.messaging.util.FakeMediaUtil; import com.android.messaging.util.ImeUtil; +import org.mockito.ArgumentMatcher; import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.compat.ArgumentMatcher; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -127,8 +130,8 @@ public class ComposeMessageViewTest extends ViewTest { view.requestDraftMessage(false); - Mockito.verify(mockDraftMessageData).loadFromStorage(Matchers.any(BindingBase.class), - Matchers.any(MessageData.class), Mockito.eq(false)); + Mockito.verify(mockDraftMessageData).loadFromStorage(any(BindingBase.class), + isNull(), Mockito.eq(false)); view.onDraftChanged(mockDraftMessageData, DraftMessageData.ALL_CHANGED); @@ -136,12 +139,9 @@ public class ComposeMessageViewTest extends ViewTest { sendButton.performClick(); Mockito.verify(mockIComposeMessageViewHost).sendMessage( - Mockito.argThat(new ArgumentMatcher() { - @Override - public boolean matchesObject(final Object o) { - assertEquals(message.getMessageText(), ((MessageData) o).getMessageText()); - return true; - } + Mockito.argThat(o -> { + assertEquals(message.getMessageText(), o.getMessageText()); + return true; })); } @@ -170,8 +170,8 @@ public class ComposeMessageViewTest extends ViewTest { view.requestDraftMessage(false); - Mockito.verify(mockDraftMessageData).loadFromStorage(Matchers.any(BindingBase.class), - Matchers.any(MessageData.class), Mockito.eq(false)); + Mockito.verify(mockDraftMessageData).loadFromStorage(any(BindingBase.class), + isNull(), Mockito.eq(false)); view.onDraftChanged(mockDraftMessageData, DraftMessageData.ALL_CHANGED); @@ -179,6 +179,6 @@ public class ComposeMessageViewTest extends ViewTest { sendButton.performClick(); Mockito.verify(mockIComposeMessageViewHost).warnOfMissingActionConditions( - Matchers.any(Boolean.class), Matchers.any(Runnable.class)); + any(Boolean.class), any(Runnable.class)); } } diff --git a/tests/src/com/android/messaging/ui/conversationlist/ConversationListItemViewTest.java b/tests/src/com/android/messaging/ui/conversationlist/ConversationListItemViewTest.java index 1fbba1f..afac0d8 100644 --- a/tests/src/com/android/messaging/ui/conversationlist/ConversationListItemViewTest.java +++ b/tests/src/com/android/messaging/ui/conversationlist/ConversationListItemViewTest.java @@ -35,9 +35,9 @@ import com.android.messaging.ui.ViewTest; import com.android.messaging.ui.conversationlist.ConversationListItemView; import com.android.messaging.util.Dates; +import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.compat.ArgumentMatcher; @MediumTest public class ConversationListItemViewTest extends ViewTest { @@ -60,12 +60,7 @@ public class ConversationListItemViewTest extends ViewTest itemDataIdMatcher = - new ArgumentMatcher() { - @Override - public boolean matchesObject(final Object arg) { - return TextUtils.equals(id, ((ConversationListItemData) arg).getConversationId()); - } - }; + arg -> TextUtils.equals(id, arg.getConversationId()); Mockito.verify(mockHost).onConversationClicked( Mockito.argThat(itemDataIdMatcher), Mockito.eq(false), Mockito.eq(conversationView)); From 3a14dd0aa8c11b3c1b09276184b9e0547e205ba5 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 15 Dec 2017 07:22:38 +0000 Subject: [PATCH 06/10] Add android.test.base/stubs dependency In preparation for the removal of the non-junit classes in the android.test.base library from the android.jar this adds a dependency on android.test.base/stubs to ensure this code will continue to compile. The following change descriptions were generated automatically and so may be a little repetitive. They are provided to give the reviewer enough information to check the comments match what has actually been changed and check the reasoning behind the changes. * tests/Android.mk Added 'android.test.base.stubs' to LOCAL_JAVA_LIBRARIES because messagingtests's will need them in order to compile once its classes are removed from the current SDK on which it currently depends. Bug: 30188076 Test: make dist Change-Id: Iabfb3c655897781ab3aee2b0dbf574d6048954a9 --- tests/Android.mk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Android.mk b/tests/Android.mk index ecdb8ab..dc1999b 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -32,7 +32,11 @@ LOCAL_CERTIFICATE := platform LOCAL_STATIC_JAVA_LIBRARIES := \ mockito-target -LOCAL_JAVA_LIBRARIES := android.test.mock.stubs android.test.runner.stubs +LOCAL_JAVA_LIBRARIES := \ + android.test.mock.stubs \ + android.test.runner.stubs \ + android.test.base.stubs \ + include $(BUILD_PACKAGE) From 2e0bf0af27a82074d8d5dec80db4c0bb03ded2a7 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Wed, 14 Feb 2018 15:26:15 -0800 Subject: [PATCH 07/10] Enable content observer notifications even for default SMS app, when the build is for Android Auto Bug: 71633682 Test: tested manually Change-Id: Iee139fd7a65f60cd6c059f5c6d2ef78464e0dfce --- src/com/android/messaging/datamodel/SyncManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/com/android/messaging/datamodel/SyncManager.java b/src/com/android/messaging/datamodel/SyncManager.java index b3571bf..26961d1 100644 --- a/src/com/android/messaging/datamodel/SyncManager.java +++ b/src/com/android/messaging/datamodel/SyncManager.java @@ -17,6 +17,7 @@ package com.android.messaging.datamodel; import android.content.Context; +import android.content.pm.PackageManager; import android.database.ContentObserver; import android.net.Uri; import android.provider.Telephony; @@ -308,6 +309,14 @@ public class SyncManager { // Primary users default SMS app - don't monitor telephony (most changes from this app) mNotifyOnChanges = false; mSyncOnChanges = false; + if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { + // This is default SMS app but on Auto platform, even default SMS app needs + // to be notified of changes because Bluetooth makes changes to Sms database + // (thru ContentProvider). Content Change notifications help the default SMS app + // refresh display with changes, whenever Bluetooth changes data in SMS db. + mNotifyOnChanges = true; + mSyncOnChanges = true; + } } if (mNotifyOnChanges || mSyncOnChanges) { context.getContentResolver().registerContentObserver(Telephony.MmsSms.CONTENT_URI, From 871938aa2c73cbd87ca978276a23952e986f4ee8 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Wed, 28 Feb 2018 17:34:49 +0000 Subject: [PATCH 08/10] Revert "Enable content observer notifications even for default SMS app, when the" This reverts commit 2e0bf0af27a82074d8d5dec80db4c0bb03ded2a7. Reason for revert: should not be in P Change-Id: I457ebe79e66abb21a9d2fc1c168802b8505c5e9f --- src/com/android/messaging/datamodel/SyncManager.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/com/android/messaging/datamodel/SyncManager.java b/src/com/android/messaging/datamodel/SyncManager.java index 26961d1..b3571bf 100644 --- a/src/com/android/messaging/datamodel/SyncManager.java +++ b/src/com/android/messaging/datamodel/SyncManager.java @@ -17,7 +17,6 @@ package com.android.messaging.datamodel; import android.content.Context; -import android.content.pm.PackageManager; import android.database.ContentObserver; import android.net.Uri; import android.provider.Telephony; @@ -309,14 +308,6 @@ public class SyncManager { // Primary users default SMS app - don't monitor telephony (most changes from this app) mNotifyOnChanges = false; mSyncOnChanges = false; - if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { - // This is default SMS app but on Auto platform, even default SMS app needs - // to be notified of changes because Bluetooth makes changes to Sms database - // (thru ContentProvider). Content Change notifications help the default SMS app - // refresh display with changes, whenever Bluetooth changes data in SMS db. - mNotifyOnChanges = true; - mSyncOnChanges = true; - } } if (mNotifyOnChanges || mSyncOnChanges) { context.getContentResolver().registerContentObserver(Telephony.MmsSms.CONTENT_URI, From 9deefdf182d69f98d361d9d24de1e4892923dac5 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 1 May 2018 14:54:46 -0700 Subject: [PATCH 09/10] Messaging ignores file URIs shared via intent Fixes b/37629504 by not creating attachments from file URIs shared via intent. Sharing file URIs is disallowed by Android N and later and is no longer supported for this app. Test: manual using the Debug command added in this change Change-Id: Ibff486c94ac703a9a4c5a80e33b934a460804a8f Merged-In: Ibff486c94ac703a9a4c5a80e33b934a460804a8f --- .../conversationlist/ShareIntentActivity.java | 13 +++++++++++ .../android/messaging/util/DebugUtils.java | 22 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java b/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java index 83b7be9..1c91e46 100644 --- a/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java +++ b/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java @@ -35,6 +35,7 @@ import com.android.messaging.util.ContentType; import com.android.messaging.util.LogUtil; import com.android.messaging.util.MediaMetadataRetrieverWrapper; import com.android.messaging.util.FileUtil; +import com.android.messaging.util.UriUtil; import java.io.IOException; import java.util.ArrayList; @@ -75,6 +76,12 @@ public class ShareIntentActivity extends BaseBugleActivity implements final String action = intent.getAction(); if (Intent.ACTION_SEND.equals(action)) { final Uri contentUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); + if (UriUtil.isFileUri(contentUri)) { + LogUtil.i( + LogUtil.BUGLE_TAG, + "Ignoring attachment from file URI which are no longer supported."); + return; + } final String contentType = extractContentType(contentUri, intent.getType()); if (LogUtil.isLoggable(LogUtil.BUGLE_TAG, LogUtil.DEBUG)) { LogUtil.d(LogUtil.BUGLE_TAG, String.format( @@ -112,6 +119,12 @@ public class ShareIntentActivity extends BaseBugleActivity implements if (imageUris != null && imageUris.size() > 0) { mDraftMessage = MessageData.createSharedMessage(null); for (final Uri imageUri : imageUris) { + if (UriUtil.isFileUri(imageUri)) { + LogUtil.i( + LogUtil.BUGLE_TAG, + "Ignoring attachment from file URI which are no longer supported."); + continue; + } final String actualContentType = extractContentType(imageUri, contentType); addSharedImagePartToDraft(actualContentType, imageUri); } diff --git a/src/com/android/messaging/util/DebugUtils.java b/src/com/android/messaging/util/DebugUtils.java index f2c1d65..1362f83 100644 --- a/src/com/android/messaging/util/DebugUtils.java +++ b/src/com/android/messaging/util/DebugUtils.java @@ -22,12 +22,15 @@ import android.app.FragmentManager; import android.app.FragmentTransaction; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.media.MediaPlayer; +import android.net.Uri; import android.os.Environment; import android.telephony.SmsMessage; import android.text.TextUtils; import android.widget.ArrayAdapter; +import com.android.messaging.Factory; import com.android.messaging.R; import com.android.messaging.datamodel.SyncManager; import com.android.messaging.datamodel.action.DumpDatabaseAction; @@ -179,6 +182,13 @@ public class DebugUtils { } }); + arrayAdapter.add(new DebugAction("Test sharing a file URI") { + @Override + public void run() { + shareFileUri(); + } + }); + builder.setAdapter(arrayAdapter, new android.content.DialogInterface.OnClickListener() { @Override @@ -422,4 +432,16 @@ public class DebugUtils { public static boolean debugClassZeroSmsEnabled() { return sDebugClassZeroSms; } + + /** Shares a ringtone file via file URI. */ + private static void shareFileUri() { + final String packageName = "com.android.messaging"; + final String fileName = "/system/media/audio/ringtones/Andromeda.ogg"; + + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setPackage(packageName); + intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + fileName)); + intent.setType("image/*"); + Factory.get().getApplicationContext().startActivity(intent); + } } From 0ee4c0e33b183d74c17b5cf6ddb43b2c6f451be9 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 1 May 2018 14:54:46 -0700 Subject: [PATCH 10/10] RESTRICT AUTOMERGE: Messaging ignores file URIs shared via intent Fixes b/37629504 by not creating attachments from file URIs shared via intent. Sharing file URIs is disallowed by Android N and later and is no longer supported for this app. Test: manual using the Debug command added in this change Change-Id: Iaecff745aca76381d387ab057ffa1f2024aebfcf --- .../conversationlist/ShareIntentActivity.java | 14 +++++++++++ .../android/messaging/util/DebugUtils.java | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java b/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java index ef7fcef..3b35205 100644 --- a/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java +++ b/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java @@ -34,6 +34,8 @@ import com.android.messaging.util.Assert; import com.android.messaging.util.ContentType; import com.android.messaging.util.LogUtil; import com.android.messaging.util.MediaMetadataRetrieverWrapper; +import com.android.messaging.util.FileUtil; +import com.android.messaging.util.UriUtil; import java.io.IOException; import java.util.ArrayList; @@ -74,6 +76,12 @@ public class ShareIntentActivity extends BaseBugleActivity implements final String action = intent.getAction(); if (Intent.ACTION_SEND.equals(action)) { final Uri contentUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); + if (UriUtil.isFileUri(contentUri)) { + LogUtil.i( + LogUtil.BUGLE_TAG, + "Ignoring attachment from file URI which are no longer supported."); + return; + } final String contentType = extractContentType(contentUri, intent.getType()); if (LogUtil.isLoggable(LogUtil.BUGLE_TAG, LogUtil.DEBUG)) { LogUtil.d(LogUtil.BUGLE_TAG, String.format( @@ -111,6 +119,12 @@ public class ShareIntentActivity extends BaseBugleActivity implements if (imageUris != null && imageUris.size() > 0) { mDraftMessage = MessageData.createSharedMessage(null); for (final Uri imageUri : imageUris) { + if (UriUtil.isFileUri(imageUri)) { + LogUtil.i( + LogUtil.BUGLE_TAG, + "Ignoring attachment from file URI which are no longer supported."); + continue; + } final String actualContentType = extractContentType(imageUri, contentType); addSharedImagePartToDraft(actualContentType, imageUri); } diff --git a/src/com/android/messaging/util/DebugUtils.java b/src/com/android/messaging/util/DebugUtils.java index f2c1d65..5302d62 100644 --- a/src/com/android/messaging/util/DebugUtils.java +++ b/src/com/android/messaging/util/DebugUtils.java @@ -22,12 +22,15 @@ import android.app.FragmentManager; import android.app.FragmentTransaction; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.media.MediaPlayer; +import android.net.Uri; import android.os.Environment; import android.telephony.SmsMessage; import android.text.TextUtils; import android.widget.ArrayAdapter; +import com.android.messaging.Factory; import com.android.messaging.R; import com.android.messaging.datamodel.SyncManager; import com.android.messaging.datamodel.action.DumpDatabaseAction; @@ -179,6 +182,13 @@ public class DebugUtils { } }); + arrayAdapter.add(new DebugAction("Test sharing a file URI") { + @Override + public void run() { + shareFileUri(); + } + }); + builder.setAdapter(arrayAdapter, new android.content.DialogInterface.OnClickListener() { @Override @@ -422,4 +432,17 @@ public class DebugUtils { public static boolean debugClassZeroSmsEnabled() { return sDebugClassZeroSms; } + + /** Shares a ringtone file via file URI. */ + private static void shareFileUri() { + final String packageName = "com.android.messaging"; + final String fileName = "/system/media/audio/ringtones/Andromeda.ogg"; + + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setPackage(packageName); + intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + fileName)); + intent.setType("image/*"); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + Factory.get().getApplicationContext().startActivity(intent); + } }