Skip to content

Commit a201037

Browse files
committed
fix(harmony): safeguard binary version sync against thread-safety errors and cache buildTime
1 parent 9d116aa commit a201037

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

harmony/pushy/src/main/ets/UpdateContext.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class UpdateContext {
2626
private static DEBUG: boolean = false;
2727
private static isUsingBundleUrl: boolean = false;
2828
private static ignoreRollback: boolean = false;
29+
private static cachedPackageVersion: string = '';
30+
private static cachedBuildTime: string = '';
2931

3032
constructor(context: common.UIAbilityContext) {
3133
this.context = context;
@@ -60,28 +62,38 @@ export class UpdateContext {
6062
}
6163

6264
public getPackageVersion(): string {
65+
if (UpdateContext.cachedPackageVersion) {
66+
return UpdateContext.cachedPackageVersion;
67+
}
6368
try {
6469
const bundleInfo = bundleManager.getBundleInfoForSelfSync(
6570
this.getBundleFlags(),
6671
);
67-
return bundleInfo?.versionName || 'Unknown';
72+
UpdateContext.cachedPackageVersion = bundleInfo?.versionName || 'Unknown';
73+
return UpdateContext.cachedPackageVersion;
6874
} catch (error) {
6975
console.error('Failed to get bundle info:', error);
7076
return '';
7177
}
7278
}
7379

7480
public getBuildTime(): string {
81+
if (UpdateContext.cachedBuildTime) {
82+
return UpdateContext.cachedBuildTime;
83+
}
7584
try {
7685
const content =
7786
this.context.resourceManager.getRawFileContentSync('meta.json');
7887
const metaData = JSON.parse(
7988
new util.TextDecoder().decodeToString(content),
8089
) as Record<string, string | number | boolean | null | undefined>;
8190
if (metaData.pushy_build_time) {
82-
return String(metaData.pushy_build_time);
91+
UpdateContext.cachedBuildTime = String(metaData.pushy_build_time);
92+
return UpdateContext.cachedBuildTime;
8393
}
84-
} catch {}
94+
} catch (error) {
95+
console.error('Failed to read build time from raw file:', error);
96+
}
8597
return '';
8698
}
8799

@@ -244,6 +256,9 @@ export class UpdateContext {
244256
packageVersion: string,
245257
buildTime: string,
246258
): void {
259+
if (!packageVersion || !buildTime) {
260+
return;
261+
}
247262
const currentState = this.getStateSnapshot();
248263
const nextState = NativePatchCore.syncStateWithBinaryVersion(
249264
packageVersion,

0 commit comments

Comments
 (0)