Skip to content

fix: 补齐 Android 升级闭环并重构可靠性与集成接口 - #21

Merged
JusterZhu merged 5 commits into
mainfrom
justerzhu-automatic-upgrade-audit
Oct 3, 2026
Merged

JusterZhu merged 5 commits into
mainfrom
justerzhu-automatic-upgrade-audit

Conversation

@JusterZhu

Copy link
Copy Markdown
Contributor

关联问题

Closes #20

变更内容

  • 安装器交接前原子保存目标版本,新增离线 CheckInstallationAsync 和首次持久化确认事件,支持跨进程恢复;损坏记录通过显式 ResetInstallationAsync 恢复。
  • 修正哈希校验取消后的状态/事件、超时误判;下载重试覆盖 HEAD、GET 和响应流中断,支持续传并受整体超时约束。
  • 统一 HTTP 客户端管理:内部客户端正确释放,外部客户端始终借用;TLS/代理冲突配置明确报错,不再静默替换 handler。
  • 抽离 IUpdatePackageSource、IInstallationStore;新增 PrepareUpdateAsync 在一个操作锁内完成查询、比较、pre-check、下载和校验,不自动打开 UI。
  • 改善并发释放:拒绝新/排队操作,当前操作退出后释放资源。
  • 示例拆分 View、可测试的 ViewModel 和 Android 平台适配层,完善配置保存、权限返回、页面取消/释放以及记录重置入口。
  • 更新中英文文档和 CI,加入 Android 示例 Release 构建。

兼容性与行为说明

  • 保留原有分阶段 API;AddListenerUpdateCompleted 仍表示 ReadyToInstall / Installing 阶段完成,不表示安装成功。
  • 兼容构造函数未指定记录路径时使用应用 LocalApplicationData/update/installation.json,不再隐式关闭跟踪;依赖注入构造函数要求提供安装存储。
  • CreateDefault 默认查询/HEAD 超时 30 秒、总下载超时 10 分钟、最多 3 次下载尝试;元数据查询不重试。超时报告网络失败,主动取消报告取消。
  • 等待操作锁时取消仍抛 OperationCanceledException。建议取消并等待活动操作结束后再 Dispose。

验证

  • dotnet test tests/GeneralUpdate.Avalonia.Android.Tests/GeneralUpdate.Avalonia.Android.Tests.csproj -c Release --no-restore:106 个测试通过。
  • Android 示例 Release 构建(含 trimming/AOT):0 警告、0 错误,生成签名 APK。
  • 覆盖真实下载、文件写入、SHA-256、重启确认,以及重试/取消/超时、客户端所有权、并发释放、权限返回和示例生命周期回归。
  • git diff --check 通过。

尚需真机验收

未连接 Android 设备,尚未验证真实 APK 覆盖安装。端到端自动化中的安装器为模拟实现,不能替代真机验收。用户仍需确认系统安装并重新打开应用;不提供静默安装、自动重启、健康检查或回滚。APK 必须同包名、兼容签名且 versionCode 递增。

Track installation outcomes across restarts, normalize cancellation and retries, manage HTTP ownership, and extract injectable package and persistence services. Simplify the sample with a testable view model and preparation/reset APIs.

Refs #20

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 3, 2026 07:37
@JusterZhu

Copy link
Copy Markdown
Contributor Author

@copilot 初始化的地方加一个中英文的配置选项,让用户决定当前组件中的提示内容显示中文还是英文。

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Global authentication can leak to untrusted download origins, and custom source timeouts can escape the result-based API.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Completes Android’s update lifecycle with durable installation confirmation, resilient downloads, injectable services, and a testable sample architecture.

Changes:

  • Adds installation journaling, reconciliation, reset, and preparation APIs.
  • Improves HTTP retries, timeout handling, ownership, and disposal.
  • Refactors the sample and expands tests, documentation, and CI.
