• 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 "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 int32_t CreateThumbnailPastDirtyDataFix(const std::string &fileId);
59     EXPORT int32_t CreateLcdPastDirtyDataFix(const std::string &fileId, const uint8_t quality = THUMBNAIL_MID);
60     EXPORT void Init(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
61 #ifdef DISTRIBUTED
62         const std::shared_ptr<DistributedKv::SingleKvStore> &kvStore,
63 #endif
64         const std::shared_ptr<OHOS::AbilityRuntime::Context> &context);
65     int32_t GetAgingDataSize(const int64_t &time, int &count);
66     int32_t QueryNewThumbnailCount(const int64_t &time, int &count);
67     void DeleteAstcWithFileIdAndDateTaken(const std::string &fileId, const std::string &dateTaken);
68     int32_t CreateAstcCloudDownload(const std::string &id, bool isCloudInsertTaskPriorityHigh = false);
69     EXPORT int32_t CreateAstcBatchOnDemand(NativeRdb::RdbPredicates &rdbPredicate, int32_t requestId);
70     EXPORT void CancelAstcBatchTask(int32_t requestId);
71     void UpdateAstcWithNewDateTaken(const std::string &fileId, const std::string &newDateTaken,
72         const std::string &formerDateTaken);
73     EXPORT int32_t CheckCloudThumbnailDownloadFinish();
74     EXPORT void AstcChangeKeyFromDateAddedToDateTaken();
75     EXPORT void UpdateCurrentStatusForTask(const bool &currentStatusForTask);
76     EXPORT bool GetCurrentStatusForTask();
77     EXPORT void NotifyTempStatusForReady(const int32_t &currentTemperatureLevel);
78     EXPORT int32_t GetCurrentTemperatureLevel();
79     EXPORT void CheckLcdSizeAndUpdateStatus();
80 private:
81     EXPORT ThumbnailService();
82     bool CheckSizeValid();
83     int32_t ParseThumbnailParam(const std::string &uri, std::string &fileId, std::string &networkId,
84         std::string &tableName);
85     int GetThumbFd(const std::string &path, const std::string &table, const std::string &id,
86         const std::string &uri, const Size &size, bool isAstc = false);
87     static std::shared_ptr<ThumbnailService> thumbnailServiceInstance_;
88     static std::mutex instanceLock_;
89 #ifdef DISTRIBUTED
90     std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_;
91 #endif
92     std::shared_ptr<MediaLibraryRdbStore> rdbStorePtr_;
93     std::shared_ptr<OHOS::AbilityRuntime::Context> context_;
94     std::shared_ptr<NativeRdb::RdbPredicates> rdbPredicatePtr_;
95     Size screenSize_;
96     int32_t currentRequestId_ = 0;
97     int32_t currentTemperatureLevel_ = 0;
98     bool isScreenSizeInit_ = false;
99     bool currentStatusForTask_ = false;
100     bool isTemperatureHighForReady_ = false;
101 };
102 } // namespace Media
103 } // namespace OHOS
104 
105 #endif  // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_SERVICE_H
106