• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     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(const int32_t &restoreAstcCount = ASTC_GENERATE_COUNT_AFTER_RESTORE);
53     EXPORT void InterruptBgworker();
54     EXPORT void StopAllWorker();
55     EXPORT int32_t CreateThumbnailFileScaned(const std::string &uri, const std::string &path,
56         bool isSync = false);
57     EXPORT int32_t CreateThumbnailFileScanedWithPicture(const std::string &uri, const std::string &path,
58         std::shared_ptr<Picture> originalPhotoPicture, bool isSync = false);
59     EXPORT int32_t CreateThumbnailPastDirtyDataFix(const std::string &fileId);
60     EXPORT int32_t CreateLcdPastDirtyDataFix(const std::string &fileId);
61     EXPORT bool HasInvalidateThumbnail(const std::string &id, const std::string &tableName,
62         const std::string &path = "", const std::string &dateTaken = "");
63     EXPORT bool DeleteThumbnailDirAndAstc(const std::string &id, const std::string &tableName,
64         const std::string &path, const std::string &dateTaken);
65     EXPORT bool BatchDeleteThumbnailDirAndAstc(const std::string &tableName, const std::vector<std::string> &ids,
66         const std::vector<std::string> &paths, const std::vector<std::string> &dateTakens);
67     EXPORT void Init(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
68     const std::shared_ptr<OHOS::AbilityRuntime::Context> &context);
69     EXPORT int32_t GetAgingDataSize(const int64_t &time, int &count);
70     int32_t QueryNewThumbnailCount(const int64_t &time, int &count);
71     void DeleteAstcWithFileIdAndDateTaken(const std::string &fileId, const std::string &dateTaken);
72     EXPORT int32_t CreateAstcCloudDownload(const std::string &id, bool isCloudInsertTaskPriorityHigh = false);
73     EXPORT int32_t LocalThumbnailGeneration();
74     EXPORT int32_t CreateAstcBatchOnDemand(NativeRdb::RdbPredicates &rdbPredicate, int32_t requestId);
75     EXPORT void CancelAstcBatchTask(int32_t requestId);
76     EXPORT bool CreateAstcMthAndYear(const std::string &id);
77     EXPORT bool RegenerateThumbnailFromCloud(const std::string &id);
78     EXPORT void UpdateAstcWithNewDateTaken(const std::string &fileId, const std::string &newDateTaken,
79         const std::string &formerDateTaken);
80     EXPORT int32_t CheckCloudThumbnailDownloadFinish();
81     EXPORT void AstcChangeKeyFromDateAddedToDateTaken();
82     EXPORT void UpdateCurrentStatusForTask(const bool &currentStatusForTask);
83     EXPORT bool GetCurrentStatusForTask();
84     EXPORT void NotifyTempStatusForReady(const int32_t &currentTemperatureLevel);
85     EXPORT int32_t GetCurrentTemperatureLevel();
86     EXPORT void CheckLcdSizeAndUpdateStatus();
87     EXPORT int32_t RepairExifRotateBackground();
88     EXPORT int32_t FixThumbnailExifRotateAfterDownloadAsset(const std::string &fileId);
89 private:
90     EXPORT ThumbnailService();
91     bool CheckSizeValid();
92     int32_t ParseThumbnailParam(const std::string &uri, std::string &fileId, std::string &networkId,
93         std::string &tableName);
94     EXPORT int GetThumbFd(const std::string &path, const std::string &table, const std::string &id,
95         const std::string &uri, const Size &size, bool isAstc = false);
96     EXPORT int GetKeyFrameThumbFd(const std::string &path, const std::string &table, const std::string &id,
97         const std::string &uri, int32_t &beginStamp, int32_t &type);
98     static std::shared_ptr<ThumbnailService> thumbnailServiceInstance_;
99     static std::mutex instanceLock_;
100     std::shared_ptr<MediaLibraryRdbStore> rdbStorePtr_;
101     std::shared_ptr<OHOS::AbilityRuntime::Context> context_;
102     std::shared_ptr<NativeRdb::RdbPredicates> rdbPredicatePtr_;
103     Size screenSize_;
104     int32_t currentRequestId_ = 0;
105     int32_t currentTemperatureLevel_ = 0;
106     bool isScreenSizeInit_ = false;
107     bool currentStatusForTask_ = false;
108     bool isTemperatureHighForReady_ = false;
109 };
110 } // namespace Media
111 } // namespace OHOS
112 
113 #endif  // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_SERVICE_H
114