feat(steam): optional Steam integration setup (#1637)

* feat(steam): add optional device integration setup

* feat(steam): show integration setup as inline settings rows

* fix(steam): offer App info when shortcuts stay blocked
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-26 17:51:44 -04:00
1 parent 73daaf7adc
commit f13916ee25
20 files changed
+813 -94

No files matched your search

@@ -0,0 +1,62 @@
package com.droiddeck.launcher.input
import android.app.Application
import android.view.KeyEvent
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28, 33], manifest = Config.NONE, application = Application::class)
class HomeGuideInputTest {
private val states = mutableListOf<Boolean>()
private var cancellations = 0
private val input = HomeGuideInput({ states.add(it) }, { cancellations++ })
private fun home(action: Int, device: Int = 10, repeat: Int = 0, down: Long = 10) =
KeyEvent(down, down + 100, action, KeyEvent.KEYCODE_HOME, repeat, 0, device, 102)
@Test fun guideIsHeldImmediatelyAndReleaseDoesNotDependOnAndroidDownTime() {
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_DOWN), true))
assertEquals(listOf(true), states)
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_DOWN, repeat = 1), true))
assertFalse(input.onKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_X), true))
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_UP, down = 77), true))
assertEquals(listOf(true, false), states)
}
@Test fun anUnownedHomePressKeepsAndroidBehaviorEvenIfSessionBecomesEligibleBeforeRelease() {
assertFalse(input.onKeyEvent(home(KeyEvent.ACTION_DOWN), false))
assertFalse(input.onKeyEvent(home(KeyEvent.ACTION_UP), true))
assertTrue(states.isEmpty())
}
@Test fun focusLossReleasesGuideAndConsumesTheOwnedReleaseWithoutAnotherTap() {
input.onKeyEvent(home(KeyEvent.ACTION_DOWN), true)
input.cancel()
assertEquals(1, cancellations)
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_DOWN, repeat = 2), false))
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_UP), false))
assertEquals(listOf(true, false), states)
assertFalse(input.onKeyEvent(home(KeyEvent.ACTION_UP), false))
}
@Test fun disablingDuringAHoldReleasesItAndDoesNotStealTheNextAndroidHomePress() {
input.onKeyEvent(home(KeyEvent.ACTION_DOWN), true)
assertTrue(input.onKeyEvent(home(KeyEvent.ACTION_UP), false))
assertEquals(listOf(true, false), states)
assertFalse(input.onKeyEvent(home(KeyEvent.ACTION_DOWN), false))
}
@Test fun guideStaysHeldUntilAllOwnersReleaseAndDisconnectCancelsTheLastOwner() {
input.onKeyEvent(home(KeyEvent.ACTION_DOWN), true)
input.onKeyEvent(home(KeyEvent.ACTION_DOWN, device = 11), true)
input.onKeyEvent(home(KeyEvent.ACTION_UP), true)
assertEquals(listOf(true), states)
input.onDeviceRemoved(11)
assertEquals(listOf(true, false), states)
assertEquals(1, cancellations)
}
}
@@ -328,6 +328,53 @@ class PadBridgeQamTest {
}
}
@Test fun homeGuidePrecedesEarlyPartnerInputAndDoesNotGenerateABareButton() {
bridge.setHomeGuidePressed(true)
assertTrue(pad().isDown(PadState.GUIDE))
bridge.applyExternal({ it.press(PadState.X, true) }, true)
assertFalse(pad().isDown(PadState.X))
advance(80)
assertTrue(pad().isDown(PadState.GUIDE))
assertTrue(pad().isDown(PadState.X))
bridge.applyExternal({ it.press(PadState.X, false) }, true)
bridge.setHomeGuidePressed(false)
advance(1000)
assertFalse(pad().isDown(PadState.GUIDE))
assertFalse(pad().isDown(PadState.X))
}
@Test fun cancellingHomeDiscardsQueuedPartnersAndReleasesGuideImmediately() {
bridge.setHomeGuidePressed(true)
bridge.applyExternal({ it.press(PadState.LB, true); it.leftY = -1f }, true)
bridge.cancelHomeGuide()
advance(1000)
assertFalse(pad().isDown(PadState.GUIDE))
assertFalse(pad().isDown(PadState.LB))
assertEquals(0f, pad().leftY)
}
@Test fun homeAndTouchGuideHaveIndependentReleases() {
bridge.setHomeGuidePressed(true)
bridge.setSystemButtons(true, false)
bridge.setHomeGuidePressed(false)
advance(1000)
assertTrue(pad().isDown(PadState.GUIDE))
bridge.setSystemButtons(false, false)
advance(1000)
assertFalse(pad().isDown(PadState.GUIDE))
}
@Test fun releasingHomeStopsHeldAxesFromBecomingNavigation() {
bridge.setHomeGuidePressed(true)
bridge.applyExternal({ it.leftY = -1f }, true)
advance(80)
assertEquals(-1f, pad().leftY)
bridge.setHomeGuidePressed(false)
advance(1000)
assertEquals(0f, pad().leftY)
assertFalse(pad().isDown(PadState.GUIDE))
}
private fun key(device: InputDevice, code: Int, action: Int = KeyEvent.ACTION_DOWN, repeat: Int = 0, scan: Int = 0) =
KeyEvent(0L, 0L, action, code, repeat, 0, device.id, scan, 0, InputDevice.SOURCE_GAMEPAD)
@@ -66,14 +66,16 @@ class DeviceControlsComponentTest {
assertEquals(3, audio.getStreamVolume(AudioManager.STREAM_MUSIC))
}
@Test fun deniedBrightnessIsReadBackAndAppliedOnlyAfterPermission() {
@Test fun deniedBrightnessDoesNotOpenSettingsOrReplayAnOldSliderValueAfterPermission() {
WriteSettingsShadow.writable = false
request("brightness", "0.75")
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
assertEquals(Settings.ACTION_MANAGE_WRITE_SETTINGS, shadowOf(context).nextStartedActivity.action)
assertNull(shadowOf(context).nextStartedActivity)
assertFalse(JSONObject(File(directory, "state.json").readText()).getBoolean("brightnessWritable"))
WriteSettingsShadow.writable = true
tick()
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
request("brightness", "0.75")
assertEquals(192, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
}
@@ -87,7 +89,7 @@ class DeviceControlsComponentTest {
assertEquals(1.0, JSONObject(File(directory, "state.json").readText()).getDouble("brightness"), 0.0001)
}
@Test fun hiddenPermissionRequestOffersANotificationAndRetainsTheLatestValue() {
@Test fun permissionNotificationOpensOptionalLauncherSetupOnlyWhenSelected() {
visible = false
WriteSettingsShadow.writable = false
request("brightness", "0.25")
@@ -96,11 +98,13 @@ class DeviceControlsComponentTest {
val notifications = context.getSystemService(NotificationManager::class.java)
val notification = notifications.activeNotifications.single().notification
notification.contentIntent.send()
assertEquals(Settings.ACTION_MANAGE_WRITE_SETTINGS, shadowOf(context).nextStartedActivity.action)
val intent = shadowOf(context).nextStartedActivity
assertEquals(com.droiddeck.launcher.core.SteamIntegration.ACTION_SETUP, intent.action)
assertEquals("BRIGHTNESS", intent.getStringExtra(com.droiddeck.launcher.core.SteamIntegration.EXTRA_FEATURE))
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(121))
WriteSettingsShadow.writable = true
tick()
assertEquals(192, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
assertTrue(notifications.activeNotifications.isEmpty())
}
@@ -123,15 +127,15 @@ class DeviceControlsComponentTest {
assertEquals(128, Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
}
@Test fun rejectedPermissionCanBeRequestedAgainWithoutOpeningRepeatedScreens() {
@Test fun repeatedSliderChangesDoNotInterruptTheSession() {
WriteSettingsShadow.writable = false
request("brightness", "0.75")
assertNotNull(shadowOf(context).nextStartedActivity)
assertNull(shadowOf(context).nextStartedActivity)
request("brightness", "0.8")
assertNull(shadowOf(context).nextStartedActivity)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(5))
request("brightness", "0.8")
assertNotNull(shadowOf(context).nextStartedActivity)
assertNull(shadowOf(context).nextStartedActivity)
}
@Test fun oversizedRequestsAreDiscardedAndDoNotBlockLaterCommands() {
@@ -0,0 +1,93 @@
package com.droiddeck.launcher.ui
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.droiddeck.launcher.core.SteamIntegration
import com.droiddeck.launcher.core.SteamIntegration.Feature
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33], qualifiers = "w960dp-h540dp-land")
class SteamIntegrationGroupTest {
@get:Rule val compose = createRobolectricComposeRule()
private val state = mutableStateOf(SteamIntegration.State())
private val requests = mutableListOf<Feature>()
private var appInfo = 0
private var location = 0
private fun stateIs(value: String) = SemanticsMatcher.expectValue(SemanticsProperties.StateDescription, value)
private fun show() = compose.setContent {
DroidDeckTheme {
SteamIntegrationGroup(state.value, onFeature = { requests.add(it) }, onAppInfo = { appInfo++ }, onLocation = { location++ })
}
}
@Test fun everySwitchRequestsOnlyItsOwnFeature() {
state.value = SteamIntegration.State(home = true)
show()
compose.onNodeWithTag("integration-action-brightness").performClick()
compose.onNodeWithTag("integration-action-home").performClick()
compose.onNodeWithTag("integration-action-shortcuts").performClick()
assertEquals(listOf(Feature.BRIGHTNESS, Feature.HOME, Feature.SHORTCUTS), requests)
}
@Test fun switchesReflectAndroidGrants() {
state.value = SteamIntegration.State(brightness = true, home = true, shortcuts = true)
show()
compose.onNodeWithTag("integration-action-brightness").assert(stateIs("On"))
compose.onNodeWithTag("integration-action-shortcuts").assert(stateIs("On"))
compose.onNodeWithTag("integration-action-wifi").assert(stateIs("Off"))
compose.onNodeWithText("3 of 4 on").assertExists()
}
@Test fun shortcutsWaitForHome() {
show()
compose.onNodeWithTag("integration-action-shortcuts").assertIsNotEnabled()
compose.onNodeWithText("Needs DroidDeck as Home").assertExists()
compose.runOnIdle { state.value = state.value.copy(home = true) }
compose.onNodeWithTag("integration-action-shortcuts").assertIsEnabled()
}
@Test fun restrictedShortcutsPointToAppInfo() {
state.value = SteamIntegration.State(home = true, shortcutsRestricted = true)
show()
compose.onNodeWithTag("integration-action-shortcuts").assertIsNotEnabled()
compose.onNodeWithText("App info").performClick()
assertEquals(1, appInfo)
compose.runOnIdle { state.value = state.value.copy(shortcutsRestricted = false) }
compose.onNodeWithText("App info").assertDoesNotExist()
compose.onNodeWithTag("integration-action-shortcuts").assertIsEnabled()
}
@Test fun unconfirmedRestrictionOffersAppInfoAfterAnAttempt() {
state.value = SteamIntegration.State(home = true)
show()
compose.onNodeWithText("App info").assertDoesNotExist()
compose.runOnIdle { state.value = state.value.copy(shortcutsTried = true) }
compose.onNodeWithTag("integration-action-shortcuts").assertIsEnabled()
compose.onNodeWithText("App info").performClick()
assertEquals(1, appInfo)
}
@Test fun deniedLocationPointsToAppInfoWithoutTogglingWifi() {
state.value = SteamIntegration.State(locationBlocked = true)
show()
compose.onNodeWithText("Location denied · allow it in App info").assertExists()
compose.onNodeWithText("App info").performClick()
assertEquals(1, location)
assertTrue(requests.isEmpty())
}
}