From a20103799cd279c585540eda77d970731eb1035a Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Tue, 30 Jun 2026 17:43:24 +0800 Subject: [PATCH] fix(harmony): safeguard binary version sync against thread-safety errors and cache buildTime --- harmony/pushy/src/main/ets/UpdateContext.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/harmony/pushy/src/main/ets/UpdateContext.ts b/harmony/pushy/src/main/ets/UpdateContext.ts index 7d70b4a7..d0b969cf 100644 --- a/harmony/pushy/src/main/ets/UpdateContext.ts +++ b/harmony/pushy/src/main/ets/UpdateContext.ts @@ -26,6 +26,8 @@ export class UpdateContext { private static DEBUG: boolean = false; private static isUsingBundleUrl: boolean = false; private static ignoreRollback: boolean = false; + private static cachedPackageVersion: string = ''; + private static cachedBuildTime: string = ''; constructor(context: common.UIAbilityContext) { this.context = context; @@ -60,11 +62,15 @@ export class UpdateContext { } public getPackageVersion(): string { + if (UpdateContext.cachedPackageVersion) { + return UpdateContext.cachedPackageVersion; + } try { const bundleInfo = bundleManager.getBundleInfoForSelfSync( this.getBundleFlags(), ); - return bundleInfo?.versionName || 'Unknown'; + UpdateContext.cachedPackageVersion = bundleInfo?.versionName || 'Unknown'; + return UpdateContext.cachedPackageVersion; } catch (error) { console.error('Failed to get bundle info:', error); return ''; @@ -72,6 +78,9 @@ export class UpdateContext { } public getBuildTime(): string { + if (UpdateContext.cachedBuildTime) { + return UpdateContext.cachedBuildTime; + } try { const content = this.context.resourceManager.getRawFileContentSync('meta.json'); @@ -79,9 +88,12 @@ export class UpdateContext { new util.TextDecoder().decodeToString(content), ) as Record; if (metaData.pushy_build_time) { - return String(metaData.pushy_build_time); + UpdateContext.cachedBuildTime = String(metaData.pushy_build_time); + return UpdateContext.cachedBuildTime; } - } catch {} + } catch (error) { + console.error('Failed to read build time from raw file:', error); + } return ''; } @@ -244,6 +256,9 @@ export class UpdateContext { packageVersion: string, buildTime: string, ): void { + if (!packageVersion || !buildTime) { + return; + } const currentState = this.getStateSnapshot(); const nextState = NativePatchCore.syncStateWithBinaryVersion( packageVersion,