diff --git a/AppScope/app.json5 b/AppScope/app.json5 index 2d0b59c916b3c5a6c463c4cff3223587e61bae2e..f1d3926f82dddd05ab441156e2bebcdf7924d750 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 4fd8ee79105be197815a24ec0499e9c7b611e89b..66deb6d9706c2b488ca3596e55713f980f2cda92 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 a176b455e68a6a35d0471a339aa9a0a7c8fbf609..6c9661e5ab7209a7bd8ed74a5ff7a0a703d5d39f 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 ebdd7dda52481967739980cfa6dedb6e84703276..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); @@ -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 6536f3dec044514888b82fb895baed5d5b1c87d2..cd8cd9f820581dfd58245ec90b66655603abb3ee 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级别日志打印 *