Skip to content

feat(mobile): add encrypted, isolated connection profiles (Phase 2) - #12121

Merged
wenshao merged 3 commits into
QwenLM:mainfrom
jabrailkhalil:feat/android-phase2-profiles
Sep 22, 2026
Merged

wenshao merged 3 commits into
QwenLM:mainfrom
jabrailkhalil:feat/android-phase2-profiles

Conversation

@jabrailkhalil

@jabrailkhalil jabrailkhalil commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

Initialization safety update (acac9a3b3d): repeated tests found that WebView 124 can reuse stale localStorage for a fresh profile name after rapid process restart. The final implementation persists an initialization marker, checks the provider registry before creation, and completes profile-scoped browsing-data deletion before loading any page or credential. New/migrated/missing profiles require both MULTI_PROFILE and DELETE_BROWSING_DATA; WebView 124 fails closed. Existing native credentials migrate intact, with a one-time browser-session/cache reset. Initialized known profiles retain state. Cancellation, concurrent deletion and stale Activity identities cannot authorize loading. Guard design (EN), 中文.

Ready for review after #11722 merged. This connection-profile foundation is rebased onto main (8b39d93a42), with head a765ac1ecf9acdc67afa51610c432a3359c3ad14. The comparison now contains its two Phase 2 commits and a YAML formatting follow-up; the already merged PWA/Android scaffold history is removed. The implementation files are byte-identical to the previously verified acac9a3b3d revision. This is the first focused Phase 2 slice, not completion of the entire mobile roadmap.

Verification provenance: a separate September 18 comment records fresh checks on the rebased head. Earlier screenshots and additional interactive/adversarial scenarios below remain pre-rebase evidence for the identical implementation; they are not new runs. Upstream CI must complete, and maintainer approval is still required.

CI follow-up, September 18: a765ac1ecf adds single quotes around the two emulator architecture values, fixing the quoted-strings failure in the mobile workflow. Pinned yamllint 1.35.1 passes, and the parsed YAML is unchanged. Native/H5 source files are unchanged from the tested head in the verification comment; upstream checks are rerunning for this additive commit.

Adds native Add/Edit/Connect/Delete controls, an Android Keystore-backed encrypted vault with recoverable migration from the development profile, and isolated WebView storage for each connection. Changing an address or credential rotates browser identity; switching destroys the old view and cancels its dialogs. Lost keys or corrupt data show explicit recovery, and providers without isolated-profile support show an update message instead of sharing browser storage.

Why it's needed

The development shell currently requires editing private preferences and stores one credential in plaintext. Users need to manage multiple daemon connections without carrying authentication or workspace state between them. The daemon-served Web Shell remains the session UI; this introduces neither a separate chat implementation nor a new protocol.

Reviewer Test Plan

How to verify

  1. On a clean install, add two named connections to the same test daemon origin with different synthetic credentials. Connect and switch between them: each receives its own credential and isolated cookies/localStorage. Reopening the editor never reveals a stored token; newly typed tokens are masked.
  2. Rename a connection, then change its credential or address. Renaming retains its browser data; changing either connection detail starts with fresh browser data. An address change cannot silently reuse the saved credential. Delete requires confirmation and leaves other connections intact.
  3. Upgrade a development installation with valid legacy preferences. Its connection should migrate, persist across relaunch, and lose the old plaintext preferences only after successful encrypted persistence. Corruption or key loss must show Retry/Reset; cancelling Reset preserves data, while confirming it requires re-entering connections.
  4. Use a provider without MULTI_PROFILE: management remains usable, while Connect gives native update guidance. On a supported provider, stop and restart the local test server and use Retry; the selected connection should recover. Cancel a native JavaScript confirmation and confirm the page receives cancellation.

Evidence (Before & After)

Before: the clean development APK only displays “No valid daemon profile.” After: native connection management and masked credential entry. Screenshots use synthetic data. A separate E2E comment records exact environments, observed behavior and limitations.

BeforeAfter: connectionsAfter: masked input
Before: no native setupAfter: two connectionsAfter: masked credential input

Tested on

OS Status
macOS Not tested
Windows Debug/unsigned-release builds, 21 JVM tests, lint; final API 35/36 emulator acceptance
Linux Not run locally; API 26/36 CI lanes require execution after submission

Environment