File Description
tests/​.../​UpdateViewModelTests.cs Tests sample lifecycle and recovery.
tests/​.../​UpdateTestDoubles.cs Adds reusable test doubles.
tests/​.../​UpdatePreparationTests.cs Tests preparation, disposal, and reset.
tests/​.../​UpdateFlowEndToEndTests.cs Extends end-to-end restart coverage.
tests/​.../​InstallationTrackingTests.cs Tests durable installation tracking.
tests/​.../​GeneralUpdate.Avalonia.Android.Tests.csproj Links new production and sample sources.
tests/​.../​DownloadReliabilityTests.cs Tests retries, timeouts, and ownership.
src/​.../​Services/​UpdateHttpClientFactory.cs Centralizes HTTP-client construction.
src/​.../​Services/​JsonFileInstallationStore.cs Implements durable JSON journaling.
src/​.../​Services/​HttpUpdatePackageClient.cs Implements injectable package discovery.
src/​.../​Services/​HttpResumableApkDownloader.cs Adds retry and resume reliability.
src/​.../​Services/​AndroidBootstrap.cs Orchestrates preparation and reconciliation.
src/​.../​README.zh-CN.md Updates Chinese package guidance.
src/​.../​README.md Updates package documentation.
src/​.../​README.en.md Updates English package guidance.
src/​.../​Models/​UpdatePreparationResult.cs Adds preparation result model.
src/​.../​Models/​InstallationRecord.cs Defines durable installation records.
src/​.../​Models/​InstallationCheckResult.cs Defines reconciliation results.
src/​.../​Models/​HttpDownloadOptions.cs Documents and validates transport policies.
src/​.../​Models/​AndroidUpdateOptions.cs Adds journal path configuration.
src/​.../​GeneralUpdateBootstrap.cs Wires new default dependencies.
src/​.../​Events/​UpdateCompletedEventArgs.cs Clarifies event semantics.
src/​.../​Events/​InstallationConfirmedEventArgs.cs Adds confirmation event data.
src/​.../​Enums/​UpdateState.cs Adds installation states.
src/​.../​Abstractions/​IUpdatePackageSource.cs Introduces package-source abstraction.
src/​.../​Abstractions/​IInstallationStore.cs Introduces journal-store abstraction.
src/​.../​Abstractions/​IAndroidBootstrap.cs Exposes new lifecycle APIs.
samples/​.../​Views/​MainView.axaml.cs Reduces view code-behind responsibilities.
samples/​.../​Views/​MainView.axaml Adds compiled ViewModel bindings.
samples/​.../​ViewModels/​UpdateViewModel.cs Implements sample update orchestration.
samples/​.../​README.md Documents sample integration and validation.
samples/​.../​Infrastructure/​IUpdateHost.cs Abstracts platform integration.
samples/​.../​Infrastructure/​AndroidUpdateHost.cs Implements Android platform services.
samples/​.../​GeneralUpdate.Avalonia.Android.Sample.csproj Adjusts Android publish RID behavior.
README.md Documents the complete Chinese workflow.
README-EN.md Documents the complete English workflow.
.github/​workflows/​ci-cd.yml Builds the Android sample in CI.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

_globalAuthProvider = null;
_ownsClient = false;
_httpOptions = httpOptions;
_globalAuthProvider = httpOptions?.AuthProvider;

if (compare > 0)
cancellationToken.ThrowIfCancellationRequested();
packageInfo = await _packageSource.GetLatestAsync(currentVersion, cancellationToken).ConfigureAwait(false);
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

Copilot AI commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

@copilot 初始化的地方加一个中英文的配置选项,让用户决定当前组件中的提示内容显示中文还是英文。

Added an AndroidUpdateOptions.Language setting (English by default, with Chinese supported) and localized the component’s built-in messages. Committed as 78e8d9d.

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
@JusterZhu

Copy link
Copy Markdown
Contributor Author

@copilot 初始化的地方加一个中英文的配置选项,让用户决定当前组件中的提示内容显示中文还是英文。

Added an AndroidUpdateOptions.Language setting (English by default, with Chinese supported) and localized the component’s built-in messages. Committed as 78e8d9d.

@copilot 代码中的提示或者声明异常都是直接写中文,没有做到可以中英文切换的目的

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

Copilot AI commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

@copilot 初始化的地方加一个中英文的配置选项,让用户决定当前组件中的提示内容显示中文还是英文。

Added an AndroidUpdateOptions.Language setting (Eng...

Localized the sample’s UI prompts, input-validation and Android platform exceptions, and added a persisted language selector that configures the updater during initialization. 114 tests pass. Commit: COMMIT_HASH.

@JusterZhu

Copy link
Copy Markdown
Contributor Author

@copilot 修复当前会话中copilot提出的修复建议

Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>

Copilot AI commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

@copilot 修复当前会话中copilot提出的修复建议

Addressed the two review findings: global download auth is restricted to the configured HTTPS verification origin and HTTP downloads require an explicit opt-out; package-source timeouts now return a network failure result/event. 120 tests pass. Commit: COMMIT_HASH.

@JusterZhu
JusterZhu merged commit dfec0c6 into main Oct 3, 2026
2 checks passed
@JusterZhu
JusterZhu deleted the justerzhu-automatic-upgrade-audit branch October 3, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 补齐 Android 自动升级闭环并修复传输、生命周期及集成问题

3 participants