From 9c101f2224c78296f549de27cfd1ca4b1b6abbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Alc=C3=A9rreca?= Date: Mon, 20 Jan 2025 18:30:57 +0000 Subject: [PATCH] Enables emulatorControl from convention plugins Change-Id: I2d544e9605b7c24eb8cf6528425bd95ab9b1e51f --- app/build.gradle.kts | 9 --- .../apps/nowinandroid/ui/EdgeToEdgeTest.kt | 60 +++++++++---------- .../AndroidApplicationConventionPlugin.kt | 2 + .../kotlin/AndroidFeatureConventionPlugin.kt | 1 + .../kotlin/AndroidLibraryConventionPlugin.kt | 1 + 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0d1efc1d2..8ef401e01 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -61,15 +61,6 @@ android { excludes.add("/META-INF/{AL2.0,LGPL2.1}") } } - testOptions { - unitTests { - isIncludeAndroidResources = true - } - // Espresso Device - emulatorControl { - enable = true - } - } namespace = "com.google.samples.apps.nowinandroid" } diff --git a/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/EdgeToEdgeTest.kt b/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/EdgeToEdgeTest.kt index 6e40445be..ee21fc322 100644 --- a/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/EdgeToEdgeTest.kt +++ b/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/EdgeToEdgeTest.kt @@ -91,36 +91,34 @@ class EdgeToEdgeTest { @Before fun enableDemoMode() { - UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).apply { - executeShellCommand( - "settings put global development_settings_enabled 1", - ) - executeShellCommand("settings put global sysui_demo_allowed 1") - executeShellCommand( - "am broadcast -a com.android.systemui.demo -e command " + - "enter", - ) - executeShellCommand( - "am broadcast -a com.android.systemui.demo -e command " + - "notifications -e visible false", - ) - executeShellCommand( - "am broadcast -a com.android.systemui.demo -e command " + - "clock -e hhmm 1234", - ) - executeShellCommand( - "am broadcast -a com.android.systemui.demo -e command " + - "network -e wifi hide", - ) - executeShellCommand( - "am broadcast -a com.android.systemui.demo -e command " + - "network -e mobile hide", - ) - executeShellCommand( - "am broadcast -a com.android.systemui.demo -e command " + - "network -e satellite hide", - ) - } + executeShellCommand( + "settings put global development_settings_enabled 1", + ) + executeShellCommand("settings put global sysui_demo_allowed 1") + executeShellCommand( + "am broadcast -a com.android.systemui.demo -e command " + + "enter", + ) + executeShellCommand( + "am broadcast -a com.android.systemui.demo -e command " + + "notifications -e visible false", + ) + executeShellCommand( + "am broadcast -a com.android.systemui.demo -e command " + + "clock -e hhmm 1234", + ) + executeShellCommand( + "am broadcast -a com.android.systemui.demo -e command " + + "network -e wifi hide", + ) + executeShellCommand( + "am broadcast -a com.android.systemui.demo -e command " + + "network -e mobile hide", + ) + executeShellCommand( + "am broadcast -a com.android.systemui.demo -e command " + + "network -e satellite hide", + ) } @After @@ -332,7 +330,7 @@ class EdgeToEdgeTest { private fun executeShellCommand(command: String) { runOnUiThread { - InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand(command) + UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).executeShellCommand(command) } // ADB commands are not synchronized. This sleep was found empirically. Thread.sleep(20) diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt index 287cc4e2f..d5de40b34 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt @@ -42,6 +42,8 @@ class AndroidApplicationConventionPlugin : Plugin { @Suppress("UnstableApiUsage") testOptions.animationsDisabled = true configureGradleManagedDevices(this) + testOptions.emulatorControl.enable = true +// testOptions.unitTests.isIncludeAndroidResources } extensions.configure { configurePrintApksTask(this) diff --git a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt index 1af5523c5..e04635d02 100644 --- a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt @@ -32,6 +32,7 @@ class AndroidFeatureConventionPlugin : Plugin { extensions.configure { testOptions.animationsDisabled = true + testOptions.emulatorControl.enable = true configureGradleManagedDevices(this) } diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt index 3fe727410..6dea352e4 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -40,6 +40,7 @@ class AndroidLibraryConventionPlugin : Plugin { defaultConfig.targetSdk = 35 defaultConfig.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testOptions.animationsDisabled = true + testOptions.emulatorControl.enable = true configureFlavors(this) configureGradleManagedDevices(this) // The resource prefix is derived from the module name,