diff --git a/common/src/main/ets/util/FormatUtils.ts b/common/src/main/ets/util/FormatUtils.ts index cb46447d7a25004872521476c0fbeb9d68fee226..28ca9e05c2af3ee4e4c58ac5c8fdba0354157b70 100644 --- a/common/src/main/ets/util/FormatUtils.ts +++ b/common/src/main/ets/util/FormatUtils.ts @@ -15,6 +15,7 @@ import type common from '@ohos.app.ability.common'; import { DeviceUtils } from '../util/DeviceUtils'; +import { Logutils } from '../LogUtils'; /** * 格式化工具 @@ -100,4 +101,22 @@ export namespace FormatUtils { let numfmt: Intl.NumberFormat = new Intl.NumberFormat(language, {style:'percent', notation:'standard'}); return numfmt.format(num); } + + /** + * JSON stringify方法封装 + * + * @param value JS对象 + * @return json字符串 + */ + export function stringify(value: T): string { + if (value) { + try { + return JSON.stringify(value); + } catch (exception) { + Logutils.error('FormateUtils', 'JSON.stringify failed !!'); + return ''; + } + } + return; + } } \ No newline at end of file diff --git a/feature/ota/src/main/ets/dialog/CountDownInstallDialogBuilder.ets b/feature/ota/src/main/ets/dialog/CountDownInstallDialogBuilder.ets index 1602bc54639942f40804dd238eeab1f4033cbe62..e3c0b99c8ba78fd115861e319556b5385279c8e0 100644 --- a/feature/ota/src/main/ets/dialog/CountDownInstallDialogBuilder.ets +++ b/feature/ota/src/main/ets/dialog/CountDownInstallDialogBuilder.ets @@ -112,7 +112,7 @@ export struct CountDownInstallDialogBuilder { } this.confirm(); }) - .backgroundColor($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_dialog_bg_transparent')) .height($r('app.float.dialog_button_height')) .layoutWeight(1) .padding({ @@ -147,7 +147,7 @@ export struct CountDownInstallDialogBuilder { } this.cancel(); }) - .backgroundColor($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_dialog_bg_transparent')) .fontColor($r('app.color.blue')) .height($r('app.float.dialog_button_height')) .fontSize($r('app.float.text_size_btn')) diff --git a/feature/ota/src/main/ets/manager/OtaUpdateManager.ets b/feature/ota/src/main/ets/manager/OtaUpdateManager.ets index e617369a743469dc128c2ac70692f2e2bed4cc4c..cf5c08c332b9cba5baee9a27403496855fac8780 100644 --- a/feature/ota/src/main/ets/manager/OtaUpdateManager.ets +++ b/feature/ota/src/main/ets/manager/OtaUpdateManager.ets @@ -389,7 +389,7 @@ export class OtaUpdateManager { private wantParser(want: Want): update.EventInfo { let eventInfo: update.EventInfo; - let eventInfoStr = want.parameters[OtaUpdateManager.KEY]; + let eventInfoStr = want?.parameters?.[OtaUpdateManager.KEY]; if (typeof eventInfoStr === 'string') { eventInfo = JSON.parse(eventInfoStr); } diff --git a/product/oh/base/src/main/ets/ServiceExtAbility/service.ts b/product/oh/base/src/main/ets/ServiceExtAbility/service.ts index cc0fe000bc0cb47360e4c6ea11d24bcf66cea681..446ff3ccd3a8b2d97a3501d1a5f3715154cb68c7 100644 --- a/product/oh/base/src/main/ets/ServiceExtAbility/service.ts +++ b/product/oh/base/src/main/ets/ServiceExtAbility/service.ts @@ -16,6 +16,7 @@ import Extension from '@ohos.app.ability.ServiceExtensionAbility'; import type Want from '@ohos.app.ability.Want'; import type rpc from '@ohos.rpc'; +import { FormatUtils } from '@ohos/common/src/main/ets/util/FormatUtils'; import { OtaUpdateManager } from '@ohos/ota/src/main/ets/manager/OtaUpdateManager'; import { LogUtils } from '@ohos/common/src/main/ets/util/LogUtils'; @@ -30,12 +31,12 @@ export default class ServiceExtAbility extends Extension { private startIdArray: number[] = []; onCreate(want: Want): void { - LogUtils.log(ServiceExtAbility.TAG, 'onCreate:' + JSON.stringify(want)); + LogUtils.log(ServiceExtAbility.TAG, 'onCreate:' + FormatUtils.stringify(want)); globalThis.extensionContext = this.context; // when start ServiceExtAbility ,set context } async onRequest(want: Want, startId: number): Promise { - LogUtils.log(ServiceExtAbility.TAG, `onRequest, want: ${want.abilityName}`); + LogUtils.log(ServiceExtAbility.TAG, `onRequest, want: ${want?.abilityName}`); this.startIdArray.push(startId); globalThis.extensionContext = this.context; await OtaUpdateManager.getInstance().handleWant(want, globalThis.extensionContext); @@ -43,7 +44,7 @@ export default class ServiceExtAbility extends Extension { } onConnect(want: Want): rpc.RemoteObject { - LogUtils.log(ServiceExtAbility.TAG, `onConnect , want: ${want.abilityName}`); + LogUtils.log(ServiceExtAbility.TAG, `onConnect , want: ${want?.abilityName}`); return null; }