1 /* 2 * Copyright (c) 2021 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_SCREEN_STATUS_MANAGER_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_SCREEN_STATUS_MANAGER_H 18 19 #include <mutex> 20 21 #include "distributed_kv_data_manager.h" 22 #include "event_handler.h" 23 #include "event_runner.h" 24 #include "singleton.h" 25 26 #include "distributed_device_callback.h" 27 #include "distributed_flow_control.h" 28 29 namespace OHOS { 30 namespace Notification { 31 class DistributedScreenStatusManager : private DistributedFlowControl, 32 public DelayedSingleton<DistributedScreenStatusManager> { 33 public: 34 /** 35 * @brief Check if any other device screen is on. 36 * 37 * @param isUsing True for any other device screen is on, otherwise false. 38 * @return Returns the error code. 39 */ 40 ErrCode CheckRemoteDevicesIsUsing(bool &isUsing); 41 42 /** 43 * @brief Set screen status of local device. 44 * 45 * @param screenOn Indicates the local device screen status. 46 * @return Returns the error code. 47 */ 48 ErrCode SetLocalScreenStatus(bool screenOn); 49 50 private: 51 void OnDeviceConnected(const std::string &deviceId); 52 void OnDeviceDisconnected(const std::string &deviceId); 53 54 void GetKvDataManager(void); 55 bool CheckKvDataManager(void); 56 void GetKvStore(void); 57 bool CheckKvStore(void); 58 59 std::string GenerateDistributedKey(const std::string &deviceId); 60 61 private: 62 std::recursive_mutex mutex_; 63 std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner_ = nullptr; 64 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_ = nullptr; 65 std::unique_ptr<DistributedKv::DistributedKvDataManager> kvDataManager_ = nullptr; 66 std::shared_ptr<DistributedKv::SingleKvStore> kvStore_ = nullptr; 67 std::shared_ptr<DistributedDeviceCallback> deviceCb_ = nullptr; 68 69 bool localScreenOn_ = false; 70 71 DECLARE_DELAYED_SINGLETON(DistributedScreenStatusManager); 72 DISALLOW_COPY_AND_MOVE(DistributedScreenStatusManager); 73 }; 74 } // namespace Notification 75 } // namespace OHOS 76 77 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_SCREEN_STATUS_MANAGER_H 78