DpcMigrationClient

public interface DpcMigrationClient


Client to make dpc migration related requests.

Summary

Public methods

abstract @NonNull ListenableFuture<DpcMigrationAttempt>
getMigrationAttempt(
    @NonNull GetDpcMigrationAttemptRequest getMigrationAttemptRequest
)

Gets a migration attempt.

abstract DpcMigrationAttempt
getMigrationAttemptAwait(
    @NonNull GetDpcMigrationAttemptRequest getMigrationAttemptRequest
)

Gets a migration attempt.

abstract @NonNull ListenableFuture<@NonNull List<@NonNull DpcMigrationAttempt>>

Returns a list of all migration attempts.

abstract @NonNull List<@NonNull DpcMigrationAttempt>

Returns a list of all migration attempts.

abstract @NonNull ListenableFuture<@NonNull DpcMigrationAttempt>
migrateDeviceManagementToAndroidManagementApi(
    @NonNull ComponentName notificationServiceComponentName,
    @NonNull ComponentName adminComponentName,
    @NonNull DpcMigrationRequest migrationRequest
)

Migrate this device to being managed by Android Management API.

abstract @NonNull DpcMigrationAttempt
migrateDeviceManagementToAndroidManagementApiAwait(
    @NonNull ComponentName notificationServiceComponentName,
    @NonNull ComponentName adminComponentName,
    @NonNull DpcMigrationRequest migrationRequest
)

Migrate this device to being managed by Android Management API.

Public methods

getMigrationAttempt

abstract @NonNull ListenableFuture<DpcMigrationAttemptgetMigrationAttempt(
    @NonNull GetDpcMigrationAttemptRequest getMigrationAttemptRequest
)

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

abstract DpcMigrationAttempt getMigrationAttemptAwait(
    @NonNull GetDpcMigrationAttemptRequest getMigrationAttemptRequest
)

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

abstract @NonNull ListenableFuture<@NonNull List<@NonNull DpcMigrationAttempt>> listMigrationAttempts()

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

abstract @NonNull List<@NonNull DpcMigrationAttemptlistMigrationAttemptsAwait()

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

abstract @NonNull ListenableFuture<@NonNull DpcMigrationAttemptmigrateDeviceManagementToAndroidManagementApi(
    @NonNull ComponentName notificationServiceComponentName,
    @NonNull ComponentName adminComponentName,
    @NonNull DpcMigrationRequest migrationRequest
)

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
@NonNull ComponentName notificationServiceComponentName

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.

@NonNull ComponentName adminComponentName

The ComponentName of the admin DeviceAdminReceiver of the calling DPC.

@NonNull DpcMigrationRequest migrationRequest

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

A ListenableFuture wrapping the result. This can be

migrateDeviceManagementToAndroidManagementApiAwait

abstract @NonNull DpcMigrationAttempt migrateDeviceManagementToAndroidManagementApiAwait(
    @NonNull ComponentName notificationServiceComponentName,
    @NonNull ComponentName adminComponentName,
    @NonNull DpcMigrationRequest migrationRequest
)

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
@NonNull ComponentName notificationServiceComponentName

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.

@NonNull ComponentName adminComponentName

The ComponentName of the admin DeviceAdminReceiver of the calling DPC.

@NonNull DpcMigrationRequest migrationRequest

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