EnvironmentClient

public interface EnvironmentClient


Client to access environment related apis.

Use EnvironmentClientFactory to create an instance.

Summary

Public methods

abstract @NonNull Environment

Returns the Environment.

abstract @NonNull ListenableFuture<@NonNull Environment>

Returns the Environment.

abstract @NonNull PrepareEnvironmentResponse
@RequiresApi(value = 28)
prepareEnvironment(
    @NonNull PrepareEnvironmentRequest request,
    ComponentName notificationServiceComponentName
)

Prepares the device environment.

abstract @NonNull ListenableFuture<@NonNull PrepareEnvironmentResponse>
@RequiresApi(value = 28)
prepareEnvironmentAsync(
    @NonNull PrepareEnvironmentRequest request,
    ComponentName notificationServiceComponentName
)

Prepares the device environment.

Public methods

getEnvironment

@RequiresApi(value = 28)
abstract @NonNull Environment getEnvironment(@NonNull GetEnvironmentRequest request)

Returns the Environment. It helps the caller to know if environment is ready or not.

Throws
java.lang.SecurityException

If the caller is not authorized to call this API.

com.google.android.managementapi.common.exceptions.ApiLevelException

If the device API level is less than 28.

com.google.android.managementapi.common.exceptions.InvalidArgumentException

If the requested roles are not valid.

com.google.android.managementapi.common.exceptions.InternalException

If call failed due to an internal error.

getEnvironmentAsync

@RequiresApi(value = 28)
abstract @NonNull ListenableFuture<@NonNull EnvironmentgetEnvironmentAsync(@NonNull GetEnvironmentRequest request)

Returns the Environment. It helps the caller to know if environment is ready or not.

Returns
@NonNull ListenableFuture<@NonNull Environment>

A ListenableFuture wrapping the result. This can be:

prepareEnvironment

@RequiresApi(value = 28)
abstract @NonNull PrepareEnvironmentResponse prepareEnvironment(
    @NonNull PrepareEnvironmentRequest request,
    ComponentName notificationServiceComponentName
)

Prepares the device environment.

Prompts the user to install the necessary Android Device Policy application. Proceeds with installation if user accepts the prompt. After successful installation, it performs operations to make sure that the Android Device Policy app is ready.

Parameters
ComponentName notificationServiceComponentName

The ComponentName of the service extending NotificationReceiverService. If provided, it must be a valid component belonging to the calling app, and exported in the manifest. To get notified of Environment preparation events, you need to:

  1. Implement the EnvironmentListener interface in your app.

  2. Provide an implementation for how to handle the received events.

  3. Extend NotificationReceiverService and provide an EnvironmentListener instance.

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

For example:

class MyEnvironmentListener : EnvironmentListener {
override fun onEnvironmentEvent(event: EnvironmentEvent) {
// Handle the environment event.
}
}

class MyNotificationReceiverService : NotificationReceiverService() {
override fun getPrepareEnvironmentListener(): EnvironmentListener? {
return MyEnvironmentListener()
}
}
Returns
@NonNull PrepareEnvironmentResponse

PrepareEnvironmentResponse containing details about the final status of the environment preparation.

Throws
com.google.android.managementapi.common.exceptions.InvalidArgumentException

If:

  • [notificationServiceComponentName] is not a valid component belonging to the calling app or not exported in the manifest.
  • The requested roles are not valid.
com.google.android.managementapi.common.exceptions.ApiLevelException

If the device API level is less than 28.

java.lang.SecurityException

If the caller is not authorized to call this API.

com.google.android.managementapi.environment.exception.GooglePlayServicesAppNotUpdatedException

If Google Play Services is not up-to-date.

com.google.android.managementapi.environment.exception.AndroidDevicePolicyInstallOrUpdateUnrecoverableException

If Android Device Policy app fails to install or update and the error is unrecoverable.

com.google.android.managementapi.environment.exception.AndroidDevicePolicyInstallOrUpdateRecoverableException

If Android Device Policy app fails to install or update and the error is recoverable (e.g. request failed due to transient network issues), so the request can be retried.

com.google.android.managementapi.environment.exception.AndroidDevicePolicyInstallConsentDeclinedException

If the user declines to install Android Device Policy app.

com.google.android.managementapi.environment.exception.AndroidDevicePolicyInstallConsentDismissedException

If the user dismisses the installation consent screen.

com.google.android.managementapi.common.exceptions.InternalException

If call failed due to an internal error.

prepareEnvironmentAsync

@RequiresApi(value = 28)
abstract @NonNull ListenableFuture<@NonNull PrepareEnvironmentResponseprepareEnvironmentAsync(
    @NonNull PrepareEnvironmentRequest request,
    ComponentName notificationServiceComponentName
)

Prepares the device environment.

Prompts the user to install the necessary Android Device Policy application. Proceeds with installation if user accepts the prompt. After successful installation, it performs operations to make sure that the Android Device Policy app is ready.

Parameters
ComponentName notificationServiceComponentName

The ComponentName of the service extending NotificationReceiverService. If provided, it must be a valid component belonging to the calling app, and exported in the manifest. To get notified of environment preparation events, you need to:

  1. Implement the EnvironmentListener interface in your app.

  2. Provide an implementation for how to handle the received events.

  3. Extend NotificationReceiverService and provide an EnvironmentListener instance.

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

For example:

class MyEnvironmentListener : EnvironmentListener {
override fun onEnvironmentEvent(event: EnvironmentEvent) {
// Handle the environment event.
}
}

class MyNotificationReceiverService : NotificationReceiverService() {
override fun getPrepareEnvironmentListener(): EnvironmentListener? {
return MyEnvironmentListener()
}
}
Returns
@NonNull ListenableFuture<@NonNull PrepareEnvironmentResponse>

A ListenableFuture wrapping the result. This can be