1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.credentials.ui; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Bundle; 22 import android.os.IBinder; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import com.android.internal.util.AnnotationValidations; 27 28 /** 29 * Result data matching {@link BaseDialogResult#RESULT_CODE_PROVIDER_ENABLED}, or {@link 30 * BaseDialogResult#RESULT_CODE_DEFAULT_PROVIDER_CHANGED}. 31 * 32 * @hide 33 */ 34 public final class ProviderDialogResult extends BaseDialogResult implements Parcelable { 35 /** Parses and returns a ProviderDialogResult from the given resultData. */ 36 @Nullable fromResultData(@onNull Bundle resultData)37 public static ProviderDialogResult fromResultData(@NonNull Bundle resultData) { 38 return resultData.getParcelable(EXTRA_PROVIDER_RESULT, ProviderDialogResult.class); 39 } 40 41 /** 42 * Used for the UX to construct the {@code resultData Bundle} to send via the {@code 43 * ResultReceiver}. 44 */ addToBundle( @onNull ProviderDialogResult result, @NonNull Bundle bundle)45 public static void addToBundle( 46 @NonNull ProviderDialogResult result, @NonNull Bundle bundle) { 47 bundle.putParcelable(EXTRA_PROVIDER_RESULT, result); 48 } 49 50 /** 51 * The intent extra key for the {@code ProviderDialogResult} object when the credential 52 * selector activity finishes. 53 */ 54 private static final String EXTRA_PROVIDER_RESULT = 55 "android.credentials.ui.extra.PROVIDER_RESULT"; 56 57 @NonNull 58 private final String mProviderId; 59 ProviderDialogResult(@onNull IBinder requestToken, @NonNull String providerId)60 public ProviderDialogResult(@NonNull IBinder requestToken, @NonNull String providerId) { 61 super(requestToken); 62 mProviderId = providerId; 63 } 64 65 @NonNull getProviderId()66 public String getProviderId() { 67 return mProviderId; 68 } 69 ProviderDialogResult(@onNull Parcel in)70 protected ProviderDialogResult(@NonNull Parcel in) { 71 super(in); 72 String providerId = in.readString8(); 73 mProviderId = providerId; 74 AnnotationValidations.validate(NonNull.class, null, mProviderId); 75 } 76 77 @Override writeToParcel(@onNull Parcel dest, int flags)78 public void writeToParcel(@NonNull Parcel dest, int flags) { 79 super.writeToParcel(dest, flags); 80 dest.writeString8(mProviderId); 81 } 82 83 @Override describeContents()84 public int describeContents() { 85 return 0; 86 } 87 88 public static final @NonNull Creator<ProviderDialogResult> CREATOR = 89 new Creator<ProviderDialogResult>() { 90 @Override 91 public ProviderDialogResult createFromParcel(@NonNull Parcel in) { 92 return new ProviderDialogResult(in); 93 } 94 95 @Override 96 public ProviderDialogResult[] newArray(int size) { 97 return new ProviderDialogResult[size]; 98 } 99 }; 100 } 101