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 #include "trash_async_worker.h" 16 #include "medialibrary_album_operations.h" 17 #include "medialibrary_smartalbum_map_operations.h" 18 #include "media_log.h" 19 20 using namespace std; 21 22 namespace OHOS { 23 namespace Media { 24 25 shared_ptr<TrashAsyncTaskWorker> TrashAsyncTaskWorker::asyncWorkerInstance_{nullptr}; 26 mutex TrashAsyncTaskWorker::instanceLock_; 27 GetInstance()28shared_ptr<TrashAsyncTaskWorker> TrashAsyncTaskWorker::GetInstance() 29 { 30 if (asyncWorkerInstance_ == nullptr) { 31 lock_guard<mutex> lockGuard(instanceLock_); 32 asyncWorkerInstance_ = shared_ptr<TrashAsyncTaskWorker>(new TrashAsyncTaskWorker()); 33 } 34 return asyncWorkerInstance_; 35 } 36 TrashAsyncTaskWorker()37TrashAsyncTaskWorker::TrashAsyncTaskWorker() {} 38 ~TrashAsyncTaskWorker()39TrashAsyncTaskWorker::~TrashAsyncTaskWorker() {} 40 Init()41void TrashAsyncTaskWorker::Init() 42 { 43 thread(&TrashAsyncTaskWorker::StartWorker, this).detach(); 44 } 45 Interrupt()46void TrashAsyncTaskWorker::Interrupt() 47 { 48 MediaLibrarySmartAlbumMapOperations::SetInterrupt(true); 49 } 50 StartWorker()51void TrashAsyncTaskWorker::StartWorker() 52 { 53 MediaLibrarySmartAlbumMapOperations::SetInterrupt(false); 54 MediaLibrarySmartAlbumMapOperations::HandleAgingOperation(); 55 MediaLibraryAlbumOperations::HandlePhotoAlbum(OperationType::AGING, {}, {}); 56 } 57 } // namespace Media 58 } // namespace OHOS 59