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 #ifdef DEVICE_USAGE_STATISTICS_ENABLE
17 #include "work_bundle_group_change_callback.h"
18 #include "work_sched_hilog.h"
19
20 namespace OHOS {
21 namespace WorkScheduler {
WorkBundleGroupChangeCallback(std::shared_ptr<WorkQueueManager> workQueueManager)22 WorkBundleGroupChangeCallback::WorkBundleGroupChangeCallback(std::shared_ptr<WorkQueueManager>
23 workQueueManager)
24 {
25 workQueueManager_ = workQueueManager;
26 }
27
OnAppGroupChanged(const DeviceUsageStats::AppGroupCallbackInfo & appGroupCallbackInfo)28 void WorkBundleGroupChangeCallback::OnAppGroupChanged(
29 const DeviceUsageStats::AppGroupCallbackInfo &appGroupCallbackInfo)
30 {
31 int32_t newGroup = appGroupCallbackInfo.GetNewGroup();
32 int32_t oldGroup = appGroupCallbackInfo.GetOldGroup();
33 int32_t userId = appGroupCallbackInfo.GetUserId();
34 std::string bundleName = appGroupCallbackInfo.GetBundleName();
35 WS_HILOGD("Bundle group changed to %{public}d with userId = %{public}d, bundleName = %{public}s",
36 newGroup, userId, bundleName.c_str());
37 if (!workQueueManager_) {
38 WS_HILOGE("workQueueManager_ is nullptr.");
39 return;
40 }
41 if (newGroup < oldGroup) {
42 bool groupChange = true;
43 workQueueManager_->OnConditionChanged(WorkCondition::Type::GROUP,
44 std::make_shared<DetectorValue>(newGroup, userId, groupChange, bundleName));
45 }
46 }
47 } // namespace WorkScheduler
48 } // namespace OHOS
49 #endif