diff options
| -rw-r--r-- | services/credentials/java/com/android/server/credentials/CredentialManagerService.java | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java index 8728c3c64715..57b3c0d431a2 100644 --- a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java +++ b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java @@ -25,6 +25,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; +import android.provider.Settings; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageInfo; @@ -482,7 +483,7 @@ public final class CredentialManagerService callback, request, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), - getEnabledProviders(), + getEnabledProvidersForUser(userId), CancellationSignal.fromTransport(cancelTransport), timestampBegan); addSessionLocked(userId, session); @@ -537,7 +538,7 @@ public final class CredentialManagerService getCredentialCallback, request, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), - getEnabledProviders(), + getEnabledProvidersForUser(userId), CancellationSignal.fromTransport(cancelTransport), timestampBegan, prepareGetCredentialCallback); @@ -655,7 +656,7 @@ public final class CredentialManagerService request, callback, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), - getEnabledProviders(), + getEnabledProvidersForUser(userId), getPrimaryProvidersForUserId(getContext(), userId), CancellationSignal.fromTransport(cancelTransport), timestampBegan); @@ -804,7 +805,7 @@ public final class CredentialManagerService verifyGetProvidersPermission(); return CredentialProviderInfoFactory.getCredentialProviderServices( - mContext, userId, providerFilter, getEnabledProviders(), + mContext, userId, providerFilter, getEnabledProvidersForUser(userId), getPrimaryProvidersForUserId(mContext, userId)); } @@ -815,7 +816,7 @@ public final class CredentialManagerService final int userId = UserHandle.getCallingUserId(); return CredentialProviderInfoFactory.getCredentialProviderServicesForTesting( - mContext, userId, providerFilter, getEnabledProviders(), + mContext, userId, providerFilter, getEnabledProvidersForUser(userId), getPrimaryProvidersForUserId(mContext, userId)); } @@ -832,24 +833,26 @@ public final class CredentialManagerService } } - @SuppressWarnings("GuardedBy") // ErrorProne requires service.mLock which is the same - // this.mLock - private Set<ComponentName> getEnabledProviders() { + private Set<ComponentName> getEnabledProvidersForUser(int userId) { + final int resolvedUserId = ActivityManager.handleIncomingUser( + Binder.getCallingPid(), Binder.getCallingUid(), + userId, false, false, + "getEnabledProvidersForUser", null); + Set<ComponentName> enabledProviders = new HashSet<>(); - synchronized (mLock) { - runForUser( - (service) -> { - try { - enabledProviders.add( - service.getCredentialProviderInfo() - .getServiceInfo().getComponentName()); - } catch (NullPointerException e) { - // Safe check - Slog.e(TAG, "Skipping provider as either the providerInfo" - + " or serviceInfo is null - weird"); - } - }); + String directValue = Settings.Secure.getStringForUser( + mContext.getContentResolver(), Settings.Secure.CREDENTIAL_SERVICE, resolvedUserId); + + if (!TextUtils.isEmpty(directValue)) { + String[] components = directValue.split(":"); + for (String componentString : components) { + ComponentName component = ComponentName.unflattenFromString(componentString); + if (component != null) { + enabledProviders.add(component); + } + } } + return enabledProviders; } @@ -879,7 +882,7 @@ public final class CredentialManagerService callback, request, constructCallingAppInfo(callingPackage, userId, null), - getEnabledProviders(), + getEnabledProvidersForUser(userId), CancellationSignal.fromTransport(cancelTransport), timestampBegan); addSessionLocked(userId, session); |