Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binder: Work around an Android Intent bug #9061

Merged
merged 1 commit into from Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -128,7 +128,14 @@ public String asAndroidAppUri() {

@Override
public int hashCode() {
return bindIntent.filterHashCode();
Intent intentForHashCode = bindIntent;
// Clear a (usually redundant) package filter to work around an Android >= 31 bug where certain
// Intents compare filterEquals() but have different filterHashCode() values. It's always safe
// to include fewer fields in the hashCode() computation.
if (intentForHashCode.getPackage() != null) {
intentForHashCode = intentForHashCode.cloneFilter().setPackage(null);
}
return intentForHashCode.filterHashCode();
}

@Override
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
public final class AndroidComponentAddressTest {
Expand Down Expand Up @@ -85,4 +86,35 @@ public void testEquality() {
.setComponent(hostComponent)))
.testEquals();
}

@Test
@Config(sdk = 30)
public void testPackageFilterEquality30AndUp() {
new EqualsTester()
.addEqualityGroup(
AndroidComponentAddress.forBindIntent(
new Intent().setAction("action").setComponent(new ComponentName("pkg", "cls"))),
AndroidComponentAddress.forBindIntent(
new Intent()
.setAction("action")
.setPackage("pkg")
.setComponent(new ComponentName("pkg", "cls"))))
.testEquals();
}

@Test
@Config(sdk = 29)
public void testPackageFilterEqualityPre30() {
new EqualsTester()
.addEqualityGroup(
AndroidComponentAddress.forBindIntent(
new Intent().setAction("action").setComponent(new ComponentName("pkg", "cls"))))
.addEqualityGroup(
AndroidComponentAddress.forBindIntent(
new Intent()
.setAction("action")
.setPackage("pkg")
.setComponent(new ComponentName("pkg", "cls"))))
.testEquals();
}
}