diff --git a/core/java/android/credentials/CredentialManager.java b/core/java/android/credentials/CredentialManager.java index 524afe975d73e97d18184af7474a9122deca725b..ad3ccc41cf6d8ad8d75079801cbbc5d314a56856 100644 --- a/core/java/android/credentials/CredentialManager.java +++ b/core/java/android/credentials/CredentialManager.java @@ -437,7 +437,14 @@ public final class CredentialManager { * Returns {@code true} if the calling application provides a CredentialProviderService that is * enabled for the current user, or {@code false} otherwise. CredentialProviderServices are * enabled on a per-service basis so the individual component name of the service should be - * passed in here. + * passed in here. <strong>Usage of this API is discouraged as it is not fully functional, and + * may throw a NullPointerException on certain devices and/or API versions.</strong> + * + * @throws IllegalArgumentException if the componentName package does not match the calling + * package name this call will throw an exception + * + * @throws NullPointerException Usage of this API is discouraged as it is not fully + * functional, and may throw a NullPointerException on certain devices and/or API versions * * @param componentName the component name to check is enabled */ diff --git a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java index a4adf5866f3d39fd265b0f59257c72f77f86ebc0..627461a2c6ed4703f1cd0bfe380bfc024684b36e 100644 --- a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java +++ b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java @@ -862,37 +862,41 @@ public final class CredentialManagerService Slog.i(TAG, "isEnabledCredentialProviderService with componentName: " + componentName.flattenToString()); - // TODO(253157366): Check additional set of services. final int userId = UserHandle.getCallingUserId(); final int callingUid = Binder.getCallingUid(); enforceCallingPackage(callingPackage, callingUid); - synchronized (mLock) { - final List<CredentialManagerServiceImpl> services = - getServiceListForUserLocked(userId); - for (CredentialManagerServiceImpl s : services) { - final ComponentName serviceComponentName = s.getServiceComponentName(); - - if (serviceComponentName.equals(componentName)) { - if (!s.getServicePackageName().equals(callingPackage)) { - // The component name and the package name do not match. - MetricUtilities.logApiCalledSimpleV2( - ApiName.IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE, - ApiStatus.FAILURE, callingUid); - Slog.w( - TAG, - "isEnabledCredentialProviderService: Component name does " - + "not match package name."); - return false; - } - MetricUtilities.logApiCalledSimpleV2( - ApiName.IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE, - ApiStatus.SUCCESS, callingUid); - return true; - } - } + + if (componentName == null) { + Slog.w(TAG, "isEnabledCredentialProviderService componentName is null"); + // If the component name was not specified then throw an error and + // record a failure because the request failed due to invalid input. + MetricUtilities.logApiCalledSimpleV2( + ApiName.IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE, + ApiStatus.FAILURE, callingUid); + return false; + } + + if (!componentName.getPackageName().equals(callingPackage)) { + Slog.w(TAG, "isEnabledCredentialProviderService component name" + + " does not match requested component"); + // If the requested component name package name does not match + // the calling package then throw an error and record a failure + // metric (because the request failed due to invalid input). + MetricUtilities.logApiCalledSimpleV2( + ApiName.IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE, + ApiStatus.FAILURE, callingUid); + throw new IllegalArgumentException("provided component name does not match" + + " does not match requesting component"); } - return false; + final Set<ComponentName> enabledProviders = getEnabledProvidersForUser(userId); + MetricUtilities.logApiCalledSimpleV2( + ApiName.IS_ENABLED_CREDENTIAL_PROVIDER_SERVICE, + ApiStatus.SUCCESS, callingUid); + if (enabledProviders == null) { + return false; + } + return enabledProviders.contains(componentName); } @Override