Disabling first-run greeter on fresh android emulator

后端 未结 2 616
滥情空心
滥情空心 2021-01-24 08:29

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 wh

2条回答
  •  抹茶落季
    2021-01-24 09:00

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

    http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.2_r1/com/android/launcher2/Launcher.java#Launcher.isClingsEnabled%28%29

    private boolean isClingsEnabled() {
        // TEMPORARY: DISABLE CLINGS ON LARGE UI
        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 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.2_r1/android/app/ActivityManager.java#ActivityManager.isRunningInTestHarness%28%29

    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.

提交回复
热议问题