From 3421274ecd068d525cc0ab8d2dae12a0608b9cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 21 Aug 2024 16:28:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5master=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=88=B05.0Release=20Signed-off-by:=20=E9=82=B9=E5=8F=8B?= =?UTF-8?q?=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AppScope/app.json5 | 4 +-- .../src/main/ets/manager/UpgradeInterface.ets | 5 ++++ .../src/main/ets/manager/OtaUpdateManager.ets | 2 +- .../ota/src/main/ets/manager/StateManager.ets | 19 ++++++++----- .../main/ets/notify/NotificationHelper.ets | 27 +++++++++++++++++++ 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/AppScope/app.json5 b/AppScope/app.json5 index 2d0b59c..f1d3926 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -3,8 +3,8 @@ "bundleName": "com.ohos.updateapp", "debug": false, "vendor": "example", - "versionCode": 2040000105, - "versionName": "204.0.0.105", + "versionCode": 2040000125, + "versionName": "204.0.0.125", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true diff --git a/common/src/main/ets/manager/UpgradeInterface.ets b/common/src/main/ets/manager/UpgradeInterface.ets index 4fd8ee7..66deb6d 100644 --- a/common/src/main/ets/manager/UpgradeInterface.ets +++ b/common/src/main/ets/manager/UpgradeInterface.ets @@ -196,5 +196,10 @@ export interface INotify { * 取消所有通知 */ cancelAll(): Promise; + + /** + * 检查notification服务是否启动 + */ + isServiceReady(): Promise; } diff --git a/feature/ota/src/main/ets/manager/OtaUpdateManager.ets b/feature/ota/src/main/ets/manager/OtaUpdateManager.ets index a176b45..6c9661e 100644 --- a/feature/ota/src/main/ets/manager/OtaUpdateManager.ets +++ b/feature/ota/src/main/ets/manager/OtaUpdateManager.ets @@ -373,7 +373,7 @@ export class OtaUpdateManager { return; } let eventInfo = this.wantParser(want); - this.log('handleWant:' + ' eventInfo is ${FormatUtils.stringify(eventInfo)}'); + this.log('handleWant: eventInfo is ' + FormatUtils.stringify(eventInfo)); if (!eventInfo?.eventId) { this.log('eventInfo?.eventId is null'); return; diff --git a/feature/ota/src/main/ets/manager/StateManager.ets b/feature/ota/src/main/ets/manager/StateManager.ets index ebdd7dd..260d6d4 100644 --- a/feature/ota/src/main/ets/manager/StateManager.ets +++ b/feature/ota/src/main/ets/manager/StateManager.ets @@ -528,6 +528,7 @@ export class InstallFailed extends BaseState { async notify(context?: common.Context): Promise { AppStorage.Set('installStatusRefresh', JSON.stringify(this.otaStatus)); + await UpgradeAdapter.getInstance().getNotifyInstance()?.isServiceReady(); await UpgradeAdapter.getInstance().getNotifyInstance()?.cancelAll(); if (VersionUtils.isInNewVersionPage()) { DialogUtils.showUpgradeFailDialog(context, this.otaStatus); @@ -577,12 +578,18 @@ export class UpgradeSuccess extends BaseState { this.isButtonClickable = false; } - async notify(context?: common.Context): Promise { - AppStorage.Set('installStatusRefresh', JSON.stringify(this.otaStatus)); - await UpgradeAdapter.getInstance().getNotifyInstance()?.cancelAll(); - let versionName = globalThis.lastVersionName; - LogUtils.log('StateManager', 'UpgradeSuccess versionName is ' + versionName); - await UpgradeAdapter.getInstance().getNotifyInstance()?.showUpgradeSuccess(versionName, context); + async notify(context?: common.Context, eventId?: update.EventId): Promise { + if (eventId == update.EventId.EVENT_UPGRADE_SUCCESS) { + LogUtils.info('StateManager', 'Upgrade success'); + AppStorage.Set('installStatusRefresh', JSON.stringify(this.otaStatus)); + await UpgradeAdapter.getInstance().getNotifyInstance()?.isServiceReady(); + await UpgradeAdapter.getInstance().getNotifyInstance()?.cancelAll(); + let versionName = globalThis.lastVersionName; + LogUtils.info('StateManager', 'UpgradeSuccess versionName is ' + versionName); + await UpgradeAdapter.getInstance().getNotifyInstance()?.showUpgradeSuccess(versionName, context); + } else { + LogUtils.error('StateManager', 'Upgrade EventId error'); + } } } diff --git a/feature/ota/src/main/ets/notify/NotificationHelper.ets b/feature/ota/src/main/ets/notify/NotificationHelper.ets index 6536f3d..cd8cd9f 100644 --- a/feature/ota/src/main/ets/notify/NotificationHelper.ets +++ b/feature/ota/src/main/ets/notify/NotificationHelper.ets @@ -205,6 +205,33 @@ export class NotificationHelper implements INotify { }); } + /** + * 检查notification服务是否启动 + */ + async isServiceReady(): Promise { + const retryTimes: number = 10; + let count: number = 0; + let isReady: boolean = false; + while (count < retryTimes) { + try { + await notification.isDistributedEnabled().then(() => { + this.logInfo('notification service is ready'); + isReady = true; + }); + if (isReady) { + break; + } + count++; + await new Promise((resolve) => setTimeout(() => resolve(), 1000)); + this.logError('notification service is not ready'); + } catch (err) { + count++; + this.logError('notification service throw abnormal'); + continue; + } + }; + } + /** * info级别日志打印 * -- Gitee