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 #ifndef BUNDLE_ACTIVE_CONTINUOUS_TASK_OBSERVER_H
17 #define BUNDLE_ACTIVE_CONTINUOUS_TASK_OBSERVER_H
18 
19 #ifdef BGTASKMGR_ENABLE
20 #include <memory>
21 #ifdef OS_ACCOUNT_PART_ENABLED
22 #include "os_account_manager.h"
23 #endif // OS_ACCOUNT_PART_ENABLED
24 #include "bundle_mgr_interface.h"
25 #include "iremote_object.h"
26 
27 #include "bundle_active_report_handler.h"
28 #include "background_task_mgr_helper.h"
29 #include "background_task_subscriber.h"
30 
31 namespace OHOS {
32 namespace DeviceUsageStats {
33 class BundleActiveContinuousTaskObserver : public OHOS::BackgroundTaskMgr::BackgroundTaskSubscriber {
34 public:
35     using IBundleMgr = OHOS::AppExecFwk::IBundleMgr;
36     void OnContinuousTaskStart(const std::shared_ptr<OHOS::BackgroundTaskMgr::ContinuousTaskCallbackInfo>
37         &continuousTaskCallbackInfo) override;
38     void OnContinuousTaskStop(const std::shared_ptr<OHOS::BackgroundTaskMgr::ContinuousTaskCallbackInfo>
39         &continuousTaskCallbackInfo) override;
40     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
41     void Init(const std::shared_ptr<BundleActiveReportHandler>& reportHandler);
42     std::atomic<bool> isRemoteDied_ {false};
43 private:
44     sptr<IBundleMgr> bundleMgr_;
45     std::shared_ptr<BundleActiveReportHandler> reportHandler_;
46     bool GetBundleMgr();
47     void ReportContinuousTaskEvent(const std::shared_ptr<OHOS::BackgroundTaskMgr::ContinuousTaskCallbackInfo>&
48         continuousTaskCallbackInfo, const bool isStart);
49 };
50 }  // namespace DeviceUsageStats
51 }  // namespace OHOS
52 #endif
53 #endif  // BUNDLE_ACTIVE_CONTINUOUS_TASK_OBSERVER_H
54 
55