Reverting the Intent package-equivalent component checks

The commit 9c5a330 skips package checks if the package-equivalent
components are set. However, it could also result in inconsistent
behavior on #filterHashCode.

Fixing the original issue from the intent itself instead.

Bug: 64108432
Bug: 64789334
Test: atest TaskTests
Change-Id: I18c717e29072df91fb19eddbddc78153a28f9563
This commit is contained in:
Louis Chang
2022-08-05 09:37:40 +00:00
parent 5608e505ad
commit 40cc579cd3
3 changed files with 5 additions and 13 deletions

View File

@@ -11051,25 +11051,13 @@ 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 (!(this.hasPackageEquivalentComponent() && other.hasPackageEquivalentComponent())
&& !Objects.equals(this.mPackage, other.mPackage)) {
return false;
}
if (!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().
*

View File

@@ -1109,6 +1109,9 @@ class Task extends TaskFragment {
// as the one in the task because either one of them could be the alias activity.
if (Objects.equals(realActivity, r.mActivityComponent) && this.intent != null) {
intent.setComponent(this.intent.getComponent());
// Make sure the package name the same to prevent one of the intent is set while the
// other one is not.
intent.setPackage(this.intent.getPackage());
}
return intent.filterEquals(this.intent);
}

View File

@@ -846,6 +846,7 @@ public class TaskTests extends WindowTestsBase {
new ComponentName(DEFAULT_COMPONENT_PACKAGE_NAME, targetClassName);
final Intent intent = new Intent();
intent.setPackage(DEFAULT_COMPONENT_PACKAGE_NAME);
intent.setComponent(aliasComponent);
final ActivityInfo info = new ActivityInfo();
info.applicationInfo = new ApplicationInfo();