From d2521bf843385841297a7fd1b34138f39ad90ae0 Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Mon, 19 Sep 2022 14:35:10 +0000 Subject: [PATCH] Fix LauncherInstrumentation for OOP tests from gradle The previous logic was assuming that if the test and target package were different, the target one was the launcher. However, in the sysui-studio case, the packages are different despite none of the packages being launcher. This detects if the test process is a gradle instrumentation, and if so selects the default launcher package name. Test: locally with sysui-studio + presubmits Bug: 234414088 Change-Id: Ie625e7d526f254f4b5f66b3a2b989d02eb95ac9c --- .../launcher3/tapl/LauncherInstrumentation.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 43766bf496..4a6aca15b5 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -239,7 +239,7 @@ public final class LauncherInstrumentation { // Launcher package. As during inproc tests the tested launcher may not be selected as the // current launcher, choosing target package for inproc. For out-of-proc, use the installed // launcher package. - mLauncherPackage = testPackage.equals(targetPackage) + mLauncherPackage = testPackage.equals(targetPackage) || isGradleInstrumentation() ? getLauncherPackageName() : targetPackage; @@ -286,6 +286,20 @@ public final class LauncherInstrumentation { } } + /** + * Gradle only supports out of process instrumentation. The test package is automatically + * generated by appending `.test` to the target package. + */ + private boolean isGradleInstrumentation() { + final String testPackage = getContext().getPackageName(); + final String targetPackage = mInstrumentation.getTargetContext().getPackageName(); + final String testSuffix = ".test"; + + return testPackage.endsWith(testSuffix) && testPackage.length() > testSuffix.length() + && testPackage.substring(0, testPackage.length() - testSuffix.length()) + .equals(targetPackage); + } + public void enableCheckEventsForSuccessfulGestures() { mCheckEventsForSuccessfulGestures = true; }