We have had a number of reports of an issue where Graphics Analyzer (GA), the graphics API debugger in Arm Mobile Studio, is unable to trace API calls for some Android applications. In these scenarios we see a socket error being reported in logcat by the GA interceptor. This blog will explain why the issue occurs and how to work around it.
Android runs every user application inside a restricted access sandbox enforced by SELinux security policies. One of the new restrictions added in Android 9.0 is to restrict application access to globally visible Unix domain sockets, which stops the GA interceptor from opening its socket connection to communicate with the GA daemon.
"... but I can trace an app on Android 9.0!"
Each Android release tends to increase the level of sandboxing applied, but doing so universally would risk breaking older applications which were developed before the restrictions were introduced. To avoid this, the level of sandboxing Android applies is determined by the application's targetSdkVersion, with newer applications targeting higher SDK levels getting the more restrictive security sandbox applied. The socket restriction which impacts GA is only triggered for applications targeting SDK version 26 or higher.
targetSdkVersion
The easiest workaround is to use a targetSdkVersion setting of 25, which disables the socket sandboxing policy. However, this prevents an application from using new Android features present in a higher API version, and is below the minimum version required for publishing new applications or application updates to the Google Play store. This makes this workaround far from ideal, so we've been working to find a better approach which allows GA to be used with a higher targetSdkVersion still in place.
The workaround we have found is to use the command line version of the GA daemon, rather than the GA daemon APK, and run it inside the same security sandbox as the application being traced.
First compile your application with the android:debuggable setting set to "true" in the application's manifest, and install it on the target device.
android:debuggable
"true"
Next, ensure that the APK GA daemon is not installed. Then install and run the command line GA daemon inside the application sandbox. The daemon binary aga-daemon can be found in the .\graphics_analyzer\target\android\arm\ directory in the Mobile Studio installation. This can be achieved by running the following command sequence:
aga-daemon
\graphics_analyzer\target\android\arm\
APP_NAME=[your-app-package-name] AGAD_PATH=[path-to-aga-daemon] adb push ${AGAD_PATH} /data/local/tmp/aga-daemon adb shell chmod 0777 /data/local/tmp/aga-daemon adb shell run-as ${APP_NAME} cp /data/local/tmp/aga-daemon /data/data/${APP_NAME}/ adb forward tcp:5002 tcp:5002 adb shell run-as ${APP_NAME} /data/data/${APP_NAME}/aga-daemon
Then connect to the daemon using the Device Manager in the Graphics Analyzer host application by manually connecting to localhost port 5002, instead of using the automatic Android connection wizard. At this point you can use Graphics Analyzer as normal to capture an API trace from the specific application that has been instrumented.
localhost
Once you have finished your capture it is important to stop the daemon on the target. Terminate the adb shell command running the daemon by pressing Ctrl+C in the host terminal running command. This will actually leave the daemon running on the target, so you must then manually kill the daemon with the following command:
adb shell
adb shell run-as ${APP_NAME} pkill aga-daemon
It is important that the daemon is killed before the test application is uninstalled. Once the application is uninstalled it is impossible to use run-as to inherit the application's identity which will render the daemon unkillable. Reinstalling the application won't help as the user ID assigned is randomized at install time, so the only way to kill the daemon at this point is to reboot the device.
run-as
Thanks to those of you that raised bug reports, and for bearing with us while we came up with a workaround. We'll be looking at how we can make this less of a manual process for a future Mobile Studio release.
[CTAToken URL="https://developer.arm.com/tools-and-software/graphics-and-gaming/arm-mobile-studio" target="_blank" text="Download Mobile Studio" class ="green"]
Hi Pete,thanks a lot for the swift reply. Even if I just use opengl es I get this error:"An exception was thrown while attempting to clean up GA from the target.: When uninstalling application-level tracing components: Unable to delete aga-daemon; Unable to delete libAGA.so"The device is a Samsung S5 on OS 6.0.1 /API-23 (I just updated it) CPU: ARMv7 VFP3 NEON Adreno 330 ES 3.0The engine is Unity, its a development build and I can connect with the profiler to device without problem there. The device is connected via USB.Thanks again for the help,seb
The 32-bit and 64-bit issues should be resolved in 2021.0. The helper script no longer exists; you should be able to set up the connection entirely via the GUI. If you only need to trace OpenGL ES not installign teh Vulkan interceptor (or visa versa) helps - unselect the one you don't need in the connection setup GUI. If that's not working please can you let us know what device / Android version / API / game engine you are running on, and we'd be happy to take a look. Thanks, Pete
I'm having the same issue with Arm Mobile Studio 2021.0Also I can't seem to find the aga_me.py you mentioned above. Is the 32 vs 64 bit issue resolved? My test device sadly does not support 64bit. Thanks for the help!
For OpenGL ES we have a bug currently with Graphics Analyzer when tracing 32-bit applications. The workaround is to use a 64-bit application build.
For Vulkan we only support tracing 64-bit applications on 64-bit devices. 32-bit applications on 64-bit capable devices will not trace. The workaround is to use a 64-bit application build.
Both of these issues will be fixed in the next release, but it is highly recommended to migrate to 64-bit application builds.
i just tried out 20.3 with a simple dev mode apk from unity, streamline seems to work fine with redmi 7(and honor x8), but failed to trace in the graphic analyzer.
when try to connect to device using both es and vilkan interp, it would prompt something is not set to 1, when i try connect with only es interpretor, it would throw some invovation error, when i try connect without any interpretor, console would log out connected to device without any interp, and expecting aga daemon is running along side with the game already, so ultimately no trace.
i m no android dev and every step of the set up to make this debug work is quite a search journey for me, i mean, can you guys not make this tool much easier to use?