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.os.IBinder; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import com.android.internal.util.AnnotationValidations; 25 26 /** 27 * A request to cancel any ongoing UI matching this request. 28 * 29 * @hide 30 */ 31 public final class CancelUiRequest implements Parcelable { 32 33 /** 34 * The intent extra key for the {@code CancelUiRequest} object when launching the UX 35 * activities. 36 */ 37 @NonNull public static final String EXTRA_CANCEL_UI_REQUEST = 38 "android.credentials.ui.extra.EXTRA_CANCEL_UI_REQUEST"; 39 40 @NonNull 41 private final IBinder mToken; 42 43 private final boolean mShouldShowCancellationUi; 44 45 @NonNull 46 private final String mAppPackageName; 47 48 /** Returns the request token matching the user request that should be cancelled. */ 49 @NonNull getToken()50 public IBinder getToken() { 51 return mToken; 52 } 53 54 @NonNull getAppPackageName()55 public String getAppPackageName() { 56 return mAppPackageName; 57 } 58 59 /** 60 * Returns whether the UI should render a cancellation UI upon the request. If false, the UI 61 * will be silently cancelled. 62 */ shouldShowCancellationUi()63 public boolean shouldShowCancellationUi() { 64 return mShouldShowCancellationUi; 65 } 66 CancelUiRequest(@onNull IBinder token, boolean shouldShowCancellationUi, @NonNull String appPackageName)67 public CancelUiRequest(@NonNull IBinder token, boolean shouldShowCancellationUi, 68 @NonNull String appPackageName) { 69 mToken = token; 70 mShouldShowCancellationUi = shouldShowCancellationUi; 71 mAppPackageName = appPackageName; 72 } 73 CancelUiRequest(@onNull Parcel in)74 private CancelUiRequest(@NonNull Parcel in) { 75 mToken = in.readStrongBinder(); 76 AnnotationValidations.validate(NonNull.class, null, mToken); 77 mShouldShowCancellationUi = in.readBoolean(); 78 mAppPackageName = in.readString8(); 79 AnnotationValidations.validate(NonNull.class, null, mAppPackageName); 80 } 81 82 @Override writeToParcel(@onNull Parcel dest, int flags)83 public void writeToParcel(@NonNull Parcel dest, int flags) { 84 dest.writeStrongBinder(mToken); 85 dest.writeBoolean(mShouldShowCancellationUi); 86 dest.writeString8(mAppPackageName); 87 } 88 89 @Override describeContents()90 public int describeContents() { 91 return 0; 92 } 93 94 @NonNull public static final Creator<CancelUiRequest> CREATOR = new Creator<>() { 95 @Override 96 public CancelUiRequest createFromParcel(@NonNull Parcel in) { 97 return new CancelUiRequest(in); 98 } 99 100 @Override 101 public CancelUiRequest[] newArray(int size) { 102 return new CancelUiRequest[size]; 103 } 104 }; 105 } 106