You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8f3eb3d
Browse filesBrowse the repository at this point in the historyBrowse files
feat(android): add settings bluetooth on|off (#3721)
* feat(android): add settings bluetooth on|off
Toggle the Android Bluetooth adapter from `settings`, next to wifi and
airplane. QA automation for media playback uses it to stand in for a
Bluetooth audio device disconnecting mid-session.
- Runs `svc bluetooth enable|disable` from Android 8.1 (API 27). From
Android 13 AOSP's `svc` forwards that to `cmd bluetooth_manager`, so one
command serves every supported level.
- The adapter is proven with `pm list features` before the write, so a
device or emulator image without android.hardware.bluetooth is refused
with UNSUPPORTED_OPERATION and reason android_bluetooth_adapter_missing,
unchanged. Builds older than Android 8.1 are refused with
android_bluetooth_command_unavailable, and an unreadable API level
fails with the getprop output before any write.
- `svc bluetooth` exits 0 when the adapter refuses the change, so the
write is confirmed by polling `settings get global bluetooth_on` for up
to 2 s (host-kit pollUntilSettled). A state that never arrives fails
with COMMAND_FAILED and reason bluetooth-not-applied, or
bluetooth-unreadable with the stored value; success reports the
resulting `bluetooth` state.
- Refusals before the write disclose dispatched: no, failures after it
dispatched: unknown. A cancelled request stops before the write.
- Apple targets refuse the setting at admission through the existing
per-owner facts.
- `pm list features` now has one parser, androidFeatureListDeclares, which
TV discovery and the Bluetooth check share. The API-level read moves out
of the permission module into device-sdk-int.ts and keeps its result.
The three copies of the underFakeTimers test helper become one in
test-utils.
* fix(settings): refuse --app on bluetooth and parse the API level strictly
- bluetooth is device-wide, so the catalog declares it the way
mobile-data does: the app rides the request input and a named app is
refused with setting_app_not_consumed before dispatch.
- readAndroidSdkInt accepts only a whole positive integer. parseInt
read `27garbage` as 27, which would let the Bluetooth gate dispatch on
an unreadable API level.
- The docs and changelog say the old-build refusal applies only once
the adapter check passes, and describe bluetooth-unreadable as an
unrecognized bluetooth_on value.
* fix(android): load the Bluetooth setting only when it runs
settings.ts imported settings-bluetooth.ts statically, so importing
mechanics.ts also evaluated settings-bluetooth.ts and the
inventory-parsers.ts it pulls in. The eager-closure budget caught the
growth (176 to 179 modules). The bluetooth case now imports the module
when it runs, the way device-boot and lifecycle load theirs.
* refactor(settings): share the global-toggle read-back and derive device-wide client arms
- mobile-data and bluetooth now go through one setAndroidGlobalToggle in
settings-global-toggle.ts: the svc write, the abort check, the
settings-global read-back poll, the typed settle error, and dispatch
disclosure. Each setting only declares its service, row, value map,
reasons, interval and hint. mobile-data gains the exit-code handling
bluetooth already had, and settings-bluetooth.ts keeps only the
adapter and API-level preflight.
- SettingsUpdateOptions derives one arm for every catalog entry with
app: 'input' and a device-level mobile scope, replacing the
hand-written mobile-data arm. client.settings.update({ setting:
'bluetooth', state: 'off' }) now type-checks. A type test asserts every
SettingName has an arm.
* fix(android): give each global-toggle read its own timeout
pollUntilSettled sleeps up to the deadline and then samples once more.
Each `settings get global` read took the deadline's remaining time as
its adb timeout, so that last read ran with a 1 ms budget and failed as
an adb timeout instead of reaching the typed not-applied reason. Reads
now get a fixed 1 s budget; the 2 s settle window still bounds polling.
* refactor(android): type the global-toggle result by its state key
AndroidGlobalToggle is generic over its stateKey, so setAndroidBluetooth
returns { bluetooth } and the mobile-data toggle { mobileData } again
instead of a string-keyed record.
Copy file name to clipboardExpand all lines: packages/contracts/src/settings-catalog.ts
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -101,6 +101,12 @@ export const SETTINGS = {
101
101
forms: [{kind: 'on-off'}],
102
102
help: 'Android switches Wi-Fi with svc wifi; an Apple simulator overrides only its status bar.',
103
103
},
104
+
bluetooth: {
105
+
forms: [{kind: 'on-off'}],
106
+
app: 'input',
107
+
appScope: {mobile: 'device-level'},
108
+
help: 'Android over adb turns its Bluetooth adapter on or off with svc bluetooth, from Android 8.1. It reports the bluetooth state the device holds afterwards, or fails with bluetooth-not-applied or bluetooth-unreadable. A device without an adapter refuses with android_bluetooth_adapter_missing, and an adapter on a build older than 8.1 with android_bluetooth_command_unavailable, before anything changes. --app is refused.',
109
+
},
104
110
airplane: {
105
111
forms: [{kind: 'on-off'}],
106
112
help: 'Android applies it through the connectivity service (Android 11+) and reports the airplaneMode that service holds; older builds fail without changing anything. An Apple simulator overrides only its status bar.',
0 commit comments