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"]
Yes, this should be resolved in Mobile Studio 2020.0, which also includes a helper script (aga_me.py) to set up the various components on the device. The application manifest must still be configured as debuggable; this is a requirement for the Android security model for sharing a domain socket between the application and the daemon which tunnels the data off the target.
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
Hi Seb, Thanks for the additional information. Unfortunately we don't support devices running Android 6, the oldest Android version we officially support is Android 8 (although we know Android 7 works on some newer devices).
The oldest device we support in the Galaxy S series is the Galaxy S7 running Android 8.
https://developer.arm.com/tools-and-software/graphics-and-gaming/arm-mobile-studio/support/supported-devicesKind regards, Pete
Thanks for clearing that up!
Hi Pete, we bought an Oppo A72 which is running Android 10 and I'm getting this error with it:Failed to set global device setting "enable_gpu_debug_layers" to value "1". (also when I just try opengl and not vulkan) Do you have an idea what could be the issue this time?Thanks a lot!
seb
Sorry to be a pain but it would be awesome to get this to work, I hope the phone is supported!