From 00f68b18b9270033c84bd51e693c787869d46556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Alc=C3=A9rreca?= Date: Mon, 20 Jan 2025 15:41:55 +0000 Subject: [PATCH] Adds more sync to EdgeToEdgeTests Change-Id: I592e5fb2ee460c69ec88db414f21bdc00e27c15f --- .github/workflows/Build.yaml | 1 - .../apps/nowinandroid/ui/EdgeToEdgeTest.kt | 43 ++++++++++++++++++- .../AndroidApplicationConventionPlugin.kt | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Build.yaml b/.github/workflows/Build.yaml index a3c21f11f..ac7897fa9 100644 --- a/.github/workflows/Build.yaml +++ b/.github/workflows/Build.yaml @@ -280,7 +280,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Set up JDK 17 uses: actions/setup-java@v4 with: 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 b8b958ba5..c434106a9 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 @@ -34,6 +34,7 @@ import androidx.test.espresso.device.sizeclass.HeightSizeClass.Companion.HeightS import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.filters.SdkSuppress +import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.dropbox.dropshots.Dropshots @@ -42,6 +43,7 @@ import com.google.samples.apps.nowinandroid.core.rules.GrantPostNotificationsPer import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.After import org.junit.AfterClass import org.junit.Before import org.junit.Rule @@ -90,6 +92,10 @@ 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 " + @@ -111,9 +117,30 @@ class EdgeToEdgeTest { "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 + fun disableDemoMode() { + exitDemoMode() + executeShellCommand( + "settings put global sysui_demo_allowed 0" + ) + executeShellCommand( + "settings put global development_settings_enabled 0" + ) + } + + private fun exitDemoMode() { + executeShellCommand( + "am broadcast -a com.android.systemui.demo -e command exit" + ) + } + companion object { @JvmStatic @AfterClass @@ -151,12 +178,15 @@ class EdgeToEdgeTest { @SdkSuppress(minSdkVersion = 35, codeName = "VanillaIceCream") @Test fun edgeToEdge_Foldable_api35_tallCutout() { - forceTallCutout() onDevice().setClosedMode() + forceTallCutout() + exitDemoMode() enableDemoMode() // Mode change resets demo mode! screenshotSystemBar("edgeToEdge_Foldable_closed_system_tallCutout_api35") onDevice().setFlatMode() + exitDemoMode() + forceTallCutout() enableDemoMode() // Mode change resets demo mode! screenshotSystemBar("edgeToEdge_Foldable_flat_system_tallCutout_api35") @@ -174,6 +204,8 @@ class EdgeToEdgeTest { onDevice().setClosedMode() onDevice().setScreenOrientation(LANDSCAPE) forceThreeButtonNavigation() + exitDemoMode() + enableDemoMode() // This fixes the satellite icon showing up uninvited. screenshotSideNavigationBar("edgeToEdge_Foldable_landscape_sideNav3button_35") onDevice().setScreenOrientation(PORTRAIT) } @@ -188,6 +220,7 @@ class EdgeToEdgeTest { screenshotNavigationBar("edgeToEdge_Foldable_closed_navGesture_$apiName") onDevice().setFlatMode() + exitDemoMode() enableDemoMode() // Flat mode resets demo mode! screenshotSystemBar("edgeToEdge_Foldable_flat_system_$apiName") forceThreeButtonNavigation() @@ -297,4 +330,12 @@ class EdgeToEdgeTest { break } } + + private fun executeShellCommand(command: String) { + runOnUiThread { + InstrumentationRegistry.getInstrumentation().uiAutomation.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 02c78484f..287cc4e2f 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt @@ -34,7 +34,7 @@ class AndroidApplicationConventionPlugin : Plugin { apply(plugin = "org.jetbrains.kotlin.android") apply(plugin = "nowinandroid.android.lint") apply(plugin = "com.dropbox.dependency-guard") - apply("com.dropbox.dropshots") + apply(plugin = "com.dropbox.dropshots") extensions.configure { configureKotlinAndroid(this)