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 * Request class for clearing a user's credential state from the credential providers. 23 * 24 * If the request type is [TYPE_CLEAR_CREDENTIAL_STATE], then the request will be sent to the 25 * credential providers to clear the user's credential state. 26 * 27 * If the request type is [TYPE_CLEAR_RESTORE_CREDENTIAL], then the request will be sent to the 28 * restore credential provider to delete any stored [RestoreCredential]. 29 * 30 * @constructor creates a new ClearCredentialStateRequest 31 * @property requestType the type of this request 32 * @throws IllegalArgumentException if the [requestType] is unsupported type. 33 */ 34 class ClearCredentialStateRequest 35 @JvmOverloads 36 constructor(val requestType: @ClearCredentialRequestTypes String = TYPE_CLEAR_CREDENTIAL_STATE) { 37 val requestBundle: Bundle = Bundle() 38 39 init { 40 if ( 41 requestType != TYPE_CLEAR_CREDENTIAL_STATE && 42 requestType != TYPE_CLEAR_RESTORE_CREDENTIAL 43 ) { 44 throw IllegalArgumentException("The request type $requestType is not supported.") 45 } 46 if (requestType == TYPE_CLEAR_RESTORE_CREDENTIAL) { 47 requestBundle.putBoolean(BUNDLE_KEY_CLEAR_RESTORE_CREDENTIAL_REQUEST, true) 48 } 49 } 50 51 companion object { 52 /** 53 * Clears credential state from all credential providers that have cached a user sign-in 54 * states. 55 */ 56 const val TYPE_CLEAR_CREDENTIAL_STATE = "androidx.credentials.TYPE_CLEAR_CREDENTIAL_STATE" 57 58 /** Clears restore credential from the device and the backup */ 59 const val TYPE_CLEAR_RESTORE_CREDENTIAL = 60 "androidx.credentials.TYPE_CLEAR_RESTORE_CREDENTIAL" 61 62 private const val BUNDLE_KEY_CLEAR_RESTORE_CREDENTIAL_REQUEST = 63 "androidx.credentials.BUNDLE_KEY_CLEAR_RESTORE_CREDENTIAL_REQUEST" 64 } 65 } 66