Final acac9a3b3d: JDK17, Gradle8.2.1, compileSDK34, AndroidX WebKit1.13.0. Debug/unsigned-release builds,21 JVM tests and lint passed (0 errors,6 existing notices). API36/WebView134:6 committed tests passed,1 old-provider-only skip. API35/WebView124:4 passed,3 unsupported-feature skips, including actual Connect failing closed without HTTP. Production-path tests inspect the first HTTP cookie and initial cookie/localStorage/IndexedDB/cache, then verify retention on reconnect. Independent rapid-restart and cancellation/stale-state checks also passed. Earlier95ff provider results below are historical and do not establish the new initialization guarantee. Native-only validation uses Gradle; no TypeScript files changed. Upstream workflows require maintainer authorization.

Risk & Scope

  • Main tradeoff: connecting now requires MULTI_PROFILE and, for initialization, DELETE_BROWSING_DATA, in addition to WebView 111+. There is no shared-storage fallback. Obsolete browser identities are never reused; deletion may wait until the next cold launch when the provider allows it.
  • Security boundary: native saved profile data is AES-GCM encrypted with a Keystore key. Web Shell still uses its existing sessionStorage token bootstrap; Chromium does not guarantee that storage is memory-only, so this is not a claim that every WebView-held token copy is encrypted. Backup/device-transfer exclusions are configured, but an actual backup/restore was not exercised.
  • Not validated/out of scope: physical devices, real remote TLS, model calls, daemon-issued per-device credentials/revocation, background SSE/notifications, files/media and full accessibility acceptance. The app remains a development client; local deletion does not revoke a server credential. Official signing/distribution remains a maintainer decision.
  • Migration: existing valid development preferences are imported once; failed writes preserve the legacy source, and failed cleanup blocks connection until recovery. Explicit reset cannot recover a missing Keystore key.

Design: English / 简体中文, synchronized in this commit.

Linked Issues

Refs #11704. Builds on merged #11722. Follows the maintainer's native-shell / REST+SSE architecture and the Phase 2 proposal.

中文说明

改动内容

**初始化安全更新(acac9a3b3d):**反复测试发现 WebView 124 在快速重启进程后可能将旧 localStorage 复用于新配置名称。最终实现持久化初始化标志,在创建前检查提供程序注册表,并在加载页面或凭据前完成配置级浏览数据清除。新建、迁移或提供程序中名称缺失的配置同时要求 MULTI_PROFILE 和 DELETE_BROWSING_DATA,WebView 124 会拒绝不安全连接。原生凭据完整迁移,浏览器会话和缓存会清除一次;已初始化且名称仍存在的配置保留状态。取消、并发删除及过期 Activity 标识不能授权加载。上方链接提供完整英中初始化设计。

#11722 已合并,本 PR 已准备好接受评审。 连接配置基础已变基到 main(8b39d93a42),当前提交为 a765ac1ecf9acdc67afa51610c432a3359c3ad14。与 main 的差异包含本切片的两个 Phase 2 提交及一个 YAML 格式修正提交,已移除合并后的 PWA/Android 骨架历史。实现文件与此前验证的 acac9a3b3d 逐字节相同。这是首个聚焦的 Phase 2 切片,并非整个移动端路线图已完成。

验证来源: 9 月 18 日的独立评论记录变基后提交的新验证。下方早先截图及额外交互/对抗场景仍是相同实现的变基前证据,不能视为本次重新执行。仍需上游 CI 完成及维护者评审通过。

9 月 18 日 CI 后续修正: a765ac1ecf 为两个模拟器架构值添加单引号,修复移动端 workflow 的 quoted-strings 错误。固定版本 yamllint 1.35.1 验证通过,YAML 解析结果不变。原生/H5 源码与验证评论中的已测试提交相同,上游检查正在针对这个追加提交重新运行。

新增原生添加、编辑、连接、删除操作,基于 Android Keystore 的加密存储、可恢复的开发配置迁移,以及每个连接独立的 WebView 存储。修改地址或凭据会轮换浏览器身份;切换时销毁旧视图并取消其对话框。密钥丢失或数据损坏时提供明确恢复入口;不支持隔离配置的提供方显示更新提示,不回退到共享存储。

动机

目前开发外壳需要编辑私有偏好,并以明文保存单个凭据。用户需要管理多个 daemon 连接,同时避免认证和工作区状态串用。会话界面仍由 daemon 提供的 Web Shell 负责;本改动不增加另一套聊天界面或新协议。

评审测试计划

