已合并
修改context #575
已合并
Zwb19991211创建于 2025年11月5日
1 个文件变更+20-27
@@ -35,7 +35,6 @@ export class brightnessManager {
35 context: Context;35 context: Context;
36 SLIDER_CHANG_MODE_MOVING = 1;36 SLIDER_CHANG_MODE_MOVING = 1;
37 private sliderChangeMode: number;37 private sliderChangeMode: number;
38- private timer: number = -1;
39 38 
40 constructor() {39 constructor() {
41 this.uri = Constants.getUriSync(Constants.KEY_BRIGHTNESS_STATUS);40 this.uri = Constants.getUriSync(Constants.KEY_BRIGHTNESS_STATUS);
@@ -51,37 +50,31 @@ export class brightnessManager {
51 }50 }
52 51 
53 public createDataShare(retryTimes: number) {52 public createDataShare(retryTimes: number) {
54- if (this.timer !== -1) {
55- clearTimeout(timer);
56- this.timer = -1;
57- }
58 Log.showInfo(TAG, `createDataShare, context ${this.context},retryTimes${retryTimes}`);53 Log.showInfo(TAG, `createDataShare, context ${this.context},retryTimes${retryTimes}`);
59- if (retryTimes < 0) {54+ if (retryTimes <= 0) {
60 Log.showError(TAG, `reached maximum retry attempts`);55 Log.showError(TAG, `reached maximum retry attempts`);
61 return;56 return;
62 }57 }
63 retryTimes = retryTimes - 1;58 retryTimes = retryTimes - 1;
64- this.timer = setTimeout(() => {59+ if (this.context == undefined || this.context == null) {
65- if (this.context == undefined || this.context == null) {60+ Log.showInfo(TAG, `constructor, context is null`);
66- Log.showInfo(TAG, `constructor, context is null`);61+ this.context =
67- this.context =62+ AbilityManager.getContext(AbilityManager.getContextName(AbilityManager.ABILITY_NAME_CONTROL_PANEL));
68- AbilityManager.getContext(AbilityManager.getContextName(AbilityManager.ABILITY_NAME_CONTROL_PANEL));63+ }
69- this.createDataShare(retryTimes);64+ Log.showInfo(TAG, `constructor, this.context ${this.context}`);
70- } else {65+ dataShare.createDataShareHelper(this.context, this.uri)
71- Log.showInfo(TAG, `constructor, this.context ${this.context}`);66+ .then((dataHelper) => {
72- dataShare.createDataShareHelper(this.context, this.uri)67+ Log.showInfo(TAG, `createDataShareHelper success.`);
73- .then((dataHelper) => {68+ this.helper = dataHelper;
74- Log.showInfo(TAG, `createDataShareHelper success.`);69+ this.registerBrightness();
75- this.helper = dataHelper;70+ this.getValue();
76- this.registerBrightness();71+ })
77- this.getValue();72+ .catch((err: BusinessError) => {
78- })73+ Log.showError(TAG, `createDataShare fail. ${JSON.stringify(err)}`);
79- .catch((err: BusinessError) => {74+ setTimeout(() => {
80- Log.showError(TAG, `createDataShare fail. ${JSON.stringify(err)}`);75+ this.createDataShare(retryTimes);
81- this.createDataShare(retryTimes);76+ }, UPDATE_INTERVAL);
82- });77+ });
83- }
84- }, UPDATE_INTERVAL);
85 }78 }
86 79 
87 registerBrightness() {80 registerBrightness() {