1 /*
2 * Copyright (c) 2021-2024 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 #include "power_mode_module.h"
17
18 #ifdef HAS_DISPLAY_MANAGER
19 #include "display_power_mgr_client.h"
20 #endif
21 #include "power_log.h"
22 #include "power_mode_policy.h"
23 #include "power_mgr_service.h"
24 #include "setting_helper.h"
25
26 #include "singleton.h"
27
28 using namespace std;
29 using namespace OHOS;
30 using namespace OHOS::AAFwk;
31 using namespace OHOS::EventFwk;
32
33 namespace OHOS {
34 namespace PowerMgr {
35 namespace {
36 sptr<SettingObserver> g_autoAdjustBrightnessObserver;
37 sptr<SettingObserver> g_autoWindowRotationObserver;
38 sptr<SettingObserver> g_vibratorsStateObserver;
39 sptr<SettingObserver> g_intellVoiceObserver;
40 }
41
PowerModeModule()42 PowerModeModule::PowerModeModule()
43 : mode_(PowerMode::NORMAL_MODE), lastMode_(LAST_MODE_FLAG), started_(false)
44 {
45 POWER_HILOGI(FEATURE_POWER_MODE, "Instance create");
46 callbackMgr_ = new CallbackManager();
47 auto policy = DelayedSingleton<PowerModePolicy>::GetInstance();
48 PowerModePolicy::ModeAction displayOffTimeAction = [&](bool isInit) { SetDisplayOffTime(isInit); };
49 policy->AddAction(PowerModePolicy::ServiceType::DISPLAY_OFFTIME, displayOffTimeAction);
50 PowerModePolicy::ModeAction sleepTimeAction = [&](bool isInit) { SetSleepTime(isInit); };
51 policy->AddAction(PowerModePolicy::ServiceType::SLEEPTIME, sleepTimeAction);
52 PowerModePolicy::ModeAction autoAdjustBrightnessAction = [&](bool isInit) { SetAutoAdjustBrightness(isInit); };
53 policy->AddAction(PowerModePolicy::ServiceType::AUTO_ADJUST_BRIGHTNESS, autoAdjustBrightnessAction);
54 PowerModePolicy::ModeAction lcdBrightnessAction = [&](bool isInit) { SetLcdBrightness(isInit); };
55 policy->AddAction(PowerModePolicy::ServiceType::LCD_BRIGHTNESS, lcdBrightnessAction);
56 PowerModePolicy::ModeAction vibrationAction = [&](bool isInit) { SetVibration(isInit); };
57 policy->AddAction(PowerModePolicy::ServiceType::VIBRATORS_STATE, vibrationAction);
58 PowerModePolicy::ModeAction onOffRotationAction = [&](bool isInit) { SetWindowRotation(isInit); };
59 policy->AddAction(PowerModePolicy::ServiceType::AUTO_WINDOWN_RORATION, onOffRotationAction);
60 PowerModePolicy::ModeAction intellVoiceAction = [&](bool isInit) { SetIntellVoiceState(isInit); };
61 policy->AddAction(PowerModePolicy::ServiceType::INTELL_VOICE, intellVoiceAction);
62 }
63
InitPowerMode()64 void PowerModeModule::InitPowerMode()
65 {
66 POWER_HILOGI(FEATURE_POWER_MODE, "Start to init power mode.");
67 int32_t saveMode = SettingHelper::ReadCurrentMode(static_cast<int32_t>(this->mode_));
68 this->mode_ = static_cast<PowerMode>(saveMode);
69 Prepare();
70 if (!DelayedSingleton<PowerModePolicy>::GetInstance()->InitRecoverMap()) {
71 UpdateModepolicy();
72 RunAction(false);
73 }
74 }
75
SetModeItem(PowerMode mode)76 void PowerModeModule::SetModeItem(PowerMode mode)
77 {
78 POWER_HILOGI(FEATURE_POWER_MODE, "SetModeItem mode_: %{public}u, mode: %{public}u", mode_, mode);
79
80 /* Same as the previous mode */
81 if (this->mode_ == mode && this->mode_ != PowerMode::PERFORMANCE_MODE) {
82 return;
83 }
84
85 /* If it's a valid mode */
86 if (mode > PowerMode::EXTREME_POWER_SAVE_MODE && mode < PowerMode::POWER_MODE_MAX) {
87 POWER_HILOGW(FEATURE_POWER_MODE, "Invalid mode %{public}d", mode);
88 return;
89 }
90
91 /* If it's a valid mode */
92 if (mode < PowerMode::POWER_MODE_MIN || mode > PowerMode::POWER_MODE_MAX) {
93 POWER_HILOGW(FEATURE_POWER_MODE, "Invalid mode %{public}d", mode);
94 return;
95 }
96
97 /* unregister setting observer for current mode */
98 UnregisterSaveModeObserver();
99
100 /* start set mode thread */
101 EnableMode(mode);
102
103 /* register setting observer for save mode */
104 RegisterSaveModeObserver();
105 }
106
GetModeItem()107 PowerMode PowerModeModule::GetModeItem()
108 {
109 POWER_HILOGD(FEATURE_POWER_MODE, "GetModeItem mode_: %{public}u", mode_);
110 /* get power mode */
111 return mode_;
112 }
113
UnregisterSaveModeObserver()114 void PowerModeModule::UnregisterSaveModeObserver()
115 {
116 if (!this->observerRegisted_) {
117 POWER_HILOGD(FEATURE_POWER_MODE, "current power mode is normal mode");
118 return;
119 }
120
121 POWER_HILOGI(FEATURE_POWER_MODE, "unregister setting observer for save mode");
122 SettingHelper::UnregisterSettingObserver(g_autoAdjustBrightnessObserver);
123 SettingHelper::UnregisterSettingObserver(g_autoWindowRotationObserver);
124 SettingHelper::UnregisterSettingObserver(g_vibratorsStateObserver);
125 SettingHelper::UnregisterSettingObserver(g_intellVoiceObserver);
126 g_autoAdjustBrightnessObserver = nullptr;
127 g_autoWindowRotationObserver = nullptr;
128 g_vibratorsStateObserver = nullptr;
129 g_intellVoiceObserver = nullptr;
130 observerRegisted_ = false;
131 }
132
RegisterSaveModeObserver()133 void PowerModeModule::RegisterSaveModeObserver()
134 {
135 if (this->mode_ == PowerMode::POWER_SAVE_MODE || this->mode_ == PowerMode::EXTREME_POWER_SAVE_MODE) {
136 POWER_HILOGD(FEATURE_POWER_MODE, "register setting observer in save mode");
137 RegisterAutoAdjustBrightnessObserver();
138 RegisterAutoWindowRotationObserver();
139 RegisterVibrateStateObserver();
140 RegisterIntellVoiceObserver();
141 observerRegisted_ = true;
142 }
143 }
144
AutoAdjustBrightnessUpdateFunc()145 static void AutoAdjustBrightnessUpdateFunc()
146 {
147 auto policy = DelayedSingleton<PowerModePolicy>::GetInstance();
148 int32_t switchVal = policy->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::AUTO_ADJUST_BRIGHTNESS);
149 auto setVal = SettingHelper::GetSettingAutoAdjustBrightness(switchVal);
150 if (setVal == switchVal) {
151 return;
152 }
153 policy->RemoveBackupMapSettingSwitch(PowerModePolicy::ServiceType::AUTO_ADJUST_BRIGHTNESS);
154 }
155
RegisterAutoAdjustBrightnessObserver()156 void PowerModeModule::RegisterAutoAdjustBrightnessObserver()
157 {
158 if (g_autoAdjustBrightnessObserver) {
159 POWER_HILOGD(FEATURE_POWER_MODE, "auto adjust brightness observer already registed");
160 return;
161 }
162 SettingObserver::UpdateFunc updateFunc = [&](const std::string&) {
163 AutoAdjustBrightnessUpdateFunc();
164 };
165 g_autoAdjustBrightnessObserver = SettingHelper::RegisterSettingAutoAdjustBrightnessObserver(updateFunc);
166 }
167
WindowRotationUpdateFunc()168 static void WindowRotationUpdateFunc()
169 {
170 auto policy = DelayedSingleton<PowerModePolicy>::GetInstance();
171 int32_t switchVal = policy->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::AUTO_WINDOWN_RORATION);
172 auto setVal = SettingHelper::GetSettingWindowRotation(switchVal);
173 if (setVal == switchVal) {
174 return;
175 }
176 policy->RemoveBackupMapSettingSwitch(PowerModePolicy::ServiceType::AUTO_WINDOWN_RORATION);
177 }
178
RegisterAutoWindowRotationObserver()179 void PowerModeModule::RegisterAutoWindowRotationObserver()
180 {
181 if (g_autoWindowRotationObserver) {
182 POWER_HILOGD(FEATURE_POWER_MODE, "auto window rotation observer already registed");
183 return;
184 }
185 SettingObserver::UpdateFunc updateFunc = [&](const std::string&) {
186 WindowRotationUpdateFunc();
187 };
188 g_autoWindowRotationObserver = SettingHelper::RegisterSettingWindowRotationObserver(updateFunc);
189 }
190
VibrateStateUpdateFunc()191 static void VibrateStateUpdateFunc()
192 {
193 auto policy = DelayedSingleton<PowerModePolicy>::GetInstance();
194 int32_t switchVal = policy->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::VIBRATORS_STATE);
195 auto setVal = SettingHelper::GetSettingVibration(switchVal);
196 if (setVal == switchVal) {
197 return;
198 }
199 policy->RemoveBackupMapSettingSwitch(PowerModePolicy::ServiceType::VIBRATORS_STATE);
200 }
201
RegisterVibrateStateObserver()202 void PowerModeModule::RegisterVibrateStateObserver()
203 {
204 if (g_vibratorsStateObserver) {
205 POWER_HILOGD(FEATURE_POWER_MODE, "vibrate state observer already registed");
206 return;
207 }
208 SettingObserver::UpdateFunc updateFunc = [&](const std::string&) {
209 VibrateStateUpdateFunc();
210 };
211 g_vibratorsStateObserver = SettingHelper::RegisterSettingVibrationObserver(updateFunc);
212 }
213
IntellVoiceUpdateFunc()214 static void IntellVoiceUpdateFunc()
215 {
216 auto policy = DelayedSingleton<PowerModePolicy>::GetInstance();
217 int32_t switchVal = policy->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::INTELL_VOICE);
218 auto setVal = SettingHelper::GetSettingIntellVoice(switchVal);
219 if (setVal == switchVal) {
220 return;
221 }
222 policy->RemoveBackupMapSettingSwitch(PowerModePolicy::ServiceType::INTELL_VOICE);
223 }
224
RegisterIntellVoiceObserver()225 void PowerModeModule::RegisterIntellVoiceObserver()
226 {
227 if (g_intellVoiceObserver) {
228 POWER_HILOGD(FEATURE_POWER_MODE, "intell voice observer already registed");
229 return;
230 }
231 SettingObserver::UpdateFunc updateFunc = [&](const std::string&) {
232 IntellVoiceUpdateFunc();
233 };
234 g_intellVoiceObserver = SettingHelper::RegisterSettingIntellVoiceObserver(updateFunc);
235 }
236
EnableMode(PowerMode mode,bool isBoot)237 void PowerModeModule::EnableMode(PowerMode mode, bool isBoot)
238 {
239 if (started_) {
240 POWER_HILOGW(FEATURE_POWER_MODE, "Power Mode is already running");
241 return;
242 }
243
244 started_ = true;
245 mode_ = mode;
246
247 /* Update power mode policy */
248 UpdateModepolicy();
249
250 /* Send state change */
251 Prepare();
252
253 /* Set action */
254 RunAction(isBoot);
255
256 /* Save power mode status to setting data*/
257 SettingHelper::SaveCurrentMode(static_cast<int32_t>(mode));
258
259 this->lastMode_ = static_cast<uint32_t>(mode);
260 started_ = false;
261 }
262
UpdateModepolicy()263 void PowerModeModule::UpdateModepolicy()
264 {
265 /* update policy */
266 DelayedSingleton<PowerModePolicy>::GetInstance()->UpdatePowerModePolicy(static_cast<uint32_t>(this->mode_));
267 }
268
AddPowerModeCallback(const sptr<IPowerModeCallback> & callback)269 void PowerModeModule::AddPowerModeCallback(const sptr<IPowerModeCallback>& callback)
270 {
271 if (callbackMgr_) {
272 callbackMgr_->AddCallback(callback);
273 }
274 }
275
DelPowerModeCallback(const sptr<IPowerModeCallback> & callback)276 void PowerModeModule::DelPowerModeCallback(const sptr<IPowerModeCallback>& callback)
277 {
278 if (callbackMgr_) {
279 callbackMgr_->RemoveCallback(callback);
280 }
281 }
282
Prepare()283 void PowerModeModule::Prepare()
284 {
285 PublishPowerModeEvent();
286 if (callbackMgr_) {
287 callbackMgr_->WaitingCallback();
288 }
289 }
290
AddCallback(const sptr<IPowerModeCallback> & callback)291 void PowerModeModule::CallbackManager::AddCallback(const sptr<IPowerModeCallback>& callback)
292 {
293 unique_lock<mutex> lock(mutex_);
294 RETURN_IF((callback == nullptr) || (callback->AsObject() == nullptr));
295 auto object = callback->AsObject();
296 auto retIt = callbacks_.insert(object);
297 if (retIt.second) {
298 object->AddDeathRecipient(this);
299 }
300 AddCallbackPidUid(object);
301 POWER_HILOGD(FEATURE_POWER_MODE, "callbacks.size = %{public}zu, insertOk = %{public}d",
302 callbacks_.size(), retIt.second);
303 }
304
AddCallbackPidUid(const sptr<IRemoteObject> & callback)305 void PowerModeModule::CallbackManager::AddCallbackPidUid(const sptr<IRemoteObject>& callback)
306 {
307 pid_t pid = IPCSkeleton::GetCallingPid();
308 auto uid = IPCSkeleton::GetCallingUid();
309 cachedRegister_.emplace(callback, std::make_pair(pid, uid));
310 }
311
RemoveCallback(const sptr<IPowerModeCallback> & callback)312 void PowerModeModule::CallbackManager::RemoveCallback(const sptr<IPowerModeCallback>& callback)
313 {
314 unique_lock<mutex> lock(mutex_);
315 RETURN_IF((callback == nullptr) || (callback->AsObject() == nullptr));
316 auto object = callback->AsObject();
317 auto it = find(callbacks_.begin(), callbacks_.end(), object);
318 if (it != callbacks_.end()) {
319 callbacks_.erase(it);
320 object->RemoveDeathRecipient(this);
321 }
322 RemoveCallbackPidUid(object);
323 POWER_HILOGD(FEATURE_POWER_MODE, "callbacks.size = %{public}zu", callbacks_.size());
324 }
325
RemoveCallbackPidUid(const sptr<IRemoteObject> & callback)326 void PowerModeModule::CallbackManager::RemoveCallbackPidUid(const sptr<IRemoteObject>& callback)
327 {
328 auto iter = cachedRegister_.find(callback);
329 if (iter != cachedRegister_.end()) {
330 cachedRegister_.erase(iter);
331 }
332 }
333
OnRemoteDied(const wptr<IRemoteObject> & remote)334 void PowerModeModule::CallbackManager::OnRemoteDied(const wptr<IRemoteObject>& remote)
335 {
336 POWER_HILOGW(FEATURE_POWER_MODE, "On remote died");
337 RETURN_IF(remote.promote() == nullptr);
338 RemoveCallback(iface_cast<IPowerModeCallback>(remote.promote()));
339 }
340
FindCallbackPidUid(const sptr<IRemoteObject> & callback)341 std::pair<int32_t, int32_t> PowerModeModule::CallbackManager::FindCallbackPidUid(
342 const sptr<IRemoteObject>& callback)
343 {
344 auto iter = cachedRegister_.find(callback);
345 return (iter != cachedRegister_.end()) ? iter->second : std::make_pair(0, 0);
346 }
347
WaitingCallback()348 void PowerModeModule::CallbackManager::WaitingCallback()
349 {
350 POWER_HILOGD(FEATURE_POWER_MODE, "Mode callback started");
351 unique_lock<mutex> lock(mutex_);
352 for (auto& obj: callbacks_) {
353 auto pidUid = FindCallbackPidUid(obj);
354 sptr<IPowerModeCallback> callback = iface_cast<IPowerModeCallback>(obj);
355 if (callback != nullptr) {
356 // IPowerModeCallback calling pid uid
357 POWER_HILOGI(FEATURE_POWER_MODE, "IPMcbP=%{public}dU=%{public}d", pidUid.first, pidUid.second);
358 PowerMode mode = PowerMode::NORMAL_MODE;
359 callback->OnPowerModeChanged(mode);
360 }
361 }
362 }
363
PublishPowerModeEvent()364 void PowerModeModule::PublishPowerModeEvent()
365 {
366 POWER_HILOGD(FEATURE_POWER_MODE, "Publish power mode module event");
367 /* send event */
368 CommonEventPublishInfo publishInfo;
369 publishInfo.SetOrdered(false);
370 std::string action;
371 uint32_t code;
372 std::string data;
373 switch (mode_) {
374 case PowerMode::PERFORMANCE_MODE:
375 action = CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED;
376 code = static_cast<uint32_t>(PowerMode::PERFORMANCE_MODE);
377 data = ToString(static_cast<uint32_t>(PowerMode::PERFORMANCE_MODE));
378 break;
379 case PowerMode::NORMAL_MODE:
380 action = CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED;
381 code = static_cast<uint32_t>(PowerMode::NORMAL_MODE);
382 data = ToString(static_cast<uint32_t>(PowerMode::NORMAL_MODE));
383 break;
384 case PowerMode::POWER_SAVE_MODE:
385 action = CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED;
386 code = static_cast<uint32_t>(PowerMode::POWER_SAVE_MODE);
387 data = ToString(static_cast<uint32_t>(PowerMode::POWER_SAVE_MODE));
388 break;
389 case PowerMode::EXTREME_POWER_SAVE_MODE:
390 action = CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED;
391 code = static_cast<uint32_t>(PowerMode::EXTREME_POWER_SAVE_MODE);
392 data = ToString(static_cast<uint32_t>(PowerMode::EXTREME_POWER_SAVE_MODE));
393 break;
394 case PowerMode::CUSTOM_POWER_SAVE_MODE:
395 action = CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED;
396 code = static_cast<uint32_t>(PowerMode::CUSTOM_POWER_SAVE_MODE);
397 data = ToString(static_cast<uint32_t>(PowerMode::CUSTOM_POWER_SAVE_MODE));
398 break;
399 default:
400 POWER_HILOGW(FEATURE_POWER_MODE, "Unknown mode");
401 return;
402 }
403 IntentWant setModeWant;
404 setModeWant.SetAction(action);
405 CommonEventData event(setModeWant);
406 event.SetCode(code);
407 event.SetData(data);
408 if (!CommonEventManager::PublishCommonEvent(event, publishInfo, nullptr)) {
409 POWER_HILOGE(FEATURE_POWER_MODE, "Failed to publish the mode event");
410 return;
411 }
412 POWER_HILOGD(FEATURE_POWER_MODE, "Publish power mode module event end");
413 }
414
RunAction(bool isBoot)415 void PowerModeModule::RunAction(bool isBoot)
416 {
417 POWER_HILOGD(FEATURE_POWER_MODE, "Run action");
418 auto policy = DelayedSingleton<PowerModePolicy>::GetInstance();
419 policy->TriggerAllActions(isBoot);
420 }
421
SetDisplayOffTime(bool isBoot)422 void PowerModeModule::SetDisplayOffTime(bool isBoot)
423 {
424 if (isBoot && SettingHelper::IsDisplayOffTimeSettingValid()) {
425 return;
426 }
427 int32_t time = DelayedSingleton<PowerModePolicy>::GetInstance()
428 ->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::DISPLAY_OFFTIME);
429 if (time == INIT_VALUE_FALSE) {
430 return;
431 }
432 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
433 POWER_HILOGI(FEATURE_POWER_MODE, "Set default display off timeout: %{public}d", time);
434 bool needUpdateSetting = time > 0;
435 pms->GetPowerStateMachine()->SetDisplayOffTime(static_cast<int64_t>(time), needUpdateSetting);
436 }
437
SetSleepTime(bool isBoot)438 void PowerModeModule::SetSleepTime([[maybe_unused]] bool isBoot)
439 {
440 int32_t time = DelayedSingleton<PowerModePolicy>::GetInstance()
441 ->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::SLEEPTIME);
442 if (time == INIT_VALUE_FALSE) {
443 return;
444 }
445 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
446 POWER_HILOGD(FEATURE_POWER_MODE, "Set sleep timeout: %{public}d", time);
447 pms->GetPowerStateMachine()->SetSleepTime(static_cast<int64_t>(time));
448 }
449
SetAutoAdjustBrightness(bool isBoot)450 void PowerModeModule::SetAutoAdjustBrightness(bool isBoot)
451 {
452 if (isBoot && SettingHelper::IsAutoAdjustBrightnessSettingValid()) {
453 return;
454 }
455 int32_t value = DelayedSingleton<PowerModePolicy>::GetInstance()
456 ->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::AUTO_ADJUST_BRIGHTNESS);
457 auto status = static_cast<SettingHelper::SwitchStatus>(value);
458 POWER_HILOGD(FEATURE_POWER_MODE, "Set auto adjust brightness status: %{public}d", status);
459 if (value == INIT_VALUE_FALSE) {
460 return;
461 }
462 SettingHelper::SetSettingAutoAdjustBrightness(status);
463 }
464
SetLcdBrightness(bool isBoot)465 void PowerModeModule::SetLcdBrightness(bool isBoot)
466 {
467 if (isBoot && SettingHelper::IsBrightnessSettingValid()) {
468 return;
469 }
470 int32_t lcdBrightness = DelayedSingleton<PowerModePolicy>::GetInstance()
471 ->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::LCD_BRIGHTNESS);
472 POWER_HILOGD(FEATURE_POWER_MODE, "Set lcd Brightness: %{public}d", lcdBrightness);
473 if (lcdBrightness == INIT_VALUE_FALSE) {
474 return;
475 }
476 SettingHelper::SetSettingBrightness(lcdBrightness);
477 #ifdef HAS_DISPLAY_MANAGER
478 OHOS::DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().SetBrightness(lcdBrightness);
479 #endif
480 }
481
SetVibration(bool isBoot)482 void PowerModeModule::SetVibration(bool isBoot)
483 {
484 if (isBoot && SettingHelper::IsVibrationSettingValid()) {
485 return;
486 }
487 int32_t vibration = DelayedSingleton<PowerModePolicy>::GetInstance()
488 ->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::VIBRATORS_STATE);
489 POWER_HILOGI(FEATURE_POWER_MODE, "Set vibrate state %{public}d", vibration);
490 if (vibration == INIT_VALUE_FALSE) {
491 return;
492 }
493 SettingHelper::SetSettingVibration(static_cast<SettingHelper::SwitchStatus>(vibration));
494 }
495
SetWindowRotation(bool isBoot)496 void PowerModeModule::SetWindowRotation(bool isBoot)
497 {
498 if (isBoot && SettingHelper::IsWindowRotationSettingValid()) {
499 return;
500 }
501 int32_t rotation = DelayedSingleton<PowerModePolicy>::GetInstance()
502 ->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::AUTO_WINDOWN_RORATION);
503 POWER_HILOGD(FEATURE_POWER_MODE, "Set window rotation state %{public}d", rotation);
504 if (rotation == INIT_VALUE_FALSE) {
505 return;
506 }
507 SettingHelper::SetSettingWindowRotation(static_cast<SettingHelper::SwitchStatus>(rotation));
508 }
509
SetIntellVoiceState(bool isBoot)510 void PowerModeModule::SetIntellVoiceState(bool isBoot)
511 {
512 if (isBoot && SettingHelper::IsIntellVoiceSettingValid()) {
513 return;
514 }
515 int32_t state = DelayedSingleton<PowerModePolicy>::GetInstance()
516 ->GetPowerModeValuePolicy(PowerModePolicy::ServiceType::INTELL_VOICE);
517 POWER_HILOGD(FEATURE_POWER_MODE, "Set intell voice state %{public}d", state);
518 if (state == INIT_VALUE_FALSE) {
519 return;
520 }
521 SettingHelper::SetSettingIntellVoice(static_cast<SettingHelper::SwitchStatus>(state));
522 }
523 } // namespace PowerMgr
524 } // namespace OHOS
525