1 /* 2 * Copyright (C) 2023 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 com.android.credentialmanager.client 18 19 import android.content.Intent 20 import android.credentials.selection.BaseDialogResult 21 import android.credentials.selection.UserSelectionDialogResult 22 import com.android.credentialmanager.model.EntryInfo 23 import com.android.credentialmanager.model.Request 24 import kotlinx.coroutines.flow.StateFlow 25 26 interface CredentialManagerClient { 27 /** The UI should monitor the request update. */ 28 val requests: StateFlow<Request?> 29 30 /** The UI got a new intent; update the request state. */ updateRequestnull31 fun updateRequest(intent: Intent) 32 33 /** Sends an error encountered during the UI. */ 34 fun sendError(@BaseDialogResult.ResultCode resultCode: Int) 35 36 /** 37 * Sends a response to the system service. The response 38 * contains information about the user's choice from the selector 39 * UI and the result of the provider operation launched with 40 * that selection. 41 * 42 * If the user choice was a normal entry, then the UI can finish 43 * the activity immediately. Otherwise if it was an authentication 44 * (locked) entry, then the UI will need to stay up and wait for 45 * a new intent from the system containing the new data for 46 * display. 47 * 48 * Note that if the provider operation returns RESULT_CANCELED, 49 * then the selector should not send that result back, and instead 50 * re-display the options to allow a user to have another choice. 51 * 52 * @throws [IllegalStateException] if [requests] is not [Request.Get]. 53 */ 54 fun sendResult(result: UserSelectionDialogResult) 55 56 /** 57 * Sends a response to the system service with a selected [EntryInfo]. 58 * 59 * @return if the current [Request.Get] flow can be ended peacefully. 60 * if not, App has to keep reacting to the further update from [requests] until [Request.Cancel] 61 * or [Request.Close] is received. 62 * 63 * @throws [IllegalStateException] if [requests] is not [Request.Get]. 64 */ 65 fun sendEntrySelectionResult( 66 entryInfo: EntryInfo, 67 resultCode: Int? = null, 68 resultData: Intent? = null, 69 isAutoSelected: Boolean = false, 70 ): Boolean 71 }