• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "bundle_active_report_controller.h"
17 
18 #include "bundle_active_log.h"
19 #include "bundle_active_user_history.h"
20 #include "bundle_active_group_handler.h"
21 #include "ibundle_active_service.h"
22 #include "bundle_active_group_controller.h"
23 #include "bundle_active_util.h"
24 
25 namespace OHOS {
26 namespace DeviceUsageStats {
GetInstance()27 BundleActiveReportController& BundleActiveReportController::GetInstance()
28 {
29     static BundleActiveReportController instance;
30     return instance;
31 }
32 
Init(const std::shared_ptr<BundleActiveCore> & bundleActiveCore)33 void BundleActiveReportController::Init(const std::shared_ptr<BundleActiveCore>& bundleActiveCore)
34 {
35     std::lock_guard<ffrt::mutex> lock(mutex_);
36     if (isInit_) {
37         return;
38     }
39     activeReportHandler_ = std::make_shared<BundleActiveReportHandler>();
40     if (activeReportHandler_ == nullptr) {
41         return;
42     }
43     activeReportHandler_->Init(bundleActiveCore);
44     isInit_ = true;
45 }
46 
DeInit()47 void BundleActiveReportController::DeInit()
48 {
49     if (!isInit_) {
50         return;
51     }
52     std::lock_guard<ffrt::mutex> lock(mutex_);
53     isInit_ = false;
54     activeReportHandler_->DeInit();
55 }
56 
GetBundleReportHandler()57 std::shared_ptr<BundleActiveReportHandler> BundleActiveReportController::GetBundleReportHandler()
58 {
59     std::lock_guard<ffrt::mutex> lock(mutex_);
60     if (!isInit_) {
61         return nullptr;
62     }
63     return activeReportHandler_;
64 }
65 }  // namespace DeviceUsageStats
66 }  // namespace OHOS
67 
68