1 /* 2 * Copyright (C) 2022-2025 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 PASTE_BOARD_DEV_PROFILE_H 17 #define PASTE_BOARD_DEV_PROFILE_H 18 19 #include "api/visibility.h" 20 #include "common/concurrent_map.h" 21 22 #include <memory> 23 #include <unordered_set> 24 25 namespace OHOS { 26 namespace MiscServices { 27 class DeviceProfileProxy; 28 29 class API_EXPORT DevProfile { 30 public: 31 using Observer = std::function<void(bool isEnable)>; 32 static DevProfile &GetInstance(); 33 int32_t GetDeviceStatus(const std::string &networkId, bool &status); 34 void PutDeviceStatus(bool status); 35 bool GetDeviceVersion(const std::string &networkId, uint32_t &deviceVersion); 36 void SubscribeProfileEvent(const std::string &networkId); 37 void UnSubscribeProfileEvent(const std::string &networkId); 38 void UnSubscribeAllProfileEvents(); 39 void SendSubscribeInfos(); 40 void ClearDeviceProfileService(); 41 void Watch(Observer observer); 42 void UpdateEnabledStatus(const std::string &udid, bool status); 43 void EraseEnabledStatus(const std::string &udid); 44 45 private: 46 DevProfile() = default; 47 virtual ~DevProfile() = default; 48 static void OnProfileUpdate(const std::string &udid, bool status); 49 void Notify(bool isEnable); 50 void PostDelayReleaseProxy(); 51 52 Observer observer_ = nullptr; 53 ConcurrentMap<std::string, bool> enabledStatusCache_; 54 std::shared_ptr<DeviceProfileProxy> proxy_ = nullptr; 55 std::recursive_mutex proxyMutex_; 56 std::unordered_set<std::string> subscribeUdidList_; 57 }; 58 } // namespace MiscServices 59 } // namespace OHOS 60 #endif // PASTE_BOARD_DEV_PROFILE_H 61