From 8fe602936ecd9819c3709fcdad8b93c100e403f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Mon, 19 Aug 2024 06:33:45 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=91=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=B6=88=E6=81=AF=E6=97=B6=E6=9C=8D=E5=8A=A1=E8=BF=98?= =?UTF-8?q?=E6=9C=AA=E5=90=AF=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- AppScope/app.json5 | 4 ++-- .../src/main/ets/manager/UpgradeInterface.ets | 5 +++++ .../ota/src/main/ets/manager/StateManager.ets | 2 ++ .../main/ets/notify/NotificationHelper.ets | 20 +++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/AppScope/app.json5 b/AppScope/app.json5 index e757ab9..5ea08d8 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 4fd8ee7..f89f5a4 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 352c564..b9cd1c9 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 6536f3d..38501ac 100644 --- a/feature/ota/src/main/ets/notify/NotificationHelper.ets +++ b/feature/ota/src/main/ets/notify/NotificationHelper.ets @@ -205,6 +205,26 @@ export class NotificationHelper implements INotify { }); } + /** + * 检查notification服务是否启动 + */ + async isServiceReady(): Promise { + const retryTimes: number = 10; + let count: number = 0; + while (count < retryTimes) { + let isReady = false; + await notification.isDistributedEnabled().then(() => { + this.logInfo('notification service is ready'); + isReady = true; + }); + if (isReady) { + break; + } + count++; + await new Promise((resolve)) => setTimeout(() => resolve(), 1000)); + } + } + /** * info级别日志打印 * -- Gitee From 853e438f5d2550dfe7580e5673a452384550af25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Mon, 19 Aug 2024 06:44:58 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- feature/ota/src/main/ets/manager/StateManager.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feature/ota/src/main/ets/manager/StateManager.ets b/feature/ota/src/main/ets/manager/StateManager.ets index b9cd1c9..260d6d4 100644 --- a/feature/ota/src/main/ets/manager/StateManager.ets +++ b/feature/ota/src/main/ets/manager/StateManager.ets @@ -528,7 +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()?.isServiceReady(); await UpgradeAdapter.getInstance().getNotifyInstance()?.cancelAll(); if (VersionUtils.isInNewVersionPage()) { DialogUtils.showUpgradeFailDialog(context, this.otaStatus); @@ -582,7 +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()?.isServiceReady(); await UpgradeAdapter.getInstance().getNotifyInstance()?.cancelAll(); let versionName = globalThis.lastVersionName; LogUtils.info('StateManager', 'UpgradeSuccess versionName is ' + versionName); -- Gitee From 58a76d262a1eb3398d734a815804268cb481d790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Mon, 19 Aug 2024 06:48:34 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- feature/ota/src/main/ets/notify/NotificationHelper.ets | 1 + 1 file changed, 1 insertion(+) diff --git a/feature/ota/src/main/ets/notify/NotificationHelper.ets b/feature/ota/src/main/ets/notify/NotificationHelper.ets index 38501ac..414b827 100644 --- a/feature/ota/src/main/ets/notify/NotificationHelper.ets +++ b/feature/ota/src/main/ets/notify/NotificationHelper.ets @@ -222,6 +222,7 @@ export class NotificationHelper implements INotify { } count++; await new Promise((resolve)) => setTimeout(() => resolve(), 1000)); + this.logError('notification service is not ready'); } } -- Gitee From e89f54479bd4f5009033fa0816dee9bddc2dcf04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Mon, 19 Aug 2024 07:46:56 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- .../main/ets/notify/NotificationHelper.ets | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/feature/ota/src/main/ets/notify/NotificationHelper.ets b/feature/ota/src/main/ets/notify/NotificationHelper.ets index 414b827..648e1e2 100644 --- a/feature/ota/src/main/ets/notify/NotificationHelper.ets +++ b/feature/ota/src/main/ets/notify/NotificationHelper.ets @@ -211,19 +211,24 @@ export class NotificationHelper implements INotify { async isServiceReady(): Promise { const retryTimes: number = 10; let count: number = 0; + let isReady: boolean = false; while (count < retryTimes) { - let isReady = false; - await notification.isDistributedEnabled().then(() => { - this.logInfo('notification service is ready'); - isReady = true; - }); - if (isReady) { - break; + 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++; + continue; } - count++; - await new Promise((resolve)) => setTimeout(() => resolve(), 1000)); - this.logError('notification service is not ready'); - } + }; } /** -- Gitee From e7f3ce23223aef75181c458bb6981dc449f77d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Mon, 19 Aug 2024 08:31:02 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- feature/ota/src/main/ets/notify/NotificationHelper.ets | 1 + 1 file changed, 1 insertion(+) diff --git a/feature/ota/src/main/ets/notify/NotificationHelper.ets b/feature/ota/src/main/ets/notify/NotificationHelper.ets index 648e1e2..1c948e2 100644 --- a/feature/ota/src/main/ets/notify/NotificationHelper.ets +++ b/feature/ota/src/main/ets/notify/NotificationHelper.ets @@ -226,6 +226,7 @@ export class NotificationHelper implements INotify { this.logError('notification service is not ready'); } catch (err) { count++; + this.logError('notification service throw abnormal'); continue; } }; -- Gitee