验证方法

  1. 全新安装后,为同一测试 daemon origin 添加两个名称不同、合成凭据不同的配置。连接并切换,确认凭据、Cookie 和 localStorage 隔离。重新打开编辑器不会显示已保存的 token;新输入的 token 被遮蔽。
  2. 重命名配置,再修改其凭据或地址。重命名保留浏览器数据;修改连接信息会使用新的浏览器数据。修改地址不能静默沿用旧凭据。删除需要确认,并保留其他配置。
  3. 升级带有有效旧偏好的开发安装。配置应迁移并在重启后保留;只有加密持久化成功才删除旧明文偏好。密文损坏或密钥丢失应显示重试/重置;取消重置保留数据,确认后需要重新输入连接信息。
  4. 使用不支持 MULTI_PROFILE 的提供方:仍可管理配置,但连接会显示原生更新提示。在支持的提供方上停止并重新启动本地测试服务器,然后点击重试,确认恢复所选连接。取消原生 JavaScript 确认框,确认页面收到取消结果。

前后对比证据

之前:全新开发 APK 只显示“No valid daemon profile”。之后:原生连接管理和遮蔽的凭据输入。上方截图均使用合成数据。独立 E2E 评论记录具体环境、观察结果和限制。

测试平台

操作系统 状态
macOS 未测试
Windows 调试及未签名发布构建、21 项 JVM 测试、lint;最终 API 35/36 模拟器验收
Linux 未在本地运行;API 26/36 CI 通道需要提交后执行

环境

最终 acac9a3b3d:JDK17、Gradle8.2.1、compileSDK34、AndroidX WebKit1.13.0。调试及未签名发布构建、21项JVM测试和lint通过(0错误、6项既有提示)。API36/WebView134的已提交测试6项通过、1项仅适用旧提供程序而跳过;API35/WebView124为4项通过、3项因能力不支持跳过,其中真实Connect验证拒绝连接且不发HTTP。产品路径测试检查首个HTTP cookie及最初的cookie/localStorage/IndexedDB/cache,并验证重连保留。独立快速重启、取消及过期状态检查也通过。早期95ff提供程序结果仅为历史记录,不能证明新的初始化保证。本改动仅涉及原生端,采用Gradle验证,没有TypeScript改动;上游工作流需要维护者授权。

风险与范围

  • 主要取舍:连接除 WebView 111+ 外,还要求提供方实际支持 MULTI_PROFILE,初始化时还必须支持 DELETE_BROWSING_DATA,不提供共享存储回退。废弃身份永不复用;删除浏览器数据可能要等到下次冷启动且提供方允许时执行。
  • 安全边界:原生保存的配置以 Keystore 密钥进行 AES-GCM 加密。Web Shell 仍采用现有 sessionStorage token 引导;Chromium 不保证仅内存存储,因此不宣称每个 WebView token 副本都被加密。已配置备份/设备迁移排除,但未实测备份恢复。
  • 未验证或不在范围内:真机、真实远程 TLS、模型调用、daemon 逐设备凭据/撤销、后台 SSE/通知、文件/媒体和完整无障碍验收。应用仍是开发客户端,本地删除不会撤销服务器凭据;官方签名与分发由维护者决定。
  • 迁移:有效开发偏好导入一次;写入失败保留旧来源,清理失败则阻止连接直到恢复。明确重置不能恢复丢失的 Keystore 密钥。

设计:English / 简体中文,本提交保持同步。

关联议题

关联 #11704,基于已合并的 #11722。遵循维护者的原生外壳 / REST+SSE 架构及 Phase 2 提案。

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

E2E and build verification — 95ff656f9f

Windows host, JDK 17, Gradle 8.2.1, SDK 34. Final debug APK SHA-256: 3578e9f5de1a5891b6605aed7654406b8b8c5e64b6e1efd948cf66be7c20be06. No user credentials or model calls were used.

Check Observed result
Debug + release APK builds Passed; release output is unsigned, not an official release
JVM tests 18 passed: origin policy, authenticated encryption, migration/fault handling, identity rotation and deletion
Android lint 0 errors; 6 dependency-version notices
API 26 / provider 69 Real Keystore migration/reopen/key loss, tampering, reset: 3 passed; unsupported browser-profile test explicitly skipped
API 34 / provider 113 Earlier verification build: same 3 storage tests passed, isolation skipped; native update guidance, CRUD/migration/masking/tamper recovery tested
API 35 / provider 124 Final APK: all 4 instrumentation tests passed, with isolation support required; positive cookie/sessionStorage controls prevent a vacuous isolation pass
Native UI on API 35 Same-origin profile switching, credential/address rotation, no-token reset, Back/Connections, Delete, connection Retry and JS confirmation tested using a localhost fixture
Repository checks Native workspace isolation, workflow size, YAML parsing, changed Markdown/YAML formatting and whitespace passed

