• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_MEDIA_DFX_MANAGER_H
17 #define OHOS_MEDIA_DFX_MANAGER_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "dfx_collector.h"
23 #include "dfx_analyzer.h"
24 #include "dfx_reporter.h"
25 
26 #include "ipc_skeleton.h"
27 #include "dfx_worker.h"
28 #include "dfx_cloud_const.h"
29 
30 namespace OHOS {
31 namespace Media {
32 
33 struct DeleteBehaviorData {
34     std::map<std::string, std::string> displayNames;
35     std::map<std::string, std::string> albumNames;
36     std::map<std::string, std::string> ownerAlbumIds;
37 };
38 
39 class DeleteBehaviorTask : public DfxData {
40 public:
41     DeleteBehaviorTask(std::string id, int32_t type, int32_t size, std::vector<std::string> &uris,
42         std::shared_ptr<DfxReporter> dfxReporter,
id_(id)43         const DeleteBehaviorData &deleteBehaviorData = {}) : id_(id), type_(type),  size_(size), uris_(uris),
44         dfxReporter_(dfxReporter), deleteBehaviorData_(deleteBehaviorData) {}
45     virtual ~DeleteBehaviorTask() override = default;
46     std::string id_;
47     int32_t type_;
48     int32_t size_;
49     std::vector<std::string> uris_;
50     std::shared_ptr<DfxReporter> dfxReporter_;
51     DeleteBehaviorData deleteBehaviorData_;
52 };
53 
54 class StatisticData : public DfxData {
55 public:
StatisticData(std::shared_ptr<DfxReporter> dfxReporter)56     StatisticData(std::shared_ptr<DfxReporter> dfxReporter) : dfxReporter_(dfxReporter) {}
57     virtual ~StatisticData() override = default;
58     std::shared_ptr<DfxReporter> dfxReporter_;
59 };
60 
61 class DfxManager {
62 public:
63     DfxManager();
64     ~DfxManager();
65 
66     EXPORT static std::shared_ptr<DfxManager> GetInstance();
67     void HandleControllerServiceError(uint32_t operationCode, int32_t errorCode);
68     void HandleTimeOutOperation(std::string &bundleName, int32_t type, int32_t object, int32_t time);
69     int32_t HandleHighMemoryThumbnail(std::string &path, int32_t mediaType, int32_t width, int32_t height);
70     void HandleThumbnailError(const std::string &path, int32_t method, int32_t errCode);
71     void HandleThumbnailGeneration(const ThumbnailData::GenerateStats &stats);
72     void HandleFiveMinuteTask();
73     int64_t HandleMiddleReport();
74     int64_t HandleOneDayReport();
75     void HandleCommonBehavior(std::string bundleName, int32_t type);
76     void HandleDeleteBehavior(int32_t type, int32_t size, std::vector<std::string> &uris, std::string bundleName = "",
77         const DeleteBehaviorData &deleteBehaviorData = {});
78     void HandleDeleteBehaviors();
79     void HandleNoPermmison(int32_t type, int32_t object, int32_t error);
80     void HandleHalfDayMissions();
81     void HandleTwoDayMissions();
82     void HandleAdaptationToMovingPhoto(const std::string &appName, bool adapted);
83     void IsDirectoryExist(const std::string &dirName);
84     void CheckStatus();
85     void HandleSyncStart(const std::string& taskId, const int32_t syncReason = 1);
86     void HandleUpdateMetaStat(uint32_t index, uint64_t diff, uint32_t syncType = 0);
87     void HandleUpdateAttachmentStat(uint32_t index, uint64_t diff);
88     void HandleUpdateAlbumStat(uint32_t index, uint64_t diff);
89     void HandleUpdateUploadMetaStat(uint32_t index, uint64_t diff);
90     void HandleUpdateUploadDetailError(int32_t error);
91     void HandleSyncEnd(const int32_t stopReason = 0);
92     void HandleReportSyncFault(const std::string& position, const SyncFaultEvent& event);
93     void HandleOneWeekMissions();
94     void HandleAccurateRefreshTimeOut(const AccurateRefreshDfxDataPoint& reportData);
95 
96 private:
97     void Init();
98     void HandleAlbumInfoBySubtype(int32_t albumSubType);
99     void ResetStatistic();
100     void CopyStatistic(CloudSyncStat& stat);
101 
102 private:
103     static std::mutex instanceLock_;
104     static std::shared_ptr<DfxManager> dfxManagerInstance_;
105     std::atomic<bool> isInitSuccess_;
106     std::shared_ptr<DfxCollector> dfxCollector_;
107     std::shared_ptr<DfxAnalyzer> dfxAnalyzer_;
108     std::shared_ptr<DfxReporter> dfxReporter_;
109     std::shared_ptr<DfxWorker> dfxWorker_;
110 
111     std::vector<std::atomic<uint64_t>> downloadMeta_;
112     std::vector<std::atomic<uint64_t>> uploadMeta_;
113     std::vector<std::atomic<uint64_t>> downloadThumb_;
114     std::vector<std::atomic<uint64_t>> downloadLcd_;
115     std::vector<std::atomic<uint64_t>> uploadAlbum_;
116     std::vector<std::atomic<uint64_t>> downloadAlbum_;
117     std::vector<std::atomic<uint64_t>> updateDetails_;
118     std::vector<std::atomic<uint64_t>> uploadMetaErr_;
119     CloudSyncInfo syncInfo_;
120     std::string taskId_;
121 };
122 } // namespace Media
123 } // namespace OHOS
124 
125 #endif  // OHOS_MEDIA_DFX_MANAGER_H