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