Feature: Install Android APK updates pushed from the master

The master now sends COMMAND_UPDATE to Android hosts: it picks a
"Build Client -> Android" APK, checks the ZIP magic and that the package
carries this master's fingerprint, then sends [cmd][size][APK][xxh64].
The client verifies length and hash, writes filesDir/update.apk and
commits a PackageInstaller session, so the system installer still asks
the user to confirm - an app cannot replace itself silently. Write and
hash failures come back over TOKEN_CLIENT_MSG, so the master sees why
nothing happened instead of a silently dropped packet.

Sending the wrong file is what the fingerprint check guards against: a
template without the master id installs fine and then cannot connect
back. "Send anyway" is offered only after spelling that out, and the
client advertises CLIENT_CAP_APK_UPDATE (0x0400) so an old APK gets
"install a new build once by hand" instead of a packet it would discard.

Also report the real versionName/versionCode at login instead of the
hardcoded v1.0.0, add android/tools/verify_update_apk.py (pre-send check
of size, ZIP_STORED libs, ABI, package, versionCode and the decrypted
CONNECT_ADDRESS, which it still locates after BuildDlg rewrote szFlag),
and translate the nine new strings in en_US, zh_TW and de_DE.

Verified on the emulator and against the live release server: generate,
sign, send, install, and the device reconnects and re-grants screen
capture. Language packs are GBK and were appended as bytes.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-11 00:53:29 +01:00
1 parent cdd9c56b3d
commit 36618b0ad0
17 files changed
+955 -8

No files matched your search

@@ -40,6 +40,9 @@ class CaptureService : Service() {
// CS-01 fix: 通过 idrHandler.post 序列化到主线程,避免 TOCTOU 竞争
@Volatile var instance: CaptureService? = null
/** onUpdateReceived 可能在服务已经销毁后从 native 线程打进来,用 application context 兜底 */
@Volatile var appContext: android.content.Context? = null
@JvmStatic
fun onNativeStatus(msg: String) {
val svc = instance ?: return
@@ -48,6 +51,14 @@ class CaptureService : Service() {
}
}
/** 服务端下发的升级 APK 已校验并落盘(filesDir/update.apk),交给安装流程 */
@JvmStatic
fun onUpdateReceived(path: String) {
val ctx = instance ?: appContext ?: return
Log.i(TAG, "onUpdateReceived: $path")
UpdateInstaller.onApkReceived(ctx, path)
}
@JvmStatic
fun onNativeExit() {
val svc = instance ?: return
@@ -115,6 +126,7 @@ class CaptureService : Service() {
override fun onCreate() {
super.onCreate()
instance = this
appContext = applicationContext
createNotificationChannel()
// CS-06: start with DATA_SYNC type only; upgrade to MEDIA_PROJECTION in
// onStartCommand when the token is actually available. On Android 14+
@@ -150,7 +162,8 @@ class CaptureService : Service() {
// ExceptionInInitializerError 包裹 UnsatisfiedLinkError(首次访问 object 时触发)
val initRet: Int
try {
initRet = YamaBridge.nativeInit(ip, port, androidId, model, osVer, res, user, packageCodePath ?: "", filesDir.absolutePath)
initRet = YamaBridge.nativeInit(ip, port, androidId, model, osVer, res, user, packageCodePath ?: "", filesDir.absolutePath,
BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
} catch (e: UnsatisfiedLinkError) {
Log.e(TAG, "Native library load failed: $e")
stopSelf()