[PM-25661] Add placeholder ProviderEvents API for credential import/export (#5866)

This commit is contained in:
Patrick Honkonen
2025-09-11 14:06:57 +00:00
committed by GitHub
parent 417a1494e3
commit c4adf3ad42
8 changed files with 170 additions and 0 deletions
@@ -0,0 +1,65 @@
package androidx.credentials.providerevents
import android.annotation.SuppressLint
import android.content.Context
import androidx.credentials.provider.CallingAppInfo
import androidx.credentials.providerevents.transfer.ImportCredentialsRequest
import androidx.credentials.providerevents.transfer.ImportCredentialsResponse
import androidx.credentials.providerevents.transfer.ProviderImportCredentialsResponse
import androidx.credentials.providerevents.transfer.RegisterExportRequest
import com.bitwarden.annotation.OmitFromCoverage
/**
* Placeholder interface representing a provider events manager.
*/
interface ProviderEventsManager {
/**
* Register as a credential export source.
*/
fun registerExport(request: RegisterExportRequest): Boolean
/**
* Begin the process of importing credentials.
*/
fun importCredentials(
context: Context,
request: ImportCredentialsRequest,
): ProviderImportCredentialsResponse
@OmitFromCoverage
@Suppress("UndocumentedPublicClass")
companion object {
/**
* Create a new instance of [ProviderEventsManager].
*/
fun create(context: Context): ProviderEventsManager = StubProviderEventsManager()
}
}
/**
* Stub implementation of [ProviderEventsManager].
*/
@OmitFromCoverage
internal class StubProviderEventsManager : ProviderEventsManager {
override fun registerExport(request: RegisterExportRequest): Boolean {
return true
}
override fun importCredentials(
context: Context,
request: ImportCredentialsRequest,
): ProviderImportCredentialsResponse {
@SuppressLint("VisibleForTests")
return ProviderImportCredentialsResponse(
response = ImportCredentialsResponse(
responseJson = "",
),
callingAppInfo = CallingAppInfo(
packageName = "",
signatures = emptyList(),
origin = null,
),
)
}
}
@@ -0,0 +1,6 @@
package androidx.credentials.providerevents.exception
/**
* Placeholder class representing a cancellation exception for importing credentials.
*/
class ImportCredentialsCancellationException : Exception()
@@ -0,0 +1,45 @@
@file:Suppress("unused")
package androidx.credentials.providerevents.playservices
import android.app.Activity
import android.content.Intent
import android.net.Uri
import androidx.credentials.providerevents.exception.ImportCredentialsException
import androidx.credentials.providerevents.transfer.ImportCredentialsResponse
import androidx.credentials.providerevents.transfer.ProviderImportCredentialsRequest
/**
* A stub implementation of the Credential Provider Events IntentHandler class.
*/
object IntentHandler {
/**
* Stub implementation of the setImportCredentialsException method.
*/
fun setImportCredentialsException(intent: Intent, exception: ImportCredentialsException) {
// Stub implementation
}
/**
* Stub implementation of the setImportCredentialsResponse method.
*/
fun setImportCredentialsResponse(
context: Activity,
uri: Uri,
response: ImportCredentialsResponse,
) {
// Stub implementation
}
/**
* Stub implementation of the retrieveImportCredentialsException method.
*/
@Suppress("FunctionOnlyReturningConstant")
fun retrieveProviderImportCredentialsRequest(
intent: Intent,
): ProviderImportCredentialsRequest? {
// Stub implementation
return null
}
}
@@ -0,0 +1,14 @@
package androidx.credentials.providerevents.transfer
import android.graphics.Bitmap
/**
* Placeholder class representing an entry in the export request.
*/
data class ExportEntry(
val id: String,
val accountDisplayName: CharSequence?,
val userDisplayName: CharSequence,
val icon: Bitmap,
val supportedCredentialTypes: Set<String>,
)
@@ -0,0 +1,6 @@
package androidx.credentials.providerevents.transfer
/**
* Placeholder class representing a request to import credentials.
*/
data class ImportCredentialsRequest(val requestJson: String)
@@ -0,0 +1,15 @@
package androidx.credentials.providerevents.transfer
import android.net.Uri
import androidx.credentials.provider.CallingAppInfo
/**
* Placeholder class for the request received by the provider after the query phase of the import
* flow is complete i.e. the user was presented with a list of entries, and the user has now made
* a selection from the list of [ExportEntry] presented on the selector UI.
*/
data class ProviderImportCredentialsRequest(
val request: ImportCredentialsRequest,
val callingAppInfo: CallingAppInfo,
val uri: Uri,
)
@@ -0,0 +1,11 @@
package androidx.credentials.providerevents.transfer
import androidx.credentials.provider.CallingAppInfo
/**
* Placeholder class representing the response to an import request.
*/
data class ProviderImportCredentialsResponse(
val response: ImportCredentialsResponse,
val callingAppInfo: CallingAppInfo,
)
@@ -0,0 +1,8 @@
package androidx.credentials.providerevents.transfer
/**
* Placeholder class representing a request to register as a credential export source.
*/
data class RegisterExportRequest(
val entries: List<ExportEntry>,
)