# CommissioningService

public interface **CommissioningService** Service implementation for Matter commissioning which facilitates communication between
your application and Google Play Services. This `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService` must be returned by an exported `https://developer.android.com/reference/android/app/Service.html`, and that
service specified in the `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningRequest` in order to commission a device into your fabric.

An example implementation may look like:

    class MatterCommissioningService : Service(), CommissioningService.Callback {
       private val commissioningServiceDelegate =
         CommissioningService.Builder(this)
           .setCallback(this)
           .build()

       override fun onBind(intent: Intent) = commissioningServiceDelegate.asBinder()

       override fun onCommissioningRequested(metadata: CommissioningRequestMetadata) {
         // perform commissioning

         commissioningServiceDelegate
           .sendCommissioningComplete(
             CommissioningCompleteMetadata.builder()
               .setToken(myInternalDeviceIdentifierString)
               .build()
           )
       }
     }
     
If a token is specified in `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningCompleteMetadata`, that token will be passed back to you in the activity result via `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningResult#getToken()`.

### Nested Class Summary

|---|---|---|---|
| class | [CommissioningService.Builder](https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService.Builder) || A builder to create an implementation of `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService`. |
| interface | [CommissioningService.Callback](https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService.Callback) || Callback interface to be notified of requests coming from Google Play Services to your application. |
| @interface | [CommissioningService.CommissioningError](https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService.CommissioningError) || Enumeration of valid error code values for `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService#sendCommissioningError(int)` |

### Public Method Summary

|---|---|
| abstract [IBinder](https://developer.android.com/reference/android/os/IBinder.html) | [asBinder](https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService#asBinder())() Returns the `https://developer.android.com/reference/android/os/IBinder.html` to return from your service. |
| abstract Task\<[Void](https://developer.android.com/reference/java/lang/Void.html)\> | [sendCommissioningComplete](https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService#sendCommissioningComplete(com.google.android.gms.home.matter.commissioning.CommissioningCompleteMetadata))([CommissioningCompleteMetadata](https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningCompleteMetadata) metadata) Asynchronously sends a response to Google Play Services indicating that you have completed commissioning of a device supplied by `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService.Callback#onCommissioningRequested(com.google.android.gms.home.matter.commissioning.CommissioningRequestMetadata)` |
| abstract Task\<[Void](https://developer.android.com/reference/java/lang/Void.html)\> | [sendCommissioningError](https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService#sendCommissioningError(int))(int errorCode) Asynchronously sends a response to Google Play Services indicating that you could not complete commissioning of a device supplied by `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService.Callback#onCommissioningRequested(com.google.android.gms.home.matter.commissioning.CommissioningRequestMetadata)` |

## Public Methods

#### public abstract [IBinder](https://developer.android.com/reference/android/os/IBinder.html) **asBinder** ()

Returns the `https://developer.android.com/reference/android/os/IBinder.html` to
return from your service.

#### public abstract Task\<[Void](https://developer.android.com/reference/java/lang/Void.html)\> **sendCommissioningComplete** ([CommissioningCompleteMetadata](https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningCompleteMetadata) metadata)

Asynchronously sends a response to Google Play Services indicating that you have
completed commissioning of a device supplied by `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService.Callback#onCommissioningRequested(com.google.android.gms.home.matter.commissioning.CommissioningRequestMetadata)`

##### Parameters

| metadata | additional metadata to send to complete the commissioning flow |
|---|---|

##### Returns

- a task that will be completed when the response has been delivered

#### public abstract Task\<[Void](https://developer.android.com/reference/java/lang/Void.html)\> **sendCommissioningError** (int errorCode)

Asynchronously sends a response to Google Play Services indicating that you could
not complete commissioning of a device supplied by `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService.Callback#onCommissioningRequested(com.google.android.gms.home.matter.commissioning.CommissioningRequestMetadata)`

##### Parameters

| errorCode | an error code from `https://developers.home.google.com/android/reference/com/google/android/gms/home/matter/commissioning/CommissioningService.CommissioningError` indicating the cause of the failure |
|---|---|

##### Returns

- a task that will be completed when the response has been delivered