1 /* 2 * Copyright (C) 2024 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.selection; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.Intent; 22 23 /** 24 * Result of creating a Credential Manager UI intent. 25 * 26 * @hide 27 */ 28 public final class IntentCreationResult { 29 @NonNull 30 private final Intent mIntent; 31 @Nullable 32 private final String mFallbackUiPackageName; 33 @Nullable 34 private final String mOemUiPackageName; 35 @NonNull 36 private final OemUiUsageStatus mOemUiUsageStatus; 37 IntentCreationResult(@onNull Intent intent, @Nullable String fallbackUiPackageName, @Nullable String oemUiPackageName, OemUiUsageStatus oemUiUsageStatus)38 private IntentCreationResult(@NonNull Intent intent, @Nullable String fallbackUiPackageName, 39 @Nullable String oemUiPackageName, OemUiUsageStatus oemUiUsageStatus) { 40 mIntent = intent; 41 mFallbackUiPackageName = fallbackUiPackageName; 42 mOemUiPackageName = oemUiPackageName; 43 mOemUiUsageStatus = oemUiUsageStatus; 44 } 45 46 /** Returns the UI intent. */ 47 @NonNull getIntent()48 public Intent getIntent() { 49 return mIntent; 50 } 51 52 /** 53 * Returns the result of attempting to use the config_oemCredentialManagerDialogComponent 54 * as the Credential Manager UI. 55 */ 56 @NonNull getOemUiUsageStatus()57 public OemUiUsageStatus getOemUiUsageStatus() { 58 return mOemUiUsageStatus; 59 } 60 61 /** 62 * Returns the package name of the ui component specified in 63 * config_fallbackCredentialManagerDialogComponent, or null if unspecified / not parsable 64 * successfully. 65 */ 66 @Nullable getFallbackUiPackageName()67 public String getFallbackUiPackageName() { 68 return mFallbackUiPackageName; 69 } 70 71 /** 72 * Returns the package name of the oem ui component specified in 73 * config_oemCredentialManagerDialogComponent, or null if unspecified / not parsable. 74 */ 75 @Nullable getOemUiPackageName()76 public String getOemUiPackageName() { 77 return mOemUiPackageName; 78 } 79 80 /** 81 * Result of attempting to use the config_oemCredentialManagerDialogComponent as the Credential 82 * Manager UI. 83 */ 84 public enum OemUiUsageStatus { 85 UNKNOWN, 86 // Success: the UI specified in config_oemCredentialManagerDialogComponent was used to 87 // fulfill the request. 88 SUCCESS, 89 // The config value was not specified (e.g. left empty). 90 OEM_UI_CONFIG_NOT_SPECIFIED, 91 // The config value component was specified but not found (e.g. component doesn't exist or 92 // component isn't a system app). 93 OEM_UI_CONFIG_SPECIFIED_BUT_NOT_FOUND, 94 // The config value component was found but not enabled. 95 OEM_UI_CONFIG_SPECIFIED_FOUND_BUT_NOT_ENABLED, 96 } 97 98 /** 99 * Builder for {@link IntentCreationResult}. 100 * 101 * @hide 102 */ 103 public static final class Builder { 104 @NonNull 105 private Intent mIntent; 106 @Nullable 107 private String mFallbackUiPackageName = null; 108 @Nullable 109 private String mOemUiPackageName = null; 110 @NonNull 111 private OemUiUsageStatus mOemUiUsageStatus = OemUiUsageStatus.UNKNOWN; 112 Builder(Intent intent)113 public Builder(Intent intent) { 114 mIntent = intent; 115 } 116 117 /** 118 * Sets the package name of the ui component specified in 119 * config_fallbackCredentialManagerDialogComponent, or null if unspecified / not parsable 120 * successfully. 121 */ 122 @NonNull setFallbackUiPackageName(@ullable String fallbackUiPackageName)123 public Builder setFallbackUiPackageName(@Nullable String fallbackUiPackageName) { 124 mFallbackUiPackageName = fallbackUiPackageName; 125 return this; 126 } 127 128 /** 129 * Sets the package name of the oem ui component specified in 130 * config_oemCredentialManagerDialogComponent, or null if unspecified / not parsable. 131 */ 132 @NonNull setOemUiPackageName(@ullable String oemUiPackageName)133 public Builder setOemUiPackageName(@Nullable String oemUiPackageName) { 134 mOemUiPackageName = oemUiPackageName; 135 return this; 136 } 137 138 /** 139 * Sets the result of attempting to use the config_oemCredentialManagerDialogComponent 140 * as the Credential Manager UI. 141 */ 142 @NonNull setOemUiUsageStatus(OemUiUsageStatus oemUiUsageStatus)143 public Builder setOemUiUsageStatus(OemUiUsageStatus oemUiUsageStatus) { 144 mOemUiUsageStatus = oemUiUsageStatus; 145 return this; 146 } 147 148 /** Builds a {@link IntentCreationResult}. */ 149 @NonNull build()150 public IntentCreationResult build() { 151 return new IntentCreationResult(mIntent, mFallbackUiPackageName, mOemUiPackageName, 152 mOemUiUsageStatus); 153 } 154 } 155 } 156