14dfc7d99Sopenharmony_ci/* 24dfc7d99Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 34dfc7d99Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44dfc7d99Sopenharmony_ci * you may not use this file except in compliance with the License. 54dfc7d99Sopenharmony_ci * You may obtain a copy of the License at 64dfc7d99Sopenharmony_ci * 74dfc7d99Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84dfc7d99Sopenharmony_ci * 94dfc7d99Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104dfc7d99Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114dfc7d99Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124dfc7d99Sopenharmony_ci * See the License for the specific language governing permissions and 134dfc7d99Sopenharmony_ci * limitations under the License. 144dfc7d99Sopenharmony_ci */ 154dfc7d99Sopenharmony_ci 164dfc7d99Sopenharmony_ci#ifndef RESOURCE_SCHEDULE_SERVICE_RESSCHED_COMMON_OOBE_MANAGER_H 174dfc7d99Sopenharmony_ci#define RESOURCE_SCHEDULE_SERVICE_RESSCHED_COMMON_OOBE_MANAGER_H 184dfc7d99Sopenharmony_ci 194dfc7d99Sopenharmony_ci#include "data_ability_observer_stub.h" 204dfc7d99Sopenharmony_ci#include "errors.h" 214dfc7d99Sopenharmony_ci#include "mutex" 224dfc7d99Sopenharmony_ci#include "ioobe_task.h" 234dfc7d99Sopenharmony_ci#include <functional> 244dfc7d99Sopenharmony_ci#include <vector> 254dfc7d99Sopenharmony_ci 264dfc7d99Sopenharmony_cinamespace OHOS { 274dfc7d99Sopenharmony_cinamespace ResourceSchedule { 284dfc7d99Sopenharmony_ci 294dfc7d99Sopenharmony_ciclass OOBEManager { 304dfc7d99Sopenharmony_cipublic: 314dfc7d99Sopenharmony_ci static OOBEManager& GetInstance(); 324dfc7d99Sopenharmony_ci bool SubmitTask(const std::shared_ptr<IOOBETask>& task); 334dfc7d99Sopenharmony_ci void StartListen(); 344dfc7d99Sopenharmony_ci ErrCode UnregisterObserver(); 354dfc7d99Sopenharmony_ci bool GetOOBValue(); 364dfc7d99Sopenharmony_ci void OnReceiveDataShareReadyCallBack(); 374dfc7d99Sopenharmony_ci 384dfc7d99Sopenharmony_ciprivate: 394dfc7d99Sopenharmony_ci class ResDataAbilityObserver : public AAFwk::DataAbilityObserverStub { 404dfc7d99Sopenharmony_ci public: 414dfc7d99Sopenharmony_ci ResDataAbilityObserver() = default; 424dfc7d99Sopenharmony_ci ~ResDataAbilityObserver() = default; 434dfc7d99Sopenharmony_ci void OnChange() override; 444dfc7d99Sopenharmony_ci 454dfc7d99Sopenharmony_ci using UpdateFunc = std::function<void()>; 464dfc7d99Sopenharmony_ci void SetUpdateFunc(const UpdateFunc& func); 474dfc7d99Sopenharmony_ci private: 484dfc7d99Sopenharmony_ci UpdateFunc update_ = nullptr; 494dfc7d99Sopenharmony_ci }; 504dfc7d99Sopenharmony_ci 514dfc7d99Sopenharmony_ci bool g_oobeValue = false; 524dfc7d99Sopenharmony_ci static std::recursive_mutex mutex_; 534dfc7d99Sopenharmony_ci static std::vector<std::shared_ptr<IOOBETask>> oobeTasks_; 544dfc7d99Sopenharmony_ci static std::vector<std::function<void()>> dataShareFunctions_; 554dfc7d99Sopenharmony_ci static sptr<OOBEManager::ResDataAbilityObserver> observer_; 564dfc7d99Sopenharmony_ci OOBEManager(); 574dfc7d99Sopenharmony_ci ~OOBEManager(); 584dfc7d99Sopenharmony_ci void Initialize(); 594dfc7d99Sopenharmony_ci ErrCode RegisterObserver(const std::string& key, const ResDataAbilityObserver::UpdateFunc& func); 604dfc7d99Sopenharmony_ci void ReRegisterObserver(const std::string& key, const ResDataAbilityObserver::UpdateFunc& func); 614dfc7d99Sopenharmony_ci}; 624dfc7d99Sopenharmony_ci} // ResourceSchedule 634dfc7d99Sopenharmony_ci} // OHOS 644dfc7d99Sopenharmony_ci#endif //RESOURCE_SCHEDULE_SERVICE_RESSCHED_COMMON_OOBE_MANAGER_H