From 370a0d6711bbd3200767f8e3edc5c87e992c5815 Mon Sep 17 00:00:00 2001 From: liugang9704 <2745340733@qq.com> Date: Sun, 28 Sep 2025 19:13:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9C=AA=E6=8D=95=E8=8E=B7=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 8 +++- .../entry/src/main/ets/segment/segment6.ets | 9 +++- .../main/ets/entryability/EntryAbility.ets | 8 +++- .../main/ets/entryability/EntryAbility.ets | 8 +++- .../main/ets/entryability/EntryAbility.ets | 8 +++- .../src/main/ets/view/InTabComponent.ets | 7 ++- .../src/main/ets/view/SwitchTabComponent.ets | 7 ++- .../main/ets/entryability/EntryAbility.ets | 8 +++- .../entry/src/main/ets/segment/segment3.ets | 10 ++++- .../entry/src/main/ets/segment/segment4.ets | 11 +++-- .../entry/src/main/ets/segment/segment5.ets | 2 - .../main/ets/entryability/EntryAbility.ets | 8 +++- .../entry/src/main/ets/pages/Bluetooth.ets | 24 +++++++--- .../entry/src/main/ets/pages/Gps.ets | 22 ++++++++-- .../entry/src/main/ets/pages/Sensor.ets | 29 ++++++++---- .../src/main/ets/pages/music/AvPlayer.ets | 39 +++++++++++++--- BptaUseResources/entry/src/main/module.json5 | 44 ++++++++++++++++++- .../main/ets/entryability/EntryAbility.ets | 17 +++++-- .../entry/src/main/ets/pages/Audio.ets | 13 ++++-- .../src/main/ets/pages/LockByApplication.ets | 10 ++++- BptaUseSoftware/entry/src/main/module.json5 | 10 ++++- .../main/ets/entryability/EntryAbility.ets | 8 +++- .../entry/src/main/ets/pages/Index.ets | 35 +++++++++++++++ .../src/main/ets/pages/ParentCallPage.ets | 10 ++++- .../main/ets/entryability/EntryAbility.ets | 21 +++++---- .../main/ets/entryability/EntryAbility.ets | 28 ++++++++---- .../entry/src/main/ets/pages/PageOne.ets | 19 ++++++-- .../entry/src/main/ets/pages/PageThree.ets | 17 +++++-- .../entry/src/main/ets/pages/PageTwo.ets | 18 ++++++-- .../src/main/ets/utils/CameraServiceOne.ets | 22 +++++++--- .../src/main/ets/utils/CameraServiceThree.ets | 10 ++++- .../src/main/ets/utils/CameraServiceTwo.ets | 40 +++++++++++------ 32 files changed, 429 insertions(+), 101 deletions(-) diff --git a/ArkUI/Component_Nesting_Optimization/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUI/Component_Nesting_Optimization/entry/src/main/ets/entryability/EntryAbility.ets index 508880af..faef53f9 100644 --- a/ArkUI/Component_Nesting_Optimization/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ArkUI/Component_Nesting_Optimization/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,4 +1,5 @@ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit' import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -6,7 +7,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/ArkUI/Component_Nesting_Optimization/entry/src/main/ets/segment/segment6.ets b/ArkUI/Component_Nesting_Optimization/entry/src/main/ets/segment/segment6.ets index 6f51145b..86f22e9f 100644 --- a/ArkUI/Component_Nesting_Optimization/entry/src/main/ets/segment/segment6.ets +++ b/ArkUI/Component_Nesting_Optimization/entry/src/main/ets/segment/segment6.ets @@ -1,6 +1,7 @@ // [Start Case5] import { ColorMetrics } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Component struct ColorMeasure { @@ -18,7 +19,12 @@ struct ColorMeasure { getBlendColor(baseColor: ResourceColor, addColor: ResourceColor): ColorMetrics { if (!baseColor || !addColor) { - return ColorMetrics.resourceColor(Color.Black); + try { + return ColorMetrics.resourceColor(Color.Black); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`); + } } let sourceColor: ColorMetrics; try { @@ -48,4 +54,5 @@ struct ColorMetricsExample { } } } + // [End Case5] \ No newline at end of file diff --git a/ArkUI/Component_Redundancy_Refresh_Optimization/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUI/Component_Redundancy_Refresh_Optimization/entry/src/main/ets/entryability/EntryAbility.ets index 508880af..2880ca09 100644 --- a/ArkUI/Component_Redundancy_Refresh_Optimization/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ArkUI/Component_Redundancy_Refresh_Optimization/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,4 +1,5 @@ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -6,7 +7,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/ArkUI/Proper_Use_Layout/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUI/Proper_Use_Layout/entry/src/main/ets/entryability/EntryAbility.ets index 664be58f..5282cb6d 100644 --- a/ArkUI/Proper_Use_Layout/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ArkUI/Proper_Use_Layout/entry/src/main/ets/entryability/EntryAbility.ets @@ -14,6 +14,7 @@ */ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -21,7 +22,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/ArkUI/PureTabsExt/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUI/PureTabsExt/entry/src/main/ets/entryability/EntryAbility.ets index d3ee54d2..6e8ddad7 100644 --- a/ArkUI/PureTabsExt/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ArkUI/PureTabsExt/entry/src/main/ets/entryability/EntryAbility.ets @@ -14,6 +14,7 @@ */ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -21,7 +22,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/ArkUI/PureTabsExt/entry/src/main/ets/view/InTabComponent.ets b/ArkUI/PureTabsExt/entry/src/main/ets/view/InTabComponent.ets index 95476169..dc7f7154 100644 --- a/ArkUI/PureTabsExt/entry/src/main/ets/view/InTabComponent.ets +++ b/ArkUI/PureTabsExt/entry/src/main/ets/view/InTabComponent.ets @@ -13,6 +13,8 @@ * limitations under the License. */ import { AbilityConstant,Configuration } from "@kit.AbilityKit"; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from "@kit.PerformanceAnalysisKit"; // [Start tabs_bar_translate] @Component @@ -41,7 +43,10 @@ export default struct InTabComponent { await this.getUIContext().getHostContext()?.resourceManager.getStringArrayValue($r('app.strarray.in_tabs_items')) .then((strarray: string[]) => { this.tabItems = strarray; - }); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `getStringArrayValue failed, code=${err.code}, message=${err.message}`) + }) } subscribeSystemLanguageUpdate() { diff --git a/ArkUI/PureTabsExt/entry/src/main/ets/view/SwitchTabComponent.ets b/ArkUI/PureTabsExt/entry/src/main/ets/view/SwitchTabComponent.ets index 6cb12f14..31699074 100644 --- a/ArkUI/PureTabsExt/entry/src/main/ets/view/SwitchTabComponent.ets +++ b/ArkUI/PureTabsExt/entry/src/main/ets/view/SwitchTabComponent.ets @@ -13,6 +13,8 @@ * limitations under the License. */ import { AbilityConstant, Configuration } from "@kit.AbilityKit"; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from "@kit.PerformanceAnalysisKit"; // [Start custom_switch_tab] @Component @@ -34,7 +36,10 @@ export default struct SwitchTabComponent { .getHostContext()?.resourceManager.getStringArrayValue($r('app.strarray.switch_tabs_items')) .then((strarray: string[]) => { this.tabItems = strarray; - }); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `getStringArrayValue failed, code=${err.code}, message=${err.message}`) + }) } subscribeSystemLanguageUpdate() { diff --git a/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/entryability/EntryAbility.ets index 508880af..2880ca09 100644 --- a/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,4 +1,5 @@ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -6,7 +7,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment3.ets b/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment3.ets index e2a62dd9..21ead008 100644 --- a/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment3.ets +++ b/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment3.ets @@ -14,8 +14,9 @@ */ // [Start Counter_example2] -import { hiTraceMeter } from '@kit.PerformanceAnalysisKit'; +import { hilog, hiTraceMeter } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component @@ -26,7 +27,12 @@ struct Index { aboutToAppear(): void { hiTraceMeter.startTrace('getStringSync', 1); // The input parameter of the getStringSync interface uses the resource directly, without using the resource ID. - this.context.resourceManager.getStringSync($r('app.string.app_name')); + try { + this.context.resourceManager.getStringSync($r('app.string.app_name')); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `getStringSync failed, code=${err.code}, message=${err.message}`); + } hiTraceMeter.finishTrace('getStringSync', 1); } diff --git a/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment4.ets b/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment4.ets index 0cddea1f..39cba0d0 100644 --- a/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment4.ets +++ b/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment4.ets @@ -14,8 +14,9 @@ */ // [Start Case2] -import { hiTraceMeter } from '@kit.PerformanceAnalysisKit'; +import { hilog, hiTraceMeter } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component @@ -26,8 +27,12 @@ struct Index { aboutToAppear(): void { hiTraceMeter.startTrace('getStringSyncAfter', 2); // The input parameter of the getStringSync interface uses the resource ID. - - this.context.resourceManager.getStringSync($r('app.string.app_name').id); + try { + this.context.resourceManager.getStringSync($r('app.string.app_name').id); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `getStringSync failed, code=${err.code}, message=${err.message}`); + } hiTraceMeter.finishTrace('getStringSyncAfter', 2); } diff --git a/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment5.ets b/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment5.ets index 92e8154a..f5ca8fdc 100644 --- a/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment5.ets +++ b/ArkUI/UI_Component_Performance_Optimization/entry/src/main/ets/segment/segment5.ets @@ -41,8 +41,6 @@ const getUsers = () => { }); } - -@Entry @Component export struct AvatarGrid { @State users: User[] = getUsers(); diff --git a/BptaUseResources/entry/src/main/ets/entryability/EntryAbility.ets b/BptaUseResources/entry/src/main/ets/entryability/EntryAbility.ets index 508880af..69f8a2d6 100644 --- a/BptaUseResources/entry/src/main/ets/entryability/EntryAbility.ets +++ b/BptaUseResources/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,12 +1,18 @@ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/BptaUseResources/entry/src/main/ets/pages/Bluetooth.ets b/BptaUseResources/entry/src/main/ets/pages/Bluetooth.ets index 4ec6438c..06b44935 100644 --- a/BptaUseResources/entry/src/main/ets/pages/Bluetooth.ets +++ b/BptaUseResources/entry/src/main/ets/pages/Bluetooth.ets @@ -5,6 +5,8 @@ // [Start blue_tooth] import { UIAbility } from '@kit.AbilityKit'; import { ble } from '@kit.ConnectivityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; // [StartExclude blue_tooth] const scanFilter: ble.ScanFilter = {} @@ -20,15 +22,25 @@ const advResponse = undefined export default class EntryAbility extends UIAbility { // ... onForeground(): void { - //Initiate Ble scan and broadcast as required by the service at the foreground - ble.startBLEScan([scanFilter], scanOptions); - ble.startAdvertising(setting, advData, advResponse); + try { + //Initiate Ble scan and broadcast as required by the service at the foreground + ble.startBLEScan([scanFilter], scanOptions); + ble.startAdvertising(setting, advData, advResponse); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `startBLEScan or startAdvertising failed, code=${err.code}, message=${err.message}`); + } } onBackground(): void { - // Return to the background to stop the Ble scanning and broadcast, which is the same as the application - ble.stopBLEScan(); - ble.stopAdvertising(); + try { + // Return to the background to stop the Ble scanning and broadcast, which is the same as the application + ble.stopBLEScan(); + ble.stopAdvertising(); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `stopBLEScan or stopAdvertising failed, code=${err.code}, message=${err.message}`); + } } } // [End blue_tooth] \ No newline at end of file diff --git a/BptaUseResources/entry/src/main/ets/pages/Gps.ets b/BptaUseResources/entry/src/main/ets/pages/Gps.ets index b43d05d2..5d427bf5 100644 --- a/BptaUseResources/entry/src/main/ets/pages/Gps.ets +++ b/BptaUseResources/entry/src/main/ets/pages/Gps.ets @@ -5,11 +5,14 @@ // [Start gps_resources] import { UIAbility } from '@kit.AbilityKit'; import { geoLocationManager } from '@kit.LocationKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; // [StartExclude gps_resources] let locationChange = (location: geoLocationManager.Location): void => { console.log('locationChanger:data:' + JSON.stringify(location)); }; + // [EndExclude gps_resources] export default class EntryAbility extends UIAbility { @@ -25,13 +28,24 @@ export default class EntryAbility extends UIAbility { let locationChange = (location: geoLocationManager.Location): void => { console.log('locationChanger:data:' + JSON.stringify(location)); }; - //The change of the listening position - geoLocationManager.on('locationChange', requestInfo, locationChange); + try { + //The change of the listening position + geoLocationManager.on('locationChange', requestInfo, locationChange); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `geoLocationManager on failed, code=${err.code}, message=${err.message}`); + } } onBackground(): void { - //The backstage cancels the listening - geoLocationManager.off('locationChange', locationChange); + try { + //The backstage cancels the listening + geoLocationManager.off('locationChange', locationChange); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `geoLocationManager off failed, code=${err.code}, message=${err.message}`); + } } } + // [End gps_resources] \ No newline at end of file diff --git a/BptaUseResources/entry/src/main/ets/pages/Sensor.ets b/BptaUseResources/entry/src/main/ets/pages/Sensor.ets index 5c2a2b93..d0c2ce29 100644 --- a/BptaUseResources/entry/src/main/ets/pages/Sensor.ets +++ b/BptaUseResources/entry/src/main/ets/pages/Sensor.ets @@ -5,21 +5,34 @@ // [Start sensor_resources] import { UIAbility } from '@kit.AbilityKit'; import { sensor } from '@kit.SensorServiceKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export default class EntryAbility extends UIAbility { // ... onForeground(): void { - //In the foreground, listen to the required type of sensor based on the service requirements - sensor.on(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { - console.info("Succeededinobtainingdata.x:" + data.x + "y:" + data.y + "z:" + data.z); - }, { - interval: 100000000 - }); + try { + //In the foreground, listen to the required type of sensor based on the service requirements + sensor.on(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { + console.info("Succeeded in obtaining data.x:" + data.x + "y:" + data.y + "z:" + data.z); + }, { + interval: 100000000 + }); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `sensor on failed, code=${err.code}, message=${err.message}`); + } } onBackground(): void { - //The backstage cancels the listening - sensor.off(sensor.SensorId.ACCELEROMETER); + try { + //The backstage cancels the listening + sensor.off(sensor.SensorId.ACCELEROMETER); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `sensor off failed, code=${err.code}, message=${err.message}`); + } } } + // [End sensor_resources] \ No newline at end of file diff --git a/BptaUseResources/entry/src/main/ets/pages/music/AvPlayer.ets b/BptaUseResources/entry/src/main/ets/pages/music/AvPlayer.ets index d10caf3e..a7a93ff8 100644 --- a/BptaUseResources/entry/src/main/ets/pages/music/AvPlayer.ets +++ b/BptaUseResources/entry/src/main/ets/pages/music/AvPlayer.ets @@ -5,28 +5,38 @@ // [Start sound_pool] import { fileIo as fs } from '@kit.CoreFileKit'; import { media } from '@kit.MediaKit'; +import { BusinessError } from '@kit.BasicServicesKit'; // [End sound_pool] // [Start av_player] import { UIAbility } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; // [StartExclude av_player] let avPlayer: media.AVPlayer + // [EndExclude av_player] export default class EntryAbility extends UIAbility { // ... onForeground(): void { //Playing according to service requirements in the foreground - avPlayer.play(); + avPlayer.play() + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `avPlayer play failed, code=${err.code}, message=${err.message}`) + }) } onBackground(): void { // Return to the background to stop playing or pause - avPlayer.stop(); // Or pause(); + avPlayer.stop() // Or pause(); + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `avPlayer stop failed, code=${err.code}, message=${err.message}`) + }) } } + // [End av_player] /** @@ -45,10 +55,25 @@ const SoundPool = async () => { await fs.open('/test_01.mp3', fs.OpenMode.READ_ONLY).then((file: fs.File) => { console.info("filefd:" + file.fd); uri = 'fd://' + (file.fd).toString() - }); // '/test_01.mp3' is used as an example. The path of the file needs to be transferred - soundId = await soundPool.load(uri); - //The foreground scene starts to play - streamId = await soundPool.play(soundId); - //Stop playing in the background scenario: soundPool.stop (streamId); + }) // '/test_01.mp3' is used as an example. The path of the file needs to be transferred + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `avPlayer stop failed, code=${err.code}, message=${err.message}`); + }) + await soundPool.load(uri) + .then((soundId: number) => { + //The foreground scene starts to play + soundPool.play(soundId) + .then((data: number) => { + streamId = data; + hilog.info(0x000, 'testTag', 'setPreferredOrientation success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `soundPool play failed, code=${err.code}, message=${err.message}`); + }) + //Stop playing in the background scenario: soundPool.stop (streamId); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `soundPool load failed, code=${err.code}, message=${err.message}`); + }) } // [End sound_pool] diff --git a/BptaUseResources/entry/src/main/module.json5 b/BptaUseResources/entry/src/main/module.json5 index a1cea8b6..34457eca 100644 --- a/BptaUseResources/entry/src/main/module.json5 +++ b/BptaUseResources/entry/src/main/module.json5 @@ -45,7 +45,49 @@ "name": "ohos.extension.backup", "resource": "$profile:backup_config" } - ], + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_BLUETOOTH", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.ACCELEROMETER", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.INTERNET", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } } ] } diff --git a/BptaUseSoftware/entry/src/main/ets/entryability/EntryAbility.ets b/BptaUseSoftware/entry/src/main/ets/entryability/EntryAbility.ets index ea1bd688..2d0f5e06 100644 --- a/BptaUseSoftware/entry/src/main/ets/entryability/EntryAbility.ets +++ b/BptaUseSoftware/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,4 +1,5 @@ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -6,7 +7,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } @@ -24,8 +30,13 @@ export default class EntryAbility extends UIAbility { return; } hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext() - AppStorage.setOrCreate('uiContext', uiContext); + try { + let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext() + AppStorage.setOrCreate('uiContext', uiContext); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `getUIContext failed, code=${err.code}, message=${err.message}`); + } }); } diff --git a/BptaUseSoftware/entry/src/main/ets/pages/Audio.ets b/BptaUseSoftware/entry/src/main/ets/pages/Audio.ets index 926f51b2..78baa051 100644 --- a/BptaUseSoftware/entry/src/main/ets/pages/Audio.ets +++ b/BptaUseSoftware/entry/src/main/ets/pages/Audio.ets @@ -6,6 +6,8 @@ import { fileIo as fs } from '@kit.CoreFileKit'; // [StartExclude audio_bpta] import { audio } from '@kit.AudioKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; let audioStreamInfo: audio.AudioStreamInfo = { samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, @@ -43,8 +45,13 @@ async function read() { let path = context.filesDir; // Path of the file const filePath = path + '/voice_call_data.wav'; // Prohibit the file from being played silently - let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY); // Open the file - let buf = new ArrayBuffer(bufferSize); - let readSize: number = await fs.read(file.fd, buf); // Read the file content + try { + let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY); // Open the file + let buf = new ArrayBuffer(bufferSize); + let readSize: number = await fs.read(file.fd, buf); // Read the file content + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `openSync or read failed, code=${err.code}, message=${err.message}`); + } } // [End audio_bpta] \ No newline at end of file diff --git a/BptaUseSoftware/entry/src/main/ets/pages/LockByApplication.ets b/BptaUseSoftware/entry/src/main/ets/pages/LockByApplication.ets index 236f0d5b..05b2736b 100644 --- a/BptaUseSoftware/entry/src/main/ets/pages/LockByApplication.ets +++ b/BptaUseSoftware/entry/src/main/ets/pages/LockByApplication.ets @@ -4,12 +4,18 @@ */ // [Start bpta_lock_by_application] import { runningLock } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; // Return to the background to release the lock runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND) .then((lock: runningLock.RunningLock) => { - lock.unhold(); - console.info('create running lock and unlock success'); + try { + lock.unhold(); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } }) .catch((err: Error) => { console.error('create running lock failed, err: ' + err); diff --git a/BptaUseSoftware/entry/src/main/module.json5 b/BptaUseSoftware/entry/src/main/module.json5 index a1cea8b6..1da6fb56 100644 --- a/BptaUseSoftware/entry/src/main/module.json5 +++ b/BptaUseSoftware/entry/src/main/module.json5 @@ -45,7 +45,15 @@ "name": "ohos.extension.backup", "resource": "$profile:backup_config" } - ], + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.RUNNING_LOCK" + }, + { + "name": "ohos.permission.INTERNET" } ] } diff --git a/ComponentEncapsulation/entry/src/main/ets/entryability/EntryAbility.ets b/ComponentEncapsulation/entry/src/main/ets/entryability/EntryAbility.ets index 2dae1b50..89f547e6 100644 --- a/ComponentEncapsulation/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ComponentEncapsulation/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,6 +13,7 @@ * limitations under the License. */ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -20,7 +21,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/ComponentEncapsulation/entry/src/main/ets/pages/Index.ets b/ComponentEncapsulation/entry/src/main/ets/pages/Index.ets index 550bf16f..9730d0f2 100644 --- a/ComponentEncapsulation/entry/src/main/ets/pages/Index.ets +++ b/ComponentEncapsulation/entry/src/main/ets/pages/Index.ets @@ -1,3 +1,5 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; + /* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,6 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +import { BusinessError } from '@kit.BasicServicesKit'; + @Entry @Component struct Index { @@ -21,26 +26,56 @@ struct Index { .width(120).margin({ top: 16 }) .onClick(() => { this.getUIContext().getRouter().pushUrl({ url: 'pages/BuilderParamPage' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('ControllerCallPage') .width(120).margin({ top: 16 }) .onClick(() => { this.getUIContext().getRouter().pushUrl({ url: 'pages/ControllerCallPage' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('EmitterCallPage') .width(120).margin({ top: 16 }) .onClick(() => { this.getUIContext().getRouter().pushUrl({ url: 'pages/EmitterCallPage' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('ParentCallPage') .width(120).margin({ top: 16 }) .onClick(() => { this.getUIContext().getRouter().pushUrl({ url: 'pages/ParentCallPage' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('WatchCallPage') .width(120).margin({ top: 16 }) .onClick(() => { this.getUIContext().getRouter().pushUrl({ url: 'pages/WatchCallPage' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) } .height('100%') diff --git a/ComponentEncapsulation/entry/src/main/ets/pages/ParentCallPage.ets b/ComponentEncapsulation/entry/src/main/ets/pages/ParentCallPage.ets index c906ba05..2f5cc59d 100644 --- a/ComponentEncapsulation/entry/src/main/ets/pages/ParentCallPage.ets +++ b/ComponentEncapsulation/entry/src/main/ets/pages/ParentCallPage.ets @@ -13,6 +13,9 @@ * limitations under the License. */ // [Start parent_call] +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + @Component export struct ChildComponent { call = () => { @@ -32,7 +35,12 @@ export struct ChildComponent { @Component struct Index { parentAction() { - this.getUIContext().getPromptAction().showToast({ message: 'Parent Action' }) + try { + this.getUIContext().getPromptAction().showToast({ message: 'Parent Action' }); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`); + } } build() { diff --git a/CustomTitleBarWindowDrag/entry/src/main/ets/entryability/EntryAbility.ets b/CustomTitleBarWindowDrag/entry/src/main/ets/entryability/EntryAbility.ets index 77569cfe..1d430507 100644 --- a/CustomTitleBarWindowDrag/entry/src/main/ets/entryability/EntryAbility.ets +++ b/CustomTitleBarWindowDrag/entry/src/main/ets/entryability/EntryAbility.ets @@ -22,7 +22,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } @@ -42,8 +47,8 @@ export default class EntryAbility extends UIAbility { hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); }); - try { - windowStage.getMainWindow().then((mainWindow: window.Window) => { + windowStage.getMainWindow() + .then((mainWindow: window.Window) => { try { mainWindow.resize(500, 400).then(() => { console.info('Succeeded in changing the window size.'); @@ -54,11 +59,11 @@ export default class EntryAbility extends UIAbility { console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); } AppStorage.setOrCreate('mainWindow', mainWindow); - }); - } catch (exception) { - hilog.error(DOMAIN, 'testTag', 'Failed to set window system bar properties, Cause: %{public}s', - JSON.stringify(exception) ?? ''); - } + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `getMainWindow failed, code=${err.code}, message=${err.message}`); + }) + // cache the window manager into AppStorage AppStorage.setOrCreate('window', windowStage); } diff --git a/DealStrideSolution/entry/src/main/ets/entryability/EntryAbility.ets b/DealStrideSolution/entry/src/main/ets/entryability/EntryAbility.ets index dd56c05a..e27cc9f8 100644 --- a/DealStrideSolution/entry/src/main/ets/entryability/EntryAbility.ets +++ b/DealStrideSolution/entry/src/main/ets/entryability/EntryAbility.ets @@ -33,16 +33,26 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability Logger.info(TAG, 'Ability onWindowStageCreate'); - windowStage.getMainWindow().then((win: window.Window): void => { - win.setWindowLayoutFullScreen(true).then((): void => { - }); - win.setWindowSystemBarProperties({ - // Navigation bar color - navigationBarColor: '#F1F3F5', - // Status bar color - statusBarColor: '#F1F3F5' + windowStage.getMainWindow() + .then((win: window.Window): void => { + win.setWindowLayoutFullScreen(true).then((): void => { + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `setWindowLayoutFullScreen failed, code=${err.code}, message=${err.message}`); + }) + win.setWindowSystemBarProperties({ + // Navigation bar color + navigationBarColor: '#F1F3F5', + // Status bar color + statusBarColor: '#F1F3F5' + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `setWindowSystemBarProperties failed, code=${err.code}, message=${err.message}`); + }) + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `getMainWindow failed, code=${err.code}, message=${err.message}`); }) - }); windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { diff --git a/DealStrideSolution/entry/src/main/ets/pages/PageOne.ets b/DealStrideSolution/entry/src/main/ets/pages/PageOne.ets index a2145ff3..c50c265e 100644 --- a/DealStrideSolution/entry/src/main/ets/pages/PageOne.ets +++ b/DealStrideSolution/entry/src/main/ets/pages/PageOne.ets @@ -14,9 +14,10 @@ */ import { image } from '@kit.ImageKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import CameraService from '../utils/CameraServiceOne'; import { CommonConstants } from '../common/CommonConstants'; -import { promptAction } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Builder export function PageOneBuilder() { @@ -46,7 +47,7 @@ export struct PageOne { } @Builder - navDestinationTitleImg(res:Resource,fun:()=>void) { + navDestinationTitleImg(res: Resource, fun: () => void) { Image(res) .padding(8) .width(40) @@ -76,7 +77,12 @@ export struct PageOne { .layoutWeight(1) this.navDestinationTitleImg($r('app.media.more'), () => { - this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }) + try { + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }) + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`); + } }) } .width('100%') @@ -150,7 +156,12 @@ export struct PublishView { right: 18 }) .onClick(() => { - this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }); + try { + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`); + } }) } } \ No newline at end of file diff --git a/DealStrideSolution/entry/src/main/ets/pages/PageThree.ets b/DealStrideSolution/entry/src/main/ets/pages/PageThree.ets index 361dfdfb..4a00c647 100644 --- a/DealStrideSolution/entry/src/main/ets/pages/PageThree.ets +++ b/DealStrideSolution/entry/src/main/ets/pages/PageThree.ets @@ -14,9 +14,10 @@ */ import { image } from '@kit.ImageKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import CameraService from '../utils/CameraServiceThree'; import { CommonConstants } from '../common/CommonConstants'; -import { promptAction } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Builder export function PageThreeBuilder() { @@ -78,7 +79,12 @@ export struct PageThree { .layoutWeight(1) this.navDestinationTitleImg($r('app.media.more'), () => { - this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }) + try { + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }) + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`); + } }) } .width('100%') @@ -158,7 +164,12 @@ export struct PublishView { right: 18 }) .onClick(() => { - this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }); + try { + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`); + } }) } } \ No newline at end of file diff --git a/DealStrideSolution/entry/src/main/ets/pages/PageTwo.ets b/DealStrideSolution/entry/src/main/ets/pages/PageTwo.ets index 93c0fad3..c4ced48b 100644 --- a/DealStrideSolution/entry/src/main/ets/pages/PageTwo.ets +++ b/DealStrideSolution/entry/src/main/ets/pages/PageTwo.ets @@ -14,9 +14,10 @@ */ import { image } from '@kit.ImageKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import CameraService from '../utils/CameraServiceTwo'; import { CommonConstants } from '../common/CommonConstants'; -import { promptAction } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Builder export function PageTwoBuilder() { @@ -76,7 +77,12 @@ export struct PageTwo { .layoutWeight(1) this.navDestinationTitleImg($r('app.media.more'), () => { - this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }) + try { + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }) + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`); + } }) } .width('100%') @@ -150,7 +156,13 @@ export struct PublishView { right: 18 }) .onClick(() => { - this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }); + try { + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') }); + + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`); + } }) } } \ No newline at end of file diff --git a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceOne.ets b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceOne.ets index 31a240f9..69bf1df1 100644 --- a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceOne.ets +++ b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceOne.ets @@ -20,6 +20,7 @@ import { image } from '@kit.ImageKit'; import { JSON } from '@kit.ArkTS'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; import Logger from './Logger'; +import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'CameraService'; @@ -29,7 +30,8 @@ class CameraService { private cameraInput: camera.CameraInput | undefined = undefined; private previewOutput: camera.PreviewOutput | undefined = undefined; private session: camera.PhotoSession | camera.VideoSession | undefined = undefined; - handlePhotoAssetCb: (photoAsset: photoAccessHelper.PhotoAsset) => void = () => {}; + handlePhotoAssetCb: (photoAsset: photoAccessHelper.PhotoAsset) => void = () => { + }; private curCameraDevice: camera.CameraDevice | undefined = undefined; private receiver: image.ImageReceiver | undefined = undefined; frameStartFlag: number = 0; @@ -42,6 +44,7 @@ class CameraService { } }; surfaceId: string = ''; + // [Start Case1_start] onImageArrival(receiver: image.ImageReceiver): void { // [StartExclude Case1_start] @@ -70,7 +73,8 @@ class CameraService { // Positive example: Case 2.When width and stride are not equal, // At this time, the camera returned preview stream data component.byteBuffer to remove stride, // copy the new dstArr data, data processing to other do not support stride interface processing. - const dstBufferSize = width * height * 1.5; // Create a dstBufferSize space of width * height * 1.5. This is NV21 data format. + const dstBufferSize = width * height * + 1.5; // Create a dstBufferSize space of width * height * 1.5. This is NV21 data format. const dstArr = new Uint8Array(dstBufferSize); // Store the buffer after the stride is removed. // For each line of data read, the camera supports an even width and height profile, which does not involve rounding. for (let j = 0; j < height * 1.5; j++) { // Loop each row of dstArr data. @@ -94,6 +98,7 @@ class CameraService { }); }) } + // [End Case1_start] getPreviewProfile(cameraOutputCapability: camera.CameraOutputCapability): camera.Profile | undefined { @@ -118,7 +123,7 @@ class CameraService { * @param cameraDeviceIndex - Camera equipment index * @returns No return value */ - async initCamera(cameraDeviceIndex: number, uiContext:UIContext): Promise { + async initCamera(cameraDeviceIndex: number, uiContext: UIContext): Promise { Logger.debug(TAG, `initCamera cameraDeviceIndex: ${cameraDeviceIndex}`); try { await this.releaseCamera(); @@ -179,8 +184,13 @@ class CameraService { getPreviewRotation() { let previewRotation: camera.ImageRotation | undefined = camera.ImageRotation.ROTATION_0; - previewRotation = this.previewOutput?.getPreviewRotation(previewRotation); - AppStorage.set('previewRotation', previewRotation); + try { + previewRotation = this.previewOutput?.getPreviewRotation(previewRotation); + AppStorage.set('previewRotation', previewRotation); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } } /** @@ -220,7 +230,7 @@ class CameraService { /** * Get the Camera Manager instance */ - getCameraManagerFn(uiContext:UIContext): camera.CameraManager | undefined { + getCameraManagerFn(uiContext: UIContext): camera.CameraManager | undefined { if (this.cameraManager) { return this.cameraManager; } diff --git a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceThree.ets b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceThree.ets index 85035097..939c998e 100644 --- a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceThree.ets +++ b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceThree.ets @@ -20,6 +20,7 @@ import { image } from '@kit.ImageKit'; import { JSON } from '@kit.ArkTS'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; import Logger from './Logger'; +import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'CameraService'; @@ -155,8 +156,13 @@ class CameraService { getPreviewRotation() { let previewRotation: camera.ImageRotation | undefined = camera.ImageRotation.ROTATION_0; - previewRotation = this.previewOutput?.getPreviewRotation(previewRotation); - AppStorage.set('previewRotation', previewRotation) + try { + previewRotation = this.previewOutput?.getPreviewRotation(previewRotation); + AppStorage.set('previewRotation', previewRotation); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } } /** diff --git a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceTwo.ets b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceTwo.ets index 36a1fe34..13434fa1 100644 --- a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceTwo.ets +++ b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceTwo.ets @@ -20,6 +20,7 @@ import { image } from '@kit.ImageKit'; import { JSON } from '@kit.ArkTS'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; import Logger from './Logger'; +import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'CameraService'; @@ -29,7 +30,8 @@ class CameraService { private cameraInput: camera.CameraInput | undefined = undefined; private previewOutput: camera.PreviewOutput | undefined = undefined; private session: camera.PhotoSession | camera.VideoSession | undefined = undefined; - handlePhotoAssetCb: (photoAsset: photoAccessHelper.PhotoAsset) => void = () => {}; + handlePhotoAssetCb: (photoAsset: photoAccessHelper.PhotoAsset) => void = () => { + }; private curCameraDevice: camera.CameraDevice | undefined = undefined; private receiver: image.ImageReceiver | undefined = undefined; frameStartFlag: number = 0; @@ -42,6 +44,7 @@ class CameraService { } }; surfaceId: string = ''; + // [Start Case2_start] onImageArrival(receiver: image.ImageReceiver): void { receiver.on('imageArrival', () => { @@ -72,14 +75,19 @@ class CameraService { srcPixelFormat: 8, }) // 2. then call the cropSync method of PixelMap to crop out the excess pixels. - pixelMap.cropSync({ - size: { width: width, height: height }, - x: 0, - y: 0 - }) // Crop the image according to the size entered, starting with (0,0), crop the area of width*height bytes. - let pixelBefore: PixelMap | undefined = AppStorage.get('stridePixel'); - await pixelBefore?.release(); - AppStorage.setOrCreate('stridePixel', pixelMap); + try { + pixelMap.cropSync({ + size: { width: width, height: height }, + x: 0, + y: 0 + }) // Crop the image according to the size entered, starting with (0,0), crop the area of width*height bytes. + let pixelBefore: PixelMap | undefined = AppStorage.get('stridePixel'); + await pixelBefore?.release(); + AppStorage.setOrCreate('stridePixel', pixelMap); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } } nextImage.release(); }) @@ -87,6 +95,7 @@ class CameraService { }); }) } + // [End Case2_start] getPreviewProfile(cameraOutputCapability: camera.CameraOutputCapability): camera.Profile | undefined { @@ -111,7 +120,7 @@ class CameraService { * @param cameraDeviceIndex - Camera equipment index * @returns No return value */ - async initCamera(cameraDeviceIndex: number, uiContext:UIContext): Promise { + async initCamera(cameraDeviceIndex: number, uiContext: UIContext): Promise { Logger.debug(TAG, `initCamera cameraDeviceIndex: ${cameraDeviceIndex}`); try { await this.releaseCamera(); @@ -172,8 +181,13 @@ class CameraService { getPreviewRotation() { let previewRotation: camera.ImageRotation | undefined = camera.ImageRotation.ROTATION_0; - previewRotation = this.previewOutput?.getPreviewRotation(previewRotation); - AppStorage.set('previewRotation', previewRotation) + try { + previewRotation = this.previewOutput?.getPreviewRotation(previewRotation); + AppStorage.set('previewRotation', previewRotation); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } } /** @@ -213,7 +227,7 @@ class CameraService { /** * Get the Camera Manager instance */ - getCameraManagerFn(uiContext:UIContext): camera.CameraManager | undefined { + getCameraManagerFn(uiContext: UIContext): camera.CameraManager | undefined { if (this.cameraManager) { return this.cameraManager; } -- Gitee From 6be8dee132e725cebf51bef08b421abf4d32e941 Mon Sep 17 00:00:00 2001 From: liugang9704 <2745340733@qq.com> Date: Sun, 28 Sep 2025 19:21:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9C=AA=E6=8D=95=E8=8E=B7=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 8 ++- .../entry/src/main/ets/pages/MotionBlur.ets | 22 ++++-- .../entry/src/main/ets/pages/StaticBlur.ets | 34 ++++++--- .../main/ets/entryability/EntryAbility.ets | 8 ++- .../entry/src/main/ets/pages/Index.ets | 51 +++++++++++-- .../src/main/ets/pages/PullToRefreshError.ets | 13 +++- .../src/main/ets/pages/PullToRefreshRight.ets | 12 +++- .../main/ets/entryability/EntryAbility.ets | 19 +++-- .../entry/src/main/ets/mode/CameraService.ets | 39 +++++++--- .../entry/src/main/ets/pages/EditPage.ets | 37 +++++----- .../entry/src/main/ets/pages/IndexPage.ets | 18 ++++- .../entry/src/main/ets/pages/PhotoPage.ets | 17 ++++- .../main/ets/entryability/EntryAbility.ets | 7 +- .../entry/src/main/ets/pages/Index.ets | 71 +++++++++++-------- .../entry/src/main/ets/pages/Index.ets | 63 ++++++++++++++-- .../src/main/ets/pages/sample1/Sample1.ets | 22 ++++-- .../src/main/ets/pages/sample2/Sample2.ets | 22 ++++-- .../src/main/ets/pages/sample3/Sample3.ets | 31 ++++++-- .../src/main/ets/pages/sample4/Sample4.ets | 16 ++++- .../src/main/ets/pages/sample5/Sample5.ets | 26 +++++-- .../entry/src/main/ets/pages/test.ets | 6 +- 21 files changed, 416 insertions(+), 126 deletions(-) diff --git a/ExpandSafeArea/entry/src/main/ets/entryability/EntryAbility.ets b/ExpandSafeArea/entry/src/main/ets/entryability/EntryAbility.ets index d3ee54d2..6e8ddad7 100644 --- a/ExpandSafeArea/entry/src/main/ets/entryability/EntryAbility.ets +++ b/ExpandSafeArea/entry/src/main/ets/entryability/EntryAbility.ets @@ -14,6 +14,7 @@ */ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -21,7 +22,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/FuzzySceneOptimization/entry/src/main/ets/pages/MotionBlur.ets b/FuzzySceneOptimization/entry/src/main/ets/pages/MotionBlur.ets index 3fbd3f2b..a270a3ef 100644 --- a/FuzzySceneOptimization/entry/src/main/ets/pages/MotionBlur.ets +++ b/FuzzySceneOptimization/entry/src/main/ets/pages/MotionBlur.ets @@ -15,6 +15,8 @@ // [Start dynamic_start] import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Component export struct MotionBlur { @@ -27,10 +29,21 @@ export struct MotionBlur { if (err.code) { return; } - // get the height of the bottom navigation bar - this.bottomSafeHeight = - this.getUIContext().px2vp(windowBar.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height); - windowBar.setWindowLayoutFullScreen(true); + + try { + // get the height of the bottom navigation bar + this.bottomSafeHeight = + this.getUIContext() + .px2vp(windowBar.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `getWindowAvoidArea failed, code=${err.code}, message=${err.message}`); + } + windowBar.setWindowLayoutFullScreen(true) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `setWindowLayoutFullScreen failed, code=${err.code}, message=${err.message}`); + }) + }); } @@ -76,4 +89,5 @@ export struct MotionBlur { .hideTitleBar(true) } } + // [End dynamic_start] \ No newline at end of file diff --git a/FuzzySceneOptimization/entry/src/main/ets/pages/StaticBlur.ets b/FuzzySceneOptimization/entry/src/main/ets/pages/StaticBlur.ets index 39a2b8e0..ac8438a0 100644 --- a/FuzzySceneOptimization/entry/src/main/ets/pages/StaticBlur.ets +++ b/FuzzySceneOptimization/entry/src/main/ets/pages/StaticBlur.ets @@ -17,6 +17,8 @@ import { image } from '@kit.ImageKit'; import { effectKit } from '@kit.ArkGraphics2D'; import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Component export struct StaticBlur { @@ -31,19 +33,34 @@ export struct StaticBlur { if (err.code) { return; } - // get the height of the bottom navigation bar - this.bottomSafeHeight = - this.getUIContext().px2vp(windowBar.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height); - windowBar.setWindowLayoutFullScreen(true); + try { + // get the height of the bottom navigation bar + this.bottomSafeHeight = + this.getUIContext() + .px2vp(windowBar.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `getWindowAvoidArea failed, code=${err.code}, message=${err.message}`); + } + windowBar.setWindowLayoutFullScreen(true) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `setWindowLayoutFullScreen failed, code=${err.code}, message=${err.message}`); + }) }); } async staticBlur() { let context = this.getUIContext().getHostContext()!; let resourceMgr = context.resourceManager; // retrieve the resourceManager object - const fileData = await resourceMgr.getRawFileContent('test.png'); // retrieve images from the rawfile directory - let buffer: ArrayBuffer = fileData.buffer.slice(0); // create an ArrayBuffer instance - this.imgSource = image.createImageSource(buffer); // create an image source instance + // const fileData = await resourceMgr.getRawFileContent('test.png'); // retrieve images from the rawfile directory + await resourceMgr.getRawFileContent('test.png') // retrieve images from the rawfile directory + .then((fileData: Uint8Array) => { + let buffer: ArrayBuffer = fileData.buffer.slice(0); // create an ArrayBuffer instance + this.imgSource = image.createImageSource(buffer); // create an image source instance + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `getRawFileContent failed, code=${err.code}, message=${err.message}`); + }) // create attributes for pixels let opts: image.InitializationOptions = { editable: true, // is it editable @@ -55,7 +72,7 @@ export struct StaticBlur { } }; // create PixelMap - await this.imgSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => { + await this.imgSource!.createPixelMap(opts).then((pixelMap: image.PixelMap) => { const blurRadius = 3; let headFilter = effectKit.createEffect(pixelMap); // create Filter Instance if (headFilter !== null) { @@ -110,4 +127,5 @@ export struct StaticBlur { .hideTitleBar(true) } } + // [End static_start] \ No newline at end of file diff --git a/MaliangGPU/entry/src/main/ets/entryability/EntryAbility.ets b/MaliangGPU/entry/src/main/ets/entryability/EntryAbility.ets index 508880af..2880ca09 100644 --- a/MaliangGPU/entry/src/main/ets/entryability/EntryAbility.ets +++ b/MaliangGPU/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,4 +1,5 @@ import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; @@ -6,7 +7,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/ScreenFlickerSolution/entry/src/main/ets/pages/Index.ets b/ScreenFlickerSolution/entry/src/main/ets/pages/Index.ets index f16f8671..1eaa134e 100644 --- a/ScreenFlickerSolution/entry/src/main/ets/pages/Index.ets +++ b/ScreenFlickerSolution/entry/src/main/ets/pages/Index.ets @@ -13,7 +13,8 @@ * limitations under the License. */ -import { router } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit' @Entry @Component @@ -34,7 +35,13 @@ struct Index { .height(40) .fontWeight(FontWeight.Bold) .onClick(() => { - this.getUIContext().getRouter().pushUrl({ url: 'pages/ClickError' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/ClickError' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) .margin({ bottom: 12 }) @@ -44,7 +51,13 @@ struct Index { .height(40) .fontWeight(FontWeight.Bold) .onClick(() => { - this.getUIContext().getRouter().pushUrl({ url: 'pages/ClickRight' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/ClickRight' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) .margin({ bottom: 12 }) @@ -54,7 +67,13 @@ struct Index { .height(40) .fontWeight(FontWeight.Bold) .onClick(() => { - this.getUIContext().getRouter().pushUrl({ url: 'pages/TabsError' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/TabsError' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) .margin({ bottom: 12 }) @@ -64,7 +83,13 @@ struct Index { .height(40) .fontWeight(FontWeight.Bold) .onClick(() => { - this.getUIContext().getRouter().pushUrl({ url: 'pages/TabsRight' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/TabsRight' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) .margin({ bottom: 12 }) @@ -74,7 +99,13 @@ struct Index { .height(40) .fontWeight(FontWeight.Bold) .onClick(() => { - this.getUIContext().getRouter().pushUrl({ url: 'pages/PullToRefreshError' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/PullToRefreshError' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) .margin({ bottom: 12 }) @@ -84,7 +115,13 @@ struct Index { .height(40) .fontWeight(FontWeight.Bold) .onClick(() => { - this.getUIContext().getRouter().pushUrl({ url: 'pages/PullToRefreshRight' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/PullToRefreshRight' }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) .margin({ bottom: 12 }) } diff --git a/ScreenFlickerSolution/entry/src/main/ets/pages/PullToRefreshError.ets b/ScreenFlickerSolution/entry/src/main/ets/pages/PullToRefreshError.ets index 58b35d05..54318fb8 100644 --- a/ScreenFlickerSolution/entry/src/main/ets/pages/PullToRefreshError.ets +++ b/ScreenFlickerSolution/entry/src/main/ets/pages/PullToRefreshError.ets @@ -16,6 +16,8 @@ import util from '@ohos.util'; import { PullToRefresh, PullToRefreshConfigurator } from '@ohos/pulltorefresh/index'; import { common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component @@ -35,7 +37,6 @@ struct PullToRefreshError { @State loadText: ResourceStr = ''; private context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; - aboutToAppear() { const arrayModelMockData: Array = getNews('mockDataOne.json', this.context); this.newsData = arrayModelMockData; @@ -343,12 +344,18 @@ class JsonObject { // Get data getNewsData(context: common.UIAbilityContext): Array { // Get data from a local file - const value = context?.resourceManager.getRawFileContentSync(this.jsonFileDir); + let value: Uint8Array | null = null; + try { + value = context?.resourceManager.getRawFileContentSync(this.jsonFileDir); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } // Decode to utf-8 format const textDecoder = util.TextDecoder.create('utf-8', { ignoreBOM: true }); - const textDecoderResult = textDecoder.decodeToString(new Uint8Array(value.buffer)); + const textDecoderResult = textDecoder.decodeToString(new Uint8Array(value!.buffer)); const jsonObj: JsonObjType = JSON.parse(textDecoderResult) as JsonObjType; const newsModelBuckets: Array = []; // Map json data to NewsModel objects diff --git a/ScreenFlickerSolution/entry/src/main/ets/pages/PullToRefreshRight.ets b/ScreenFlickerSolution/entry/src/main/ets/pages/PullToRefreshRight.ets index 5a8dd207..95cd501e 100644 --- a/ScreenFlickerSolution/entry/src/main/ets/pages/PullToRefreshRight.ets +++ b/ScreenFlickerSolution/entry/src/main/ets/pages/PullToRefreshRight.ets @@ -16,6 +16,8 @@ import util from '@ohos.util'; import { PullToRefresh, PullToRefreshConfigurator } from '@ohos/pulltorefresh/index'; import { common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component @@ -342,12 +344,18 @@ class JsonObject { // Get data getNewsData(context: common.UIAbilityContext): Array { // Get data from a local file - const value = context?.resourceManager.getRawFileContentSync(this.jsonFileDir); + let value: Uint8Array | null = null; + try { + value = context?.resourceManager.getRawFileContentSync(this.jsonFileDir); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } // Decode to utf-8 format const textDecoder = util.TextDecoder.create('utf-8', { ignoreBOM: true }); - const textDecoderResult = textDecoder.decodeToString(new Uint8Array(value.buffer)); + const textDecoderResult = textDecoder.decodeToString(new Uint8Array(value!.buffer)); const jsonObj: JsonObjType = JSON.parse(textDecoderResult) as JsonObjType; const newsModelBuckets: Array = []; // Map json data to NewsModel objects diff --git a/SegmentedPhotograph/entry/src/main/ets/entryability/EntryAbility.ets b/SegmentedPhotograph/entry/src/main/ets/entryability/EntryAbility.ets index 02fd7f22..73463ff9 100644 --- a/SegmentedPhotograph/entry/src/main/ets/entryability/EntryAbility.ets +++ b/SegmentedPhotograph/entry/src/main/ets/entryability/EntryAbility.ets @@ -33,12 +33,19 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { Logger.info(TAG, 'Ability onWindowStageCreate'); - windowStage.getMainWindow().then((win: window.Window): void => { - if (!win) { - return; - } - win.setWindowLayoutFullScreen(true); - }); + windowStage.getMainWindow() + .then((win: window.Window): void => { + if (!win) { + return; + } + win.setWindowLayoutFullScreen(true) + .catch((err: BusinessError) => { + Logger.error(TAG, `Failed to setWindowLayoutFullScreen, code=${err.code}, message=${err.message}`) + }) + }) + .catch((err: BusinessError) => { + Logger.error(TAG, `Failed to getMainWindow, code=${err.code}, message=${err.message}`) + }) this.requestPermissionsFn(); windowStage.loadContent('pages/IndexPage', (err, data) => { if (err.code) { diff --git a/SegmentedPhotograph/entry/src/main/ets/mode/CameraService.ets b/SegmentedPhotograph/entry/src/main/ets/mode/CameraService.ets index bbd333ce..c1a948db 100644 --- a/SegmentedPhotograph/entry/src/main/ets/mode/CameraService.ets +++ b/SegmentedPhotograph/entry/src/main/ets/mode/CameraService.ets @@ -203,6 +203,7 @@ class CameraService { Logger.error(TAG, `initCamera fail: ${JSON.stringify(err)}`); } } + // [End init_camera] /** @@ -211,7 +212,12 @@ class CameraService { getZoomRatioRange(): Array { let zoomRatioRange: Array = []; if (this.session !== undefined) { - zoomRatioRange = this.session.getZoomRatioRange(); + try { + zoomRatioRange = this.session.getZoomRatioRange(); + } catch (error) { + let err = error as BusinessError; + Logger.warn('testTag', `getZoomRatioRange failed, code=${err.code}, message=${err.message}`); + } } return zoomRatioRange; } @@ -250,9 +256,15 @@ class CameraService { quality: camera.QualityLevel.QUALITY_LEVEL_HIGH, mirror: cameraDeviceIndex ? true : false }; - await this.photoOutput?.capture(photoSettings); - Logger.info(TAG, 'takePicture end'); + try { + await this.photoOutput?.capture(photoSettings); + Logger.info(TAG, 'takePicture end'); + } catch (error) { + let err = error as BusinessError; + Logger.warn('testTag', `capture failed, code=${err.code}, message=${err.message}`); + } } + // [End take_picture] /** @@ -364,6 +376,7 @@ class CameraService { return undefined; } } + // [End create_photo_outputFn] /** @@ -632,15 +645,19 @@ class CameraService { * Focus mode */ setFocusMode(focusMode: camera.FocusMode): void { - // Check whether the focus mode is supported - Logger.info(TAG, `setFocusMode is called`); - let isSupported = this.session?.isFocusModeSupported(focusMode); - Logger.info(TAG, `setFocusMode isSupported: ${isSupported}`); - // Setting the Focus Mode - if (!isSupported) { - return; + try { + // Check whether the focus mode is supported + let isSupported = this.session?.isFocusModeSupported(focusMode); + Logger.info(TAG, `setFocusMode isSupported: ${isSupported}`); + // Setting the Focus Mode + if (!isSupported) { + return; + } + this.session?.setFocusMode(focusMode); + } catch (error) { + let err = error as BusinessError; + Logger.warn('testTag', `isFocusModeSupported or setFocusMode failed, code=${err.code}, message=${err.message}`); } - this.session?.setFocusMode(focusMode); } } diff --git a/SegmentedPhotograph/entry/src/main/ets/pages/EditPage.ets b/SegmentedPhotograph/entry/src/main/ets/pages/EditPage.ets index 3cef80c2..879002da 100644 --- a/SegmentedPhotograph/entry/src/main/ets/pages/EditPage.ets +++ b/SegmentedPhotograph/entry/src/main/ets/pages/EditPage.ets @@ -53,23 +53,25 @@ struct EditPage { }; requestImage(requestImageParams: RequestImageParams): void { - try { - class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler { - onDataPrepared(data: ArrayBuffer, map: Map): void { - Logger.info(TAG, 'onDataPrepared map' + JSON.stringify(map)); - requestImageParams.callback(data); - Logger.info(TAG, 'onDataPrepared end'); - } - }; - let requestOptions: photoAccessHelper.RequestOptions = { - deliveryMode: photoAccessHelper.DeliveryMode.BALANCE_MODE, - }; - const handler = new MediaDataHandler(); - photoAccessHelper.MediaAssetManager.requestImageData(requestImageParams.context, requestImageParams.photoAsset, - requestOptions, handler); - } catch (error) { - Logger.error(TAG, `Failed in requestImage, error code: ${error.code}`); - } + class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler { + onDataPrepared(data: ArrayBuffer, map: Map): void { + Logger.info(TAG, 'onDataPrepared map' + JSON.stringify(map)); + requestImageParams.callback(data); + Logger.info(TAG, 'onDataPrepared end'); + } + }; + let requestOptions: photoAccessHelper.RequestOptions = { + deliveryMode: photoAccessHelper.DeliveryMode.BALANCE_MODE, + }; + const handler = new MediaDataHandler(); + photoAccessHelper.MediaAssetManager.requestImageData(requestImageParams.context, requestImageParams.photoAsset, + requestOptions, handler) + .then(() => { + Logger.info(TAG, 'requestImageData success'); + }) + .catch((err: BusinessError) => { + Logger.error(TAG, `requestImageData failed, code=${err.code}, message=${err.message}`) + }) } aboutToAppear() { @@ -88,6 +90,7 @@ struct EditPage { this.curPixelMap = GlobalContext.get().getT('photoAsset'); } } + // [End photo_buffer_callback] build() { diff --git a/SegmentedPhotograph/entry/src/main/ets/pages/IndexPage.ets b/SegmentedPhotograph/entry/src/main/ets/pages/IndexPage.ets index 05e054fe..d6649c9d 100644 --- a/SegmentedPhotograph/entry/src/main/ets/pages/IndexPage.ets +++ b/SegmentedPhotograph/entry/src/main/ets/pages/IndexPage.ets @@ -13,7 +13,9 @@ * limitations under the License. */ +import { BusinessError } from '@kit.BasicServicesKit'; import { Constants } from '../common/Constants'; +import Logger from '../common/utils/Logger'; @Entry @Component @@ -35,7 +37,13 @@ struct IndexPage { .height(42) .onClick(() => { AppStorage.setOrCreate('photoMode', Constants.SINGLE_STAGE_MODE); - this.getUIContext().getRouter().pushUrl({ url: 'pages/PhotoPage' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/PhotoPage' }) + .then(() => { + Logger.info('pushUrl success'); + }) + .catch((err: BusinessError) => { + Logger.error(`pushUrl failed, code=${err.code}, message=${err.message}`) + }) }) Button($r('app.string.segmented_photography')) .height(42) @@ -44,7 +52,13 @@ struct IndexPage { .width('100%') .onClick(() => { AppStorage.setOrCreate('photoMode', Constants.SUBSECTION_MODE); - this.getUIContext().getRouter().pushUrl({ url: 'pages/PhotoPage' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/PhotoPage' }) + .then(() => { + Logger.info('pushUrl success'); + }) + .catch((err: BusinessError) => { + Logger.error(`pushUrl failed, code=${err.code}, message=${err.message}`) + }) }) }.margin({ bottom: 46 }) diff --git a/SegmentedPhotograph/entry/src/main/ets/pages/PhotoPage.ets b/SegmentedPhotograph/entry/src/main/ets/pages/PhotoPage.ets index ea9988e7..e921bb14 100644 --- a/SegmentedPhotograph/entry/src/main/ets/pages/PhotoPage.ets +++ b/SegmentedPhotograph/entry/src/main/ets/pages/PhotoPage.ets @@ -20,6 +20,7 @@ import { GlobalContext } from '../common/utils/GlobalContext'; import { Constants } from '../common/Constants'; import { common } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; const TAG = 'PhotoPage'; @@ -55,7 +56,13 @@ struct PhotoPage { let SystemBarProperties: window.SystemBarProperties = { statusBarContentColor: '#ffffff', }; - this.windowClass.setWindowSystemBarProperties(SystemBarProperties); + this.windowClass.setWindowSystemBarProperties(SystemBarProperties) + .then(() => { + Logger.info('setWindowSystemBarProperties success'); + }) + .catch((err: BusinessError) => { + Logger.error(`setWindowSystemBarProperties failed, code=${err.code}, message=${err.message}`) + }) } catch (exception) { console.error(`Failed to obtain the window. Cause code: ${exception.code}, message: ${exception.message}`); } @@ -73,7 +80,13 @@ struct PhotoPage { let SystemBarProperties: window.SystemBarProperties = { statusBarContentColor: '#000000', }; - this.windowClass.setWindowSystemBarProperties(SystemBarProperties); + this.windowClass.setWindowSystemBarProperties(SystemBarProperties) + .then(() => { + Logger.info('setWindowSystemBarProperties success'); + }) + .catch((err: BusinessError) => { + Logger.error(`setWindowSystemBarProperties failed, code=${err.code}, message=${err.message}`) + }) await CameraService.releaseCamera(); } diff --git a/SubwindowAdaptWhenRotate/entry/src/main/ets/entryability/EntryAbility.ets b/SubwindowAdaptWhenRotate/entry/src/main/ets/entryability/EntryAbility.ets index a9999757..69709678 100644 --- a/SubwindowAdaptWhenRotate/entry/src/main/ets/entryability/EntryAbility.ets +++ b/SubwindowAdaptWhenRotate/entry/src/main/ets/entryability/EntryAbility.ets @@ -22,7 +22,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`); + } hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/SubwindowAdaptWhenRotate/entry/src/main/ets/pages/Index.ets b/SubwindowAdaptWhenRotate/entry/src/main/ets/pages/Index.ets index 709aa3bd..dd4c638a 100644 --- a/SubwindowAdaptWhenRotate/entry/src/main/ets/pages/Index.ets +++ b/SubwindowAdaptWhenRotate/entry/src/main/ets/pages/Index.ets @@ -47,34 +47,31 @@ struct Index { hilog.error(DOMAIN, TAG, 'subWindow is null'); return; } - let subwindowRect: window.Rect = this.subWindow.getWindowProperties().windowRect; - let newWidth: number = subwindowRect.height; - let newHeight: number = subwindowRect.width; - let newX: number = subwindowRect.top; - let newY: number = subwindowRect.left; + let subwindowRect: window.Rect | null = null; try { - let promise = this.subWindow.resize(newWidth, newHeight); - promise.then(() => { + subwindowRect = this.subWindow.getWindowProperties().windowRect; + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `getWindowProperties failed, code=${err.code}, message=${err.message}`); + } + let newWidth: number = subwindowRect!.height; + let newHeight: number = subwindowRect!.width; + let newX: number = subwindowRect!.top; + let newY: number = subwindowRect!.left; + this.subWindow.resize(newWidth, newHeight) + .then(() => { hilog.info(DOMAIN, TAG, 'Succeeded in changing the window size') }).catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, `Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); - }); - } catch (exception) { - hilog.error(DOMAIN, TAG, - `Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); - } + hilog.error(DOMAIN, TAG, `Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); + }); - try { - let promise = this.subWindow.moveWindowTo(newX, newY); - promise.then(() => { + this.subWindow.moveWindowTo(newX, newY) + .then(() => { hilog.info(DOMAIN, TAG, 'Succeeded in moving the window'); }).catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, `Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); - }); - } catch (exception) { - hilog.error(DOMAIN, TAG, - `Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); - } + hilog.error(DOMAIN, TAG, `Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); + }); + } // [StartExclude rotate_sample] @@ -89,13 +86,31 @@ struct Index { if (!this.mainWindow) { return; } - let mainWindowRect: window.Rect = this.mainWindow.getWindowProperties().windowRect; - let mainWindowWidth: number = mainWindowRect.width; - let mainWindowHeight: number = mainWindowRect.height; - this.subWindow.resize(mainWindowWidth - SUB_WINDOW_LEFT_OFFSET, mainWindowHeight - SUB_WINDOW_TOP_OFFSET); - this.subWindow.moveWindowTo(SUB_WINDOW_LEFT_OFFSET / 2, SUB_WINDOW_TOP_OFFSET / 2); + let mainWindowRect: window.Rect | null = null; + try { + mainWindowRect = this.mainWindow.getWindowProperties().windowRect; + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `getWindowProperties failed, code=${err.code}, message=${err.message}`); + } + + let mainWindowWidth: number = mainWindowRect!.width; + let mainWindowHeight: number = mainWindowRect!.height; + this.subWindow.resize(mainWindowWidth - SUB_WINDOW_LEFT_OFFSET, mainWindowHeight - SUB_WINDOW_TOP_OFFSET) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `resize failed, code=${err.code}, message=${err.message}`); + }) + this.subWindow.moveWindowTo(SUB_WINDOW_LEFT_OFFSET / 2, SUB_WINDOW_TOP_OFFSET / 2) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `moveWindowTo failed, code=${err.code}, message=${err.message}`); + }) this.subWindow.setUIContent('pages/Subwindow').then(() => { - this.subWindow?.setWindowBackgroundColor('#ff0000'); + try { + this.subWindow?.setWindowBackgroundColor('#ff0000'); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `setWindowBackgroundColor failed, code=${err.code}, message=${err.message}`); + } this.subWindow?.showWindow().then(() => { hilog.info(DOMAIN, TAG, 'Show subwindow success'); }).catch((error: BusinessError) => { diff --git a/TaskPoolPractice/entry/src/main/ets/pages/Index.ets b/TaskPoolPractice/entry/src/main/ets/pages/Index.ets index ee9df1ab..42aa01fe 100644 --- a/TaskPoolPractice/entry/src/main/ets/pages/Index.ets +++ b/TaskPoolPractice/entry/src/main/ets/pages/Index.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { router } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component @@ -28,42 +29,90 @@ struct Index { .height(40) .width('100%') .onClick(() => { - this.getUIContext().getRouter().pushUrl({url: "pages/sample1/Sample1"}) + this.getUIContext() + .getRouter() + .pushUrl({ url: "pages/sample1/Sample1" }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('Sample2') .height(40) .width('100%') .onClick(() => { - this.getUIContext().getRouter().pushUrl({url: "pages/sample2/Sample2"}) + this.getUIContext() + .getRouter() + .pushUrl({ url: "pages/sample2/Sample2" }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('Sample3') .height(40) .width('100%') .onClick(() => { - this.getUIContext().getRouter().pushUrl({url: "pages/sample3/Sample3"}) + this.getUIContext() + .getRouter() + .pushUrl({ url: "pages/sample3/Sample3" }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('Sample4') .height(40) .width('100%') .onClick(() => { - this.getUIContext().getRouter().pushUrl({url: "pages/sample4/Sample4"}) + this.getUIContext() + .getRouter() + .pushUrl({ url: "pages/sample4/Sample4" }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('Sample5') .height(40) .width('100%') .onClick(() => { - this.getUIContext().getRouter().pushUrl({url: "pages/sample5/Sample5"}) + this.getUIContext() + .getRouter() + .pushUrl({ url: "pages/sample5/Sample5" }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) Button('Sample6') .height(40) .width('100%') .onClick(() => { - this.getUIContext().getRouter().pushUrl({url: "pages/sample6/Sample6"}) + this.getUIContext() + .getRouter() + .pushUrl({ url: "pages/sample6/Sample6" }) + .then(() => { + hilog.info(0x000, 'testTag', 'pushUrl success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `pushUrl failed, code=${err.code}, message=${err.message}`); + }) }) } .height('100%') diff --git a/TaskPoolPractice/entry/src/main/ets/pages/sample1/Sample1.ets b/TaskPoolPractice/entry/src/main/ets/pages/sample1/Sample1.ets index de2e6263..adc915fe 100644 --- a/TaskPoolPractice/entry/src/main/ets/pages/sample1/Sample1.ets +++ b/TaskPoolPractice/entry/src/main/ets/pages/sample1/Sample1.ets @@ -1,11 +1,11 @@ - // [Start bar] // Sample1.ets import { Bar } from './wrong/a'; -import { BusinessError } from '@kit.BasicServicesKit'; +import { BusinessError } from '@ohos.base'; import { taskpool } from '@kit.ArkTS'; import { Foo } from './correct/b'; import { hilog } from '@kit.PerformanceAnalysisKit'; + // [End bar] // [Start wrong] @@ -19,6 +19,7 @@ function wrongConcurrentFunc() { hilog.error(0xFF00, 'sampleTag', 'error occur: ' + error.message); } } + // [End wrong] // [Start sample_fun] @@ -27,6 +28,7 @@ function wrongConcurrentFunc() { function correctConcurrentFunc() { let foo: Foo = new Foo; } + // [End sample_fun] @Entry @@ -44,7 +46,13 @@ struct Sample1 { .onClick(() => { // [Start task_pool] // Sample1.ets - taskpool.execute(wrongConcurrentFunc); + taskpool.execute(wrongConcurrentFunc) + .then(() => { + hilog.info(0x000, 'testTag', 'execute success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) // [End task_pool] }) @@ -54,7 +62,13 @@ struct Sample1 { .onClick(() => { // [Start correct_fun] // Sample1.ets - taskpool.execute(correctConcurrentFunc); + taskpool.execute(correctConcurrentFunc) + .then(() => { + hilog.info(0x000, 'testTag', 'execute success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) // [End correct_fun] }) } diff --git a/TaskPoolPractice/entry/src/main/ets/pages/sample2/Sample2.ets b/TaskPoolPractice/entry/src/main/ets/pages/sample2/Sample2.ets index 4d30e0f4..f28ef6d5 100644 --- a/TaskPoolPractice/entry/src/main/ets/pages/sample2/Sample2.ets +++ b/TaskPoolPractice/entry/src/main/ets/pages/sample2/Sample2.ets @@ -3,6 +3,7 @@ import { http } from '@kit.NetworkKit'; import { taskpool } from '@kit.ArkTS'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Concurrent function concurrentFunc() { @@ -15,6 +16,7 @@ function concurrentFunc() { hilog.info(0xFF00, 'sampleTag', 'No more data in response, data receive end'); }); } + // [End con_1] @Entry @@ -32,7 +34,13 @@ struct Sample2 { .onClick(() => { // [Start con_2] // Sample2.ets - taskpool.execute(concurrentFunc); + taskpool.execute(concurrentFunc) + .then(() => { + hilog.info(0x000, 'testTag', 'execute success'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) // [End con_2] }) @@ -43,10 +51,14 @@ struct Sample2 { // [Start task_1] // Sample2.ets let task: taskpool.LongTask = new taskpool.LongTask(concurrentFunc); - taskpool.execute(task).then(() => { - hilog.info(0xFF00, 'sampleTag', 'receive http msg success.'); - taskpool.terminateTask(task); - }) + taskpool.execute(task) + .then(() => { + hilog.info(0xFF00, 'sampleTag', 'receive http msg success.'); + taskpool.terminateTask(task); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) // [End task_1] }) } diff --git a/TaskPoolPractice/entry/src/main/ets/pages/sample3/Sample3.ets b/TaskPoolPractice/entry/src/main/ets/pages/sample3/Sample3.ets index 8e057f99..205bb6eb 100644 --- a/TaskPoolPractice/entry/src/main/ets/pages/sample3/Sample3.ets +++ b/TaskPoolPractice/entry/src/main/ets/pages/sample3/Sample3.ets @@ -1,5 +1,5 @@ import { taskpool } from '@kit.ArkTS'; -import { emitter } from '@kit.BasicServicesKit'; +import { BusinessError, emitter } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; // [Start wrong_1] @@ -8,9 +8,15 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; function wrongConcurrentFunc() { let promise = Promise.resolve(); promise.then(() => { - taskpool.Task.sendData(); + try { + taskpool.Task.sendData(); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `sendData failed, code=${err.code}, message=${err.message}`); + } }) } + // [End wrong_1] // [Start correct_fun_1] @@ -19,9 +25,10 @@ function wrongConcurrentFunc() { function correctConcurrentFunc() { let promise = Promise.resolve(); promise.then(() => { - emitter.emit("1", {data: {name: "anonymous"}}); + emitter.emit("1", { data: { name: "anonymous" } }); }) } + // [End correct_fun_1] @Entry @@ -43,7 +50,14 @@ struct Sample3 { task.onReceiveData(() => { hilog.info(0xFF00, 'sampleTag', "onReceiveData has been called"); }) - taskpool.execute(task); + taskpool.execute(task) + .then(() => { + hilog.info(0xFF00, 'sampleTag', 'receive http msg success.'); + taskpool.terminateTask(task); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) // [End task_pool_1] }) @@ -59,7 +73,14 @@ struct Sample3 { emitter.off("1") taskpool.terminateTask(task) }) - taskpool.execute(task); + taskpool.execute(task) + .then(() => { + hilog.info(0xFF00, 'sampleTag', 'receive http msg success.'); + taskpool.terminateTask(task); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) // [End task_7] }) } diff --git a/TaskPoolPractice/entry/src/main/ets/pages/sample4/Sample4.ets b/TaskPoolPractice/entry/src/main/ets/pages/sample4/Sample4.ets index 3afb2843..6a3b97e4 100644 --- a/TaskPoolPractice/entry/src/main/ets/pages/sample4/Sample4.ets +++ b/TaskPoolPractice/entry/src/main/ets/pages/sample4/Sample4.ets @@ -59,7 +59,13 @@ struct Sample4 { // [Start sample_5] // Sample4.ets let task: taskpool.Task = new taskpool.Task(correctConcurrentFunc); - taskpool.execute(task); + taskpool.execute(task) + .then(() => { + hilog.info(0xFF00, 'sampleTag', 'receive http msg success.'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) // [End sample_5] }) @@ -71,7 +77,13 @@ struct Sample4 { // Sample4.ets try { let foo = new Foo(); - taskpool.execute(correctConcurrentFunc1, foo); + taskpool.execute(correctConcurrentFunc1, foo) + .then(() => { + hilog.info(0xFF00, 'sampleTag', 'receive http msg success.'); + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) } catch (e) { let error: ErrorEvent = e; hilog.error(0xFF00, 'sampleTag', "error info: " + error.message); diff --git a/TaskPoolPractice/entry/src/main/ets/pages/sample5/Sample5.ets b/TaskPoolPractice/entry/src/main/ets/pages/sample5/Sample5.ets index 624635f8..3bf1642f 100644 --- a/TaskPoolPractice/entry/src/main/ets/pages/sample5/Sample5.ets +++ b/TaskPoolPractice/entry/src/main/ets/pages/sample5/Sample5.ets @@ -1,7 +1,8 @@ - // [Start pool_1] // Sample5.ets import { taskpool } from '@kit.ArkTS'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Concurrent function imageProcessing(dataSlice: ArrayBuffer): ArrayBuffer { @@ -17,14 +18,25 @@ function histogramStatistic(pixelBuffer: ArrayBuffer): void { let buffer3: ArrayBuffer = pixelBuffer.slice(number * 2); let group: taskpool.TaskGroup = new taskpool.TaskGroup(); - group.addTask(imageProcessing, buffer1); - group.addTask(imageProcessing, buffer2); - group.addTask(imageProcessing, buffer3); + try { + group.addTask(imageProcessing, buffer1); + group.addTask(imageProcessing, buffer2); + group.addTask(imageProcessing, buffer3); + } catch (error) { + let err = error as BusinessError; + hilog.warn(0x000, 'testTag', `addTask failed, code=${err.code}, message=${err.message}`); + } + + taskpool.execute(group, taskpool.Priority.HIGH) + .then((ret: Object) => { + // Step 3: Summarize the result array. + }) + .catch((err: BusinessError) => { + hilog.error(0x000, 'testTag', `execute failed, code=${err.code}, message=${err.message}`); + }) - taskpool.execute(group, taskpool.Priority.HIGH).then((ret: Object) => { - // Step 3: Summarize the result array. - }) } + // [End pool_1] @Entry diff --git a/TaskPoolPractice/entry/src/main/ets/pages/test.ets b/TaskPoolPractice/entry/src/main/ets/pages/test.ets index 8a9181f5..87ca9057 100644 --- a/TaskPoolPractice/entry/src/main/ets/pages/test.ets +++ b/TaskPoolPractice/entry/src/main/ets/pages/test.ets @@ -1,7 +1,7 @@ // [Start abc] -import { a } from './a' -import { b } from './b' -import { c } from './c' +import { a } from './a'; +import { b } from './b'; +import { c } from './c'; // [End abc] import { hilog } from '@kit.PerformanceAnalysisKit'; // [Start err] -- Gitee