Loading core/java/android/credentials/CredentialManager.java +8 −1 Original line number Diff line number Diff line Loading @@ -355,7 +355,11 @@ public final class CredentialManager { * Sets a list of all user configurable credential providers registered on the system. This API * is intended for settings apps. * * @param providers the list of enabled providers * @param primaryProviders the primary providers that user selected for saving credentials. In * the most case, there should be only one primary provider, However, * if there are more than one CredentialProviderService in the same APK, * they should be passed in altogether. * @param providers the list of enabled providers. * @param userId the user ID to configure credential manager for * @param executor the callback will take place on this {@link Executor} * @param callback the callback invoked when the request succeeds or fails Loading @@ -363,6 +367,7 @@ public final class CredentialManager { */ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setEnabledProviders( @NonNull List<String> primaryProviders, @NonNull List<String> providers, int userId, @CallbackExecutor @NonNull Executor executor, Loading @@ -370,9 +375,11 @@ public final class CredentialManager { requireNonNull(executor, "executor must not be null"); requireNonNull(callback, "callback must not be null"); requireNonNull(providers, "providers must not be null"); requireNonNull(primaryProviders, "primaryProviders must not be null"); try { mService.setEnabledProviders( primaryProviders, providers, userId, new SetEnabledProvidersTransport(executor, callback)); } catch (RemoteException e) { e.rethrowFromSystemServer(); Loading core/java/android/credentials/CredentialProviderInfo.java +31 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ public final class CredentialProviderInfo implements Parcelable { @Nullable private CharSequence mSettingsSubtitle = null; private final boolean mIsSystemProvider; private final boolean mIsEnabled; private final boolean mIsPrimary; /** * Constructs an information instance of the credential provider. Loading @@ -58,6 +59,7 @@ public final class CredentialProviderInfo implements Parcelable { mIsSystemProvider = builder.mIsSystemProvider; mSettingsSubtitle = builder.mSettingsSubtitle; mIsEnabled = builder.mIsEnabled; mIsPrimary = builder.mIsPrimary; mOverrideLabel = builder.mOverrideLabel; } Loading Loading @@ -108,6 +110,15 @@ public final class CredentialProviderInfo implements Parcelable { return mIsEnabled; } /** * Returns whether the provider is set as primary by the user. * * @hide */ public boolean isPrimary() { return mIsPrimary; } /** Returns the settings subtitle. */ @Nullable public CharSequence getSettingsSubtitle() { Loading @@ -125,6 +136,7 @@ public final class CredentialProviderInfo implements Parcelable { dest.writeTypedObject(mServiceInfo, flags); dest.writeBoolean(mIsSystemProvider); dest.writeBoolean(mIsEnabled); dest.writeBoolean(mIsPrimary); TextUtils.writeToParcel(mOverrideLabel, dest, flags); TextUtils.writeToParcel(mSettingsSubtitle, dest, flags); Loading @@ -149,6 +161,9 @@ public final class CredentialProviderInfo implements Parcelable { + "isEnabled=" + mIsEnabled + ", " + "isPrimary=" + mIsPrimary + ", " + "overrideLabel=" + mOverrideLabel + ", " Loading @@ -164,6 +179,7 @@ public final class CredentialProviderInfo implements Parcelable { mServiceInfo = in.readTypedObject(ServiceInfo.CREATOR); mIsSystemProvider = in.readBoolean(); mIsEnabled = in.readBoolean(); mIsPrimary = in.readBoolean(); mOverrideLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); mSettingsSubtitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); Loading Loading @@ -193,6 +209,7 @@ public final class CredentialProviderInfo implements Parcelable { private boolean mIsSystemProvider = false; @Nullable private CharSequence mSettingsSubtitle = null; private boolean mIsEnabled = false; private boolean mIsPrimary = false; @Nullable private CharSequence mOverrideLabel = null; /** Loading Loading @@ -248,6 +265,20 @@ public final class CredentialProviderInfo implements Parcelable { return this; } /** * Sets whether it is set as primary by the user. * * <p>Primary provider will be used for saving credentials by default. In most cases, there * should only one primary provider exist. However, if there are multiple credential * providers exist in the same package, all of them will be marked as primary. * * @hide */ public @NonNull Builder setPrimary(boolean isPrimary) { mIsPrimary = isPrimary; return this; } /** Builds a new {@link CredentialProviderInfo} instance. */ public @NonNull CredentialProviderInfo build() { return new CredentialProviderInfo(this); Loading core/java/android/credentials/ICredentialManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ interface ICredentialManager { @nullable ICancellationSignal clearCredentialState(in ClearCredentialStateRequest request, in IClearCredentialStateCallback callback, String callingPackage); void setEnabledProviders(in List<String> providers, in int userId, in ISetEnabledProvidersCallback callback); void setEnabledProviders(in List<String> primaryProviders, in List<String> providers, in int userId, in ISetEnabledProvidersCallback callback); void registerCredentialDescription(in RegisterCredentialDescriptionRequest request, String callingPackage); Loading core/java/android/service/credentials/CredentialProviderInfoFactory.java +46 −26 Original line number Diff line number Diff line Loading @@ -80,8 +80,7 @@ public final class CredentialProviderInfoFactory { * @param userId the android userId for which the current process is running * @param isSystemProvider whether this provider is a system provider * @throws PackageManager.NameNotFoundException If provider service is not found * @throws SecurityException If provider does not require the relevant * permission * @throws SecurityException If provider does not require the relevant permission */ public static CredentialProviderInfo create( @NonNull Context context, Loading @@ -94,20 +93,19 @@ public final class CredentialProviderInfoFactory { getServiceInfoOrThrow(serviceComponent, userId), isSystemProvider, /* disableSystemAppVerificationForTests= */ false, /* isEnabled= */ false); /* isEnabled= */ false, /* isPrimary= */ false); } /** * Constructs an information instance of the credential provider. * * @param context the context object * @param serviceInfo the service info for the provider app. This must * be retrieved from the * @param serviceInfo the service info for the provider app. This must be retrieved from the * {@code PackageManager} * @param isSystemProvider whether the provider app is a system provider * @param disableSystemAppVerificationForTests whether to disable system app permission * verification so that tests can install system * providers * verification so that tests can install system providers * @param isEnabled whether the user enabled this provider * @throws SecurityException If provider does not require the relevant permission */ Loading @@ -116,7 +114,8 @@ public final class CredentialProviderInfoFactory { @NonNull ServiceInfo serviceInfo, boolean isSystemProvider, boolean disableSystemAppVerificationForTests, boolean isEnabled) boolean isEnabled, boolean isPrimary) throws SecurityException { verifyProviderPermission(serviceInfo); if (isSystemProvider) { Loading @@ -131,6 +130,7 @@ public final class CredentialProviderInfoFactory { return populateMetadata(context, serviceInfo) .setSystemProvider(isSystemProvider) .setEnabled(isEnabled) .setPrimary(isPrimary) .build(); } Loading Loading @@ -168,7 +168,9 @@ public final class CredentialProviderInfoFactory { Slog.w(TAG, "Context is null in isSystemProviderWithValidPermission"); return false; } return PermissionUtils.hasPermission(context, serviceInfo.packageName, return PermissionUtils.hasPermission( context, serviceInfo.packageName, Manifest.permission.PROVIDE_DEFAULT_ENABLED_CREDENTIAL_SERVICE); } Loading @@ -181,8 +183,11 @@ public final class CredentialProviderInfoFactory { if (disableSystemAppVerificationForTests) { Bundle metadata = serviceInfo.metaData; if (metadata == null) { Slog.w(TAG, "metadata is null while reading " + "TEST_SYSTEM_PROVIDER_META_DATA_KEY: " + serviceInfo); Slog.w( TAG, "metadata is null while reading " + "TEST_SYSTEM_PROVIDER_META_DATA_KEY: " + serviceInfo); return false; } return metadata.getBoolean( Loading Loading @@ -215,7 +220,9 @@ public final class CredentialProviderInfoFactory { // 3. Stop if we are missing data. if (resources == null) { Slog.w(TAG, "Resources are null for the serviceInfo being processed: " Slog.w( TAG, "Resources are null for the serviceInfo being processed: " + serviceInfo.getComponentName()); return builder; } Loading Loading @@ -408,7 +415,7 @@ public final class CredentialProviderInfoFactory { si, /* isSystemProvider= */ true, disableSystemAppVerificationForTests, enabledServices.contains(si.getComponentName())); enabledServices.contains(si.getComponentName()), false); if (cpi.isSystemProvider()) { providerInfos.add(cpi); } else { Loading Loading @@ -446,7 +453,8 @@ public final class CredentialProviderInfoFactory { @NonNull Context context, int userId, int providerFilter, Set<ComponentName> enabledServices) { Set<ComponentName> enabledServices, Set<String> primaryServices) { requireNonNull(context, "context must not be null"); // Get the device policy. Loading @@ -459,7 +467,11 @@ public final class CredentialProviderInfoFactory { context, pp, disableSystemAppVerificationForTests, providerFilter); generator.addUserProviders( getUserProviders( context, userId, disableSystemAppVerificationForTests, enabledServices)); context, userId, disableSystemAppVerificationForTests, enabledServices, primaryServices)); generator.addSystemProviders( getAvailableSystemServices( context, userId, disableSystemAppVerificationForTests, enabledServices)); Loading @@ -475,7 +487,8 @@ public final class CredentialProviderInfoFactory { @NonNull Context context, int userId, int providerFilter, Set<ComponentName> enabledServices) { Set<ComponentName> enabledServices, Set<String> primaryServices) { requireNonNull(context, "context must not be null"); // Get the device policy. Loading @@ -488,7 +501,11 @@ public final class CredentialProviderInfoFactory { context, pp, disableSystemAppVerificationForTests, providerFilter); generator.addUserProviders( getUserProviders( context, userId, disableSystemAppVerificationForTests, enabledServices)); context, userId, disableSystemAppVerificationForTests, enabledServices, primaryServices)); generator.addSystemProviders( getAvailableSystemServices( context, userId, disableSystemAppVerificationForTests, enabledServices)); Loading Loading @@ -581,7 +598,8 @@ public final class CredentialProviderInfoFactory { @NonNull Context context, @UserIdInt int userId, boolean disableSystemAppVerificationForTests, Set<ComponentName> enabledServices) { Set<ComponentName> enabledServices, Set<String> primaryServices) { final List<CredentialProviderInfo> services = new ArrayList<>(); final List<ResolveInfo> resolveInfos = context.getPackageManager() Loading @@ -603,7 +621,9 @@ public final class CredentialProviderInfoFactory { serviceInfo, /* isSystemProvider= */ false, disableSystemAppVerificationForTests, enabledServices.contains(serviceInfo.getComponentName())); enabledServices.contains(serviceInfo.getComponentName()), primaryServices.contains( serviceInfo.getComponentName().flattenToString())); if (!cpi.isSystemProvider()) { services.add(cpi); } Loading core/tests/coretests/src/android/credentials/CredentialManagerTest.java +243 −194 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/credentials/CredentialManager.java +8 −1 Original line number Diff line number Diff line Loading @@ -355,7 +355,11 @@ public final class CredentialManager { * Sets a list of all user configurable credential providers registered on the system. This API * is intended for settings apps. * * @param providers the list of enabled providers * @param primaryProviders the primary providers that user selected for saving credentials. In * the most case, there should be only one primary provider, However, * if there are more than one CredentialProviderService in the same APK, * they should be passed in altogether. * @param providers the list of enabled providers. * @param userId the user ID to configure credential manager for * @param executor the callback will take place on this {@link Executor} * @param callback the callback invoked when the request succeeds or fails Loading @@ -363,6 +367,7 @@ public final class CredentialManager { */ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setEnabledProviders( @NonNull List<String> primaryProviders, @NonNull List<String> providers, int userId, @CallbackExecutor @NonNull Executor executor, Loading @@ -370,9 +375,11 @@ public final class CredentialManager { requireNonNull(executor, "executor must not be null"); requireNonNull(callback, "callback must not be null"); requireNonNull(providers, "providers must not be null"); requireNonNull(primaryProviders, "primaryProviders must not be null"); try { mService.setEnabledProviders( primaryProviders, providers, userId, new SetEnabledProvidersTransport(executor, callback)); } catch (RemoteException e) { e.rethrowFromSystemServer(); Loading
core/java/android/credentials/CredentialProviderInfo.java +31 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ public final class CredentialProviderInfo implements Parcelable { @Nullable private CharSequence mSettingsSubtitle = null; private final boolean mIsSystemProvider; private final boolean mIsEnabled; private final boolean mIsPrimary; /** * Constructs an information instance of the credential provider. Loading @@ -58,6 +59,7 @@ public final class CredentialProviderInfo implements Parcelable { mIsSystemProvider = builder.mIsSystemProvider; mSettingsSubtitle = builder.mSettingsSubtitle; mIsEnabled = builder.mIsEnabled; mIsPrimary = builder.mIsPrimary; mOverrideLabel = builder.mOverrideLabel; } Loading Loading @@ -108,6 +110,15 @@ public final class CredentialProviderInfo implements Parcelable { return mIsEnabled; } /** * Returns whether the provider is set as primary by the user. * * @hide */ public boolean isPrimary() { return mIsPrimary; } /** Returns the settings subtitle. */ @Nullable public CharSequence getSettingsSubtitle() { Loading @@ -125,6 +136,7 @@ public final class CredentialProviderInfo implements Parcelable { dest.writeTypedObject(mServiceInfo, flags); dest.writeBoolean(mIsSystemProvider); dest.writeBoolean(mIsEnabled); dest.writeBoolean(mIsPrimary); TextUtils.writeToParcel(mOverrideLabel, dest, flags); TextUtils.writeToParcel(mSettingsSubtitle, dest, flags); Loading @@ -149,6 +161,9 @@ public final class CredentialProviderInfo implements Parcelable { + "isEnabled=" + mIsEnabled + ", " + "isPrimary=" + mIsPrimary + ", " + "overrideLabel=" + mOverrideLabel + ", " Loading @@ -164,6 +179,7 @@ public final class CredentialProviderInfo implements Parcelable { mServiceInfo = in.readTypedObject(ServiceInfo.CREATOR); mIsSystemProvider = in.readBoolean(); mIsEnabled = in.readBoolean(); mIsPrimary = in.readBoolean(); mOverrideLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); mSettingsSubtitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); Loading Loading @@ -193,6 +209,7 @@ public final class CredentialProviderInfo implements Parcelable { private boolean mIsSystemProvider = false; @Nullable private CharSequence mSettingsSubtitle = null; private boolean mIsEnabled = false; private boolean mIsPrimary = false; @Nullable private CharSequence mOverrideLabel = null; /** Loading Loading @@ -248,6 +265,20 @@ public final class CredentialProviderInfo implements Parcelable { return this; } /** * Sets whether it is set as primary by the user. * * <p>Primary provider will be used for saving credentials by default. In most cases, there * should only one primary provider exist. However, if there are multiple credential * providers exist in the same package, all of them will be marked as primary. * * @hide */ public @NonNull Builder setPrimary(boolean isPrimary) { mIsPrimary = isPrimary; return this; } /** Builds a new {@link CredentialProviderInfo} instance. */ public @NonNull CredentialProviderInfo build() { return new CredentialProviderInfo(this); Loading
core/java/android/credentials/ICredentialManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ interface ICredentialManager { @nullable ICancellationSignal clearCredentialState(in ClearCredentialStateRequest request, in IClearCredentialStateCallback callback, String callingPackage); void setEnabledProviders(in List<String> providers, in int userId, in ISetEnabledProvidersCallback callback); void setEnabledProviders(in List<String> primaryProviders, in List<String> providers, in int userId, in ISetEnabledProvidersCallback callback); void registerCredentialDescription(in RegisterCredentialDescriptionRequest request, String callingPackage); Loading
core/java/android/service/credentials/CredentialProviderInfoFactory.java +46 −26 Original line number Diff line number Diff line Loading @@ -80,8 +80,7 @@ public final class CredentialProviderInfoFactory { * @param userId the android userId for which the current process is running * @param isSystemProvider whether this provider is a system provider * @throws PackageManager.NameNotFoundException If provider service is not found * @throws SecurityException If provider does not require the relevant * permission * @throws SecurityException If provider does not require the relevant permission */ public static CredentialProviderInfo create( @NonNull Context context, Loading @@ -94,20 +93,19 @@ public final class CredentialProviderInfoFactory { getServiceInfoOrThrow(serviceComponent, userId), isSystemProvider, /* disableSystemAppVerificationForTests= */ false, /* isEnabled= */ false); /* isEnabled= */ false, /* isPrimary= */ false); } /** * Constructs an information instance of the credential provider. * * @param context the context object * @param serviceInfo the service info for the provider app. This must * be retrieved from the * @param serviceInfo the service info for the provider app. This must be retrieved from the * {@code PackageManager} * @param isSystemProvider whether the provider app is a system provider * @param disableSystemAppVerificationForTests whether to disable system app permission * verification so that tests can install system * providers * verification so that tests can install system providers * @param isEnabled whether the user enabled this provider * @throws SecurityException If provider does not require the relevant permission */ Loading @@ -116,7 +114,8 @@ public final class CredentialProviderInfoFactory { @NonNull ServiceInfo serviceInfo, boolean isSystemProvider, boolean disableSystemAppVerificationForTests, boolean isEnabled) boolean isEnabled, boolean isPrimary) throws SecurityException { verifyProviderPermission(serviceInfo); if (isSystemProvider) { Loading @@ -131,6 +130,7 @@ public final class CredentialProviderInfoFactory { return populateMetadata(context, serviceInfo) .setSystemProvider(isSystemProvider) .setEnabled(isEnabled) .setPrimary(isPrimary) .build(); } Loading Loading @@ -168,7 +168,9 @@ public final class CredentialProviderInfoFactory { Slog.w(TAG, "Context is null in isSystemProviderWithValidPermission"); return false; } return PermissionUtils.hasPermission(context, serviceInfo.packageName, return PermissionUtils.hasPermission( context, serviceInfo.packageName, Manifest.permission.PROVIDE_DEFAULT_ENABLED_CREDENTIAL_SERVICE); } Loading @@ -181,8 +183,11 @@ public final class CredentialProviderInfoFactory { if (disableSystemAppVerificationForTests) { Bundle metadata = serviceInfo.metaData; if (metadata == null) { Slog.w(TAG, "metadata is null while reading " + "TEST_SYSTEM_PROVIDER_META_DATA_KEY: " + serviceInfo); Slog.w( TAG, "metadata is null while reading " + "TEST_SYSTEM_PROVIDER_META_DATA_KEY: " + serviceInfo); return false; } return metadata.getBoolean( Loading Loading @@ -215,7 +220,9 @@ public final class CredentialProviderInfoFactory { // 3. Stop if we are missing data. if (resources == null) { Slog.w(TAG, "Resources are null for the serviceInfo being processed: " Slog.w( TAG, "Resources are null for the serviceInfo being processed: " + serviceInfo.getComponentName()); return builder; } Loading Loading @@ -408,7 +415,7 @@ public final class CredentialProviderInfoFactory { si, /* isSystemProvider= */ true, disableSystemAppVerificationForTests, enabledServices.contains(si.getComponentName())); enabledServices.contains(si.getComponentName()), false); if (cpi.isSystemProvider()) { providerInfos.add(cpi); } else { Loading Loading @@ -446,7 +453,8 @@ public final class CredentialProviderInfoFactory { @NonNull Context context, int userId, int providerFilter, Set<ComponentName> enabledServices) { Set<ComponentName> enabledServices, Set<String> primaryServices) { requireNonNull(context, "context must not be null"); // Get the device policy. Loading @@ -459,7 +467,11 @@ public final class CredentialProviderInfoFactory { context, pp, disableSystemAppVerificationForTests, providerFilter); generator.addUserProviders( getUserProviders( context, userId, disableSystemAppVerificationForTests, enabledServices)); context, userId, disableSystemAppVerificationForTests, enabledServices, primaryServices)); generator.addSystemProviders( getAvailableSystemServices( context, userId, disableSystemAppVerificationForTests, enabledServices)); Loading @@ -475,7 +487,8 @@ public final class CredentialProviderInfoFactory { @NonNull Context context, int userId, int providerFilter, Set<ComponentName> enabledServices) { Set<ComponentName> enabledServices, Set<String> primaryServices) { requireNonNull(context, "context must not be null"); // Get the device policy. Loading @@ -488,7 +501,11 @@ public final class CredentialProviderInfoFactory { context, pp, disableSystemAppVerificationForTests, providerFilter); generator.addUserProviders( getUserProviders( context, userId, disableSystemAppVerificationForTests, enabledServices)); context, userId, disableSystemAppVerificationForTests, enabledServices, primaryServices)); generator.addSystemProviders( getAvailableSystemServices( context, userId, disableSystemAppVerificationForTests, enabledServices)); Loading Loading @@ -581,7 +598,8 @@ public final class CredentialProviderInfoFactory { @NonNull Context context, @UserIdInt int userId, boolean disableSystemAppVerificationForTests, Set<ComponentName> enabledServices) { Set<ComponentName> enabledServices, Set<String> primaryServices) { final List<CredentialProviderInfo> services = new ArrayList<>(); final List<ResolveInfo> resolveInfos = context.getPackageManager() Loading @@ -603,7 +621,9 @@ public final class CredentialProviderInfoFactory { serviceInfo, /* isSystemProvider= */ false, disableSystemAppVerificationForTests, enabledServices.contains(serviceInfo.getComponentName())); enabledServices.contains(serviceInfo.getComponentName()), primaryServices.contains( serviceInfo.getComponentName().flattenToString())); if (!cpi.isSystemProvider()) { services.add(cpi); } Loading
core/tests/coretests/src/android/credentials/CredentialManagerTest.java +243 −194 File changed.Preview size limit exceeded, changes collapsed. Show changes