package com.yorvana.testsupport import androidx.test.platform.app.InstrumentationRegistry import java.io.FileInputStream object DemoMode { fun enter() { runShell("cmd uimode night no") // Force Gesture Navigation via settings and overlay runShell("settings put secure navigation_mode 2") runShell("cmd overlay enable com.android.internal.systemui.navbar.gestural") runShell("settings put global sysui_demo_allowed 1") runShell("am broadcast -a com.android.systemui.demo -e command enter") runShell("am broadcast -a com.android.systemui.demo -e command clock -e hhmm 0900") runShell("am broadcast -a com.android.systemui.demo -e command battery -e level 100 -e plugged false") runShell("am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4") runShell("am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4") runShell("am broadcast -a com.android.systemui.demo -e command notifications -e visible false") // Give the system a moment to settle the UI changes (nav bar, demo mode) Thread.sleep(2000) } fun exit() { runShell("cmd overlay enable com.android.internal.systemui.navbar.threebutton") runShell("settings put secure navigation_mode 0") runShell("am broadcast -a com.android.systemui.demo -e command exit") } fun ensureOutputDirectory() { runShell("mkdir -p ${ScreenshotConstants.DEVICE_SCREENSHOT_DIR}") } fun runShell(command: String): String { val automation = InstrumentationRegistry.getInstrumentation().uiAutomation val descriptor = automation.executeShellCommand(command) return try { FileInputStream(descriptor.fileDescriptor).use { it.readBytes() } .toString(Charsets.UTF_8) } finally { descriptor.close() } } }