Build command, from the native package:

gradlew.bat --no-daemon :app:assembleDebug :app:assembleRelease :app:testDebugUnitTest :app:lintDebug :app:assembleDebugAndroidTest

Instrumented acceptance, after installing the matching application and test APKs:

adb -s emulator-5558 shell am instrument -w -r com.qwen.mobileshell.test/androidx.test.runner.AndroidJUnitRunner
adb -s emulator-5556 shell am instrument -w -r -e requireProfileIsolation true com.qwen.mobileshell.test/androidx.test.runner.AndroidJUnitRunner

Read the per-test statuses: the old-provider runner prints OK (4 tests) even with one assumption skip. Those runs are 3 passed / 1 skipped, not four passing isolation-capable tests. CI includes API 26 and API 35 lanes, and the API 35 lane fails if profile isolation is unsupported. Remote CI results are not implied by these local results.

Observed native behavior

  • The baseline APK had no native setup UI and retained the synthetic development token in plaintext. Upgrading migrated it into encrypted storage and removed the old preferences. Rename/add/delete persisted through cold launch. Stored credentials were never prefilled in the editor; new input was masked.
  • Invalid names/addresses were rejected. Changing an address with “Keep the saved credential” and no replacement was rejected. Tampered ciphertext showed recovery; Retry did not bypass it. Cancel kept the data, while confirmed Reset stayed empty after relaunch.
  • On API 35, Alpha and Beta at the same local origin each received their own synthetic fragment token. They retained their own localStorage/cookies on return; each new WebView began with fresh sessionStorage. Credential rotation, origin change and an origin roundtrip all started empty browser storage. Explicitly clearing the token sent no token and exposed no earlier browser state.
  • Removing a test reverse tunnel showed the native connection error; restoring it and pressing Retry recovered the selected profile. Back/Connections returned to the list. Deleting Beta preserved Alpha. A fixture-triggered native JS confirmation returned false on Cancel and true on OK.
  • Two full self-audit passes and an independent code review found no remaining actionable issue after fixes. The native E2E run caught an initially unmasked input; that defect was fixed and rechecked before this submission.

The API 34 UI evidence and initial Alpha creation used earlier local builds; the final API 35 switch/edit/rotation/confirmation/retry/delete/no-token checks used the SHA above. Final API 26 and API 35 instrumentation used that SHA. The local fixture produced 11 state reports and two confirmation results; it was stopped and its reverse tunnels removed after testing.

Limits

This is emulator evidence with synthetic localhost content, not a real daemon/model or remote-TLS session. Physical devices, backup/restore, renderer termination, stale-callback race injection, TalkBack/font-scale acceptance and Android rotation were not exercised. Native vault encryption does not change the H5 sessionStorage persistence contract, and local credential deletion does not provide server-side revocation. The dependent parent still needs to land before this slice can be considered for merge.

中文验证摘要

最终提交 95ff656f9f,调试 APK SHA-256 如上。Debug/release 构建、18 个 JVM 测试通过;lint 零错误、六条依赖版本提示。API 26 的真实 Keystore/迁移/损坏/重置测试 3 项通过,配置隔离因旧提供方不支持而跳过;API 34 早期验证构建结果相同。API 35 最终构建的 4 项设备测试全部通过,且强制要求隔离能力,不能以跳过冒充成功。

原生界面验证了旧明文配置迁移、配置增删改与重启持久化、输入遮蔽、地址修改不沿用旧 token、损坏恢复和确认重置。API 35 本地合成页面验证了同源配置的 Cookie/localStorage 隔离、新视图 sessionStorage 清空、凭据/地址轮换、移除 token 不保留旧状态、连接错误后的重试、返回导航、删除单个配置,以及 JS 确认取消/接受分别返回 false/true。初次 Alpha 创建与 API 34 截图使用较早构建;最终切换、轮换、确认、重试、删除、无 token 检查及 API 26/35 设备测试使用上方最终 SHA。

