AccountSetupClient

interface AccountSetupClient


Client for managing the setup of a managed account on device.

Lifecycle Integration Requirement: To correctly handle the result callbacks required by operations like launchAuthenticationActivity, this client relies on AndroidX Activity Result APIs. The caller must integrate this client with the Android component lifecycle (Activity or Fragment) by:

  1. Retrieving the observer using getLifecycleObserver.

  2. Registering this observer with the Lifecycle of the host Activity or Fragment, typically in onCreate (e.g., lifecycle.addObserver(client.lifecycleObserver)).

Status Updates: To get notified of asynchronous account setup status changes, the calling app needs to:

  1. Implement the AccountSetupListener interface.

  2. Provide an implementation for handling received status updates.

  3. Extend NotificationReceiverService and provide an AccountSetupListener instance.

  4. Add the extended NotificationReceiverService class to your AndroidManifest.xml and ensure it is exported.

Use AccountSetupClientFactory to create an instance of this client.

Summary

Public functions

suspend AccountSetupAttempt
cancelAccountSetupAttempt(
    cancelAccountSetupAttemptRequest: CancelAccountSetupAttemptRequest
)

Cancels the specified account setup attempt.

ListenableFuture<AccountSetupAttempt>
cancelAccountSetupAttemptFuture(
    cancelAccountSetupAttemptRequest: CancelAccountSetupAttemptRequest
)

Cancels the specified account setup attempt.

suspend AccountSetupAttempt
launchAuthenticationActivity(
    launchAuthenticationActivityRequest: LaunchAuthenticationActivityRequest
)

Launches the minute maid activity to authenticate the user, or the account picker if the account is already present on the device.

ListenableFuture<AccountSetupAttempt>
launchAuthenticationActivityFuture(
    launchAuthenticationActivityRequest: LaunchAuthenticationActivityRequest
)

Launches the minute maid activity to authenticate the user, or the account picker if the account is already present on the device.

suspend List<AccountSetupAttempt>

Lists all account setup attempts.

ListenableFuture<List<AccountSetupAttempt>>

Lists all account setup attempts.

suspend AccountSetupAttempt
startAccountSetup(startAccountSetupRequest: StartAccountSetupRequest)

Starts account setup.

ListenableFuture<AccountSetupAttempt>
startAccountSetupFuture(
    startAccountSetupRequest: StartAccountSetupRequest
)

Starts account setup.

Public properties

LifecycleObserver

The LifecycleObserver that handles lifecycle-dependent setup for this client.

Public functions

cancelAccountSetupAttempt

suspend fun cancelAccountSetupAttempt(
    cancelAccountSetupAttemptRequest: CancelAccountSetupAttemptRequest
): AccountSetupAttempt

Cancels the specified account setup attempt.

Parameters
cancelAccountSetupAttemptRequest: CancelAccountSetupAttemptRequest

The request to cancel the account setup attempt.

Returns
AccountSetupAttempt

The updated account setup attempt.

cancelAccountSetupAttemptFuture

fun cancelAccountSetupAttemptFuture(
    cancelAccountSetupAttemptRequest: CancelAccountSetupAttemptRequest
): ListenableFuture<AccountSetupAttempt>

Cancels the specified account setup attempt.

Parameters
cancelAccountSetupAttemptRequest: CancelAccountSetupAttemptRequest

The request to cancel the account setup attempt.

Returns
ListenableFuture<AccountSetupAttempt>

A ListenableFuture wrapping the result. This can be

  • A successful future wrapping the updated account setup attempt.

  • A failed future if the account setup attempt is not found or is already in a final state (error or success).

launchAuthenticationActivity

suspend fun launchAuthenticationActivity(
    launchAuthenticationActivityRequest: LaunchAuthenticationActivityRequest
): AccountSetupAttempt

Launches the minute maid activity to authenticate the user, or the account picker if the account is already present on the device.

Parameters
launchAuthenticationActivityRequest: LaunchAuthenticationActivityRequest

