From 9c5a3300a5c02d95f79ea71bc4b7383879fc9b73 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Mon, 2 Sep 2019 14:25:15 +0800 Subject: [PATCH] Do not check package if package-equivalent components have set Two intents that can be resolved to the same component were evaluated as different intent filters, because one had the package name set while the other one did not(null). Skip performing package check if both two intents have components which equals to its set package. Bug: 64108432 Test: manual Change-Id: I8163cbb6b56366ebbecaede7fa04ab3eab7cfe9f --- core/java/android/content/Intent.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 3418b7be42d62..72204daf01efd 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -10004,13 +10004,25 @@ public class Intent implements Parcelable, Cloneable { if (!Objects.equals(this.mData, other.mData)) return false; if (!Objects.equals(this.mType, other.mType)) return false; if (!Objects.equals(this.mIdentifier, other.mIdentifier)) return false; - if (!Objects.equals(this.mPackage, other.mPackage)) return false; + if (!(this.hasPackageEquivalentComponent() && other.hasPackageEquivalentComponent()) + && !Objects.equals(this.mPackage, other.mPackage)) { + return false; + } if (!Objects.equals(this.mComponent, other.mComponent)) return false; if (!Objects.equals(this.mCategories, other.mCategories)) return false; return true; } + /** + * Return {@code true} if the component name is not null and is in the same package that this + * intent limited to. otherwise return {@code false}. + */ + private boolean hasPackageEquivalentComponent() { + return mComponent != null + && (mPackage == null || mPackage.equals(mComponent.getPackageName())); + } + /** * Generate hash code that matches semantics of filterEquals(). *