README.md
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
50$ source build/envsetup.sh && lunch <TARGET>
51$ m com.google.android.tethering.next deapexer
52$ $ANDROID_BUILD_TOP/out/host/linux-x86/bin/deapexer decompress --input \
53 ${ANDROID_PRODUCT_OUT}/system/apex/com.google.android.tethering.next.capex \
54 --output /tmp/tethering.apex
55$ adb install -r /tmp/tethering.apex
56```
57
58## Build and Install from tm-mainline-prod branch
59When build and flash the APEX from tm-mainline-prod, you may see the error below.
60```
61[INSTALL_FAILED_VERSION_DOWNGRADE: Downgrade of APEX package com.google.android.tethering is not allowed. Active version: 990090000 attempted: 339990000])
62```
63This is because the device is flashed with AOSP built from master or other branches, which has
64prebuilt APEX with higher version. We can use root access to replace the prebuilt APEX with the APEX
65built from tm-mainline-prod as below.
661. adb root && adb remount; adb shell mount -orw,remount /system/apex
672. cp tethering.next.apex com.google.android.tethering.apex
683. adb push com.google.android.tethering.apex /system/apex/
694. adb reboot
70After the steps above, the APEX can be reinstalled with adb install -r.
71(More APEX background can be found in https://source.android.com/docs/core/ota/apex#using-an-apex.)
72
73## Build APEX to support multiple platforms
74If you need to flash the APEX to different devices, Pixel 6, Pixel 7, or even devices from OEM, you
75can share the APEX by ```source build/envsetup.sh && lunch aosp_arm64-userdebug```. This can avoid
76 re-compiling for different targets.
77