Loading core/java/android/credentials/ui/Entry.java +32 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,10 @@ package android.credentials.ui; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.PendingIntent; import android.app.slice.Slice; import android.content.Intent; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; Loading Loading @@ -85,6 +88,8 @@ public class Entry implements Parcelable { @NonNull private final String mKey; @NonNull private final String mSubkey; @Nullable private PendingIntent mPendingIntent; @Nullable private Intent mFrameworkExtrasIntent; @NonNull private final Slice mSlice; Loading @@ -100,14 +105,29 @@ public class Entry implements Parcelable { AnnotationValidations.validate(NonNull.class, null, mSubkey); mSlice = slice; AnnotationValidations.validate(NonNull.class, null, mSlice); mPendingIntent = in.readTypedObject(PendingIntent.CREATOR); mFrameworkExtrasIntent = in.readTypedObject(Intent.CREATOR); } /** Constructor to be used for an entry that does not require further activities * to be invoked when selected. */ public Entry(@NonNull String key, @NonNull String subkey, @NonNull Slice slice) { mKey = key; mSubkey = subkey; mSlice = slice; } /** Constructor to be used for an entry that requires a pending intent to be invoked * when clicked. */ public Entry(@NonNull String key, @NonNull String subkey, @NonNull Slice slice, @NonNull PendingIntent pendingIntent, @Nullable Intent intent) { this(key, subkey, slice); mPendingIntent = pendingIntent; mFrameworkExtrasIntent = intent; } /** * Returns the identifier of this entry that's unique within the context of the CredentialManager * request. Loading @@ -133,11 +153,23 @@ public class Entry implements Parcelable { return mSlice; } @Nullable public PendingIntent getPendingIntent() { return mPendingIntent; } @Nullable public Intent getFrameworkExtrasIntent() { return mFrameworkExtrasIntent; } @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeString8(mKey); dest.writeString8(mSubkey); mSlice.writeToParcel(dest, flags); mPendingIntent.writeToParcel(dest, flags); mFrameworkExtrasIntent.writeToParcel(dest, flags); } @Override Loading core/java/android/credentials/ui/ProviderPendingIntentResponse.java 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.credentials.ui; import android.annotation.Nullable; import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.NonNull; /** * Response from a provider's pending intent * * @hide */ public final class ProviderPendingIntentResponse implements Parcelable { private final int mResultCode; @Nullable private final Intent mResultData; public ProviderPendingIntentResponse(int resultCode, @Nullable Intent resultData) { mResultCode = resultCode; mResultData = resultData; } protected ProviderPendingIntentResponse(Parcel in) { mResultCode = in.readInt(); mResultData = in.readTypedObject(Intent.CREATOR); } public static final Creator<ProviderPendingIntentResponse> CREATOR = new Creator<ProviderPendingIntentResponse>() { @Override public ProviderPendingIntentResponse createFromParcel(Parcel in) { return new ProviderPendingIntentResponse(in); } @Override public ProviderPendingIntentResponse[] newArray(int size) { return new ProviderPendingIntentResponse[size]; } }; @Override public int describeContents() { return 0; } @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeSerializable(mResultCode); dest.writeTypedObject(mResultData, flags); } /** Returns the result code associated with this pending intent activity result. */ public int getResultCode() { return mResultCode; } /** Returns the result data associated with this pending intent activity result. */ @NonNull public Intent getResultData() { return mResultData; } } core/java/android/credentials/ui/UserSelectionDialogResult.java +20 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce @NonNull private final String mProviderId; @NonNull private final String mEntryKey; @NonNull private final String mEntrySubkey; @Nullable private ProviderPendingIntentResponse mProviderPendingIntentResponse; public UserSelectionDialogResult( @NonNull IBinder requestToken, @NonNull String providerId, Loading @@ -67,6 +68,17 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce mEntrySubkey = entrySubkey; } public UserSelectionDialogResult( @NonNull IBinder requestToken, @NonNull String providerId, @NonNull String entryKey, @NonNull String entrySubkey, @Nullable ProviderPendingIntentResponse providerPendingIntentResponse) { super(requestToken); mProviderId = providerId; mEntryKey = entryKey; mEntrySubkey = entrySubkey; mProviderPendingIntentResponse = providerPendingIntentResponse; } /** Returns provider package name whose entry was selected by the user. */ @NonNull public String getProviderId() { Loading @@ -85,6 +97,12 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce return mEntrySubkey; } /** Returns the pending intent response from the provider. */ @Nullable public ProviderPendingIntentResponse getPendingIntentProviderResponse() { return mProviderPendingIntentResponse; } protected UserSelectionDialogResult(@NonNull Parcel in) { super(in); String providerId = in.readString8(); Loading @@ -97,6 +115,7 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce AnnotationValidations.validate(NonNull.class, null, mEntryKey); mEntrySubkey = entrySubkey; AnnotationValidations.validate(NonNull.class, null, mEntrySubkey); mProviderPendingIntentResponse = in.readTypedObject(ProviderPendingIntentResponse.CREATOR); } @Override Loading @@ -105,6 +124,7 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce dest.writeString8(mProviderId); dest.writeString8(mEntryKey); dest.writeString8(mEntrySubkey); dest.writeTypedObject(mProviderPendingIntentResponse, flags); } @Override Loading core/java/android/service/credentials/CredentialProviderService.java +11 −2 Original line number Diff line number Diff line Loading @@ -43,8 +43,13 @@ import java.util.Objects; public abstract class CredentialProviderService extends Service { /** Extra to be used by provider to populate the credential when ending the activity started * through the {@code pendingIntent} on the selected {@link SaveEntry}. **/ public static final String EXTRA_SAVE_CREDENTIAL = "android.service.credentials.extra.SAVE_CREDENTIAL"; public static final String EXTRA_CREATE_CREDENTIAL_RESPONSE = "android.service.credentials.extra.CREATE_CREDENTIAL_RESPONSE"; /** Extra to be used by provider to populate the {@link CredentialsDisplayContent} when * an authentication action entry is selected. **/ public static final String EXTRA_GET_CREDENTIALS_DISPLAY_CONTENT = "android.service.credentials.extra.GET_CREDENTIALS_DISPLAY_CONTENT"; /** * Provider must read the value against this extra to receive the complete create credential Loading @@ -53,6 +58,10 @@ public abstract class CredentialProviderService extends Service { public static final String EXTRA_CREATE_CREDENTIAL_REQUEST_PARAMS = "android.service.credentials.extra.CREATE_CREDENTIAL_REQUEST_PARAMS"; /** Extra to be used by the provider when setting the credential result. */ public static final String EXTRA_GET_CREDENTIAL = "android.service.credentials.extra.GET_CREDENTIAL"; private static final String TAG = "CredProviderService"; public static final String CAPABILITY_META_DATA_KEY = "android.credentials.capabilities"; Loading packages/CredentialManager/src/com/android/credentialmanager/DataConverter.kt +10 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.credentialmanager import android.content.ComponentName import android.content.Context import android.content.pm.PackageManager import android.credentials.ui.Entry Loading Loading @@ -146,9 +147,17 @@ class CreateFlowUtils { ): List<com.android.credentialmanager.createflow.EnabledProviderInfo> { // TODO: get from the actual service info val packageManager = context.packageManager return providerDataList.map { val componentName = ComponentName.unflattenFromString(it.providerFlattenedComponentName) var packageName = componentName?.packageName if (componentName == null) { // TODO: Remove once test data is fixed packageName = it.providerFlattenedComponentName } val pkgInfo = packageManager .getPackageInfo(it.providerFlattenedComponentName, .getPackageInfo(packageName!!, PackageManager.PackageInfoFlags.of(0)) com.android.credentialmanager.createflow.EnabledProviderInfo( // TODO: decide what to do when failed to load a provider icon Loading Loading
core/java/android/credentials/ui/Entry.java +32 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,10 @@ package android.credentials.ui; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.PendingIntent; import android.app.slice.Slice; import android.content.Intent; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; Loading Loading @@ -85,6 +88,8 @@ public class Entry implements Parcelable { @NonNull private final String mKey; @NonNull private final String mSubkey; @Nullable private PendingIntent mPendingIntent; @Nullable private Intent mFrameworkExtrasIntent; @NonNull private final Slice mSlice; Loading @@ -100,14 +105,29 @@ public class Entry implements Parcelable { AnnotationValidations.validate(NonNull.class, null, mSubkey); mSlice = slice; AnnotationValidations.validate(NonNull.class, null, mSlice); mPendingIntent = in.readTypedObject(PendingIntent.CREATOR); mFrameworkExtrasIntent = in.readTypedObject(Intent.CREATOR); } /** Constructor to be used for an entry that does not require further activities * to be invoked when selected. */ public Entry(@NonNull String key, @NonNull String subkey, @NonNull Slice slice) { mKey = key; mSubkey = subkey; mSlice = slice; } /** Constructor to be used for an entry that requires a pending intent to be invoked * when clicked. */ public Entry(@NonNull String key, @NonNull String subkey, @NonNull Slice slice, @NonNull PendingIntent pendingIntent, @Nullable Intent intent) { this(key, subkey, slice); mPendingIntent = pendingIntent; mFrameworkExtrasIntent = intent; } /** * Returns the identifier of this entry that's unique within the context of the CredentialManager * request. Loading @@ -133,11 +153,23 @@ public class Entry implements Parcelable { return mSlice; } @Nullable public PendingIntent getPendingIntent() { return mPendingIntent; } @Nullable public Intent getFrameworkExtrasIntent() { return mFrameworkExtrasIntent; } @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeString8(mKey); dest.writeString8(mSubkey); mSlice.writeToParcel(dest, flags); mPendingIntent.writeToParcel(dest, flags); mFrameworkExtrasIntent.writeToParcel(dest, flags); } @Override Loading
core/java/android/credentials/ui/ProviderPendingIntentResponse.java 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.credentials.ui; import android.annotation.Nullable; import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.NonNull; /** * Response from a provider's pending intent * * @hide */ public final class ProviderPendingIntentResponse implements Parcelable { private final int mResultCode; @Nullable private final Intent mResultData; public ProviderPendingIntentResponse(int resultCode, @Nullable Intent resultData) { mResultCode = resultCode; mResultData = resultData; } protected ProviderPendingIntentResponse(Parcel in) { mResultCode = in.readInt(); mResultData = in.readTypedObject(Intent.CREATOR); } public static final Creator<ProviderPendingIntentResponse> CREATOR = new Creator<ProviderPendingIntentResponse>() { @Override public ProviderPendingIntentResponse createFromParcel(Parcel in) { return new ProviderPendingIntentResponse(in); } @Override public ProviderPendingIntentResponse[] newArray(int size) { return new ProviderPendingIntentResponse[size]; } }; @Override public int describeContents() { return 0; } @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeSerializable(mResultCode); dest.writeTypedObject(mResultData, flags); } /** Returns the result code associated with this pending intent activity result. */ public int getResultCode() { return mResultCode; } /** Returns the result data associated with this pending intent activity result. */ @NonNull public Intent getResultData() { return mResultData; } }
core/java/android/credentials/ui/UserSelectionDialogResult.java +20 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce @NonNull private final String mProviderId; @NonNull private final String mEntryKey; @NonNull private final String mEntrySubkey; @Nullable private ProviderPendingIntentResponse mProviderPendingIntentResponse; public UserSelectionDialogResult( @NonNull IBinder requestToken, @NonNull String providerId, Loading @@ -67,6 +68,17 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce mEntrySubkey = entrySubkey; } public UserSelectionDialogResult( @NonNull IBinder requestToken, @NonNull String providerId, @NonNull String entryKey, @NonNull String entrySubkey, @Nullable ProviderPendingIntentResponse providerPendingIntentResponse) { super(requestToken); mProviderId = providerId; mEntryKey = entryKey; mEntrySubkey = entrySubkey; mProviderPendingIntentResponse = providerPendingIntentResponse; } /** Returns provider package name whose entry was selected by the user. */ @NonNull public String getProviderId() { Loading @@ -85,6 +97,12 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce return mEntrySubkey; } /** Returns the pending intent response from the provider. */ @Nullable public ProviderPendingIntentResponse getPendingIntentProviderResponse() { return mProviderPendingIntentResponse; } protected UserSelectionDialogResult(@NonNull Parcel in) { super(in); String providerId = in.readString8(); Loading @@ -97,6 +115,7 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce AnnotationValidations.validate(NonNull.class, null, mEntryKey); mEntrySubkey = entrySubkey; AnnotationValidations.validate(NonNull.class, null, mEntrySubkey); mProviderPendingIntentResponse = in.readTypedObject(ProviderPendingIntentResponse.CREATOR); } @Override Loading @@ -105,6 +124,7 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce dest.writeString8(mProviderId); dest.writeString8(mEntryKey); dest.writeString8(mEntrySubkey); dest.writeTypedObject(mProviderPendingIntentResponse, flags); } @Override Loading
core/java/android/service/credentials/CredentialProviderService.java +11 −2 Original line number Diff line number Diff line Loading @@ -43,8 +43,13 @@ import java.util.Objects; public abstract class CredentialProviderService extends Service { /** Extra to be used by provider to populate the credential when ending the activity started * through the {@code pendingIntent} on the selected {@link SaveEntry}. **/ public static final String EXTRA_SAVE_CREDENTIAL = "android.service.credentials.extra.SAVE_CREDENTIAL"; public static final String EXTRA_CREATE_CREDENTIAL_RESPONSE = "android.service.credentials.extra.CREATE_CREDENTIAL_RESPONSE"; /** Extra to be used by provider to populate the {@link CredentialsDisplayContent} when * an authentication action entry is selected. **/ public static final String EXTRA_GET_CREDENTIALS_DISPLAY_CONTENT = "android.service.credentials.extra.GET_CREDENTIALS_DISPLAY_CONTENT"; /** * Provider must read the value against this extra to receive the complete create credential Loading @@ -53,6 +58,10 @@ public abstract class CredentialProviderService extends Service { public static final String EXTRA_CREATE_CREDENTIAL_REQUEST_PARAMS = "android.service.credentials.extra.CREATE_CREDENTIAL_REQUEST_PARAMS"; /** Extra to be used by the provider when setting the credential result. */ public static final String EXTRA_GET_CREDENTIAL = "android.service.credentials.extra.GET_CREDENTIAL"; private static final String TAG = "CredProviderService"; public static final String CAPABILITY_META_DATA_KEY = "android.credentials.capabilities"; Loading
packages/CredentialManager/src/com/android/credentialmanager/DataConverter.kt +10 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.credentialmanager import android.content.ComponentName import android.content.Context import android.content.pm.PackageManager import android.credentials.ui.Entry Loading Loading @@ -146,9 +147,17 @@ class CreateFlowUtils { ): List<com.android.credentialmanager.createflow.EnabledProviderInfo> { // TODO: get from the actual service info val packageManager = context.packageManager return providerDataList.map { val componentName = ComponentName.unflattenFromString(it.providerFlattenedComponentName) var packageName = componentName?.packageName if (componentName == null) { // TODO: Remove once test data is fixed packageName = it.providerFlattenedComponentName } val pkgInfo = packageManager .getPackageInfo(it.providerFlattenedComponentName, .getPackageInfo(packageName!!, PackageManager.PackageInfoFlags.of(0)) com.android.credentialmanager.createflow.EnabledProviderInfo( // TODO: decide what to do when failed to load a provider icon Loading