diff options
| author | Dianne Hackborn <hackbod@google.com> | 2013-08-04 16:50:16 -0700 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2013-08-05 16:53:26 -0700 |
| commit | 221ea892dcc661bd07d6f36ff012edca2c48aed4 (patch) | |
| tree | 33a29861257497ebd865fe5565c9e3bfbde3cb1a /core/java/android/content/Intent.java | |
| parent | 33041bd90301d50c61e6375bbd9bb6da2f1c8cba (diff) | |
Start restricting service calls with implicit intents.
The bindService() and startService() calls have always had
undefined behavior when used with an implicit Intent and there
are multiple matching services. Because of this, it is not
safe for applications to use such Intents when interacting with
services, yet the platform would merrily go about doing... something.
In KLP I want to cause this case to be invalid, resulting in
an exception thrown back to the app. Unfortunately there are
lots of (scary) things relying on this behavior, so we can't
immediately turn it into an exception, even one qualified by the
caller's target SDK version.
In this change, we start loggin a WTF when such a call happens,
and clean up some stuff in Bluetooth that was doing this behavior.
Change-Id: I62e25d07890588d2362104e20b054aebb6c0e007
Diffstat (limited to 'core/java/android/content/Intent.java')
| -rw-r--r-- | core/java/android/content/Intent.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 30ea3f957cb0..205ca6bd05d8 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -16,6 +16,7 @@ package android.content; +import android.content.pm.ApplicationInfo; import android.util.ArraySet; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -44,6 +45,7 @@ import java.io.Serializable; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.Set; @@ -5034,6 +5036,39 @@ public class Intent implements Parcelable, Cloneable { } /** + * Special function for use by the system to resolve service + * intents to system apps. Throws an exception if there are + * multiple potential matches to the Intent. Returns null if + * there are no matches. + * @hide + */ + public ComponentName resolveSystemService(PackageManager pm, int flags) { + if (mComponent != null) { + return mComponent; + } + + List<ResolveInfo> results = pm.queryIntentServices(this, flags); + if (results == null) { + return null; + } + ComponentName comp = null; + for (int i=0; i<results.size(); i++) { + ResolveInfo ri = results.get(i); + if ((ri.serviceInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) { + continue; + } + ComponentName foundComp = new ComponentName(ri.serviceInfo.applicationInfo.packageName, + ri.serviceInfo.name); + if (comp != null) { + throw new IllegalStateException("Multiple system services handle " + this + + ": " + comp + ", " + foundComp); + } + comp = foundComp; + } + return comp; + } + + /** * Set the general action to be performed. * * @param action An action name, such as ACTION_VIEW. Application-specific @@ -5068,7 +5103,7 @@ public class Intent implements Parcelable, Cloneable { * * @see #getData * @see #setDataAndNormalize - * @see android.net.Intent#normalize + * @see android.net.Uri#normalizeScheme() */ public Intent setData(Uri data) { mData = data; |
