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 androidx.credentials 18 19 import android.os.Bundle 20 21 /** 22 * Base custom create request class for registering a credential. 23 * 24 * An application can construct a subtype custom request and call 25 * [CredentialManager.createCredential] to launch framework UI flows to collect consent and any 26 * other metadata needed from the user to register a new user credential. 27 * 28 * If you get a [CreateCustomCredentialRequest] instead of a type-safe request class such as 29 * [CreatePasswordRequest], [CreatePublicKeyCredentialRequest], etc., then you should check if you 30 * have any other library at interest that supports this custom [type] of credential request, and if 31 * so use its parsing utilities to resolve to a type-safe class within that library. 32 * 33 * Note: The Bundle keys for [credentialData] and [candidateQueryData] should not be in the form of 34 * androidx.credentials.*` as they are reserved for internal use by this androidx library. 35 * 36 * @param type the credential type determined by the credential-type-specific subclass for custom 37 * use cases 38 * @param credentialData the data of this [CreateCustomCredentialRequest] in the [Bundle] format 39 * (note: bundle keys in the form of `androidx.credentials.*` and `android.credentials.*` are 40 * reserved for internal library usage) 41 * @param candidateQueryData the partial request data in the [Bundle] format that will be sent to 42 * the provider during the initial candidate query stage, which should not contain sensitive user 43 * credential information (note: bundle keys in the form of `androidx.credentials.*` and 44 * `android.credentials.*` are reserved for internal library usage) 45 * @param isSystemProviderRequired true if must only be fulfilled by a system provider and false 46 * otherwise 47 * @param isAutoSelectAllowed defines if a create entry will be automatically chosen if it is the 48 * only one available option, false by default 49 * @param displayInfo the information to be displayed on the screen 50 * @param origin the origin of a different application if the request is being made on behalf of 51 * that application (Note: for API level >=34, setting a non-null value for this parameter will 52 * throw a SecurityException if android.permission.CREDENTIAL_MANAGER_SET_ORIGIN is not present) 53 * @param preferImmediatelyAvailableCredentials true if you prefer the operation to return 54 * immediately when there is no available passkey registration offering instead of falling back to 55 * discovering remote options, and false (default) otherwise 56 * @throws IllegalArgumentException If [type] is empty 57 * @throws NullPointerException If [type], [credentialData], or [candidateQueryData] is null 58 */ 59 open class CreateCustomCredentialRequest 60 @JvmOverloads 61 constructor( 62 type: String, 63 credentialData: Bundle, 64 candidateQueryData: Bundle, 65 isSystemProviderRequired: Boolean, 66 displayInfo: DisplayInfo, 67 isAutoSelectAllowed: Boolean = false, 68 origin: String? = null, 69 preferImmediatelyAvailableCredentials: Boolean = false, 70 ) : 71 CreateCredentialRequest( 72 type, 73 credentialData, 74 candidateQueryData, 75 isSystemProviderRequired, 76 isAutoSelectAllowed, 77 displayInfo, 78 origin, 79 preferImmediatelyAvailableCredentials 80 ) { 81 init { <lambda>null82 require(type.isNotEmpty()) { "type should not be empty" } 83 } 84 } 85