• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_USER_HISTORY_H
17 #define BUNDLE_ACTIVE_USER_HISTORY_H
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 
23 #include "bundle_active_package_history.h"
24 #include "bundle_active_group_common.h"
25 #include "bundle_active_usage_database.h"
26 
27 namespace OHOS {
28 namespace DeviceUsageStats {
29 using namespace DeviceUsageStatsGroupConst;
30 class BundleActiveCore;
31 
32 class BundleActiveUserHistory {
33 public:
34     std::map<int, std::shared_ptr<std::map<std::string, std::shared_ptr<BundleActivePackageHistory>>>> userHistory_;
35     int64_t bootBasedTimeStamp_;
36     int64_t bootBasedDuration_;
37     int64_t screenOnTimeStamp_;
38     int64_t ScreenOnDuration_;
39     BundleActiveUsageDatabase database_;
40     BundleActiveUserHistory(const int64_t bootBasedTimeStamp,
41         const std::shared_ptr<BundleActiveCore>& bundleActiveCore);
42     std::shared_ptr<BundleActivePackageHistory> GetUsageHistoryForBundle(const std::string& bundleName,
43         const int32_t userId, const int64_t bootBasedTimeStamp, const bool create);
44     std::shared_ptr<std::map<std::string, std::shared_ptr<BundleActivePackageHistory>>> GetUserHistory(
45             const int32_t userId, const bool create);
46     std::shared_ptr<BundleActivePackageHistory> GetUsageHistoryInUserHistory(std::shared_ptr<std::map<std::string,
47         std::shared_ptr<BundleActivePackageHistory>>> oneUserHistory, std::string bundleName,
48         int64_t bootBasedTimeStamp, bool create);
49     int64_t GetBootBasedTimeStamp(int64_t bootBasedTimeStamp);
50     int64_t GetScreenOnTimeStamp(int64_t bootBasedTimeStamp);
51     void ReportUsage(std::shared_ptr<BundleActivePackageHistory> oneBundleUsageHistory, const std::string& bundleName,
52         const int32_t newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp,
53         const int64_t timeUntilNextCheck, const int32_t userId);
54     int32_t SetAppGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp,
55         int32_t newGroup, uint32_t groupReason, const bool isFlush);
56     int32_t GetLevelIndex(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp,
57         const std::vector<int64_t> screenTimeLeve, const std::vector<int64_t> bootFromTimeLevel);
58     void WriteDeviceDuration();
59     void WriteBundleUsage(const int32_t userId);
60     void PrintData(int32_t userId);
61     void UpdateBootBasedAndScreenTime(const bool& isScreenOn, const int64_t bootBasedTimeStamp,
62         const bool& isShutdown = false);
63     void OnBundleUninstalled(const int32_t userId, const std::string bundleName);
64 
65 private:
66     std::mutex setGroupMutex_;
67     bool isScreenOn_;
68     std::weak_ptr<BundleActiveCore> bundleActiveCore_;
69 };
70 }  // namespace DeviceUsageStats
71 }  // namespace OHOS
72 #endif  // BUNDLE_ACTIVE_USER_HISTORY_H
73 
74