summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorPatrick Baumann <patb@google.com>2020-04-06 12:13:33 -0700
committerPatrick Baumann <patb@google.com>2020-04-08 10:23:49 -0700
commit40cb0205d4a04a660b2bb473a7c569813124a20b (patch)
treea023f4c6dbb75043f49d8f9ded604c51d5448b15 /core/java
parent3dfc45e593326ae43407e8e6fb853ee5c6552228 (diff)
Only grant visibility of protected broadcasts to system
This change ensures that only the system (appId < 10000) may see apps with receivers of protected broadcasts. Test: atest AppsFilterTest Fixes: 142386375 Change-Id: Ia421d2aa22d37eafbb6c1cd217ab2cb1626480b0
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/content/IntentFilter.java41
1 files changed, 32 insertions, 9 deletions
diff --git a/core/java/android/content/IntentFilter.java b/core/java/android/content/IntentFilter.java
index f951d2b89958..745add174582 100644
--- a/core/java/android/content/IntentFilter.java
+++ b/core/java/android/content/IntentFilter.java
@@ -17,6 +17,7 @@
package android.content;
import android.annotation.IntDef;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.Uri;
@@ -40,6 +41,7 @@ import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -766,16 +768,30 @@ public class IntentFilter implements Parcelable {
* @return True if the action is listed in the filter.
*/
public final boolean matchAction(String action) {
- return matchAction(action, false);
+ return matchAction(action, false /*wildcardSupported*/, null /*ignoreActions*/);
}
/**
* Variant of {@link #matchAction(String)} that allows a wildcard for the provided action.
* @param wildcardSupported if true, will allow action to use wildcards
- */
- private boolean matchAction(String action, boolean wildcardSupported) {
- if (wildcardSupported && !mActions.isEmpty() && WILDCARD.equals(action)) {
- return true;
+ * @param ignoreActions if not null, the set of actions to should not be considered valid while
+ * calculating the match
+ */
+ private boolean matchAction(String action, boolean wildcardSupported,
+ @Nullable Collection<String> ignoreActions) {
+ if (wildcardSupported && WILDCARD.equals(action)) {
+ if (ignoreActions == null) {
+ return !mActions.isEmpty();
+ }
+ for (int i = mActions.size() - 1; i >= 0; i--) {
+ if (!ignoreActions.contains(mActions.get(i))) {
+ return true;
+ }
+ }
+ return false;
+ }
+ if (ignoreActions != null && ignoreActions.contains(action)) {
+ return false;
}
return hasAction(action);
}
@@ -1779,17 +1795,24 @@ public class IntentFilter implements Parcelable {
*/
public final int match(String action, String type, String scheme,
Uri data, Set<String> categories, String logTag) {
- return match(action, type, scheme, data, categories, logTag, false /*supportWildcards*/);
+ return match(action, type, scheme, data, categories, logTag, false /*supportWildcards*/,
+ null /*ignoreActions*/);
}
/**
* Variant of {@link #match(ContentResolver, Intent, boolean, String)} that supports wildcards
* in the action, type, scheme, host and path.
- * @hide if true, will allow supported parameters to use wildcards to match this filter
+ * @param supportWildcards if true, will allow supported parameters to use wildcards to match
+ * this filter
+ * @param ignoreActions a collection of actions that, if not null should be ignored and not used
+ * if provided as the matching action or the set of actions defined by this
+ * filter
+ * @hide
*/
public final int match(String action, String type, String scheme,
- Uri data, Set<String> categories, String logTag, boolean supportWildcards) {
- if (action != null && !matchAction(action, supportWildcards)) {
+ Uri data, Set<String> categories, String logTag, boolean supportWildcards,
+ @Nullable Collection<String> ignoreActions) {
+ if (action != null && !matchAction(action, supportWildcards, ignoreActions)) {
if (false) Log.v(
logTag, "No matching action " + action + " for " + this);
return NO_MATCH_ACTION;