diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2013-10-07 10:16:12 -0700 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2013-10-07 14:19:13 -0700 |
| commit | 85f5f8132015d8a5043ea4413702420d0d157c9f (patch) | |
| tree | 08493f51fca4a3ebd4eaf584e8c0fa03b373be9c /core/java/android | |
| parent | ca25db0cb3d6b9686a42c9cb99d90dc095f20cd8 (diff) | |
| download | frameworks_base-85f5f8132015d8a5043ea4413702420d0d157c9f.zip frameworks_base-85f5f8132015d8a5043ea4413702420d0d157c9f.tar.gz frameworks_base-85f5f8132015d8a5043ea4413702420d0d157c9f.tar.bz2 | |
Add <intent-filter> support to <provider>.
For the new documents work, we're only interested in the subset of
ContentProviders that actually implement DocumentsContract. Instead
of returning all providers, add <intent-filter> support to make it
easier to limit the set of returned ProviderInfo.
Define a well-known action for DocumentsProviders, and start using it
when querying for roots. Continue supporting the old <meta-data>
approach until all apps have been updated.
Bug: 8599233
Change-Id: I05f049bba21311f5421738002f99ee214447c909
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ApplicationPackageManager.java | 16 | ||||
| -rw-r--r-- | core/java/android/content/pm/IPackageManager.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/content/pm/PackageManager.java | 18 | ||||
| -rw-r--r-- | core/java/android/content/pm/PackageParser.java | 29 | ||||
| -rw-r--r-- | core/java/android/content/pm/ProviderInfo.java | 9 | ||||
| -rw-r--r-- | core/java/android/content/pm/ResolveInfo.java | 60 | ||||
| -rw-r--r-- | core/java/android/provider/DocumentsContract.java | 6 |
7 files changed, 122 insertions, 19 deletions
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java index 55c6672..b505d4f 100644 --- a/core/java/android/app/ApplicationPackageManager.java +++ b/core/java/android/app/ApplicationPackageManager.java @@ -585,6 +585,22 @@ final class ApplicationPackageManager extends PackageManager { } @Override + public List<ResolveInfo> queryIntentContentProvidersAsUser( + Intent intent, int flags, int userId) { + try { + return mPM.queryIntentContentProviders(intent, + intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId); + } catch (RemoteException e) { + throw new RuntimeException("Package manager has died", e); + } + } + + @Override + public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) { + return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId()); + } + + @Override public ProviderInfo resolveContentProvider(String name, int flags) { try { diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl index acd4ffa..267fb2a 100644 --- a/core/java/android/content/pm/IPackageManager.aidl +++ b/core/java/android/content/pm/IPackageManager.aidl @@ -123,6 +123,9 @@ interface IPackageManager { List<ResolveInfo> queryIntentServices(in Intent intent, String resolvedType, int flags, int userId); + List<ResolveInfo> queryIntentContentProviders(in Intent intent, + String resolvedType, int flags, int userId); + /** * This implements getInstalledPackages via a "last returned row" * mechanism that is not exposed in the API. This is to get around the IPC diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 9203af9..ba9c9f5 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -2202,6 +2202,24 @@ public abstract class PackageManager { public abstract List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId); + /** {@hide} */ + public abstract List<ResolveInfo> queryIntentContentProvidersAsUser( + Intent intent, int flags, int userId); + + /** + * Retrieve all providers that can match the given intent. + * + * @param intent An intent containing all of the desired specification + * (action, data, type, category, and/or component). + * @param flags Additional option flags. + * @return A List<ResolveInfo> containing one entry for each matching + * ProviderInfo. These are ordered from best to worst match. If + * there are no matching providers, an empty list is returned. + * @see #GET_INTENT_FILTERS + * @see #GET_RESOLVED_FILTER + */ + public abstract List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags); + /** * Find a single content provider by its base path name. * diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index b489ee9..17d13e5 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -2819,7 +2819,14 @@ public class PackageParser { continue; } - if (parser.getName().equals("meta-data")) { + if (parser.getName().equals("intent-filter")) { + ProviderIntentInfo intent = new ProviderIntentInfo(outInfo); + if (!parseIntent(res, parser, attrs, true, intent, outError)) { + return false; + } + outInfo.intents.add(intent); + + } else if (parser.getName().equals("meta-data")) { if ((outInfo.metaData=parseMetaData(res, parser, attrs, outInfo.metaData, outError)) == null) { return false; @@ -3982,7 +3989,7 @@ public class PackageParser { return si; } - public final static class Provider extends Component { + public final static class Provider extends Component<ProviderIntentInfo> { public final ProviderInfo info; public boolean syncable; @@ -4116,6 +4123,24 @@ public class PackageParser { } } + public static final class ProviderIntentInfo extends IntentInfo { + public final Provider provider; + + public ProviderIntentInfo(Provider provider) { + this.provider = provider; + } + + public String toString() { + StringBuilder sb = new StringBuilder(128); + sb.append("ProviderIntentInfo{"); + sb.append(Integer.toHexString(System.identityHashCode(this))); + sb.append(' '); + provider.appendComponentShortName(sb); + sb.append('}'); + return sb.toString(); + } + } + /** * @hide */ diff --git a/core/java/android/content/pm/ProviderInfo.java b/core/java/android/content/pm/ProviderInfo.java index a534176..f6ea058 100644 --- a/core/java/android/content/pm/ProviderInfo.java +++ b/core/java/android/content/pm/ProviderInfo.java @@ -19,6 +19,7 @@ package android.content.pm; import android.os.Parcel; import android.os.Parcelable; import android.os.PatternMatcher; +import android.util.Printer; /** * Holds information about a specific @@ -112,7 +113,13 @@ public final class ProviderInfo extends ComponentInfo flags = orig.flags; isSyncable = orig.isSyncable; } - + + public void dump(Printer pw, String prefix) { + super.dumpFront(pw, prefix); + pw.println(prefix + "authority=" + authority); + pw.println(prefix + "flags=0x" + Integer.toHexString(flags)); + } + public int describeContents() { return 0; } diff --git a/core/java/android/content/pm/ResolveInfo.java b/core/java/android/content/pm/ResolveInfo.java index e360e40..1ff41c0 100644 --- a/core/java/android/content/pm/ResolveInfo.java +++ b/core/java/android/content/pm/ResolveInfo.java @@ -23,6 +23,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import android.util.Printer; +import android.util.Slog; import java.text.Collator; import java.util.Comparator; @@ -34,20 +35,30 @@ import java.util.Comparator; * <intent> tags. */ public class ResolveInfo implements Parcelable { + private static final String TAG = "ResolveInfo"; + /** - * The activity or broadcast receiver that corresponds to this resolution match, - * if this resolution is for an activity or broadcast receiver. One and only one of this and - * serviceInfo must be non-null. + * The activity or broadcast receiver that corresponds to this resolution + * match, if this resolution is for an activity or broadcast receiver. + * Exactly one of {@link #activityInfo}, {@link #serviceInfo}, or + * {@link #providerInfo} will be non-null. */ public ActivityInfo activityInfo; /** - * The service that corresponds to this resolution match, if this - * resolution is for a service. One and only one of this and - * activityInfo must be non-null. + * The service that corresponds to this resolution match, if this resolution + * is for a service. Exactly one of {@link #activityInfo}, + * {@link #serviceInfo}, or {@link #providerInfo} will be non-null. */ public ServiceInfo serviceInfo; - + + /** + * The provider that corresponds to this resolution match, if this + * resolution is for a provider. Exactly one of {@link #activityInfo}, + * {@link #serviceInfo}, or {@link #providerInfo} will be non-null. + */ + public ProviderInfo providerInfo; + /** * The IntentFilter that was matched for this ResolveInfo. */ @@ -120,6 +131,13 @@ public class ResolveInfo implements Parcelable { */ public boolean system; + private ComponentInfo getComponentInfo() { + if (activityInfo != null) return activityInfo; + if (serviceInfo != null) return serviceInfo; + if (providerInfo != null) return providerInfo; + throw new IllegalStateException("Missing ComponentInfo!"); + } + /** * Retrieve the current textual label associated with this resolution. This * will call back on the given PackageManager to load the label from @@ -142,7 +160,7 @@ public class ResolveInfo implements Parcelable { return label.toString().trim(); } } - ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo; + ComponentInfo ci = getComponentInfo(); ApplicationInfo ai = ci.applicationInfo; if (labelRes != 0) { label = pm.getText(ci.packageName, labelRes, ai); @@ -176,7 +194,7 @@ public class ResolveInfo implements Parcelable { return dr; } } - ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo; + ComponentInfo ci = getComponentInfo(); ApplicationInfo ai = ci.applicationInfo; if (icon != 0) { dr = pm.getDrawable(ci.packageName, icon, ai); @@ -196,8 +214,8 @@ public class ResolveInfo implements Parcelable { */ public final int getIconResource() { if (icon != 0) return icon; - if (activityInfo != null) return activityInfo.getIconResource(); - if (serviceInfo != null) return serviceInfo.getIconResource(); + final ComponentInfo ci = getComponentInfo(); + if (ci != null) return ci.getIconResource(); return 0; } @@ -225,6 +243,9 @@ public class ResolveInfo implements Parcelable { } else if (serviceInfo != null) { pw.println(prefix + "ServiceInfo:"); serviceInfo.dump(pw, prefix + " "); + } else if (providerInfo != null) { + pw.println(prefix + "ProviderInfo:"); + providerInfo.dump(pw, prefix + " "); } } @@ -234,6 +255,7 @@ public class ResolveInfo implements Parcelable { public ResolveInfo(ResolveInfo orig) { activityInfo = orig.activityInfo; serviceInfo = orig.serviceInfo; + providerInfo = orig.providerInfo; filter = orig.filter; priority = orig.priority; preferredOrder = orig.preferredOrder; @@ -247,7 +269,7 @@ public class ResolveInfo implements Parcelable { } public String toString() { - ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo; + final ComponentInfo ci = getComponentInfo(); StringBuilder sb = new StringBuilder(128); sb.append("ResolveInfo{"); sb.append(Integer.toHexString(System.identityHashCode(this))); @@ -278,6 +300,9 @@ public class ResolveInfo implements Parcelable { } else if (serviceInfo != null) { dest.writeInt(2); serviceInfo.writeToParcel(dest, parcelableFlags); + } else if (providerInfo != null) { + dest.writeInt(3); + providerInfo.writeToParcel(dest, parcelableFlags); } else { dest.writeInt(0); } @@ -309,18 +334,21 @@ public class ResolveInfo implements Parcelable { }; private ResolveInfo(Parcel source) { + activityInfo = null; + serviceInfo = null; + providerInfo = null; switch (source.readInt()) { case 1: activityInfo = ActivityInfo.CREATOR.createFromParcel(source); - serviceInfo = null; break; case 2: serviceInfo = ServiceInfo.CREATOR.createFromParcel(source); - activityInfo = null; + break; + case 3: + providerInfo = ProviderInfo.CREATOR.createFromParcel(source); break; default: - activityInfo = null; - serviceInfo = null; + Slog.w(TAG, "Missing ComponentInfo!"); break; } if (source.readInt() != 0) { diff --git a/core/java/android/provider/DocumentsContract.java b/core/java/android/provider/DocumentsContract.java index 631a8d4..1c14c38 100644 --- a/core/java/android/provider/DocumentsContract.java +++ b/core/java/android/provider/DocumentsContract.java @@ -70,8 +70,14 @@ public final class DocumentsContract { } /** {@hide} */ + @Deprecated public static final String META_DATA_DOCUMENT_PROVIDER = "android.content.DOCUMENT_PROVIDER"; + /** + * Intent action used to identify {@link DocumentsProvider} instances. + */ + public static final String PROVIDER_INTERFACE = "android.content.action.DOCUMENTS_PROVIDER"; + /** {@hide} */ public static final String ACTION_MANAGE_ROOT = "android.provider.action.MANAGE_ROOT"; /** {@hide} */ |
