From 514881581d1a73b1dce83dbe38fe3a6c5d54b42b Mon Sep 17 00:00:00 2001 From: paulhu Date: Mon, 1 Feb 2021 19:31:01 +0800 Subject: [PATCH] New API for comparing two intents of PendingIntent object. Bug: 174237997 Test: atest PendingIntentTest Merged-In: Ic5eb20f94ff6fd6953315a5f848effa25b813da7 Change-Id: Ic5eb20f94ff6fd6953315a5f848effa25b813da7 --- core/api/module-lib-current.txt | 4 ++++ core/api/test-current.txt | 4 ++++ core/java/android/app/PendingIntent.java | 27 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt index 24adb7d619781..a0f84b4759bac 100644 --- a/core/api/module-lib-current.txt +++ b/core/api/module-lib-current.txt @@ -6,6 +6,10 @@ package android.app { method public void setMaxManifestReceiverApiLevel(int); } + public final class PendingIntent implements android.os.Parcelable { + method @RequiresPermission("android.permission.GET_INTENT_SENDER_INTENT") public boolean intentFilterEquals(@Nullable android.app.PendingIntent); + } + } package android.net { diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 68721418b4072..8bef02cbd4f2c 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -248,6 +248,10 @@ package android.app { method public boolean matchesCallFilter(android.os.Bundle); } + public final class PendingIntent implements android.os.Parcelable { + method @RequiresPermission("android.permission.GET_INTENT_SENDER_INTENT") public boolean intentFilterEquals(@Nullable android.app.PendingIntent); + } + public final class PictureInPictureParams implements android.os.Parcelable { method public java.util.List getActions(); method public float getAspectRatio(); diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java index 41cac75cbd758..c89b53e2c4159 100644 --- a/core/java/android/app/PendingIntent.java +++ b/core/java/android/app/PendingIntent.java @@ -19,6 +19,9 @@ package android.app; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; +import android.annotation.SystemApi; +import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.IIntentReceiver; @@ -1170,6 +1173,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