AccountHelper

class AccountHelper(context: Context)(source)

Helper de gestion de comptes système centralisé.

Nécessite GET_ACCOUNTS dans le manifest (normal permission sur API < 26, accordée automatiquement ; signature/système sur API ≥ 26 pour les comptes tiers).

Enregistrement Koin :

single { AccountHelper(androidContext()) }

Utilisation :

val accounts = accountHelper.getAccounts(AccountConfig.Google)
val primary = accountHelper.getPrimaryAccount(AccountConfig.Google)
val token = accountHelper.peekAuthToken(account, "oauth2:profile")

Constructors

Link copied to clipboard
constructor(context: Context)

Functions

Link copied to clipboard
@RequiresPermission(value = "android.permission.GET_ACCOUNTS")
fun getAccounts(config: AccountConfig): List<Account>

Retourne tous les comptes du config.accountType accessibles. Retourne une liste vide si la permission est absente ou refusée.

Link copied to clipboard
@RequiresPermission(value = "android.permission.GET_ACCOUNTS")
fun getPrimaryAccount(config: AccountConfig): Account?

Retourne le premier compte trouvé, ou null.

Link copied to clipboard
@RequiresPermission(value = "android.permission.GET_ACCOUNTS")
fun hasAccount(config: AccountConfig): Boolean

true si au moins un compte du config.accountType est disponible.

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.USE_CREDENTIALS", "android.permission.MANAGE_ACCOUNTS"])
fun invalidateAuthToken(accountType: String, token: String)

Invalide un token en cache (forcer un refresh au prochain accès).

Link copied to clipboard
@RequiresPermission(value = "android.permission.AUTHENTICATE_ACCOUNTS")
fun peekAuthToken(account: Account, authTokenType: String): String?

Lit un token d'auth en cache (sans déclencher de flow d'authentification). Retourne null si aucun token n'est mis en cache.