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 FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_SERVICE_H 17 #define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_SERVICE_H 18 19 #include <mutex> 20 21 #include "picture.h" 22 23 #include "fa_ability_context.h" 24 #include "media_file_uri.h" 25 #include "medialibrary_rdbstore.h" 26 #include "pixel_map.h" 27 #include "rdb_helper.h" 28 #include "rdb_predicates.h" 29 #include "result_set_bridge.h" 30 #include "single_kvstore.h" 31 #include "userfile_manager_types.h" 32 #include "thumbnail_const.h" 33 34 namespace OHOS { 35 namespace Media { 36 #define EXPORT __attribute__ ((visibility ("default"))) 37 class ThumbnailService { 38 public: 39 EXPORT virtual ~ThumbnailService() = default; 40 EXPORT static std::shared_ptr<ThumbnailService> GetInstance(); 41 EXPORT void ReleaseService(); 42 43 EXPORT int GetThumbnailFd(const std::string &uri, bool isAstc = false); 44 EXPORT int GetKeyFrameThumbnailFd(const std::string &uri, bool isAstc = false); 45 EXPORT int32_t LcdAging(); 46 #ifdef DISTRIBUTED 47 EXPORT int32_t LcdDistributeAging(const std::string &udid); 48 #endif 49 EXPORT int32_t GenerateThumbnailBackground(); 50 EXPORT int32_t UpgradeThumbnailBackground(bool isWifiConnected); 51 EXPORT int32_t GenerateHighlightThumbnailBackground(); 52 EXPORT int32_t TriggerHighlightThumbnail(std::string &id, std::string &tracks, std::string &trigger, 53 std::string &genType); 54 55 EXPORT int32_t RestoreThumbnailDualFrame(const int32_t &restoreAstcCount = ASTC_GENERATE_COUNT_AFTER_RESTORE); 56 EXPORT void InterruptBgworker(); 57 EXPORT void StopAllWorker(); 58 #ifdef DISTRIBUTED 59 EXPORT int32_t InvalidateDistributeThumbnail(const std::string &udid); 60 #endif 61 EXPORT int32_t CreateThumbnailFileScaned(const std::string &uri, const std::string &path, 62 bool isSync = false); 63 EXPORT int32_t CreateThumbnailFileScanedWithPicture(const std::string &uri, const std::string &path, 64 std::shared_ptr<Picture> originalPhotoPicture, bool isSync = false); 65 EXPORT int32_t CreateThumbnailPastDirtyDataFix(const std::string &fileId); 66 EXPORT int32_t CreateLcdPastDirtyDataFix(const std::string &fileId, const uint8_t quality = THUMBNAIL_MID); 67 bool HasInvalidateThumbnail(const std::string &id, const std::string &tableName, 68 const std::string &path = "", const std::string &dateTaken = ""); 69 EXPORT void Init(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 70 #ifdef DISTRIBUTED 71 const std::shared_ptr<DistributedKv::SingleKvStore> &kvStore, 72 #endif 73 const std::shared_ptr<OHOS::AbilityRuntime::Context> &context); 74 EXPORT int32_t GetAgingDataSize(const int64_t &time, int &count); 75 int32_t QueryNewThumbnailCount(const int64_t &time, int &count); 76 void DeleteAstcWithFileIdAndDateTaken(const std::string &fileId, const std::string &dateTaken); 77 EXPORT int32_t CreateAstcCloudDownload(const std::string &id, bool isCloudInsertTaskPriorityHigh = false); 78 EXPORT int32_t LocalThumbnailGeneration(); 79 EXPORT int32_t CreateAstcBatchOnDemand(NativeRdb::RdbPredicates &rdbPredicate, int32_t requestId); 80 EXPORT void CancelAstcBatchTask(int32_t requestId); 81 EXPORT bool CreateAstcMthAndYear(const std::string &id); 82 void UpdateAstcWithNewDateTaken(const std::string &fileId, const std::string &newDateTaken, 83 const std::string &formerDateTaken); 84 EXPORT int32_t CheckCloudThumbnailDownloadFinish(); 85 EXPORT void AstcChangeKeyFromDateAddedToDateTaken(); 86 EXPORT void UpdateCurrentStatusForTask(const bool ¤tStatusForTask); 87 EXPORT bool GetCurrentStatusForTask(); 88 EXPORT void NotifyTempStatusForReady(const int32_t ¤tTemperatureLevel); 89 EXPORT int32_t GetCurrentTemperatureLevel(); 90 EXPORT void CheckLcdSizeAndUpdateStatus(); 91 private: 92 EXPORT ThumbnailService(); 93 bool CheckSizeValid(); 94 int32_t ParseThumbnailParam(const std::string &uri, std::string &fileId, std::string &networkId, 95 std::string &tableName); 96 EXPORT int GetThumbFd(const std::string &path, const std::string &table, const std::string &id, 97 const std::string &uri, const Size &size, bool isAstc = false); 98 EXPORT int GetKeyFrameThumbFd(const std::string &path, const std::string &table, const std::string &id, 99 const std::string &uri, int32_t &beginStamp, int32_t &type); 100 static std::shared_ptr<ThumbnailService> thumbnailServiceInstance_; 101 static std::mutex instanceLock_; 102 #ifdef DISTRIBUTED 103 std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_; 104 #endif 105 std::shared_ptr<MediaLibraryRdbStore> rdbStorePtr_; 106 std::shared_ptr<OHOS::AbilityRuntime::Context> context_; 107 std::shared_ptr<NativeRdb::RdbPredicates> rdbPredicatePtr_; 108 Size screenSize_; 109 int32_t currentRequestId_ = 0; 110 int32_t currentTemperatureLevel_ = 0; 111 bool isScreenSizeInit_ = false; 112 bool currentStatusForTask_ = false; 113 bool isTemperatureHighForReady_ = false; 114 }; 115 } // namespace Media 116 } // namespace OHOS 117 118 #endif // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_SERVICE_H 119