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 "pixel_map.h" 24 #include "rdb_helper.h" 25 #include "result_set_bridge.h" 26 #include "single_kvstore.h" 27 #include "userfile_manager_types.h" 28 #include "thumbnail_const.h" 29 30 namespace OHOS { 31 namespace Media { 32 #define EXPORT __attribute__ ((visibility ("default"))) 33 class ThumbnailService { 34 public: 35 EXPORT virtual ~ThumbnailService() = default; 36 EXPORT static std::shared_ptr<ThumbnailService> GetInstance(); 37 EXPORT void ReleaseService(); 38 39 EXPORT int GetThumbnailFd(const std::string &uri, bool isAstc = false); 40 EXPORT int32_t LcdAging(); 41 #ifdef DISTRIBUTED 42 EXPORT int32_t LcdDistributeAging(const std::string &udid); 43 #endif 44 EXPORT int32_t GenerateThumbnails(); 45 EXPORT void InterruptBgworker(); 46 EXPORT void StopAllWorker(); 47 #ifdef DISTRIBUTED 48 EXPORT int32_t InvalidateDistributeThumbnail(const std::string &udid); 49 #endif 50 EXPORT int32_t CreateThumbnail(const std::string &uri, const std::string &path, 51 bool isSync = false); 52 void InvalidateThumbnail(const std::string &id, const std::string &tableName, 53 const std::string &path = ""); 54 EXPORT void Init(const std::shared_ptr<NativeRdb::RdbStore> &rdbStore, 55 #ifdef DISTRIBUTED 56 const std::shared_ptr<DistributedKv::SingleKvStore> &kvStore, 57 #endif 58 const std::shared_ptr<OHOS::AbilityRuntime::Context> &context); 59 int32_t GetAgingDataSize(const int64_t &time, int &count); 60 int32_t QueryNewThumbnailCount(const int64_t &time, int &count); 61 int32_t CreateAstcFromFileId(const std::string &id); 62 private: 63 EXPORT ThumbnailService(); 64 bool CheckSizeValid(); 65 int32_t ParseThumbnailParam(const std::string &uri, std::string &fileId, std::string &networkId, 66 std::string &tableName); 67 int GetThumbFd(const std::string &path, const std::string &table, const std::string &id, 68 const std::string &uri, const Size &size, bool isAstc = false); 69 int32_t CreateThumbnailInfo(const std::string &path, const std::string &tableName, const std::string &fileId, 70 const std::string &uri, const bool &isSync); 71 int32_t CreateDefaultThumbnail(const std::string &path, 72 const std::string &tableName, const std::string &fileId, const std::string &uri, const bool &isSync); 73 int32_t CreateLcdThumbnail(const std::string &path, 74 const std::string &tableName, const std::string &fileId, const bool &isSync); 75 static std::shared_ptr<ThumbnailService> thumbnailServiceInstance_; 76 static std::mutex instanceLock_; 77 #ifdef DISTRIBUTED 78 std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_; 79 #endif 80 std::shared_ptr<NativeRdb::RdbStore> rdbStorePtr_; 81 std::shared_ptr<OHOS::AbilityRuntime::Context> context_; 82 Size screenSize_; 83 bool isScreenSizeInit_ = false; 84 }; 85 } // namespace Media 86 } // namespace OHOS 87 88 #endif // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_SERVICE_H_ 89