diff --git a/AppScope/app.json5 b/AppScope/app.json5 index f706bbb4dfa77f90f36a8c01480780c08a8e16b6..b6ab6f3eb09bceb3553c2f562c9def96c15ee90b 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -3,8 +3,8 @@ "bundleName": "com.ohos.updateapp", "debug": false, "vendor": "example", - "versionCode": 2040000120, - "versionName": "204.0.0.120", + "versionCode": 2040000127, + "versionName": "204.0.0.127", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true diff --git a/common/src/main/ets/const/update_const.ts b/common/src/main/ets/const/update_const.ts index 592157637f42efdf7d4a4008f8159c8cd83af987..abf5aca462a66af491a562a965e724ac34642f52 100644 --- a/common/src/main/ets/const/update_const.ts +++ b/common/src/main/ets/const/update_const.ts @@ -71,6 +71,11 @@ export enum UpdateState { */ INSTALL_SUCCESS = 82, + /** + * 状态-安装暂停 + */ + INSTALL_PAUSE = 83, + /** * 状态--升级中 */ @@ -109,6 +114,13 @@ export interface OtaStatus { endReason?: string; } +export enum OtaMode { + REGULAR_OTA = 0, + STREAM_OTA = 1, + AB_REGULAR_OTA = 2, + AB_STREAM_OTA = 3 +} + /** * 升级错误码 * diff --git a/common/src/main/ets/manager/UpgradeInterface.ets b/common/src/main/ets/manager/UpgradeInterface.ets index 66deb6d9706c2b488ca3596e55713f980f2cda92..eed8e3ebead2a6cfc7120af4d4b8361d20c64cc1 100644 --- a/common/src/main/ets/manager/UpgradeInterface.ets +++ b/common/src/main/ets/manager/UpgradeInterface.ets @@ -113,7 +113,10 @@ export interface VersionPageInfo { * 生效模式 */ effectiveMode?: update.EffectiveMode; - + /** + * 升级模式 + */ + otaMode?:update.OtaMode; /** * 更新日志 */ diff --git a/feature/ota/src/main/ets/OtaPage.ets b/feature/ota/src/main/ets/OtaPage.ets index 074f111c53872c2a140bb9a1ea95137b02958c92..37cec3e0ad3ca0cef0cb39407908983ed07beb8e 100644 --- a/feature/ota/src/main/ets/OtaPage.ets +++ b/feature/ota/src/main/ets/OtaPage.ets @@ -50,6 +50,7 @@ export class OtaPage implements IPage { version: component.displayVersion, size: component.size, effectiveMode: component.effectiveMode, + otaMode:component.otaMode, changelog: { version: component.displayVersion, size: FormatUtils.formatFileSize(component.size), diff --git a/feature/ota/src/main/ets/manager/StateManager.ets b/feature/ota/src/main/ets/manager/StateManager.ets index 260d6d4a1e802a0c9cf5078887a7ec9bcfcd7770..2bd43f3f004a8aadd5aebb4d76e459877b44324b 100644 --- a/feature/ota/src/main/ets/manager/StateManager.ets +++ b/feature/ota/src/main/ets/manager/StateManager.ets @@ -108,6 +108,9 @@ export namespace StateManager { case UpdateState.INSTALLING: stateObject = new Installing(); break; + case UpdateState.INSTALL_PAUSE: + stateObject = new InstallPaused(); + break; case UpdateState.INSTALL_FAILED: stateObject = new InstallFailed(); break; @@ -327,6 +330,35 @@ export class Downloading extends BaseState { } } +export class InstallPaused extends BaseState { + constructor() { + super(); + this.actionSet.push(UpdateAction.SHOW_NEW_VERSION); + this.actionSet.push(UpdateAction.SHOW_PROCESS_VIEW); + + this.actionSet.push(UpdateAction.INSTALL); + + this.state = UpdateState.INSTALL_PAUSE; + this.downloadStateText = $r('app.string.download_status_download_pause'); + this.buttonText = $r('app.string.continue'); + this.buttonClickAction = UpdateAction.INSTALL; + + this.isButtonClickable = true; + } + + async notify(context?: common.Context, eventId?: update.EventId): Promise { + if (!VersionUtils.isInNewVersionPage()) { + return; + } + if (this.otaStatus?.endReason) { + await UpgradeAdapter.getInstance().getNotifyInstance()?.cancelAll(); + let message = await context.resourceManager.getString($r('app.string.install_pause_message').id); + ToastUtils.showToast(message); + } + + } +} + /** * 状态--下载暂停 * @@ -463,10 +495,21 @@ export class Installing extends BaseState { super(); this.actionSet.push(UpdateAction.SHOW_NEW_VERSION); this.actionSet.push(UpdateAction.SHOW_PROCESS_VIEW); + this.checkAbStreamInstall(); + } + + async checkAbStreamInstall() { + let isABStreamInstall = await VersionUtils.isABStreamInstall(); this.state = UpdateState.INSTALLING; - this.buttonText = $r('app.string.btn_upgrade') - this.isButtonClickable = false; this.downloadStateText = $r('app.string.new_version_status_installing'); + if (isABStreamInstall) { + this.buttonText = $r('app.string.cancel'); + this.isButtonClickable = true; + this.buttonClickAction = UpdateAction.CANCEL; + } else { + this.buttonText = $r('app.string.btn_upgrade'); + this.isButtonClickable = false; + } } async notify(context?: common.Context): Promise { diff --git a/feature/ota/src/main/ets/util/VersionUtils.ets b/feature/ota/src/main/ets/util/VersionUtils.ets index b9cb303c54860a31ad7b3bb0e91520e5230fddbf..9284da31681553bebce4694a9066b542318e580b 100644 --- a/feature/ota/src/main/ets/util/VersionUtils.ets +++ b/feature/ota/src/main/ets/util/VersionUtils.ets @@ -129,6 +129,24 @@ export namespace VersionUtils { })?.[0]; return component?.effectiveMode === update.EffectiveMode.LIVE_AND_COLD; } + + /** + * 是否是AB升级 + * + * @return 是否是AB升级 + */ + export async function isABStreamInstall(): Promise { + let newVersionInfo = globalThis.cachedNewVersionInfo || await OtaUpdateManager.getInstance().getNewVersion() + .then(upgradeData => { + this.log(`isABInstall upgradeData: ${upgradeData}`); + return upgradeData.callResult == UpgradeCallResult.OK ? upgradeData.data : null; + }); + let components: update.VersionComponent[] = VersionUtils.sortComponents(newVersionInfo?.versionComponents); + let component: update.VersionComponent = components?.filter((component: update.VersionComponent) => { + return component.componentType == update.ComponentType.OTA; + })?.[0]; + return component?.otaMode === update.OtaMode.AB_STREAM_OTA; + } } export default VersionUtils; \ No newline at end of file diff --git a/feature/ota/src/main/resources/base/element/string.json b/feature/ota/src/main/resources/base/element/string.json index 78940f09b6b19ed83619625541eca9022506aa8c..1ff53f730bfaae667f7cebe9bbdc6f1eefff3cb0 100644 --- a/feature/ota/src/main/resources/base/element/string.json +++ b/feature/ota/src/main/resources/base/element/string.json @@ -12,6 +12,10 @@ "name":"btn_upgrade", "value":"Install" }, + { + "name": "btn_pause", + "value": "pause" + }, { "name":"title_new_version", "value":"New version" @@ -140,6 +144,14 @@ "name":"install_success_message", "value":"Update successfully installed" }, + { + "name":"install_pause_message", + "value":"Update pause. Please try again." + }, + { + "name":"install_pause", + "value":"Update pause" + }, { "name":"install_fail_message", "value":"Installation failed" diff --git a/feature/ota/src/main/resources/zh_CN/element/string.json b/feature/ota/src/main/resources/zh_CN/element/string.json index 2a490484687c1bfc9bbd57b0f9eda73e364b8778..78814df6874aa3045e20e59feef628d319903fd4 100644 --- a/feature/ota/src/main/resources/zh_CN/element/string.json +++ b/feature/ota/src/main/resources/zh_CN/element/string.json @@ -12,6 +12,10 @@ "name":"btn_upgrade", "value":"安装" }, + { + "name": "btn_pause", + "value": "暂停" + }, { "name":"title_new_version", "value":"新版本" @@ -140,6 +144,14 @@ "name":"install_success_message", "value":"新版本安装成功" }, + { + "name":"install_pause_message", + "value":"安装暂停,请重试" + }, + { + "name":"install_pause", + "value":"安装暂停" + }, { "name":"install_fail_message", "value":"新版本安装失败" diff --git a/product/oh/base/src/main/ets/pages/newVersion.ets b/product/oh/base/src/main/ets/pages/newVersion.ets index 950d0539ccb08c8dce8708a33ce6f9b1d917343d..9f8c7f6492a606c6fcf2228b2f43a00ca8db4140 100644 --- a/product/oh/base/src/main/ets/pages/newVersion.ets +++ b/product/oh/base/src/main/ets/pages/newVersion.ets @@ -38,6 +38,8 @@ import { StateManager, UpdateAction } from '@ohos/ota/src/main/ets/manager/State import { UpgradeAdapter } from '@ohos/ota/src/main/ets/UpgradeAdapter'; import { VersionUtils } from '@ohos/ota/src/main/ets/util/VersionUtils'; import { NotificationHelper } from '@ohos/ota/src/main/ets/notify/NotificationHelper'; +import prompt from '@ohos.prompt'; +import RouterUtils from '@ohos/ota/src/main/ets/util/RouterUtils'; /** * 新版本页面 @@ -60,6 +62,7 @@ struct NewVersion { private dialogText: string | Resource = ''; @State private isInitComplete: boolean = false; private effectiveMode: update.EffectiveMode = update.EffectiveMode.COLD; + @State otaMode: update.OtaMode = update.OtaMode.AB_STREAM_OTA; private dialogType: CountDownDialogType = CountDownDialogType.OTA; @State private buttonText: string = ''; @StorageProp('installStatusRefresh') @Watch('refresh') @@ -172,12 +175,15 @@ struct NewVersion { } let stateButtonText = StateManager.getButtonText(this.updateStatus); this.buttonText = FormatUtils.toUpperCase(globalThis.abilityContext, stateButtonText); - this.isButtonVisible = this.updateStatus !== UpdateState.INSTALLING && - this.updateStatus !== UpdateState.INSTALL_FAILED && - (this.isABInstall() || this.updateStatus !== UpdateState.INSTALL_SUCCESS) && - this.updateStatus !== UpdateState.UPGRADING && - this.updateStatus !== UpdateState.UPGRADE_FAILED && - this.updateStatus !== UpdateState.UPGRADE_SUCCESS; + this.isButtonVisible = + this.updateStatus !== UpdateState.INSTALL_FAILED && + (this.isABInstall() || this.updateStatus !== UpdateState.INSTALL_SUCCESS) && + this.updateStatus !== UpdateState.UPGRADING && + this.updateStatus !== UpdateState.UPGRADE_FAILED && + this.updateStatus !== UpdateState.UPGRADE_SUCCESS && + (this.isABStreamInstall() || + (this.updateStatus !== UpdateState.INSTALL_PAUSE && + this.updateStatus !== UpdateState.INSTALLING)); } public async initNewVersionPageInfo(): Promise { @@ -197,6 +203,7 @@ struct NewVersion { this.dialogText = pageInfo?.countDownDialogInfo?.dialogText; this.dialogType = pageInfo?.countDownDialogInfo?.dialogType; this.effectiveMode = pageInfo?.effectiveMode; + this.otaMode = pageInfo?.otaMode; let size: number = 0; let array: ChangelogInfo[] = []; @@ -237,10 +244,18 @@ struct NewVersion { if (await NetUtils.isCellularNetwork()) { DialogHelper.displayNetworkDialog({ onConfirm: () => { - OtaUpdateManager.getInstance().download(update.NetType.CELLULAR); + if (this.isABStreamInstall()) { + this.upgrade(); + } else { + OtaUpdateManager.getInstance().download(update.NetType.CELLULAR); + } } }); } else { - OtaUpdateManager.getInstance().download(); + if (this.isABStreamInstall()) { + this.upgrade(); + } else { + OtaUpdateManager.getInstance().download(); + } } break; case UpdateAction.INSTALL: @@ -253,7 +268,11 @@ struct NewVersion { OtaUpdateManager.getInstance().cancel(); break; case UpdateAction.RESUME: - OtaUpdateManager.getInstance().resumeDownload(); + if (this.isABStreamInstall()) { + this.upgrade(); + } else { + OtaUpdateManager.getInstance().resumeDownload(); + } break; default: break; @@ -337,7 +356,11 @@ struct NewVersion { } private isABInstall(): boolean { - return this.effectiveMode === update.EffectiveMode.LIVE_AND_COLD; + return this.effectiveMode === update.EffectiveMode.LIVE_AND_COLD || this.isABStreamInstall(); + } + + private isABStreamInstall(): boolean { + return this.otaMode === update.OtaMode.AB_STREAM_OTA; } private refresh() {