|
| 1 | +# RDFM Android Device Client |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +The RDFM Android Device Client allows for integrating an Android-based device with the RDFM server. |
| 6 | +Currently, only OTA update functionality is implemented. |
| 7 | + |
| 8 | +## Integrating the app |
| 9 | + |
| 10 | +This app is **not meant to be built separately** (i.e in Android Studio), but as part of the source tree for an existing device. |
| 11 | +The app integrates with the Android UpdateEngine to perform the actual update installation, which requires it to be a system app. |
| 12 | +Some configuration is required to the existing system sources. |
| 13 | + |
| 14 | +### Copying the sources |
| 15 | + |
| 16 | +First, copy the sources of the app to the root directory of the AOSP source tree. |
| 17 | +After cloning this repository, run the following: |
| 18 | +``` |
| 19 | +mkdir -v -p <path-to-aosp-tree>/vendor/antmicro/rdfm |
| 20 | +cd devices/android-client/ |
| 21 | +cp -r app/src/main/* <path-to-aosp-tree>/vendor/antmicro/rdfm |
| 22 | +``` |
| 23 | + |
| 24 | +### Configuring the device Makefile |
| 25 | + |
| 26 | +The [product Makefile](https://source.android.com/docs/setup/create/new-device#build-a-product) must be configured to build the RDFM app into the system image. |
| 27 | +To do this, add `rdfm` to the `PRODUCT_PACKAGES` variable in the target device Makefile: |
| 28 | +``` |
| 29 | +PRODUCT_PACKAGES += rdfm |
| 30 | +``` |
| 31 | + |
| 32 | +### Building the app |
| 33 | + |
| 34 | +Afterwards, [the usual Android build procedure](https://source.android.com/docs/setup/build/building) can be used to build just the app. |
| 35 | +From an already configured build environment, run: |
| 36 | +``` |
| 37 | +mma rdfm |
| 38 | +``` |
| 39 | +The resulting signed APK is in `out/target/product/<product-name>/system/app/rdfm/rdfm.apk`. |
| 40 | + |
| 41 | +### Using HTTPS for server requests |
| 42 | + |
| 43 | +The default Android system CA certificates are used when validating the certificate presented by the server. |
| 44 | +If the RDFM server that is configured in the app uses a certificate that is signed by a custom Certificate Authority, the CA certificate must be added to the system roots. |
| 45 | + |
| 46 | +## System versioning |
| 47 | + |
| 48 | +The app performs update check requests to the configured RDFM server. |
| 49 | +The build version and device type are retrieved from the system properties: |
| 50 | +- `ro.build.version.incremental` - the current software version (matches `rdfm.software.version`) |
| 51 | +- `ro.build.product` - device type (matches `rdfm.hardware.devtype`) |
| 52 | + |
| 53 | +When uploading an OTA package to the RDFM server, currently these values must be **manually** extracted from the update package, and passed as arguments to `rdfm-mgmt`: |
| 54 | +``` |
| 55 | +rdfm-mgmt packages upload --path ota.zip --version <ro.build.version.incremental> --device <ro.build.product> |
| 56 | +``` |
| 57 | + |
| 58 | +You can extract the values from the [package metadata file](https://source.android.com/docs/core/ota/tools#ota-package-metadata) by unzipping the OTA package. |
| 59 | + |
| 60 | +## Configuring the app |
| 61 | + |
| 62 | +The application will automatically start on system boot. |
| 63 | +Available configuration options are shown below. |
| 64 | + |
| 65 | +### Build-time app configuration |
| 66 | + |
| 67 | +The default build-time configuration can be modified by providing a custom `conf.xml` file in the `app/src/main/res/values/` folder, similar to the one shown below: |
| 68 | + |
| 69 | +```xml |
| 70 | +<?xml version="1.0" encoding="utf-8"?> |
| 71 | +<resources> |
| 72 | +<!-- |
| 73 | + This is an example overlay configuration file for the RDFM app. |
| 74 | + To modify the default server address, you can do: |
| 75 | + |
| 76 | + <string name="default_rdfm_server_address">http://rdfm.example.local:6000/</string> |
| 77 | + |
| 78 | + Likewise, overlaying the default update check interval can be done similarly: |
| 79 | + |
| 80 | + <string name="default_update_check_interval_seconds">240</string> |
| 81 | + |
| 82 | + NOTE: These settings are only used during the app's first startup. To change them afterwards, |
| 83 | + you must delete the existing configuration file. |
| 84 | +--> |
| 85 | +</resources> |
| 86 | +``` |
| 87 | + |
| 88 | +This build-time configuration is applied **only once, at first startup of the app**, as the main use case for this is first-time configuration for newly provisioned devices. |
| 89 | +Modifying it afterwards (for example, via an update containing a new version of the RDFM app) will not result in the change of existing configuration. |
| 90 | + |
| 91 | +### Runtime app configuration |
| 92 | + |
| 93 | +It is possible to change the app's configuration at runtime by simply starting the RDFM app from the drawer and selecting `Settings` from the context menu. |
| 94 | + |
| 95 | +### Configuration options |
| 96 | + |
| 97 | +The following configuration options are available: |
| 98 | +- RDFM server URL (`http`/`https` scheme) |
| 99 | +- Update check interval (in seconds) |
| 100 | +- Maximum amount of concurrent shell sessions (set to `0` to disable reverse shell functionality) |
| 101 | + |
| 102 | +## Available intents |
| 103 | + |
| 104 | +### Update check intent |
| 105 | + |
| 106 | +This intent allows an external app to force perform an update check outside of the usual automatic update check interval. |
| 107 | +To do this, the app that wants to perform the update check must have the `com.antmicro.update.rdfm.permission.UPDATE_CHECK` permission defined in its `AndroidManifest.xml` file: |
| 108 | + |
| 109 | +```xml |
| 110 | +<uses-permission android:name="com.antmicro.update.rdfm.permission.UPDATE_CHECK" /> |
| 111 | +``` |
| 112 | + |
| 113 | +Afterwards, an update check can then be forced like so: |
| 114 | +```java |
| 115 | +Intent configIntent = new Intent("com.antmicro.update.rdfm.startUpdate"); |
| 116 | +mContext.sendBroadcast(configIntent); |
| 117 | +``` |
| 118 | + |
| 119 | +### External configuration via intents |
| 120 | + |
| 121 | +The app settings can also be configured via intents, for example in order to change between different deployment environments. |
| 122 | +To do this, the app that performs the configuring step must have the `com.antmicro.update.rdfm.permission.CONFIGURATION` permission defined in its `AndroidManifest.xml` file: |
| 123 | +```xml |
| 124 | +<uses-permission android:name="com.antmicro.update.rdfm.permission.CONFIGURATION" /> |
| 125 | +``` |
| 126 | + |
| 127 | +To configure the app, use the `com.antmicro.update.rdfm.configurationSet` intent and set extra values on the intent to the settings you wish to change. |
| 128 | +For example, to set the server address: |
| 129 | +```java |
| 130 | +Intent configIntent = new Intent("com.antmicro.update.rdfm.configurationSet"); |
| 131 | +configIntent.putExtra("ota_server_address", "http://CUSTOM-OTA-ADDRESS/"); |
| 132 | +mContext.sendBroadcast(configIntent); |
| 133 | +``` |
| 134 | + |
| 135 | +The supported configuration key names can be found in the `res/values/strings.xml` file with the `preference_` prefix. |
| 136 | + |
| 137 | +Aside from setting the configuration, you can also fetch the current configuration of the app: |
| 138 | +```java |
| 139 | +Intent configIntent = new Intent("com.antmicro.update.rdfm.configurationGet"); |
| 140 | +mContext.sendBroadcast(configIntent); |
| 141 | + |
| 142 | +// Now listen for `com.antmicro.update.rdfm.configurationResponse` broadcast intent |
| 143 | +// The intent's extras bundle will contain the configuration keys and values |
| 144 | +``` |
| 145 | + |
| 146 | +## Development |
| 147 | + |
| 148 | +The provided Gradle files can be used for development purposes, simply open the `devices/android-client` directory in Android Studio. |
| 149 | +Missing references to the `UpdateEngine` class are expected, but they do not prevent regular use of the IDE. |
| 150 | + |
| 151 | +Do note however that **the app is not buildable from Android Studio**, as it requires integration with the aforementioned system API. |
| 152 | +To test the app, an existing system source tree must be used. |
| 153 | +Copy the modified sources to the AOSP tree, and re-run the [application build](#building-the-app). |
| 154 | +The modified APK can then be uploaded to the device via ADB by running: |
| 155 | +``` |
| 156 | +adb install <path-to-rdfm.apk> |
| 157 | +``` |
| 158 | + |
| 159 | +### Restarting the app |
| 160 | + |
| 161 | +With the target device connected via ADB, run: |
| 162 | +``` |
| 163 | +adb shell am force-stop com.antmicro.update.rdfm |
| 164 | +adb shell am start -n com.antmicro.update.rdfm/.MainActivity |
| 165 | +``` |
| 166 | + |
| 167 | +### Fetching app logs |
| 168 | + |
| 169 | +To view the application logs, run: |
| 170 | +``` |
| 171 | +adb logcat --pid=`adb shell pidof -s com.antmicro.update.rdfm` |
| 172 | +``` |
0 commit comments