The request to launch the authentication activity. The request must contain an account setup attempt in AUTHENTICATION_ACTIVITY_LAUNCH_REQUIRED_INFORMATION state.

Throws
java.lang.SecurityException

If the caller is not a Device Owner or a Profile Owner.

com.google.android.managementapi.accountsetup.AccountSetupInvalidStateException

If the account setup attempt is not in AUTHENTICATION_ACTIVITY_LAUNCH_REQUIRED_INFORMATION state.

launchAuthenticationActivityFuture

fun launchAuthenticationActivityFuture(
    launchAuthenticationActivityRequest: LaunchAuthenticationActivityRequest
): ListenableFuture<AccountSetupAttempt>

Launches the minute maid activity to authenticate the user, or the account picker if the account is already present on the device.

Parameters
launchAuthenticationActivityRequest: LaunchAuthenticationActivityRequest

The request to launch the authentication activity. The request must contain an account setup attempt in AUTHENTICATION_ACTIVITY_LAUNCH_REQUIRED_INFORMATION state.

Returns
ListenableFuture<AccountSetupAttempt>

A ListenableFuture wrapping the result. This can be

  • A successful future wrapping an account setup attempt in IN_PROGRESS state, in case of success.

  • A failed future wrapping a SecurityException, if the caller is not a Device Owner or a Profile Owner.

  • A failed future wrapping an AccountSetupInvalidStateException, if the account setup attempt is not in AUTHENTICATION_ACTIVITY_LAUNCH_REQUIRED_INFORMATION state.

listAccountSetupAttempts

suspend fun listAccountSetupAttempts(): List<AccountSetupAttempt>

Lists all account setup attempts. Only the last 20 account setup attempts are returned.

Returns
List<AccountSetupAttempt>

A list of all account setup attempts.

listAccountSetupAttemptsFuture

fun listAccountSetupAttemptsFuture(): ListenableFuture<List<AccountSetupAttempt>>

Lists all account setup attempts. Only the last 20 account setup attempts are returned.

Returns
ListenableFuture<List<AccountSetupAttempt>>

A ListenableFuture wrapping the result.

startAccountSetup

suspend fun startAccountSetup(startAccountSetupRequest: StartAccountSetupRequest): AccountSetupAttempt

Starts account setup.

NOTE: This method delegates the android.app.admin.DevicePolicyManager.DELEGATION_APP_RESTRICTIONS scope to the Android Device Policy app, allowing it to manage app restrictions on behalf of the calling admin. Upon completion of the account setup, this delegation scope to Android Device Policy will be removed.

Parameters
startAccountSetupRequest: StartAccountSetupRequest

The request to start account setup.

Returns
AccountSetupAttempt

The account setup attempt.

startAccountSetupFuture

fun startAccountSetupFuture(
    startAccountSetupRequest: StartAccountSetupRequest
): ListenableFuture<AccountSetupAttempt>

Starts account setup.

NOTE: This method delegates the android.app.admin.DevicePolicyManager.DELEGATION_APP_RESTRICTIONS scope to the Android Device Policy app, allowing it to manage app restrictions on behalf of the calling admin. Upon completion of the account setup, this delegation scope to Android Device Policy will be removed.

Parameters
startAccountSetupRequest: StartAccountSetupRequest

The request to start account setup.

Returns
ListenableFuture<AccountSetupAttempt>

A ListenableFuture wrapping the result. This can be

Public properties

lifecycleObserver

val lifecycleObserverLifecycleObserver

The LifecycleObserver that handles lifecycle-dependent setup for this client.

This observer must be registered with the Lifecycle of the Activity or Fragment that is hosting this client instance (e.g., lifecycle.addObserver(...) typically called in the host's onCreate).

Registering this observer allows the client to correctly initialize internal components, particularly the androidx.activity.result.ActivityResultLauncher needed to process the result of launchAuthenticationActivity. Failure to register this observer will result in errors when attempting to launch the authentication activity.