DpcMigrationClient

interface DpcMigrationClient


Client to make dpc migration related requests.

Summary

Public functions

ListenableFuture<DpcMigrationAttempt?>
getMigrationAttempt(
    getMigrationAttemptRequest: GetDpcMigrationAttemptRequest
)

Gets a migration attempt.

suspend DpcMigrationAttempt?
getMigrationAttemptAwait(
    getMigrationAttemptRequest: GetDpcMigrationAttemptRequest
)

Gets a migration attempt.

ListenableFuture<List<DpcMigrationAttempt>>

Returns a list of all migration attempts.

suspend List<DpcMigrationAttempt>

Returns a list of all migration attempts.

ListenableFuture<DpcMigrationAttempt>
migrateDeviceManagementToAndroidManagementApi(
    notificationServiceComponentName: ComponentName,
    adminComponentName: ComponentName,
    migrationRequest: DpcMigrationRequest
)

Migrate this device to being managed by Android Management API.

suspend DpcMigrationAttempt
migrateDeviceManagementToAndroidManagementApiAwait(
    notificationServiceComponentName: ComponentName,
    adminComponentName: ComponentName,
    migrationRequest: DpcMigrationRequest
)

Migrate this device to being managed by Android Management API.

Public functions

getMigrationAttempt

fun getMigrationAttempt(
    getMigrationAttemptRequest: GetDpcMigrationAttemptRequest
): ListenableFuture<DpcMigrationAttempt?>

Gets a migration attempt.

If no name is specified in the GetDpcMigrationAttemptRequest, the most recent DpcMigrationAttempt is returned.

This method can be called only by a Device Owner or Profile Owner, or a previous Device Owner or Profile Owner which migrated to Android Management API.

Returns
ListenableFuture<DpcMigrationAttempt?>

A ListenableFuture wrapping the result. This can be

  • A successful future wrapping a DpcMigrationAttempt, in case of success.

  • A successful future wrapping null, in case the DpcMigrationAttempt is not found.

  • A failed future wrapping a SecurityException, in case the caller is not a Device Owner or a Profile Owner, or a previous Device Owner or Profile Owner which migrated to Android Management API.

  • A failed future wrapping DpcMigrationException If dpc migration related call failed. The message and the subtype of the exception contain more details about the failure.

getMigrationAttemptAwait

suspend fun getMigrationAttemptAwait(
    getMigrationAttemptRequest: GetDpcMigrationAttemptRequest
): DpcMigrationAttempt?

Gets a migration attempt.

If no name is specified in the GetDpcMigrationAttemptRequest, the most recent DpcMigrationAttempt is returned.

This method can be called only by a Device Owner or Profile Owner, or a previous Device Owner or Profile Owner which migrated to Android Management API.

Returns
DpcMigrationAttempt?

The requested DpcMigrationAttempt or null, if it cannot be found

Throws
java.lang.SecurityException

If the caller is not a Device Owner or a Profile Owner, or a previous Device Owner or Profile Owner which migrated to Android Management API.

com.google.android.managementapi.dpcmigration.DpcMigrationException

If dpc migration related call failed. The message and the subtype of the exception contain more details about the failure.

listMigrationAttempts

fun listMigrationAttempts(): ListenableFuture<List<DpcMigrationAttempt>>

Returns a list of all migration attempts.

This method can be called only by a Device Owner or Profile Owner, or a previous Device Owner or Profile Owner which migrated to Android Management API. Note: older migration attempts are deleted automatically and not returned.

Returns
ListenableFuture<List<DpcMigrationAttempt>>

A ListenableFuture wrapping the result. This can be

  • A successful future wrapping a list of DpcMigrationAttempt, in case of success.

  • A failed future wrapping a SecurityException, in case the caller is not a Device Owner or a Profile Owner, or a previous Device Owner or Profile Owner which migrated to Android Management API.

  • A failed future wrapping DpcMigrationException If dpc migration related call failed. The message and the subtype of the exception contain more details about the failure.

listMigrationAttemptsAwait

suspend fun listMigrationAttemptsAwait(): List<DpcMigrationAttempt>

Returns a list of all migration attempts.

This method can be called only by a Device Owner or Profile Owner, or a previous Device Owner or Profile Owner which migrated to Android Management API. Note: older migration attempts are deleted automatically and not returned.

Throws
java.lang.SecurityException

If the caller is not a Device Owner or a Profile Owner, or a previous Device Owner or Profile Owner which migrated to Android Management API.

com.google.android.managementapi.dpcmigration.DpcMigrationException

