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 29 namespace OHOS { 30 namespace Media { 31 32 class DeleteBehaviorTask : public DfxData { 33 public: DeleteBehaviorTask(std::string id,int32_t type,int32_t size,std::vector<std::string> & uris,std::shared_ptr<DfxReporter> dfxReporter)34 DeleteBehaviorTask(std::string id, int32_t type, int32_t size, std::vector<std::string> &uris, 35 std::shared_ptr<DfxReporter> dfxReporter) : id_(id), type_(type), size_(size), uris_(uris), 36 dfxReporter_(dfxReporter) {} 37 virtual ~DeleteBehaviorTask() override = default; 38 std::string id_; 39 int32_t type_; 40 int32_t size_; 41 std::vector<std::string> uris_; 42 std::shared_ptr<DfxReporter> dfxReporter_; 43 }; 44 45 class StatisticData : public DfxData { 46 public: StatisticData(std::shared_ptr<DfxReporter> dfxReporter)47 StatisticData(std::shared_ptr<DfxReporter> dfxReporter) : dfxReporter_(dfxReporter) {} 48 virtual ~StatisticData() override = default; 49 std::shared_ptr<DfxReporter> dfxReporter_; 50 }; 51 52 class DfxManager { 53 public: 54 DfxManager(); 55 ~DfxManager(); 56 static std::shared_ptr<DfxManager> GetInstance(); 57 void HandleTimeOutOperation(std::string &bundleName, int32_t type, int32_t object, int32_t time); 58 int32_t HandleHighMemoryThumbnail(std::string &path, int32_t mediaType, int32_t width, int32_t height); 59 void HandleThumbnailError(const std::string &path, int32_t method, int32_t errCode); 60 void HandleThumbnailGeneration(const ThumbnailData::GenerateStats &stats); 61 void HandleFiveMinuteTask(); 62 int64_t HandleMiddleReport(); 63 int64_t HandleOneDayReport(); 64 void HandleCommonBehavior(std::string bundleName, int32_t type); 65 void HandleDeleteBehavior(int32_t type, int32_t size, std::vector<std::string> &uris, std::string bundleName = ""); 66 void HandleDeleteBehaviors(); 67 void HandleNoPermmison(int32_t type, int32_t object, int32_t error); 68 void HandleHalfDayMissions(); 69 void HandleAdaptationToMovingPhoto(const std::string &appName, bool adapted); 70 void IsDirectoryExist(const std::string &dirName); 71 void CheckStatus(); 72 73 private: 74 void Init(); 75 void HandleAlbumInfoBySubtype(int32_t albumSubType); 76 77 private: 78 static std::mutex instanceLock_; 79 static std::shared_ptr<DfxManager> dfxManagerInstance_; 80 std::atomic<bool> isInitSuccess_; 81 std::shared_ptr<DfxCollector> dfxCollector_; 82 std::shared_ptr<DfxAnalyzer> dfxAnalyzer_; 83 std::shared_ptr<DfxReporter> dfxReporter_; 84 std::shared_ptr<DfxWorker> dfxWorker_; 85 }; 86 } // namespace Media 87 } // namespace OHOS 88 89 #endif // OHOS_MEDIA_DFX_MANAGER_H