1# Nearby Mainline Module 2This directory contains code for the AOSP Nearby mainline module. 3 4##Directory Structure 5 6`apex` 7 - Files associated with the Nearby mainline module APEX. 8 9`framework` 10 - Contains client side APIs and AIDL files. 11 12`jni` 13 - JNI wrapper for invoking Android APIs from native code. 14 15`native` 16 - Native code implementation for nearby module services. 17 18`service` 19 - Server side implementation for nearby module services. 20 21`tests` 22 - Unit/Multi devices tests for Nearby module (both Java and native code). 23 24## IDE setup 25 26```sh 27$ source build/envsetup.sh && lunch <TARGET> 28$ cd packages/modules/Nearby 29$ aidegen . 30# This will launch Intellij project for Nearby module. 31``` 32Note, the setup above may fail to index classes defined in proto, such 33that all classes defined in proto shows red in IDE and cannot be auto-completed. 34To fix, you can mannually add jar files generated from proto to the class path 35as below. First, find the jar file of presence proto with 36```sh 37ls $ANDROID_BUILD_TOP/out/soong/.intermediates/packages/modules/Connectivity/nearby/service/proto/presence-lite-protos/android_common/combined/presence-lite-protos.jar 38``` 39Then, add the jar in IDE as below. 401. Menu: File > Project Structure 412. Select Modules at the left panel and select the Dependencies tab. 423. Select the + icon and select 1 JARs or Directories option. 434. Select the JAR file found above, make sure it is checked in the beginning square. 445. Click the OK button. 456. Restart the IDE to re-index. 46 47## Build and Install 48 49```sh 50For master on AOSP (Android) host 51$ source build/envsetup.sh 52$ lunch aosp_oriole-trunk_staging-userdebug 53$ m com.android.tethering 54$ $ANDROID_BUILD_TOP/out/host/linux-x86/bin/deapexer decompress --input $ANDROID_PRODUCT_OUT/system/apex/com.android.tethering.capex --output /tmp/tethering.apex 55$ adb install /tmp/tethering.apex 56$ adb reboot 57 58NOTE: Developers should use AOSP by default, udc-mainline-prod should not be used unless for Google internal features. 59For udc-mainline-prod on Google internal host 60Build unbundled module using banchan 61$ source build/envsetup.sh 62$ banchan com.google.android.tethering mainline_modules_arm64 63$ m apps_only dist 64$ adb install out/dist/com.google.android.tethering.apex 65$ adb reboot 66Ensure that the module you are installing is compatible with the module currently preloaded on the phone (in /system/apex/com.google.android.tethering.apex). Compatible means: 67 681. Same package name 692. Same keys used to sign the apex and the payload 703. Higher version 71 72See go/mainline-local-build#build-install-local-module for more information 73``` 74 75## Build and Install from tm-mainline-prod branch 76When build and flash the APEX from tm-mainline-prod, you may see the error below. 77``` 78[INSTALL_FAILED_VERSION_DOWNGRADE: Downgrade of APEX package com.google.android.tethering is not allowed. Active version: 990090000 attempted: 339990000]) 79``` 80This is because the device is flashed with AOSP built from master or other branches, which has 81prebuilt APEX with higher version. We can use root access to replace the prebuilt APEX with the APEX 82built from tm-mainline-prod as below. 831. adb root && adb remount -R 842. cp tethering.next.apex com.google.android.tethering.apex 853. adb push com.google.android.tethering.apex /system/apex/ 864. adb reboot 87After the steps above, the APEX can be reinstalled with adb install -r. 88(More APEX background can be found in https://source.android.com/docs/core/ota/apex#using-an-apex.) 89 90## Build APEX to support multiple platforms 91If you need to flash the APEX to different devices, Pixel 6, Pixel 7, or even devices from OEM, you 92can share the APEX by ```source build/envsetup.sh && lunch aosp_arm64-userdebug```. This can avoid 93 re-compiling for different targets. 94