1# Nearby Mainline Fast Pair end-to-end tests 2 3This document refers to the Mainline Fast Pair project source code in the 4packages/modules/Connectivity/nearby. This is not an officially supported Google 5product. 6 7## About the Fast Pair Project 8 9The Connectivity Nearby mainline module is created in the Android T to host 10Better Together related functionality. Fast Pair is one of the main 11functionalities to provide seamless onboarding and integrated experiences for 12peripheral devices (for example, headsets like Google Pixel Buds) in the Nearby 13component. 14 15## Fully automated test 16 17### Prerequisites 18 19The fully automated end-to-end (e2e) tests are host-driven tests (which means 20test logics are in the host test scripts) using Mobly runner in Python. The two 21phones are installed with the test snippet 22`NearbyMultiDevicesClientsSnippets.apk` in the test time to let the host scripts 23control both sides for testing. Here's the overview of the test environment. 24 25Workstation (runs Python test scripts and controls Android devices through USB 26ADB) \ 27├── Phone 1: As Fast Pair seeker role, to scan, pair Fast Pair devices nearby \ 28└── Phone 2: As Fast Pair provider role, to simulate a Fast Pair device (for 29example, a Bluetooth headset) 30 31Note: These two phones need to be physically within 0.3 m of each other. 32 33### Prepare Phone 1 (Fast Pair seeker role) 34 35This is the phone to scan/pair Fast Pair devices nearby using the Nearby 36Mainline module. Test it by flashing with the Android T ROM. 37 38### Prepare Phone 2 (Fast Pair provider role) 39 40This is the phone to simulate a Fast Pair device (for example, a Bluetooth 41headset). Flash it with a customized ROM with the following changes: 42 43* Adjust Bluetooth profile configurations. \ 44 The Fast Pair provider simulator is an opposite role to the seeker. It needs 45 to enable/disable the following Bluetooth profile: 46 * Disable A2DP source (bluetooth.profile.a2dp.source.enabled) 47 * Enable A2DP sink (bluetooth.profile.a2dp.sink.enabled) 48 * Disable the AVRCP controller (bluetooth.profile.avrcp.controller.enabled) 49 * Enable the AVRCP target (bluetooth.profile.avrcp.target.enabled) 50 * Enable the HFP service (bluetooth.profile.hfp.ag.enabled, bluetooth.profile.hfp.hf.enabled) 51 52```makefile 53# The Bluetooth profiles that Fast Pair provider simulator expect to have enabled. 54PRODUCT_PRODUCT_PROPERTIES += \ 55 bluetooth.device.default_name=FastPairProviderSimulator \ 56 bluetooth.profile.a2dp.source.enabled=false \ 57 bluetooth.profile.a2dp.sink.enabled=true \ 58 bluetooth.profile.avrcp.controller.enabled=false \ 59 bluetooth.profile.avrcp.target.enabled=true \ 60 bluetooth.profile.hfp.ag.enabled=true \ 61 bluetooth.profile.hfp.hf.enabled=true 62``` 63 64* Adjust Bluetooth TX power limitation in Bluetooth module and disable the 65 Fast Pair in Google Play service (aka GMS) 66 67```shell 68adb root 69adb shell am broadcast \ 70 -a 'com.google.android.gms.phenotype.FLAG_OVERRIDE' \ 71 --es package "com.google.android.gms.nearby" \ 72 --es user "\*" \ 73 --esa flags "enabled" \ 74 --esa types "boolean" \ 75 --esa values "false" \ 76 com.google.android.gms 77``` 78 79### Running tests 80 81To run the tests, enter: 82 83```shell 84atest -v CtsNearbyMultiDevicesTestSuite 85``` 86 87## Manual testing the seeker side with headsets 88 89Use this testing with headsets such as Google Pixel buds. 90 91The `FastPairTestDataProviderService.apk` is a run-time configurable Fast Pair 92data provider service (`FastPairDataProviderService`): 93 94`packages/modules/Connectivity/nearby/tests/multidevices/clients/test_service/fastpair_seeker_data_provider` 95 96It has a test data manager(`FastPairTestDataManager`) to receive intent 97broadcasts to add or clear the test data cache (`FastPairTestDataCache`). This 98cache provides the data to return to the Fast Pair module for onXXX calls (for 99example, `onLoadFastPairAntispoofKeyDeviceMetadata`) so you can feed the 100metadata for your device. 101 102Here are some sample uses: 103 104* Send FastPairAntispoofKeyDeviceMetadata for PixelBuds-A to 105 FastPairTestDataCache \ 106 `./fast_pair_data_provider_shell.sh -m=718c17 107 -a=../test_data/fastpair/pixelbuds-a_antispoofkey_devicemeta_json.txt` 108* Send FastPairAccountDevicesMetadata for PixelBuds-A to FastPairTestDataCache 109 \ 110 `./fast_pair_data_provider_shell.sh 111 -d=../test_data/fastpair/pixelbuds-a_account_devicemeta_json.txt` 112* Send FastPairAntispoofKeyDeviceMetadata for Provider Simulator to 113 FastPairTestDataCache \ 114 `./fast_pair_data_provider_shell.sh -m=00000c 115 -a=../test_data/fastpair/simulator_antispoofkey_devicemeta_json.txt` 116* Send FastPairAccountDevicesMetadata for Provider Simulator to 117 FastPairTestDataCache \ 118 `./fast_pair_data_provider_shell.sh 119 -d=../test_data/fastpair/simulator_account_devicemeta_json.txt` 120* Clear FastPairTestDataCache \ 121 `./fast_pair_data_provider_shell.sh -c` 122 123See 124[host/tool/fast_pair_data_provider_shell.sh](host/tool/fast_pair_data_provider_shell.sh) 125for more documentation. 126 127To install the data provider as system private app, consider remounting the 128system partition: 129 130``` 131adb root && adb remount 132``` 133 134Push it in: 135 136``` 137adb push ${ANDROID_PRODUCT_OUT}/system/app/NearbyFastPairSeekerDataProvider 138/system/priv-app/ 139``` 140 141Then reboot: 142 143``` 144adb reboot 145``` 146 147## Manual testing the seeker side with provider simulator app 148 149The `NearbyFastPairProviderSimulatorApp.apk` is a simple Android app to let you 150control the state of the Fast Pair provider simulator. Install this app on phone 1512 (Fast Pair provider role) to work correctly. 152 153See 154[clients/test_support/fastpair_provider/simulator_app/Android.bp](clients/test_support/fastpair_provider/simulator_app/Android.bp) 155for more documentation. 156