diff --git a/README.md b/README.md index 388d0bf..9fd314c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ An Android app that toggles the developer settings I use most, without opening D - Stay awake while charging (AC, USB and wireless) - Keep screen on for a chosen time, charging or not -The app is for my own phones. It is not published on the Play Store. It needs Android 11 (API 30) or later. +The app is for my own phones and Meta Quest headset. It is not published on the Play Store. It needs Android 11 (API 30) or later. ## Build @@ -82,6 +82,41 @@ A foreground service holds a screen wake lock. Its ongoing notification counts d action. On Android 13 and later, the app asks for notification permission the first time; without it, the screen still stays on but the notification is hidden. The power button still turns the screen off. +## Meta Quest + +The app also runs on Meta Quest headsets. It was tested on a Quest 3 with Horizon OS on Android 14. + +### Set up a Quest + +1. Turn on developer mode. This needs a Meta developer account. In the Meta Horizon app on your phone, open the + headset's settings and turn on Developer mode. Restart the headset. +2. Connect the headset to the computer with a USB cable. Put the headset on and allow USB debugging for this + computer. +3. Install the app and grant the permission: + + ```bash + adb install -r app/build/outputs/apk/debug/app-debug.apk + adb shell pm grant com.rangelreale.devsettings android.permission.WRITE_SECURE_SETTINGS + ``` + +4. In the headset, open the Library, filter it by Unknown sources, and open Dev Settings. It opens as a flat panel. + +To use adb without the cable, run `adb tcpip 5555` while the cable is connected. Then disconnect it and run +`adb connect :5555`. You can also turn on wireless debugging from the app: it shows the address for +`adb connect`. That address only accepts a computer that is already paired. + +### Differences on a Quest + +The app recognises a Quest by the `oculus.hardware.standalone_vr` system feature and changes as follows: + +- USB debugging and wireless debugging work. Turning on wireless debugging opens the Quest's own dialog asking to + allow the network, and the app shows the address for `adb connect`. +- Stay awake and Keep screen on are hidden. The proximity sensor puts the headset to sleep about 20 seconds after + it is taken off, and neither setting prevents that. +- The warning that Developer options are off is hidden. The Quest does not set `development_settings_enabled`; + developer mode is turned on in the Meta Horizon app instead. +- Quick Settings tiles are not available, because Horizon OS has no Quick Settings panel for them. + ## Releases CI runs on every pull request and every push to `master`: unit tests, lint and a debug build diff --git a/app/src/main/java/com/rangelreale/devsettings/data/DevicePlatform.kt b/app/src/main/java/com/rangelreale/devsettings/data/DevicePlatform.kt new file mode 100644 index 0000000..d815bc5 --- /dev/null +++ b/app/src/main/java/com/rangelreale/devsettings/data/DevicePlatform.kt @@ -0,0 +1,33 @@ +package com.rangelreale.devsettings.data + +/** + * The kind of device the app runs on. Some features behave differently on a Meta Quest headset. + * + * Tested on a Quest 3 with Horizon OS on Android 14: + * - `development_settings_enabled` is not set, although USB and wireless debugging work. + * - The proximity sensor puts the headset to sleep about 20 seconds after it is taken off. + * Neither `stay_on_while_plugged_in` nor a screen wake lock prevents this. + */ +enum class DevicePlatform( + /** True when `development_settings_enabled` reflects whether the debugging settings take effect. */ + val usesDeveloperOptionsFlag: Boolean, + /** True when "Stay awake while charging" and "Keep screen on" keep the device awake. */ + val supportsKeepAwake: Boolean, +) { + PHONE(usesDeveloperOptionsFlag = true, supportsKeepAwake = true), + META_QUEST(usesDeveloperOptionsFlag = false, supportsKeepAwake = false), + ; + + companion object { + /** System feature that every Meta Quest headset reports. */ + const val QUEST_FEATURE = "oculus.hardware.standalone_vr" + + /** [hasSystemFeature] is usually `PackageManager::hasSystemFeature`. */ + fun detect(hasSystemFeature: (String) -> Boolean): DevicePlatform = + if (hasSystemFeature(QUEST_FEATURE)) META_QUEST else PHONE + } +} + +/** True when the app should warn that Developer options are off. */ +fun DevSettingsRepository.shouldWarnDeveloperOptionsOff(platform: DevicePlatform): Boolean = + platform.usesDeveloperOptionsFlag && !developerOptionsEnabled() diff --git a/app/src/main/java/com/rangelreale/devsettings/ui/MainScreen.kt b/app/src/main/java/com/rangelreale/devsettings/ui/MainScreen.kt index 7359d92..f6d85a9 100644 --- a/app/src/main/java/com/rangelreale/devsettings/ui/MainScreen.kt +++ b/app/src/main/java/com/rangelreale/devsettings/ui/MainScreen.kt @@ -66,11 +66,13 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.rangelreale.devsettings.R import com.rangelreale.devsettings.SystemScreens import com.rangelreale.devsettings.data.DevSetting +import com.rangelreale.devsettings.data.DevicePlatform import com.rangelreale.devsettings.data.DevSettingsRepository import com.rangelreale.devsettings.data.GlobalKeys import com.rangelreale.devsettings.data.WirelessDebugInfo import com.rangelreale.devsettings.data.WriteResult import com.rangelreale.devsettings.data.grantCommand +import com.rangelreale.devsettings.data.shouldWarnDeveloperOptionsOff import com.rangelreale.devsettings.keepon.KeepScreenOnDuration import com.rangelreale.devsettings.keepon.KeepScreenOnService import com.rangelreale.devsettings.keepon.KeepScreenOnState @@ -83,13 +85,13 @@ import kotlinx.coroutines.launch /** Values read from the system on each refresh. */ private data class Snapshot( val hasPermission: Boolean, - val developerOptions: Boolean, + val warnDeveloperOptionsOff: Boolean, val enabled: Map, ) -private fun DevSettingsRepository.snapshot() = Snapshot( +private fun DevSettingsRepository.snapshot(platform: DevicePlatform) = Snapshot( hasPermission = hasPermission(), - developerOptions = developerOptionsEnabled(), + warnDeveloperOptionsOff = shouldWarnDeveloperOptionsOff(platform), enabled = DevSetting.entries.associateWith { isEnabled(it) }, ) @@ -114,10 +116,11 @@ fun MainScreen(repository: DevSettingsRepository) { val scope = rememberCoroutineScope() val snackbar = remember { SnackbarHostState() } - var snapshot by remember { mutableStateOf(repository.snapshot()) } + val platform = remember { DevicePlatform.detect(context.packageManager::hasSystemFeature) } + var snapshot by remember { mutableStateOf(repository.snapshot(platform)) } var resumeCount by remember { mutableIntStateOf(0) } fun refresh() { - snapshot = repository.snapshot() + snapshot = repository.snapshot(platform) } // Re-read on every resume: values may have changed while the app was in the background. @@ -190,9 +193,9 @@ fun MainScreen(repository: DevSettingsRepository) { verticalArrangement = Arrangement.spacedBy(12.dp), ) { if (!snapshot.hasPermission) { - SetupCard(command = grantCommand(context.packageName), onCopy = ::copy) + SetupCard(command = grantCommand(context.packageName), platform = platform, onCopy = ::copy) } - if (!snapshot.developerOptions) { + if (snapshot.warnDeveloperOptionsOff) { DeveloperOptionsCard(onOpenAboutPhone = { SystemScreens.openAboutPhone(context) }) } @@ -216,20 +219,30 @@ fun MainScreen(repository: DevSettingsRepository) { onCopy = ::copy, onOpenPairing = { SystemScreens.openWirelessDebugging(context) }, ) - HorizontalDivider() - val stayAwake = snapshot.enabled.getValue(DevSetting.STAY_AWAKE) - SettingRow( - setting = DevSetting.STAY_AWAKE, - checked = stayAwake, - enabled = snapshot.hasPermission, - onCheckedChange = { onSwitch(DevSetting.STAY_AWAKE, it) }, - stateText = if (stayAwake) stringResource(R.string.stay_awake_on_detail) else null, - ) - HorizontalDivider() - KeepScreenOnSection( - status = keepOnStatus, - enabled = snapshot.hasPermission, - onStartFailed = { showMessage(context.getString(R.string.keep_screen_on_failed)) }, + if (platform.supportsKeepAwake) { + HorizontalDivider() + val stayAwake = snapshot.enabled.getValue(DevSetting.STAY_AWAKE) + SettingRow( + setting = DevSetting.STAY_AWAKE, + checked = stayAwake, + enabled = snapshot.hasPermission, + onCheckedChange = { onSwitch(DevSetting.STAY_AWAKE, it) }, + stateText = if (stayAwake) stringResource(R.string.stay_awake_on_detail) else null, + ) + HorizontalDivider() + KeepScreenOnSection( + status = keepOnStatus, + enabled = snapshot.hasPermission, + onStartFailed = { showMessage(context.getString(R.string.keep_screen_on_failed)) }, + ) + } + } + + if (!platform.supportsKeepAwake) { + Text( + stringResource(R.string.quest_keep_awake_unsupported), + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(horizontal = 16.dp), ) } @@ -263,7 +276,7 @@ fun MainScreen(repository: DevSettingsRepository) { } @Composable -private fun SetupCard(command: String, onCopy: (String) -> Unit) { +private fun SetupCard(command: String, platform: DevicePlatform, onCopy: (String) -> Unit) { Card( modifier = Modifier.fillMaxWidth(), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.errorContainer), @@ -271,7 +284,11 @@ private fun SetupCard(command: String, onCopy: (String) -> Unit) { Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { Text(stringResource(R.string.setup_title), style = MaterialTheme.typography.titleMedium) Text(stringResource(R.string.setup_body)) - Text(stringResource(R.string.setup_step_1)) + Text( + stringResource( + if (platform == DevicePlatform.META_QUEST) R.string.setup_step_1_quest else R.string.setup_step_1, + ), + ) Text(stringResource(R.string.setup_step_2)) Surface( color = MaterialTheme.colorScheme.surface, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 778d990..a62c2a0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,7 @@ One-time setup This app needs the WRITE_SECURE_SETTINGS permission. Only a computer can grant it. 1. Turn on USB debugging in Developer options, then connect the phone to a computer. + 1. Turn on developer mode for the headset in the Meta Horizon app, then connect the headset to a computer. 2. On the computer, run this command: 3. Come back here. The switches turn on within a few seconds. Copy command @@ -55,5 +56,6 @@ Keeping the screen on Until you stop it Stop + Stay awake and Keep screen on are hidden on Meta Quest. The headset sleeps when you take it off, whatever these settings say. Holds the screen on, charging or not. diff --git a/app/src/test/java/com/rangelreale/devsettings/data/DevicePlatformTest.kt b/app/src/test/java/com/rangelreale/devsettings/data/DevicePlatformTest.kt new file mode 100644 index 0000000..7e54ed2 --- /dev/null +++ b/app/src/test/java/com/rangelreale/devsettings/data/DevicePlatformTest.kt @@ -0,0 +1,41 @@ +package com.rangelreale.devsettings.data + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class DevicePlatformTest { + private val store = FakeSettingsStore() + private val repo = DevSettingsRepository(store) + + @Test + fun questFeatureMeansMetaQuest() { + val platform = DevicePlatform.detect { it == "oculus.hardware.standalone_vr" } + assertEquals(DevicePlatform.META_QUEST, platform) + } + + @Test + fun otherFeaturesMeanPhone() { + assertEquals(DevicePlatform.PHONE, DevicePlatform.detect { false }) + assertEquals(DevicePlatform.PHONE, DevicePlatform.detect { it == "android.hardware.telephony" }) + } + + @Test + fun onlyPhoneSupportsKeepAwake() { + assertTrue(DevicePlatform.PHONE.supportsKeepAwake) + assertFalse(DevicePlatform.META_QUEST.supportsKeepAwake) + } + + @Test + fun phoneWarnsWhenDeveloperOptionsAreOff() { + assertTrue(repo.shouldWarnDeveloperOptionsOff(DevicePlatform.PHONE)) + store.values["development_settings_enabled"] = 1 + assertFalse(repo.shouldWarnDeveloperOptionsOff(DevicePlatform.PHONE)) + } + + @Test + fun questNeverWarnsAboutDeveloperOptions() { + assertFalse(repo.shouldWarnDeveloperOptionsOff(DevicePlatform.META_QUEST)) + } +}