Search code examples
androidgradleandroid-testinggradle-managed-device

How to disable pop-ups in immersive mode when using Gradle-managed devices?


I want to start using Gradle-managed devices to test my Android app with the following configuration in my build.gradle file.

testOptions {
    animationsDisabled = true
    managedDevices {
        devices {
            pixel2api31(ManagedVirtualDevice) {
                device = "Pixel 2"
                apiLevel = 31
                systemImageSource = "aosp"
            }
            nexus9api26(ManagedVirtualDevice) {
                device = "Nexus 9"
                apiLevel = 26
                systemImageSource = "aosp"
            }
        }
        groups {
            phoneAndTablet {
                targetDevices.add(devices.pixel2api31)
                targetDevices.add(devices.nexus9api26)
            }
        }
    }
}

The problem is that a part of the app runs in immersive mode (fullscreen) which triggers a pop-up informing the user about how to exit the immersive mode. Of course this is a problem with automated tests.

The pop-up as well as a potential solution via adb commands is described here. But I can't use adb commands with Gradle-managed devices (there are some quite old open issues at Google and android-test about it).

Is there another solution (other than a BuildConfig.DEBUG == false workaround condition in production code to prevent immersive mode)?


Solution

  • The solution was quite obvious in the documentation: I have to use aosp-atd instead of aosp as systemImageSource in order to use Automated Test Devices which are optimized for testing.