USAP是安卓10起携带的一个用来加快应用冷启动速度的功能。正常的情况下,你只需要设置属性persist.device_config.runtime_native.usap_pool_enabled
为true
即可启用该功能。
但是可能是因为这个功能默认是不开的,实际上Android 12有BUG导致功能不生效,谷歌也没人发现。
实际使用的过程中,可能会遇到这个报错
USAP: Attempt to invoke virtual method 'int com.android.internal.os.ZygoteCommandBuffer.getCount()' on a null object reference
ZygoteProcess: IO Exception while communicating with USAP pool - Connection reset by peer
明明有usap的进程产生,但是实际上新进程启动并不会使用usap进程。
查看AOSP的更新记录,发现实际上根本就是安卓12的bug,在安卓13上已经修复。参考修改如下 https://cs.android.com/android/_/android/platform/frameworks/base/+/3688f9590c7e48f87ca513bc8ab7b58a54d913c0
当然,修改的时候可以顺便修改另外一处 https://cs.android.com/android/_/android/platform/frameworks/base/+/1bc2b9c6120048f16785d07b3e9afa59a623a474