Reference documentation and code samples for the Google Cloud Device Streaming V1 Client class DirectAccessServiceClient.
Service Description: A service for allocating Android devices and interacting with the live-allocated devices.
Each Session will wait for available capacity, at a higher priority over Test Execution. When allocated, the session will be exposed through a stream for integration.
DirectAccessService is currently available as a preview to select developers. You can register today on behalf of you and your team at https://developer.android.com/studio/preview/android-device-streaming
This class provides the ability to make remote calls to the backing service through method calls that map to API methods.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.
Namespace
Google \ Cloud \ DeviceStreaming \ V1 \ ClientMethods
__construct
Constructor.
Parameters | |
---|---|
Name | Description |
options |
array
Optional. Options for configuring the service API wrapper. |
↳ apiEndpoint |
string
The address of the API remote host. May optionally include the port, formatted as "
|
↳ credentials |
string|array|FetchAuthTokenInterface|CredentialsWrapper
The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source for authentication to Google Cloud Platform, you must validate it before providing it to any Google API or library. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. For more information https://cloud.google.com/docs/authentication/external/externally-sourced-credentials |
↳ credentialsConfig |
array
Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() . |
↳ disableRetries |
bool
Determines whether or not retries defined by the client configuration should be disabled. Defaults to |
↳ clientConfig |
string|array
Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder. |
↳ transport |
string|TransportInterface
The transport used for executing network requests. May be either the string |
↳ transportConfig |
array
Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options. |
↳ clientCertSource |
callable
A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
↳ logger |
false|LoggerInterface
A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag |
adbConnect
Exposes an ADB connection if the device supports ADB.
gRPC headers are used to authenticate the Connect RPC, as well as associate to a particular DeviceSession. In particular, the user must specify the "X-Omnilab-Session-Name" header.
Parameters | |
---|---|
Name | Description |
callOptions |
array
Optional. |
↳ timeoutMillis |
int
Timeout to use for this call. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\BidiStream |
use Google\ApiCore\ApiException;
use Google\ApiCore\BidiStream;
use Google\Cloud\DeviceStreaming\V1\AdbMessage;
use Google\Cloud\DeviceStreaming\V1\Client\DirectAccessServiceClient;
use Google\Cloud\DeviceStreaming\V1\DeviceMessage;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function adb_connect_sample(): void
{
// Create a client.
$directAccessServiceClient = new DirectAccessServiceClient();
// Prepare the request message.
$request = new AdbMessage();
// Call the API and handle any network failures.
try {
/** @var BidiStream $stream */
$stream = $directAccessServiceClient->adbConnect();
$stream->writeAll([$request,]);
/** @var DeviceMessage $element */
foreach ($stream->closeWriteAndReadAll() as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
cancelDeviceSession
Cancel a DeviceSession.
This RPC changes the DeviceSession to state FINISHED and terminates all connections. Canceled sessions are not deleted and can be retrieved or listed by the user until they expire based on the 28 day deletion policy.
The async variant is DirectAccessServiceClient::cancelDeviceSessionAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\CancelDeviceSessionRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
use Google\ApiCore\ApiException;
use Google\Cloud\DeviceStreaming\V1\CancelDeviceSessionRequest;
use Google\Cloud\DeviceStreaming\V1\Client\DirectAccessServiceClient;
/**
* @param string $formattedName Name of the DeviceSession, e.g.
* "projects/{project_id}/deviceSessions/{session_id}"
* Please see {@see DirectAccessServiceClient::deviceSessionName()} for help formatting this field.
*/
function cancel_device_session_sample(string $formattedName): void
{
// Create a client.
$directAccessServiceClient = new DirectAccessServiceClient();
// Prepare the request message.
$request = (new CancelDeviceSessionRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
$directAccessServiceClient->cancelDeviceSession($request);
printf('Call completed successfully.' . PHP_EOL);
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = DirectAccessServiceClient::deviceSessionName('[PROJECT]', '[DEVICE_SESSION]');
cancel_device_session_sample($formattedName);
}
createDeviceSession
Creates a DeviceSession.
The async variant is DirectAccessServiceClient::createDeviceSessionAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\CreateDeviceSessionRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\DeviceStreaming\V1\DeviceSession |
use Google\ApiCore\ApiException;
use Google\Cloud\DeviceStreaming\V1\AndroidDevice;
use Google\Cloud\DeviceStreaming\V1\Client\DirectAccessServiceClient;
use Google\Cloud\DeviceStreaming\V1\CreateDeviceSessionRequest;
use Google\Cloud\DeviceStreaming\V1\DeviceSession;
/**
* @param string $formattedParent The Compute Engine project under which this device will be
* allocated. "projects/{project_id}"
* Please see {@see DirectAccessServiceClient::projectName()} for help formatting this field.
* @param string $deviceSessionAndroidDeviceAndroidModelId The id of the Android device to be used.
* Use the TestEnvironmentDiscoveryService to get supported options.
* @param string $deviceSessionAndroidDeviceAndroidVersionId The id of the Android OS version to be used.
* Use the TestEnvironmentDiscoveryService to get supported options.
*/
function create_device_session_sample(
string $formattedParent,
string $deviceSessionAndroidDeviceAndroidModelId,
string $deviceSessionAndroidDeviceAndroidVersionId
): void {
// Create a client.
$directAccessServiceClient = new DirectAccessServiceClient();
// Prepare the request message.
$deviceSessionAndroidDevice = (new AndroidDevice())
->setAndroidModelId($deviceSessionAndroidDeviceAndroidModelId)
->setAndroidVersionId($deviceSessionAndroidDeviceAndroidVersionId);
$deviceSession = (new DeviceSession())
->setAndroidDevice($deviceSessionAndroidDevice);
$request = (new CreateDeviceSessionRequest())
->setParent($formattedParent)
->setDeviceSession($deviceSession);
// Call the API and handle any network failures.
try {
/** @var DeviceSession $response */
$response = $directAccessServiceClient->createDeviceSession($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = DirectAccessServiceClient::projectName('[PROJECT]');
$deviceSessionAndroidDeviceAndroidModelId = '[ANDROID_MODEL_ID]';
$deviceSessionAndroidDeviceAndroidVersionId = '[ANDROID_VERSION_ID]';
create_device_session_sample(
$formattedParent,
$deviceSessionAndroidDeviceAndroidModelId,
$deviceSessionAndroidDeviceAndroidVersionId
);
}
getDeviceSession
Gets a DeviceSession, which documents the allocation status and whether the device is allocated. Clients making requests from this API must poll GetDeviceSession.
The async variant is DirectAccessServiceClient::getDeviceSessionAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\GetDeviceSessionRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\DeviceStreaming\V1\DeviceSession |
use Google\ApiCore\ApiException;
use Google\Cloud\DeviceStreaming\V1\Client\DirectAccessServiceClient;
use Google\Cloud\DeviceStreaming\V1\DeviceSession;
use Google\Cloud\DeviceStreaming\V1\GetDeviceSessionRequest;
/**
* @param string $formattedName Name of the DeviceSession, e.g.
* "projects/{project_id}/deviceSessions/{session_id}"
* Please see {@see DirectAccessServiceClient::deviceSessionName()} for help formatting this field.
*/
function get_device_session_sample(string $formattedName): void
{
// Create a client.
$directAccessServiceClient = new DirectAccessServiceClient();
// Prepare the request message.
$request = (new GetDeviceSessionRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var DeviceSession $response */
$response = $directAccessServiceClient->getDeviceSession($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = DirectAccessServiceClient::deviceSessionName('[PROJECT]', '[DEVICE_SESSION]');
get_device_session_sample($formattedName);
}
listDeviceSessions
Lists DeviceSessions owned by the project user.
The async variant is DirectAccessServiceClient::listDeviceSessionsAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\ListDeviceSessionsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\DeviceStreaming\V1\Client\DirectAccessServiceClient;
use Google\Cloud\DeviceStreaming\V1\DeviceSession;
use Google\Cloud\DeviceStreaming\V1\ListDeviceSessionsRequest;
/**
* @param string $formattedParent The name of the parent to request, e.g. "projects/{project_id}"
* Please see {@see DirectAccessServiceClient::projectName()} for help formatting this field.
*/
function list_device_sessions_sample(string $formattedParent): void
{
// Create a client.
$directAccessServiceClient = new DirectAccessServiceClient();
// Prepare the request message.
$request = (new ListDeviceSessionsRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $directAccessServiceClient->listDeviceSessions($request);
/** @var DeviceSession $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = DirectAccessServiceClient::projectName('[PROJECT]');
list_device_sessions_sample($formattedParent);
}
updateDeviceSession
Updates the current DeviceSession to the fields described by the update_mask.
The async variant is DirectAccessServiceClient::updateDeviceSessionAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\UpdateDeviceSessionRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\DeviceStreaming\V1\DeviceSession |
use Google\ApiCore\ApiException;
use Google\Cloud\DeviceStreaming\V1\AndroidDevice;
use Google\Cloud\DeviceStreaming\V1\Client\DirectAccessServiceClient;
use Google\Cloud\DeviceStreaming\V1\DeviceSession;
use Google\Cloud\DeviceStreaming\V1\UpdateDeviceSessionRequest;
/**
* @param string $deviceSessionAndroidDeviceAndroidModelId The id of the Android device to be used.
* Use the TestEnvironmentDiscoveryService to get supported options.
* @param string $deviceSessionAndroidDeviceAndroidVersionId The id of the Android OS version to be used.
* Use the TestEnvironmentDiscoveryService to get supported options.
*/
function update_device_session_sample(
string $deviceSessionAndroidDeviceAndroidModelId,
string $deviceSessionAndroidDeviceAndroidVersionId
): void {
// Create a client.
$directAccessServiceClient = new DirectAccessServiceClient();
// Prepare the request message.
$deviceSessionAndroidDevice = (new AndroidDevice())
->setAndroidModelId($deviceSessionAndroidDeviceAndroidModelId)
->setAndroidVersionId($deviceSessionAndroidDeviceAndroidVersionId);
$deviceSession = (new DeviceSession())
->setAndroidDevice($deviceSessionAndroidDevice);
$request = (new UpdateDeviceSessionRequest())
->setDeviceSession($deviceSession);
// Call the API and handle any network failures.
try {
/** @var DeviceSession $response */
$response = $directAccessServiceClient->updateDeviceSession($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$deviceSessionAndroidDeviceAndroidModelId = '[ANDROID_MODEL_ID]';
$deviceSessionAndroidDeviceAndroidVersionId = '[ANDROID_VERSION_ID]';
update_device_session_sample(
$deviceSessionAndroidDeviceAndroidModelId,
$deviceSessionAndroidDeviceAndroidVersionId
);
}
cancelDeviceSessionAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\CancelDeviceSessionRequest
|
optionalArgs |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface<void> |
createDeviceSessionAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\CreateDeviceSessionRequest
|
optionalArgs |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\DeviceStreaming\V1\DeviceSession> |
getDeviceSessionAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\GetDeviceSessionRequest
|
optionalArgs |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\DeviceStreaming\V1\DeviceSession> |
listDeviceSessionsAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\ListDeviceSessionsRequest
|
optionalArgs |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
updateDeviceSessionAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\DeviceStreaming\V1\UpdateDeviceSessionRequest
|
optionalArgs |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\DeviceStreaming\V1\DeviceSession> |
static::deviceSessionName
Formats a string containing the fully-qualified path to represent a device_session resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
deviceSession |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted device_session resource. |
static::projectName
Formats a string containing the fully-qualified path to represent a project resource.
Parameter | |
---|---|
Name | Description |
project |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted project resource. |
static::parseName
Parses a formatted name string and returns an associative array of the components in the name.
The following name formats are supported: Template: Pattern
- deviceSession: projects/{project}/deviceSessions/{device_session}
- project: projects/{project}
The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.
Parameters | |
---|---|
Name | Description |
formattedName |
string
The formatted name string |
template |
?string
Optional name of template to match |
Returns | |
---|---|
Type | Description |
array |
An associative array from name component IDs to component values. |