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 #ifndef RESOURCE_SCHEDULE_SERVICE_RESSCHED_COMMON_OOBE_MANAGER_H 17 #define RESOURCE_SCHEDULE_SERVICE_RESSCHED_COMMON_OOBE_MANAGER_H 18 19 #include "data_ability_observer_stub.h" 20 #include "errors.h" 21 #include "mutex" 22 #include "ioobe_task.h" 23 #include <functional> 24 #include <vector> 25 #include "ffrt.h" 26 27 namespace OHOS { 28 namespace ResourceSchedule { 29 30 class OOBEManager { 31 public: 32 static OOBEManager& GetInstance(); 33 bool SubmitTask(const std::shared_ptr<IOOBETask>& task); 34 void StartListen(); 35 ErrCode UnregisterObserver(); 36 bool GetOOBValue(); 37 void OnReceiveDataShareReadyCallBack(); 38 39 private: 40 class ResDataAbilityObserver : public AAFwk::DataAbilityObserverStub { 41 public: 42 ResDataAbilityObserver() = default; 43 ~ResDataAbilityObserver() = default; 44 void OnChange() override; 45 46 using UpdateFunc = std::function<void()>; 47 void SetUpdateFunc(const UpdateFunc& func); 48 private: 49 UpdateFunc update_ = nullptr; 50 }; 51 52 bool g_oobeValue = false; 53 static ffrt::recursive_mutex mutex_; 54 static std::vector<std::shared_ptr<IOOBETask>> oobeTasks_; 55 static std::vector<std::function<void()>> dataShareFunctions_; 56 static sptr<OOBEManager::ResDataAbilityObserver> observer_; 57 OOBEManager(); 58 ~OOBEManager(); 59 void Initialize(); 60 ErrCode RegisterObserver(const std::string& key, const ResDataAbilityObserver::UpdateFunc& func); 61 void ReRegisterObserver(const std::string& key, const ResDataAbilityObserver::UpdateFunc& func); 62 void ExecuteDataShareFunction(); 63 }; 64 } // ResourceSchedule 65 } // OHOS 66 #endif //RESOURCE_SCHEDULE_SERVICE_RESSCHED_COMMON_OOBE_MANAGER_H