From 361199b5e742c6635d4d7a03de6cf37b31cf442c Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Mon, 30 Aug 2010 17:42:07 -0700 Subject: [PATCH] Add PackageManager API to get information about a provider component. Kind-of useful when all you have is a ComponentName. Change-Id: I9a99f12daabb29e97e882e09c43ca0df70c00651 --- api/current.xml | 40 ++++++++++++++-- core/java/android/app/ContextImpl.java | 15 ++++++ .../android/content/pm/IPackageManager.aidl | 2 + .../android/content/pm/PackageManager.java | 46 ++++++++++++++----- .../android/server/PackageManagerService.java | 12 +++++ .../android/test/mock/MockPackageManager.java | 6 +++ 6 files changed, 106 insertions(+), 15 deletions(-) diff --git a/api/current.xml b/api/current.xml index 9bedb67298730..1305bad4ea7fd 100644 --- a/api/current.xml +++ b/api/current.xml @@ -48120,7 +48120,7 @@ deprecated="not deprecated" visibility="public" > - + @@ -48516,6 +48516,23 @@ + + + + + + + + - + @@ -48588,7 +48605,7 @@ deprecated="not deprecated" visibility="public" > - + @@ -158313,6 +158330,23 @@ + + + + + + + + Throws {@link NameNotFoundException} if an activity with the given * class name can not be found on the system. * - * @param className The full name (i.e. - * com.google.apps.contacts.ContactsList) of an Activity - * class. + * @param component The full component name (i.e. + * com.google.apps.contacts/com.google.apps.contacts.ContactsList) of an Activity + * class. * @param flags Additional option flags. Use any combination of * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, * to modify the data (in ApplicationInfo) returned. @@ -1009,7 +1009,7 @@ public abstract class PackageManager { * @see #GET_META_DATA * @see #GET_SHARED_LIBRARY_FILES */ - public abstract ActivityInfo getActivityInfo(ComponentName className, + public abstract ActivityInfo getActivityInfo(ComponentName component, int flags) throws NameNotFoundException; /** @@ -1019,9 +1019,9 @@ public abstract class PackageManager { *

Throws {@link NameNotFoundException} if a receiver with the given * class name can not be found on the system. * - * @param className The full name (i.e. - * com.google.apps.contacts.CalendarAlarm) of a Receiver - * class. + * @param component The full component name (i.e. + * com.google.apps.calendar/com.google.apps.calendar.CalendarAlarm) of a Receiver + * class. * @param flags Additional option flags. Use any combination of * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, * to modify the data returned. @@ -1032,7 +1032,7 @@ public abstract class PackageManager { * @see #GET_META_DATA * @see #GET_SHARED_LIBRARY_FILES */ - public abstract ActivityInfo getReceiverInfo(ComponentName className, + public abstract ActivityInfo getReceiverInfo(ComponentName component, int flags) throws NameNotFoundException; /** @@ -1042,9 +1042,9 @@ public abstract class PackageManager { *

Throws {@link NameNotFoundException} if a service with the given * class name can not be found on the system. * - * @param className The full name (i.e. - * com.google.apps.media.BackgroundPlayback) of a Service - * class. + * @param component The full component name (i.e. + * com.google.apps.media/com.google.apps.media.BackgroundPlayback) of a Service + * class. * @param flags Additional option flags. Use any combination of * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, * to modify the data returned. @@ -1054,7 +1054,29 @@ public abstract class PackageManager { * @see #GET_META_DATA * @see #GET_SHARED_LIBRARY_FILES */ - public abstract ServiceInfo getServiceInfo(ComponentName className, + public abstract ServiceInfo getServiceInfo(ComponentName component, + int flags) throws NameNotFoundException; + + /** + * Retrieve all of the information we know about a particular content + * provider class. + * + *

Throws {@link NameNotFoundException} if a provider with the given + * class name can not be found on the system. + * + * @param component The full component name (i.e. + * com.google.providers.media/com.google.providers.media.MediaProvider) of a + * ContentProvider class. + * @param flags Additional option flags. Use any combination of + * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, + * to modify the data returned. + * + * @return ProviderInfo containing information about the service. + * + * @see #GET_META_DATA + * @see #GET_SHARED_LIBRARY_FILES + */ + public abstract ProviderInfo getProviderInfo(ComponentName component, int flags) throws NameNotFoundException; /** diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java index ab50ba75fe12e..abf8b7cbf998c 100644 --- a/services/java/com/android/server/PackageManagerService.java +++ b/services/java/com/android/server/PackageManagerService.java @@ -1615,6 +1615,18 @@ class PackageManagerService extends IPackageManager.Stub { return null; } + public ProviderInfo getProviderInfo(ComponentName component, int flags) { + synchronized (mPackages) { + PackageParser.Provider p = mProvidersByComponent.get(component); + if (Config.LOGV) Log.v( + TAG, "getProviderInfo " + component + ": " + p); + if (p != null && mSettings.isEnabledLP(p.info, flags)) { + return PackageParser.generateProviderInfo(p, flags); + } + } + return null; + } + public String[] getSystemSharedLibraryNames() { Set libSet; synchronized (mPackages) { diff --git a/test-runner/src/android/test/mock/MockPackageManager.java b/test-runner/src/android/test/mock/MockPackageManager.java index e96173bf5d989..f0cbaa0a69eed 100644 --- a/test-runner/src/android/test/mock/MockPackageManager.java +++ b/test-runner/src/android/test/mock/MockPackageManager.java @@ -126,6 +126,12 @@ public class MockPackageManager extends PackageManager { throw new UnsupportedOperationException(); } + @Override + public ProviderInfo getProviderInfo(ComponentName className, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + @Override public List getInstalledPackages(int flags) { throw new UnsupportedOperationException();