react-native-update 10.37.19 → 10.38.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-CN.md +4 -4
- package/README.md +2 -12
- package/android/bin/.settings/org.eclipse.buildship.core.prefs +13 -0
- package/android/build.gradle +4 -0
- package/android/jni/Android.mk +14 -1
- package/android/jni/Application.mk +5 -2
- package/android/lib/arm64-v8a/librnupdate.so +0 -0
- package/android/lib/armeabi-v7a/librnupdate.so +0 -0
- package/android/lib/x86/librnupdate.so +0 -0
- package/android/lib/x86_64/librnupdate.so +0 -0
- package/android/src/main/java/cn/reactnative/modules/update/ArchivePatchPlanResult.java +6 -0
- package/android/src/main/java/cn/reactnative/modules/update/CopyGroupResult.java +6 -0
- package/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +136 -136
- package/android/src/main/java/cn/reactnative/modules/update/NativeUpdateCore.java +34 -0
- package/android/src/main/java/cn/reactnative/modules/update/StateCoreResult.java +16 -0
- package/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java +131 -48
- package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleImpl.java +88 -40
- package/cpp/patch_core/archive_patch_core.cpp +125 -0
- package/cpp/patch_core/archive_patch_core.h +59 -0
- package/cpp/patch_core/patch_core.cpp +533 -0
- package/cpp/patch_core/patch_core.h +68 -0
- package/cpp/patch_core/patch_core_android.cpp +112 -0
- package/cpp/patch_core/state_core.cpp +110 -0
- package/cpp/patch_core/state_core.h +58 -0
- package/cpp/patch_core/tests/patch_core_test.cpp +473 -0
- package/cpp/patch_core/update_core_android.cpp +469 -0
- package/harmony/pushy.har +0 -0
- package/ios/RCTPushy/RCTPushy.mm +233 -143
- package/package.json +17 -15
- package/react-native-update.podspec +3 -0
- package/scripts/build-harmony-har.js +12 -0
- package/scripts/prepublish.ts +49 -3
- package/scripts/prune-host-stl.sh +6 -0
- package/scripts/test-patch-core.sh +39 -0
- package/src/client.ts +129 -76
- package/src/core.ts +2 -1
- package/src/endpoint.ts +171 -0
- package/src/utils.ts +40 -27
- package/android/jni/lzma/DOC/7zC.txt +0 -187
- package/android/jni/lzma/DOC/7zFormat.txt +0 -469
- package/android/jni/lzma/DOC/Methods.txt +0 -173
- package/android/jni/lzma/DOC/installer.txt +0 -166
- package/android/jni/lzma/DOC/lzma-history.txt +0 -446
- package/android/jni/lzma/DOC/lzma-sdk.txt +0 -357
- package/android/jni/lzma/DOC/lzma-specification.txt +0 -1176
- package/android/jni/lzma/DOC/lzma.txt +0 -328
- package/android/jni/lzma/bin/7zS2.sfx +0 -0
- package/android/jni/lzma/bin/7zS2con.sfx +0 -0
- package/android/jni/lzma/bin/7zSD.sfx +0 -0
- package/android/jni/lzma/bin/7zdec.exe +0 -0
- package/android/jni/lzma/bin/7zr.exe +0 -0
- package/android/jni/lzma/bin/installer/config.txt +0 -5
- package/android/jni/lzma/bin/installer/cr.bat +0 -5
- package/android/jni/lzma/bin/lzma.exe +0 -0
- package/android/jni/lzma/bin/x64/7zr.exe +0 -0
- package/error.js +0 -1609
- package/harmony/har-wrapper/AppScope/app.json5 +0 -8
- package/harmony/har-wrapper/build-profile.json5 +0 -35
- package/harmony/har-wrapper/hvigor/hvigor-config.json5 +0 -5
- package/harmony/har-wrapper/hvigorfile.ts +0 -6
- package/harmony/har-wrapper/oh-package.json5 +0 -4
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/cache-v2-77b153ce45aba0ed28ef.json +0 -1415
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/cmakeFiles-v1-b65a07793384e0ce3e08.json +0 -809
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/codemodel-v2-ce0e89410afd8bf3a057.json +0 -60
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/directory-.-Release-f5ebdc15457944623624.json +0 -14
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/index-2026-03-18T12-02-38-0668.json +0 -89
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/target-rnupdate-Release-267153624504c9c3ffdd.json +0 -222
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.ninja_deps +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.ninja_log +0 -8
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeCache.txt +0 -415
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeCCompiler.cmake +0 -74
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeCXXCompiler.cmake +0 -85
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeDetermineCompilerABI_C.bin +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeSystem.cmake +0 -15
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CompilerIdC/CMakeCCompilerId.c +0 -880
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CompilerIdC/CMakeCCompilerId.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -869
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CompilerIdCXX/CMakeCXXCompilerId.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/CMakeConfigureLog.yaml +0 -388
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/TargetDirectories.txt +0 -3
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/cmake.check_cache +0 -1
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/HDiffPatch/file_for_patch.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/HDiffPatch/libHDiffPatch/HPatch/patch.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/hpatch.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/lzma/C/Lzma2Dec.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/lzma/C/LzmaDec.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/pushy.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rules.ninja +0 -64
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/additional_project_files.txt +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/build.ninja +0 -206
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/build_file_index.txt +0 -1
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/cmake_install.cmake +0 -54
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/compile_commands.json +0 -38
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/configure_fingerprint.json +0 -1
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/hvigor_native_config.json +0 -1
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/metadata_generation_command.txt +0 -17
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/native_work_dir.txt +0 -1
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/output.log +0 -14
- package/harmony/pushy/.cxx/default/default/release/hvigor/arm64-v8a/summary.cmake +0 -0
- package/harmony/pushy/BuildProfile.ets +0 -17
- package/harmony/pushy/OAT.xml +0 -38
- package/harmony/pushy/README.md +0 -0
- package/harmony/pushy/build-profile.json5 +0 -15
- package/harmony/pushy/hvigor-plugin.ts +0 -34
- package/harmony/pushy/hvigorfile.ts +0 -1
- package/harmony/pushy/index.ets +0 -2
- package/harmony/pushy/oh-package-lock.json5 +0 -20
- package/harmony/pushy/oh-package.json5 +0 -13
- package/harmony/pushy/src/main/cpp/CMakeLists.txt +0 -51
- package/harmony/pushy/src/main/cpp/PushyPackage.h +0 -55
- package/harmony/pushy/src/main/cpp/PushyTurboModule.cpp +0 -142
- package/harmony/pushy/src/main/cpp/PushyTurboModule.h +0 -38
- package/harmony/pushy/src/main/cpp/pushy.c +0 -117
- package/harmony/pushy/src/main/cpp/pushy.h +0 -8
- package/harmony/pushy/src/main/ets/DownloadTask.ts +0 -570
- package/harmony/pushy/src/main/ets/DownloadTaskParams.ts +0 -19
- package/harmony/pushy/src/main/ets/EventHub.ts +0 -39
- package/harmony/pushy/src/main/ets/Logger.ts +0 -52
- package/harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets +0 -50
- package/harmony/pushy/src/main/ets/PushyPackage.ts +0 -22
- package/harmony/pushy/src/main/ets/PushyTurboModule.ts +0 -171
- package/harmony/pushy/src/main/ets/SaveFile.ts +0 -34
- package/harmony/pushy/src/main/ets/UpdateContext.ts +0 -262
- package/harmony/pushy/src/main/ets/UpdateModuleImpl.ts +0 -123
- package/harmony/pushy/src/main/module.json5 +0 -7
- package/harmony/pushy/src/main/resources/base/element/string.json +0 -8
- package/harmony/pushy/src/main/resources/en_US/element/string.json +0 -8
- package/harmony/pushy/src/main/resources/zh_CN/element/string.json +0 -8
- package/harmony/pushy/ts.ts +0 -3
- package/src/__tests__/core.test.ts +0 -103
- package/src/__tests__/utils.test.ts +0 -36
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FileJSBundle,
|
|
3
|
-
JSBundleProvider,
|
|
4
|
-
JSBundleProviderError,
|
|
5
|
-
} from '@rnoh/react-native-openharmony';
|
|
6
|
-
import common from '@ohos.app.ability.common';
|
|
7
|
-
import fs from '@ohos.file.fs';
|
|
8
|
-
import { UpdateContext } from './UpdateContext';
|
|
9
|
-
|
|
10
|
-
export class PushyFileJSBundleProvider extends JSBundleProvider {
|
|
11
|
-
private updateContext: UpdateContext;
|
|
12
|
-
private path: string = '';
|
|
13
|
-
|
|
14
|
-
constructor(context: common.UIAbilityContext) {
|
|
15
|
-
super();
|
|
16
|
-
this.updateContext = new UpdateContext(context);
|
|
17
|
-
this.path = this.updateContext.getBundleUrl();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getURL(): string {
|
|
21
|
-
return this.path;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async getBundle(): Promise<FileJSBundle> {
|
|
25
|
-
if (!this.path) {
|
|
26
|
-
throw new JSBundleProviderError({
|
|
27
|
-
whatHappened: 'No pushy bundle found. using default bundle',
|
|
28
|
-
howCanItBeFixed: [''],
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
await fs.access(this.path, fs.OpenMode.READ_ONLY);
|
|
33
|
-
return {
|
|
34
|
-
filePath: this.path,
|
|
35
|
-
};
|
|
36
|
-
} catch (error) {
|
|
37
|
-
throw new JSBundleProviderError({
|
|
38
|
-
whatHappened: `Couldn't load JSBundle from ${this.path}`,
|
|
39
|
-
extraData: error,
|
|
40
|
-
howCanItBeFixed: [
|
|
41
|
-
`Check if a bundle exists at "${this.path}" on your device.`,
|
|
42
|
-
],
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getAppKeys(): string[] {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
2
|
-
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
3
|
-
import { PushyTurboModule } from './PushyTurboModule';
|
|
4
|
-
|
|
5
|
-
class PushyTurboModulesFactory extends TurboModulesFactory {
|
|
6
|
-
createTurboModule(name: string): TurboModule | null {
|
|
7
|
-
if (name === 'Pushy') {
|
|
8
|
-
return new PushyTurboModule(this.ctx);
|
|
9
|
-
}
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
hasTurboModule(name: string): boolean {
|
|
14
|
-
return name === 'Pushy';
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class PushyPackage extends RNPackage {
|
|
19
|
-
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
20
|
-
return new PushyTurboModulesFactory(ctx);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TurboModule,
|
|
3
|
-
TurboModuleContext,
|
|
4
|
-
} from '@rnoh/react-native-openharmony/ts';
|
|
5
|
-
import common from '@ohos.app.ability.common';
|
|
6
|
-
import dataPreferences from '@ohos.data.preferences';
|
|
7
|
-
import { bundleManager } from '@kit.AbilityKit';
|
|
8
|
-
import logger from './Logger';
|
|
9
|
-
import { UpdateModuleImpl } from './UpdateModuleImpl';
|
|
10
|
-
import { UpdateContext } from './UpdateContext';
|
|
11
|
-
import { EventHub } from './EventHub';
|
|
12
|
-
import { util } from '@kit.ArkTS';
|
|
13
|
-
|
|
14
|
-
const TAG = 'PushyTurboModule';
|
|
15
|
-
|
|
16
|
-
export class PushyTurboModule extends TurboModule {
|
|
17
|
-
mUiCtx: common.UIAbilityContext;
|
|
18
|
-
context: UpdateContext;
|
|
19
|
-
|
|
20
|
-
constructor(protected ctx: TurboModuleContext) {
|
|
21
|
-
super(ctx);
|
|
22
|
-
logger.debug(TAG, ',PushyTurboModule constructor');
|
|
23
|
-
this.mUiCtx = ctx.uiAbilityContext;
|
|
24
|
-
this.context = new UpdateContext(this.mUiCtx);
|
|
25
|
-
EventHub.getInstance().setRNInstance(ctx.rnInstance);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getConstants(): Object {
|
|
29
|
-
logger.debug(TAG, ',call getConstants');
|
|
30
|
-
const context = this.mUiCtx;
|
|
31
|
-
const preferencesManager = dataPreferences.getPreferencesSync(context, {
|
|
32
|
-
name: 'update',
|
|
33
|
-
});
|
|
34
|
-
const isFirstTime = preferencesManager.getSync(
|
|
35
|
-
'isFirstTime',
|
|
36
|
-
false,
|
|
37
|
-
) as boolean;
|
|
38
|
-
const rolledBackVersion = preferencesManager.getSync(
|
|
39
|
-
'rolledBackVersion',
|
|
40
|
-
'',
|
|
41
|
-
) as string;
|
|
42
|
-
const uuid = preferencesManager.getSync('uuid', '') as string;
|
|
43
|
-
const currentVersion = preferencesManager.getSync(
|
|
44
|
-
'currentVersion',
|
|
45
|
-
'',
|
|
46
|
-
) as string;
|
|
47
|
-
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
|
|
48
|
-
|
|
49
|
-
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
|
|
50
|
-
let bundleFlags =
|
|
51
|
-
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
|
52
|
-
let packageVersion = '';
|
|
53
|
-
try {
|
|
54
|
-
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
|
55
|
-
packageVersion = bundleInfo?.versionName || 'Unknown';
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error('Failed to get bundle info:', error);
|
|
58
|
-
}
|
|
59
|
-
const storedPackageVersion = preferencesManager.getSync(
|
|
60
|
-
'packageVersion',
|
|
61
|
-
'',
|
|
62
|
-
) as string;
|
|
63
|
-
const storedBuildTime = preferencesManager.getSync(
|
|
64
|
-
'buildTime',
|
|
65
|
-
'',
|
|
66
|
-
) as string;
|
|
67
|
-
let buildTime = '';
|
|
68
|
-
try {
|
|
69
|
-
const resourceManager = this.mUiCtx.resourceManager;
|
|
70
|
-
const content = resourceManager.getRawFileContentSync('meta.json');
|
|
71
|
-
const metaData = JSON.parse(
|
|
72
|
-
new util.TextDecoder().decodeToString(content),
|
|
73
|
-
);
|
|
74
|
-
if (metaData.pushy_build_time) {
|
|
75
|
-
buildTime = String(metaData.pushy_build_time);
|
|
76
|
-
}
|
|
77
|
-
} catch {}
|
|
78
|
-
|
|
79
|
-
const packageVersionChanged =
|
|
80
|
-
!storedPackageVersion || packageVersion !== storedPackageVersion;
|
|
81
|
-
const buildTimeChanged = !storedBuildTime || buildTime !== storedBuildTime;
|
|
82
|
-
|
|
83
|
-
if (packageVersionChanged || buildTimeChanged) {
|
|
84
|
-
this.context.cleanUp();
|
|
85
|
-
preferencesManager.putSync('packageVersion', packageVersion);
|
|
86
|
-
preferencesManager.putSync('buildTime', buildTime);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (isFirstTime) {
|
|
90
|
-
preferencesManager.deleteSync('isFirstTime');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (rolledBackVersion) {
|
|
94
|
-
preferencesManager.deleteSync('rolledBackVersion');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
downloadRootDir: `${context.filesDir}/_update`,
|
|
99
|
-
currentVersionInfo,
|
|
100
|
-
packageVersion,
|
|
101
|
-
currentVersion,
|
|
102
|
-
buildTime,
|
|
103
|
-
isUsingBundleUrl,
|
|
104
|
-
isFirstTime,
|
|
105
|
-
rolledBackVersion,
|
|
106
|
-
uuid,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
setLocalHashInfo(hash: string, info: string): boolean {
|
|
111
|
-
logger.debug(TAG, ',call setLocalHashInfo');
|
|
112
|
-
return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
getLocalHashInfo(hash: string): string {
|
|
116
|
-
return UpdateModuleImpl.getLocalHashInfo(this.context, hash);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async setUuid(uuid: string): Promise<void> {
|
|
120
|
-
logger.debug(TAG, ',call setUuid');
|
|
121
|
-
return UpdateModuleImpl.setUuid(this.context, uuid);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async reloadUpdate(options: { hash: string }): Promise<void> {
|
|
125
|
-
logger.debug(TAG, ',call reloadUpdate');
|
|
126
|
-
return UpdateModuleImpl.reloadUpdate(this.context, this.mUiCtx, options);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async setNeedUpdate(options: { hash: string }): Promise<boolean> {
|
|
130
|
-
logger.debug(TAG, ',call setNeedUpdate');
|
|
131
|
-
return UpdateModuleImpl.setNeedUpdate(this.context, options);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async markSuccess(): Promise<boolean> {
|
|
135
|
-
logger.debug(TAG, ',call markSuccess');
|
|
136
|
-
return UpdateModuleImpl.markSuccess(this.context);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async downloadPatchFromPpk(options: {
|
|
140
|
-
updateUrl: string;
|
|
141
|
-
hash: string;
|
|
142
|
-
originHash: string;
|
|
143
|
-
}): Promise<void> {
|
|
144
|
-
logger.debug(TAG, ',call downloadPatchFromPpk');
|
|
145
|
-
return UpdateModuleImpl.downloadPatchFromPpk(this.context, options);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async downloadPatchFromPackage(options: {
|
|
149
|
-
updateUrl: string;
|
|
150
|
-
hash: string;
|
|
151
|
-
}): Promise<void> {
|
|
152
|
-
logger.debug(TAG, ',call downloadPatchFromPackage');
|
|
153
|
-
return UpdateModuleImpl.downloadPatchFromPackage(this.context, options);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async downloadFullUpdate(options: {
|
|
157
|
-
updateUrl: string;
|
|
158
|
-
hash: string;
|
|
159
|
-
}): Promise<void> {
|
|
160
|
-
logger.debug(TAG, ',call downloadFullUpdate');
|
|
161
|
-
return UpdateModuleImpl.downloadFullUpdate(this.context, options);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
addListener(_eventName: string): void {
|
|
165
|
-
logger.debug(TAG, ',call addListener');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
removeListeners(_count: number): void {
|
|
169
|
-
logger.debug(TAG, ',call removeListeners');
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import resourceManager from '@ohos.resourceManager';
|
|
2
|
-
import fs, { ReadOptions } from '@ohos.file.fs';
|
|
3
|
-
|
|
4
|
-
export const saveFileToSandbox = (
|
|
5
|
-
from: resourceManager.RawFileDescriptor,
|
|
6
|
-
toPath: string,
|
|
7
|
-
) => {
|
|
8
|
-
let to = fs.openSync(toPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
|
9
|
-
|
|
10
|
-
let bufferSize = 30000;
|
|
11
|
-
let buffer = new ArrayBuffer(bufferSize); // 创建buffer缓冲区
|
|
12
|
-
// 要copy的文件的offset和length
|
|
13
|
-
let currentOffset = from.offset;
|
|
14
|
-
let readOption: ReadOptions = {
|
|
15
|
-
offset: currentOffset, // 期望读取文件的位置。可选,默认从当前位置开始读
|
|
16
|
-
length: bufferSize, // 每次期望读取数据的长度。可选,默认缓冲区长度
|
|
17
|
-
};
|
|
18
|
-
// 后面len会一直减,直到没有
|
|
19
|
-
while (true) {
|
|
20
|
-
// 读取buffer容量的内容
|
|
21
|
-
let readLength = fs.readSync(from.fd, buffer, readOption);
|
|
22
|
-
// 写入buffer容量的内容
|
|
23
|
-
fs.writeSync(to.fd, buffer, { length: readLength });
|
|
24
|
-
// 判断后续内容,修改读文件的参数
|
|
25
|
-
// buffer没读满代表文件读完了
|
|
26
|
-
if (readLength < bufferSize) {
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
if (readOption.offset) {
|
|
30
|
-
readOption.offset += readLength;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
fs.close(to);
|
|
34
|
-
};
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import preferences from '@ohos.data.preferences';
|
|
2
|
-
import bundleManager from '@ohos.bundle.bundleManager';
|
|
3
|
-
import fileIo from '@ohos.file.fs';
|
|
4
|
-
import { DownloadTask } from './DownloadTask';
|
|
5
|
-
import common from '@ohos.app.ability.common';
|
|
6
|
-
import { DownloadTaskParams } from './DownloadTaskParams';
|
|
7
|
-
|
|
8
|
-
export class UpdateContext {
|
|
9
|
-
private context: common.UIAbilityContext;
|
|
10
|
-
private rootDir: string;
|
|
11
|
-
private preferences: preferences.Preferences;
|
|
12
|
-
private static DEBUG: boolean = false;
|
|
13
|
-
private static isUsingBundleUrl: boolean = false;
|
|
14
|
-
|
|
15
|
-
constructor(context: common.UIAbilityContext) {
|
|
16
|
-
this.context = context;
|
|
17
|
-
this.rootDir = context.filesDir + '/_update';
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
if (!fileIo.accessSync(this.rootDir)) {
|
|
21
|
-
fileIo.mkdirSync(this.rootDir);
|
|
22
|
-
}
|
|
23
|
-
} catch (e) {
|
|
24
|
-
console.error('Failed to create root directory:', e);
|
|
25
|
-
}
|
|
26
|
-
this.initPreferences();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private initPreferences() {
|
|
30
|
-
try {
|
|
31
|
-
this.preferences = preferences.getPreferencesSync(this.context, {
|
|
32
|
-
name: 'update',
|
|
33
|
-
});
|
|
34
|
-
const packageVersion = this.getPackageVersion();
|
|
35
|
-
const storedVersion = this.preferences.getSync('packageVersion', '');
|
|
36
|
-
if (!storedVersion) {
|
|
37
|
-
this.preferences.putSync('packageVersion', packageVersion);
|
|
38
|
-
this.preferences.flush();
|
|
39
|
-
} else if (storedVersion && packageVersion !== storedVersion) {
|
|
40
|
-
this.cleanUp();
|
|
41
|
-
this.preferences.clear();
|
|
42
|
-
this.preferences.putSync('packageVersion', packageVersion);
|
|
43
|
-
this.preferences.flush();
|
|
44
|
-
}
|
|
45
|
-
} catch (e) {
|
|
46
|
-
console.error('Failed to init preferences:', e);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public setKv(key: string, value: string): void {
|
|
51
|
-
this.preferences.putSync(key, value);
|
|
52
|
-
this.preferences.flush();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public getKv(key: string): string {
|
|
56
|
-
return this.preferences.getSync(key, '') as string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public isFirstTime(): boolean {
|
|
60
|
-
return this.preferences.getSync('firstTime', false) as boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public rolledBackVersion(): string {
|
|
64
|
-
return this.preferences.getSync('rolledBackVersion', '') as string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public markSuccess(): void {
|
|
68
|
-
this.preferences.putSync('firstTimeOk', true);
|
|
69
|
-
const lastVersion = this.preferences.getSync('lastVersion', '') as string;
|
|
70
|
-
const curVersion = this.preferences.getSync('currentVersion', '') as string;
|
|
71
|
-
|
|
72
|
-
if (lastVersion && lastVersion !== curVersion) {
|
|
73
|
-
this.preferences.deleteSync('lastVersion');
|
|
74
|
-
this.preferences.deleteSync(`hash_${lastVersion}`);
|
|
75
|
-
}
|
|
76
|
-
this.preferences.flush();
|
|
77
|
-
this.cleanUp();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public clearFirstTime(): void {
|
|
81
|
-
this.preferences.putSync('firstTime', false);
|
|
82
|
-
this.preferences.flush();
|
|
83
|
-
this.cleanUp();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public clearRollbackMark(): void {
|
|
87
|
-
this.preferences.putSync('rolledBackVersion', null);
|
|
88
|
-
this.preferences.flush();
|
|
89
|
-
this.cleanUp();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public async downloadFullUpdate(url: string, hash: string): Promise<void> {
|
|
93
|
-
try {
|
|
94
|
-
const params = new DownloadTaskParams();
|
|
95
|
-
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FULL;
|
|
96
|
-
params.url = url;
|
|
97
|
-
params.hash = hash;
|
|
98
|
-
params.targetFile = `${this.rootDir}/${hash}.ppk`;
|
|
99
|
-
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
|
100
|
-
const downloadTask = new DownloadTask(this.context);
|
|
101
|
-
await downloadTask.execute(params);
|
|
102
|
-
} catch (e) {
|
|
103
|
-
console.error('Failed to download full update:', e);
|
|
104
|
-
throw e;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public async downloadFile(
|
|
109
|
-
url: string,
|
|
110
|
-
hash: string,
|
|
111
|
-
fileName: string,
|
|
112
|
-
): Promise<void> {
|
|
113
|
-
const params = new DownloadTaskParams();
|
|
114
|
-
params.type = DownloadTaskParams.TASK_TYPE_PLAIN_DOWNLOAD;
|
|
115
|
-
params.url = url;
|
|
116
|
-
params.hash = hash;
|
|
117
|
-
params.targetFile = this.rootDir + '/' + fileName;
|
|
118
|
-
|
|
119
|
-
const downloadTask = new DownloadTask(this.context);
|
|
120
|
-
await downloadTask.execute(params);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public async downloadPatchFromPpk(
|
|
124
|
-
url: string,
|
|
125
|
-
hash: string,
|
|
126
|
-
originHash: string,
|
|
127
|
-
): Promise<void> {
|
|
128
|
-
const params = new DownloadTaskParams();
|
|
129
|
-
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK;
|
|
130
|
-
params.url = url;
|
|
131
|
-
params.hash = hash;
|
|
132
|
-
params.originHash = originHash;
|
|
133
|
-
params.targetFile = `${this.rootDir}/${originHash}_${hash}.ppk.patch`;
|
|
134
|
-
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
|
135
|
-
params.originDirectory = `${this.rootDir}/${params.originHash}`;
|
|
136
|
-
|
|
137
|
-
const downloadTask = new DownloadTask(this.context);
|
|
138
|
-
await downloadTask.execute(params);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public async downloadPatchFromPackage(
|
|
142
|
-
url: string,
|
|
143
|
-
hash: string,
|
|
144
|
-
): Promise<void> {
|
|
145
|
-
try {
|
|
146
|
-
const params = new DownloadTaskParams();
|
|
147
|
-
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APP;
|
|
148
|
-
params.url = url;
|
|
149
|
-
params.hash = hash;
|
|
150
|
-
params.targetFile = `${this.rootDir}/${hash}.app.patch`;
|
|
151
|
-
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
|
152
|
-
|
|
153
|
-
const downloadTask = new DownloadTask(this.context);
|
|
154
|
-
return await downloadTask.execute(params);
|
|
155
|
-
} catch (e) {
|
|
156
|
-
console.error('Failed to download package patch:', e);
|
|
157
|
-
throw e;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public switchVersion(hash: string): void {
|
|
162
|
-
try {
|
|
163
|
-
const bundlePath = `${this.rootDir}/${hash}/bundle.harmony.js`;
|
|
164
|
-
if (!fileIo.accessSync(bundlePath)) {
|
|
165
|
-
throw Error(`Bundle version ${hash} not found.`);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const lastVersion = this.getKv('currentVersion');
|
|
169
|
-
this.setKv('currentVersion', hash);
|
|
170
|
-
if (lastVersion && lastVersion !== hash) {
|
|
171
|
-
this.setKv('lastVersion', lastVersion);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
this.setKv('firstTime', 'true');
|
|
175
|
-
this.setKv('firstTimeOk', 'false');
|
|
176
|
-
this.setKv('rolledBackVersion', '');
|
|
177
|
-
} catch (e) {
|
|
178
|
-
console.error('Failed to switch version:', e);
|
|
179
|
-
throw e;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public getBundleUrl() {
|
|
184
|
-
UpdateContext.isUsingBundleUrl = true;
|
|
185
|
-
const currentVersion = this.getCurrentVersion();
|
|
186
|
-
if (!currentVersion) {
|
|
187
|
-
return '';
|
|
188
|
-
}
|
|
189
|
-
if (!this.isFirstTime()) {
|
|
190
|
-
if (!this.preferences.getSync('firstTimeOk', true)) {
|
|
191
|
-
return this.rollBack();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
let version = currentVersion;
|
|
195
|
-
while (version) {
|
|
196
|
-
const bundleFile = `${this.rootDir}/${version}/bundle.harmony.js`;
|
|
197
|
-
try {
|
|
198
|
-
if (!fileIo.accessSync(bundleFile)) {
|
|
199
|
-
console.error(`Bundle version ${version} not found.`);
|
|
200
|
-
version = this.rollBack();
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
return bundleFile;
|
|
204
|
-
} catch (e) {
|
|
205
|
-
console.error('Failed to access bundle file:', e);
|
|
206
|
-
version = this.rollBack();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return '';
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
getPackageVersion(): string {
|
|
213
|
-
let bundleFlags =
|
|
214
|
-
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
|
215
|
-
let packageVersion = '';
|
|
216
|
-
try {
|
|
217
|
-
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
|
218
|
-
packageVersion = bundleInfo?.versionName || 'Unknown';
|
|
219
|
-
} catch (error) {
|
|
220
|
-
console.error('获取包信息失败:', error);
|
|
221
|
-
}
|
|
222
|
-
return packageVersion;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
public getCurrentVersion(): string {
|
|
226
|
-
const currentVersion = this.getKv('currentVersion');
|
|
227
|
-
return currentVersion;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
private rollBack(): string {
|
|
231
|
-
const lastVersion = this.preferences.getSync('lastVersion', '') as string;
|
|
232
|
-
const currentVersion = this.preferences.getSync(
|
|
233
|
-
'currentVersion',
|
|
234
|
-
'',
|
|
235
|
-
) as string;
|
|
236
|
-
if (!lastVersion) {
|
|
237
|
-
this.preferences.deleteSync('currentVersion');
|
|
238
|
-
} else {
|
|
239
|
-
this.preferences.deleteSync('lastVersion');
|
|
240
|
-
this.preferences.putSync('currentVersion', lastVersion);
|
|
241
|
-
}
|
|
242
|
-
this.preferences.putSync('firstTimeOk', true);
|
|
243
|
-
this.preferences.putSync('firstTime', false);
|
|
244
|
-
this.preferences.putSync('rolledBackVersion', currentVersion);
|
|
245
|
-
this.preferences.flush();
|
|
246
|
-
return lastVersion;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
public async cleanUp() {
|
|
250
|
-
const params = new DownloadTaskParams();
|
|
251
|
-
params.type = DownloadTaskParams.TASK_TYPE_CLEANUP;
|
|
252
|
-
params.hash = this.preferences.getSync('currentVersion', '') as string;
|
|
253
|
-
params.originHash = this.preferences.getSync('lastVersion', '') as string;
|
|
254
|
-
params.unzipDirectory = this.rootDir;
|
|
255
|
-
const downloadTask = new DownloadTask(this.context);
|
|
256
|
-
await downloadTask.execute(params);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
public getIsUsingBundleUrl(): boolean {
|
|
260
|
-
return UpdateContext.isUsingBundleUrl;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import bundleManager from '@ohos.bundle.bundleManager';
|
|
2
|
-
import common from '@ohos.app.ability.common';
|
|
3
|
-
import { UpdateContext } from './UpdateContext';
|
|
4
|
-
import logger from './Logger';
|
|
5
|
-
|
|
6
|
-
const TAG = 'UpdateModuleImpl';
|
|
7
|
-
|
|
8
|
-
export class UpdateModuleImpl {
|
|
9
|
-
static readonly NAME = 'Pushy';
|
|
10
|
-
|
|
11
|
-
static async downloadFullUpdate(
|
|
12
|
-
updateContext: UpdateContext,
|
|
13
|
-
options: { updateUrl: string; hash: string },
|
|
14
|
-
): Promise<void> {
|
|
15
|
-
return updateContext.downloadFullUpdate(options.updateUrl, options.hash);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static async downloadPatchFromPackage(
|
|
19
|
-
updateContext: UpdateContext,
|
|
20
|
-
options: { updateUrl: string; hash: string },
|
|
21
|
-
): Promise<void> {
|
|
22
|
-
return updateContext.downloadPatchFromPackage(
|
|
23
|
-
options.updateUrl,
|
|
24
|
-
options.hash,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static async downloadPatchFromPpk(
|
|
29
|
-
updateContext: UpdateContext,
|
|
30
|
-
options: { updateUrl: string; hash: string; originHash: string },
|
|
31
|
-
): Promise<void> {
|
|
32
|
-
return updateContext.downloadPatchFromPpk(
|
|
33
|
-
options.updateUrl,
|
|
34
|
-
options.hash,
|
|
35
|
-
options.originHash,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static async reloadUpdate(
|
|
40
|
-
updateContext: UpdateContext,
|
|
41
|
-
context: common.UIAbilityContext,
|
|
42
|
-
options: { hash: string },
|
|
43
|
-
): Promise<void> {
|
|
44
|
-
const hash = options.hash;
|
|
45
|
-
if (!hash) {
|
|
46
|
-
throw Error('hash不能为空');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
await updateContext.switchVersion(hash);
|
|
51
|
-
const bundleInfo = await bundleManager.getBundleInfoForSelf(
|
|
52
|
-
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION,
|
|
53
|
-
);
|
|
54
|
-
await context.terminateSelf();
|
|
55
|
-
const want = {
|
|
56
|
-
bundleName: bundleInfo.name,
|
|
57
|
-
abilityName: context.abilityInfo?.name,
|
|
58
|
-
};
|
|
59
|
-
await context.startAbility(want);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
logger.error(TAG, `reloadUpdate failed: ${error}`);
|
|
62
|
-
throw Error(`switchVersion failed ${error.message}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static async setNeedUpdate(
|
|
67
|
-
updateContext: UpdateContext,
|
|
68
|
-
options: { hash: string },
|
|
69
|
-
): Promise<boolean> {
|
|
70
|
-
const hash = options.hash;
|
|
71
|
-
if (!hash) {
|
|
72
|
-
throw Error('empty hash');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
await updateContext.switchVersion(hash);
|
|
77
|
-
return true;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
logger.error(TAG, `setNeedUpdate failed: ${error}`);
|
|
80
|
-
throw Error(`switchVersionLater failed: ${error.message}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static async markSuccess(updateContext: UpdateContext): Promise<boolean> {
|
|
85
|
-
try {
|
|
86
|
-
await updateContext.markSuccess();
|
|
87
|
-
return true;
|
|
88
|
-
} catch (error) {
|
|
89
|
-
logger.error(TAG, `markSuccess failed: ${error}`);
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static async setUuid(
|
|
95
|
-
updateContext: UpdateContext,
|
|
96
|
-
uuid: string,
|
|
97
|
-
): Promise<void> {
|
|
98
|
-
return updateContext.setKv('uuid', uuid);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
static checkJson(json: string): boolean {
|
|
102
|
-
try {
|
|
103
|
-
JSON.parse(json);
|
|
104
|
-
return true;
|
|
105
|
-
} catch {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static setLocalHashInfo(
|
|
111
|
-
updateContext: UpdateContext,
|
|
112
|
-
hash: string,
|
|
113
|
-
info: string,
|
|
114
|
-
): boolean {
|
|
115
|
-
updateContext.setKv(`hash_${hash}`, info);
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
static getLocalHashInfo(updateContext: UpdateContext, hash: string): string {
|
|
120
|
-
const value = updateContext.getKv(`hash_${hash}`);
|
|
121
|
-
return value;
|
|
122
|
-
}
|
|
123
|
-
}
|