这不是实际 daemon/模型调用或远程 TLS 验收。未验证真机、备份恢复、renderer 终止、旧回调竞争注入、无障碍与旋转。原生加密不改变 H5 sessionStorage 的持久化约定,也不提供服务器撤销。CI 结果需另行查看;本 PR 依赖前置 PR 合入。测试服务器和反向隧道已清理。

Synthetic API 35 fixture screenshots

api35-beta-return api35-native-confirm

GitHub currently requires maintainer approval for the fork CI workflows. Please authorize the runs when appropriate; the results above are local verification.

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

Initialization regression fixed in acac9a3b3d911ef1eedd65687b0e09c706d74321. This supersedes the earlier assumption that a new UUID profile alone guarantees empty storage.

Repeated runs on unchanged 95ff656/WebView124 reproduced fresh names reading old localStorage after rapid process termination. The fix uses AndroidX1.13 complete profile-scoped clearing, a durable initialization marker and provider-name checks before creation. No document/token loads until the clear callback and successful vault write. New/migrated/missing profiles on124 now fail closed; known initialized profiles retain state. Migration preserves native credentials and resets browser sessions/cache once.

Final artifact checks:

Environment Result
JDK17 / Gradle8.2.1 Debug +unsignedrelease,21 JVM tests, lint0errors/6existing notices
API36 / WebView134.0.6998.135 6 committed tests passed;1 old-provider-only skip
API35 / WebView124.0.6367.219 4 passed;3 unsupported-feature skips; actualConnect sends0 HTTP requests

The committed production-path regression checks the very first HTTP cookie and initial cookie/localStorage/IndexedDB/cache, then verifies retention on reconnect. Independent acceptance also passed rapid two-process restart with durabletrue but an absent provider name, cancellation during a real clear, stale browser-identity rotation, an explicitly simulated pending-name reservation, and concurrent durable deletion through a second real Activity vault. The latter is controlled persisted-deletion testing, not native Delete-dialog acceptance; the initial premature async-dialog assertion was a harness failure and was corrected without changing production code. No app-data wipe, arbitrary metadata-flush delay or provider-private mutation was used to hide the baseline.

Debug APK SHA-256: 25CFCC8CF82F903B1DEF6662FA959D09E14A84D43C449FA82383D54C0A1FF29B. Both complete design languages, migration/requirements and API26/36 CI lanes are updated. Two clean audits and independent review are complete. The guard is being integrated and revalidated in each sibling PR; upstream CI still requires maintainer authorization.

中文:acac9a3b3d911ef1eedd65687b0e09c706d74321 修复初始化回归,取代“新UUID即可保证空存储”的旧假设。未修改95ff656在WebView124快速终止进程后复现新名称读取旧localStorage。修复采用AndroidX1.13完整配置级清除、持久化标志和创建前名称检查,必须完成回调及凭据库写入后才加载文档/令牌;124对新建、迁移或名称缺失的配置拒绝不安全连接,已初始化且名称已知的配置保留状态。迁移保留原生凭据并清除一次浏览器会话/缓存。JDK17/Gradle8.2.1下调试和未签名发布构建、21项JVM、lint通过(0错误、6项既有提示)。API36/WebView134的已提交测试6通过1跳过;API35/WebView124为4通过3能力跳过,真实Connect发0个HTTP请求。已提交产品路径回归检查首个HTTP cookie及最初四类存储,并验证重连保留。独立验收还覆盖持久化true但提供程序名称缺失的双进程快速重启、真实清除期间取消、过期浏览器标识、明确模拟的占用锁,以及通过第二个真实Activity凭据库进行并发持久化删除。最后一项不是原生删除对话框验收;最初过早断言异步对话框结果的夹具失败已保留并修正,未改产品代码。没有清空应用数据、任意等待元数据刷新或修改提供程序私有文件来隐藏基线故障。最终调试APK哈希如上。英中设计、迁移要求和API26/36 CI已更新,完成两轮干净自审及独立审查;正在逐一集成并复验兄弟PR,上游CI仍需维护者授权。

@jabrailkhalil
jabrailkhalil force-pushed the feat/android-phase2-profiles branch from acac9a3 to 92f6af0 Compare September 18, 2026 08:37
@github-actions

Copy link
Copy Markdown
Contributor

Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration.

中文

请勿对活跃的 PR 执行 rebase 或 force-push,因为这会使已有的评审评论失效。另外,供日后参考:作为集成流程的一部分,机器人始终会自动将所有改动压缩(squash)为单个提交。