1# Microdroid Demo app in C++ 2 3This app is a demonstration of how to create a VM and run payload in it, in C++. 4 5## Restriction 6 7This is for VMs that are part of the platform itself. Specifically, this C++ example is for cases 8like creating and using a VM from a HAL process. 9 10For non-system-level VMs, you must use the Java APIs from an Android app. See the [Java demo 11app](../demo/README.md). 12 13## Building 14 15```sh 16source build/envsetup.sh 17choosecombo 1 aosp_arm64 userdebug 18m MicrodroidTestApp 19m vm_demo_native 20``` 21 22`MicrodroidTestApp` is the application what will be running in the VM. Actually, we will run a 23native shared library `MicrodroidTestNativeLib.so` from the APK. 24 25`vm_demo_native` runs on the host (i.e. Android). Its job is to start the VM and connect to the 26native shared lib and do some work using the lib. Specifically, we will call an AIDL method 27`addInteger` which adds two integers and returns the sum. The computation will be done in the VM. 28 29## Installing 30 31```sh 32adb push out/target/product/generic_arm64/testcases/MicrodroidTestApp/arm64/MicrodroidTestApp.apk \ 33 /data/local/tmp/ 34adb push out/target/product/generic_arm64/system/bin/vm_demo_native /data/local/tmp/ 35``` 36 37## Running 38 39```sh 40adb root 41adb shell setenforce 0 42adb shell /data/local/tmp/vm_demo_native 43``` 44 45Rooting and selinux disabling are required just because there's no sepolicy configured for this demo 46application. For production, you need to set the sepolicy up correctly. You may use 47`system/sepolicy/private/composd.te` (specifically, the macro `virtualizationservice_use`) as a 48reference. 49 50## Expected output 51 52```sh 53[2023-05-10T23:45:54.904181191+09:00 INFO crosvm] crosvm started. 54[2023-05-10T23:45:54.906048663+09:00 INFO crosvm] CLI arguments parsed. 55... 56The answer from VM is 30 57[ 1.996707][ T57] microdroid_manager[57]: task successfully finished 58... 59[2023-05-10T23:45:58.263614461+09:00 INFO crosvm] exiting with success 60Done 61``` 62