Skip to content

Commit

Permalink
fix(howto): polish exchange-oob-data page
Browse files Browse the repository at this point in the history
Provide complete howto guide for the integration of out-of-band v2
feature into Android application.
  • Loading branch information
adglkh committed Nov 19, 2024
1 parent 317e1dd commit 56860a5
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions howto/stream/exchange-oob-data.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

(howto-exchange-oob-data)=
# How to exchange out-of-band data

Expand Down Expand Up @@ -117,10 +118,6 @@ To build up the communication bridge between an Android application and the Anbo

The `anbox-webrtc-data-proxy` system daemon runs in the instance and registers an Android system service named `org.anbox.webrtc.IDataProxyService`. This service allows Android developers to easily make use of binder interprocess communication (IPC) for data communication between an Android application and the Anbox WebRTC platform through a file descriptor.

```{note}
To interact with the `org.anbox.webrtc.IDataProxyService` system service, the Android application must be installed as a system app. See {ref}`howto-install-apk-system-app` for instructions.
```

#### Get notified about the availability of data channels

To get notified about the availability of data channels, an Android application can register the following broadcast receiver in the `AndroidManifest.xml` file:
Expand Down Expand Up @@ -159,6 +156,10 @@ public class DataChannelEventReceiver extends BroadcastReceiver {
}
```

```{note}
If an instance is running on Android 14 image, enabling the out-of-band v2 feature requires the Android app to be running in order to receive broadcasts. If the app is in the [cached state](https://developer.android.com/guide/components/activities/process-lifecycle), the system places [context-registered broadcasts in a queue]((https://developer.android.com/develop/background-work/background-tasks/broadcasts#android-14)),meaning the app may not receive broadcasts immediately, as it would when the app is actively running.
```

#### Access the data proxy service

There are two ways to access the `org.anbox.webrtc.IDataProxyService` from an Android application:
Expand Down Expand Up @@ -269,6 +270,50 @@ try {
ex.printStackTrace();
}
```
#### Install the APK as system app
To connect the data channel to the Anbox WebRTC data proxy service within an Android container, the Android app must be installed and running as a system app. To do so, proceed with the following steps:
1. Add the attribute `android:sharedUserId="android.uid.system"` into the `<manifest>` tag in the AndroidManifest.xml file of your Android app
2. Create an addon to install your APK as a system app through the pre-start hook with the following content:
```
#!/bin/bash -ex
# Only install the APK as a system app when bootstrapping an application.
if [ "$INSTANCE_TYPE" = "regular" ]; then
exit 0
fi
aam install-system-app \
--apk="${ADDON_DIR}"/app.apk \
--permissions=<comma-separated list of permissions that the application requires> \
--package-name=<package_name>
--access-hidden-api
```
See [How to install an APK as a system app](https://documentation.ubuntu.com/anbox-cloud/en/latest/howto/port/install-apk-system-app/#howto-install-apk-system-app) for details.
3. Navigate to the addon directory and add it to AMS:
```
amc addon add install-out-of-band-app .
```
#### Run end-to-end test
Launch an instance with streaming enabled and the addon created above
```
amc launch --raw jammy:android12:amd64 \
--enable-streaming \
--features allow_custom_system_signatures \
--addons install-out-of-band-app
```
```{note}
Enabling the `allow_custom_system_signatures` feature is required to run the Android application as a system app in an Android container
```

Once the instance is running, test whether the Android application can connect to the data channel created by the WebRTC client and verify that messages can be successfully sent and received between both ends.

<!-- wokeignore:rule=master -->
For a complete Android example, see the [out_of_band_v2](https://github.com/canonical/anbox-streaming-sdk/tree/master/examples/android/out_of_band_v2) project.

Expand Down

0 comments on commit 56860a5

Please sign in to comment.