diff --git a/AppScope/app.json5 b/AppScope/app.json5 index e757ab92596872eefe3e1555d5d3487c3ea19066..5ea08d8f9f05b257ea6fa3cd88e10e4725ebbf02 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -3,8 +3,8 @@ "bundleName": "com.ohos.updateapp", "debug": false, "vendor": "example", - "versionCode": 2040000110, - "versionName": "204.0.0.110", + "versionCode": 2040000115, + "versionName": "204.0.0.115", "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 4fd8ee79105be197815a24ec0499e9c7b611e89b..f89f5a49ffb32812132e60819911f395c0124288 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/StateManager.ets b/feature/ota/src/main/ets/manager/StateManager.ets index 352c564c813eb7f0955e1188630ca877816bb674..260d6d4a1e802a0c9cf5078887a7ec9bcfcd7770 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); @@ -581,6 +582,7 @@ export class UpgradeSuccess extends BaseState { 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); diff --git a/feature/ota/src/main/ets/notify/NotificationHelper.ets b/feature/ota/src/main/ets/notify/NotificationHelper.ets index 6536f3dec044514888b82fb895baed5d5b1c87d2..1c948e2aaf928703b5795d33a11689af41f9741e 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级别日志打印 *