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