### Navigate to boot classpath JAR files
Source: https://source.android.com/docs/core/runtime/boot-image-profiles
Builds the distribution and lists the boot.zip file in the product output directory.
```shell
m dist
ls $ANDROID_PRODUCT_OUT/boot.zip
```
--------------------------------
### Android.mk options to install extra apps
Source: https://source.android.com/docs/core/tests/development/instrumentation
Example lines from Android.mk that install additional APKs during test setup.
```xml
```
--------------------------------
### Invoke DynamicSystemClient.start
Source: https://source.android.com/docs/core/ota/dynamic-system-updates
Example of invoking DynamicSystemClient.start with the URL and uncompressed size of the selected image. This is part of the OEM app's purpose to fetch an image list and start the DSU installation.
```java
DynamicSystemClient aot = new DynamicSystemClient(...)
aot.start(
...URL of the selected image...,
...uncompressed size of the selected image...);
```
--------------------------------
### Run helloworld with FileLogger and view host log
Source: https://source.android.com/docs/core/tests/tradefed/fundamentals/full_example
Commands to run the example and view the generated host log file, with example output showing the logged message.
```text
tf >run example/helloworld
…
05-16 21:38:21 I/XmlResultReporter: Saved device_logcat log to /tmp/0/inv_6390011618174565918/device_logcat_1302097394309452308.txt
05-16 21:38:21 I/XmlResultReporter: Saved host_log log to /tmp/0/inv_6390011618174565918/host_log_4255420317120216614.txt
…
```
```text
more /tmp/0/inv_6390011618174565918/host_log_4255420317120216614.txt
```
```text
…
05-16 21:38:21 I/HelloWorldTest: Hello, TF World! I have device 004ad9880810a548
```
--------------------------------
### Example: Get SetTxpower method details
Source: https://source.android.com/docs/devices/cuttlefish/control-environment
Example GET request to get details for the SetTxpower method. The response shows the request and response type names.
```http
https://localhost:1443/devices/cvd-1/services/WmediumdService/SetTxpower
```
```json
{"request_type_name":"wmediumdserver.SetTxpowerRequest","response_type_name":"google.protobuf.Empty"}
```
--------------------------------
### Setup repack_bootimg environment
Source: https://source.android.com/docs/core/tests/vts/vts-on-gsi
Unzip otatools.zip and add the bin directory to PATH, then verify repack_bootimg is available.
```bash
unzip otatools.zip -d otatools
export PATH="${PWD}/otatools/bin:${PATH}"
repack_bootimg --help
```
--------------------------------
### Example: Get SetTxpowerRequest type details
Source: https://source.android.com/docs/devices/cuttlefish/control-environment
Example GET request to get detailed information for the wmediumdserver.SetTxpowerRequest message type. The response shows the proto message definition.
```http
https://localhost:1443/devices/cvd-1/services/WmediumdService/wmediumdserver.SetTxpowerRequest/type
```
```protobuf
message SetTxpowerRequest {
string mac_address = 1;
int32 tx_power = 2;
}
```
--------------------------------
### Setup example: Download AOSP source and extract device binaries
Source: https://source.android.com/docs/security/test/libfuzzer
Commands to set up the AOSP build environment for a Pixel (taimen) device with USB debugging enabled. Downloads repo, initializes the manifest, syncs source, and extracts device binaries.
```bash
mkdir ~/bin
export PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
repo init -u https://android.googlesource.com/platform/manifest -b main
repo sync -c -j8
wget https://dl.google.com/dl/android/aosp/google_devices-taimen-qq1a.191205.008-f4537f93.tgz
tar xvf google_devices-taimen-qq1a.191205.008-f4537f93.tgz
./extract-google_devices-taimen.sh
wget https://dl.google.com/dl/android/aosp/qcom-taimen-qq1a.191205.008-760afa6e.tgz
tar xvf qcom-taimen-qq1a.191205.008-760afa6e.tgz
./extract-qcom-taimen.sh
. build/envsetup.sh
lunch aosp_taimen-userdebug
```
--------------------------------
### Example Flow to Start a Record
Source: https://source.android.com/docs/devices/tv/tuner-framework
Example code showing how to open, configure, and start a DvrRecorder, handle record events, and use the status listener.
```APIDOC
## Example Flow to Start a Record
### Description
Example flow to start a record using DvrRecorder, FilterCallback, and OnRecordStatusChangedListener.
### Steps
1. Open, configure, and start DvrRecorder.
2. Receive RecordEvent and retrieve index information.
3. Initialize OnRecordStatusChangedListener and store record data.
### Code Example
```java
DvrRecorder recorder = openDvrRecorder(/* bufferSize */ 1000, executor, listener);
DvrSettings dvrSettings = DvrSettings
.builder()
.setDataFormat(DvrSettings.DATA_FORMAT_TS)
.setLowThreshold(100)
.setHighThreshold(900)
.setPacketSize(188)
.build();
recorder.configure(dvrSettings);
recorder.attachFilter(filter);
recorder.setFileDescriptor(fd);
recorder.start();
```
```java
FilterCallback filterCallback = new FilterCallback() {
@Override
public void onFilterEvent(Filter filter, FilterEvent[] events) {
for (FilterEvent event : events) {
if (event instanceof TsRecordEvent) {
TsRecordEvent recordEvent = (TsRecordEvent) event;
int tsMask = recordEvent.getTsIndexMask();
int scMask = recordEvent.getScIndexMask();
int packetId = recordEvent.getPacketId();
long dataLength = recordEvent.getDataLength();
// handle the masks etc.
}
}
}
};
```
```java
OnRecordStatusChangedListener listener = new OnRecordStatusChangedListener() {
@Override
public void onRecordStatusChanged(int status) {
// a customized way to consume data efficiently by using status as a hint.
if (status == Filter.STATUS_DATA_READY) {
recorder.write(size);
}
}
};
```
```
--------------------------------
### repo init -u url [options]
Source: https://source.android.com/docs/setup/reference/repo
Installs Repo in the current directory, creating a .repo/ directory. Use -u to specify the manifest repository URL, -m to select a manifest file (default default.xml), and -b to specify a revision or manifest-branch.
```bash
repo init -u url [options]
```
--------------------------------
### Set up environment and download Android source
Source: https://source.android.com/docs/automotive/start/avd/android_virtual_device
Initializes a repository for the android12L-release branch and syncs the source code. Requires repo tool and network access.
```bash
ANDROID_BRANCH="android12L-release"
REPO_URL="https://android.googlesource.com/platform/manifest"
mkdir $ANDROID_BRANCH && cd $ANDROID_BRANCH && repo init -u $REPO_URL -b
$ANDROID_BRANCH --partial-clone && repo sync -c -j8
```
--------------------------------
### OTA metadata file example for tardis device
Source: https://source.android.com/docs/core/ota/tools
Shows the contents of the metadata file for an OTA package targeting the tardis device. The pre- fields define the required starting state, and the post- fields define the expected state after installation.
```text
post-build=google/tardis/tardis:11/RP1A.200521.001/6516341:userdebug/dev-keys
post-build-incremental=6516341
post-sdk-level=30
post-security-patch-level=2020-07-05
post-timestamp=1590026334
pre-build=google/tardis/tardis:11/RP1A.200519.002.A1/6515794:userdebug/dev-keys
pre-build-incremental=6515794
pre-device=tardis
```
--------------------------------
### List all services for Wi-Fi example
Source: https://source.android.com/docs/devices/cuttlefish/control-environment
First step of the example use case: get a list of all available services. The output shows services including OpenwrtControlService, EchoService, GnssGrpcProxy, and WmediumdService.
```bash
cvd env ls
(Omitted)
{
"services" :
[
"OpenwrtControlService",
"EchoService",
"GnssGrpcProxy",
"WmediumdService"
]
}
```
--------------------------------
### Field naming conventions example
Source: https://source.android.com/docs/setup/contribute/code-style
Example class demonstrating field naming conventions: static final fields are ALL_CAPS, public fields start with lowercase, static fields start with s, and non-public non-static fields start with m.
```java
public class MyClass {
public static final int SOME_CONSTANT = 42;
public int publicField;
private static MyClass sSingleton;
int mPackagePrivate;
private int mPrivate;
protected int mProtected;
}
```
--------------------------------
### Configure and start a filter
Source: https://source.android.com/docs/devices/tv/tuner-framework
Example of configuring and starting a filter with specific settings.
```APIDOC
## configure and start
### Description
Configures the filter with settings and starts it.
### Method
configure, start
### Parameters
- **config** (FilterConfiguration) - Required - The filter configuration.
### Request Example
```java
Settings settings = SectionSettingsWithTableInfo
.builder(Filter.TYPE_TS)
.setTableId(2)
.setVersion(1)
.setCrcEnabled(true)
.setRaw(false)
.setRepeat(false)
.build();
FilterConfiguration config = TsFilterConfiguration
.builder()
.setTpid(10)
.setSettings(settings)
.build();
filter.configure(config);
filter.start();
```
### Response
No return value.
```
--------------------------------
### Install repo and Bazel bootstrap
Source: https://source.android.com/docs/core/architecture/bootloader/generic-bootloader/gbl-dev
Install the required tools for building GBL.
```bash
sudo apt install repo bazel-bootstrap
```
--------------------------------
### Start method names with the verb
Source: https://source.android.com/docs/setup/contribute/api-guidelines
Good example: method name starts with the verb (reload) followed by the subject.
```java
public void reloadTable() {
mTable.reload();
}
```
--------------------------------
### repo download example for platform/build
Source: https://source.android.com/docs/setup/reference/repo
Example of downloading change 23823 into the platform/build directory.
```bash
repo download platform/build 23823
```
--------------------------------
### Example: List services for cvd-1
Source: https://source.android.com/docs/devices/cuttlefish/control-environment
Example GET request to list all services for device cvd-1. The response shows the available services.
```http
https://localhost:1443/devices/cvd-1/services
```
```json
{"services":["OpenwrtControlService","EchoService","GnssGrpcProxy","WmediumdService"]}
```
--------------------------------
### List configurations from classpath
Source: https://source.android.com/docs/core/tests/tradefed/fundamentals/full_example
After moving helloworld.xml into the tradefed core library and rebuilding, this command lists all configurations available on the classpath. The output shows the example/helloworld config.
```text
tf> list configs
[…]
example/helloworld: Runs the hello world test
```
--------------------------------
### Configure postinstall step for system partition
Source: https://source.android.com/docs/core/ota/ab/ab_implement
Add these key-value pairs to product or device .mk files to run a program at /system/usr/bin/postinst. The path is relative to the root of the filesystem, and the filesystem type is passed to the mount(2) system call.
```makefile
AB_OTA_POSTINSTALL_CONFIG += \
RUN_POSTINSTALL_system=true \
POSTINSTALL_PATH_system=usr/bin/postinst \
FILESYSTEM_TYPE_system=ext4
```