1 /*
2 * Copyright (c) 2023 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 #ifdef DEVICE_STANDBY_ENABLE
17 #include "work_standby_state_change_callback.h"
18 #include "work_sched_hilog.h"
19
20 namespace OHOS {
21 namespace WorkScheduler {
WorkStandbyStateChangeCallback(std::shared_ptr<WorkQueueManager> workQueueManager)22 WorkStandbyStateChangeCallback::WorkStandbyStateChangeCallback(std::shared_ptr<WorkQueueManager>
23 workQueueManager)
24 {
25 workQueueManager_ = workQueueManager;
26 }
27
OnDeviceIdleMode(bool napped,bool sleeping)28 void WorkStandbyStateChangeCallback::OnDeviceIdleMode(bool napped, bool sleeping)
29 {
30 WS_HILOGD("work_scheduler get OnDeviceIdleMode callback");
31 if (napped && !isSleep_) {
32 WS_HILOGD("device_standby state is nap, do not need process");
33 return;
34 }
35 WS_HILOGI("work_scheduler get OnDeviceIdleMode callback, sleeping is %{public}d", sleeping);
36 workQueueManager_->OnConditionChanged(WorkCondition::Type::STANDBY,
37 std::make_shared<DetectorValue>(0, 0, sleeping, std::string()));
38 isSleep_ = sleeping;
39 }
40
OnAllowListChanged(int32_t uid,const std::string & name,uint32_t allowType,bool added)41 void WorkStandbyStateChangeCallback::OnAllowListChanged(int32_t uid, const std::string& name,
42 uint32_t allowType, bool added)
43 {
44 WS_HILOGD("%{public}s apply allow, added type is %{public}d", name.c_str(), added);
45 if (!isSleep_) {
46 WS_HILOGD("current device_standby state is not sleep");
47 return;
48 }
49 workQueueManager_->OnConditionChanged(WorkCondition::Type::STANDBY,
50 std::make_shared<DetectorValue>(0, 0, isSleep_, std::string()));
51 }
52 } // namespace WorkScheduler
53 } // namespace OHOS
54 #endif