Skip to content

Commit

Permalink
Creates EmulatorConfigRule to configure the emulator for full screen …
Browse files Browse the repository at this point in the history
…screenshots.
  • Loading branch information
rharter committed May 21, 2024
1 parent 8b7d70e commit b332894
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
13 changes: 2 additions & 11 deletions .github/scripts/emu_setup.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#!/bin/bash

adb wait-for-devices

echo "Cleaning up old emulator data"
adb uninstall com.dropbox.dropshots.test || true
adb shell rm -rf /storage/emulated/0/Download/screenshots || true

adb wait-for-devices
adb shell settings put global sysui_demo_allowed 1
adb shell am broadcast -a com.android.systemui.demo -e command enter
adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1234
adb shell am broadcast -a com.android.systemui.demo -e command battery -e plugged false
adb shell am broadcast -a com.android.systemui.demo -e command battery -e level 100
adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4
adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4
adb shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false
adb shell cmd overlay enable com.android.internal.systemui.navbar.gestural
1 change: 1 addition & 0 deletions dropshots/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies {
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.rules)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.uiautomator)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class DropshotsTest {
private val fakeValidator = FakeResultValidator()
private val isRecordingScreenshots = isRecordingScreenshots()

@get:Rule
val emulatorConfigRule = EmulatorConfigRule()

@get:Rule
val activityScenarioRule = ActivityScenarioRule(TestActivity::class.java)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.dropbox.dropshots

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement

class EmulatorConfigRule : TestRule {
override fun apply(base: Statement, description: Description): Statement =
EmulatorConfigStatement(base)

private class EmulatorConfigStatement(
private val base: Statement,
) : Statement() {
override fun evaluate() {
enableDemoMode()
base.evaluate()
disableDemoMode()
}

private fun enableDemoMode() {
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
.apply {
executeShellCommand("cmd overlay enable com.android.internal.systemui.navbar.gestural")
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 clock -e hhmm 1234")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command battery -e plugged false")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command battery -e level 100")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4")
executeShellCommand("am broadcast -a com.android.systemui.demo -e command notifications -e visible false")
}
}

private fun disableDemoMode() {
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
.executeShellCommand("am broadcast -a com.android.systemui.demo -e command exit")
}
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ androidx-test-core = { module = "androidx.test:core-ktx", version = "1.5.0" }
androidx-test-ext-junit = { module = "androidx.test.ext:junit-ktx", version = "1.1.5" }
androidx-test-rules = { module = "androidx.test:rules", version = "1.5.0" }
androidx-test-runner = { module = "androidx.test:runner", version = "1.5.2" }
androidx-test-uiautomator = { group = "androidx.test.uiautomator", name = "uiautomator", version = "2.3.0" }
differ = "com.dropbox.differ:differ:0.0.1-alpha1"
junit = "junit:junit:4.12"
truth = "com.google.truth:truth:1.1.3"
Expand Down

0 comments on commit b332894

Please sign in to comment.