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,I don't know if this is the same issue but im getting this in 2021.3
Sorry to be a pain but it would be awesome to get this to work, I hope the phone is supported!
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
Thanks for clearing that up!
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