1 /*
2  * Copyright (c) 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 #ifndef CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_APP_STARTUP_SCENE_REC_H
17 #define CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_APP_STARTUP_SCENE_REC_H
18 
19 #include <string>
20 #include <unordered_set>
21 #include <mutex>
22 #include <memory>
23 #include <atomic>
24 #include "ffrt.h"
25 #include "nlohmann/json.hpp"
26 namespace OHOS {
27 namespace ResourceSchedule {
28 class AppStartupSceneRec {
29 public:
30     static AppStartupSceneRec &GetInstance();
31     void Init();
32     void Deinit();
33     void RecordIsContinuousStartup(const int32_t abilityState, const std::string uid,
34 		const std::string bundleName);
35 private:
36     AppStartupSceneRec();
37     ~AppStartupSceneRec();
38     bool IsAppStartUp(int32_t abilityState);
39     void CleanRecordSceneData();
40     void UpdateAppStartupNum(const std::string uid, const int64_t curTime, const std::string bundleName);
41     bool IsContinuousStartup();
42     int32_t appStartCount_ = 0;
43     int64_t lastAppStartTime_ = 0;
44     std::atomic_bool isReportContinuousStartup_ = false;
45     std::vector<std::string> startPkgs_;
46     std::unordered_set<std::string> startUidSet_;
47     std::unordered_set<std::string> startIgnorePkgs_;
48     std::shared_ptr<ffrt::queue> ffrtQueue_ = nullptr;
49     ffrt::task_handle exitContinuousStartupTask;
50     ffrt::mutex mutex_;
51 };
52 }
53 }
54 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_APP_STARTUP_SCENE_REC_H