Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bd5f497 authored by Becca Hughes's avatar Becca Hughes Committed by Android (Google) Code Review
Browse files

Merge "Fix the exception thrown when API called bug" into main

parents 19c9e983 da68db7c
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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
     */
+30 −26
Original line number Diff line number Diff line
@@ -862,38 +862,42 @@ 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.
            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);
                            Slog.w(
                                    TAG,
                                    "isEnabledCredentialProviderService: Component name does "
                                            + "not match package name.");
                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.SUCCESS, callingUid);
                        return true;
                    }
                }
                      ApiStatus.FAILURE, callingUid);
                throw new IllegalArgumentException("provided component name does not match"
                        + " does not match requesting component");
            }

            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
        public List<CredentialProviderInfo> getCredentialProviderServices(