1 /* 2 * Copyright (C) 2024 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 #include "cloud_thumbnail_observer.h" 17 #include "medialibrary_rdb_utils.h" 18 19 using namespace std; 20 using namespace OHOS::DistributedKv; 21 using namespace OHOS::NativeRdb; 22 23 namespace OHOS { 24 namespace Media { 25 IsFileIdValid(const std::string & fileId)26static inline bool IsFileIdValid(const std::string& fileId) 27 { 28 if (fileId.empty()) { 29 return false; 30 } 31 for (char const& ch : fileId) { 32 if (std::isdigit(ch) == 0) { 33 return false; 34 } 35 } 36 return true; 37 } 38 OnChange(const ChangeInfo & changeInfo)39void CloudThumbnailObserver::OnChange(const ChangeInfo &changeInfo) 40 { 41 MediaLibraryRdbUtils::SetNeedRefreshAlbum(true); 42 if (changeInfo.changeType_ != ChangeType::INSERT) { 43 MEDIA_DEBUG_LOG("change type is %{public}d, not insert", changeInfo.changeType_); 44 return; 45 } 46 for (auto &uri : changeInfo.uris_) { 47 string uriString = uri.ToString(); 48 auto pos = uriString.find_last_of('/'); 49 if (pos == std::string::npos) { 50 continue; 51 } 52 string idString = uriString.substr(pos + 1); 53 if (!IsFileIdValid(idString)) { 54 MEDIA_DEBUG_LOG("cloud observer get no valid fileId and uri : %{public}s", uriString.c_str()); 55 continue; 56 } 57 ThumbnailService::GetInstance()->CreateAstcCloudDownload(idString); 58 } 59 } 60 } // namespace Media 61 } // namespace OHOS