diff --git a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts index ef66d3e8c0c2a3fb7f0e49649ae82005a503df2c..17527aee9433bc6dca98ef7b9b232ac813e8d795 100644 --- a/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts +++ b/features/brightnesscomponent/src/main/ets/default/brightnessManager.ts @@ -38,7 +38,7 @@ export class brightnessManager { constructor() { this.uri = Constants.getUriSync(Constants.KEY_BRIGHTNESS_STATUS); Log.showInfo(TAG, 'settings geturi of brightness is ' + Constants.URI_VAR); - this.context = AbilityManager.getContext(AbilityManager.ABILITY_NAME_CONTROL_PANEL); + this.context = AbilityManager.getContext(AbilityManager.getContextName(AbilityManager.ABILITY_NAME_CONTROL_PANEL)); this.init(); } @@ -49,25 +49,19 @@ export class brightnessManager { } public createDataShare() { - if (this.context == undefined || this.context == null) { - Log.showInfo(TAG, `constructor, this.context is null`); - return; + if (this.context == null || this.context == undefined) { + this.context = AbilityManager.getContext(AbilityManager.getContextName(AbilityManager.ABILITY_NAME_CONTROL_PANEL)); } - Log.showInfo(TAG, `createDataShare, this.context ${this.context}`); - const UPDATE_INTERVAL = 500; - const timer = setInterval(() => { dataShare.createDataShareHelper(this.context, this.uri) .then((dataHelper) => { Log.showInfo(TAG, `createDataShareHelper success.`); this.helper = dataHelper; this.registerBrightness(); this.getValue(); - clearInterval(timer); }) .catch((err: BusinessError) => { Log.showError(TAG, `createDataShare fail. ${JSON.stringify(err)}`); }); - }, UPDATE_INTERVAL); } registerBrightness() {