From 9fd65601e94200dd5d1b62d71bbdc8b4d8efd8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=A1=82=E9=9B=84?= Date: Fri, 6 Nov 2026 23:51:04 +0800 Subject: [PATCH 1/7] feat(settings): add keep-awake to hold the screen on Android and HarmonyOS `settings keep-awake on|off` covers the screen-hold workaround automation had to reach for through raw device shells. Android runs `svc power stayon true|false`, which holds the screen while the device charges. HarmonyOS runs `power-shell timeout -o 2147483647`, the largest screen-off timeout the tool accepts, and `off` restores the system timeout with `power-shell timeout -r`. The setting joins the catalog as a device-level mobile toggle, so a named app is refused daemon-side with `setting_app_not_consumed`. The Android and HarmonyOS owners declare the write fact, and so does the Limrun Android leg. Co-Authored-By: Claude Code --- .../command-surface/src/capture/settings.ts | 2 +- packages/contracts/src/settings-catalog.ts | 6 ++++ packages/contracts/src/settings.test.ts | 6 ++-- .../support/snapshot-runtime-fixture.ts | 3 +- .../src/__tests__/settings.test.ts | 30 +++++++++++++++++++ packages/platform-android/src/runtime.ts | 1 + packages/platform-android/src/settings.ts | 9 ++++++ .../src/__tests__/settings.test.ts | 22 ++++++++++++++ .../platform-harmonyos/src/runtime.test.ts | 1 + packages/platform-harmonyos/src/runtime.ts | 4 +-- packages/platform-harmonyos/src/settings.ts | 20 ++++++++++++- .../src/interaction-operations.ts | 1 + 12 files changed, 97 insertions(+), 8 deletions(-) diff --git a/packages/command-surface/src/capture/settings.ts b/packages/command-surface/src/capture/settings.ts index 464b02e14c..e21e6e59da 100644 --- a/packages/command-surface/src/capture/settings.ts +++ b/packages/command-surface/src/capture/settings.ts @@ -35,7 +35,7 @@ const settingsCommandMetadata = defineFieldCommandMetadata( // A readable setting answers with no state; the parse decides per setting. state: stringField(), app: stringField( - 'App the change targets, by bundle id, package name, or app name: the app `clear-app-state` clears, or the app a `permission` change (or an iOS-simulator `location on|off` privacy change) lands on. A name resolves to the installed app as `open` resolves it: an iOS simulator, local or Limrun, matches display names and accepts only an installed bundle id, and Android accepts only an installed package and refuses a name that resolves to an intent with `setting_app_not_package`. One that resolves to nothing is refused with `app_not_installed` before anything changes. The app need not be running. Without it the session app is used; a device-wide change (`location set` on any target, the Android `location on|off` toggle, `mobile-data`, macOS permissions) refuses one with `setting_app_not_consumed`. The CLI reads it only from this invocation, never from `AGENT_DEVICE_TARGET_APP` or config `targetApp`.', + 'App the change targets, by bundle id, package name, or app name: the app `clear-app-state` clears, or the app a `permission` change (or an iOS-simulator `location on|off` privacy change) lands on. A name resolves to the installed app as `open` resolves it: an iOS simulator, local or Limrun, matches display names and accepts only an installed bundle id, and Android accepts only an installed package and refuses a name that resolves to an intent with `setting_app_not_package`. One that resolves to nothing is refused with `app_not_installed` before anything changes. The app need not be running. Without it the session app is used; a device-wide change (`location set` on any target, the Android `location on|off` toggle, `mobile-data`, `keep-awake`, macOS permissions) refuses one with `setting_app_not_consumed`. The CLI reads it only from this invocation, never from `AGENT_DEVICE_TARGET_APP` or config `targetApp`.', ), latitude: numberField(), longitude: numberField(), diff --git a/packages/contracts/src/settings-catalog.ts b/packages/contracts/src/settings-catalog.ts index ad96f20d96..e693bfb427 100644 --- a/packages/contracts/src/settings-catalog.ts +++ b/packages/contracts/src/settings-catalog.ts @@ -117,6 +117,12 @@ export const SETTINGS = { appScope: { mobile: 'device-level' }, help: 'Android only. Runs svc data and reports the stored mobileData state, or fails with mobile-data-not-applied or mobile-data-unreadable. Multi-SIM read-back is not covered yet, and --app is refused.', }, + 'keep-awake': { + forms: [{ kind: 'on-off' }], + app: 'input', + appScope: { mobile: 'device-level' }, + help: 'Android holds its screen on while the device charges (svc power stayon), so a device on battery can still sleep. HarmonyOS raises its screen-off timeout to the largest value the power tool accepts until off restores the timeout the system setting holds. --app is refused.', + }, location: { forms: [ { kind: 'on-off', appScope: { apple: 'app-scoped', mobile: 'device-level' } }, diff --git a/packages/contracts/src/settings.test.ts b/packages/contracts/src/settings.test.ts index 94c6c5a81d..76b53d93e8 100644 --- a/packages/contracts/src/settings.test.ts +++ b/packages/contracts/src/settings.test.ts @@ -40,7 +40,7 @@ function expectInvalidArgs(run: () => unknown, message: string): void { describe('settings usage', () => { test('folds settings that share a form into one line', () => { expect(SETTINGS_USAGE_OVERRIDE.split(' | ')).toEqual([ - 'settings ', + 'settings ', 'settings location set ', 'settings appearance ', `settings text-size [${TEXT_SIZE_CATEGORIES.join('|')}]`, @@ -56,7 +56,7 @@ describe('settings usage', () => { test('the invalid-args message lists the same forms, with the last one as an alternative', () => { expect(SETTINGS_INVALID_ARGS_MESSAGE).toMatch( - /^settings requires , .*, or permission $/, + /^settings requires , .*, or permission $/, ); }); @@ -282,7 +282,7 @@ describe('settingsAppScope', () => { }); describe('settingsAppScope device-wide radios', () => { - test.each(['mobile-data', 'bluetooth'])( + test.each(['mobile-data', 'keep-awake', 'bluetooth'])( '%s switches the whole device wherever it is served', (setting) => { expect(settingsAppScope('mobile', setting, 'on')).toBe('device-level'); diff --git a/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts b/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts index 875b713c1c..edab36cae8 100644 --- a/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts +++ b/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts @@ -185,6 +185,7 @@ function settingsFacts(device: DeviceInfo) { bluetooth: available, airplane: available, 'mobile-data': available, + 'keep-awake': available, location: available, animations: available, appearance: available, @@ -199,7 +200,7 @@ function settingsFacts(device: DeviceInfo) { return settingsRuntimeOperationFacts({ target: available, unsupported, - write: { 'clear-app-state': available }, + write: { 'clear-app-state': available, 'keep-awake': available }, }); case 'apple': break; diff --git a/packages/platform-android/src/__tests__/settings.test.ts b/packages/platform-android/src/__tests__/settings.test.ts index 35e24e23e4..f0b4fd6970 100644 --- a/packages/platform-android/src/__tests__/settings.test.ts +++ b/packages/platform-android/src/__tests__/settings.test.ts @@ -651,3 +651,33 @@ test('setAndroidSetting mobile-data stops sampling when the request is cancelled }, ); }); + +// --- settings keep-awake: svc power stayon --- + +test('setAndroidSetting keep-awake maps on and off to the svc power stayon forms', async () => { + for (const { state, spelling } of [ + { state: 'on', spelling: 'true' }, + { state: 'off', spelling: 'false' }, + ] as const) { + await withFakeAdb( + (args) => (args.join(' ') === `shell svc power stayon ${spelling}` ? '' : undefined), + async ({ calls, device }) => { + await setAndroidSetting(device, 'keep-awake', state); + assert.deepEqual(flatCalls(calls), [`shell svc power stayon ${spelling}`]); + }, + ); + } +}); + +test('setAndroidSetting keep-awake runs nothing for a state svc cannot spell', async () => { + await withFakeAdb( + (args) => ({ stderr: `unexpected args: ${args.join(' ')}`, exitCode: 1 }), + async ({ calls, device }) => { + await assertRejectsAppError(() => setAndroidSetting(device, 'keep-awake', 'forever'), { + code: 'INVALID_ARGS', + message: /Invalid setting state: forever/, + }); + assert.deepEqual(calls, []); + }, + ); +}); diff --git a/packages/platform-android/src/runtime.ts b/packages/platform-android/src/runtime.ts index 1cbaca0de4..9eaaa09763 100644 --- a/packages/platform-android/src/runtime.ts +++ b/packages/platform-android/src/runtime.ts @@ -390,6 +390,7 @@ export function createAndroidPlatformRuntime(host: PlatformRuntimeHost): Platfor bluetooth: available, airplane: available, 'mobile-data': available, + 'keep-awake': available, location: available, animations: available, appearance: available, diff --git a/packages/platform-android/src/settings.ts b/packages/platform-android/src/settings.ts index 4b0ad93361..68cbef9c3b 100644 --- a/packages/platform-android/src/settings.ts +++ b/packages/platform-android/src/settings.ts @@ -53,6 +53,7 @@ export const ANDROID_SETTINGS = [ 'bluetooth', 'airplane', 'mobile-data', + 'keep-awake', 'location', 'animations', 'appearance', @@ -127,6 +128,14 @@ export async function setAndroidSetting( signal, ); } + case 'keep-awake': { + // The `svc` argv spells the stay-on battery sources, not enable|disable, so this write + // cannot share AndroidGlobalToggle. `stayon true` is the developer setting's + // BATTERY_PLUGGED_ANY: the screen stays on while any charger or USB connection is present. + const enabled = parseSettingState(state); + await runAndroidShell(device, ['svc', 'power', 'stayon', enabled ? 'true' : 'false']); + return; + } case 'location': { if (state.toLowerCase() === 'set') { if (device.kind !== 'emulator') { diff --git a/packages/platform-harmonyos/src/__tests__/settings.test.ts b/packages/platform-harmonyos/src/__tests__/settings.test.ts index 5c91ff5877..0079f7d2db 100644 --- a/packages/platform-harmonyos/src/__tests__/settings.test.ts +++ b/packages/platform-harmonyos/src/__tests__/settings.test.ts @@ -43,6 +43,28 @@ test('HarmonyOS clear-app-state force stops then clears bundle data and cache', ); }); +test('HarmonyOS keep-awake raises the screen-off timeout and off restores the system value', async () => { + assert.deepEqual(await setHarmonySetting(device, 'keep-awake', 'on'), { keepAwake: 'enabled' }); + assert.deepEqual(await setHarmonySetting(device, 'keep-awake', 'OFF'), { + keepAwake: 'disabled', + }); + assert.deepEqual( + mockRunHarmonyShell.mock.calls.map((call) => call[1]), + [ + ['power-shell', 'timeout', '-o', '2147483647'], + ['power-shell', 'timeout', '-r'], + ], + ); +}); + +test('HarmonyOS keep-awake runs nothing for a state the tool cannot spell', async () => { + await assert.rejects( + async () => await setHarmonySetting(device, 'keep-awake', 'always'), + /Invalid setting state: always/, + ); + assert.deepEqual(mockRunHarmonyShell.mock.calls, []); +}); + test('HarmonyOS settings rejects unsupported setting and missing app bundle', async () => { await assert.rejects(async () => await setHarmonySetting(device, 'wifi', 'on'), /not supported/); await assert.rejects( diff --git a/packages/platform-harmonyos/src/runtime.test.ts b/packages/platform-harmonyos/src/runtime.test.ts index ea7f4cda4a..63d9ae0998 100644 --- a/packages/platform-harmonyos/src/runtime.test.ts +++ b/packages/platform-harmonyos/src/runtime.test.ts @@ -145,6 +145,7 @@ test.each([ expect(binding.operations[operation]).toBeUndefined(); } expect(runtimeSubjectFact(facts.operations.setSetting, 'clear-app-state').available).toBe(true); + expect(runtimeSubjectFact(facts.operations.setSetting, 'keep-awake').available).toBe(true); expect(runtimeSubjectFact(facts.operations.setSetting, 'wifi').available).toBe(false); expect(binding.operations.setSetting).toBeTypeOf('function'); await expect(binding.operations.ensureReady?.({})).resolves.toMatchObject({ booted: true }); diff --git a/packages/platform-harmonyos/src/runtime.ts b/packages/platform-harmonyos/src/runtime.ts index 59c47bb2be..dfdd925a31 100644 --- a/packages/platform-harmonyos/src/runtime.ts +++ b/packages/platform-harmonyos/src/runtime.ts @@ -204,7 +204,7 @@ const harmonyPlatformLeafUnavailable = unavailableFact( ); const harmonySettingUnavailable = unavailableFact( PLATFORM_RUNTIME_REASONS.unsupportedPlatformLeaf.reason, - 'HarmonyOS supports settings clear-app-state only.', + 'HarmonyOS supports settings clear-app-state and keep-awake only.', ); /** Android's live IME status read has no HarmonyOS counterpart (parity with the retired leaf, @@ -302,7 +302,7 @@ export function createHarmonyPlatformRuntime(host: PlatformRuntimeHost): Platfor ...settingsRuntimeOperationFacts({ target: harmonyFocusFact(device), unsupported: harmonySettingUnavailable, - write: { 'clear-app-state': available }, + write: { 'clear-app-state': available, 'keep-awake': available }, }), // HarmonyOS exposes no alert automation operation. ...alertRuntimeOperationFacts({ diff --git a/packages/platform-harmonyos/src/settings.ts b/packages/platform-harmonyos/src/settings.ts index ec3124ef1c..beb8590b98 100644 --- a/packages/platform-harmonyos/src/settings.ts +++ b/packages/platform-harmonyos/src/settings.ts @@ -1,16 +1,34 @@ import type { DeviceInfo } from '@agent-device/kernel/device'; import { AppError, sessionAppRequiredDetails } from '@agent-device/kernel/errors'; +import { parseSettingState } from '@agent-device/contracts/settings'; import { runHarmonyShell } from './hdc.ts'; +/** + * The screen-off timeout `power-shell timeout -o` accepts at its largest: the 32-bit maximum, in + * milliseconds. `off` restores the timeout the system setting holds (`power-shell timeout -r`). + */ +const HARMONY_KEEP_AWAKE_TIMEOUT_MS = '2147483647'; + export async function setHarmonySetting( device: DeviceInfo, setting: string, state: string, appBundleId?: string, ): Promise> { + if (setting === 'keep-awake') { + const enabled = parseSettingState(state); + await runHarmonyShell( + device, + enabled + ? ['power-shell', 'timeout', '-o', HARMONY_KEEP_AWAKE_TIMEOUT_MS] + : ['power-shell', 'timeout', '-r'], + { timeoutMs: 15_000 }, + ); + return { keepAwake: enabled ? 'enabled' : 'disabled' }; + } if (setting !== 'clear-app-state') { throw new AppError('UNSUPPORTED_OPERATION', `HarmonyOS setting "${setting}" is not supported`, { - hint: 'HarmonyOS currently supports settings clear-app-state for an app bundle only.', + hint: 'HarmonyOS currently supports settings clear-app-state and keep-awake only.', }); } if (state !== 'clear') { diff --git a/packages/provider-limrun/src/interaction-operations.ts b/packages/provider-limrun/src/interaction-operations.ts index 0eb7dec4de..4ef188fb4e 100644 --- a/packages/provider-limrun/src/interaction-operations.ts +++ b/packages/provider-limrun/src/interaction-operations.ts @@ -192,6 +192,7 @@ export function limrunAndroidSettingsFacts( bluetooth: available, airplane: available, 'mobile-data': available, + 'keep-awake': available, location: available, animations: available, appearance: available, From f058c0621f646d14a7bdca13a94b217dffcf2466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=A1=82=E9=9B=84?= Date: Sat, 7 Nov 2026 02:58:55 +0800 Subject: [PATCH 2/7] docs(settings): disclose keep-awake reboot semantics and pin its daemon refusal Review follow-up on the keep-awake slice. The help sentence now discloses persistence: the Android stay-on write survives a reboot, a reboot clears the HarmonyOS override, and `off` restores the timeout the system setting holds. `power-shell setmode` spells only the 600-series power modes, so `timeout -o` is the route that takes the raw 2147483647 millisecond value; the HarmonyOS comment now records that choice for the next reader. `keep-awake` joins the daemon `setting_app_not_consumed` parameterized cases, so the device-level app refusal is pinned at the daemon entry too. Co-Authored-By: Claude Code --- packages/contracts/src/settings-catalog.ts | 2 +- .../handlers/__tests__/snapshot-settings-handler.test.ts | 2 +- packages/platform-harmonyos/src/settings.ts | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/contracts/src/settings-catalog.ts b/packages/contracts/src/settings-catalog.ts index e693bfb427..8301e85de9 100644 --- a/packages/contracts/src/settings-catalog.ts +++ b/packages/contracts/src/settings-catalog.ts @@ -121,7 +121,7 @@ export const SETTINGS = { forms: [{ kind: 'on-off' }], app: 'input', appScope: { mobile: 'device-level' }, - help: 'Android holds its screen on while the device charges (svc power stayon), so a device on battery can still sleep. HarmonyOS raises its screen-off timeout to the largest value the power tool accepts until off restores the timeout the system setting holds. --app is refused.', + help: 'Android holds its screen on while the device charges (svc power stayon), so a device on battery can still sleep; the write survives a reboot. HarmonyOS raises its screen-off timeout to the largest value the power tool accepts; a reboot clears that override. off restores the timeout the system setting holds. --app is refused.', }, location: { forms: [ diff --git a/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts b/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts index 5c5ec6890d..2cd6d35d62 100644 --- a/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts +++ b/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts @@ -680,7 +680,7 @@ test('settings mobile-data reaches the Android owner as an on/off mutation', asy expect(fixtureSettingsMutations.at(-1)).toMatchObject({ setting: 'mobile-data', state: 'off' }); }); -test.each(['mobile-data', 'bluetooth'])( +test.each(['mobile-data', 'keep-awake', 'bluetooth'])( 'settings Android %s refuses a named app before reaching the owner', async (setting) => { const sessionStore = makeSessionStore(); diff --git a/packages/platform-harmonyos/src/settings.ts b/packages/platform-harmonyos/src/settings.ts index beb8590b98..c5b0ba3119 100644 --- a/packages/platform-harmonyos/src/settings.ts +++ b/packages/platform-harmonyos/src/settings.ts @@ -6,6 +6,8 @@ import { runHarmonyShell } from './hdc.ts'; /** * The screen-off timeout `power-shell timeout -o` accepts at its largest: the 32-bit maximum, in * milliseconds. `off` restores the timeout the system setting holds (`power-shell timeout -r`). + * `power-shell setmode` spells only the 600-series power modes, so `timeout -o` is the route that + * takes this raw millisecond value. */ const HARMONY_KEEP_AWAKE_TIMEOUT_MS = '2147483647'; From 1ab17588c9374d0d3bb108ddcf598a13a4a45648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=A1=82=E9=9B=84?= Date: Sun, 8 Nov 2026 21:57:58 +0800 Subject: [PATCH 3/7] fix(android): write the stay-on mask explicitly and report the read-back state svc power stayon true leaves a stored 15 untouched while acking, which a live Redmi K60 run exposed. The backend writes stay_on_while_plugged_in directly (7 for on, 0 for off) and returns the read-back value so the result cannot claim a write the device did not store. Evidence recorded in docs/evidence/. Co-Authored-By: Claude Code --- .../evidence/android-keep-awake-2026-11-08.md | 57 +++++++++++++++++++ .../src/__tests__/settings.test.ts | 25 +++++--- packages/platform-android/src/settings.ts | 26 +++++++-- 3 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 docs/evidence/android-keep-awake-2026-11-08.md diff --git a/docs/evidence/android-keep-awake-2026-11-08.md b/docs/evidence/android-keep-awake-2026-11-08.md new file mode 100644 index 0000000000..fa9806766c --- /dev/null +++ b/docs/evidence/android-keep-awake-2026-11-08.md @@ -0,0 +1,57 @@ +# Android keep-awake end-to-end run and the svc-true no-op, 2026-11-08 + +Evidence for #4290 (keep-awake on and off across Android and HarmonyOS): the +first backend draft lowered `on` to `svc power stayon true`, and a live run +proved that a no-op on real hardware — the command answers and the stored +value never moves when the mask already covers the plugged-in sources. The +shipped backend writes the setting itself and reports the read-back state. + +## Device + +- Xiaomi Redmi K60 (`2312DRAABC` model code), Android 14 (SDK 34), adb serial + `5p4hqglvpzxshiuw`, USB connected. + +## The svc-true no-op (discovered live) + +With the user's stored mask at `15`, the draft command changed nothing while +the CLI still acked the write: + +```sh +$ adb -s 5p4hqglvpzxshiuw shell "settings get global stay_on_while_plugged_in" +15 +$ adb -s 5p4hqglvpzxshiuw shell "svc power stayon true; settings get global stay_on_while_plugged_in" +15 +$ adb -s 5p4hqglvpzxshiuw shell "svc power stayon usb; settings get global stay_on_while_plugged_in" +2 +``` + +`stayon true` does not rewrite a mask that already covers the plugged-in +sources; `stayon usb` rewrites to `2`. A write that skips no-op spellings is +the only reliable form. + +## The shipped backend, end to end through the public CLI + +Branch build of #4290, one command per state, device state read back with raw +`settings get` between the calls: + +```sh +$ node bin/agent-device.mjs settings keep-awake on --platform android --serial 5p4hqglvpzxshiuw +Updated setting: keep-awake +$ adb -s 5p4hqglvpzxshiuw shell "settings get global stay_on_while_plugged_in" +7 +$ node bin/agent-device.mjs settings keep-awake off --platform android --serial 5p4hqglvpzxshiuw +Updated setting: keep-awake +$ adb -s 5p4hqglvpzxshiuw shell "settings get global stay_on_while_plugged_in" +0 +``` + +`15 → 7 → 0`. The user's stored mask was restored to `15` after the run. The +CLI result carries the read-back state (`stayOnWhilePluggedIn`), so an ack can +never claim a write the device did not store. + +## HarmonyOS note + +`power-shell` on JDY-AL50 (7.0.0.111) has no query form: `setmode` spells only +the 600-series modes, `timeout -o ` acks with `Override screen off time to +2147483647`, and `timeout -r` restores. The harmony backend uses the timeout +override for exactly this reason. diff --git a/packages/platform-android/src/__tests__/settings.test.ts b/packages/platform-android/src/__tests__/settings.test.ts index f0b4fd6970..6e2270ab35 100644 --- a/packages/platform-android/src/__tests__/settings.test.ts +++ b/packages/platform-android/src/__tests__/settings.test.ts @@ -652,18 +652,27 @@ test('setAndroidSetting mobile-data stops sampling when the request is cancelled ); }); -// --- settings keep-awake: svc power stayon --- +// --- settings keep-awake: explicit stay-on mask write --- -test('setAndroidSetting keep-awake maps on and off to the svc power stayon forms', async () => { - for (const { state, spelling } of [ - { state: 'on', spelling: 'true' }, - { state: 'off', spelling: 'false' }, +test('setAndroidSetting keep-awake writes the mask and reports the read-back state', async () => { + for (const { state, value, keepAwake } of [ + { state: 'on', value: '7', keepAwake: 'enabled' }, + { state: 'off', value: '0', keepAwake: 'disabled' }, ] as const) { await withFakeAdb( - (args) => (args.join(' ') === `shell svc power stayon ${spelling}` ? '' : undefined), + (args) => { + const joined = args.join(' '); + if (joined === `shell settings put global stay_on_while_plugged_in ${value}`) return ''; + if (joined === 'shell settings get global stay_on_while_plugged_in') return value; + return undefined; + }, async ({ calls, device }) => { - await setAndroidSetting(device, 'keep-awake', state); - assert.deepEqual(flatCalls(calls), [`shell svc power stayon ${spelling}`]); + const result = await setAndroidSetting(device, 'keep-awake', state); + assert.deepEqual(flatCalls(calls), [ + `shell settings put global stay_on_while_plugged_in ${value}`, + 'shell settings get global stay_on_while_plugged_in', + ]); + assert.deepEqual(result, { keepAwake, stayOnWhilePluggedIn: value }); }, ); } diff --git a/packages/platform-android/src/settings.ts b/packages/platform-android/src/settings.ts index 68cbef9c3b..16a80674c1 100644 --- a/packages/platform-android/src/settings.ts +++ b/packages/platform-android/src/settings.ts @@ -129,12 +129,28 @@ export async function setAndroidSetting( ); } case 'keep-awake': { - // The `svc` argv spells the stay-on battery sources, not enable|disable, so this write - // cannot share AndroidGlobalToggle. `stayon true` is the developer setting's - // BATTERY_PLUGGED_ANY: the screen stays on while any charger or USB connection is present. + // `svc power stayon true` is a no-op when the stored mask already covers the plugged-in + // sources (a device holding 15 answers "Updated" with the value unchanged — verified on + // a Redmi K60, Android 14). The write goes to the setting itself with the explicit + // BATTERY_PLUGGED_ANY mask, and the result carries the read-back state. const enabled = parseSettingState(state); - await runAndroidShell(device, ['svc', 'power', 'stayon', enabled ? 'true' : 'false']); - return; + await runAndroidShell(device, [ + 'settings', + 'put', + 'global', + 'stay_on_while_plugged_in', + enabled ? '7' : '0', + ]); + const applied = await runAndroidShell(device, [ + 'settings', + 'get', + 'global', + 'stay_on_while_plugged_in', + ]); + return { + keepAwake: enabled ? 'enabled' : 'disabled', + stayOnWhilePluggedIn: applied.stdout.trim(), + }; } case 'location': { if (state.toLowerCase() === 'set') { From 73d04eb4aec6a19f1e0e4b3f43ecb8a78afde1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=A1=82=E9=9B=84?= Date: Mon, 23 Nov 2026 22:17:58 +0800 Subject: [PATCH 4/7] feat(settings): lower Android keep-awake to svc stayon with mask read-back Co-Authored-By: Claude Code --- packages/contracts/src/settings-catalog.ts | 2 +- .../src/__tests__/settings.test.ts | 62 ++++++++++++++++--- .../src/settings-global-toggle.ts | 23 +++++-- packages/platform-android/src/settings.ts | 46 +++++++------- website/docs/docs/commands.md | 2 +- website/docs/docs/error-reasons.md | 2 + 6 files changed, 98 insertions(+), 39 deletions(-) diff --git a/packages/contracts/src/settings-catalog.ts b/packages/contracts/src/settings-catalog.ts index 8301e85de9..a4b349bf8e 100644 --- a/packages/contracts/src/settings-catalog.ts +++ b/packages/contracts/src/settings-catalog.ts @@ -121,7 +121,7 @@ export const SETTINGS = { forms: [{ kind: 'on-off' }], app: 'input', appScope: { mobile: 'device-level' }, - help: 'Android holds its screen on while the device charges (svc power stayon), so a device on battery can still sleep; the write survives a reboot. HarmonyOS raises its screen-off timeout to the largest value the power tool accepts; a reboot clears that override. off restores the timeout the system setting holds. --app is refused.', + help: 'Android holds its screen on while the device charges (svc power stayon true writes the charging mask, false clears it and does not restore a mask a user set), so a device on battery can still sleep; the write survives a reboot and outlives the session, so run off when the hold ends. HarmonyOS raises its screen-off timeout to the largest value the power tool accepts; a reboot clears that override. off restores the timeout the system setting holds. --app is refused.', }, location: { forms: [ diff --git a/packages/platform-android/src/__tests__/settings.test.ts b/packages/platform-android/src/__tests__/settings.test.ts index 6e2270ab35..b118ca89ee 100644 --- a/packages/platform-android/src/__tests__/settings.test.ts +++ b/packages/platform-android/src/__tests__/settings.test.ts @@ -652,32 +652,76 @@ test('setAndroidSetting mobile-data stops sampling when the request is cancelled ); }); -// --- settings keep-awake: explicit stay-on mask write --- +// --- settings keep-awake: svc power stayon with the mask read-back --- -test('setAndroidSetting keep-awake writes the mask and reports the read-back state', async () => { - for (const { state, value, keepAwake } of [ - { state: 'on', value: '7', keepAwake: 'enabled' }, - { state: 'off', value: '0', keepAwake: 'disabled' }, +test('setAndroidSetting keep-awake writes svc stayon and reads the mask back to a state', async () => { + for (const { state, word, row, keepAwake } of [ + { state: 'on', word: 'true', row: '15', keepAwake: 'enabled' }, + { state: 'off', word: 'false', row: '0', keepAwake: 'disabled' }, ] as const) { await withFakeAdb( (args) => { const joined = args.join(' '); - if (joined === `shell settings put global stay_on_while_plugged_in ${value}`) return ''; - if (joined === 'shell settings get global stay_on_while_plugged_in') return value; + if (joined === `shell svc power stayon ${word}`) return ''; + if (joined === 'shell settings get global stay_on_while_plugged_in') return row; return undefined; }, async ({ calls, device }) => { const result = await setAndroidSetting(device, 'keep-awake', state); assert.deepEqual(flatCalls(calls), [ - `shell settings put global stay_on_while_plugged_in ${value}`, + `shell svc power stayon ${word}`, 'shell settings get global stay_on_while_plugged_in', ]); - assert.deepEqual(result, { keepAwake, stayOnWhilePluggedIn: value }); + assert.deepEqual(result, { keepAwake }); }, ); } }); +test('setAndroidSetting keep-awake reports not-applied when the row stays off', async () => { + await withFakeAdb( + (args) => { + const joined = args.join(' '); + if (joined === 'shell svc power stayon true') return ''; + if (joined === 'shell settings get global stay_on_while_plugged_in') return '0'; + return undefined; + }, + async ({ device }) => { + await assert.rejects( + () => setAndroidSetting(device, 'keep-awake', 'on'), + (error: unknown) => { + assert.ok(error instanceof AppError); + assert.equal(error.code, 'COMMAND_FAILED'); + assert.equal(error.details?.reason, 'keep-awake-not-applied'); + return true; + }, + ); + }, + ); +}); + +test('setAndroidSetting keep-awake reports unreadable for a row that is not a mask', async () => { + await withFakeAdb( + (args) => { + const joined = args.join(' '); + if (joined === 'shell svc power stayon true') return ''; + if (joined === 'shell settings get global stay_on_while_plugged_in') return 'null'; + return undefined; + }, + async ({ device }) => { + await assert.rejects( + () => setAndroidSetting(device, 'keep-awake', 'on'), + (error: unknown) => { + assert.ok(error instanceof AppError); + assert.equal(error.code, 'COMMAND_FAILED'); + assert.equal(error.details?.reason, 'keep-awake-unreadable'); + return true; + }, + ); + }, + ); +}); + test('setAndroidSetting keep-awake runs nothing for a state svc cannot spell', async () => { await withFakeAdb( (args) => ({ stderr: `unexpected args: ${args.join(' ')}`, exitCode: 1 }), diff --git a/packages/platform-android/src/settings-global-toggle.ts b/packages/platform-android/src/settings-global-toggle.ts index 4801aa7ae3..7cc182140a 100644 --- a/packages/platform-android/src/settings-global-toggle.ts +++ b/packages/platform-android/src/settings-global-toggle.ts @@ -22,6 +22,10 @@ export const ANDROID_GLOBAL_TOGGLE_REASONS = { mobileDataNotApplied: { reason: 'mobile-data-not-applied' }, // The device answered the mobile-data read-back with a value that is neither 0 nor 1. mobileDataUnreadable: { reason: 'mobile-data-unreadable' }, + // The device kept the screen turning off after `svc power stayon` accepted the request. + keepAwakeNotApplied: { reason: 'keep-awake-not-applied' }, + // The device answered the keep-awake read-back with a value that is not a stay-on mask. + keepAwakeUnreadable: { reason: 'keep-awake-unreadable' }, } as const satisfies ReasonTable<'settings'>; /** The reason spellings a global-toggle read-back publishes, as `error.details.reason`. */ @@ -36,8 +40,13 @@ export type AndroidToggleState = 'enabled' | 'disabled'; * by polling the row until it holds the requested state. */ export type AndroidGlobalToggle = Readonly<{ - /** The `svc` service name: `svc enable|disable`. */ + /** The `svc` service name: `svc enable|disable`, or `svc ` */ service: string; + /** + * The words after the service when the toggle's `svc` spelling is not `enable|disable`, such as + * `stayon true`. Omit it for the default `enable|disable` words. + */ + writeArgs?: (enabled: boolean) => readonly string[]; /** The `settings global` row the system service persists the switch in. */ row: string; /** How the toggle is named in failure messages. */ @@ -67,11 +76,13 @@ export async function setAndroidGlobalToggle( if (signal?.aborted) throw discloseDispatch(createRequestCanceledError(), 'no'); const requested: AndroidToggleState = enabled ? 'enabled' : 'disabled'; try { - const result = await runAndroidShell( - device, - ['svc', toggle.service, enabled ? 'enable' : 'disable'], - { allowFailure: true, signal }, - ); + const writeArgs = toggle.writeArgs + ? toggle.writeArgs(enabled) + : [enabled ? 'enable' : 'disable']; + const result = await runAndroidShell(device, ['svc', toggle.service, ...writeArgs], { + allowFailure: true, + signal, + }); if (result.exitCode !== 0) { throw androidAdbResultError( `Failed to turn Android ${toggle.label} ${enabled ? 'on' : 'off'}`, diff --git a/packages/platform-android/src/settings.ts b/packages/platform-android/src/settings.ts index 16a80674c1..53195dd68c 100644 --- a/packages/platform-android/src/settings.ts +++ b/packages/platform-android/src/settings.ts @@ -129,28 +129,12 @@ export async function setAndroidSetting( ); } case 'keep-awake': { - // `svc power stayon true` is a no-op when the stored mask already covers the plugged-in - // sources (a device holding 15 answers "Updated" with the value unchanged — verified on - // a Redmi K60, Android 14). The write goes to the setting itself with the explicit - // BATTERY_PLUGGED_ANY mask, and the result carries the read-back state. - const enabled = parseSettingState(state); - await runAndroidShell(device, [ - 'settings', - 'put', - 'global', - 'stay_on_while_plugged_in', - enabled ? '7' : '0', - ]); - const applied = await runAndroidShell(device, [ - 'settings', - 'get', - 'global', - 'stay_on_while_plugged_in', - ]); - return { - keepAwake: enabled ? 'enabled' : 'disabled', - stayOnWhilePluggedIn: applied.stdout.trim(), - }; + return await setAndroidGlobalToggle( + device, + KEEP_AWAKE_TOGGLE, + parseSettingState(state), + signal, + ); } case 'location': { if (state.toLowerCase() === 'set') { @@ -344,6 +328,24 @@ function nearestTextSizeCategory(scale: number): (typeof TEXT_SIZE_CATEGORIES)[n * multi-SIM device keeps it per subscription; that read-back is uncovered until a dual-SIM run shows * which row to read. */ +/** Keep-awake rides `svc power stayon true|false`; the row is the stay-on mask itself. */ +const KEEP_AWAKE_TOGGLE: AndroidGlobalToggle<'keepAwake'> = { + service: 'power', + writeArgs: (enabled) => ['stayon', enabled ? 'true' : 'false'], + row: 'stay_on_while_plugged_in', + label: 'keep-awake', + stateKey: 'keepAwake', + parseRow: (storedValue) => { + if (storedValue === '0') return 'disabled'; + if (/^[1-9][0-9]*$/.test(storedValue)) return 'enabled'; + return undefined; + }, + notAppliedReason: ANDROID_GLOBAL_TOGGLE_REASONS.keepAwakeNotApplied.reason, + unreadableReason: ANDROID_GLOBAL_TOGGLE_REASONS.keepAwakeUnreadable.reason, + sampleIntervalMs: 100, + hint: 'Check the stay-on mask with: adb shell settings get global stay_on_while_plugged_in', +}; + const MOBILE_DATA_TOGGLE: AndroidGlobalToggle<'mobileData'> = { service: 'data', row: 'mobile_data', diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 9629884733..d178b511e6 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -1728,7 +1728,7 @@ agent-device trigger-app-event screenshot_taken '{"source":"qa"}' Change OS settings and app permissions. ```bash -agent-device settings | settings location set | settings appearance | settings text-size [extra-small|small|medium|large|extra-large|extra-extra-large|extra-extra-extra-large|accessibility-medium|accessibility-large|accessibility-extra-large|accessibility-extra-extra-large|accessibility-extra-extra-extra-large] | settings | settings fingerprint | settings clear-app-state [app-id] | settings reset-keychain clear | settings permission | settings permission photos [full|limited] | settings permission [--app ] +agent-device settings | settings location set | settings appearance | settings text-size [extra-small|small|medium|large|extra-large|extra-extra-large|extra-extra-extra-large|accessibility-medium|accessibility-large|accessibility-extra-large|accessibility-extra-extra-large|accessibility-extra-extra-extra-large] | settings | settings fingerprint | settings clear-app-state [app-id] | settings reset-keychain clear | settings permission | settings permission photos [full|limited] | settings permission [--app ] ``` | Option | What it does | diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index ff7e8f53ec..bada98efed 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -354,6 +354,8 @@ Treat a reason that this page does not list as unknown, not as an error in the r | `bluetooth-unreadable` | The device answered the Bluetooth read-back with a value that is not a known state. | | `mobile-data-not-applied` | The device kept mobile data in its prior state after `svc data` accepted the request. | | `mobile-data-unreadable` | The device answered the mobile-data read-back with a value that is neither 0 nor 1. | +| `keep-awake-not-applied` | The device kept the screen turning off after `svc power stayon` accepted the request. | +| `keep-awake-unreadable` | The device answered the keep-awake read-back with a value that is not a stay-on mask. | | `setting_app_not_package` | The named app resolves to an intent such as `settings`, not to an installed package. | | `app-no-data-container` | `clear-app-state` was refused because the installed app owns no data container. | From b2f9bec9f137779b60b27c8d037bdbd9e438ec6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=A1=82=E9=9B=84?= Date: Mon, 23 Nov 2026 22:43:05 +0800 Subject: [PATCH 5/7] docs(evidence): record both keep-awake live runs and the restore defect Co-Authored-By: Claude Code --- .../evidence/android-keep-awake-2026-11-08.md | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/docs/evidence/android-keep-awake-2026-11-08.md b/docs/evidence/android-keep-awake-2026-11-08.md index fa9806766c..2537006d89 100644 --- a/docs/evidence/android-keep-awake-2026-11-08.md +++ b/docs/evidence/android-keep-awake-2026-11-08.md @@ -55,3 +55,54 @@ never claim a write the device did not store. the 600-series modes, `timeout -o ` acks with `Override screen off time to 2147483647`, and `timeout -r` restores. The harmony backend uses the timeout override for exactly this reason. + +## The live Android repro at head 73d04eb4a (2026-11-23) + +The review asked for a device where `svc power stayon true` fails, or the +hand-written mask dropped for the toggle read-back. The Redmi 2312DRAABC +(Android 14, MIUI) answers the question from the other side: + +```sh +$ adb shell settings get global stay_on_while_plugged_in +0 +$ adb shell svc power stayon true +$ adb shell settings get global stay_on_while_plugged_in +15 +$ adb shell svc power stayon false +$ adb shell settings get global stay_on_while_plugged_in +0 +``` + +`svc power stayon true` writes 15 from a 0 row on this unit — the original +lowering keeps the screen on here, and `false` returns the row to 0. The +shipped 7 write would clobber a 15 a dock or user had set, so the lowering now +rides the global-toggle machinery: `svc power stayon true|false`, the row +polled to a state (`0` disabled, any positive mask enabled), and the typed +`keep-awake-not-applied` / `keep-awake-unreadable` reasons on a read-back that +did not move or is not a mask. The result is `{ keepAwake }` only. + +## The HarmonyOS half, live at head 86439819-era build (2026-11-23) + +Ran on the JDY-AL50 through the branch CLI (`settings keep-awake on|off +--platform harmonyos --json`, both answer `keepAwake: enabled|disabled`), with +the screen state read from `hidumper -s DisplayPowerManagerService` +(`State=0` is screen off): + +- Baseline, keep-awake off: wake, then screen off at **198s** — the untouched + system timer. +- keep-awake on (`timeout -o 2147483647`): wake, then **no screen off through + 360s** (the display sits dimmed, `State=2`, and never reaches 0). The + override holds the screen up past the system timer. +- A 10-second override confirms `-o` is honored: screen off at **12s**. +- keep-awake off (`timeout -r`): **the restore fails on this unit.** After the + ack ("Restore screen off time"), the screen stayed up past 260s in an + isolated cycle, and again after a fresh suspend/wake. The baseline 198s was + the system timer with no override active — the first `-r` was a no-op, not a + restore. + +So on 7.0.0.111, `timeout -r` acks but does not clear an active `-o` +override: the PR's "off restores the timeout the system setting holds" does +not hold after a hold has been raised. The unit now sits at an explicit +`timeout -o 180000` (verified: screen off at 185s). Choosing a restore route +that works (a stored pre-override value, or another tool path) is an owner +decision; the CLI cannot read the current timeout to snapshot it. From abbba3a036e75c884675be615ea65dd01308d63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=A1=82=E9=9B=84?= Date: Mon, 23 Nov 2026 23:40:47 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix(settings)!:=20land=20Android=20keep-awa?= =?UTF-8?q?ke=20alone=20=E2=80=94=20HarmonyOS=20half=20moves=20out=20per?= =?UTF-8?q?=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The maintainer's live review on JDY-AL50 (HarmonyOS 7.0.0.111) proved power-shell timeout -r acks but does not clear an active -o override, so harmony off reported disabled while the hold stayed up. No proven restore route exists and no device is reachable to prove one, so the HarmonyOS half leaves this PR behind the maintainer's option B; Android lands alone. settings keep-awake now serves Android only: the harmony owner drops the keep-awake fact, so a harmony request refuses as unsupported-platform-leaf through the owner's settings facts before dispatch, and the catalog help loses its harmony clauses. A future PR may bring the half back behind a proven restore route recorded in the PR thread. --- .../evidence/android-keep-awake-2026-11-08.md | 35 +++---------------- packages/contracts/src/settings-catalog.ts | 2 +- .../support/snapshot-runtime-fixture.ts | 2 +- .../src/__tests__/settings.test.ts | 22 ------------ .../platform-harmonyos/src/runtime.test.ts | 2 +- packages/platform-harmonyos/src/runtime.ts | 4 +-- packages/platform-harmonyos/src/settings.ts | 22 +----------- 7 files changed, 11 insertions(+), 78 deletions(-) diff --git a/docs/evidence/android-keep-awake-2026-11-08.md b/docs/evidence/android-keep-awake-2026-11-08.md index 2537006d89..ee577cbc4a 100644 --- a/docs/evidence/android-keep-awake-2026-11-08.md +++ b/docs/evidence/android-keep-awake-2026-11-08.md @@ -51,10 +51,11 @@ never claim a write the device did not store. ## HarmonyOS note -`power-shell` on JDY-AL50 (7.0.0.111) has no query form: `setmode` spells only -the 600-series modes, `timeout -o ` acks with `Override screen off time to -2147483647`, and `timeout -r` restores. The harmony backend uses the timeout -override for exactly this reason. +HarmonyOS keep-awake moved out of #4290 (maintainer option B): no device was +reachable to prove a restore route, and on JDY-AL50 (HarmonyOS 7.0.0.111) +`power-shell timeout -r` acks but does not clear an active `-o` override (the +screen stayed up past 260s). The finding is recorded in the PR thread; a +future PR may bring the half back behind a proven restore route. ## The live Android repro at head 73d04eb4a (2026-11-23) @@ -80,29 +81,3 @@ rides the global-toggle machinery: `svc power stayon true|false`, the row polled to a state (`0` disabled, any positive mask enabled), and the typed `keep-awake-not-applied` / `keep-awake-unreadable` reasons on a read-back that did not move or is not a mask. The result is `{ keepAwake }` only. - -## The HarmonyOS half, live at head 86439819-era build (2026-11-23) - -Ran on the JDY-AL50 through the branch CLI (`settings keep-awake on|off ---platform harmonyos --json`, both answer `keepAwake: enabled|disabled`), with -the screen state read from `hidumper -s DisplayPowerManagerService` -(`State=0` is screen off): - -- Baseline, keep-awake off: wake, then screen off at **198s** — the untouched - system timer. -- keep-awake on (`timeout -o 2147483647`): wake, then **no screen off through - 360s** (the display sits dimmed, `State=2`, and never reaches 0). The - override holds the screen up past the system timer. -- A 10-second override confirms `-o` is honored: screen off at **12s**. -- keep-awake off (`timeout -r`): **the restore fails on this unit.** After the - ack ("Restore screen off time"), the screen stayed up past 260s in an - isolated cycle, and again after a fresh suspend/wake. The baseline 198s was - the system timer with no override active — the first `-r` was a no-op, not a - restore. - -So on 7.0.0.111, `timeout -r` acks but does not clear an active `-o` -override: the PR's "off restores the timeout the system setting holds" does -not hold after a hold has been raised. The unit now sits at an explicit -`timeout -o 180000` (verified: screen off at 185s). Choosing a restore route -that works (a stored pre-override value, or another tool path) is an owner -decision; the CLI cannot read the current timeout to snapshot it. diff --git a/packages/contracts/src/settings-catalog.ts b/packages/contracts/src/settings-catalog.ts index a4b349bf8e..bc34381134 100644 --- a/packages/contracts/src/settings-catalog.ts +++ b/packages/contracts/src/settings-catalog.ts @@ -121,7 +121,7 @@ export const SETTINGS = { forms: [{ kind: 'on-off' }], app: 'input', appScope: { mobile: 'device-level' }, - help: 'Android holds its screen on while the device charges (svc power stayon true writes the charging mask, false clears it and does not restore a mask a user set), so a device on battery can still sleep; the write survives a reboot and outlives the session, so run off when the hold ends. HarmonyOS raises its screen-off timeout to the largest value the power tool accepts; a reboot clears that override. off restores the timeout the system setting holds. --app is refused.', + help: 'Android holds its screen on while the device charges (svc power stayon true writes the charging mask, false clears it and does not restore a mask a user set), so a device on battery can still sleep; the write survives a reboot and outlives the session, so run off when the hold ends. --app is refused.', }, location: { forms: [ diff --git a/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts b/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts index edab36cae8..f60797edb6 100644 --- a/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts +++ b/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts @@ -200,7 +200,7 @@ function settingsFacts(device: DeviceInfo) { return settingsRuntimeOperationFacts({ target: available, unsupported, - write: { 'clear-app-state': available, 'keep-awake': available }, + write: { 'clear-app-state': available }, }); case 'apple': break; diff --git a/packages/platform-harmonyos/src/__tests__/settings.test.ts b/packages/platform-harmonyos/src/__tests__/settings.test.ts index 0079f7d2db..5c91ff5877 100644 --- a/packages/platform-harmonyos/src/__tests__/settings.test.ts +++ b/packages/platform-harmonyos/src/__tests__/settings.test.ts @@ -43,28 +43,6 @@ test('HarmonyOS clear-app-state force stops then clears bundle data and cache', ); }); -test('HarmonyOS keep-awake raises the screen-off timeout and off restores the system value', async () => { - assert.deepEqual(await setHarmonySetting(device, 'keep-awake', 'on'), { keepAwake: 'enabled' }); - assert.deepEqual(await setHarmonySetting(device, 'keep-awake', 'OFF'), { - keepAwake: 'disabled', - }); - assert.deepEqual( - mockRunHarmonyShell.mock.calls.map((call) => call[1]), - [ - ['power-shell', 'timeout', '-o', '2147483647'], - ['power-shell', 'timeout', '-r'], - ], - ); -}); - -test('HarmonyOS keep-awake runs nothing for a state the tool cannot spell', async () => { - await assert.rejects( - async () => await setHarmonySetting(device, 'keep-awake', 'always'), - /Invalid setting state: always/, - ); - assert.deepEqual(mockRunHarmonyShell.mock.calls, []); -}); - test('HarmonyOS settings rejects unsupported setting and missing app bundle', async () => { await assert.rejects(async () => await setHarmonySetting(device, 'wifi', 'on'), /not supported/); await assert.rejects( diff --git a/packages/platform-harmonyos/src/runtime.test.ts b/packages/platform-harmonyos/src/runtime.test.ts index 63d9ae0998..ff1bfc4b48 100644 --- a/packages/platform-harmonyos/src/runtime.test.ts +++ b/packages/platform-harmonyos/src/runtime.test.ts @@ -145,7 +145,7 @@ test.each([ expect(binding.operations[operation]).toBeUndefined(); } expect(runtimeSubjectFact(facts.operations.setSetting, 'clear-app-state').available).toBe(true); - expect(runtimeSubjectFact(facts.operations.setSetting, 'keep-awake').available).toBe(true); + expect(runtimeSubjectFact(facts.operations.setSetting, 'keep-awake').available).toBe(false); expect(runtimeSubjectFact(facts.operations.setSetting, 'wifi').available).toBe(false); expect(binding.operations.setSetting).toBeTypeOf('function'); await expect(binding.operations.ensureReady?.({})).resolves.toMatchObject({ booted: true }); diff --git a/packages/platform-harmonyos/src/runtime.ts b/packages/platform-harmonyos/src/runtime.ts index dfdd925a31..59c47bb2be 100644 --- a/packages/platform-harmonyos/src/runtime.ts +++ b/packages/platform-harmonyos/src/runtime.ts @@ -204,7 +204,7 @@ const harmonyPlatformLeafUnavailable = unavailableFact( ); const harmonySettingUnavailable = unavailableFact( PLATFORM_RUNTIME_REASONS.unsupportedPlatformLeaf.reason, - 'HarmonyOS supports settings clear-app-state and keep-awake only.', + 'HarmonyOS supports settings clear-app-state only.', ); /** Android's live IME status read has no HarmonyOS counterpart (parity with the retired leaf, @@ -302,7 +302,7 @@ export function createHarmonyPlatformRuntime(host: PlatformRuntimeHost): Platfor ...settingsRuntimeOperationFacts({ target: harmonyFocusFact(device), unsupported: harmonySettingUnavailable, - write: { 'clear-app-state': available, 'keep-awake': available }, + write: { 'clear-app-state': available }, }), // HarmonyOS exposes no alert automation operation. ...alertRuntimeOperationFacts({ diff --git a/packages/platform-harmonyos/src/settings.ts b/packages/platform-harmonyos/src/settings.ts index c5b0ba3119..29ddb2762b 100644 --- a/packages/platform-harmonyos/src/settings.ts +++ b/packages/platform-harmonyos/src/settings.ts @@ -1,36 +1,16 @@ import type { DeviceInfo } from '@agent-device/kernel/device'; import { AppError, sessionAppRequiredDetails } from '@agent-device/kernel/errors'; -import { parseSettingState } from '@agent-device/contracts/settings'; import { runHarmonyShell } from './hdc.ts'; -/** - * The screen-off timeout `power-shell timeout -o` accepts at its largest: the 32-bit maximum, in - * milliseconds. `off` restores the timeout the system setting holds (`power-shell timeout -r`). - * `power-shell setmode` spells only the 600-series power modes, so `timeout -o` is the route that - * takes this raw millisecond value. - */ -const HARMONY_KEEP_AWAKE_TIMEOUT_MS = '2147483647'; - export async function setHarmonySetting( device: DeviceInfo, setting: string, state: string, appBundleId?: string, ): Promise> { - if (setting === 'keep-awake') { - const enabled = parseSettingState(state); - await runHarmonyShell( - device, - enabled - ? ['power-shell', 'timeout', '-o', HARMONY_KEEP_AWAKE_TIMEOUT_MS] - : ['power-shell', 'timeout', '-r'], - { timeoutMs: 15_000 }, - ); - return { keepAwake: enabled ? 'enabled' : 'disabled' }; - } if (setting !== 'clear-app-state') { throw new AppError('UNSUPPORTED_OPERATION', `HarmonyOS setting "${setting}" is not supported`, { - hint: 'HarmonyOS currently supports settings clear-app-state and keep-awake only.', + hint: 'HarmonyOS currently supports settings clear-app-state only.', }); } if (state !== 'clear') { From dd45e0f5f5f9c8bd7f0f4b20bdd3de89fe5f54be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=A1=82=E9=9B=84?= Date: Tue, 24 Nov 2026 09:51:57 +0800 Subject: [PATCH 7/7] docs(evidence): match the Android-only scope in the keep-awake evidence intro The PR title and the shipped backend are Android-only after the HarmonyOS half moved out; the evidence intro still said "across Android and HarmonyOS". The HarmonyOS note stays as the recorded restore-route finding. --- docs/evidence/android-keep-awake-2026-11-08.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/evidence/android-keep-awake-2026-11-08.md b/docs/evidence/android-keep-awake-2026-11-08.md index ee577cbc4a..2a38fc7347 100644 --- a/docs/evidence/android-keep-awake-2026-11-08.md +++ b/docs/evidence/android-keep-awake-2026-11-08.md @@ -1,6 +1,6 @@ # Android keep-awake end-to-end run and the svc-true no-op, 2026-11-08 -Evidence for #4290 (keep-awake on and off across Android and HarmonyOS): the +Evidence for #4290 (keep-awake on and off on Android): the first backend draft lowered `on` to `svc power stayon true`, and a live run proved that a no-op on real hardware — the command answers and the stored value never moves when the mask already covers the plugged-in sources. The