From 2ffe80d8d2ef394919f1da59136bae65ef5766e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 18 Jun 2025 13:43:15 +0800 Subject: [PATCH 1/8] =?UTF-8?q?arkts=201.2=20=E9=9D=99=E6=80=81=E5=8C=96?= =?UTF-8?q?=20Signed-off-by:=20=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bundle.json | 4 +- foundations/model/include/business_error.h | 5 + frameworks/js/ani/BUILD.gn | 114 + frameworks/js/ani/idl/@ohos.update.d.ts | 2073 +++++++++++++++++ frameworks/js/ani/idl/ohos.update.taihe | 342 +++ frameworks/js/ani/include/ani_base_updater.h | 55 + .../js/ani/include/ani_common_conveter.h | 93 + frameworks/js/ani/include/ani_local_updater.h | 32 + frameworks/js/ani/include/ani_restorer.h | 33 + frameworks/js/ani/include/ani_updater.h | 62 + frameworks/js/ani/src/ani_base_updater.cpp | 148 ++ frameworks/js/ani/src/ani_common_conveter.cpp | 305 +++ frameworks/js/ani/src/ani_local_updater.cpp | 47 + frameworks/js/ani/src/ani_restorer.cpp | 32 + frameworks/js/ani/src/ani_updater.cpp | 195 ++ frameworks/js/ani/src/taihe_impl.cpp | 239 ++ .../callback/src/base_callback_utils.cpp | 1 + 17 files changed, 3779 insertions(+), 1 deletion(-) create mode 100644 frameworks/js/ani/BUILD.gn create mode 100644 frameworks/js/ani/idl/@ohos.update.d.ts create mode 100644 frameworks/js/ani/idl/ohos.update.taihe create mode 100644 frameworks/js/ani/include/ani_base_updater.h create mode 100644 frameworks/js/ani/include/ani_common_conveter.h create mode 100644 frameworks/js/ani/include/ani_local_updater.h create mode 100644 frameworks/js/ani/include/ani_restorer.h create mode 100644 frameworks/js/ani/include/ani_updater.h create mode 100644 frameworks/js/ani/src/ani_base_updater.cpp create mode 100644 frameworks/js/ani/src/ani_common_conveter.cpp create mode 100644 frameworks/js/ani/src/ani_local_updater.cpp create mode 100644 frameworks/js/ani/src/ani_restorer.cpp create mode 100644 frameworks/js/ani/src/ani_updater.cpp create mode 100644 frameworks/js/ani/src/taihe_impl.cpp diff --git a/bundle.json b/bundle.json index 10d428cf..f16d9256 100644 --- a/bundle.json +++ b/bundle.json @@ -51,12 +51,14 @@ "preferences", "sys_installer", "time_service", - "relational_store" + "relational_store", + "runtime_core" ], "third_party": [] }, "build": { "modules": [ + "//base/update/updateservice/frameworks/js/ani/:update_framework_taihe", "//base/update/updateservice/frameworks/js/napi/update:update", "//base/update/updateservice/interfaces/inner_api/engine:updateservicekits", "//base/update/updateservice/interfaces/inner_api/modulemgr:update_module_mgr", diff --git a/foundations/model/include/business_error.h b/foundations/model/include/business_error.h index 24a7f572..2eabd721 100644 --- a/foundations/model/include/business_error.h +++ b/foundations/model/include/business_error.h @@ -39,6 +39,11 @@ struct BusinessError { return *this; } + bool IsSuccess() const + { + return errorNum == CallResult::SUCCESS; + } + BusinessError &AddErrorMessage(int32_t errorCode, const std::string &errorMessage) { ErrorMessage errMsg; diff --git a/frameworks/js/ani/BUILD.gn b/frameworks/js/ani/BUILD.gn new file mode 100644 index 00000000..bbff8340 --- /dev/null +++ b/frameworks/js/ani/BUILD.gn @@ -0,0 +1,114 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("../../../updateengine.gni") +import("$updateengine_root_path/foundations/foundations.gni") + +copy_taihe_idl("copy_update_framework") { + sources = [ "idl/ohos.update.taihe" ] +} + +subsystem_name = "updater" +part_name = "update_service" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" +ohos_taihe("run_taihe_update") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_update_framework" ] + outputs = [ + "$taihe_generated_file_path/src/ani_constructor.cpp", + "$taihe_generated_file_path/src/ohos.update.ani.cpp", + "$taihe_generated_file_path/src/ohos.update.abi.c", + ] +} + +ani_includes = [ + "include", + "$updateengine_root_path/frameworks/js/napi/update/include", + "$updateengine_root_path/frameworks/js/napi/update/common/include", +] +ani_includes += foundations_include + + +ani_deps = [ + ":run_taihe_update", + "$updateengine_root_path/foundations:update_foundations", + "$updateengine_root_path/frameworks/js/napi/update:$updateengine_client_library_name", + "$updateengine_root_path/interfaces/inner_api/engine:$updateengine_inner_library_name", +] + +ani_deps +=foundations_deps + + +ani_external_deps =[ + "c_utils:utils", + "runtime_core:ani", + "runtime_core:libarkruntime", + "runtime_core:ani_helpers", + "cJSON:cjson", +] +ani_external_deps += foundations_external_deps + +taihe_shared_library("update_ani") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + taihe_generated_file_path = "$taihe_generated_file_path" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe_update") + include_dirs = ani_includes + sources += [ + "src/ani_base_updater.cpp", + "src/ani_common_conveter.cpp", + "src/ani_local_updater.cpp", + "src/ani_restorer.cpp", + "src/ani_updater.cpp", + "src/taihe_impl.cpp", + ] + deps = ani_deps + external_deps = ani_external_deps +} + +generate_static_abc("update_framework_abc") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/@ohos.update.ets" ] + is_boot_abc = "True" + dst_file = "$target_out_dir/update_ani.abc" + out_puts = [ "$target_out_dir/update_ani.abc" ] + device_dst_file = "/system/framework/update_ani.abc" + dependencies = [ ":run_taihe_update" ] +} + +ohos_prebuilt_etc("update_framework_etc") { + source = "$target_out_dir/update_ani.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":update_framework_abc" ] +} + +group("update_framework_taihe") { + deps = [ + ":update_framework_etc", + ":update_ani", + ] +} \ No newline at end of file diff --git a/frameworks/js/ani/idl/@ohos.update.d.ts b/frameworks/js/ani/idl/@ohos.update.d.ts new file mode 100644 index 00000000..8f6b97e8 --- /dev/null +++ b/frameworks/js/ani/idl/@ohos.update.d.ts @@ -0,0 +1,2073 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @kit BasicServicesKit + */ + +import type { AsyncCallback } from './@ohos.base'; + +/** + * A static class to do update for device. + * + * @namespace update + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ +declare namespace update { + /** + * Get online update handler for the calling device. + * + * @param { UpgradeInfo } upgradeInfo - Indicates client app and business type. + * @returns { Updater } online update handler to perform online update. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + function getOnlineUpdater(upgradeInfo: UpgradeInfo): Updater; + + /** + * Get restore handler. + * + * @returns { Restorer } restore handler to perform factory reset. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + function getRestorer(): Restorer; + + /** + * Get local update handler. + * + * @returns { LocalUpdater } local update handler to perform local update. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + function getLocalUpdater(): LocalUpdater; + + /** + * A static class to do online update. + * + * @interface Updater + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface Updater { + /** + * Check new version. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { AsyncCallback } callback - Callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + checkNewVersion(callback: AsyncCallback): void; + + /** + * Check new version. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @returns { Promise } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + checkNewVersion(): Promise; + + /** + * Get new version. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { AsyncCallback } callback - Callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getNewVersionInfo(callback: AsyncCallback): void; + + /** + * Get new version. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @returns { Promise } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getNewVersionInfo(): Promise; + + /** + * Get new version description. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { DescriptionOptions } descriptionOptions - Options of the description file. + * @param { AsyncCallback> } callback - Callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getNewVersionDescription( + versionDigestInfo: VersionDigestInfo, + descriptionOptions: DescriptionOptions, + callback: AsyncCallback> + ): void; + + /** + * Get new version description. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { DescriptionOptions } descriptionOptions - Options of the description file. + * @returns { Promise> } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getNewVersionDescription( + versionDigestInfo: VersionDigestInfo, + descriptionOptions: DescriptionOptions + ): Promise>; + + /** + * Get current version. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { AsyncCallback } callback - Callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getCurrentVersionInfo(callback: AsyncCallback): void; + + /** + * Get current version. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @returns { Promise } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getCurrentVersionInfo(): Promise; + + /** + * Get current version description. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { DescriptionOptions } descriptionOptions - Options of the description file. + * @param { AsyncCallback> } callback - Callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getCurrentVersionDescription( + descriptionOptions: DescriptionOptions, + callback: AsyncCallback> + ): void; + + /** + * Get current version description. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { DescriptionOptions } descriptionOptions - Options of the description file. + * @returns { Promise> } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getCurrentVersionDescription(descriptionOptions: DescriptionOptions): Promise>; + + /** + * Get task info. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { AsyncCallback } callback - Callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getTaskInfo(callback: AsyncCallback): void; + + /** + * Get task info. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @returns { Promise } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getTaskInfo(): Promise; + + /** + * Trigger download new version packages. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { DownloadOptions } downloadOptions - Download options. + * @param { AsyncCallback } callback - Callback used to return the result. + * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + download( + versionDigestInfo: VersionDigestInfo, + downloadOptions: DownloadOptions, + callback: AsyncCallback + ): void; + + /** + * Trigger download new version packages. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { DownloadOptions } downloadOptions - Download options. + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + download(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions): Promise; + + /** + * Resume download new version packages. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { ResumeDownloadOptions } resumeDownloadOptions - Options for resume download. + * @param { AsyncCallback } callback - Callback used to return the result. + * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + resumeDownload( + versionDigestInfo: VersionDigestInfo, + resumeDownloadOptions: ResumeDownloadOptions, + callback: AsyncCallback + ): void; + + /** + * Resume download new version packages. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { ResumeDownloadOptions } resumeDownloadOptions - Options for resume download. + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + resumeDownload(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions): Promise; + + /** + * Pause download new version packages. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { PauseDownloadOptions } pauseDownloadOptions - Options for pause download. + * @param { AsyncCallback } callback - Callback used to return the result. + * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + pauseDownload( + versionDigestInfo: VersionDigestInfo, + pauseDownloadOptions: PauseDownloadOptions, + callback: AsyncCallback + ): void; + + /** + * Pause download new version packages. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { PauseDownloadOptions } pauseDownloadOptions - Options for pause download. + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + pauseDownload(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions): Promise; + + /** + * Install packages for the device. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { UpgradeOptions } upgradeOptions - Update options. + * @param { AsyncCallback } callback - Callback used to return the result. + * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + upgrade(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions, callback: AsyncCallback): void; + + /** + * Install packages for the device. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { UpgradeOptions } upgradeOptions - Update options. + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + upgrade(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions): Promise; + + /** + * Clear error during upgrade. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { ClearOptions } clearOptions - Clear options. + * @param { AsyncCallback } callback - Callback used to return the result. + * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + clearError(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions, callback: AsyncCallback): void; + + /** + * Clear error during upgrade. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { VersionDigestInfo } versionDigestInfo - Version digest information. + * @param { ClearOptions } clearOptions - Clear options. + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + clearError(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions): Promise; + + /** + * Get current upgrade policy. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { AsyncCallback } callback - Callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getUpgradePolicy(callback: AsyncCallback): void; + + /** + * Get current upgrade policy. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @returns { Promise } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + getUpgradePolicy(): Promise; + + /** + * Set upgrade policy. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { UpgradePolicy } policy - Update policy. + * @param { AsyncCallback } callback - Callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + setUpgradePolicy(policy: UpgradePolicy, callback: AsyncCallback): void; + + /** + * Set upgrade policy. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { UpgradePolicy } policy - Update policy. + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + setUpgradePolicy(policy: UpgradePolicy): Promise; + + /** + * Terminate upgrade task. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { AsyncCallback } callback - Callback used to return the result. + * If the operation is successful, 'err' is 'undefined'; otherwise, 'err' is an 'Error' object. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + terminateUpgrade(callback: AsyncCallback): void; + + /** + * Terminate upgrade task. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + terminateUpgrade(): Promise; + + /** + * Subscribe task update events + * + * @param { EventClassifyInfo } eventClassifyInfo - Event information. + * @param { UpgradeTaskCallback } taskCallback - Event callback. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + on(eventClassifyInfo: EventClassifyInfo, taskCallback: UpgradeTaskCallback): void; + + /** + * Unsubscribe task update events + * + * @param { EventClassifyInfo } eventClassifyInfo - Event information. + * @param { UpgradeTaskCallback } taskCallback - Event callback. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + off(eventClassifyInfo: EventClassifyInfo, taskCallback?: UpgradeTaskCallback): void; + } + + /** + * A static class to do restore. + * + * @interface Restorer + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface Restorer { + /** + * Reboot and clean user data. + * + * @permission ohos.permission.FACTORY_RESET + * @param { AsyncCallback } callback - Callback used to return the result. + * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + factoryReset(callback: AsyncCallback): void; + + /** + * Reboot and clean user data. + * + * @permission ohos.permission.FACTORY_RESET + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + factoryReset(): Promise; + } + + /** + * A static class to do local update. + * + * @interface LocalUpdater + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface LocalUpdater { + /** + * Verify local update package. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { UpgradeFile } upgradeFile - Update file. + * @param { string } certsFile - Path of the certificate file. + * @param { AsyncCallback } callback - Callback used to return the verify upgrade package result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + verifyUpgradePackage(upgradeFile: UpgradeFile, certsFile: string, callback: AsyncCallback): void; + + /** + * Verify local update package. + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { UpgradeFile } upgradeFile - Update file. + * @param { string } certsFile - Path of the certificate file. + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + verifyUpgradePackage(upgradeFile: UpgradeFile, certsFile: string): Promise; + + /** + * Apply local update package. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { Array } upgradeFiles - Update files. + * @param { AsyncCallback } callback - Callback used to return the apply new version result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + applyNewVersion(upgradeFiles: Array, callback: AsyncCallback): void; + + /** + * Apply local update package. + * Apps should listen to task update event + * + * @permission ohos.permission.UPDATE_SYSTEM + * @param { Array } upgradeFiles - Update files. + * @returns { Promise } Promise that returns no value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @throws { BusinessError } 401 - Parameter verification failed. + * @throws { BusinessError } 11500104 - IPC error. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + applyNewVersion(upgradeFiles: Array): Promise; + + /** + * Subscribe task update events + * + * @param { EventClassifyInfo } eventClassifyInfo - Event information. + * @param { UpgradeTaskCallback } taskCallback - Event callback. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + on(eventClassifyInfo: EventClassifyInfo, taskCallback: UpgradeTaskCallback): void; + + /** + * Unsubscribe task update events + * + * @param { EventClassifyInfo } eventClassifyInfo - Event information. + * @param { UpgradeTaskCallback } taskCallback - Event callback. + * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + off(eventClassifyInfo: EventClassifyInfo, taskCallback?: UpgradeTaskCallback): void; + } + + /** + * Represents upgrade info. + * + * @typedef UpgradeInfo + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface UpgradeInfo { + /** + * Upgrade client package name + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + upgradeApp: string; + + /** + * BusinessType of upgrade + * + * @type { BusinessType } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + businessType: BusinessType; + } + + /** + * Represents business type. + * + * @typedef BusinessType + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface BusinessType { + /** + * Vendor of business type + * + * @type { BusinessVendor } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + vendor: BusinessVendor; + + /** + * Update service type + * + * @type { BusinessSubType } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + subType: BusinessSubType; + } + + /** + * Represents new version check result. + * + * @typedef CheckResult + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface CheckResult { + /** + * New version exist or not + * + * @type { boolean } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + isExistNewVersion: boolean; + + /** + * New version info + * + * @type { NewVersionInfo } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + newVersionInfo: NewVersionInfo; + } + + /** + * Represents new version info. + * + * @typedef NewVersionInfo + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface NewVersionInfo { + /** + * Digest info of new version + * + * @type { VersionDigestInfo } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + versionDigestInfo: VersionDigestInfo; + + /** + * New version component array + * + * @type { Array } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + versionComponents: Array; + } + + /** + * Represents version digest info. + * + * @typedef VersionDigestInfo + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface VersionDigestInfo { + /** + * Version digest value + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + versionDigest: string; + } + + /** + * Represents version component info. + * + * @typedef VersionComponent + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface VersionComponent { + /** + * Version component id + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + componentId: string; + + /** + * Version component type + * + * @type { ComponentType } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + componentType: ComponentType; + + /** + * Upgrade action + * + * @type { UpgradeAction } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + upgradeAction: UpgradeAction; + + /** + * Display version number + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + displayVersion: string; + + /** + * Internal version number + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + innerVersion: string; + + /** + * Update package size + * + * @type { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + size: number; + + /** + * Effective mode + * + * @type { EffectiveMode } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + effectiveMode: EffectiveMode; + + /** + * Information about the version description file + * + * @type { DescriptionInfo } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + descriptionInfo: DescriptionInfo; + } + + /** + * Represents description options. + * + * @typedef DescriptionOptions + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface DescriptionOptions { + /** + * Format of the description file + * + * @type { DescriptionFormat } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + format: DescriptionFormat; + + /** + * Language of the description file + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + language: string; + } + + /** + * Represents version component description. + * + * @typedef ComponentDescription + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface ComponentDescription { + /** + * Component id + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + componentId: string; + + /** + * Information about the description file + * + * @type { DescriptionInfo } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + descriptionInfo: DescriptionInfo; + } + + /** + * Represents new version description information. + * + * @typedef DescriptionInfo + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface DescriptionInfo { + /** + * Description content type + * + * @type { DescriptionType } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + descriptionType: DescriptionType; + + /** + * Content of the description file + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + content: string; + } + + /** + * Represents current version info. + * + * @typedef CurrentVersionInfo + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface CurrentVersionInfo { + /** + * System version number + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + osVersion: string; + + /** + * Device name + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + deviceName: string; + + /** + * Current version component array + * + * @type { Array } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + versionComponents: Array; + } + + /** + * Represents download options. + * + * @typedef DownloadOptions + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface DownloadOptions { + /** + * Allow download with the network type + * + * @type { NetType } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + allowNetwork: NetType; + + /** + * Upgrade command + * + * @type { Order } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + order: Order; + } + + /** + * Represents resume download options. + * + * @typedef ResumeDownloadOptions + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface ResumeDownloadOptions { + /** + * Allow download with the network type + * + * @type { NetType } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + allowNetwork: NetType; + } + + /** + * Represents pause download options. + * + * @typedef PauseDownloadOptions + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface PauseDownloadOptions { + /** + * Whether allow auto resume when net available + * + * @type { boolean } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + isAllowAutoResume: boolean; + } + + /** + * Represents upgrade options. + * + * @typedef UpgradeOptions + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface UpgradeOptions { + /** + * Upgrade command + * + * @type { Order } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + order: Order; + } + + /** + * Represents clear error options. + * + * @typedef ClearOptions + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface ClearOptions { + /** + * Clear status error + * + * @type { UpgradeStatus } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + status: UpgradeStatus; + } + + /** + * Represents upgrade policy. + * + * @typedef UpgradePolicy + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface UpgradePolicy { + /** + * Download strategy: open or close + * + * @type { boolean } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + downloadStrategy: boolean; + + /** + * Auto upgrade strategy: open or close + * + * @type { boolean } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + autoUpgradeStrategy: boolean; + + /** + * Auto upgrade period + * + * @type { Array } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + autoUpgradePeriods: Array; + } + + /** + * Represents upgrade period. + * + * @typedef UpgradePeriod + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface UpgradePeriod { + /** + * Start time of upgrade period + * + * @type { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + start: number; + + /** + * End time of upgrade period + * + * @type { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + end: number; + } + + /** + * Represents task info. + * + * @typedef TaskInfo + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface TaskInfo { + /** + * Whether upgrade task exist + * + * @type { boolean } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + existTask: boolean; + + /** + * Task body info + * + * @type { TaskBody } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + taskBody: TaskBody; + } + + /** + * Represents event info. + * + * @typedef EventInfo + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface EventInfo { + /** + * Event id + * + * @type { EventId } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + eventId: EventId; + + /** + * Task body info + * + * @type { TaskBody } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + taskBody: TaskBody; + } + + /** + * Represents task body info. + * + * @typedef TaskBody + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface TaskBody { + /** + * Digest info of new version + * + * @type { VersionDigestInfo } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + versionDigestInfo: VersionDigestInfo; + + /** + * Upgrade status + * + * @type { UpgradeStatus } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + status: UpgradeStatus; + + /** + * Upgrade sub status + * + * @type { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + subStatus: number; + + /** + * Upgrade progress + * + * @type { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + progress: number; + + /** + * Install mode + * + * @type { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + installMode: number; + + /** + * Error messages + * + * @type { Array } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + errorMessages: Array; + + /** + * Version component array + * + * @type { Array } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + versionComponents: Array; + } + + /** + * Represents error message. + * + * @typedef ErrorMessage + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface ErrorMessage { + /** + * Error code + * + * @type { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + errorCode: number; + + /** + * Error message + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + errorMessage: string; + } + + /** + * Represents event classify info. + * + * @typedef EventClassifyInfo + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface EventClassifyInfo { + /** + * Event classify + * + * @type { EventClassify } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + eventClassify: EventClassify; + + /** + * Additional information + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + extraInfo: string; + } + + /** + * Represents upgrade file info. + * + * @typedef UpgradeFile + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface UpgradeFile { + /** + * Upgrade file type + * + * @type { ComponentType } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + fileType: ComponentType; + + /** + * Upgrade file path + * + * @type { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + filePath: string; + } + + /** + * Called when upgrade task info changes. + * You need to implement this method in a child class. + * + * @typedef UpgradeTaskCallback + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export interface UpgradeTaskCallback { + /** + * Event callback. + * + * @param { EventInfo } eventInfo - Event information. + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + (eventInfo: EventInfo): void; + } + + /** + * Enumerates business vendor type. + * + * @enum { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum BusinessVendor { + /** + * Device vendor is open source. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + PUBLIC = 'public' + } + + /** + * Enumerates business sub type. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum BusinessSubType { + /** + * Business sub type is Firmware. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + FIRMWARE = 1 + } + + /** + * Enumerates component type. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum ComponentType { + /** + * Component type is OTA. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + OTA = 1 + } + + /** + * Enumerates upgrade action type. + * + * @enum { string } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum UpgradeAction { + /** + * Differential package. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + UPGRADE = 'upgrade', + + /** + * Recovery package. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + RECOVERY = 'recovery' + } + + /** + * Enumerates effective mode. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum EffectiveMode { + /** + * Cold update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + COLD = 1, + + /** + * Live update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + LIVE = 2, + + /** + * Hybrid live and cold update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + LIVE_AND_COLD = 3 + } + + /** + * Enumerates description type. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum DescriptionType { + /** + * Description type is content. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + CONTENT = 0, + + /** + * Description type is link. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + URI = 1 + } + + /** + * Enumerates description format. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum DescriptionFormat { + /** + * Description format is standard format. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + STANDARD = 0, + + /** + * Description format is Simple format. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + SIMPLIFIED = 1 + } + + /** + * Enumerates network type. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum NetType { + /** + * Network type is data network. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + CELLULAR = 1, + + /** + * Network type is Wi-Fi hotspot. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + METERED_WIFI = 2, + + /** + * Network type is non Wi-Fi hotspot. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + NOT_METERED_WIFI = 4, + + /** + * Network type is Wi-Fi. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + WIFI = 6, + + /** + * Network type is data network and Wi-Fi. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + CELLULAR_AND_WIFI = 7 + } + + /** + * Enumerates upgrade order. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum Order { + /** + * Upgrade order is download. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + DOWNLOAD = 1, + + /** + * Upgrade order is Install. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + INSTALL = 2, + + /** + * Upgrade order is download and install. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + DOWNLOAD_AND_INSTALL = 3, + + /** + * Upgrade order is apply. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + APPLY = 4, + + /** + * Upgrade order is install and apply. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + INSTALL_AND_APPLY = 6 + } + + /** + * Enumerates upgrade status. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum UpgradeStatus { + /** + * Upgrade status is waiting for download. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + WAITING_DOWNLOAD = 20, + + /** + * Upgrade status is downloading. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + DOWNLOADING = 21, + + /** + * Upgrade status is download paused. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + DOWNLOAD_PAUSED = 22, + + /** + * Upgrade status is download failed. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + DOWNLOAD_FAIL = 23, + + /** + * Upgrade status is waiting for installation. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + WAITING_INSTALL = 30, + + /** + * Upgrade status is upgrading. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + UPDATING = 31, + + /** + * Upgrade status is waiting for applying the update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + WAITING_APPLY = 40, + + /** + * Upgrade status is applying the update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + APPLYING = 41, + + /** + * Upgrade status is update succeeded. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + UPGRADE_SUCCESS = 50, + + /** + * Upgrade status is update failed. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + UPGRADE_FAIL = 51 + } + + /** + * Enumerates event classify. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum EventClassify { + /** + * Event classify is task event. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + TASK = 0x01000000 + } + + /** + * Enumerates event id. + * + * @enum { number } + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + export enum EventId { + /** + * Event id is task event. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_TASK_BASE = EventClassify.TASK, + + /** + * Event id is task received. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_TASK_RECEIVE, + + /** + * Event id is task cancelled. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_TASK_CANCEL, + + /** + * Event id is waiting for download. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_DOWNLOAD_WAIT, + + /** + * Event id is download started. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_DOWNLOAD_START, + + /** + * Event id is download progress update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_DOWNLOAD_UPDATE, + + /** + * Event id is download paused. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_DOWNLOAD_PAUSE, + + /** + * Event id is download resumed. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_DOWNLOAD_RESUME, + + /** + * Event id is download succeeded. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_DOWNLOAD_SUCCESS, + + /** + * Event id is download failed. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_DOWNLOAD_FAIL, + + /** + * Event id is waiting for update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_UPGRADE_WAIT, + + /** + * Event id is update started. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_UPGRADE_START, + + /** + * Event id is update in progress. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_UPGRADE_UPDATE, + + /** + * Event id is waiting for applying the update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_APPLY_WAIT, + + /** + * Event id is applying the update. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_APPLY_START, + + /** + * Event id is update succeeded. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_UPGRADE_SUCCESS, + + /** + * Event id is update failed. + * + * @syscap SystemCapability.Update.UpdateService + * @systemapi hide for inner use. + * @since 9 + */ + EVENT_UPGRADE_FAIL + } +} + +export default update; \ No newline at end of file diff --git a/frameworks/js/ani/idl/ohos.update.taihe b/frameworks/js/ani/idl/ohos.update.taihe new file mode 100644 index 00000000..35e58e9c --- /dev/null +++ b/frameworks/js/ani/idl/ohos.update.taihe @@ -0,0 +1,342 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.update", "update") + +@!sts_inject(""" + static { + loadLibrary("update_ani.z") + } +""") + + struct UpgradeInfo { + upgradeApp: String; + businessType: BusinessType; + } + + struct BusinessType { + vendor: BusinessVendor; + subType: BusinessSubType; + } + + struct CheckResult { + isExistNewVersion: bool; + newVersionInfo: NewVersionInfo; + } + + struct NewVersionInfo { + versionDigestInfo: VersionDigestInfo; + versionComponents: Array; + } + + struct VersionDigestInfo { + versionDigest: String; + } + + struct VersionComponent { + componentId: String; + componentType: ComponentType; + upgradeAction: UpgradeAction; + displayVersion: String; + innerVersion: String; + size: i32; + effectiveMode: EffectiveMode; + descriptionInfo: DescriptionInfo; + } + + struct DescriptionOptions { + format: DescriptionFormat; + language: String; + } + + struct ComponentDescription { + componentId: String; + descriptionInfo: DescriptionInfo; + } + + struct DescriptionInfo { + descriptionType: DescriptionType; + content: String; + } + + struct CurrentVersionInfo { + osVersion: String; + deviceName: String; + versionComponents: Array; + } + + struct DownloadOptions { + allowNetwork: NetType; + order: Order; + } + + struct ResumeDownloadOptions { + allowNetwork: NetType; + } + + struct PauseDownloadOptions { + isAllowAutoResume: bool; + } + + struct UpgradeOptions { + order: Order; + } + + struct ClearOptions { + status: UpgradeStatus; + } + + struct UpgradePolicy { + downloadStrategy: bool; + autoUpgradeStrategy: bool; + autoUpgradePeriods: Array; + } + + struct UpgradePeriod { + start: i32; + end: i32; + } + + struct TaskInfo { + existTask: bool; + taskBody: TaskBody; + } + + struct EventInfo { + eventId: EventId; + taskBody: TaskBody; + } + + struct TaskBody { + versionDigestInfo: VersionDigestInfo; + status: UpgradeStatus; + subStatus: i32; + progress: i32; + installMode: i32; + errorMessages: Array; + versionComponents: Array; + } + + struct ErrorMessage { + errorCode: i32; + errorMessage: String; + } + + struct EventClassifyInfo { + eventClassify: EventClassify; + extraInfo: String; + } + + struct UpgradeFile { + fileType: ComponentType; + filePath: String; + } + + enum BusinessVendor : String { + PUBLIC = "public" + } + + enum BusinessSubType : i32 { + FIRMWARE = 1 + } + + enum ComponentType : i32 { + OTA = 1 + } + + enum UpgradeAction : String { + UPGRADE = "upgrade", + RECOVERY = "recovery" + } + + enum EffectiveMode : i32 { + COLD = 1, + LIVE = 2, + LIVE_AND_COLD = 3 + } + + enum DescriptionType : i32 { + CONTENT = 0, + URI = 1 + } + + enum DescriptionFormat : i32 { + STANDARD = 0, + SIMPLIFIED = 1 + } + + enum NetType : i32 { + CELLULAR = 1, + METERED_WIFI = 2, + NOT_METERED_WIFI = 4, + WIFI = 6, + CELLULAR_AND_WIFI = 7 + } + + enum Order : i32 { + DOWNLOAD = 1, + INSTALL = 2, + DOWNLOAD_AND_INSTALL = 3, + APPLY = 4, + INSTALL_AND_APPLY = 6 + } + + enum UpgradeStatus : i32 { + ERROR = -1, + INIT = 0, + CHECKING_VERSION = 10, + CHECK_VERSION_FAIL = 11, + CHECK_VERSION_SUCCESS = 12, + DOWNLOADING = 20, + DOWNLOAD_PAUSE = 21, + DOWNLOAD_CANCEL = 22, + DOWNLOAD_FAIL = 23, + DOWNLOAD_SUCCESS = 24, + VERIFYING = 30, + VERIFY_FAIL = 31, + VERIFY_SUCCESS = 32, + AUTHING = 60, + AUTH_FAIL = 61, + AUTH_SUCCESS = 62, + WAIT_TRANSFER = 68, + TRANSFER_START = 69, + PACKAGE_TRANSING = 70, + PACKAGE_TRANS_FAIL = 71, + PACKAGE_TRANS_SUCCESS = 72, + INSTALLING = 80, + INSTALL_FAIL = 81, + INSTALL_SUCCESS = 82, + INSTALL_PAUSE = 83, + UPDATING = 90, + UPDATE_FAIL = 91, + UPDATE_SUCCESS = 92, + UPGRADE_REBOOT = 93, + UPGRADE_COUNT_DOWN = 100, + UPGRADE_CANCEL = 101 + } + + enum EventClassify : i32 { + TASK = 0x01000000 + } + + enum EventId : i32 { + EVENT_TASK_BASE = 0x01000000, // EventClassify.TASK, + EVENT_TASK_RECEIVE, + EVENT_TASK_CANCEL, + EVENT_DOWNLOAD_WAIT, + EVENT_DOWNLOAD_START, + EVENT_DOWNLOAD_UPDATE, + EVENT_DOWNLOAD_PAUSE, + EVENT_DOWNLOAD_RESUME, + EVENT_DOWNLOAD_SUCCESS, + EVENT_DOWNLOAD_FAIL, + EVENT_UPGRADE_WAIT, + EVENT_UPGRADE_START, + EVENT_UPGRADE_UPDATE, + EVENT_APPLY_WAIT, + EVENT_APPLY_START, + EVENT_UPGRADE_SUCCESS, + EVENT_UPGRADE_FAIL + } + +@!sts_inject("""export type UpgradeTaskCallback = (eventInfo: EventInfo) => void;""") + +interface Updater { + @gen_async("checkNewVersion") + @gen_promise("checkNewVersion") + checkNewVersionSync(): CheckResult; + + @gen_async("getNewVersionInfo") + @gen_promise("getNewVersionInfo") + getNewVersionInfoSync(): NewVersionInfo; + + @gen_async("getNewVersionDescription") + @gen_promise("getNewVersionDescription") + getNewVersionDescriptionSync(versionDigestInfo: VersionDigestInfo, descriptionOptions: DescriptionOptions): Array; + + @gen_async("getCurrentVersionInfo") + @gen_promise("getCurrentVersionInfo") + getCurrentVersionInfoSync(): CurrentVersionInfo; + + @gen_async("getCurrentVersionDescription") + @gen_promise("getCurrentVersionDescription") + getCurrentVersionDescriptionSync(descriptionOptions: DescriptionOptions): Array; + + @gen_async("getTaskInfo") + @gen_promise("getTaskInfo") + getTaskInfoSync(): TaskInfo; + + @gen_async("download") + @gen_promise("download") + downloadSync(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions): void; + + @gen_async("resumeDownload") + @gen_promise("resumeDownload") + resumeDownloadSync(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions): void; + + @gen_async("pauseDownload") + @gen_promise("pauseDownload") + pauseDownloadSync(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions): void; + + @gen_async("upgrade") + @gen_promise("upgrade") + upgradeSync(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions): void; + + @gen_async("clearError") + @gen_promise("clearError") + clearErrorSync(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions): void; + + @gen_async("getUpgradePolicy") + @gen_promise("getUpgradePolicy") + getUpgradePolicySync(): UpgradePolicy; + + @gen_async("setUpgradePolicy") + @gen_promise("setUpgradePolicy") + setUpgradePolicySync(policy: UpgradePolicy): void; + + @gen_async("terminateUpgrade") + @gen_promise("terminateUpgrade") + terminateUpgradeSync():void; + + on(eventClassifyInfo: EventClassifyInfo, taskCallback: (eventInfo: EventInfo) => void): void; + + off(eventClassifyInfo: EventClassifyInfo, taskCallback:Optional<(eventInfo: EventInfo) => void>): void; + } + + interface Restorer { + @gen_async("factoryReset") + @gen_promise("factoryReset") + factoryResetSync(): void; + } + + interface LocalUpdater { + @gen_async("verifyUpgradePackage") + @gen_promise("verifyUpgradePackage") + verifyUpgradePackageSync(upgradeFile: UpgradeFile, certsFile: String): void; + + @gen_async("applyNewVersion") + @gen_promise("applyNewVersion") + applyNewVersionSync(upgradeFiles: Array): void; + + on(eventClassifyInfo: EventClassifyInfo, taskCallback: (eventInfo: EventInfo) => void): void; + + off(eventClassifyInfo: EventClassifyInfo, taskCallback:Optional<(eventInfo: EventInfo) => void>): void; + } + + function getOnlineUpdater(upgradeInfo: UpgradeInfo): Updater; + + function getRestorer(): Restorer; + + function getLocalUpdater(): LocalUpdater; \ No newline at end of file diff --git a/frameworks/js/ani/include/ani_base_updater.h b/frameworks/js/ani/include/ani_base_updater.h new file mode 100644 index 00000000..5f2cabfa --- /dev/null +++ b/frameworks/js/ani/include/ani_base_updater.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANI_BASE_UPDATER_H +#define ANI_BASE_UPDATER_H + +#include +#include + +#include "ohos.update.EventInfo.proj.1.hpp" +#include "taihe/callback.hpp" + +#include "business_error.h" +#include "event_info.h" + +namespace OHOS::UpdateEngine { +class AniBaseUpdater { +public: + virtual ~AniBaseUpdater(); + AniBaseUpdater() = default; + + void On(taihe::callback_view callback); + void Off(const taihe::callback &callback); + void OffAll(); + +protected: + virtual void RegisterCallback() {} + virtual std::string GetPermissionName(); + virtual void UnRegisterCallback() {} + bool SetError(int32_t ret, const std::string &funcName, const BusinessError &error); + void CallbackEventInfo(const EventInfo &eventInfo); + +private: + BusinessError GetIpcBusinessError(const std::string &funcName, int32_t ipcRequestCode); + bool IsCommonError(CallResult callResult); + int32_t ConvertToErrorCode(CallResult callResult); + + std::mutex mutex_; + std::vector> callbacks_; +}; +} + +#endif // ANI_BASE_UPDATER_H diff --git a/frameworks/js/ani/include/ani_common_conveter.h b/frameworks/js/ani/include/ani_common_conveter.h new file mode 100644 index 00000000..316dddf7 --- /dev/null +++ b/frameworks/js/ani/include/ani_common_conveter.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANI_COMMON_CONVETER_H +#define ANI_COMMON_CONVETER_H + +#include "ohos.update.CheckResult.proj.1.hpp" +#include "ohos.update.ClearOptions.proj.1.hpp" +#include "ohos.update.ComponentDescription.proj.1.hpp" +#include "ohos.update.CurrentVersionInfo.proj.1.hpp" +#include "ohos.update.DescriptionOptions.proj.1.hpp" +#include "ohos.update.DownloadOptions.proj.1.hpp" +#include "ohos.update.EventInfo.proj.1.hpp" +#include "ohos.update.PauseDownloadOptions.proj.1.hpp" +#include "ohos.update.ResumeDownloadOptions.proj.1.hpp" +#include "ohos.update.TaskBody.proj.1.hpp" +#include "ohos.update.TaskInfo.proj.1.hpp" +#include "ohos.update.UpgradeFile.proj.1.hpp" +#include "ohos.update.UpgradeInfo.proj.1.hpp" +#include "ohos.update.UpgradeOptions.proj.1.hpp" +#include "ohos.update.UpgradePolicy.proj.1.hpp" + +#include "check_result.h" +#include "clear_options.h" +#include "component_description.h" +#include "current_version_info.h" +#include "description_options.h" +#include "download_options.h" +#include "event_info.h" +#include "pause_download_options.h" +#include "resume_download_options.h" +#include "upgrade_status.h" +#include "task_body.h" +#include "task_info.h" +#include "upgrade_file.h" +#include "upgrade_info.h" +#include "upgrade_options.h" +#include "upgrade_policy.h" + +namespace OHOS::UpdateEngine { +class AniCommonConverter { +public: + static ohos::update::ErrorMessage Converter(const ErrorMessage &error); + static taihe::array Converter(const std::vector &errors); + static ohos::update::TaskInfo Converter(const TaskInfo &info); + static ohos::update::CurrentVersionInfo Converter(const CurrentVersionInfo &info); + static ohos::update::NewVersionInfo Converter(const NewVersionInfo &info); + static ohos::update::CheckResult Converter(const CheckResult &result); + static ohos::update::TaskBody Converter(const TaskBody &taskBody); + static ohos::update::VersionDigestInfo Converter(const VersionDigestInfo &versionDigestInfo); + static ohos::update::UpgradeStatus Converter(const UpgradeStatus &status); + static ohos::update::ComponentType Converter(const ComponentType &componentType); + static ohos::update::DescriptionType Converter(const DescriptionType &descriptionType); + static ohos::update::EffectiveMode Converter(const EffectiveMode &effectiveMode); + static ohos::update::EventId Converter(const EventId &effectiveMode); + static ohos::update::DescriptionInfo Converter(const DescriptionInfo &description); + static ohos::update::UpgradeAction Converter(const std::string &action); + static ohos::update::UpgradePolicy Converter(const UpgradePolicy &upgradePolicy); + static ohos::update::ComponentDescription Converter(const ComponentDescription &componentDescription); + static taihe::array Converter( + const std::vector &componentDescriptions); + static ohos::update::VersionComponent Converter(const VersionComponent &component); + static taihe::array Converter(const std::vector &components); + static ohos::update::UpgradePeriod Converter(const UpgradePeriod &upgradePeriod); + static taihe::array Converter(const std::vector &upgradePeriods); + static ohos::update::EventInfo Converter(const EventInfo &info); + static VersionDigestInfo Converter(const ohos::update::VersionDigestInfo &versionDigestInfo); + static DescriptionOptions Converter(const ohos::update::DescriptionOptions &descriptionOptions); + static DownloadOptions Converter(const ohos::update::DownloadOptions &downloadOptions); + static ResumeDownloadOptions Converter(const ohos::update::ResumeDownloadOptions &resumeDownloadOptions); + static PauseDownloadOptions Converter(const ohos::update::PauseDownloadOptions &pauseDownloadOptions); + static UpgradeOptions Converter(const ohos::update::UpgradeOptions &upgradeOptions); + static ClearOptions Converter(const ohos::update::ClearOptions &clearOptions); + static UpgradeFile Converter(const ohos::update::UpgradeFile &upgradeFile); + static UpgradeInfo Converter(const ohos::update::UpgradeInfo &info); + static BusinessType Converter(const ohos::update::BusinessType &businessType); + static UpgradePeriod Converter(const ohos::update::UpgradePeriod &period); + static UpgradePolicy Converter(const ohos::update::UpgradePolicy &policy); +}; +} +#endif // ANI_COMMON_CONVETER_H diff --git a/frameworks/js/ani/include/ani_local_updater.h b/frameworks/js/ani/include/ani_local_updater.h new file mode 100644 index 00000000..072becd6 --- /dev/null +++ b/frameworks/js/ani/include/ani_local_updater.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANI_LOCAL_UPDATER_H +#define ANI_LOCAL_UPDATER_H + +#include "ohos.update.UpgradeFile.proj.1.hpp" + +#include "ani_base_updater.h" + +namespace OHOS::UpdateEngine { +class AniLocalUpdater final : public AniBaseUpdater { +public: + AniLocalUpdater() = default; + + void VerifyUpgradePackageSync(const ohos::update::UpgradeFile &upgradeFile, taihe::string_view certsFile); + void ApplyNewVersionSync(const taihe::array_view &upgradeFiles); +}; +} +#endif // ANI_LOCAL_UPDATER_H diff --git a/frameworks/js/ani/include/ani_restorer.h b/frameworks/js/ani/include/ani_restorer.h new file mode 100644 index 00000000..01bdd187 --- /dev/null +++ b/frameworks/js/ani/include/ani_restorer.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANI_RESTORER_H +#define ANI_RESTORER_H + +#include "ani_base_updater.h" + +namespace OHOS::UpdateEngine { +class AniRestorer final : public AniBaseUpdater { +public: + explicit AniRestorer() = default; + ~AniRestorer() override = default; + + void FactoryResetSync(); + +protected: + std::string GetPermissionName() override; +}; +} // namespace OHOS::UpdateEngine +#endif // ANI_RESTORER_H diff --git a/frameworks/js/ani/include/ani_updater.h b/frameworks/js/ani/include/ani_updater.h new file mode 100644 index 00000000..29338796 --- /dev/null +++ b/frameworks/js/ani/include/ani_updater.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANI_UPDATER_H +#define ANI_UPDATER_H + +#include "ohos.update.proj.hpp" +#include "ohos.update.impl.hpp" + +#include "ani_base_updater.h" +#include "upgrade_info.h" + +namespace OHOS::UpdateEngine { +class AniUpdater final : public AniBaseUpdater { +public: + explicit AniUpdater(const UpgradeInfo &info); + + ohos::update::CheckResult CheckNewVersionSync(); + ohos::update::NewVersionInfo GetNewVersionInfoSync(); + taihe::array GetNewVersionDescriptionSync( + const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::DescriptionOptions &descriptionOptions); + ohos::update::CurrentVersionInfo GetCurrentVersionInfoSync(); + taihe::array GetCurrentVersionDescriptionSync( + const ohos::update::DescriptionOptions &descriptionOptions); + ohos::update::TaskInfo GetTaskInfoSync(); + void DownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::DownloadOptions &downloadOptions); + void ResumeDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::ResumeDownloadOptions &resumeDownloadOptions); + void PauseDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::PauseDownloadOptions &pauseDownloadOptions); + void UpgradeSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::UpgradeOptions &upgradeOptions); + void ClearErrorSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::ClearOptions &clearOptions); + ohos::update::UpgradePolicy getUpgradePolicySync(); + void SetUpgradePolicySync(const ohos::update::UpgradePolicy &policy); + void TerminateUpgradeSync(); + +protected: + void RegisterCallback() override; + void UnRegisterCallback() override; + +private: + UpgradeInfo upgradeInfo_; +}; +} + +#endif // ANI_UPDATER_H diff --git a/frameworks/js/ani/src/ani_base_updater.cpp b/frameworks/js/ani/src/ani_base_updater.cpp new file mode 100644 index 00000000..121c5b20 --- /dev/null +++ b/frameworks/js/ani/src/ani_base_updater.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_base_updater.h" + +#include "taihe/runtime.hpp" + +#include "ani_common_conveter.h" +#include "update_log.h" + +namespace OHOS::UpdateEngine { +AniBaseUpdater::~AniBaseUpdater() +{ + OffAll(); +} + +void AniBaseUpdater::On(taihe::callback_view callback) +{ + std::unique_lock lock(mutex_); + taihe::callback taiheCallback(callback); + if (callbacks_.empty()) { + RegisterCallback(); + } + callbacks_.push_back(taiheCallback); +} + +void AniBaseUpdater::Off([[maybe_unused]] const taihe::callback &callback) +{ + std::unique_lock lock(mutex_); + if (callbacks_.empty()) { + UnRegisterCallback(); + } +} + +void AniBaseUpdater::OffAll() +{ + std::unique_lock lock(mutex_); + callbacks_.clear(); + UnRegisterCallback(); +} + +std::string AniBaseUpdater::GetPermissionName() +{ + return "ohos.permission.UPDATE_SYSTEM"; +} + +bool AniBaseUpdater::SetError(int32_t ret, const std::string &funcName, const BusinessError &error) +{ + if (ret != 0) { + const BusinessError errorInfo = GetIpcBusinessError(funcName, ret); + taihe::set_business_error(ConvertToErrorCode(errorInfo.errorNum), errorInfo.message); + return true; + } + if (!error.IsSuccess()) { + taihe::set_business_error(ConvertToErrorCode(error.errorNum), error.message); + return true; + } + return false; +} + +void AniBaseUpdater::CallbackEventInfo(const EventInfo &eventInfo) +{ + std::unique_lock lock(mutex_); + for ([[maybe_unused]] const auto &callback : callbacks_) { + callback(AniCommonConverter::Converter(eventInfo)); + } +} + +bool AniBaseUpdater::IsCommonError(CallResult callResult) +{ + return callResult == CallResult::UN_SUPPORT || callResult == CallResult::NOT_SYSTEM_APP || + callResult == CallResult::APP_NOT_GRANTED || callResult == CallResult::PARAM_ERR; +} + +int32_t AniBaseUpdater::ConvertToErrorCode(CallResult callResult) +{ + if (IsCommonError(callResult) || callResult == CallResult::SUCCESS) { + return CAST_INT(callResult); + } + constexpr int32_t componentErr = 11500000; + return componentErr + CAST_INT(callResult); +} + +BusinessError AniBaseUpdater::GetIpcBusinessError(const std::string &funcName, int32_t ipcRequestCode) +{ + BusinessError businessError; + std::string msg = "execute error"; + const auto ipcCallResult = static_cast(ipcRequestCode); + const std::string callResultStr = std::to_string(ConvertToErrorCode(ipcCallResult)); + + switch (ipcRequestCode) { + case INT_NOT_SYSTEM_APP: + msg = "BusinessError " + callResultStr + NOT_SYSTEM_APP_INFO.data(); + break; + case INT_APP_NOT_GRANTED: + msg = "BusinessError " + callResultStr + ": Permission denied. An attempt was made to " + funcName + + " forbidden by permission: " + GetPermissionName() + "."; + break; + case INT_CALL_IPC_ERR: + msg = "BusinessError " + callResultStr + ": IPC error."; + break; + case INT_UN_SUPPORT: + msg = "BusinessError " + callResultStr + ": Capability not supported. " + "function " + funcName + + " can not work correctly due to limited device capabilities."; + break; + case INT_PARAM_ERR: + msg = "param error"; + break; + case INT_CALL_FAIL: + msg = "BusinessError " + callResultStr + ": Execute fail."; + break; + case INT_FORBIDDEN: + msg = "BusinessError " + callResultStr + ": Forbidden execution."; + break; + case INT_DEV_UPG_INFO_ERR: + msg = "BusinessError " + callResultStr + ": Device info error."; + break; + case INT_TIME_OUT: + msg = "BusinessError " + callResultStr + ": Execute timeout."; + break; + case INT_DB_ERROR: + msg = "BusinessError " + callResultStr + ": DB error."; + break; + case INT_IO_ERROR: + msg = "BusinessError " + callResultStr + ": IO error."; + break; + case INT_NET_ERROR: + msg = "BusinessError " + callResultStr + ": Network error."; + break; + default: + break; + } + businessError.Build(static_cast(ipcRequestCode), msg); + return businessError; +} +} diff --git a/frameworks/js/ani/src/ani_common_conveter.cpp b/frameworks/js/ani/src/ani_common_conveter.cpp new file mode 100644 index 00000000..f830fd2a --- /dev/null +++ b/frameworks/js/ani/src/ani_common_conveter.cpp @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_common_conveter.h" + +namespace OHOS::UpdateEngine { +ohos::update::ErrorMessage AniCommonConverter::Converter(const ErrorMessage &error) +{ + return { + .errorCode = static_cast(error.errorCode), + .errorMessage = error.errorMessage + }; +} + +taihe::array AniCommonConverter::Converter(const std::vector &errors) +{ + std::vector taiheErrorMessage; + taiheErrorMessage.reserve(errors.size()); + for (const auto &error : errors) { + taiheErrorMessage.push_back(Converter(error)); + } + return { taiheErrorMessage }; +} + +ohos::update::TaskInfo AniCommonConverter::Converter(const TaskInfo &info) +{ + return { + .existTask = info.existTask, + .taskBody = Converter(info.taskBody) + }; +} + +ohos::update::CurrentVersionInfo AniCommonConverter::Converter(const CurrentVersionInfo &info) +{ + return { + .deviceName = info.deviceName, + .osVersion = info.osVersion, + .versionComponents = Converter(info.versionComponents) + }; +} + +ohos::update::NewVersionInfo AniCommonConverter::Converter(const NewVersionInfo &info) +{ + return { + .versionComponents = Converter(info.versionComponents), + .versionDigestInfo = Converter(info.versionDigestInfo) + }; +} + +ohos::update::CheckResult AniCommonConverter::Converter(const CheckResult &result) +{ + return { + .isExistNewVersion = result.isExistNewVersion, + .newVersionInfo = Converter(result.newVersionInfo) + }; +} + +ohos::update::TaskBody AniCommonConverter::Converter(const TaskBody &taskBody) +{ + ohos::update::TaskBody value = { + .progress = taskBody.progress, + .status = Converter(taskBody.status), + .errorMessages = Converter(taskBody.errorMessages), + .installMode = static_cast(taskBody.installMode), + .subStatus = static_cast(taskBody.subStatus), + .versionComponents = Converter(taskBody.versionComponents), + .versionDigestInfo = Converter(taskBody.versionDigestInfo) + }; + return value; +} + +ohos::update::VersionDigestInfo AniCommonConverter::Converter(const VersionDigestInfo &versionDigestInfo) +{ + return { + .versionDigest = versionDigestInfo.versionDigest + }; +} + +ohos::update::UpgradeStatus AniCommonConverter::Converter(const UpgradeStatus &status) +{ + return ohos::update::UpgradeStatus::from_value(static_cast(status)); +} + +ohos::update::ComponentType AniCommonConverter::Converter(const ComponentType &componentType) +{ + return ohos::update::ComponentType::from_value(static_cast(componentType)); +} + +ohos::update::DescriptionType AniCommonConverter::Converter(const DescriptionType &descriptionType) +{ + return ohos::update::DescriptionType::from_value(static_cast(descriptionType)); +} + +ohos::update::EffectiveMode AniCommonConverter::Converter(const EffectiveMode &effectiveMode) +{ + return ohos::update::EffectiveMode::from_value(static_cast(effectiveMode)); +} + +ohos::update::DescriptionInfo AniCommonConverter::Converter(const DescriptionInfo &description) +{ + return { + .content = description.content, + .descriptionType = Converter(description.descriptionType) + }; +} + +ohos::update::UpgradeAction AniCommonConverter::Converter(const std::string &action) +{ + return ohos::update::UpgradeAction::from_value(action); +} + +ohos::update::UpgradePolicy AniCommonConverter::Converter(const UpgradePolicy &upgradePolicy) +{ + std::vector vectors = { std::begin(upgradePolicy.autoUpgradePeriods), + std::end(upgradePolicy.autoUpgradePeriods) }; + return { + .downloadStrategy = upgradePolicy.downloadStrategy, + .autoUpgradePeriods = Converter(vectors), + .autoUpgradeStrategy = upgradePolicy.autoUpgradeStrategy + }; +} + +ohos::update::ComponentDescription AniCommonConverter::Converter(const ComponentDescription &componentDescription) +{ + return { + .componentId = componentDescription.componentId, + .descriptionInfo = Converter(componentDescription.descriptionInfo) + }; +} + +taihe::array AniCommonConverter::Converter( + const std::vector &componentDescriptions) +{ + std::vector taiheComponents; + taiheComponents.reserve(componentDescriptions.size()); + for (const auto &component : componentDescriptions) { + taiheComponents.push_back(Converter(component)); + } + return { taiheComponents }; +} + +ohos::update::VersionComponent AniCommonConverter::Converter(const VersionComponent &component) +{ + return { + .size = static_cast(component.size), + .componentId = component.componentId, + .componentType = Converter(static_cast(component.componentType)), + .descriptionInfo = Converter(component.descriptionInfo), + .displayVersion = component.displayVersion, + .effectiveMode = Converter(static_cast(component.effectiveMode)), + .innerVersion = component.innerVersion, + .upgradeAction = Converter(component.upgradeAction) + }; +} + +taihe::array AniCommonConverter::Converter( + const std::vector &components) +{ + std::vector taiheComponents; + taiheComponents.reserve(components.size()); + for (const auto &component : components) { + taiheComponents.push_back(Converter(component)); + } + return { taiheComponents }; +} + +ohos::update::UpgradePeriod AniCommonConverter::Converter(const UpgradePeriod &upgradePeriod) +{ + return { + .start = static_cast(upgradePeriod.start), + .end = static_cast(upgradePeriod.end) + }; +} + +taihe::array AniCommonConverter::Converter( + const std::vector &upgradePeriods) +{ + std::vector taiheUpgradePeriods; + taiheUpgradePeriods.reserve(upgradePeriods.size()); + for (const auto &period : upgradePeriods) { + taiheUpgradePeriods.push_back(Converter(period)); + } + return { taiheUpgradePeriods }; +} + +VersionDigestInfo AniCommonConverter::Converter(const ohos::update::VersionDigestInfo &versionDigestInfo) +{ + VersionDigestInfo res; + res.versionDigest = versionDigestInfo.versionDigest; + return res; +} + +DescriptionOptions AniCommonConverter::Converter(const ohos::update::DescriptionOptions &descriptionOptions) +{ + DescriptionOptions res; + res.format = static_cast(descriptionOptions.format.get_value()); + res.language = descriptionOptions.language; + return res; +} + +DownloadOptions AniCommonConverter::Converter(const ohos::update::DownloadOptions &downloadOptions) +{ + DownloadOptions res; + res.allowNetwork = static_cast(downloadOptions.allowNetwork.get_value()); + res.order = static_cast(downloadOptions.order.get_value()); + return res; +} + +ResumeDownloadOptions AniCommonConverter::Converter(const ohos::update::ResumeDownloadOptions &resumeDownloadOptions) +{ + ResumeDownloadOptions res; + res.allowNetwork = static_cast(resumeDownloadOptions.allowNetwork.get_value()); + return res; +} + +PauseDownloadOptions AniCommonConverter::Converter(const ohos::update::PauseDownloadOptions &pauseDownloadOptions) +{ + PauseDownloadOptions res; + res.isAllowAutoResume = pauseDownloadOptions.isAllowAutoResume; + return res; +} + +UpgradeOptions AniCommonConverter::Converter(const ohos::update::UpgradeOptions &upgradeOptions) +{ + UpgradeOptions res; + res.order = static_cast(upgradeOptions.order.get_value()); + return res; +} + +ClearOptions AniCommonConverter::Converter(const ohos::update::ClearOptions &clearOptions) +{ + ClearOptions res; + res.status = static_cast(clearOptions.status.get_value()); + return res; +} + +UpgradeFile AniCommonConverter::Converter(const ohos::update::UpgradeFile &upgradeFile) +{ + UpgradeFile res; + res.filePath = upgradeFile.filePath; + res.fileType = static_cast(upgradeFile.fileType.get_value()); + return res; +} + +UpgradeInfo AniCommonConverter::Converter(const ohos::update::UpgradeInfo &info) +{ + UpgradeInfo upgradeInfo; + upgradeInfo.upgradeApp = info.upgradeApp; + upgradeInfo.businessType = Converter(info.businessType); + return upgradeInfo; +} + +BusinessType AniCommonConverter::Converter(const ohos::update::BusinessType &businessType) +{ + BusinessType business; + business.vendor = businessType.vendor; + business.subType = static_cast(businessType.subType.get_value()); + return business; +} + +UpgradePeriod AniCommonConverter::Converter(const ohos::update::UpgradePeriod &period) +{ + UpgradePeriod upgradePeriod; + upgradePeriod.start = period.start; + upgradePeriod.end = period.end; + return upgradePeriod; +} + +UpgradePolicy AniCommonConverter::Converter(const ohos::update::UpgradePolicy &policy) +{ + UpgradePolicy upgradePolicy; + upgradePolicy.downloadStrategy = policy.downloadStrategy; + upgradePolicy.autoUpgradeStrategy = policy.autoUpgradeStrategy; + const std::size_t range = std::min(policy.autoUpgradePeriods.size(), std::size(upgradePolicy.autoUpgradePeriods)); + for (std::size_t index = 0; index < range; ++index) { + upgradePolicy.autoUpgradePeriods[index] = Converter(policy.autoUpgradePeriods[index]); + } + return upgradePolicy; +} + +ohos::update::EventId AniCommonConverter::Converter(const EventId &effectiveMode) +{ + return ohos::update::EventId::from_value(static_cast(effectiveMode)); +} + +ohos::update::EventInfo AniCommonConverter::Converter(const EventInfo &info) +{ + return { + .eventId = Converter(info.eventId), + .taskBody = Converter(info.taskBody) + }; +} +} diff --git a/frameworks/js/ani/src/ani_local_updater.cpp b/frameworks/js/ani/src/ani_local_updater.cpp new file mode 100644 index 00000000..bb20bab3 --- /dev/null +++ b/frameworks/js/ani/src/ani_local_updater.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_local_updater.h" + +#include "taihe/runtime.hpp" + +#include "ani_common_conveter.h" +#include "update_service_kits.h" +#include "upgrade_file.h" + +namespace OHOS::UpdateEngine { +void AniLocalUpdater::VerifyUpgradePackageSync(const ohos::update::UpgradeFile &upgradeFile, + taihe::string_view certsFile) +{ + BusinessError error; + const int32_t ret = UpdateServiceKits::GetInstance().VerifyUpgradePackage(std::string(upgradeFile.filePath), + std::string(certsFile), error); + SetError(ret, "verifyUpgradePackage", error); +} + +void AniLocalUpdater::ApplyNewVersionSync(const taihe::array_view &upgradeFiles) +{ + BusinessError error; + UpgradeInfo upgradeInfo; + upgradeInfo.upgradeApp = LOCAL_UPGRADE_INFO; + const std::string miscFile = "/dev/block/by-name/misc"; + std::vector packageNames; + for (const auto &value : upgradeFiles) { + packageNames.emplace_back(AniCommonConverter::Converter(value).filePath); + } + const int32_t ret = UpdateServiceKits::GetInstance().ApplyNewVersion(upgradeInfo, miscFile, packageNames, error); + SetError(ret, "applyNewVersion", error); +} +} diff --git a/frameworks/js/ani/src/ani_restorer.cpp b/frameworks/js/ani/src/ani_restorer.cpp new file mode 100644 index 00000000..b76d04a0 --- /dev/null +++ b/frameworks/js/ani/src/ani_restorer.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_restorer.h" + +#include "update_service_kits.h" + +namespace OHOS::UpdateEngine { +void AniRestorer::FactoryResetSync() +{ + BusinessError error; + const int32_t ret = UpdateServiceKits::GetInstance().FactoryReset(error); + SetError(ret, "factoryReset", error); +} + +std::string AniRestorer::GetPermissionName() +{ + return "ohos.permission.FACTORY_RESET"; +} +} // namespace OHOS::UpdateEngine diff --git a/frameworks/js/ani/src/ani_updater.cpp b/frameworks/js/ani/src/ani_updater.cpp new file mode 100644 index 00000000..222325ab --- /dev/null +++ b/frameworks/js/ani/src/ani_updater.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_updater.h" + +#include + +#include "taihe/runtime.hpp" + +#include "ani_common_conveter.h" +#include "task_info.h" +#include "update_service_kits.h" + +namespace OHOS::UpdateEngine { +AniUpdater::AniUpdater(const UpgradeInfo &info) : upgradeInfo_(info) +{ + ENGINE_LOGI("AniUpdater construct upgradeInfo = %{public}s", info.ToString().c_str()); +} + +ohos::update::CheckResult AniUpdater::CheckNewVersionSync() +{ + BusinessError error; + CheckResult result; + const auto ret = UpdateServiceKits::GetInstance().CheckNewVersion(upgradeInfo_, error, result); + SetError(ret, "checkNewVersion", error); + return AniCommonConverter::Converter(result); +} + +ohos::update::NewVersionInfo AniUpdater::GetNewVersionInfoSync() +{ + BusinessError error; + NewVersionInfo info; + const auto ret = UpdateServiceKits::GetInstance().GetNewVersionInfo(upgradeInfo_, info, error); + SetError(ret, "getNewVersionInfo", error); + return AniCommonConverter::Converter(info); +} + +taihe::array AniUpdater::GetNewVersionDescriptionSync( + const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::DescriptionOptions &descriptionOptions) +{ + BusinessError error; + VersionDescriptionInfo result; + const auto ret = UpdateServiceKits::GetInstance().GetNewVersionDescription(upgradeInfo_, + AniCommonConverter::Converter(versionDigestInfo), AniCommonConverter::Converter(descriptionOptions), result, + error); + SetError(ret, "getNewVersionDescription", error); + return AniCommonConverter::Converter(result.componentDescriptions); +} + +ohos::update::CurrentVersionInfo AniUpdater::GetCurrentVersionInfoSync() +{ + BusinessError error; + CurrentVersionInfo info; + const auto ret = UpdateServiceKits::GetInstance().GetCurrentVersionInfo(upgradeInfo_, info, error); + SetError(ret, "getCurrentVersionInfo", error); + return AniCommonConverter::Converter(info); +} + +taihe::array AniUpdater::GetCurrentVersionDescriptionSync( + const ohos::update::DescriptionOptions &descriptionOptions) +{ + VersionDescriptionInfo currentVersionDescriptionInfo; + BusinessError error; + const auto ret = UpdateServiceKits::GetInstance().GetCurrentVersionDescription(upgradeInfo_, + AniCommonConverter::Converter(descriptionOptions), currentVersionDescriptionInfo, error); + SetError(ret, "getCurrentVersionDescription", error); + return AniCommonConverter::Converter(currentVersionDescriptionInfo.componentDescriptions); +} + +ohos::update::TaskInfo AniUpdater::GetTaskInfoSync() +{ + TaskInfo taskInfo; + BusinessError businessError; + const auto ret = UpdateServiceKits::GetInstance().GetTaskInfo(upgradeInfo_, taskInfo, businessError); + SetError(ret, "getTaskInfo", businessError); + return AniCommonConverter::Converter(taskInfo); +} + +void AniUpdater::DownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::DownloadOptions &downloadOptions) +{ + BusinessError businessError; + const auto ret = + UpdateServiceKits::GetInstance().Download(upgradeInfo_, AniCommonConverter::Converter(versionDigestInfo), + AniCommonConverter::Converter(downloadOptions), businessError); + SetError(ret, "download", businessError); +} + +void AniUpdater::ResumeDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::ResumeDownloadOptions &resumeDownloadOptions) +{ + BusinessError businessError; + const auto ret = + UpdateServiceKits::GetInstance().ResumeDownload(upgradeInfo_, AniCommonConverter::Converter(versionDigestInfo), + AniCommonConverter::Converter(resumeDownloadOptions), businessError); + SetError(ret, "resumeDownload", businessError); +} + +void AniUpdater::PauseDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::PauseDownloadOptions &pauseDownloadOptions) +{ + BusinessError businessError; + const auto ret = + UpdateServiceKits::GetInstance().PauseDownload(upgradeInfo_, AniCommonConverter::Converter(versionDigestInfo), + AniCommonConverter::Converter(pauseDownloadOptions), businessError); + SetError(ret, "pauseDownload", businessError); +} + +void AniUpdater::UpgradeSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::UpgradeOptions &upgradeOptions) +{ + BusinessError businessError; + const auto ret = UpdateServiceKits::GetInstance().Upgrade(upgradeInfo_, + AniCommonConverter::Converter(versionDigestInfo), AniCommonConverter::Converter(upgradeOptions), businessError); + SetError(ret, "upgrade", businessError); +} + +void AniUpdater::ClearErrorSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::ClearOptions &clearOptions) +{ + BusinessError businessError; + const auto ret = UpdateServiceKits::GetInstance().ClearError(upgradeInfo_, + AniCommonConverter::Converter(versionDigestInfo), AniCommonConverter::Converter(clearOptions), businessError); + SetError(ret, "clearError", businessError); +} + +ohos::update::UpgradePolicy AniUpdater::getUpgradePolicySync() +{ + BusinessError businessError; + UpgradePolicy policy; + + const auto ret = UpdateServiceKits::GetInstance().GetUpgradePolicy(upgradeInfo_, policy, businessError); + SetError(ret, "getUpgradePolicy", businessError); + return AniCommonConverter::Converter(policy); +} + +void AniUpdater::SetUpgradePolicySync(const ohos::update::UpgradePolicy &policy) +{ + BusinessError businessError; + + const auto ret = UpdateServiceKits::GetInstance().SetUpgradePolicy(upgradeInfo_, + AniCommonConverter::Converter(policy), businessError); + SetError(ret, "getUpgradePolicy", businessError); +} + +void AniUpdater::TerminateUpgradeSync() +{ + BusinessError businessError; + + UpdateServiceKits::GetInstance().TerminateUpgrade(upgradeInfo_, businessError); + if (!businessError.IsSuccess()) { + taihe::set_business_error(static_cast(businessError.errorNum), businessError.message); + } +} + +void AniUpdater::RegisterCallback() +{ + ENGINE_LOGI("AniUpdater::RegisterCallback"); + const UpdateCallbackInfo callback{ [=](const EventInfo &eventInfo) { CallbackEventInfo(eventInfo); } }; + constexpr int32_t sleepDuration = 10; // 回调注册失败后再次尝试之前的等待时间,单位:毫秒 + constexpr int32_t maxRetryTimes = 5; // 回调注册失败最大尝试次数 + int32_t retryTimes = 0; + do { + int32_t ret = UpdateServiceKits::GetInstance().RegisterUpdateCallback(upgradeInfo_, callback); + if (ret == INT_CALL_SUCCESS) { + break; + } + + if (retryTimes++ < maxRetryTimes) { + ENGINE_LOGI("InitCallback fail, will retry after %{public}d milliseconds", sleepDuration); + std::this_thread::sleep_for(std::chrono::milliseconds(sleepDuration)); + } else { + ENGINE_LOGE("InitCallback fail after retry %{public}d times", retryTimes); + } + } while (retryTimes < maxRetryTimes); +} + +void AniUpdater::UnRegisterCallback() +{ + UpdateServiceKits::GetInstance().UnregisterUpdateCallback(upgradeInfo_); +} +} diff --git a/frameworks/js/ani/src/taihe_impl.cpp b/frameworks/js/ani/src/taihe_impl.cpp new file mode 100644 index 00000000..9e1050e7 --- /dev/null +++ b/frameworks/js/ani/src/taihe_impl.cpp @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.update.proj.hpp" +#include "ohos.update.impl.hpp" +#include "taihe/runtime.hpp" + +#include "ani_common_conveter.h" +#include "ani_local_updater.h" +#include "ani_restorer.h" +#include "ani_updater.h" + +using namespace OHOS::UpdateEngine; +namespace { +class UpdaterImpl { +public: + explicit UpdaterImpl(const UpgradeInfo &upgradeInfo) : upgradeInfo_(upgradeInfo) {} + + ohos::update::CheckResult checkNewVersionSync() + { + ENGINE_LOGI("%{public}s method invoked", __func__); + return GetAniUpdater()->CheckNewVersionSync(); + } + + ohos::update::NewVersionInfo getNewVersionInfoSync() + { + ENGINE_LOGI("%{public}s method invoked", __func__); + return GetAniUpdater()->GetNewVersionInfoSync(); + } + + taihe::array getNewVersionDescriptionSync( + const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::DescriptionOptions &descriptionOptions) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + return GetAniUpdater()->GetNewVersionDescriptionSync(versionDigestInfo, descriptionOptions); + } + + ohos::update::CurrentVersionInfo getCurrentVersionInfoSync() + { + ENGINE_LOGI("%{public}s method invoked", __func__); + return GetAniUpdater()->GetCurrentVersionInfoSync(); + } + + taihe::array getCurrentVersionDescriptionSync( + ohos::update::DescriptionOptions const & descriptionOptions) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + return GetAniUpdater()->GetCurrentVersionDescriptionSync(descriptionOptions); + } + + ohos::update::TaskInfo getTaskInfoSync() + { + ENGINE_LOGI("%{public}s method invoked", __func__); + return GetAniUpdater()->GetTaskInfoSync(); + } + + void downloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::DownloadOptions &downloadOptions) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetAniUpdater()->DownloadSync(versionDigestInfo, downloadOptions); + } + + void resumeDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::ResumeDownloadOptions &resumeDownloadOptions) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetAniUpdater()->ResumeDownloadSync(versionDigestInfo, resumeDownloadOptions); + } + + void pauseDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::PauseDownloadOptions &pauseDownloadOptions) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetAniUpdater()->PauseDownloadSync(versionDigestInfo, pauseDownloadOptions); + } + + void upgradeSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::UpgradeOptions &upgradeOptions) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetAniUpdater()->UpgradeSync(versionDigestInfo, upgradeOptions); + } + + void clearErrorSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + const ohos::update::ClearOptions &clearOptions) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetAniUpdater()->ClearErrorSync(versionDigestInfo, clearOptions); + } + + ohos::update::UpgradePolicy getUpgradePolicySync() + { + ENGINE_LOGI("%{public}s method invoked", __func__); + return GetAniUpdater()->getUpgradePolicySync(); + } + + void setUpgradePolicySync(const ohos::update::UpgradePolicy &policy) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetAniUpdater()->SetUpgradePolicySync(policy); + } + + void terminateUpgradeSync() + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetAniUpdater()->TerminateUpgradeSync(); + } + + void on(const ohos::update::EventClassifyInfo &eventClassifyInfo, + taihe::callback_view taskCallback) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetAniUpdater()->On(taskCallback); + } + + void off(const ::ohos::update::EventClassifyInfo &eventClassifyInfo, + taihe::optional_view> taskCallback) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + if (taskCallback) { + GetAniUpdater()->Off(*taskCallback); + return; + } + GetAniUpdater()->OffAll(); + } + +private: + std::shared_ptr GetAniUpdater() + { + if (!aniUpdatersMap_.count(upgradeInfo_)) { + aniUpdatersMap_[upgradeInfo_] = std::make_shared(upgradeInfo_); + } + return aniUpdatersMap_[upgradeInfo_]; + } + + static inline std::map> aniUpdatersMap_; + UpgradeInfo upgradeInfo_; +}; + +class RestorerImpl { +public: + RestorerImpl() = default; + + void factoryResetSync() + { + ENGINE_LOGI("%{public}s method invoked", __func__); + if (aniRestorer_ == nullptr) { + aniRestorer_ = std::make_shared(); + } + aniRestorer_->FactoryResetSync(); + } + +private: + static inline std::shared_ptr aniRestorer_ = nullptr; +}; + +class LocalUpdaterImpl { +public: + LocalUpdaterImpl() = default; + + void verifyUpgradePackageSync(const ohos::update::UpgradeFile &upgradeFile, taihe::string_view certsFile) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetLocalUpdater()->VerifyUpgradePackageSync(upgradeFile, certsFile); + } + + void applyNewVersionSync(taihe::array_view upgradeFiles) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetLocalUpdater()->ApplyNewVersionSync(upgradeFiles); + } + + void on(const ohos::update::EventClassifyInfo &eventClassifyInfo, + taihe::callback_view taskCallback) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + GetLocalUpdater()->On(taskCallback); + } + + void off(const ::ohos::update::EventClassifyInfo &eventClassifyInfo, + taihe::optional_view> taskCallback) + { + ENGINE_LOGI("%{public}s method invoked", __func__); + if (taskCallback) { + GetLocalUpdater()->Off(*taskCallback); + return; + } + GetLocalUpdater()->OffAll(); + } + +private: + std::shared_ptr GetLocalUpdater() + { + if (localUpdater_ == nullptr) { + localUpdater_ = std::make_shared(); + } + return localUpdater_; + } + + static inline std::shared_ptr localUpdater_ = nullptr; +}; + +ohos::update::Updater getOnlineUpdater(const ohos::update::UpgradeInfo &upgradeInfo) +{ + const auto &info = AniCommonConverter::Converter(upgradeInfo); + return taihe::make_holder(info); +} + +ohos::update::Restorer getRestorer() +{ + return taihe::make_holder(); +} + +ohos::update::LocalUpdater getLocalUpdater() +{ + return taihe::make_holder(); +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_getOnlineUpdater(getOnlineUpdater); +TH_EXPORT_CPP_API_getRestorer(getRestorer); +TH_EXPORT_CPP_API_getLocalUpdater(getLocalUpdater); +// NOLINTEND diff --git a/services/core/ability/callback/src/base_callback_utils.cpp b/services/core/ability/callback/src/base_callback_utils.cpp index 1731c69c..5719a3ce 100644 --- a/services/core/ability/callback/src/base_callback_utils.cpp +++ b/services/core/ability/callback/src/base_callback_utils.cpp @@ -15,6 +15,7 @@ #include "base_callback_utils.h" +#include "firmware_callback_utils.h" #include "iupdate_callback.h" #include "subscribe_info.h" #include "update_log.h" -- Gitee From ca1a6ea14472fcb50dc8c7003d77a30e054803f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 18 Jun 2025 14:34:23 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9codecheck=20Signed-off-by?= =?UTF-8?q?:=20=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/ani/idl/@ohos.update.d.ts | 2073 ----------------- frameworks/js/ani/src/ani_updater.cpp | 2 +- .../callback/src/base_callback_utils.cpp | 1 - 3 files changed, 1 insertion(+), 2075 deletions(-) delete mode 100644 frameworks/js/ani/idl/@ohos.update.d.ts diff --git a/frameworks/js/ani/idl/@ohos.update.d.ts b/frameworks/js/ani/idl/@ohos.update.d.ts deleted file mode 100644 index 8f6b97e8..00000000 --- a/frameworks/js/ani/idl/@ohos.update.d.ts +++ /dev/null @@ -1,2073 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * @kit BasicServicesKit - */ - -import type { AsyncCallback } from './@ohos.base'; - -/** - * A static class to do update for device. - * - * @namespace update - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ -declare namespace update { - /** - * Get online update handler for the calling device. - * - * @param { UpgradeInfo } upgradeInfo - Indicates client app and business type. - * @returns { Updater } online update handler to perform online update. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - function getOnlineUpdater(upgradeInfo: UpgradeInfo): Updater; - - /** - * Get restore handler. - * - * @returns { Restorer } restore handler to perform factory reset. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - function getRestorer(): Restorer; - - /** - * Get local update handler. - * - * @returns { LocalUpdater } local update handler to perform local update. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - function getLocalUpdater(): LocalUpdater; - - /** - * A static class to do online update. - * - * @interface Updater - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface Updater { - /** - * Check new version. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { AsyncCallback } callback - Callback used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - checkNewVersion(callback: AsyncCallback): void; - - /** - * Check new version. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @returns { Promise } Promise used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - checkNewVersion(): Promise; - - /** - * Get new version. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { AsyncCallback } callback - Callback used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getNewVersionInfo(callback: AsyncCallback): void; - - /** - * Get new version. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @returns { Promise } Promise used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getNewVersionInfo(): Promise; - - /** - * Get new version description. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { DescriptionOptions } descriptionOptions - Options of the description file. - * @param { AsyncCallback> } callback - Callback used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getNewVersionDescription( - versionDigestInfo: VersionDigestInfo, - descriptionOptions: DescriptionOptions, - callback: AsyncCallback> - ): void; - - /** - * Get new version description. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { DescriptionOptions } descriptionOptions - Options of the description file. - * @returns { Promise> } Promise used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getNewVersionDescription( - versionDigestInfo: VersionDigestInfo, - descriptionOptions: DescriptionOptions - ): Promise>; - - /** - * Get current version. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { AsyncCallback } callback - Callback used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getCurrentVersionInfo(callback: AsyncCallback): void; - - /** - * Get current version. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @returns { Promise } Promise used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getCurrentVersionInfo(): Promise; - - /** - * Get current version description. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { DescriptionOptions } descriptionOptions - Options of the description file. - * @param { AsyncCallback> } callback - Callback used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getCurrentVersionDescription( - descriptionOptions: DescriptionOptions, - callback: AsyncCallback> - ): void; - - /** - * Get current version description. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { DescriptionOptions } descriptionOptions - Options of the description file. - * @returns { Promise> } Promise used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getCurrentVersionDescription(descriptionOptions: DescriptionOptions): Promise>; - - /** - * Get task info. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { AsyncCallback } callback - Callback used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getTaskInfo(callback: AsyncCallback): void; - - /** - * Get task info. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @returns { Promise } Promise used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getTaskInfo(): Promise; - - /** - * Trigger download new version packages. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { DownloadOptions } downloadOptions - Download options. - * @param { AsyncCallback } callback - Callback used to return the result. - * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - download( - versionDigestInfo: VersionDigestInfo, - downloadOptions: DownloadOptions, - callback: AsyncCallback - ): void; - - /** - * Trigger download new version packages. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { DownloadOptions } downloadOptions - Download options. - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - download(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions): Promise; - - /** - * Resume download new version packages. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { ResumeDownloadOptions } resumeDownloadOptions - Options for resume download. - * @param { AsyncCallback } callback - Callback used to return the result. - * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - resumeDownload( - versionDigestInfo: VersionDigestInfo, - resumeDownloadOptions: ResumeDownloadOptions, - callback: AsyncCallback - ): void; - - /** - * Resume download new version packages. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { ResumeDownloadOptions } resumeDownloadOptions - Options for resume download. - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - resumeDownload(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions): Promise; - - /** - * Pause download new version packages. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { PauseDownloadOptions } pauseDownloadOptions - Options for pause download. - * @param { AsyncCallback } callback - Callback used to return the result. - * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - pauseDownload( - versionDigestInfo: VersionDigestInfo, - pauseDownloadOptions: PauseDownloadOptions, - callback: AsyncCallback - ): void; - - /** - * Pause download new version packages. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { PauseDownloadOptions } pauseDownloadOptions - Options for pause download. - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - pauseDownload(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions): Promise; - - /** - * Install packages for the device. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { UpgradeOptions } upgradeOptions - Update options. - * @param { AsyncCallback } callback - Callback used to return the result. - * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - upgrade(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions, callback: AsyncCallback): void; - - /** - * Install packages for the device. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { UpgradeOptions } upgradeOptions - Update options. - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - upgrade(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions): Promise; - - /** - * Clear error during upgrade. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { ClearOptions } clearOptions - Clear options. - * @param { AsyncCallback } callback - Callback used to return the result. - * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - clearError(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions, callback: AsyncCallback): void; - - /** - * Clear error during upgrade. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { VersionDigestInfo } versionDigestInfo - Version digest information. - * @param { ClearOptions } clearOptions - Clear options. - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - clearError(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions): Promise; - - /** - * Get current upgrade policy. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { AsyncCallback } callback - Callback used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getUpgradePolicy(callback: AsyncCallback): void; - - /** - * Get current upgrade policy. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @returns { Promise } Promise used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - getUpgradePolicy(): Promise; - - /** - * Set upgrade policy. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { UpgradePolicy } policy - Update policy. - * @param { AsyncCallback } callback - Callback used to return the result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - setUpgradePolicy(policy: UpgradePolicy, callback: AsyncCallback): void; - - /** - * Set upgrade policy. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { UpgradePolicy } policy - Update policy. - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - setUpgradePolicy(policy: UpgradePolicy): Promise; - - /** - * Terminate upgrade task. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { AsyncCallback } callback - Callback used to return the result. - * If the operation is successful, 'err' is 'undefined'; otherwise, 'err' is an 'Error' object. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - terminateUpgrade(callback: AsyncCallback): void; - - /** - * Terminate upgrade task. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - terminateUpgrade(): Promise; - - /** - * Subscribe task update events - * - * @param { EventClassifyInfo } eventClassifyInfo - Event information. - * @param { UpgradeTaskCallback } taskCallback - Event callback. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - on(eventClassifyInfo: EventClassifyInfo, taskCallback: UpgradeTaskCallback): void; - - /** - * Unsubscribe task update events - * - * @param { EventClassifyInfo } eventClassifyInfo - Event information. - * @param { UpgradeTaskCallback } taskCallback - Event callback. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - off(eventClassifyInfo: EventClassifyInfo, taskCallback?: UpgradeTaskCallback): void; - } - - /** - * A static class to do restore. - * - * @interface Restorer - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface Restorer { - /** - * Reboot and clean user data. - * - * @permission ohos.permission.FACTORY_RESET - * @param { AsyncCallback } callback - Callback used to return the result. - * If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - factoryReset(callback: AsyncCallback): void; - - /** - * Reboot and clean user data. - * - * @permission ohos.permission.FACTORY_RESET - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - factoryReset(): Promise; - } - - /** - * A static class to do local update. - * - * @interface LocalUpdater - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface LocalUpdater { - /** - * Verify local update package. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { UpgradeFile } upgradeFile - Update file. - * @param { string } certsFile - Path of the certificate file. - * @param { AsyncCallback } callback - Callback used to return the verify upgrade package result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - verifyUpgradePackage(upgradeFile: UpgradeFile, certsFile: string, callback: AsyncCallback): void; - - /** - * Verify local update package. - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { UpgradeFile } upgradeFile - Update file. - * @param { string } certsFile - Path of the certificate file. - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - verifyUpgradePackage(upgradeFile: UpgradeFile, certsFile: string): Promise; - - /** - * Apply local update package. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { Array } upgradeFiles - Update files. - * @param { AsyncCallback } callback - Callback used to return the apply new version result. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - applyNewVersion(upgradeFiles: Array, callback: AsyncCallback): void; - - /** - * Apply local update package. - * Apps should listen to task update event - * - * @permission ohos.permission.UPDATE_SYSTEM - * @param { Array } upgradeFiles - Update files. - * @returns { Promise } Promise that returns no value. - * @throws { BusinessError } 201 - Permission denied. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @throws { BusinessError } 401 - Parameter verification failed. - * @throws { BusinessError } 11500104 - IPC error. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - applyNewVersion(upgradeFiles: Array): Promise; - - /** - * Subscribe task update events - * - * @param { EventClassifyInfo } eventClassifyInfo - Event information. - * @param { UpgradeTaskCallback } taskCallback - Event callback. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - on(eventClassifyInfo: EventClassifyInfo, taskCallback: UpgradeTaskCallback): void; - - /** - * Unsubscribe task update events - * - * @param { EventClassifyInfo } eventClassifyInfo - Event information. - * @param { UpgradeTaskCallback } taskCallback - Event callback. - * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - off(eventClassifyInfo: EventClassifyInfo, taskCallback?: UpgradeTaskCallback): void; - } - - /** - * Represents upgrade info. - * - * @typedef UpgradeInfo - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface UpgradeInfo { - /** - * Upgrade client package name - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - upgradeApp: string; - - /** - * BusinessType of upgrade - * - * @type { BusinessType } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - businessType: BusinessType; - } - - /** - * Represents business type. - * - * @typedef BusinessType - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface BusinessType { - /** - * Vendor of business type - * - * @type { BusinessVendor } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - vendor: BusinessVendor; - - /** - * Update service type - * - * @type { BusinessSubType } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - subType: BusinessSubType; - } - - /** - * Represents new version check result. - * - * @typedef CheckResult - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface CheckResult { - /** - * New version exist or not - * - * @type { boolean } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - isExistNewVersion: boolean; - - /** - * New version info - * - * @type { NewVersionInfo } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - newVersionInfo: NewVersionInfo; - } - - /** - * Represents new version info. - * - * @typedef NewVersionInfo - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface NewVersionInfo { - /** - * Digest info of new version - * - * @type { VersionDigestInfo } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - versionDigestInfo: VersionDigestInfo; - - /** - * New version component array - * - * @type { Array } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - versionComponents: Array; - } - - /** - * Represents version digest info. - * - * @typedef VersionDigestInfo - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface VersionDigestInfo { - /** - * Version digest value - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - versionDigest: string; - } - - /** - * Represents version component info. - * - * @typedef VersionComponent - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface VersionComponent { - /** - * Version component id - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - componentId: string; - - /** - * Version component type - * - * @type { ComponentType } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - componentType: ComponentType; - - /** - * Upgrade action - * - * @type { UpgradeAction } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - upgradeAction: UpgradeAction; - - /** - * Display version number - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - displayVersion: string; - - /** - * Internal version number - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - innerVersion: string; - - /** - * Update package size - * - * @type { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - size: number; - - /** - * Effective mode - * - * @type { EffectiveMode } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - effectiveMode: EffectiveMode; - - /** - * Information about the version description file - * - * @type { DescriptionInfo } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - descriptionInfo: DescriptionInfo; - } - - /** - * Represents description options. - * - * @typedef DescriptionOptions - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface DescriptionOptions { - /** - * Format of the description file - * - * @type { DescriptionFormat } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - format: DescriptionFormat; - - /** - * Language of the description file - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - language: string; - } - - /** - * Represents version component description. - * - * @typedef ComponentDescription - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface ComponentDescription { - /** - * Component id - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - componentId: string; - - /** - * Information about the description file - * - * @type { DescriptionInfo } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - descriptionInfo: DescriptionInfo; - } - - /** - * Represents new version description information. - * - * @typedef DescriptionInfo - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface DescriptionInfo { - /** - * Description content type - * - * @type { DescriptionType } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - descriptionType: DescriptionType; - - /** - * Content of the description file - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - content: string; - } - - /** - * Represents current version info. - * - * @typedef CurrentVersionInfo - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface CurrentVersionInfo { - /** - * System version number - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - osVersion: string; - - /** - * Device name - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - deviceName: string; - - /** - * Current version component array - * - * @type { Array } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - versionComponents: Array; - } - - /** - * Represents download options. - * - * @typedef DownloadOptions - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface DownloadOptions { - /** - * Allow download with the network type - * - * @type { NetType } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - allowNetwork: NetType; - - /** - * Upgrade command - * - * @type { Order } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - order: Order; - } - - /** - * Represents resume download options. - * - * @typedef ResumeDownloadOptions - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface ResumeDownloadOptions { - /** - * Allow download with the network type - * - * @type { NetType } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - allowNetwork: NetType; - } - - /** - * Represents pause download options. - * - * @typedef PauseDownloadOptions - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface PauseDownloadOptions { - /** - * Whether allow auto resume when net available - * - * @type { boolean } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - isAllowAutoResume: boolean; - } - - /** - * Represents upgrade options. - * - * @typedef UpgradeOptions - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface UpgradeOptions { - /** - * Upgrade command - * - * @type { Order } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - order: Order; - } - - /** - * Represents clear error options. - * - * @typedef ClearOptions - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface ClearOptions { - /** - * Clear status error - * - * @type { UpgradeStatus } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - status: UpgradeStatus; - } - - /** - * Represents upgrade policy. - * - * @typedef UpgradePolicy - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface UpgradePolicy { - /** - * Download strategy: open or close - * - * @type { boolean } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - downloadStrategy: boolean; - - /** - * Auto upgrade strategy: open or close - * - * @type { boolean } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - autoUpgradeStrategy: boolean; - - /** - * Auto upgrade period - * - * @type { Array } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - autoUpgradePeriods: Array; - } - - /** - * Represents upgrade period. - * - * @typedef UpgradePeriod - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface UpgradePeriod { - /** - * Start time of upgrade period - * - * @type { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - start: number; - - /** - * End time of upgrade period - * - * @type { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - end: number; - } - - /** - * Represents task info. - * - * @typedef TaskInfo - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface TaskInfo { - /** - * Whether upgrade task exist - * - * @type { boolean } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - existTask: boolean; - - /** - * Task body info - * - * @type { TaskBody } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - taskBody: TaskBody; - } - - /** - * Represents event info. - * - * @typedef EventInfo - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface EventInfo { - /** - * Event id - * - * @type { EventId } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - eventId: EventId; - - /** - * Task body info - * - * @type { TaskBody } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - taskBody: TaskBody; - } - - /** - * Represents task body info. - * - * @typedef TaskBody - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface TaskBody { - /** - * Digest info of new version - * - * @type { VersionDigestInfo } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - versionDigestInfo: VersionDigestInfo; - - /** - * Upgrade status - * - * @type { UpgradeStatus } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - status: UpgradeStatus; - - /** - * Upgrade sub status - * - * @type { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - subStatus: number; - - /** - * Upgrade progress - * - * @type { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - progress: number; - - /** - * Install mode - * - * @type { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - installMode: number; - - /** - * Error messages - * - * @type { Array } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - errorMessages: Array; - - /** - * Version component array - * - * @type { Array } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - versionComponents: Array; - } - - /** - * Represents error message. - * - * @typedef ErrorMessage - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface ErrorMessage { - /** - * Error code - * - * @type { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - errorCode: number; - - /** - * Error message - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - errorMessage: string; - } - - /** - * Represents event classify info. - * - * @typedef EventClassifyInfo - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface EventClassifyInfo { - /** - * Event classify - * - * @type { EventClassify } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - eventClassify: EventClassify; - - /** - * Additional information - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - extraInfo: string; - } - - /** - * Represents upgrade file info. - * - * @typedef UpgradeFile - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface UpgradeFile { - /** - * Upgrade file type - * - * @type { ComponentType } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - fileType: ComponentType; - - /** - * Upgrade file path - * - * @type { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - filePath: string; - } - - /** - * Called when upgrade task info changes. - * You need to implement this method in a child class. - * - * @typedef UpgradeTaskCallback - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export interface UpgradeTaskCallback { - /** - * Event callback. - * - * @param { EventInfo } eventInfo - Event information. - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - (eventInfo: EventInfo): void; - } - - /** - * Enumerates business vendor type. - * - * @enum { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum BusinessVendor { - /** - * Device vendor is open source. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - PUBLIC = 'public' - } - - /** - * Enumerates business sub type. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum BusinessSubType { - /** - * Business sub type is Firmware. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - FIRMWARE = 1 - } - - /** - * Enumerates component type. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum ComponentType { - /** - * Component type is OTA. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - OTA = 1 - } - - /** - * Enumerates upgrade action type. - * - * @enum { string } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum UpgradeAction { - /** - * Differential package. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - UPGRADE = 'upgrade', - - /** - * Recovery package. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - RECOVERY = 'recovery' - } - - /** - * Enumerates effective mode. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum EffectiveMode { - /** - * Cold update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - COLD = 1, - - /** - * Live update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - LIVE = 2, - - /** - * Hybrid live and cold update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - LIVE_AND_COLD = 3 - } - - /** - * Enumerates description type. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum DescriptionType { - /** - * Description type is content. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - CONTENT = 0, - - /** - * Description type is link. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - URI = 1 - } - - /** - * Enumerates description format. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum DescriptionFormat { - /** - * Description format is standard format. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - STANDARD = 0, - - /** - * Description format is Simple format. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - SIMPLIFIED = 1 - } - - /** - * Enumerates network type. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum NetType { - /** - * Network type is data network. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - CELLULAR = 1, - - /** - * Network type is Wi-Fi hotspot. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - METERED_WIFI = 2, - - /** - * Network type is non Wi-Fi hotspot. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - NOT_METERED_WIFI = 4, - - /** - * Network type is Wi-Fi. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - WIFI = 6, - - /** - * Network type is data network and Wi-Fi. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - CELLULAR_AND_WIFI = 7 - } - - /** - * Enumerates upgrade order. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum Order { - /** - * Upgrade order is download. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - DOWNLOAD = 1, - - /** - * Upgrade order is Install. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - INSTALL = 2, - - /** - * Upgrade order is download and install. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - DOWNLOAD_AND_INSTALL = 3, - - /** - * Upgrade order is apply. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - APPLY = 4, - - /** - * Upgrade order is install and apply. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - INSTALL_AND_APPLY = 6 - } - - /** - * Enumerates upgrade status. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum UpgradeStatus { - /** - * Upgrade status is waiting for download. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - WAITING_DOWNLOAD = 20, - - /** - * Upgrade status is downloading. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - DOWNLOADING = 21, - - /** - * Upgrade status is download paused. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - DOWNLOAD_PAUSED = 22, - - /** - * Upgrade status is download failed. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - DOWNLOAD_FAIL = 23, - - /** - * Upgrade status is waiting for installation. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - WAITING_INSTALL = 30, - - /** - * Upgrade status is upgrading. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - UPDATING = 31, - - /** - * Upgrade status is waiting for applying the update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - WAITING_APPLY = 40, - - /** - * Upgrade status is applying the update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - APPLYING = 41, - - /** - * Upgrade status is update succeeded. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - UPGRADE_SUCCESS = 50, - - /** - * Upgrade status is update failed. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - UPGRADE_FAIL = 51 - } - - /** - * Enumerates event classify. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum EventClassify { - /** - * Event classify is task event. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - TASK = 0x01000000 - } - - /** - * Enumerates event id. - * - * @enum { number } - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - export enum EventId { - /** - * Event id is task event. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_TASK_BASE = EventClassify.TASK, - - /** - * Event id is task received. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_TASK_RECEIVE, - - /** - * Event id is task cancelled. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_TASK_CANCEL, - - /** - * Event id is waiting for download. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_DOWNLOAD_WAIT, - - /** - * Event id is download started. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_DOWNLOAD_START, - - /** - * Event id is download progress update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_DOWNLOAD_UPDATE, - - /** - * Event id is download paused. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_DOWNLOAD_PAUSE, - - /** - * Event id is download resumed. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_DOWNLOAD_RESUME, - - /** - * Event id is download succeeded. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_DOWNLOAD_SUCCESS, - - /** - * Event id is download failed. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_DOWNLOAD_FAIL, - - /** - * Event id is waiting for update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_UPGRADE_WAIT, - - /** - * Event id is update started. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_UPGRADE_START, - - /** - * Event id is update in progress. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_UPGRADE_UPDATE, - - /** - * Event id is waiting for applying the update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_APPLY_WAIT, - - /** - * Event id is applying the update. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_APPLY_START, - - /** - * Event id is update succeeded. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_UPGRADE_SUCCESS, - - /** - * Event id is update failed. - * - * @syscap SystemCapability.Update.UpdateService - * @systemapi hide for inner use. - * @since 9 - */ - EVENT_UPGRADE_FAIL - } -} - -export default update; \ No newline at end of file diff --git a/frameworks/js/ani/src/ani_updater.cpp b/frameworks/js/ani/src/ani_updater.cpp index 222325ab..f44d01a3 100644 --- a/frameworks/js/ani/src/ani_updater.cpp +++ b/frameworks/js/ani/src/ani_updater.cpp @@ -153,7 +153,7 @@ void AniUpdater::SetUpgradePolicySync(const ohos::update::UpgradePolicy &policy) const auto ret = UpdateServiceKits::GetInstance().SetUpgradePolicy(upgradeInfo_, AniCommonConverter::Converter(policy), businessError); - SetError(ret, "getUpgradePolicy", businessError); + SetError(ret, "setUpgradePolicy", businessError); } void AniUpdater::TerminateUpgradeSync() diff --git a/services/core/ability/callback/src/base_callback_utils.cpp b/services/core/ability/callback/src/base_callback_utils.cpp index 5719a3ce..1731c69c 100644 --- a/services/core/ability/callback/src/base_callback_utils.cpp +++ b/services/core/ability/callback/src/base_callback_utils.cpp @@ -15,7 +15,6 @@ #include "base_callback_utils.h" -#include "firmware_callback_utils.h" #include "iupdate_callback.h" #include "subscribe_info.h" #include "update_log.h" -- Gitee From f5e34d78e4b0df3d357fd4727c78fb1130c55f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 18 Jun 2025 07:45:50 +0000 Subject: [PATCH 3/8] 111 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- bundle.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index f16d9256..7834b42d 100644 --- a/bundle.json +++ b/bundle.json @@ -58,7 +58,7 @@ }, "build": { "modules": [ - "//base/update/updateservice/frameworks/js/ani/:update_framework_taihe", + "//base/update/updateservice/frameworks/js/ani:update_framework_taihe", "//base/update/updateservice/frameworks/js/napi/update:update", "//base/update/updateservice/interfaces/inner_api/engine:updateservicekits", "//base/update/updateservice/interfaces/inner_api/modulemgr:update_module_mgr", -- Gitee From 6f24ec318bee5d9dae643aa4847328cdd8dfcfb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 18 Jun 2025 10:18:59 +0000 Subject: [PATCH 4/8] =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- frameworks/js/ani/include/ani_common_conveter.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frameworks/js/ani/include/ani_common_conveter.h b/frameworks/js/ani/include/ani_common_conveter.h index 316dddf7..5eebc9d3 100644 --- a/frameworks/js/ani/include/ani_common_conveter.h +++ b/frameworks/js/ani/include/ani_common_conveter.h @@ -22,14 +22,18 @@ #include "ohos.update.CurrentVersionInfo.proj.1.hpp" #include "ohos.update.DescriptionOptions.proj.1.hpp" #include "ohos.update.DownloadOptions.proj.1.hpp" +#include "ohos.update.EffectiveMode.proj.0.hpp" #include "ohos.update.EventInfo.proj.1.hpp" +#include "ohos.update.ErrorMessage.proj.1.hpp" #include "ohos.update.PauseDownloadOptions.proj.1.hpp" #include "ohos.update.ResumeDownloadOptions.proj.1.hpp" #include "ohos.update.TaskBody.proj.1.hpp" #include "ohos.update.TaskInfo.proj.1.hpp" +#include "ohos.update.UpgradeAction.proj.0.hpp" #include "ohos.update.UpgradeFile.proj.1.hpp" #include "ohos.update.UpgradeInfo.proj.1.hpp" #include "ohos.update.UpgradeOptions.proj.1.hpp" +#include "ohos.update.UpgradePeriod.proj.1.hpp" #include "ohos.update.UpgradePolicy.proj.1.hpp" #include "check_result.h" -- Gitee From 947c7b9c4bc3180b258f73984057367e6d6b844c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 18 Jun 2025 11:56:51 +0000 Subject: [PATCH 5/8] #include "ohos.update.proj.hpp" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- frameworks/js/ani/include/ani_base_updater.h | 2 +- .../js/ani/include/ani_common_conveter.h | 20 +------------------ frameworks/js/ani/include/ani_local_updater.h | 2 +- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/frameworks/js/ani/include/ani_base_updater.h b/frameworks/js/ani/include/ani_base_updater.h index 5f2cabfa..b44ec15f 100644 --- a/frameworks/js/ani/include/ani_base_updater.h +++ b/frameworks/js/ani/include/ani_base_updater.h @@ -19,7 +19,7 @@ #include #include -#include "ohos.update.EventInfo.proj.1.hpp" +#include "ohos.update.proj.hpp" #include "taihe/callback.hpp" #include "business_error.h" diff --git a/frameworks/js/ani/include/ani_common_conveter.h b/frameworks/js/ani/include/ani_common_conveter.h index 5eebc9d3..deab9de3 100644 --- a/frameworks/js/ani/include/ani_common_conveter.h +++ b/frameworks/js/ani/include/ani_common_conveter.h @@ -16,25 +16,7 @@ #ifndef ANI_COMMON_CONVETER_H #define ANI_COMMON_CONVETER_H -#include "ohos.update.CheckResult.proj.1.hpp" -#include "ohos.update.ClearOptions.proj.1.hpp" -#include "ohos.update.ComponentDescription.proj.1.hpp" -#include "ohos.update.CurrentVersionInfo.proj.1.hpp" -#include "ohos.update.DescriptionOptions.proj.1.hpp" -#include "ohos.update.DownloadOptions.proj.1.hpp" -#include "ohos.update.EffectiveMode.proj.0.hpp" -#include "ohos.update.EventInfo.proj.1.hpp" -#include "ohos.update.ErrorMessage.proj.1.hpp" -#include "ohos.update.PauseDownloadOptions.proj.1.hpp" -#include "ohos.update.ResumeDownloadOptions.proj.1.hpp" -#include "ohos.update.TaskBody.proj.1.hpp" -#include "ohos.update.TaskInfo.proj.1.hpp" -#include "ohos.update.UpgradeAction.proj.0.hpp" -#include "ohos.update.UpgradeFile.proj.1.hpp" -#include "ohos.update.UpgradeInfo.proj.1.hpp" -#include "ohos.update.UpgradeOptions.proj.1.hpp" -#include "ohos.update.UpgradePeriod.proj.1.hpp" -#include "ohos.update.UpgradePolicy.proj.1.hpp" +#include "ohos.update.proj.hpp" #include "check_result.h" #include "clear_options.h" diff --git a/frameworks/js/ani/include/ani_local_updater.h b/frameworks/js/ani/include/ani_local_updater.h index 072becd6..9d088b21 100644 --- a/frameworks/js/ani/include/ani_local_updater.h +++ b/frameworks/js/ani/include/ani_local_updater.h @@ -16,7 +16,7 @@ #ifndef ANI_LOCAL_UPDATER_H #define ANI_LOCAL_UPDATER_H -#include "ohos.update.UpgradeFile.proj.1.hpp" +#include "ohos.update.proj.hpp" #include "ani_base_updater.h" -- Gitee From 33511bfbdd21975b81ed8fc3720ff9d440a7d4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 18 Jun 2025 21:55:56 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9ani=5Fconstructor.cpp=20S?= =?UTF-8?q?igned-off-by:=20=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/ani/BUILD.gn | 2 +- frameworks/js/ani/idl/ohos.update.taihe | 48 +++++++++---------- frameworks/js/ani/include/ani_updater.h | 2 +- frameworks/js/ani/src/ani_constructor.cpp | 31 +++++++++++++ frameworks/js/ani/src/ani_updater.cpp | 2 +- frameworks/js/ani/src/taihe_impl.cpp | 56 +++++++++++------------ 6 files changed, 86 insertions(+), 55 deletions(-) create mode 100644 frameworks/js/ani/src/ani_constructor.cpp diff --git a/frameworks/js/ani/BUILD.gn b/frameworks/js/ani/BUILD.gn index bbff8340..5d68d681 100644 --- a/frameworks/js/ani/BUILD.gn +++ b/frameworks/js/ani/BUILD.gn @@ -28,7 +28,6 @@ ohos_taihe("run_taihe_update") { taihe_generated_file_path = "$taihe_generated_file_path" deps = [ ":copy_update_framework" ] outputs = [ - "$taihe_generated_file_path/src/ani_constructor.cpp", "$taihe_generated_file_path/src/ohos.update.ani.cpp", "$taihe_generated_file_path/src/ohos.update.abi.c", ] @@ -78,6 +77,7 @@ taihe_shared_library("update_ani") { include_dirs = ani_includes sources += [ "src/ani_base_updater.cpp", + "src/ani_constructor.cpp", "src/ani_common_conveter.cpp", "src/ani_local_updater.cpp", "src/ani_restorer.cpp", diff --git a/frameworks/js/ani/idl/ohos.update.taihe b/frameworks/js/ani/idl/ohos.update.taihe index 35e58e9c..7bc3f25c 100644 --- a/frameworks/js/ani/idl/ohos.update.taihe +++ b/frameworks/js/ani/idl/ohos.update.taihe @@ -256,87 +256,87 @@ interface Updater { @gen_async("checkNewVersion") @gen_promise("checkNewVersion") - checkNewVersionSync(): CheckResult; + CheckNewVersionSync(): CheckResult; @gen_async("getNewVersionInfo") @gen_promise("getNewVersionInfo") - getNewVersionInfoSync(): NewVersionInfo; + GetNewVersionInfoSync(): NewVersionInfo; @gen_async("getNewVersionDescription") @gen_promise("getNewVersionDescription") - getNewVersionDescriptionSync(versionDigestInfo: VersionDigestInfo, descriptionOptions: DescriptionOptions): Array; + GetNewVersionDescriptionSync(versionDigestInfo: VersionDigestInfo, descriptionOptions: DescriptionOptions): Array; @gen_async("getCurrentVersionInfo") @gen_promise("getCurrentVersionInfo") - getCurrentVersionInfoSync(): CurrentVersionInfo; + GetCurrentVersionInfoSync(): CurrentVersionInfo; @gen_async("getCurrentVersionDescription") @gen_promise("getCurrentVersionDescription") - getCurrentVersionDescriptionSync(descriptionOptions: DescriptionOptions): Array; + GetCurrentVersionDescriptionSync(descriptionOptions: DescriptionOptions): Array; @gen_async("getTaskInfo") @gen_promise("getTaskInfo") - getTaskInfoSync(): TaskInfo; + GetTaskInfoSync(): TaskInfo; @gen_async("download") @gen_promise("download") - downloadSync(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions): void; + DownloadSync(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions): void; @gen_async("resumeDownload") @gen_promise("resumeDownload") - resumeDownloadSync(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions): void; + ResumeDownloadSync(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions): void; @gen_async("pauseDownload") @gen_promise("pauseDownload") - pauseDownloadSync(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions): void; + PauseDownloadSync(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions): void; @gen_async("upgrade") @gen_promise("upgrade") - upgradeSync(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions): void; + UpgradeSync(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions): void; @gen_async("clearError") @gen_promise("clearError") - clearErrorSync(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions): void; + ClearErrorSync(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions): void; @gen_async("getUpgradePolicy") @gen_promise("getUpgradePolicy") - getUpgradePolicySync(): UpgradePolicy; + GetUpgradePolicySync(): UpgradePolicy; @gen_async("setUpgradePolicy") @gen_promise("setUpgradePolicy") - setUpgradePolicySync(policy: UpgradePolicy): void; + SetUpgradePolicySync(policy: UpgradePolicy): void; @gen_async("terminateUpgrade") @gen_promise("terminateUpgrade") - terminateUpgradeSync():void; + TerminateUpgradeSync():void; - on(eventClassifyInfo: EventClassifyInfo, taskCallback: (eventInfo: EventInfo) => void): void; + On(eventClassifyInfo: EventClassifyInfo, taskCallback: (eventInfo: EventInfo) => void): void; - off(eventClassifyInfo: EventClassifyInfo, taskCallback:Optional<(eventInfo: EventInfo) => void>): void; + Off(eventClassifyInfo: EventClassifyInfo, taskCallback:Optional<(eventInfo: EventInfo) => void>): void; } interface Restorer { @gen_async("factoryReset") @gen_promise("factoryReset") - factoryResetSync(): void; + FactoryResetSync(): void; } interface LocalUpdater { @gen_async("verifyUpgradePackage") @gen_promise("verifyUpgradePackage") - verifyUpgradePackageSync(upgradeFile: UpgradeFile, certsFile: String): void; + VerifyUpgradePackageSync(upgradeFile: UpgradeFile, certsFile: String): void; @gen_async("applyNewVersion") @gen_promise("applyNewVersion") - applyNewVersionSync(upgradeFiles: Array): void; + ApplyNewVersionSync(upgradeFiles: Array): void; - on(eventClassifyInfo: EventClassifyInfo, taskCallback: (eventInfo: EventInfo) => void): void; + On(eventClassifyInfo: EventClassifyInfo, taskCallback: (eventInfo: EventInfo) => void): void; - off(eventClassifyInfo: EventClassifyInfo, taskCallback:Optional<(eventInfo: EventInfo) => void>): void; + Off(eventClassifyInfo: EventClassifyInfo, taskCallback:Optional<(eventInfo: EventInfo) => void>): void; } - function getOnlineUpdater(upgradeInfo: UpgradeInfo): Updater; + function GetOnlineUpdater(upgradeInfo: UpgradeInfo): Updater; - function getRestorer(): Restorer; + function GetRestorer(): Restorer; - function getLocalUpdater(): LocalUpdater; \ No newline at end of file + function GetLocalUpdater(): LocalUpdater; \ No newline at end of file diff --git a/frameworks/js/ani/include/ani_updater.h b/frameworks/js/ani/include/ani_updater.h index 29338796..85f62907 100644 --- a/frameworks/js/ani/include/ani_updater.h +++ b/frameworks/js/ani/include/ani_updater.h @@ -46,7 +46,7 @@ public: const ohos::update::UpgradeOptions &upgradeOptions); void ClearErrorSync(const ohos::update::VersionDigestInfo &versionDigestInfo, const ohos::update::ClearOptions &clearOptions); - ohos::update::UpgradePolicy getUpgradePolicySync(); + ohos::update::UpgradePolicy GetUpgradePolicySync(); void SetUpgradePolicySync(const ohos::update::UpgradePolicy &policy); void TerminateUpgradeSync(); diff --git a/frameworks/js/ani/src/ani_constructor.cpp b/frameworks/js/ani/src/ani_constructor.cpp new file mode 100644 index 00000000..900b2133 --- /dev/null +++ b/frameworks/js/ani/src/ani_constructor.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "taihe/runtime.hpp" +#include "ohos.update.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::update::ANIRegister(env)) { + std::cerr << "Error from ohos::update::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/js/ani/src/ani_updater.cpp b/frameworks/js/ani/src/ani_updater.cpp index f44d01a3..a9bcc5f7 100644 --- a/frameworks/js/ani/src/ani_updater.cpp +++ b/frameworks/js/ani/src/ani_updater.cpp @@ -137,7 +137,7 @@ void AniUpdater::ClearErrorSync(const ohos::update::VersionDigestInfo &versionDi SetError(ret, "clearError", businessError); } -ohos::update::UpgradePolicy AniUpdater::getUpgradePolicySync() +ohos::update::UpgradePolicy AniUpdater::GetUpgradePolicySync() { BusinessError businessError; UpgradePolicy policy; diff --git a/frameworks/js/ani/src/taihe_impl.cpp b/frameworks/js/ani/src/taihe_impl.cpp index 9e1050e7..36c9bcaf 100644 --- a/frameworks/js/ani/src/taihe_impl.cpp +++ b/frameworks/js/ani/src/taihe_impl.cpp @@ -28,19 +28,19 @@ class UpdaterImpl { public: explicit UpdaterImpl(const UpgradeInfo &upgradeInfo) : upgradeInfo_(upgradeInfo) {} - ohos::update::CheckResult checkNewVersionSync() + ohos::update::CheckResult CheckNewVersionSync() { ENGINE_LOGI("%{public}s method invoked", __func__); return GetAniUpdater()->CheckNewVersionSync(); } - ohos::update::NewVersionInfo getNewVersionInfoSync() + ohos::update::NewVersionInfo GetNewVersionInfoSync() { ENGINE_LOGI("%{public}s method invoked", __func__); return GetAniUpdater()->GetNewVersionInfoSync(); } - taihe::array getNewVersionDescriptionSync( + taihe::array GetNewVersionDescriptionSync( const ohos::update::VersionDigestInfo &versionDigestInfo, const ohos::update::DescriptionOptions &descriptionOptions) { @@ -48,86 +48,86 @@ public: return GetAniUpdater()->GetNewVersionDescriptionSync(versionDigestInfo, descriptionOptions); } - ohos::update::CurrentVersionInfo getCurrentVersionInfoSync() + ohos::update::CurrentVersionInfo GetCurrentVersionInfoSync() { ENGINE_LOGI("%{public}s method invoked", __func__); return GetAniUpdater()->GetCurrentVersionInfoSync(); } - taihe::array getCurrentVersionDescriptionSync( + taihe::array GetCurrentVersionDescriptionSync( ohos::update::DescriptionOptions const & descriptionOptions) { ENGINE_LOGI("%{public}s method invoked", __func__); return GetAniUpdater()->GetCurrentVersionDescriptionSync(descriptionOptions); } - ohos::update::TaskInfo getTaskInfoSync() + ohos::update::TaskInfo GetTaskInfoSync() { ENGINE_LOGI("%{public}s method invoked", __func__); return GetAniUpdater()->GetTaskInfoSync(); } - void downloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + void DownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, const ohos::update::DownloadOptions &downloadOptions) { ENGINE_LOGI("%{public}s method invoked", __func__); GetAniUpdater()->DownloadSync(versionDigestInfo, downloadOptions); } - void resumeDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + void ResumeDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, const ohos::update::ResumeDownloadOptions &resumeDownloadOptions) { ENGINE_LOGI("%{public}s method invoked", __func__); GetAniUpdater()->ResumeDownloadSync(versionDigestInfo, resumeDownloadOptions); } - void pauseDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + void PauseDownloadSync(const ohos::update::VersionDigestInfo &versionDigestInfo, const ohos::update::PauseDownloadOptions &pauseDownloadOptions) { ENGINE_LOGI("%{public}s method invoked", __func__); GetAniUpdater()->PauseDownloadSync(versionDigestInfo, pauseDownloadOptions); } - void upgradeSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + void UpgradeSync(const ohos::update::VersionDigestInfo &versionDigestInfo, const ohos::update::UpgradeOptions &upgradeOptions) { ENGINE_LOGI("%{public}s method invoked", __func__); GetAniUpdater()->UpgradeSync(versionDigestInfo, upgradeOptions); } - void clearErrorSync(const ohos::update::VersionDigestInfo &versionDigestInfo, + void ClearErrorSync(const ohos::update::VersionDigestInfo &versionDigestInfo, const ohos::update::ClearOptions &clearOptions) { ENGINE_LOGI("%{public}s method invoked", __func__); GetAniUpdater()->ClearErrorSync(versionDigestInfo, clearOptions); } - ohos::update::UpgradePolicy getUpgradePolicySync() + ohos::update::UpgradePolicy GetUpgradePolicySync() { ENGINE_LOGI("%{public}s method invoked", __func__); - return GetAniUpdater()->getUpgradePolicySync(); + return GetAniUpdater()->GetUpgradePolicySync(); } - void setUpgradePolicySync(const ohos::update::UpgradePolicy &policy) + void SetUpgradePolicySync(const ohos::update::UpgradePolicy &policy) { ENGINE_LOGI("%{public}s method invoked", __func__); GetAniUpdater()->SetUpgradePolicySync(policy); } - void terminateUpgradeSync() + void TerminateUpgradeSync() { ENGINE_LOGI("%{public}s method invoked", __func__); GetAniUpdater()->TerminateUpgradeSync(); } - void on(const ohos::update::EventClassifyInfo &eventClassifyInfo, + void On(const ohos::update::EventClassifyInfo &eventClassifyInfo, taihe::callback_view taskCallback) { ENGINE_LOGI("%{public}s method invoked", __func__); GetAniUpdater()->On(taskCallback); } - void off(const ::ohos::update::EventClassifyInfo &eventClassifyInfo, + void Off(const ::ohos::update::EventClassifyInfo &eventClassifyInfo, taihe::optional_view> taskCallback) { ENGINE_LOGI("%{public}s method invoked", __func__); @@ -155,7 +155,7 @@ class RestorerImpl { public: RestorerImpl() = default; - void factoryResetSync() + void FactoryResetSync() { ENGINE_LOGI("%{public}s method invoked", __func__); if (aniRestorer_ == nullptr) { @@ -172,26 +172,26 @@ class LocalUpdaterImpl { public: LocalUpdaterImpl() = default; - void verifyUpgradePackageSync(const ohos::update::UpgradeFile &upgradeFile, taihe::string_view certsFile) + void VerifyUpgradePackageSync(const ohos::update::UpgradeFile &upgradeFile, taihe::string_view certsFile) { ENGINE_LOGI("%{public}s method invoked", __func__); GetLocalUpdater()->VerifyUpgradePackageSync(upgradeFile, certsFile); } - void applyNewVersionSync(taihe::array_view upgradeFiles) + void ApplyNewVersionSync(taihe::array_view upgradeFiles) { ENGINE_LOGI("%{public}s method invoked", __func__); GetLocalUpdater()->ApplyNewVersionSync(upgradeFiles); } - void on(const ohos::update::EventClassifyInfo &eventClassifyInfo, + void On(const ohos::update::EventClassifyInfo &eventClassifyInfo, taihe::callback_view taskCallback) { ENGINE_LOGI("%{public}s method invoked", __func__); GetLocalUpdater()->On(taskCallback); } - void off(const ::ohos::update::EventClassifyInfo &eventClassifyInfo, + void Off(const ::ohos::update::EventClassifyInfo &eventClassifyInfo, taihe::optional_view> taskCallback) { ENGINE_LOGI("%{public}s method invoked", __func__); @@ -214,18 +214,18 @@ private: static inline std::shared_ptr localUpdater_ = nullptr; }; -ohos::update::Updater getOnlineUpdater(const ohos::update::UpgradeInfo &upgradeInfo) +ohos::update::Updater GetOnlineUpdater(const ohos::update::UpgradeInfo &upgradeInfo) { const auto &info = AniCommonConverter::Converter(upgradeInfo); return taihe::make_holder(info); } -ohos::update::Restorer getRestorer() +ohos::update::Restorer GetRestorer() { return taihe::make_holder(); } -ohos::update::LocalUpdater getLocalUpdater() +ohos::update::LocalUpdater GetLocalUpdater() { return taihe::make_holder(); } @@ -233,7 +233,7 @@ ohos::update::LocalUpdater getLocalUpdater() // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_getOnlineUpdater(getOnlineUpdater); -TH_EXPORT_CPP_API_getRestorer(getRestorer); -TH_EXPORT_CPP_API_getLocalUpdater(getLocalUpdater); +TH_EXPORT_CPP_API_GetOnlineUpdater(GetOnlineUpdater); +TH_EXPORT_CPP_API_GetRestorer(GetRestorer); +TH_EXPORT_CPP_API_GetLocalUpdater(GetLocalUpdater); // NOLINTEND -- Gitee From 32d3107a75b78ec7cb8d11d434c8fa65f292dd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Thu, 19 Jun 2025 01:27:02 +0000 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- frameworks/js/ani/src/ani_constructor.cpp | 1 - frameworks/js/ani/src/ani_updater.cpp | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/frameworks/js/ani/src/ani_constructor.cpp b/frameworks/js/ani/src/ani_constructor.cpp index 900b2133..38a6db14 100644 --- a/frameworks/js/ani/src/ani_constructor.cpp +++ b/frameworks/js/ani/src/ani_constructor.cpp @@ -23,7 +23,6 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) return ANI_ERROR; } if (ANI_OK != ohos::update::ANIRegister(env)) { - std::cerr << "Error from ohos::update::ANIRegister" << std::endl; return ANI_ERROR; } *result = ANI_VERSION_1; diff --git a/frameworks/js/ani/src/ani_updater.cpp b/frameworks/js/ani/src/ani_updater.cpp index a9bcc5f7..0824b4dd 100644 --- a/frameworks/js/ani/src/ani_updater.cpp +++ b/frameworks/js/ani/src/ani_updater.cpp @@ -150,7 +150,6 @@ ohos::update::UpgradePolicy AniUpdater::GetUpgradePolicySync() void AniUpdater::SetUpgradePolicySync(const ohos::update::UpgradePolicy &policy) { BusinessError businessError; - const auto ret = UpdateServiceKits::GetInstance().SetUpgradePolicy(upgradeInfo_, AniCommonConverter::Converter(policy), businessError); SetError(ret, "setUpgradePolicy", businessError); @@ -159,11 +158,8 @@ void AniUpdater::SetUpgradePolicySync(const ohos::update::UpgradePolicy &policy) void AniUpdater::TerminateUpgradeSync() { BusinessError businessError; - UpdateServiceKits::GetInstance().TerminateUpgrade(upgradeInfo_, businessError); - if (!businessError.IsSuccess()) { - taihe::set_business_error(static_cast(businessError.errorNum), businessError.message); - } + SetError(ret, "TerminateUpgradeSync", businessError); } void AniUpdater::RegisterCallback() -- Gitee From 9737171b07172ae3a2dda71199bb452b44fb2b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Thu, 19 Jun 2025 02:46:46 +0000 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- frameworks/js/ani/src/ani_updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/ani/src/ani_updater.cpp b/frameworks/js/ani/src/ani_updater.cpp index 0824b4dd..48003de9 100644 --- a/frameworks/js/ani/src/ani_updater.cpp +++ b/frameworks/js/ani/src/ani_updater.cpp @@ -158,7 +158,7 @@ void AniUpdater::SetUpgradePolicySync(const ohos::update::UpgradePolicy &policy) void AniUpdater::TerminateUpgradeSync() { BusinessError businessError; - UpdateServiceKits::GetInstance().TerminateUpgrade(upgradeInfo_, businessError); + const auto ret = UpdateServiceKits::GetInstance().TerminateUpgrade(upgradeInfo_, businessError); SetError(ret, "TerminateUpgradeSync", businessError); } -- Gitee