From 3ce7789814c7a4450eafddebb7484c61c99931b4 Mon Sep 17 00:00:00 2001 From: zhangwenbo <1291179520@qq.com> Date: Tue, 2 Sep 2025 20:19:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9context=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwenbo <1291179520@qq.com> --- .../src/main/ets/default/brightnessManager.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts index ef66d3e8..916786b1 100644 --- a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts +++ b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts @@ -34,6 +34,8 @@ export class brightnessManager { context: Context; SLIDER_CHANG_MODE_MOVING = 1; private sliderChangeMode: number; + private RETRY: number = 0; + private MAX_RETRY: number = 60; constructor() { this.uri = Constants.getUriSync(Constants.KEY_BRIGHTNESS_STATUS); @@ -44,18 +46,23 @@ export class brightnessManager { async init(): Promise { Log.showInfo(TAG, 'init'); - this.createDataShare() + this.createDataShare(); Log.showInfo(TAG, `init helper ${this.helper}`); } public createDataShare() { - if (this.context == undefined || this.context == null) { - Log.showInfo(TAG, `constructor, this.context is null`); + if( this.RETRY > this.MAX_RETRY) { + Log.showError(TAG, `create context is null`); return; } - Log.showInfo(TAG, `createDataShare, this.context ${this.context}`); - const UPDATE_INTERVAL = 500; + this.RETRY = this.RETRY+1; + const UPDATE_INTERVAL = 1000; const timer = setInterval(() => { + if (this.context == undefined || this.context == null) { + Log.showInfo(TAG, `constructor, this.context is null`); + this.context = AbilityManager.getContext(AbilityManager.ABILITY_NAME_CONTROL_PANEL); + } + Log.showInfo(TAG, `createDataShare, this.context ${this.context}`); dataShare.createDataShareHelper(this.context, this.uri) .then((dataHelper) => { Log.showInfo(TAG, `createDataShareHelper success.`); @@ -65,6 +72,7 @@ export class brightnessManager { clearInterval(timer); }) .catch((err: BusinessError) => { + this.createDataShare() Log.showError(TAG, `createDataShare fail. ${JSON.stringify(err)}`); }); }, UPDATE_INTERVAL); -- Gitee From ce3191e8051dbc1ce0892d47ebfaec11d44be1a2 Mon Sep 17 00:00:00 2001 From: zhangwenbo <1291179520@qq.com> Date: Tue, 2 Sep 2025 21:13:08 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9context=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwenbo <1291179520@qq.com> --- .../src/main/ets/default/brightnessManager.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts index 916786b1..eb3a9e54 100644 --- a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts +++ b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts @@ -26,6 +26,7 @@ import Constants from "../../../../../../common/src/main/ets/default/Constants"; import createOrGet from '../../../../../../common/src/main/ets/default/SingleInstanceHelper'; const TAG = 'Control-brightnessManager'; +const UPDATE_INTERVAL = 1000; var mBrightnessValue = AppStorage.SetAndLink('BrightnessValue', 100); export class brightnessManager { @@ -34,7 +35,7 @@ export class brightnessManager { context: Context; SLIDER_CHANG_MODE_MOVING = 1; private sliderChangeMode: number; - private RETRY: number = 0; + private retry: number = 0; private MAX_RETRY: number = 60; constructor() { @@ -55,11 +56,11 @@ export class brightnessManager { Log.showError(TAG, `create context is null`); return; } - this.RETRY = this.RETRY+1; - const UPDATE_INTERVAL = 1000; + this.retry = this.retry + 1; + const timer = setInterval(() => { if (this.context == undefined || this.context == null) { - Log.showInfo(TAG, `constructor, this.context is null`); + Log.showInfo(TAG, `Exceeded the maxiretry of retries`); this.context = AbilityManager.getContext(AbilityManager.ABILITY_NAME_CONTROL_PANEL); } Log.showInfo(TAG, `createDataShare, this.context ${this.context}`); -- Gitee From 0f769e6f0cc01d41a1527e64a11f91e7b4bf9fd3 Mon Sep 17 00:00:00 2001 From: zhangwenbo <1291179520@qq.com> Date: Wed, 3 Sep 2025 20:31:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9context=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwenbo <1291179520@qq.com> --- .../src/main/ets/default/brightnessManager.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts index eb3a9e54..c73d67f7 100644 --- a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts +++ b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts @@ -62,6 +62,10 @@ export class brightnessManager { if (this.context == undefined || this.context == null) { Log.showInfo(TAG, `Exceeded the maxiretry of retries`); this.context = AbilityManager.getContext(AbilityManager.ABILITY_NAME_CONTROL_PANEL); + this.createDataShare(); + return; + } else { + clearInterval(timer); } Log.showInfo(TAG, `createDataShare, this.context ${this.context}`); dataShare.createDataShareHelper(this.context, this.uri) @@ -70,10 +74,8 @@ export class brightnessManager { this.helper = dataHelper; this.registerBrightness(); this.getValue(); - clearInterval(timer); }) .catch((err: BusinessError) => { - this.createDataShare() Log.showError(TAG, `createDataShare fail. ${JSON.stringify(err)}`); }); }, UPDATE_INTERVAL); -- Gitee From 95a2660bdab208f6a6bb4a7acde6385d2bfdc5ad Mon Sep 17 00:00:00 2001 From: zhangwenbo <1291179520@qq.com> Date: Wed, 3 Sep 2025 21:15:45 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9context=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwenbo <1291179520@qq.com> --- .../src/main/ets/default/brightnessManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts index c73d67f7..ae6bbed5 100644 --- a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts +++ b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts @@ -52,7 +52,7 @@ export class brightnessManager { } public createDataShare() { - if( this.RETRY > this.MAX_RETRY) { + if( this.retry > this.MAX_RETRY) { Log.showError(TAG, `create context is null`); return; } -- Gitee