If dpc migration related call failed. The message and the subtype of the exception contain more details about the failure.

migrateDeviceManagementToAndroidManagementApi

fun migrateDeviceManagementToAndroidManagementApi(
    notificationServiceComponentName: ComponentName,
    adminComponentName: ComponentName,
    migrationRequest: DpcMigrationRequest
): ListenableFuture<DpcMigrationAttempt>

Migrate this device to being managed by Android Management API.

Once the migration completes the calling app loses its Device Owner or Profile Owner privileges, as these are transferred to Android Device Policy.

Warning: This cannot be undone! The returned ListenableFuture completes when Android Device Policy has received the request and completed preliminary checks on the migration token. In case of failure the ListenableFuture will wrap an Exception.

This method can be called only by a Device Owner or Profile Owner. On Android 10 and below, this must not be called on a device with both a Device Owner and a Profile Owner.

Configured Wi-Fi networks are required to be passed in DpcMigrationRequest by the Profile Owner (except on Android 12) on a personally-owned device if it has configured any Wi-Fi networks. These must not be passed in on a company-owned device. Note that these Wi-Fi networks will be removed just before the device management is migrated to Android Device Policy. In case of a failure to remove a network, migration will also fail and since removal of the networks is not an atomic operation, some networks might have already been removed.

On personally-owned devices with a work profile running Android 12, all Wi-Fi networks configured by the calling DPC will be removed just before the device management is migrated to Android Device Policy, regardless of the Wi-Fi networks passed in migrationRequest.

Parameters
notificationServiceComponentName: ComponentName

The ComponentName of the service extending NotificationReceiverService. It must be a valid component belonging to the calling app, and exported in the manifest, otherwise an IllegalArgumentException will be thrown.

adminComponentName: ComponentName

The ComponentName of the admin DeviceAdminReceiver of the calling DPC.

migrationRequest: DpcMigrationRequest

The DpcMigrationRequest containing the migration token and configured Wi-Fi networks. The latter are only required if the caller is the Profile Owner on a personally-owned device and has configured any networks.

Returns
ListenableFuture<DpcMigrationAttempt>

A ListenableFuture wrapping the result. This can be

migrateDeviceManagementToAndroidManagementApiAwait

suspend fun migrateDeviceManagementToAndroidManagementApiAwait(
    notificationServiceComponentName: ComponentName,
    adminComponentName: ComponentName,
    migrationRequest: DpcMigrationRequest
): DpcMigrationAttempt

Migrate this device to being managed by Android Management API.

Once the migration completes the calling app loses its Device Owner or Profile Owner privileges, as these are transferred to Android Device Policy.

Warning: This cannot be undone! This suspend fun returns when Android Device Policy has received the request and completed preliminary checks on the migration token. In case of failure an Exception is thrown.

This method can be called only by a Device Owner or Profile Owner. On Android 10 and below, this must not be called on a device with both a Device Owner and a Profile Owner.

Configured Wi-Fi networks are required to be passed in DpcMigrationRequest by the Profile Owner (except on Android 12) on a personally-owned device if it has configured any Wi-Fi networks. These must not be passed in on a company-owned device. Note that these Wi-Fi networks will be removed just before the device management is migrated to Android Device Policy. In case of a failure to remove a network, migration will also fail and since removal of the networks is not an atomic operation, some networks might have already been removed.

On personally-owned devices with a work profile running Android 12, all Wi-Fi networks configured by the calling DPC will be removed just before the device management is migrated to Android Device Policy, regardless of the Wi-Fi networks passed in migrationRequest.

Parameters
notificationServiceComponentName: ComponentName

The ComponentName of the service extending NotificationReceiverService. It must be a valid component belonging to the calling app, and exported in the manifest, otherwise an IllegalArgumentException will be thrown.

adminComponentName: ComponentName

The ComponentName of the admin DeviceAdminReceiver of the calling DPC.

migrationRequest: DpcMigrationRequest

The DpcMigrationRequest containing the migration token and configured Wi-Fi networks. The latter are only required if the caller is the Profile Owner on a personally-owned device and has configured any networks.

Returns
DpcMigrationAttempt

DpcMigrationException with the current status of the migration in case of success.

Throws
java.lang.SecurityException

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

java.lang.IllegalArgumentException

If the migration token is empty, or if notificationServiceComponentName does not refer to a valid component extending NotificationReceiverService which is exported in the manifest, or if adminComponentName is not an active admin belonging to the current package.

com.google.android.managementapi.dpcmigration.DpcMigrationException

If dpc migration related call failed. The message and the subtype of the exception contain more details about the failure.