From e48076b31f39fb58642777009fc54e5aea706407 Mon Sep 17 00:00:00 2001 From: paulhu Date: Wed, 3 Mar 2021 11:44:31 +0800 Subject: [PATCH] New API for comparing two intents of PendingIntent object. Bug: 174237997 Test: atest PendingIntentTest Change-Id: Ic5eb20f94ff6fd6953315a5f848effa25b813da7 --- core/api/module-lib-current.txt | 1 + core/api/test-current.txt | 1 + core/java/android/app/PendingIntent.java | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt index f7e6e03dab07e..6089318d4f466 100644 --- a/core/api/module-lib-current.txt +++ b/core/api/module-lib-current.txt @@ -35,6 +35,7 @@ package android.app { } public final class PendingIntent implements android.os.Parcelable { + method @RequiresPermission(android.Manifest.permission.GET_INTENT_SENDER_INTENT) public boolean intentFilterEquals(@Nullable android.app.PendingIntent); method @NonNull @RequiresPermission(android.Manifest.permission.GET_INTENT_SENDER_INTENT) public java.util.List queryIntentComponents(int); } diff --git a/core/api/test-current.txt b/core/api/test-current.txt index a57d824125377..2d4b3caeb27f2 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -302,6 +302,7 @@ package android.app { } public final class PendingIntent implements android.os.Parcelable { + method @RequiresPermission("android.permission.GET_INTENT_SENDER_INTENT") public boolean intentFilterEquals(@Nullable android.app.PendingIntent); method @NonNull @RequiresPermission("android.permission.GET_INTENT_SENDER_INTENT") public java.util.List queryIntentComponents(int); field @Deprecated public static final int FLAG_MUTABLE_UNAUDITED = 33554432; // 0x2000000 } diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java index 009c9366b1d67..11adc5a60fb3f 100644 --- a/core/java/android/app/PendingIntent.java +++ b/core/java/android/app/PendingIntent.java @@ -1256,6 +1256,30 @@ public final class PendingIntent implements Parcelable { } } + /** + * Comparison operator on two PendingIntent objects, such that true is returned when they + * represent {@link Intent}s that are equal as per {@link Intent#filterEquals}. + * + * @param other The other PendingIntent to compare against. + * @return True if action, data, type, class, and categories on two intents are the same. + * + * @hide + */ + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + @TestApi + @RequiresPermission(android.Manifest.permission.GET_INTENT_SENDER_INTENT) + public boolean intentFilterEquals(@Nullable PendingIntent other) { + if (other == null) { + return false; + } + try { + return ActivityManager.getService().getIntentForIntentSender(other.mTarget) + .filterEquals(getIntent()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /** * Comparison operator on two PendingIntent objects, such that true * is returned then they both represent the same operation from the