aragaer aragaer - 1 year ago 241
Android Question

Disabling first-run greeter on fresh android emulator

I am writing a test that requires launching application directly from launcher. Because I can't emulate it correctly by launching through intent.

The problem is that when I am running the test on a fresh emulator (I am using Travis CI, but it can be easily reproduced on my home PC) the emulator starts with the "first run" greeter overlay. Which blocks my uiautomator code from correctly launching the application.

I have tried to add some code to close that greeter but unfortunately it can appear with some delay, when my "greeter detecting and closing" code has already stopped working thinking that the coast is clear.

Is there any guaranteed way to disable that greeter? Some preference maybe or just an example of code that will reliably kill the greeter.

Answer Source

Apparently the greeter is called "cling". Searching though (rather old) code I found the following:

private boolean ´┐╝isClingsEnabled() {
    if (LauncherApplication.isScreenLarge()) return false;
    // disable clings when running in a test harness
    if(ActivityManager.isRunningInTestHarness()) return false;
    return true;

And next stop is isRunningInTestHarness() at

public static boolean isRunningInTestHarness() {
    return SystemProperties.getBoolean("ro.test_harness", false);

Which in turn leads to adb shell setprop ro.test_harness true. Which just works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download