1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @syscap SystemCapability.PowerManager.DisplayPowerManager 18 * @since 3 19 */ 20export interface BrightnessResponse { 21 /** 22 * Screen brightness, which ranges from 1 to 100. 23 * @since 3 24 */ 25 value: number; 26} 27 28/** 29 * @syscap SystemCapability.PowerManager.DisplayPowerManager 30 * @since 3 31 */ 32export interface GetBrightnessOptions { 33 /** 34 * Called when the current screen brightness is obtained. 35 * @since 3 36 */ 37 success?: (data: BrightnessResponse) => void; 38 39 /** 40 * Called when the current screen brightness fails to be obtained. 41 * @since 3 42 */ 43 fail?: (data: string, code: number) => void; 44 45 /** 46 * Called when the execution is completed. 47 * @since 3 48 */ 49 complete?: () => void; 50} 51 52/** 53 * @syscap SystemCapability.PowerManager.DisplayPowerManager 54 * @since 3 55 */ 56export interface SetBrightnessOptions { 57 /** 58 * Screen brightness. The value is an integer ranging from 1 to 100. 59 * If the value is less than or equal to 0, value 1 will be used. 60 * If the value is greater than 100, value 100 will be used. 61 * If the value contains decimals, the integral part of the value will be used. 62 * For example, if value is 8.1 is set, value 8 will be used. 63 * @since 3 64 */ 65 value: number; 66 67 /** 68 * Called when the setting is successful. 69 * @since 3 70 */ 71 success?: () => void; 72 73 /** 74 * Called when the setting fails. 75 * @since 3 76 */ 77 fail?: (data: string, code: number) => void; 78 79 /** 80 * Called when the execution is completed. 81 * @since 3 82 */ 83 complete?: () => void 84} 85 86/** 87 * @syscap SystemCapability.PowerManager.DisplayPowerManager 88 * @since 3 89 */ 90export interface BrightnessModeResponse { 91 /** 92 * The value can be 0 or 1. 93 * 0: The screen brightness is manually adjusted. 94 * 1: The screen brightness is automatically adjusted. 95 * @since 3 96 */ 97 mode: number; 98} 99 100/** 101 * @syscap SystemCapability.PowerManager.DisplayPowerManager 102 * @since 3 103 */ 104export interface GetBrightnessModeOptions { 105 /** 106 * Called when the screen brightness adjustment mode is obtained. 107 * @since 3 108 */ 109 success?: (data: BrightnessModeResponse) => void; 110 111 /** 112 * Called when the screen brightness adjustment mode fails to be obtained. 113 * @since 3 114 */ 115 fail?: (data: string, code: number) => void; 116 117 /** 118 * Called when the execution is completed. 119 * @since 3 120 */ 121 complete?: () => void; 122} 123 124/** 125 * @syscap SystemCapability.PowerManager.DisplayPowerManager 126 * @since 3 127 */ 128export interface SetBrightnessModeOptions { 129 /** 130 * The screen brightness mode. 131 * 0: The screen brightness is manually adjusted. 132 * 1: The screen brightness is automatically adjusted. 133 * @since 3 134 */ 135 mode: number; 136 137 /** 138 * Called when the setting is successful. 139 * @since 3 140 */ 141 success?: () => void; 142 143 /** 144 * Called when the setting fails. 145 * @since 3 146 */ 147 fail?: (data: string, code: number) => void; 148 149 /** 150 * Called when the execution is completed. 151 * @since 3 152 */ 153 complete?: () => void 154} 155 156/** 157 * @syscap SystemCapability.PowerManager.DisplayPowerManager 158 * @since 3 159 */ 160export interface SetKeepScreenOnOptions { 161 /** 162 * Whether to always keep the screen on. 163 * @since 3 164 */ 165 keepScreenOn: boolean; 166 167 /** 168 * Called when the setting is successful. 169 * @since 3 170 */ 171 success?: () => void; 172 173 /** 174 * Called when the setting fails. 175 * @since 3 176 */ 177 fail?: (data: string, code: number) => void; 178 179 /** 180 * Called when the execution is completed. 181 * @since 3 182 */ 183 complete?: () => void 184} 185 186/** 187 * @syscap SystemCapability.PowerManager.DisplayPowerManager 188 * @since 3 189 * @import brightness from '@system.brightness'; 190 */ 191export default class Brightness { 192 /** 193 * Obtains the current screen brightness. 194 * @param options Options. 195 * @since 3 196 */ 197 static getValue(options?: GetBrightnessOptions): void; 198 199 /** 200 * Sets the screen brightness. 201 * @param options Options. 202 * @since 3 203 */ 204 static setValue(options?: SetBrightnessOptions): void; 205 206 /** 207 * Obtains the screen brightness adjustment mode. 208 * @param options Options. 209 * @since 3 210 */ 211 static getMode(options?: GetBrightnessModeOptions): void; 212 213 /** 214 * Sets the screen brightness adjustment mode. 215 * @param options Options. 216 * @since 3 217 */ 218 static setMode(options?: SetBrightnessModeOptions): void; 219 220 /** 221 * Sets whether to always keey the screen on. 222 * @param options Options. 223 * @since 3 224 */ 225 static setKeepScreenOn(options?: SetKeepScreenOnOptions): void; 226}