Skip to content

Run the embedded XServer as a foreground service - #614

Open
TheoneK423 wants to merge 1 commit into
Cateners:mainfrom
TheoneK423:codex/xserver-foreground-service
Open

Run the embedded XServer as a foreground service#614
TheoneK423 wants to merge 1 commit into
Cateners:mainfrom
TheoneK423:codex/xserver-foreground-service

Conversation

@TheoneK423

Copy link
Copy Markdown

Background

Tiny Container provides two ways to access the graphical desktop: AVNC and X11 (Termux:X11). On a Xiaomi Pad 6S Pro running HyperOS 3 with 8 GB of RAM, X11 would frequently disconnect and display “not connected”. This issue did not occur when using AVNC.

Investigation showed that the container itself continued running, but the com.fct.tc4:xserver process had an oom_score_adj value of 800. Android could terminate it under increased background memory pressure, leaving X11 unable to reconnect to the graphical desktop.

Changes

  • Add XServerService based on the existing CmdEntryPointService.
  • Run the XServer as an Android foreground service with a low-importance ongoing notification.
  • Declare the specialUse foreground-service type for recent Android versions.
  • Route the existing XServer start and stop operations through the new service.
  • Preserve the existing launch arguments, environment variables, and shutdown behavior.

Results

The XServer's oom_score_adj was reduced from 800 to 200, and Android now recognizes it as a foreground-service process.

During testing with multiple background applications and elevated memory pressure, neither XServer termination nor X11 disconnection was reproduced. Stopping and restarting the container also restarted the XServer and graphical desktop normally.


背景

Tiny Container 提供 AVNC 和 X11(Termux:X11)两种图形桌面连接方式。在搭载澎湃 OS 3、8 GB 内存的小米平板 6S Pro 上,使用 X11 时会在运行过程中频繁断联并显示“未连接”,而使用 AVNC 时没有出现该断联问题。

排查发现,容器本身仍在正常运行,但 com.fct.tc4:xserver 进程的 oom_score_adj800,在后台内存压力增大时容易被 Android 系统终止,导致 X11 无法重新连接图形桌面。

修改

  • 增加基于现有 CmdEntryPointServiceXServerService
  • 将 XServer 作为 Android 前台服务运行,并显示低优先级常驻通知。
  • 为较新 Android 版本声明 specialUse 前台服务类型。
  • 将原有 XServer 启动和停止入口切换到新服务。
  • 保留原有的启动参数、环境变量和停止行为。

效果

修改前,XServer 的 oom_score_adj800;修改后降至 200,Android 将其识别为前台服务进程。

在开启多个后台应用并制造较高内存压力后,测试期间未再复现 XServer 被系统终止或 X11 断联的问题。停止并重新启动容器后,XServer 和图形桌面也能正常重新启动。

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.

1 participant