AccountSetupClient

public 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 methods

abstract @NonNull AccountSetupAttempt
cancelAccountSetupAttempt(
    @NonNull CancelAccountSetupAttemptRequest cancelAccountSetupAttemptRequest
)

Cancels the specified account setup attempt.

abstract @NonNull ListenableFuture<@NonNull AccountSetupAttempt>

Cancels the specified account setup attempt.

abstract @NonNull LifecycleObserver

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

abstract @NonNull AccountSetupAttempt
launchAuthenticationActivity(
    @NonNull LaunchAuthenticationActivityRequest launchAuthenticationActivityRequest
)

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

abstract @NonNull ListenableFuture<@NonNull AccountSetupAttempt>

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

abstract @NonNull List<@NonNull AccountSetupAttempt>

Lists all account setup attempts.

abstract @NonNull ListenableFuture<@NonNull List<@NonNull AccountSetupAttempt>>

Lists all account setup attempts.

abstract @NonNull AccountSetupAttempt
startAccountSetup(
    @NonNull StartAccountSetupRequest startAccountSetupRequest
)

Starts account setup.

abstract @NonNull ListenableFuture<@NonNull AccountSetupAttempt>
startAccountSetupFuture(
    @NonNull StartAccountSetupRequest startAccountSetupRequest
)

Starts account setup.

Public methods

cancelAccountSetupAttempt

abstract @NonNull AccountSetupAttempt cancelAccountSetupAttempt(
    @NonNull CancelAccountSetupAttemptRequest cancelAccountSetupAttemptRequest
)

Cancels the specified account setup attempt.

Parameters
@NonNull CancelAccountSetupAttemptRequest cancelAccountSetupAttemptRequest

The request to cancel the account setup attempt.

Returns
@NonNull AccountSetupAttempt

The updated account setup attempt.

cancelAccountSetupAttemptFuture

abstract @NonNull ListenableFuture<@NonNull AccountSetupAttemptcancelAccountSetupAttemptFuture(
    @NonNull CancelAccountSetupAttemptRequest cancelAccountSetupAttemptRequest
)

Cancels the specified account setup attempt.

Parameters
@NonNull CancelAccountSetupAttemptRequest cancelAccountSetupAttemptRequest

The request to cancel the account setup attempt.

Returns
@NonNull ListenableFuture<@NonNull 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).

getLifecycleObserver

abstract @NonNull LifecycleObserver getLifecycleObserver()

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.

launchAuthenticationActivity

abstract @NonNull AccountSetupAttempt launchAuthenticationActivity(
    @NonNull LaunchAuthenticationActivityRequest launchAuthenticationActivityRequest
)

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

Parameters
@NonNull 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

abstract @NonNull ListenableFuture<@NonNull AccountSetupAttemptlaunchAuthenticationActivityFuture(
    @NonNull LaunchAuthenticationActivityRequest launchAuthenticationActivityRequest
)

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

Parameters
@NonNull 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
@NonNull ListenableFuture<@NonNull 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

abstract @NonNull List<@NonNull AccountSetupAttemptlistAccountSetupAttempts()

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

Returns
@NonNull List<@NonNull AccountSetupAttempt>

A list of all account setup attempts.

listAccountSetupAttemptsFuture

abstract @NonNull ListenableFuture<@NonNull List<@NonNull AccountSetupAttempt>> listAccountSetupAttemptsFuture()

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

startAccountSetup

abstract @NonNull AccountSetupAttempt startAccountSetup(
    @NonNull StartAccountSetupRequest startAccountSetupRequest
)

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
@NonNull StartAccountSetupRequest startAccountSetupRequest

The request to start account setup.

Returns
@NonNull AccountSetupAttempt

The account setup attempt.

startAccountSetupFuture

abstract @NonNull ListenableFuture<@NonNull AccountSetupAttemptstartAccountSetupFuture(
    @NonNull StartAccountSetupRequest startAccountSetupRequest
)

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
@NonNull StartAccountSetupRequest startAccountSetupRequest

The request to start account setup.

Returns
@NonNull ListenableFuture<@NonNull AccountSetupAttempt>

A ListenableFuture wrapping the result. This can be